akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 100000000;

bool operator <(const string &s1, const string &s2){
	int i = 0;
	while(s1[i] == '0' && i < s1.size()) i++;
	string s = s1.substr(i, s1.size()-i);
	i = 0;
	while(s2[i] == '0' && i < s2.size()) i++;
	string t = s2.substr(i, s2.size()-i);

	if(s.size() > t.size()) return false;
	if(s.size() < t.size()) return true;
	rep(i, s.size()){
		if(s[i] < t[i]) return true;
		if(s[i] > t[i]) return false;
	}
	return false;
}

int main(){
	while(1){
		int w, h;
		cin >> w >> h;
		if(!w && !h) break;
		vector<string> table(h);
		rep(i, h){
			cin >> table[i];
		}

		vector<vector<string> > ls(h, vector<string>(w, ""));

		rep(i, h){
			rep(j, w){
				if(table[i][j] < '0' || table[i][j] > '9' ) continue;
				if(j-1 < 0 && i-1 < 0){
					ls[i][j] = table[i][j];
					continue;
				}
				string left;
				if(j-1 < 0) left = "";
				else left = ls[i][j-1] + table[i][j];
				string above;
				if(i-1 < 0) above = "";
				else above = ls[i-1][j] + table[i][j];
				if(left < above){
					ls[i][j] = above;
				}else{
					ls[i][j] = left;
				}

			}
		}

		string secret;

		rep(i, h){
			rep(j, w){
				secret = (secret<ls[i][j]?ls[i][j]:secret);
			}
		}

		int i = 0;
		while(secret[i] == '0' && i < secret.size()) i++;
		string res = secret.substr(i, secret.size()-i);

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1348
N, M, Q = map(int, input().split());
L = [];
R = [];

for i in range(M):
    Lnew, Rnew = map(int, input().split());
    L.append(Lnew);
    R.append(Rnew);

p = [];
q = [];

for i in range(Q):
    pnew, qnew = map(int, input().split());
    p.append(pnew);
    q.append(qnew);


trainList = [0] * (N**2);
ansList   = [0] * (N**2);

for i in range(M):
    trainList[(R[i]-L[i])*N+(L[i]-1)]+=1;

for i in range(N**2):
    if(i<N):
        ansList[i]=trainList[i];
    elif(i<N*2):
        ansList[i]=trainList[i]+ansList[i-N]+ansList[i-N+1];
    else:
        ansList[i]=trainList[i]+ansList[i-N]+ansList[i-N+1]-ansList[i-2*N+1];

for i in range(Q):
    ln=q[i]-p[i];
    print(ansList[ln*N+p[i]-1]);


Measured memory_bytes: 29588
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int n,k;
	int ans;
	
	//データの読み込み
	scanf("%d %d",&n,&k);
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	if(n%k){
		ans = 1;
	}else{
		ans = 0;
	}
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(M)]
A = sorted(A,key=lambda x:x[0])
cnt = 0
bmin = 10**6
for i in range(M):
    a,b = A[i][0],A[i][1]
    if a>=bmin:
        cnt += 1
        bmin = b
    else:
        bmin = min(bmin,b)
cnt += 1
print(cnt)

Measured memory_bytes: 29932
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n,a,b;
    while(cin>>n>>a>>b){
        if((n|a|b)==0)break;
        bool c[n+1];
        int i=0,ret=0;
        fill((bool *)c,(bool *)c+n+1,false);
        c[0] = true;
        for(i;i<n+1;i++){
            if(c[i]){
                if(i+a<=n)c[i+a]=true;
                if(i+b<=n)c[i+b]=true;
            }else{
                ret++;
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
import Data.List

main = do
  [n,k]<-map read.words<$>getLine
  vs <- map read.words<$>getLine
  print $ solve n k vs

solve :: Int->Int->[Int]->Int
solve n k vs = maximum ans
  where
  ss = map g ses
  ses = [(a,b)|a<-[0..n],b<-[a..n],b-a>=n-k]
  g (a,b) = take a vs ++ drop b vs
  ans = map f ss
  f s = go (k-length s) s'
    where
    go _ [] = 0
    go 0 s = sum s
    go n (e:s)
      | e<0 = go (n-1) s
      | otherwise = e + go n s
    s' = sort s

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>

struct {
  int x,y;
} typedef point;

using namespace std;

point A[100];
point B[100];
bool AT[100];
bool BY[100];

bool compx(point a, point b) {
  return ( a.x > b.x );
}

bool compy( point a, point b) {
  return ( a.y < b.y);
}

int main()
{
  int N;
  int sum = 0;

  cin >> N;

  for ( int i = 0; i < N; ++i ) {
    scanf("%d%d", &A[i].x, &A[i].y);
  }

  for ( int i = 0; i < N; ++i ) {
    scanf("%d%d", &B[i].x, &B[i].y);
  }

  sort(A, A+N, compx);
  sort(B, B+N,compy);

  for ( int i = 0; i < N; ++i )
  {
    int pos;
    for ( pos = 0; pos < N; ++pos ) {
      if ( A[pos].x < B[i].x && A[pos].y < B[i].y && !AT[pos]) break;
    }

    if ( pos == N ) continue;

    AT[pos] = true;

  }

  for ( int i = 0; i < N; ++i ) if ( AT[i] ) ++sum;

  cout << sum << "\n";
}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
  char s[20];
  int i;

  scanf("%s", s);

  for (i = 0;i<20;i++){
    if(s[i]==',') {
      s[i] = ' ';
    }
  }

  printf("%s", s);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
	int m;
	int coin[6] = {500, 100, 50, 10, 5, 1};

	while (cin >> m, m){
		int cnt = 0;
		int change = 1000 - m;

		for (int i = 0; i < 6; i++){
			cnt += change / coin[i];
			change %= coin[i]; // -= coin[i] * (change / coin[i]);
		}

		cout << cnt << endl;
	}

	return (0);
}

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

int dfs(int n, int s, int i, int acc){
    if(n == 0) return s == acc ? 1 : 0;
    else if(i == 9) return 0;

    int res = 0;
    for(int j=i+1;j<=9;++j) res += dfs(n-1, s, j, acc + j);
    return res;
}

int main(){
    int n, s;
    while(cin >> n >> s, n != 0){
        int ans = 0;
        for(int i=0;i<=9;++i) ans += dfs(n-1, s, i, i);
        cout << ans << endl;
    }

    return 0;
}


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

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long;
using pll = pair<ll, ll>;

int main()
{
    ll H, W, M;
    cin >> H >> W >> M;

    map<ll, ll> NX;
    map<ll, ll> NY;
    set<pll> P;

    ll xn = 0, yn = 0;

    rep (i, M)
    {
        ll x, y;
        cin >> x >> y;
        --x;
        --y;

        P.insert(pll(x, y));

        if (!NX[x]) { NX[x] = 1; } else { ++NX[x]; }
        if (!NY[y]) { NY[y] = 1; } else { ++NY[y]; }

        xn = max(xn, NX[x]);
        yn = max(yn, NY[y]);
    }

    vector<ll> xs;
    vector<ll> ys;

    for (const auto& kv : NX) { if (kv.second == xn) { xs.emplace_back(kv.first); } }
    for (const auto& kv : NY) { if (kv.second == yn) { ys.emplace_back(kv.first); } }

    const auto find = [&]()
    {
        for (const auto& x : xs)
        for (const auto& y : ys)
        {
            const auto pos = pll(x, y);
            if (P.find(pos) == P.end()) { return true; }
        }

        return false;
    };

    cout << xn + yn - (find() ? 0 : 1) << endl;

    return 0;
}


Measured memory_bytes: 67840
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

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


signed main(void) {
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    rep(i,n){
        cout << s[i] << t[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
n = int(input())
heights = [int(h) for h in input().split()]
current = heights[0] - 1

for h in heights[1:]:
    if current < h:
        current = h - 1
    elif current == h:
        current = h
    else:
        current = -1
        break

if current < 0:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define rREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define rFOR(i, a, b) for (ll i = a; i >= b; --i)
#define aFOR(i, V) for (auto i : V)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
#define INF 1'000'000'007 // 10^9 + 7
#define MOD 1'000'000'007 // 10^9 + 7
#define lINF 1'000'000'000'000'000'007 // 10^18 + 7
// ------------------------------

int main() {
    int N;
    cin >> N;
    int flag = 0;
    int cnt = 0;
    REP(i, N) {
        int D1, D2;
        cin >> D1 >> D2;
        if (D1 == D2) cnt += 1;
        else {
            flag = max(flag, cnt);
            cnt = 0;
        }
    }
    flag = max(flag, cnt);
    if (flag >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string.h>
using namespace std;

int main(){
  string S;
  bool flag = false;
  cin >> S;
  for(int i=0;i<3; i++){
    char c = S[i];
    char c2 = S[i+1];
    if(c == c2) flag = true;
  }

  if(!flag) cout<< "Good" <<endl;
  else cout<<"Bad"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
char str[31][31];
int dx[]={1,1,1,0,0,-1,-1,-1};
int dy[]={1,0,-1,1,-1,1,0,-1};
map<pair<int,pair<int,int> > ,int> m;
int x[21];
int y[21];
int fi[31][31];
int sz;
int solve(int bit,int row,int col){
	if(row>=18)return 0;
	if(m.count(make_pair(bit,make_pair(row,col))))return m[make_pair(bit,make_pair(row,col))];
	int ret=99999999;
	for(int i=0;i<8;i++){
		int nr=row+dx[i];
		int nc=col+dy[i];
		int tb=bit;
		while(0<=nr&&nr<=18&&0<=nc&&nc<=14){
			if(!~fi[nr][nc]||!(bit&(1<<fi[nr][nc])))break;
			tb-=(1<<(fi[nr][nc]));
			nr+=dx[i];nc+=dy[i];
		}
		if(nr-dx[i]==row&&nc-dy[i]==col)continue;
		if(nr<19&&(nc<0||nc>=15))continue;
		ret=min(ret,solve(tb,nr,nc)+1);
	}
	return m[make_pair(bit,make_pair(row,col))]=ret;
}
int main(){
	for(int i=0;i<19;i++)scanf("%s",str[i]);
	int row=0;
	int col=0;
	for(int i=0;i<31;i++)for(int j=0;j<31;j++)fi[i][j]=-1;
	for(int i=0;i<19;i++)for(int j=0;j<15;j++){
		if(str[i][j]=='O'){row=i;col=j;}
		if(str[i][j]=='X'){
			fi[i][j]=sz;
			x[sz]=i;y[sz]=j;sz++;
		}
	}
	int ret=solve((1<<sz)-1,row,col);
	if(ret>99999)printf("-1\n");
	else printf("%d\n",ret);
}

Measured memory_bytes: 6192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
ll p[10000],c[10000];
ll ans=-1000000000000000000LL;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>p[i];
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=1;i<=n;i++)
	{
		int next=p[i];
	    int l=1;
	    ll s=c[next];
		ans=max(ans,s);
	    while(l<k&&next!=i)
		{
	    	next=p[next];
	    	s+=c[next];
	    	ans=max(ans,s);
	    	l++;
	    }
	    if(s>=0LL&&l<k)
		{
	    	s*=(ll)((k-l)/l);
	    	int t=k%l+l;
	    	while(t>0)
			{
		        next=p[next];
		        s+=c[next];
		        if(s>ans) ans=s;        
		        t--;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3724
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    string w[n];
    F0R(i,n) cin >> w[i];
    F0R(i,n-1){
      if(w[i][w[i].length()-1] != w[i+1][0])
      {
        cout << "No"<<endl;
        return 0;
      }
      F0R(j,i) {
        if(w[i] == w[j]){
          cout << "No"<<endl;
          return 0;
        }
      }
    }
    F0R(i,n-1) {
      if(w[i] == w[n-1]){
        cout << "No"<<endl;
        return 0;
      }
    }
    cout << "Yes" << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
  long long int N;
  long long int i,j,k;
  long long int answer;
  
  scanf("%lld",&N);
  long long int str[N+3];
  long long int seisuu[N+3];
  
  for(i=0;i<N;i++){
    scanf("%lld",&str[i]);  
  }
  for(i=0;i<N;i++){
    j = i+1;
    seisuu[i] = j;
  }  
  
  j = 0;
  for(i=0;i<N;i++){
    if( str[i] == seisuu[j] ){
      //printf("%d\n",seisuu[j]);
      j++;
    }
  }
  
  if( j == 0 ){
    answer = -1;
  }
  else{
    j = j-1;
  
    answer = N - seisuu[j];
  }
  
  printf("%lld\n",answer);
  
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = (int)(n)-1; i >=0; i--)

using ll = long long;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  string c = s;
  reverse(c.begin(),c.end());
  vector<int> E(n),W(n);
  rep(i,n){
    E.at(i) = 0;
    W.at(i) = 0;
  }
  rep(i,n){
    if(i==0){
      if(c.at(i)=='E')E.at(i)=1;
    }else{
      E.at(i)=E.at(i-1);
      if(c.at(i)=='E')E.at(i)+=1;
    }
  }
  rep(i,n){
    if(i==0){
      if(s.at(i)=='W')W.at(i)=1;
    }else{
      W.at(i)=W.at(i-1);
      if(s.at(i)=='W')W.at(i)+=1;
    }
  }
  int ans = n;
  rep(i,n){
    //s.at(i) is leader;
    int tmp = 0;
    if(i==0){
      tmp = E.at(n-2);
    }else if(i==n-1){
      tmp = W.at(n-2);
    }else{
      tmp = W.at(i-1) + E.at(n-i-1); 
    }
    ans = min(ans,tmp);
  }
  cout<<ans<<endl;
}


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

using namespace std;

int main(){

  string record;
  
  while(1){

	int a=0;
	int b=0;
	
	cin>>record;

	if(record == "0")
	  break;

	bool flag = false; 
	
	for(int i=0;i<record.size()-1;++i){
	  if(record[i] == record[i+1] && record[i] == 'A')
		a++;
	  else if(record[i] == record[i+1] && record[i] == 'B')
		b++;
	  else if(record[i] != record[i+1] && record[i] == 'A')
		b++;
	  else if(record[i] != record[i+1] && record[i] == 'B')
		a++;

	  if(flag == false && (a == 11 || b == 11))
		break;

	  if(flag == true && (a-b == 2 || b-a == 2))
		break;
	  
	  if(a == 10 & b == 10)
		flag =true;

	}

	if(a > b) a++;
	else b++;
	
	cout<<a<<" "<<b<<endl;
	
  }
  
}



Measured memory_bytes: 3004
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
long long int n,k;
vector<vector<long long int> > matrix(50,vector<long long int> (50,0));
vector<vector<long long int> > temp(50,vector<long long int> (50,0));

void multiply(vector<vector<long long int> > &a,vector<vector<long long int> > &b)
{
    long long int i,j,kk;
    vector<vector<long long int> > xx(50,vector<long long int> (50));
    for(i=0;i<50;i++)
    {
        for(j=0;j<50;j++)
        {
            for(kk=0;kk<50;kk++)
            {
                xx[i][j]=(xx[i][j]+((a[i][kk]*b[kk][j])%mod))%mod;
            }
        }
    }

    for(i=0;i<50;i++)
        for(j=0;j<50;j++)
            a[i][j]=xx[i][j];
}

int main()
{
    cin>>n>>k;
    long long int i,j;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>matrix[i][j],temp[i][i]=1;

    while(k)
    {
        if(k&1)
            multiply(temp,matrix);
        multiply(matrix,matrix);
        k/=2;
    }

    long long int ans=0;
    for(i=0;i<50;i++)
        for(j=0;j<50;j++)
            ans=(ans+temp[i][j])%mod;
    cout<<ans;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

class Node:
    def __init__(self, sigma, depth):
        self.end = False
        self.child = [None] * sigma
        self.depth = depth
    def __setitem__(self, i, x):
        self.child[i] = x
    def __getitem__(self, i):
        return self.child[i]

class Trie():
    def __init__(self, sigma):
        self.sigma = sigma
        self.root = Node(sigma, 0)
    
    def add(self, S):
        vn = self.root
        for cs in S:
            if vn[cs] is None:
                vn[cs] = Node(self.sigma, vn.depth + 1)
            vn = vn[cs]
        vn.end = True

ans = 0

N, L = map(int, readline().split())

Tr = Trie(2)

for _ in range(N):
    S = list(map(int, readline().strip()))
    Tr.add(S)

cnt = 0
stack = [Tr.root]
while stack:
    vn = stack.pop()
    for i in range(2):
        if vn[i] is None:
            r = L - vn.depth
            cnt ^= -r&r
        else:
            stack.append(vn[i])

print('Alice' if cnt else 'Bob')


Measured memory_bytes: 61404
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1000010,Mo=1000000007;
int fac[N],inv[N];
inline int Pow(int x,int y) {
    int ret=1;
    while(y) {
	if(y&1) ret=1LL*ret*x%Mo;
	x=1LL*x*x%Mo,y>>=1;
    }
    return ret;
}
inline int C(int n,int m) {
    if(n<m) return 0;
    return 1LL*fac[n]*inv[m]%Mo*inv[n-m]%Mo;
}
int main() {
    int n,ans=0;
    cin>>n;
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%Mo;
    inv[n]=Pow(fac[n],Mo-2);
    for(int i=n;i;i--) inv[i-1]=1LL*inv[i]*i%Mo;
    for(int i=1,la=0;i<n;i++) {
	int t=1LL*C(i-1,n-i-1)*fac[i]%Mo*fac[n-i-1]%Mo;
	ans=(ans+1LL*(t-la+Mo)*i)%Mo,la=t;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 8064
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		ArrayList<Integer> multiArray = new ArrayList<>();
		for(int i = 1; i <= 9; i++) {
			for(int j = 1; j <= 9; j++) {
				multiArray.add(i * j);
			}
		}
		if(multiArray.contains(N)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 23252
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		ArrayList<Integer> list=new ArrayList<Integer>();
		Map<Integer, Integer> map=new HashMap<Integer, Integer>();
		while(scan.hasNext()){
			int x=scan.nextInt();
			if(map.containsKey(x)){
				map.put(x, map.get(x)+1);
			}else{
				map.put(x, 1);
			}
		}

		int max=0;
		int len=map.size();
		for (Map.Entry<Integer, Integer> val: map.entrySet()) {

			if(val.getValue()>=max){
				max=Math.max(max, val.getValue());
			}
		}
		for (Map.Entry<Integer, Integer> val: map.entrySet()) {

			if(val.getValue()==max){
				list.add(val.getKey());
			}
		}
		
		Collections.sort(list);
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}

	}

}

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

int main() {
    using vi = vector<int>;
    
    int n;
    cin >> n;
    long sum = 0;
    rep(i,n+1) {
        if(i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(){
	int k[30];
	int a[30][30];
	int n,m,count=0;
	int i,j,jug;
	
	scanf("%d %d",&n,&m);
	for(i = 0;i < n;i++){
		scanf("%d",&k[i]);
		for(j=0;j < k[i];j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i = 1;i <= m ;i++){
		jug = 0;
		for(j=0;j<n;j++){
			
			for(int l=0 ;l < k[j];l++){
				if(a[j][l] == i) jug++;
			}
		}
		if(jug == n) count++;
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 128
A1 = input().split()
A1 = [int(l) for l in A1]
A2 = input().split()
A2 = [int(l) for l in A2]
A3 = input().split()
A3 = [int(l) for l in A3]

N = int(input())

for i in range(N):
    b = int(input())
    for j in range(3):
        if A1[j] == b:
            A1[j] = 0
    for j in range(3):
        if A2[j] == b:
            A2[j] = 0
    for j in range(3):
        if A3[j] == b:
            A3[j] = 0
T = "No"
if A1[0] == 0 and A1[1] == 0 and A1[2] == 0:
    T = "Yes"
elif A2[0] == 0 and A2[1] == 0 and A2[2] == 0:
    T = "Yes"
elif A3[0] == 0 and A3[1] == 0 and A3[2] == 0:
    T = "Yes"
elif A1[0] == 0 and A2[1] == 0 and A3[2] == 0:
    T = "Yes"
elif A1[2] == 0 and A2[1] == 0 and A3[0] == 0:
    T = "Yes"
for i in range(3):
    if A1[i] == 0 and A2[i] == 0 and A3[i] == 0:
        T = "Yes"
print(T)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main
{
	public static void main( String args[] )
	{
		Scanner input = new Scanner(System.in);
		int h, w;
		while(true)
		{
			h=input.nextInt();
			w=input.nextInt();
			if(h == 0 && w == 0)
				break;
			else {
				for(int i = 0; i < h; i++)
				{
					for(int k = 0; k < w; k++)
					{
						if((i+k)%2==0)
							System.out.print("#");
						else
							System.out.print(".");
					}
					System.out.println();
				}
			}
			System.out.println();
		}
	}
}

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

int main()
{
	string S;
	cin >> S;

	int l = 0;
	int r = S.size() - 1;
	int ans = 0;
	while( l < r ) {
		if( S[l] == S[r] ) {
			l++;
			r--;
		}
		else if( S[l] == 'x' ) {
			ans++;
			l++;
		}
		else if( S[r] == 'x' ) {
			ans++;
			r--;
		}
		else{
			cout << -1 << endl;
			return 0;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;


int main(){
    string s;
    cin >> s;
    int n = s.length();
    ll answer = 0;
    // {0, 1, ..., n-1} の部分集合の全探索
    for (ll bit = 0; bit < (1<<(n-1)); ++bit)
    {
        bitset<16> tmp(bit);
        ll cost = 1;
        /* bit で表される集合の処理を書く */
        for(int i = n-1; i > 0; i--){
            char c = s.at(i);
            answer += cost * (c - '0');
            if(tmp.test(n-1-i)) {
                cost = 1;
            }
            else cost *= 10;
        }
        answer += cost * (s.at(0) - '0');
    }
    cout << answer << endl;
}

Measured memory_bytes: 3556
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
long long n,m;
int main(){
	scanf("%lld%lld",&n,&m);
	/*n/=2;m/=2;
	n^=m;*/
	if (abs(n-m)>1) printf("Alice\n");else printf("Brown\n");
	return 0;
}

Measured memory_bytes: 128
use std::io;
use io_ext::Reader;

fn main() {
    let stdin = io::stdin();
    let mut r = Reader::new(stdin.lock());

    let n: usize = r.read_line().parse().unwrap();
    let mut poses = Vec::with_capacity(n);
    for _ in 0..n {
        let mut s = r.read_line().split_whitespace();
        let (x, y): (isize, isize) = (s.next().unwrap().parse().unwrap(), s.next().unwrap().parse().unwrap());
        poses.push((x, y));
    }
    // let n = 2;
    // let poses: Vec<(isize, isize)> = vec![(-879, 981), (-866, 890)];

    let mut sum: f64 = 0.0;
    for i in 0..n {
        for j in (i + 1)..n {
            let (px, py) = poses[i];
            let (qx, qy) = poses[j];
            let dist = ((px - qx) * (px - qx) + (py - qy) * (py - qy)) as f64;
            let dist = dist.sqrt();
            sum += dist;
        }
    }

    let ans = sum * 2.0 / n as f64;

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

/// Extension of io module.
pub mod io_ext {
    use std::io::BufRead;

    pub struct Reader<R> {
        buf: String,
        inner: R,
    }

    impl<R> Reader<R> {
        #[inline]
        pub fn new(inner: R) -> Self {
            Reader { buf: String::new(), inner: inner }
        }

        #[inline]
        pub fn into_inner(self) -> R {
            self.inner
        }
    }

    impl<R: BufRead> Reader<R> {
        #[allow(deprecated)]
        #[inline]
        pub fn read_line(&mut self) -> &str {
            self.buf.clear();
            self.inner.read_line(&mut self.buf).unwrap_or_else(|e| panic!("{}", e));
            self.buf.trim_right()
        }
    }
}

/// Module supporting to parse strings.
pub mod parse {
    use std::str::FromStr;
    use std::borrow::Borrow;

    pub trait ParseNext: Iterator {
        fn parse_next<F: FromStr>(&mut self) -> F;
    }

    impl<'a, S: Borrow<str>, I: Iterator<Item=S>> ParseNext for I {
        fn parse_next<F: FromStr>(&mut self) -> F {
            if let Some(s) = self.next() {
                match s.borrow().parse() {
                    Ok(x) => x,
                    Err(_) => panic!("provided string cannot be parsed")
                }
            } else {
                panic!("iterator has no next element")
            }
        }
    }
}


Measured memory_bytes: 4352
n = int(input())
data = list(map(int, input().split(" ")))
data.insert(0,0)
data.append(0)
allans = 0
for i in range(0, len(data)-1):
    allans += abs(data[i+1]-data[i])
for i in range(1, len(data)-1):
    temp=abs(data[i]-data[i-1])
    temp2=abs(data[i+1]-data[i])
    temp3=abs(data[i+1]-data[i-1])
    print(allans-temp-temp2+temp3)

Measured memory_bytes: 14048
#include <iostream>
using namespace std;

long long fib(int k){
    if (k <= -2) return 0LL;
    if (k <= 0) return 1LL;
    return fib(k-1) + fib(k-2);
}

int main(){
    const long long MOD = 1e9+7;
    const int MAX_H = 100;
    const int MAX_W = 8;
    int H, W, K;
    long long dp[MAX_H + 10][MAX_W + 10];

    cin >> H >> W >> K;
    for (int i = 0; i <= H; ++i){
        for (int j = 1; j <= W; ++j){
            if (i == 0 && j == 1) dp[i][j] = 1LL;
            else dp[i][j] = 0LL;
        }
    }
    
    long long tmp;
    for (int i = 1; i <= H; ++i){
        for (int j = 1; j <= W; ++j){
            
            if (j - 1 >= 1){
                tmp = dp[i-1][j-1] * fib((j-2)-1) % MOD;
                tmp = tmp * fib(W-(j+1)) % MOD;
                dp[i][j] = (dp[i][j] + tmp) % MOD;
            }
            
            tmp = dp[i-1][j] * fib((j-1)-1) % MOD;
            tmp = tmp * fib(W-(j+1)) % MOD;
            dp[i][j] = (dp[i][j] + tmp) % MOD;
            
            if (j + 1 <= W){
                tmp = dp[i-1][j+1] * fib((j-1)-1) % MOD;
                tmp = tmp * fib(W-(j+2)) % MOD;
                dp[i][j] = (dp[i][j] + tmp) % MOD;
            }
        }
    }
    cout << dp[H][K] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N, A, B;
    cin >> N >> A >> B;

    ll ans = INF;
    if ((B - A) % 2LL == 0) ans = (B - A) / 2LL;
    else {
        chmin(ans, A + (B - A) / 2);
        ll tmp = A;
        A = N - B + 1;
        B = N - tmp + 1;
        chmin(ans, A + (B - A) / 2);
    }

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

Measured memory_bytes: 384
import java.util.Scanner;



public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		
		int[][] a = new int[r+1][c+1];
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	}
}

Measured memory_bytes: 41424
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define INF (1000000000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  long H, W;
  scanf("%ld %ld", &H, &W);

  // there are only four patterns of cutting
  // ||
  long diff1 = W % 3 == 0 ? 0 : H;
  // -
  // -
  long diff2 = H % 3 == 0 ? 0 : W;
  // |-
  long diff3 = INF;
  const long h3_1 = H / 2, h3_2 = H - h3_1;
  for (int j = 1; j <= W; j++) {
    const long S1 = H * j, S2 = h3_1 * (W - j), S3 = h3_2 * (W - j);
    diff3 = min(diff3, max(max(abs(S1 - S2), abs(S2 - S3)), abs(S3 - S1)));
  }
  // |
  // -
  long diff4 = INF;
  const long w4_1 = W / 2, w4_2 = W - w4_1;
  for (int i = 1; i <= H; i++) {
    const long S1 = i * W, S2 = (H - i) * w4_1, S3 = (H - i) * w4_2;
    diff4 = min(diff4, max(max(abs(S1 - S2), abs(S2 - S3)), abs(S3 - S1)));
  }

  // print ans
  printf("%ld\n", min(diff1, min(diff2, min(diff3, diff4))));
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{

int n,m,x;
cin>>n>>m>>x;
int s[111];
int k;
for(int i=0;i<m;i++)
    cin>>s[i];
for(int i=0;i<m;i++)
    if(s[i]>x) {k=i;
                break;} 
cout<<min(m-k,k);
   
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Freed freopen ("0in.txt","r",stdin);
#define Fout freopen ("0out.txt","w",stdout);
#define pi acos(-1.0)
#define ll long long
#define pb push_back
#define Mod 1000000007
#define limit 1000008
using namespace std;

void solve(int t)
{
    int a,k,i,j,n,sum=0,mx=0,ind,ct=1;
    cin >> n;
    if(n<600)
        cout <<8<<endl;
    else if(n<800)
        cout <<7<<endl;
    else if(n<1000)
        cout <<6<<endl;
    else if(n<1200)
        cout <<5<<endl;
    else if(n<1400)
        cout <<4<<endl;
    else if(n<1600)
        cout <<3<<endl;
    else if(n<1800)
        cout <<2<<endl;
    else
        cout <<1<<endl;
}
int  main()
{
//    Fast
//    Freed
//    Fout
    int t,tt=1;
   // cin >> tt;
    for(t=1; t<=tt; t++)
        solve(t);
  return 0;
}




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

int main()
{
   int n,l;
   cin>>n>>l;
   vector<string>v;
   for(int i=0;i<n;i++)
   {
      string s;
      cin>>s;
      v.push_back(s);
   }
   sort(v.begin(),v.end());
   for(int i=0;i<n;i++)
   {
        cout<<v[i];
   }
}


Measured memory_bytes: 256
n = gets.to_i

if n < 10 * 10
  puts n < 10 ? n : 9
elsif n < 10 * 10 * 10
  puts n - 99 + 9 
elsif n == 1000
  puts 909
elsif n < 10 * 10 * 10 *10
  puts 909
elsif n < 10 * 10 * 10 * 10 * 10
  puts n - 9999 + 909
elsif n == 100000
  puts 90909
end

Measured memory_bytes: 1788
#include <stdio.h>
void Swap(int x[],int r,int l){
	int temp;
	temp=x[r];
	x[r]=x[l];
	x[l]=temp;
}
void Qsort(int x[],int l,int r){
	int i,j,p;
	i=l;
	j=r;
	p=x[(l+r)/2];
	while(1){
		while(x[i]<p)i++;
		while(x[j]>p)j--;
		if(i>=j)break;
		Swap(x,i,j);
		i++;
		j--;
	}
	if(i-l>1)Qsort(x,l,i-1);
	if(r-j>1)Qsort(x,j+1,r);
}
int main(){
	int h[10],i;
	for(i=0; i<10; i++)scanf("%d",&h[i]);
	Qsort(h,0,9);
	//for(i=0; i<10; i++)printf("  %d\n",h[i]);
	printf("%d\n%d\n%d\n",h[9],h[8],h[7]);
	return 0;
}

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


// Useful container manipulation / traversal macros
#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(a,b)       ( (b).find(a) != (b).end())
#define tr(c,i)       for(auto i = (c).begin(); i != (c).end(); i++)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define fill(a,v)      memset(a, v, sizeof a)

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    int n;
    cin>>n;

    lli ans = 0;
    while(n--){
        lli x;
        cin>>x;

        ans = gcd(ans, x);
    }

    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
 int n,ban=1,pans,qans;
  cin>>n;
  vector<int> p(n),q(n),r(n);
  rep(i,n)cin>>p[i];
  rep(i,n)cin>>q[i];
  rep(i,n)r[i]=i+1;
  do{
   if(p==r) pans=ban;
   if(q==r) qans=ban;
    ban++;
  }while(next_permutation(r.begin(),r.end()));
  cout<<abs(pans-qans)<<endl;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b;
        string s;
        cin>>a>>b>>s;
        REP(i,s.size()){
            if((i==a&&s[i]!='-' )||(i!=a&&(s[i]<'0' || s[i]>'9' ))){cout<<"No\n";return 0;}
        }
        cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

class AbstractSort
{
    protected:
        int *array, length;
    
    public:
        AbstractSort() : array(nullptr), length(0)
        {

        }

        virtual void sort() = 0;

        void Setlength() {
            scanf("%d", &length);
        }

        void SetArray() {
            array = (int *)malloc(length * sizeof(int));
            for(int i=0; i<length; ++i) 
                scanf("%d", &array[i]);
        }

        void PrintArray() {
            for(int i=0; i<length; ++i) {
                if(i)
                    printf(" ");

                printf("%d", array[i]);
            }
            printf("\n");
        }

        void DeleteArray() {
            delete(array);
        }

        virtual ~AbstractSort() {

        }
};

class MergeSort : public AbstractSort
{
    private:
        int cnt;

    public:
        MergeSort() :cnt(0)
        {

        }

        void merge(int left, int mid, int right) {
            int i, j, n1, n2, *L, *R;
            n1 = mid - left;
            n2 = right - mid;

            L = (int *)malloc((n1 + 1) * sizeof(int));
            L[n1] = INT_MAX;
            for(int i=0; i<n1; ++i)
                L[i] = array[left+i];
            
            R = (int *)malloc((n2 + 1) * sizeof(int));
            R[n2] = INT_MAX;
            for(int i=0; i<n2; ++i)
                R[i] = array[mid+i];

            i = j = 0;
            for(int k=left; k<right; ++k) {
                ++cnt;
                if(L[i] <= R[j]) {
                    array[k] = L[i];
                    ++i;
                }

                else {
                    array[k] = R[j];
                    ++j;
                }
            }
        }

        void mergesort(int left, int right) {
            int mid;
            if(left+1 < right) {
                mid = (left + right) / 2;
                mergesort(left, mid);
                mergesort(mid, right);
                merge(left, mid, right);
            }
        }

        void sort() override {
            Setlength();
            SetArray();
            mergesort(0, length);
            PrintArray();
            printf("%d\n", cnt);
        }
};

int main() {
    AbstractSort *_Absort;
    _Absort = new MergeSort();
    _Absort->sort();
    delete(_Absort);
    return 0;
}


Measured memory_bytes: 65360
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local M, D = read.nn()
local function check(m, d)
    local d1 = d % 10
    local d2 = d // 10
    if d1>=2 and d2>=2 then
        return d1*d2 == m
    else
        return false
    end
end
local ans = 0
for m=1,M do
    for d=1,D do
        ans = ans + (check(m, d) and 1 or 0)
    end
end

print(ans)

Measured memory_bytes: 1132
n = int(input())

t_arr = [0]*(n+1)
x_arr = [0]*(n+1)
y_arr = [0]*(n+1)

for i in range(n+1):
    # 先頭はt0 x0 y0 なのでそのままにする
    if i == 0:continue
    pos = input().split()
    t_arr[i] = int(pos[0])
    x_arr[i] = int(pos[1])
    y_arr[i] = int(pos[2])

is_possible = True

for i in range(n):
    # 次の場所までに移動できる時間(回数)
    t = t_arr[i+1] - t_arr[i];
    
    # 次の場所までの距離
    x = abs(x_arr[i] - x_arr[i+1])
    y = abs(y_arr[i] - y_arr[i+1])
    d = x + y
    
    if d <= t and t%2 == d%2:
        continue
    else:
        is_possible = False
        break
    
print("Yes" if is_possible else "No")
    

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

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

  int ans = 0;

  if(n < 1000) {
    ans = 1000 - n;
    cout << ans << endl;
    return 0;
  } else if(n % 1000 == 0) {
    cout << ans << endl;
    return 0;
  } else {
    while(n > 1000) {
      n -= 1000;
      ans = 1000 - n;
    }
  }

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

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

using namespace std;

#define ll long long

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	ll times=1;
	// cin>>times;
	while(times--)
	{
		ll n,val;
		cin>>n>>val;
		if(n*500>=val)
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>a;
    if(a==7||a==5||a==3)Cout("YES");
    else Cout("NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;
bool ispal(string s){
	int n=s.size();
	if(s.length()%2==0){
		
					string a=s.substr(0,n/2);
					string b=s.substr(n/2,n);
					reverse(b.begin(),b.end());
					if(a==b) return 1;
					
				}
				else{
					string a=(s.substr(0,n/2));
					string b=s.substr(n/2+1,n) ;
					reverse(b.begin(),b.end());
					if(a==b) return 1;}
									
				return 0;

}
 
int main() {


				 fast
				string s;
				cin>>s;
				bool p=0;
				int n=s.size();
				//if(n==1) {cout<<"No"<<endl; return 0;}
				if(!ispal(s)){
					cout<<"No"<<endl;
					//cout<<1<<endl;
				}
				else{
					if(ispal(s.substr(0,(n-1)/2)) and (ispal(s.substr((n+2)/2,n)))) cout<<"Yes"<<endl;
					else cout<<"No"<<endl;
				 }
				// cout<<ispal("abba");
				// string s1="abba";
				// cout<<s1.substr(s1.size()/2,s1.size());
				// cout<<ispal(s.substr(0,(n-1)/2));
                return 0;
            }

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

int main() {
  int n;
  cin >> n;
  vector<pair<int,int>> blue(n),red(n);
  for (int i=0; i<n; i++) {
    cin >> red.at(i).second >> red.at(i).first;
  }
  for (int i=0; i<n; i++) {
    cin >> blue.at(i).first >> blue.at(i).second;
  }

  sort(red.begin(),red.end());
  sort(blue.begin(),blue.end());

  int rn = n, ans = 0;
  for (int bi=0; bi<n; bi++) {
    for (int ri=rn-1; ri>=0; ri--) {
      if (red.at(ri).second < blue.at(bi).first && red.at(ri).first < blue.at(bi).second) {
	ans++;
	red.erase(red.begin() + ri);
	rn--;
	break;
      }
    }
  }

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<typeinfo>
#include<cassert>
#include<functional>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;

int main(){

  int N,X;

  cin >> N >> X;

  int min = INT_MAX;

  int sum = 0;
  for(int i = 0;i < N;i++){
	  int a;
	  cin >> a;
	  sum += a;
	  if(a < min){
		  min = a;
	  }
  }

  cout << N + (X-sum)/min;


  return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int H, W, N;

int main()
{
    cin >> H;
    cin >> W;
    cin >> N;
    int a = max(H, W);
    if (N % a == 0)
    {
        cout << N / a << endl;
        return 0;
    }
    else
    {
        cout << N / a + 1 << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int m,n,mx[200+2],my[200+2],nx[1000+2],ny[1000+2];

bool find(int x,int y){
	for(int i=0;i<n;i++){
		if(nx[i]==x&&ny[i]==y)return true;
	}
	return false;
}

int main(){
while(1){
	scanf("%d",&m);
if(m==0)break;
	for(int i=0;i<m;i++)scanf("%d%d",&mx[i],&my[i]);
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d",&nx[i],&ny[i]);
	for(int i=0;i<n;i++){
		bool c=true;
		for(int j=1;j<m;j++){
			if(!find(nx[i]-mx[0]+mx[j],ny[i]-my[0]+my[j])){c=false; break;}
		}
		if(c){printf("%d %d\n",nx[i]-mx[0],ny[i]-my[0]); break;}
	}
}
}

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

const int N=1e+5+5;

int n;
long long int h[N],dp[N];
long long int solve(int i)
{
    if(i>=n)
        return 0;
    if(i==n-1)
        return abs(h[n]-h[i]);
    if(dp[i]==-1)
    {
        dp[i]=min(abs(h[i+1]-h[i])+solve(i+1),abs(h[i+2]-h[i])+solve(i+2));
    }
    return dp[i];
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
        dp[i]=-1;
    }
    cout<<solve(1);
}

Measured memory_bytes: 3328
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int count = 0;
        for(int i = 0; i <= a; i++){
            for(int j = 0; j <= b; j++){
                for(int k = 0; k <= c; k++){
                    if(x == 500*i+100*j+50*k){
                        count++;
                    }
                }
            }
        }
        System.out.print(count);
    }
}

Measured memory_bytes: 21588
#include<stdio.h>
#define N 100
#define White 0
#define Gray 1
#define Black 2

int n,A[N][N];
int color[N],b[N],c[N],d;

void Visit(int u){
    int e;
    color[u]=Gray;
    b[u]=++d;
    for(e=0;e<n;e++){
        if(A[u][e]==0)continue;
        if(color[e]==White){
            Visit(e);
        }
    }
    color[u]=Black;
    c[u]=++d;
}

void depth(){
    int u;
    for(u=0;u<n;u++)color[u]=White;
    d=0;

    for(u=0;u<n;u++){
        if(color[u]==White)Visit(u);
}
for(u=0;u<n;u++){
printf("%d %d %d\n",u+1,b[u],c[u]);

}
}


int main(){
int u,v,w,i,j;

scanf("%d",&n);
for(i=0;i<n;i++){
    for(j=0;j<w;j++)A[i][j]=0;
}

for(i=0;i<n;i++){
 scanf("%d %d",&u,&w);
 u--; 
 for(j=0;j<w;j++){
     scanf("%d",&v);
     v--;
     A[u][v]=1;
 }  
}
depth();

return 0;


}


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

int main() {
  int X, Y, Z, K;
  std::cin >> X >> Y >> Z >> K;

  std::vector<long long> A(X);
  std::vector<long long> B(Y);
  std::vector<long long> C(Z);

  for (int i=0; i<X; i++) std::cin >> A[i];
  for (int i=0; i<Y; i++) std::cin >> B[i];
  for (int i=0; i<Z; i++) std::cin >> C[i];

  std::vector<long long> E(X*Y);

  for (int i=0; i<X; i++)
    for (int j=0; j<Y; j++)
      E[i*Y+j] = A[i] + B[j];

  std::sort(E.begin(), E.end(), std::greater<long long>());
  E.resize(std::min(K, X*Y));

  std::vector<long long> F(E.size()*Z);

  for (int i=0; i<E.size(); i++)
    for (int j=0; j<Z; j++)
      F[i*Z+j] = E[i] + C[j];

  std::sort(F.begin(), F.end(), std::greater<long long>());

  for (int i=0; i<K; i++)
    std::cout << F[i] << '\n';

  return 0;
}


Measured memory_bytes: 31616
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
#define INF 10000000

typedef struct{
  int r;
  int c;
}Matrix;

int scalar(int *);
int min(int,int);

int p[MAX];
int m[MAX][MAX];
int n;

int main(){
  int i;
  
  scanf("%d",&n);
  
  for(i=0 ; i<n ;i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }

  printf("%d\n",scalar(p));
  
  return 0;
}

int scalar(int *p){
  int i,j,k,l,q;
  for(i=1 ; i<=n ; i++){
    m[i][i]=0;
  }

  for(l=2 ; l<=n ; l++){
    for(i=1 ; i<=n-l+1 ; i++){
      j=i+l-1;
      m[i][j]=INF;
      for(k=i ; k<j ; k++){
	q = m[i][k] + m[k+1][j] + p[i-1]* p[k] * p[j];
	m[i][j]=min(m[i][j],q);
      }     
    }
  }
  return m[1][j];
}

int min(int m,int q){
  if(m<q)return m;
  else return q;
}

Measured memory_bytes: 636
n = int(input())
adj = [[float('inf')]*n for _ in range(n)]
for i in range(n):
    a = list(map(int, input().split()))
    for j,k in zip(a[2::2], a[3::2]):
        adj[i][j] = k
color = [0]*n
d = [float('inf')]*n
d[0] = 0

while 1:
    mincost = float('inf')
    for i in range(n):
        if color[i] != 1 and d[i] < mincost:
            mincost = d[i]
            u = i
    if mincost == float('inf'):
        break
        
    color[u] = 1
    
    for i in range(n):
        if color[i] != 1 and adj[u][i] != float('inf'):
            if d[u]+adj[u][i] < d[i]:
                d[i] = d[u] + adj[u][i]
                
for i in range(n):
    print(i, d[i])
                


Measured memory_bytes: 5824