akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	int n,max,min;
	cin >> n;
	vector<int> vec;
	char s[10];
	for(int i=0;i<n;i++)
	{
		vec.clear();
		max=min=0;
		scanf("%s",s);
		for(int j=0;j<strlen(s);j++)
		{
			vec.pb(s[j]-'0');
		}
		sort(vec.begin(),vec.end());
		for(int j=0;j<vec.size();j++)
		{
			min+=(((int)pow(10,j))*vec[vec.size()-1-j]);
		}
		for(int j=0;j<vec.size();j++)
		{
			max+=(((int)pow(10,j))*vec[j]);
		}
		cout << max-min << endl;
	}
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;

int main(){
    
    int W,N;
    vector<int> S(13,0);
    vector<int> H(13,0);
    vector<int> C(13,0);
    vector<int> D(13,0);

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        char kind;
        int val;
        cin >> kind >> val;
        if(kind == 'S'){
          S[val-1] = 1;
        }else if (kind == 'H'){
          H[val-1] = 1;
        }else if (kind == 'C'){
          C[val-1] = 1;
        }else{ // D
          D[val-1] = 1;
        }
    }
    for (int i = 0; i < 13; i++)
    {
        if(S[i] == 0){
            cout << "S" << " " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++)
    {
        if(H[i] == 0){
            cout << "H" << " " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++)
    {
        if(C[i] == 0){
            cout << "C" << " " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++)
    {
        if(D[i] == 0){
            cout << "D" << " " << i+1 << endl;
        }
    }
    

    return(0);
}


Measured memory_bytes: 3092
import math
n,d = map(int,input().split())

xys = []
for i in range(n):
    x,y = map(int,input().split())
    xys.append([x,y])


def dis(x,y):
    return math.sqrt(x**2 + y**2)

c = 0
for i in range(n):
    if dis(xys[i][0],xys[i][1]) <= d:
        c += 1

print(c)


Measured memory_bytes: 39288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C096
    {
        static void Main(string[] args)
        {
            string[] a0 = Console.ReadLine().Split(' ');
            int H = int.Parse(a0[0]), W = int.Parse(a0[1]);
            char[,] s = new char[H+2, W+2];
            for (int i = 0; i < H; i++)
            {
                string s1 = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    s[i+1, j+1] = s1[j];
                }
            }

            bool impossible = false;
            for(int i = 1; i <= H; i++)
            {
                for(int j = 1; j <= W; j++)
                {
                    if (s[i, j] == '#')
                    {
                        if(s[i-1,j]!='#' && s[i+1,j]!='#')
                        {
                            if (s[i, j-1] != '#' && s[i, j+1] != '#')
                            {
                                impossible = true;
                                break;
                            }
                        }
                    }
                }
            }

            string r = impossible ? "No" : "Yes";
            Console.WriteLine(r);

        }

        }
    }


Measured memory_bytes: 11092
#include<stdio.h>
int main()
{
      long long int n=0,i,a,b;
      scanf("%lld",&a);
      for(i=1;i<=a;i++){
      scanf("%lld",&b);
      n=n+b;
      }
      printf("%lld\n",n-a);




      return 0;
}


Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int h,w;
  cin >> h >> w;
  vector<string>vec(h);
  rep(i,h) cin >> vec[i];
  rep(i,w+2)cout << '#';
  cout << endl;
  rep(i,h){
    cout << "#" << vec[i] << "#" << endl;;
  }
  rep(i,w+2)cout << '#';
  cout << endl;
  return 0;     
}


Measured memory_bytes: 256
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize,
        k: usize,
        pp: [Usize1; n],
        cc: [i64; n],
    }
    let mut ans = None;
    
    for i in 0..n {
        let mut index = i;
        let mut cycle_sum = 0;
        let mut cycle_count = 0;
        loop {
            index = pp[index];
            cycle_sum += cc[index];
            cycle_count += 1;
            if index == i {
                break;
            }
        }

        let mut sum = 0;
        for count in 1..=std::cmp::min(k, cycle_count) {
            index = pp[index];
            sum += cc[index];

            let sum = if cycle_sum > 0 {
                let n = (k - count) / cycle_count;
                cycle_sum * n as i64 + sum
            } else {
                sum
            };
            if let Some(ans) = ans.as_mut() {
                *ans = std::cmp::max(*ans, sum);
            } else {
                ans = Some(sum);
            }
        }
    }

    println!("{}", ans.unwrap());
}


