akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main(){
  int n; cin >> n;
  vector<vector<int>> f(n, vector<int>(10));
  vector<vector<int>> p(n, vector<int>(11));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 10; ++j){
      cin >> f[i][j];
    }
  }
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 11; ++j){
      cin >> p[i][j];
    }
  }
  long long profit = -INF;
  long long temp;
  int cnt;
  for(int bit = 1; bit < (1 << 10); ++bit){
    temp = 0;
    for(int i = 0; i < n; ++i){
      cnt = 0;
      for(int j = 0; j < 10; ++j){
        if(f[i][j] && bit & (1 << j)) cnt++;
      }
      temp += p[i][cnt];
    }
    profit = max(profit, temp);
  }
  cout << profit << endl;
}

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

int d,score,i,j,k,pscore,cscore,id;
int c[26],s[365][26],last[26],t[365];
int day1,day2,v1,v2,csize,f,check[4];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> d;
  for(i=0;i<26;i++) {
    cin >> c[i];
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      cin >> s[i][j];
    }
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      int tscore=s[i][j];
      for(int k=0;k<26;k++) {
        if(k==j) continue;
        tscore-=c[k]*(i+1-last[k]);
      }
      if(j==0) score=tscore;
      else if(tscore>score) {
        score=tscore;
        t[i]=j;
      }
    }
    last[t[i]]=i+1;
  }
  int cnt=800000;
  while(cnt--) {
    day1=rand()%d;
    v1=rand()%26;
    if(t[day1]==v1) continue;
    check[0]=t[day1];
    check[1]=v1;
    csize=2;
    f=0;
    if(cnt%10==0) {
      day2=rand()%d;
      v2=rand()%26;
      if(day1!=day2&&t[day2]!=v2) {
        f=1;
        if(t[day1]!=t[day2]&&v1!=t[day2]) {
          check[csize++]=t[day2];
        }
        if(t[day1]!=v2&&v1!=v2) {
          check[csize++]=v2;
        }
      }
    }
    pscore=0;
    cscore=0;
    for(i=0;i<csize;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      pscore+=s[i][t[i]];
      last[t[i]]=i+1;
      for(j=0;j<csize;j++) {
        int id=check[j];
        pscore-=c[id]*(i+1-last[id]);
      }
    }
    for(i=0;i<csize;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      if(day1==i) {
        cscore+=s[i][v1];
        last[v1]=i+1;
      }
      else if(f&&day2==i) {
        cscore+=s[i][v2];
        last[v2]=i+1;
      }
      else {
        cscore+=s[i][t[i]];
        last[t[i]]=i+1;
      }
      for(j=0;j<csize;j++) {
        id=check[j];
        cscore-=c[id]*(i+1-last[id]);
      }
    }
    if(pscore<cscore) {
      t[day1]=v1;
      t[day2]=v2;
    }
  }
  for(i=0;i<d;i++) {
    printf("%d\n",t[i]+1);
  }
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N), A(M), B(M);
    for (int i = 0; i < N; i++) cin >> H.at(i);
    for (int i = 0; i < M; i++) cin >> A.at(i) >> B.at(i);
    vector<bool> good(N, true);
    int ans = 0;

    for (int i = 0; i < M; i++) {
        if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
            good.at(A.at(i) - 1) = false;
            good.at(B.at(i) - 1) = false;
        } else if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
            good.at(B.at(i) - 1) = false;
        } else {
            good.at(A.at(i) - 1) = false;
        }
    }
    for (int i = 0; i < N; i++) {
        if (good.at(i) == true) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4552
#include <stdio.h>

int main()
{
	char Str[16];

	#ifdef _WIN32
		freopen("input.txt", "r", stdin);
	#endif

	scanf("%s", Str);


#ifdef _WIN32
	printf("input : %s\n", Str);
#endif

	if ((Str[2] == Str[3]) && (Str[4] == Str[5]))
		printf("Yes");
	else
		printf("No");
}







Measured memory_bytes: 128
#include <stdio.h>

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

int main(void){
	int i,j,SET;
	int T,n;
	int x,y,d,nx,ny,nnx,nny;
	int cnt,firstFlg;
	char s[102][102];

	scanf("%d",&T);

	for(SET=1;SET<=T;SET++){
		if(SET != 1) putchar('\n');

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

		x = 0;
		y = n-1;
		d = 0;

		while(1){
			firstFlg = 1;
			cnt = 0;

			while(1){
				s[y][x] = '#';
				cnt++;

				nx = x + dx[d];
				ny = y + dy[d];
				if(nx < 0 || n <= nx || ny < 0 || n <= ny){
					d = (d + 1) % 4;
					break;
				}

				nnx = x + 2 * dx[d];
				nny = y + 2 * dy[d];
				if(0 <= nnx && nnx < n && 0 <= nny && nny < n && s[nny][nnx] == '#'){
					d = (d + 1) % 4;
					break;
				}

				x = nx;
				y = ny;
				firstFlg = 0;
			}
			if(firstFlg || cnt <= 2) break;
		}

		if(n == 2) s[0][1] = '#';

		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				putchar(s[i][j]);
			}
			putchar('\n');
		}
	}

	return 0;
}

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