Measured memory_bytes: 2344
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	int h,n,a;
	long long ans=0;
	scanf("%d%d",&h,&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		ans+=a;
	}
	if(ans>=h){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int main(){

  string str;

  cin>>str;

  char temp1='1';
  char temp2='0';

  int cnt=0;
  int cnt2=0;
  
  for(int i=0;i<str.length();i++){
	if(str[i]!=temp1){
	  cnt++;
	}
	if(str[i]!=temp2){
	  cnt2++;
	}

	if(temp1=='0'){
	  temp1='1';
	}else{
	  temp1='0';
	}
	
	if(temp2=='0'){
	  temp2='1';
	}else{
	  temp2='0';
	}
  }

  cout<<min(cnt,cnt2)<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vi;

int d[110][110][1<<4];

int main(){
  int n,m,e,s,t,r;
  cin >> n >> m >> e >> s >> t >> r;
  vector<vi> g(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<vi> ev(e,vi(3));
  int sbit = 0;
  rep(i,e){
    rep(j,3)cin >> ev[i][j];
    if(ev[i][2] == s)sbit |= 1<<i;
  }

  memset(d,-1,sizeof(d));
  d[s][0][sbit] = 0;
  queue<int> q;
  q.push(s*10000 + sbit);

  while(q.size()){
    int p = q.front(); q.pop();
    int v = p/10000, x = p/100%100, bit = p%100;

    if(v==t){
      cout << d[v][x][bit] << endl;
      return 0;
    }

    //ocarina
    if(d[s][0][bit]<0){
      d[s][0][bit] = d[v][x][bit]+1;
      q.push(s*10000 + bit);
    }

    if(x>=r)continue;
    //normal road
    for(int u : g[v]){
      int nbit = bit;
      rep(i,e){
	if(u == ev[i][2])nbit |= 1<<i;
      }
      if(d[u][x+1][nbit]<0){
	d[u][x+1][nbit] = d[v][x][bit] + 1;
	q.push(u*10000 + (x+1)*100 + nbit);
      }
    }

    //event road
    rep(i,e){
      if( (bit>>i)&1 ){
	if(v==ev[i][0]){
	  int u = ev[i][1], nbit = bit;
	  rep(i,e){
	    if(u == ev[i][2])nbit |= 1<<i;
	  }
	  if(d[u][x+1][nbit]<0){
	    d[u][x+1][nbit] = d[v][x][bit] + 1;
	    q.push(u*10000 + (x+1)*100 + nbit);
	  }
	}

	if(v==ev[i][1]){
	  int u = ev[i][0], nbit = bit;
	  rep(i,e){
	    if(u == ev[i][2])nbit |= 1<<i;
	  }
	  if(d[u][x+1][nbit]<0){
	    d[u][x+1][nbit] = d[v][x][bit] + 1;
	    q.push(u*10000 + (x+1)*100 + nbit);
	  }
	}

      }
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 2040
N = int(input())
list_l = []
list_r = []
ans = 0
for time in range(N) :
    A = [int(i) for i in input().split()]
    list_l.append(A[0])
    list_r.append(A[1])
    ans += list_r[time] - list_l[time] + 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>

#define Np 1000
#define Nm -1000

double distance(double,double);
double pythagorean(double,double);
int intersection(double,double,double);

double c1x,c1y,c1r;
double c2x,c2y,c2r;

int main(){
  int judge;
  double distance_x,distance_y;
  double dis;
  
  //printf("please enter circle1's x,y,r\n");
  scanf("%lf%lf%lf",&c1x,&c1y,&c1r);
  //printf("please enter circle2's x,y,r\n");
  scanf("%lf%lf%lf",&c2x,&c2y,&c2r);

  if(c1x < Nm || c1x > Np ||
     c1y < Nm || c1y > Np ||
     c2x < Nm || c2x > Np ||
     c2y < Nm || c2y > Np ||
     c1r < 1 || c1r > Np ||
     c2r < 1 || c2r > Np){
    printf("restriction\n");
    printf("-1000 <=c1x,c1y,c2x,c2y<= 1000\n");
    return 0;
  }
  else if(c1x == c2x && c1y == c2y && c1r == c2r){
    printf("restriction\n");
    printf("c1 and c2 not same\n");
    return 0;
  }

  //printf("c1y: %lf\n",c1y);
  //printf("c2y: %lf\n",c2y);

  distance_x = fabs(c1x-c2x);
  distance_y = fabs(c1y-c2y);
  
  //distance_x = distance(c1x,c2x);
  //distance_y = distance(c1y,c1y);
  //printf("%lf",distance_y);

  dis = pythagorean(distance_x,distance_y);
  judge = intersection(dis,c1r,c2r);
  /*
  if(judge == 4){printf("%d common tangent lines\n",judge);return 0;}
  else if(judge == 3){printf("%d common tangent lines\n",judge);return 0;}
  else if(judge == 2){printf("%d common tangent lines\n",judge);return 0;}
  else if(judge == 1){printf("%d common tangent lines\n",judge);return 0;}
  else if(judge == 0){printf("%d common tangent lines\n",judge);return 0;}
  else printf("program error\n");
  */
  if(judge == 4){printf("%d\n",judge);return 0;}
  else if(judge == 3){printf("%d\n",judge);return 0;}
  else if(judge == 2){printf("%d\n",judge);return 0;}
  else if(judge == 1){printf("%d\n",judge);return 0;}
  else if(judge == 0){printf("%d\n",judge);return 0;}
  else printf("program error\n");
}


double distance(double c1,double c2){
  printf("c1: %lf\n",c1);
  printf("c2: %lf\n",c2);
  return fabs(c1-c2);
}

double pythagorean(double a,double b){
  double sum;
  a = pow(a,2.0);
  b = pow(b,2.0);
  sum = a + b;
  //printf("%lf\n",a);
  //printf("%lf\n",b);
  //printf("%lf\n",sum);
  return sqrt(sum);
  
}

int intersection(double dis,double r1,double r2){
  double sum_r;
  double sub_r;
  
  sum_r = r1+r2;
  sub_r = fabs(r1-r2);
  //printf("%lf\n",sum_r);
  //printf("%lf\n",dis);
  if(dis > sum_r)return 4;
  else if(dis == sum_r)return 3;
  else if(sub_r < dis && dis < sum_r)return 2;
  else if(sub_r == dis)return 1;
  else if(dis < sub_r)return 0;
  else {printf("program error\n");return 5;}
}



Measured memory_bytes: 2112
from collections import deque
letter = deque(input())
Q= int(input())
reversed = False
for i in range(Q):
    query = input().split()
    if len(query)==1:
        reversed = not bool(reversed)
    else:
        if int(query[1])==1: #まえに追加
            if reversed == False:
                letter.appendleft(query[2])
            else:
                letter.append(query[2])
        else:
            if reversed == False:
                letter.append(query[2])
            else:
                letter.appendleft(query[2])
if reversed==True:
    letter.reverse()

output = ''.join(letter)
print(output)


Measured memory_bytes: 8436
#include<iostream>
using namespace std;
int main(){
	int r,c;
	cin >> r >> c;
	int A[r][c],cona[r],conb[c];
	int sam=0;

	for(int i=0; i<r; i++) cona[i] = 0;
	for(int j=0; j<c; j++) conb[j] = 0;

	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin >> A[i][j];
			cona[i] += A[i][j];
			conb[j] += A[i][j];
		}
	}

	int i,j;

	for(i=0; i<r; i++){
		for(j=0; j<c; j++){
			if(j>0) cout << " ";
			cout << A[i][j];
		}

		cout << " " << cona[i] << endl;
	}

	for(j=0; j<c; j++){
		sam += conb[j];
		cout << conb[j] << " ";
	}

	cout << sam << endl;

	return 0;

}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int n; cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  
  sort(all(a));

  bool same = false;
  rep(i,n-1) {
    if(a[i] == a[i+1]){same = true; break;}
  }
  cout << (same ? "NO" : "YES") << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <vector>
using namespace std;

int n;
int G[100][100];

void init() {
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            G[i][j] = 0;
        }
    }
}

void makeAdjMatrix() {
    int u, k, to;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> to;
            G[u - 1][to - 1] = 1;
        }
    }
}

void print() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j == n - 1) {
                cout << G[i][j];
            } else {
                cout << G[i][j] << " ";
            }
        }
        cout << endl;
    }
}

int main() {
    init();
    cin >> n;
    makeAdjMatrix();
    print();
    return 0;
}


Measured memory_bytes: 3136
//
//  abc150_d.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll INF = 1000000007;
#define PI 3.14159265

const int MAX = 110000;

ll fac[MAX], finv[MAX], inv[MAX];

std::vector<int> permutations;

int gcd(int a, int b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

int main() {
  int n, m;
  std::cin >> n >> m;
  ll a[n];
  std::cin >> a[0];

  ll x = 2;
  while(a[0]%x == 0) {
    x = x*2;
  }
  x /= 2;
  a[0] /= 2;

  ll lcm = a[0];
  for (int i = 1; i < n; i++) {
    std::cin >> a[i];
    if (a[i]%x!=0 || a[i]%(x*2)==0) {
      std::cout << 0 << std::endl;
      return 0;
    }
    a[i] /= 2;
    lcm = (lcm*a[i]) / gcd(lcm, a[i]);
    if (lcm > m) {
      std::cout << 0 << std::endl;
      return 0;
    }
  }

  ll ans = 0;
  for (int i = lcm; i <= m; i+=2*lcm) {
    ans++;
  }

  // std::cout << lcm << std::endl;
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> Vector;
typedef vector<vector<ll> > DVector;

#define fi          first
#define se          second
#define pb          push_back
#define INF         INT_MAX/3
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define dbg(x)      cout<<#x"="<<x<<endl
#define ub(x,y)     upper_bound(all(x),y)-x.begin()
#define lb(x,y)     lower_bound(all(x),y)-x.begin()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define rep(i,n)    repl(i,0,n-1)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<int>())
#define mkp(x,y)    make_pair(x,y)

void insertionSort(Vector a){
  cout << a[0];
  repl(i, 1, a.size()-1) cout << ' ' << a[i];
  cout << endl;

  repl(i,1,a.size()-1){
    ll v = a[i];
    int j = i-1;
    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
      a[j+1] = v;
    }

    cout << a[0];
    repl(i, 1, a.size()-1) cout << ' ' << a[i];
    cout << endl;
  }
}

int main(){
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  Vector a(n);
  rep(i,n)cin >> a[i];
  insertionSort(a);
}

Measured memory_bytes: 3156
#include <stdio.h>

int main(){
	int N, i, j=0;
	scanf("%d", &N);
	int a[N], b[N], c;
	for(i=0;i<N;i++){
		scanf("%d", &a[i]);
	}
	for(i=0;i<N;i++){
		c=a[i];
		b[i]=0;
		while(c%2==0){
			b[i]++;
			c/=2;
		}
	}
	
	for(i=0;i<N;i++){
		j+=b[i];
	}
	printf("%d", j);
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m; cin>>n>>m;
    scc_graph s{n};
    rep(i,m){
        int a,b; cin>>a>>b;
        s.add_edge(a,b);
    }
    auto c=s.scc();
    printf("%d\n",(int)c.size());
    for(auto v:c){
        printf("%d ",(int)v.size());
        for(auto p:v) printf("%d ",p);
        printf("\n");
    }
}

Measured memory_bytes: 40604
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
};