int main(){
    ll ans=0;
    int n,i;
    string s;
    cin>>n>>s;
    vector<int> r,b,g;
    rep(i,0,n)
        if(s[i]=='R') r.push_back(i);
        else if(s[i]=='G') g.push_back(i);
        else b.push_back(i);
    ans=(r.size())*(g.size())*(b.size());
    for(i=0;i<r.size();i++){
        int t=min(r[i],n-r[i]-1);
        for(int k=1;k<=t;k++){
            if(binary_search(b.begin(),b.end(),r[i]+k)&&binary_search(g.begin(),g.end(),r[i]-k)) ans--;
            else if(binary_search(b.begin(),b.end(),r[i]-k)&&binary_search(g.begin(),g.end(),r[i]+k)) ans--;
        }
    }
    
    for(i=0;i<g.size();i++){
        int t=min(g[i],n-g[i]-1);
        for(int k=1;k<=t;k++){
            if(binary_search(r.begin(),r.end(),g[i]+k)&&binary_search(b.begin(),b.end(),g[i]-k)) ans--;
            else if(binary_search(r.begin(),r.end(),g[i]-k)&&binary_search(b.begin(),b.end(),g[i]+k)) ans--;
        }
    }
    
    for(i=0;i<b.size();i++){
        int t=min(b[i],n-b[i]-1);
        for(int k=1;k<=t;k++){
            if(binary_search(r.begin(),r.end(),b[i]+k)&&binary_search(g.begin(),g.end(),b[i]-k)) ans--;
            else if(binary_search(r.begin(),r.end(),b[i]-k)&&binary_search(g.begin(),g.end(),b[i]+k)) ans--;
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main(){
    int n,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int j=i,keta=0;
        while(j!=0){
            j/=10;
            keta++;
        }
        if(keta%2==1){
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;
int L[200001];
int R[200001];

int main(){
   int N,K,C;
   cin >> N>>K>>C;
   string S;
   cin >> S;
   memset(L,-1, sizeof(L));
   memset(R,INT_MAX/2, sizeof(R));
   int cur=0;
   for(int i = 0 ; cur<K&&i < N; i++){
      if(S[i]=='x') continue;
      else{
         L[cur]=i;
         cur++;
         i+=C;
      }
   }
   cur=K-1;
   for(int i = N-1 ; cur>=0&&i >=0; i--){
      if(S[i]=='x') continue;
      else{
         R[cur]=i;
         cur--;
         i-=C;
      }
   }
   for(int i=0; i<K; i++){
      if(L[i]==R[i]){
         cout << L[i]+1<<endl;
      }
   }
   return 0;
}


Measured memory_bytes: 3332
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main(){
    int N;
    int a[3000]={};
    cin >> N;
    int sum = 0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        sum += a[i];
    }

    cout << sum -N << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

struct Edge
{
	int kindOfTask;
	int runNum;
};


void solve()
{
	int N, M;
	cin >> N >> M;
	vector<Edge> a[50001];
	int s, t, e;
	while (cin >> s >> t >> e, s || t || e)
	{
		Edge edge;
		edge.kindOfTask = --t;
		edge.runNum = e;
		a[--s].push_back(edge);
	}
	int L;
	cin >> L;
	for (int i = 0; i < L; ++i)
	{
		vector<int> c(M);
		for (int j = 0; j < M; ++j)
		{
			cin >> c[j];
		}
		bool isFirst = true;
		for (int j = 0; j < N; ++j)
		{
			int salary = 0;
			for (int k = 0; k < a[j].size(); ++k)
			{
				Edge edge = a[j][k];
				salary += edge.runNum * c[edge.kindOfTask];
			}
			if (!isFirst)
			{
				cout << " ";
			}
			isFirst = false;
			cout << salary;
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
using LL = long long;
LL lv[51],pate[51];
LL calc(int n,LL x) {
    if (x==0) return 0;
    if (x==lv[n]) return pate[n];

    LL res = 0;
    if (x>=1+lv[n-1]+1) {
        res += 1 + calc(n-1, x-1-lv[n-1]-1);
    }
    if (x>=1) {
        res += calc(n-1, min(lv[n-1], x-1));
    }
    return res;
}
int main()
{
    lv[0] = 1;
    REP(i,1,50) lv[i] = 2*lv[i-1] + 3;
    pate[0] = 1;
    REP(i,1,50) pate[i] = 2*pate[i-1] + 1;

    int n;
    LL x;
    while (~scanf("%d %lld", &n, &x)) {
        printf("%lld\n", calc(n,x));
    }
    return 0;
}


Measured memory_bytes: 256
int Primejudgment(int m[], int loop);

int main()
{
	int n,r[10000],i,j=0,k=0,ans,count=0;

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

	ans= Primejudgment(r,j);
	if (ans == 1) count++;
	j++;
	ans = 0;

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

int Primejudgment(int m[],int loop)
{
	int i;
	if (m[loop] < 2)
		return 0;
	else if (m[loop] == 2) {
	
		return 1;
	}

	if (m[loop] % 2 == 0)
		return 0;

	for (i = 3; i <= m[loop] / i; i += 2)
		if (m[loop] % i == 0)
			return 0;

	return 1;
}

Measured memory_bytes: 1832
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct pint
{   
	int a;
	int i;

};
vector< vector<int> > dp;
int rec(int i,vector<pint>& a,int l,int r)
{
     if(i==a.size())
     	 return 0;
     	if(dp[i][r]!=-1)
     		return dp[i][r];
     int ans=0;
     ans=a[i].a*abs(l-a[i].i)+rec(i+1,a,l+1,r);      
     ans=max(ans,a[i].a*abs(r-a[i].i)+rec(i+1,a,l,r-1));
     return dp[i][r]=ans;
}
bool com(pint a,pint b)
{
	 return a.a>=b.a;
}
void solve()
{
   long long n;
   cin>>n;
   vector<pint> v(n);
   for(int i=0;i<n;i++)
   {
      cin>>v[i].a;
      v[i].i=i;
   }

   dp.clear();
   dp.resize(n,vector<int>(n,-1));
   sort(v.begin(),v.end(),com);
   // for(auto x:v)
   // {
   // 	 cout<<x.a<<" "<<x.i<<"\n";
   // }
   cout<<rec(0,v,0,n-1);
}
main()
{
int t;
t=1;
while(t--)
{
solve();

}
}


Measured memory_bytes: 34680
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);

	int s = min(B,D) - max(A,C);
	if(s<0) s = 0;
	printf("%d\n",s);

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[110000];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<b;i++)scanf("%d",d+i);
	for(int i=0;i<b;i++){
		d[i]-=c;
		if(d[i]<0)d[i]+=a;
	}
	d[b++]=0;d[b++]=a;
	std::sort(d,d+b);
	int ret=999999999;
	for(int i=1;i<b;i++){
		ret=min(ret,100*(a-(d[i]-d[i-1])+min(d[i-1],a-d[i])));
	}printf("%d\n",ret);
}


Measured memory_bytes: 2808
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define MOD 1e9+7
using namespace std;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  if (a == 0) {
    if (b == 0) cout << 1 << endl;
    else cout << b / x  + 1 << endl;
  }
  else cout << b / x - (a - 1) / x << endl;
}

Measured memory_bytes: 256
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

A, B, C, D = iInM()

if A + B > C + D:
    print('Left')
elif A + B == C + D:
    print('Balanced')
else:
    print('Right')

Measured memory_bytes: 62332
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

signed main(){
	int N, D, H, i;
	scanf("%lld%lld%lld", &N, &H, &D);
	int fact = 1, fact_sum = 0;
	for(i = 1; i <= N; i++){
		fact = MOD(fact * i);
		fact_sum = MOD(fact_sum + fact);
	}
	vector<int> dp(H + 1, 0), s(H + 1, 0);
	dp[1] = 1;
	s[1] = 1;
	for(i = 2; i <= H; i++){
		dp[i] = MOD(fact_sum * (s[i - 1] - s[max(0ll, i - D - 1)]));
		if(i <= D){
			dp[i] = MOD(dp[i] + 1);
		}
		s[i] = MOD(s[i - 1] + dp[i]);
	}
/*	for(i = 0; i <= H; i++){
		printf("dp[%lld] = %lld\n", i, dp[i]);
	}
*/	printf("%lld\n", MOD(fact * dp[H]));
	return 0;
}

Measured memory_bytes: 15872
import heapq

n,m = map(int,input().split())

a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b, c = (int(x) for x in input().split())
    bc.append([b, c])
bc = sorted(bc, key=lambda x: -x[1])

heapq.heapify(a)

for i in range(m):
    count = 0
    if bc[i][1] < a[0]:
        break
    while a[0] < bc[i][1] and count < bc[i][0]:
        heapq.heappop(a)
        heapq.heappush(a,bc[i][1])
        count += 1
print(sum(a))

Measured memory_bytes: 100776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, int> DIP;
typedef pair<DIP, P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll a, b, q, s[MAX_N], t[MAX_N];
    cin >> a >> b >> q;
    REP(i,a) cin >> s[i+1];
    REP(i,b) cin >> t[i+1];
    s[0] = -LLINF/4;
    s[a+1] = LLINF/4;
    t[0] = -LLINF/4;
    t[b+1] = LLINF/4;
    REP(i,q){
        ll x, ids, idt, ls, rs, lt, rt, ans = LLINF/4;
        cin >> x;
        ids = lower_bound(s,s+a+1,x)-s;
        idt = lower_bound(t,t+b+1,x)-t;
        ls = s[ids-1];
        rs = s[ids];
        lt = t[idt-1];
        rt = t[idt];
        ans = min(ans, abs(rs-x)+abs(rt-rs));
        ans = min(ans, abs(rt-x)+abs(rt-rs));
        ans = min(ans, abs(ls-x)+abs(lt-ls));
        ans = min(ans, abs(lt-x)+abs(lt-ls));
        ans = min(ans, abs(rs-x)+abs(lt-rs));
        ans = min(ans, abs(lt-x)+abs(lt-rs));
        ans = min(ans, abs(rt-x)+abs(ls-rt));
        ans = min(ans, abs(ls-x)+abs(ls-rt));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3968
#include <stdio.h>

#define MAX_NUM 100000
int main()
{
	int N, M;
	int gatearray[MAX_NUM][2];
	int i, j;
	int maxnum = MAX_NUM;
	int minnum = 0;
	scanf("%d %d", &N, &M);
	for (i = 0; i < M; i++) {
		scanf("%d %d", &gatearray[i][0], &gatearray[i][1]);
	}
	for (i = 0; i < M; i++) {
		if (maxnum > gatearray[i][1]) {
			maxnum = gatearray[i][1];
		}
		if (minnum < gatearray[i][0]) {
			minnum = gatearray[i][0];
		}
	}
	if ((maxnum - minnum) < 0) {
		printf("0\n");
	}
	else {
		printf("%d\n", maxnum - minnum + 1);
	}
	return 0;
}

Measured memory_bytes: 896
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;

public class Main {

    static final long DIV = 1000000007;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int ans = n / Math.max(h, w);
        if(n % Math.max(h, w) != 0) ans++;
        System.out.println(ans);
    }



    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}



Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

using ps = pair<string, int>;

int main() {
  int n;
  cin >> n;
  
  map<string, int> mp;
  vector<ps> tt;
  rep(i, n) {
    string s;
    int t;
    cin >> s >> t;
    mp[s] = 1;
    tt.push_back(make_pair(s, t));
  }

  for (auto&& itr : mp) {
    vector<pair<int,int>> eva;
    for (int i = 0; i < n; ++i) {
      if (tt[i].first == itr.first) {
        // debug(tt[i].second);
        eva.push_back(make_pair(tt[i].second, i+1));
      }
    }
    sorti(eva);
    for (int i = eva.size() - 1; i >= 0; --i) {
      
      cout << eva[i].second << endl;
    }
  }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	input := nextLine()
	inputFields := strings.Fields(input)
	n, _ := strconv.ParseInt(inputFields[0], 10, 64)
	k, _ := strconv.ParseInt(inputFields[1], 10, 64)
	fmt.Println(n - k + 1)
}


Measured memory_bytes: 640
import sys
import numpy as np
from collections import Counter

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]


from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = INT()
S = [[s for s in input().strip()] for _ in range(N)]

words = []
for s in S:
	s.sort()
	words.append(s)

words.sort()

ans = []
tmp = ''
num = -1
for w in words:
	#print(tmp , w, num)
	if tmp == w:
		#print('same')
		ans[num] += 1
		#print(ans)
	else:
		#print('different')
		tmp = w
		num+=1
		ans.append(1)
		#print(ans)
		
#print(ans)

count = 0
for a in ans:
	if a != 1: count += cmb(a, 2)

print(count)

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, ans = 0;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    bool ok = false, start;
    while(!ok) {
        ok = true;
        start = false;
        rep(i, n) {
            if(h[i] == 0) {
                if(start) {
                    ans++;
                    start = false;
                }
            }
            else {
                start = true;
                h[i]--;
                if(h[i] != 0) ok = false;
                if(i == n-1) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,j,n,m) for(int i=j;i<n;i+=m)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=(ll)1e18;

ll n;
ll d[MAXn],a[MAXn];
ll cal(ll b){
  ll ret=0;
  REP(i,n) ret+=abs(a[i]-(b+i+1));
  return ret;
}
int main(){
  IOS();
  cin>>n;
  REP(i,n){
    cin>>a[i];
    d[i] = a[i]-i-1;
  }
  sort(d,d+n);
  pary(d,d+n);
  ll tp = n/2;
  debug(tp);
  ll ans = min(cal(d[tp]),cal(d[tp-1]));
  cout<<ans<<endl;
}


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

int main(){
    ll n, k, s; cin >> n >> k >> s;
    int  i = 0;
    for(i =0; i < k; i++){
        cout << s << " ";
    }
    if(s == 1000000000){s -= 3;}
    for(; i < n ; i++){
        cout << s+1 << " ";
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int a, b; cin >> a >> b;

    cout << max({a + b, a - b, a * b}) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] value = new int[w];
		for(int i = 0; i< w; i++) {
			value[i] = i + 1;
		}

		for(int i=0; i<n; i++) {
			String str= sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) -1;
			int b = Integer.parseInt(ab[1]) -1;
			int tmp = value[a];
			value[a] = value[b];
			value[b] = tmp;
		}

		for(int i=0; i<w; i++) {
			System.out.println(value[i]);
		}
		sc.close();
	}
}

Measured memory_bytes: 17200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 1007;
const int MOD = 1000000007;

void solve() {
    long long n;
    string res;
    cin >> n;
    while (n--) {
        res = char(n%26+'a') + res;
        n /= 26;
    }
    cout << res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

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

int main() {
  int h,n;
  cin >> h>>n;
  vector<int>g(n);
  for(int i=0;i<n;i++){
    cin >>g.at(i);
  }
  int a=0;
  for(int i=0;i<n;i++){
    a+=g.at(i);
  }
  if(a>=h){
    cout << "Yes"<<endl;
  }
  else{
    cout << "No"<<endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main (){
    int n, m;
    cin >> n >> m;
    double count = 0;
    double sum = 0;
    vector<int> v;
    for (int i = 0; i < n; i++){
        int k;
        cin >> k;
        v.push_back(k);
        sum += k;
    }
    float x = (sum/(4*m));
    for (int i = 0; i < n; i++){
        if (v[i] >= x){
            count ++;
        }
    }
    if (count >= m){
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }


}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    vector<bool> table(1e5, false);
    int cnt = 0;
    REP(i, N) {
        int a;
        std::cin >> a;
        if(table[a - 1]) {
            cnt++;
        }
        else {
            table[a - 1] = true;
        }
    }
    std::cout << (N - ((cnt % 2 == 0) ? cnt : cnt + 1)) << std::endl;

    return 0;
}


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

#define ll long long

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a, b, t;
	cin >> a >> b >> t;
	cout << b * (t / a) << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;

//125
int main() {
	ll N;
	scanf("%lld", &N);

	ll abs_min = 100000000000;
	ll sum = 0;
	ll count_negative = 0;
	ll count_zero = 0;
	for (ll i = 0; i < N; i++) {
		ll num;
		scanf("%lld", &num);
		abs_min = std::min(std::abs(num), abs_min);

		if (num < 0) {
			count_negative++;
		}
		else if (num == 0) {
			count_zero++;
		}

		sum += std::abs(num);
	}

	ll result = 0;
	if (count_zero > 0) {
		result = sum;
	}
	else if (count_negative % 2 == 0) {
		result = sum;
	}
	else {
		result = sum - abs_min * 2;
	}

	printf("%lld\n", result);

	return 0;
}

//124
/*
int main() {
	ll N, K;
	scanf("%lld %lld", &N, &K);

	char s[100010];
	scanf("%s", &s);

	vector<ll> state_length; //index0,2,4,...�͋t����

	int prev_state = 1; //�ŏ��������Ƃ�����index0��0������悤��
	ll length = 0;
	for (ll i = 0; i < N; i++) {
		char c = s[i];
		if (c == '0') {
			//��
			if (prev_state == 0) {
				length++;
			}
			else {
				state_length.push_back(length);
				length = 1;
				prev_state = 0;
			}
		}
		else {
			//�t
			if (prev_state == 1) {
				length++;
			}
			else {
				state_length.push_back(length);
				length = 1;
				prev_state = 1;
			}
		}
	}
	state_length.push_back(length);
	if (prev_state == 1) {
		state_length.push_back(0); //�Ō�͐��ŏI���悤��
	}
	else {
		state_length.push_back(0);
		state_length.push_back(0); //�Ō�͐��ŏI���悤��
	}

	ll state_length_size = (ll)state_length.size();
	ll window = std::min(state_length_size, 1 + K * 2);
	ll start = 0;
	ll end = window;
	ll sum = 0;
	for (int i = start; i < end; i++) {
		sum += state_length[i];
	}
	ll max = sum;

	while (true) {
		start += 2;
		end += 2;
		if (end >= state_length_size) {
			break;
		}

		sum -= state_length[start - 2];
		sum -= state_length[start - 1];
		sum += state_length[end - 2];
		sum += state_length[end - 1];

		if (sum > max) {
			max = sum;
		}
	}

	printf("%lld\n", max);

	return 0;
}
*/


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 1000000007;

signed main() {
	int x, y;
	cin >> x >> y;
	int sum = y / x;
	int iwa = 1;
	int ans = 0;
	while (iwa <= sum) {
		iwa *= 2;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>

using namespace std;


int main() {

    int H, W;
    int h, w;
    cin >> H >> W >> h >> w;

    cout << (H - h) * (W - w) << "\n";

    return 0;
}

Measured memory_bytes: 256
// 問題の URL を書いておく
// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = int64_t;
using ull = uint64_t;

bool isValid(ull n, ull v)
{
    if(v - 1 == 0)
    {
        return false;
    }
    auto m = v - 1;
    return n / m == n % m;
}

int main(int, const char**)
{
    ull n;
    cin >> n;
    ull ans = 0;
    for(ull i = 1; i * i <= n; ++i)
    {
        if(n % i == 0)
        {
            if(isValid(n, i))
            {
                ans += (i - 1);
            }
            if(isValid(n, n / i))
            {
                ans += (n / i - 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	var S string
	fmt.Scanf("%s", &S)

	for i, char := range S {
		if i == K-1 {
			fmt.Print(string(char + 0x20))

		} else {
			fmt.Print(string(char))
		}
	}
	fmt.Println()

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int cnt[4];
    rep(i, 4) cnt[i] = 0;
    for(int i=0; i<3; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        cnt[a]++;
        cnt[b]++;
    }
    sort(cnt, cnt+4);
    if(cnt[0]==1 && cnt[1]==1 && cnt[2]==2 && cnt[3]==2) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	vector<int> b;
	b = a;
	sort(b.begin(), b.end());
	
	int med1 = b[n / 2 - 1];
	int med2 = b[n / 2];
	
	for(int i = 0; i < n; ++i) {
		if( a[i] <= med1 ) cout << med2 << endl;
		else cout << med1 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    edge(lint t, lint c) : to(t), cost(c) {
    }
};

// dijkstra
// depend:edge
vector<long long int> dijkstra(vector<vector<edge>>& g, int start) {
    using lint = long long int;
    vector<lint> res(g.size(), LLONG_MAX);
    res[start] = 0;
    // first:距離、second:行き先
    priority_queue<pair<lint, lint>, vector<pair<lint, lint>>,
                   greater<pair<lint, lint>>>
        pq;
    pq.push({0, start});
    while (!pq.empty()) {
        lint dist = pq.top().first, now = pq.top().second;
        pq.pop();
        if (res[now] < dist) continue;
        for (int i = 0; i < (int)g[now].size(); i++) {
            edge e = g[now][i];
            if (res[e.to] > res[now] + e.cost) {
                res[e.to] = res[now] + e.cost;
                pq.push(make_pair(res[e.to], e.to));
            }
        }
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    // key[i]の第j-bitが1==i番目の鍵はj番目の宝箱を開けられる
    vector<int> key(m, 0);
    for (int i = 0; i < m; i++) {
        int b;
        cin >> a[i] >> b;
        //キーの作成
        for (int j = 0; j < b; j++) {
            int c;
            cin >> c;
            key[i] += 1 << (c - 1);
        }
    }
    //グラフの作成
    vector<vector<edge>> g((1 << n));
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < m; j++) {
            g[i].push_back(edge(i | key[j], a[j]));
        }
    }
    vector<lint> cost = dijkstra(g, 0);
    if (cost[(1 << n) - 1] == LLONG_MAX) {
        cout << -1 << endl;
    } else {
        cout << cost[(1 << n) - 1] << endl;
    }
}

Measured memory_bytes: 66176
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

LL N,M,a,b,c,d;
string s;

int main(){
    cin>>N>>a>>b;
    if(abs(N-a)<abs(N-b)){
        cout<<"A"<<endl;
    }else{
        cout<<"B"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
   int n;

   cin >> n;

   long long a[n+5];
   a[0] = 2;
   a[1] = 1;

   for(int i=2;i<=n;i++){
       a[i] = a[i-1] + a[i-2];
   }
   cout << a[n] << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a[N];
  
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N, greater<int>()); 
  int score1 = 0; //Aliceのスコア
  int score2 = 0; //Bobのスコア
  for(int i = 0;i < N; i += 2){
    score1 += a[i];
  }
  for(int i = 1;i < N; i += 2){
    score2 += a[i];
  }
  cout << score1 - score2 << endl;

}



Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(a: i64, b: i64, c: i64, d: i64);

    // x以下でcでもdでも割り切れない数の個数
    // -> 全体 - (cで割り切れる個数 + dで割り切れる個数 - cdの最小公倍数で割り切れる個数)
    fn f(x: i64, c: i64, d: i64) -> i64 {
        let g = gcd(c, d);
        let l = c / g * d;
        // x以下のうちaで割り切れる数の個数 -> x / a
        x - (x / c + x / d - x / l)
    }

    // [l, r]区間の総和 = lまでの総和 - (r-1)までの総和
    let ans = f(b, c, d) - f(a - 1, c, d);
    println!("{}", ans);
}

pub fn gcd<T>(x: T, y: T) -> T
where
    T: PartialEq + Copy + std::ops::Rem<Output = T> + std::convert::From<u8>,
{
    if y == T::from(0u8) {
        x
    } else {
        gcd(y, x % y)
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
const int N = 5000*6+5;
string all[N];
int main()
{
   string s;
   int k;
   while(cin >> s)
   {
       cin >> k;
       int len = s.length();
       int cnt = 0;
       for(int i = 0; i < len;i++)
       {
           string now = "";
           for(int j = i; j < i + k && j < len; j++)
           {
               now += s[j];
               all[cnt++] = now;
           }
       }
       sort(all,all+cnt);
       cnt = unique(all,all+cnt) - all;
       cout << all[k-1] << endl;
   }
}


Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split()))
M = int(input())
Q = list(map(int,input().split()))
SL = []
for bit in range(1<<N):
    SUM = 0
    for i in range(N):
        if bit & (1<<i):
            SUM += A[i]
    SL.append(SUM)
for q in Q:
    if q in SL:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 43084
a = int(input())

result = False
h1 = -1;
h2 = -1;
while a > 0:
    result = result or (h1 == h2 and h1 == a%10)
    h2 = h1
    h1 = a%10


    a = a//10;

if result:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main(){
  int N, A, B, C;
  scanf("%d", &N);
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  std::queue<char > queue;
  bool result = true;
  std::vector<std::string > s(N);
  std::vector<std::string > next(N);
  next[N-1]="AB";
  for (int i=0; i<N; i++){
    std::cin >> s[i];
  }
  std::string cand = s[N-1];
  for (int i=N-2; i>0; i--){
    next[i]=cand;
    if (s[i-1]!=s[i]) cand=s[i];
  }
  next[0]=cand;

  /*for (int i=0; i<N; i++){
    std::cout << i << ": " << next[i] << std::endl;
    }*/

  for (int i=0; i<N; i++){
    if (s[i]=="AB"){
      if (A==B && next[i]=="BC"){
        B++;
        A--;
        queue.push('B');
      } else if (A==B && next[i]=="AC"){
        A++;
        B--;
        queue.push('A');
      } else if(A>B) {
        A--;
        B++;
        queue.push('B');
      } else {
        A++;
        B--;
        queue.push('A');
      }
      if (A<0 || B<0){
        result = false;
      }
    } else if (s[i]=="BC"){
      if (B==C && next[i]=="AC"){
        C++;
        B--;
        queue.push('C');
      } else if (B==C && next[i]=="AB"){
        B++;
        C--;
        queue.push('B');
      } else if(B>C) {
        B--;
        C++;
        queue.push('C');
      } else {
        B++;
        C--;
        queue.push('B');
      }
      if (B<0 || C<0){
        result = false;
      }
    } else {
      if (A==C && next[i]=="AB"){
        A++;
        C--;
        queue.push('A');
      } else if (A==C && next[i]=="BC"){
        C++;
        A--;
        queue.push('C');
      } else if(C>A) {
        C--;
        A++;
        queue.push('A');
      } else {
        C++;
        A--;
        queue.push('C');
      }
      if (C<0 || A<0){
        result = false;
      }
    }
  }
  if (result){
    printf("Yes\n");
    while(queue.size()>0){
      char value = queue.front();
      printf("%c\n", value);
      queue.pop();
    }
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 7660
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static int BubbleSort(final int N, int[] A){
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	}
}

Measured memory_bytes: 19688
//GhostCai is huger than wjmzbmr
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1005;
struct Edge{
	int to,nxt;
}e[N<<1];
int n,x[N],head[N],ecnt,f[N],g[2][5005];
void add(int bg,int ed){e[++ecnt].nxt=head[bg];e[ecnt].to=ed;head[bg]=ecnt;}
void dfs(int u) {
	for(int i=head[u];i;i=e[i].nxt) dfs(e[i].to);
	memset(g[0],0x3f,sizeof g[0]);
	int cur=0;
	g[cur][0]=0;
	for(int i=head[u];i;i=e[i].nxt) {
		int v=e[i].to;cur^=1;
		memset(g[cur],0x3f,sizeof g[cur]);
		for(int j=0;j<=x[u];j++) {
			if(j-x[v]>=0) g[cur][j]=min(g[cur^1][j-x[v]]+f[v],g[cur][j]);
			if(j-f[v]>=0) g[cur][j]=min(g[cur^1][j-f[v]]+x[v],g[cur][j]);
		}		
	}
	for(int i=0;i<=x[u];i++) f[u]=min(f[u],g[cur][i]);
}
int main() {
	scanf("%d",&n);
	for(int i=2,p;i<=n;i++) scanf("%d",&p),add(p,i);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	memset(f,0x3f,sizeof f);
	dfs(1);
	if(f[1]<0x3f3f3f3f) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 384