vector<pair<ll,pint>> edges;
ll a[202020],d;

ll dist(int x,int y){
    return d*abs(x-y)+a[x]+a[y];
}
void dfs(int l,int r){
    if(l+1>=r)return;
    ll mini=longinf,idx=-1;
    int m=(l+r)/2;
    for(int i=l;i<m;++i){
        if(dist(i,m)<mini)mini=dist(i,m),idx=i;
    }
    for(int i=m;i<r;++i){
        edges.push_back({dist(idx,i),{idx,i}});
    }
    mini=longinf;idx=-1;
    for(int i=m;i<r;++i){
        if(dist(i,l)<mini)mini=dist(i,l),idx=i;
    }
    for(int i=l;i<m;++i){
        edges.push_back({dist(idx,i),{idx,i}});
    }
    dfs(l,m);
    dfs(m,r);
}
int main(){
    int n;cin>>n>>d;
    rep(i,n)cin>>a[i];
    dfs(0,n);
    sort(edges.begin(),edges.end());
    UnionFind uf(n);
    ll ans=0;
    for(auto e:edges){
        if(uf.unite(e.second.first,e.second.second))ans+=e.first;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 69472
#include <bits/stdc++.h>
using namespace std;


int main(void)
{
	string s1;
	cin >> s1;

	string s2;
	cin >> s2;

	int n = s1.size();
	int m = s2.size();

	vector<vector<int>> dp;
	for(int i = 0;i < s1.size()+1;i++)
	{
		vector<int> temp;
		for(int j = 0;j < s2.size()+1;j++)
			temp.push_back(0);
		dp.push_back(temp);
	}

	for(int i = 0;i <= n;i++)
	{
		for(int j = 0;j <= m;j++)
		{
			if(i == 0 || j == 0)
				dp[i][j] = 0;
			else if(s1[i-1] == s2[j-1])
				dp[i][j] = 1 + dp[i-1][j-1];
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}

	int i = n;
	int j = m;

	string ans;
	while(i > 0 && j > 0)
	{
		if(s1[i-1] == s2[j-1])
		{
			ans.push_back(s1[i-1]);
			i--;
			j--;
		}
		else if(dp[i-1][j] > dp[i][j-1])
		{
			i--;
		}
		else
			j--;
	}

	reverse(ans.begin(),ans.end());

	cout << ans;
	return 0;
}

Measured memory_bytes: 35584
#include <stdio.h>

#include <iostream>
#include <vector>
#include <string.h>

#pragma warning (push)
#pragma warning (disable : 4996)
#define mod 1000000007;

using namespace std;

int main()
{
    int N;
    
    cin >> N;

    cout << (int)(N / 2) + N % 2;
}

#pragma warning (pop)

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 
signed main(){
    int a,b;
    cin>>a>>b;
    if(a<=5){
        cout<<0<<endl;
    }else if(a<=12){
        cout<<b/2<<endl;
    }else {
        cout<<b<<endl;
    }
}

Measured memory_bytes: 764
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[][]dp;
	static char[][]mat;
	static long mod=1000000007;
	static long solve(int r,int c)
	{
		if(r>=mat.length || c>=mat[0].length)
			return 0;
		if(mat[r][c]=='#')
			return 0;
		if(r==mat.length-1 && c==mat[0].length-1)
			return 1;
		if(dp[r][c]!=-1)
			return dp[r][c];
		long res=0;
		res=(solve(r+1,c)+solve(r,c+1))%mod;
		dp[r][c]=res;
		return res;
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		int[]ar=split();
		int n=ar[0];
		int m=ar[1];
		mat=new char[n][m];
		for(int i=0;i<n;i++)
		{
			String s=br.readLine();
			for(int j=0;j<m;j++)
			{
				mat[i][j]=s.charAt(j);
			}
		}
		dp=new long[n+1][m+1];
		for(int i=0;i<=n;i++)
		{
			Arrays.fill(dp[i], -1);
		}
		System.out.println(solve(0,0));
	}
}


Measured memory_bytes: 46980
#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll mx = LLONG_MIN;

    mx = max(mx, a * c);
    mx = max(mx, a * d);
    mx = max(mx, b * c);
    mx = max(mx, b * d);

    cout << mx ;
    
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int N, M;
vi c;

vvi dp(25, vi(50005, -1));

int dfs(int i, int dif) {
    if (dif == 0) return 0;
    if (i == M or dif < 0) return 500050;
    if (dp[i][dif] != -1) return dp[i][dif];

    int val1 = dfs(i, dif-c[i])+1;
    int val2 = dfs(i+1, dif);
    dp[i][dif] = min(val1, val2);

    return dp[i][dif];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    c.resize(M);
    REP(i, M) cin >> c[i];

    cout << dfs(0, N) << endl;
    return 0;
}



Measured memory_bytes: 10212
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const int maxn=1e5+5;
int n,m,u,v,fa[maxn],h[maxn];
int FIND(int x){
    if(x==fa[x]) return x;
    return fa[x]=FIND(fa[x]);
}
void UNION(int x,int y){
    x=FIND(x);
    y=FIND(y);
    if(x==y) return;
    if(h[x]<h[y]){
        fa[x]=y;
    }
    else{
        fa[y]=x;
        if(h[x]==h[y]) ++h[x];
    }
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
        fa[i]=i;
        h[i]=0;
	}
	for(int i=1;i<=m;i++){
        u=read(),v=read();
        UNION(u,v);
	}
	int ans=0,tmp=FIND(1);
	for(int i=2;i<=n;i++){
        if(FIND(i)!=tmp){
            UNION(i,1);
            tmp=FIND(1);
            ++ans;
        }
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4544
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
e=[[0 for i in range(n)] for j in range(n)]
xx=[]
for i in range(m):
 x=i2()
 x[0]-=1
 x[1]-=1
 xx.append(x)
 e[x[0]][x[1]]=1
 e[x[1]][x[0]]=1
d=[0 for i in range(n)]
def dfs(v):
    d[v]=1
    for i in range(n):
        if e[v][i]==1 and d[i]==0:
            dfs(i)
a=0
for i in xx:
 e[i[0]][i[1]]=0
 e[i[1]][i[0]]=0
 dfs(0)
 if 0 in d:
   a+=1
 d=[0 for j in range(n)]
 e[i[0]][i[1]]=1
 e[i[1]][i[0]]=1
print(a)


Measured memory_bytes: 41836
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int H,A;
void input()
{
    cin>>H>>A;
    return;
}

void solve()
{
    if(H%A) cout<<H/A+1<<endl;
    else cout<<H/A<<endl;
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 400005
using namespace std;
long /*double*/long ans=0;
long long n,a[N];
template<typename T> 
inline void read(T &x) 
{
    int f=0;
    int orz=1;
    char c=getchar();
    while(c<'0'||c>'9') 
    { 
        if (c=='-') 
            orz=-1; 
        c=getchar(); 
    }
    while(c>='0'&&c<='9') 
    {
        f=(f << 3)+(f << 1)+(c & 15);
        c=getchar(); 
    }
    f*=orz;
    x=f;
}
template<typename T>
void write(T x)
{
    /*if (x==INF)
    {
        write(-1);
        return;
    }*/
    if (x<0)
    {
        x=-x;
        putchar('-');
    }
    if (x>=10)
        write(x/10);
    putchar(x%10+'0');
}
int main()
{
	read(n);
	n=n << 1;
	for (register int i=1;i<=n;i++)
		read(a[i]);
	sort(a+1,a+n+1);
	for (register int i=1;i<=n;i++)
		ans=ans+(unsigned long long)a[i]*(i-1);
	/*ans/=(n-1);*/
	printf("%.13Lf",(long double)ans/(n-1));
	putchar('\n');
	return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

S = input()
T = input()
if len(S) + 1 == len(T) and T.startswith(S):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 10840
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a.at(i);

    int ans = MOD;
    for (int z = -1000; z <= 1000; z++) { // 0(N) = 2000 * 100
        int sum = 0;
        rep(j, N) {
            sum += (a.at(j) - z) * (a.at(j) - z);
        }
        ans = min(ans, sum);
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3464
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        for(int i =1 ; ; i++){
            int x =sc.nextInt();
            if(x==0){
                break;
            }
            System.out.printf("Case %d: %d\n",i,x);
        }
    }
}



Measured memory_bytes: 62892
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int N,K;
  string S;
  cin>>N;
  cin>>S;
  cin>>K;
  string A;
  for(int i=0; i<N; i++){
    if(S[i]==S[K-1]){
      A=A+S[i];
    }
    else{
      A=A+'*';
    }
  }
  cout <<A<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input().split()]

dp = [0]*(N+1)
L1 = [[0]*2 for _ in range(N+1)]
L2 = [[0]*2 for _ in range(N+1)]
L1[0][0] = 1000

for i in range(N):
    for j in range(i+1):
        if L1[i+1][0] < L1[j][0]+L1[j][1]*A[i]:
            L1[i+1][0] = L1[j][0]+L1[j][1]*A[i]
            L1[i+1][1] = 0
        if L1[i+1][0] < L2[j][0]+L2[j][1]*A[i]:
            L1[i+1][0] = L2[j][0]+L2[j][1]*A[i]
            L1[i+1][1] = 0
        if L2[i+1][1] < L1[j][1]+L1[j][0]//A[i] or (L2[i+1][1] == L1[j][1]+L1[j][0]//A[i] and L2[i+1][0] < L1[j][0]%A[i]):
            L2[i+1][1] = L1[j][1]+L1[j][0]//A[i]
            L2[i+1][0] = L1[j][0]%A[i]
        if L2[i+1][1] < L2[j][1]+L2[j][0]//A[i] or (L2[i+1][1] == L2[j][1]+L2[j][0]//A[i] and L2[i+1][0] < L2[j][0]%A[i]):
            L2[i+1][1] = L2[j][1]+L2[j][0]//A[i]
            L2[i+1][0] = L2[j][0]%A[i]
    dp[i+1] = max(dp[i], L1[i+1][0]+L1[i+1][1]*A[i], L2[i+1][0]+L2[i+1][1]*A[i])

print(dp[-1])

Measured memory_bytes: 68872
n = int(input())
k = int(input())
a = 0
x = list(map(int, input().split()))
ans = 0
for i in range(n):
   if abs(x[i]-a) <= abs(k-x[i]):
      ans += 2*abs(x[i]-a)
   else:
      ans += 2*abs(k-x[i])
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int ans=0;
    for(int i=1;i<=n;i++) {
        for(int j=i+1;j<=n;j++) {
            if(a[i]!=a[j]) {
                for(int k=j+1;k<=n;k++) {
                    if(a[i]==a[k] || a[j]==a[k]) continue;
                    if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i]) {
                        ans++;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }
//string al="abcdefghijklmnopqrstuvwxyz";
//vector< vector<int> > v (size1, vector<int>(size2) );



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;cin>>N>>M;
    vector<ll> a(M);
    vector<ll> b(M);
    vector<ll> c(M);
    ll C;
    ll c_bit; //1 2 4 5(N=6) -> 011011
    FOR(i,0,M){
        cin>>a[i]>>b[i];
        c_bit=0;
        FOR(j,0,b[i]){
            cin>>C;C--;
            c_bit |= 1<<C;
        }
        c[i]=c_bit;
        //cout<<c_bit<<endl;
    }

    ll ans=1e9;
    vector< vector<ll> > dp (M+1, vector<ll>(1<<N,1e9) );
    FOR(i,0,M+1)dp[i][0]=0;
    ll bit;
    
    FOR(i,1,M+1){
        FOR(j,0,1<<N){
            dp[i][j]=min(dp[i][j],dp[i-1][j]);
            //min(dp[i][j | c[i-1]],...)を加えないとdp[i][j | c[i-1]]が1e9で上書きされてしまう
            dp[i][j | c[i-1]]=min(dp[i][j | c[i-1]],min(dp[i-1][j | c[i-1]],dp[i-1][j]+a[i-1]));
            bit=j | c[i-1];
            if(bit==(1<<N)-1){
                ans=min(ans,dp[i][bit]);
            }
        }
    }
    
    cout<< (ans==1e9 ? -1 : ans) <<endl;
    
}
//688

Measured memory_bytes: 32384
// D.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[]) {
	int N, T;
	cin >> N >> T;
	int a[100000];
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	int mx = 0, mn = 1 << 30;
	int d = 0;
	for (int i = 0; i < N; ++i) {
		mn = min(mn, a[i]);
		d = max(d, a[i] - mn);
	}
	int ans = 0;
	mx = 0, mn = 1 << 30;
	for (int i = 0; i < N; ++i) {
		mn = min(mn, a[i]);
		if (a[i] - mn == d) {
			++ans;
			++mn;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    if(s == "SUN") cout << 7 << endl;
    if(s == "MON") cout << 6 << endl;
    if(s == "TUE") cout << 5 << endl;
    if(s == "WED") cout << 4 << endl;
    if(s == "THU") cout << 3 << endl;
    if(s == "FRI") cout << 2 << endl;
    if(s == "SAT") cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 768
from collections import deque
inf=10**3


def BFS():
    color=[["white" for _ in range(w)] for _ in range(h)]
    D=[[inf for _ in range(w)] for _ in range(h)]

    D[0][0]=1
    color[0][0]="gray"
    queue=deque([[0,0]])
    while len(queue)>0:
        a,b=queue.popleft()
        for c,d in [[1,0],[-1,0],[0,1],[0,-1]]:
            X,Y=a+c,b+d
            if 0<=X<h and 0<=Y<w:
                if S[X][Y]=="." and color[X][Y]=="white":
                    D[X][Y]=min(D[X][Y],D[a][b]+1)
                    color[X][Y]="gray"
                    queue.append([X,Y])
        color[a][b]="black"

    return D[-1][-1]


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
D=BFS()
black=sum([S[i].count("#") for i in range(h)])
print(h*w-D-black if D!=inf else -1)

Measured memory_bytes: 40688
N, K = gets.split.map(&:to_i)
table = Hash.new { 0 }
gets.split.map(&:to_i).each do |a|
  table[a] += 1
end
count_list = table.values.sort
c = [count_list.size - K, 0].max
ans = count_list.take(c).reduce(0, &:+)
puts ans


Measured memory_bytes: 32880
/*
    ITP1_2_B
*/

#include <stdio.h>

int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a < b && b < c)
        puts("Yes");
    else
        puts("No");
    return (0);
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>

using namespace std;

int64_t numbers_divided(int64_t right, int64_t modulo) {
    return (right - 1) / modulo;
}

int64_t numbers_divided(int64_t left, int64_t right, int64_t modulo) {
    return numbers_divided(right, modulo) - numbers_divided(left, modulo);
}

int64_t lcm(int64_t a, int64_t b) {
    return a / __gcd(a, b) * b;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    ++b;
    int64_t ans = b - a - numbers_divided(a, b, c) - numbers_divided(a, b, d) + numbers_divided(a, b, lcm(c, d));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
l_s = input()
sum = 0
for i in range(2**(len(l_s)-1)):
    m_s = list(l_s)
    countj = 0
    for j in range(len(l_s)-1):
        if ((i >> j) & 1):
            m_s.insert(j+1+countj,'+')
            countj += 1
    m_s = ''.join(m_s)
    sum += eval(m_s)
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using  namespace std;
typedef pair<int,int> P;

int main() {
  int n;
  cin >> n;
  set<P> red, blue;
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    red.insert(P(x,y));
  }
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    blue.insert(P(x,y));
  }

  int ans = 0;
  for (P b : blue) {
    P buf(-1, -1);
    int cnt = 0;
    for (P r : red) {
      if (r.first > b.first) break;
      if (r.second > buf.second && r.second <= b.second) {
        buf = r;
        ++cnt;
      }
    }
    if (cnt) {
      ++ans;
      red.erase(buf);
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<sstream>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
const int inf=1e8;
int mml[205][205],mms[205][205],dp[1005][205],num[1005];
int main(){
    int n,m,a,b,c,r;
    char str[5];
    while(scanf("%d%d",&n,&m)&&n){
        for(int i=0;i<n;i++){
            mml[i][i]=mms[i][i]=0;
            for(int j=i+1;j<n;j++){
                mml[i][j]=mml[j][i]=inf;
                mms[i][j]=mms[j][i]=inf;
            }
        }
        for(int i=0;i<m;i++){
            scanf("%d%d%d%s",&a,&b,&c,str);
            a--,b--;
            if(str[0]=='L'){
                mml[a][b]=mml[b][a]=min(mml[a][b],c);
            }else{
                mms[a][b]=mms[b][a]=min(mms[a][b],c);
            }
        }
        scanf("%d",&r);
        for(int i=0;i<r;i++){
            scanf("%d",&num[i]);
            num[i]--;
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    mml[i][j]=min(mml[i][j],mml[i][k]+mml[k][j]);
                    mms[i][j]=min(mms[i][j],mms[i][k]+mms[k][j]);
                }
            }
        }
        for(int i=0;i<r;i++){
            for(int j=0;j<n;j++){
                dp[i][j]=inf;
            }
        }
        for(int i=0;i<n;i++){
            dp[0][i]=mms[num[0]][i]+mml[i][num[0]];
        }
        int ans=inf;
        for(int i=1;i<r;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    if(j!=k)
                        dp[i][k]=min(dp[i][k],dp[i-1][j]+mml[num[i-1]][j]+mms[j][k]+mml[k][num[i]]);
                    else dp[i][j]=min(dp[i][j],dp[i-1][j]+mml[num[i-1]][num[i]]);
                }
            }
        }
        for(int i=0;i<n;i++){
            ans=min(ans,dp[r-1][i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 4208
for i in range(3000):
    x = list(input().split(" "))
    if x[0] == "0" and x[1] == "0":
        break
    idx = 0
    for j in x:
        x[idx] = int(j)
        idx += 1
    x.sort()
    print(x[0], x[1])

Measured memory_bytes: 7564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int gcd(int a, int b){
    int r,temp;
    if (a < b){
        temp = a;
        a = b;
        b = temp;
    }
    while ( (r = a % b) != 0){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    vector<int> left(N);
    vector<int> right(N);
    vector<int> M(N,0);
    left[0] = vec[0];
    rep(i,N - 1){
        left[i + 1] = gcd(left[i],vec[i + 1]);
    }
    right[N - 1] = vec[N - 1];
    repr(i,N - 2){
        right[i] = gcd(right[i + 1],vec[i]);
    }
    M[0] = right[1];
    M[N - 1] = left[N - 2];
    for (int i = 1; i < N - 1; i++){
        M[i] = gcd(left[i - 1],right[i + 1]);
    }
    int ans = M[0];
    for (int i = 1; i < N; i++){
        ans = max(ans,M[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
x,k,d = gets.split(' ').map(&:to_i)
odd = (k % 2).odd?
d2 = d * 2
cand=[]
leftest = x - d * k
rightest = x + d*k
cand << leftest.abs
cand << rightest.abs
if leftest < 0 && rightest > 0 
  nr =  (x + (odd ? d : 0)) % d2
  nl = nr - d2
  cand << nr.abs
  cand << nl.abs
end
p cand.min

Measured memory_bytes: 14380
# 最も単純にやると
# 盤面の移動のしかたはN^2通り
# それぞれに対して、対称行列かの判定はO(N^2)個の条件を確認する必要がある
# したがってO(N^4)である。間に合わない。
# しかし、対称行列であれば、1行1列を右下に移動しても対称行列である。
# これより、行またはだけを移動した場合について確認すれば良い。O(N^3)。

n = int(input())
masume = [input() for i in range(n)]

count = 0
for diff in range(n):
    flag = True
    for i in range(n):
        for j in range(i+1, n):
            if masume[(i+diff)%n][j] != masume[(j+diff)%n][i]:
                flag = False
                break
        if not flag:
            break
    count += flag

print(count * n)


Measured memory_bytes: 74288
#include <stdio.h>
 
int main(){
  char c[1200];
  int i, j;
  
  while(1){
    scanf("%c",&c[i]);
    if(c[i]=='\n'){
      break;
    }
    i++;
  }
  for( j = 0; j < i; j++){
    if(c[j] >= 'A' && c[j] <= 'Z') c[j] += 32;
    else if( c[j] >= 'a' && c[j] <= 'z') c[j] -= 32;
    printf("%c",c[j]);
    if( j == i-1)printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2088
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;

int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    vector<bool> inf(n, 0), vis(n, 0);
    vector<int> to(n);
    for(int i = 0; i < n; i++){
        if(vis[i])  continue;
        vis[i] = true;

        if(p[i] == 0){
            to[i] = i;
            continue;
        }

        int now = i + p[i];
        set<int> res;
        res.insert(i);
        while(!vis[now]){
            vis[now] = true;
            res.insert(now);
            now = now + p[now];
        }
        
        if(p[now] == 0){
            for(int v : res)    to[v] = now;
        }else if(res.count(now) || inf[now]){
            for(int v : res)    inf[v] = true;
        }else{
            for(int v : res)    to[v] = to[now];
        }
    }
    vector<int> step(n, 1<<30);
    step[0] = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int i = q.front();  q.pop();
        if(i+6 >= n-1){
            cout << step[i]+(i!=n-1) << endl;
            break;
        }
        for(int j = 1; j <= 6; j++){
            if(inf[i+j])    continue;
            if(step[i]+1 < step[to[i+j]]){
                step[to[i+j]] = step[i]+1;
                q.push(to[i+j]);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 7472
import math
import sys
sys.setrecursionlimit(10 ** 6 + 10)
from collections import defaultdict

def kari():
    map(int, input().split())

    num, num2 = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num2)]

def main():
    a, b = map(int, input().split())

    if a >= 13:
        print(b)
    elif a >= 6:
        print(b //2)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n, x; cin >> n >> x;
    vector<int> a(n), b(n);
    long long ans=0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(!i) b[i] = min(a[i], x);
        else b[i] = min(a[i], x-b[i-1]);
        ans += a[i] - b[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;

using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using tt = pair<pii, int>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int MOD = 1e9 + 7;

int main(){
  int n, m;cin >> n >> m;
  int p, y;
  vector< tt > data(m);
  vector<pair<int, int> > ANS(m);
  REP(i, m){
    cin >> p >> y;
    pair<int, int> tmp = make_pair(p, y);
    data[i] = make_pair(tmp, i);
  }
  sort(data.begin(), data.end());
  pair<int, int> t;
  int k, t1, t2;
  int before = 0;
  int conseq = 1;
  REP(i, m){
    t = data[i].first;
    t1 = t.first; t2 = t.second;
    k = data[i].second;
    if(before != t1){
      before = t1;
      conseq = 1;
    }
    else{
      conseq++;
    }
    ANS[k] = make_pair(t1, conseq);
  }
  int a, b;
  REP(i, m){
    a = ANS[i].first;
    b = ANS[i].second;
    printf("%06d%06d\n", a, b);
  }
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a == 0) return b;
    else if (b == 0) return a;
    else return gcd(b, a%b);
}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<ll> l(n+1);
    vector<ll> r(n+1);
    l[0] = r[n] = 0;
    for (int i = 1; i <= n; i++) {
        l[i] = gcd(a[i-1], l[i-1]);
        r[n-i] = gcd(a[n-i], r[n-i+1]);
    }

    ll max_gcd = 0;
    for (int i = 0; i < n; i++) {
        ll tmp = gcd(l[i], r[i+1]);
        max_gcd = max(tmp, max_gcd);
    }

    cout << max_gcd << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    ll N;
    cin >> N;
    if (N <1000)
    {
        cout << "ABC" << endl;
    }
    else
    {
        cout << "ABD" << endl;
    }
}


Measured memory_bytes: 3632