akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define LEN 100005

struct P
{
	char name[100];
	int t;
};

P Q[LEN];
int head, tail;

void enqueue(P x)
{
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue()
{
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);

	for (int i = 0; i < n; i++)
	{
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 0;
	tail = n;

	int time = 0;
	while (head != tail)
	{
		P x = dequeue();

		if (x.t - q > 0)
		{
			time += q;
			x.t = x.t - q;
			enqueue(x);
		}
		else
		{
			time += x.t;
			printf("%s %d\n", x.name, time);
		}
	}
}


Measured memory_bytes: 12736
def solve():
    N = int(input())
    S = input()

    ans, j = 0, 1
    for i in range(N):
        s = S[i:i+j]
        while S[i+j:].find(s) != -1:
            j += 1
            s = S[i:i+j]
            ans += 1

    print(ans)


if __name__ == '__main__':
    solve()

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

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

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

  vector<bool> dp(K + 1, false);
  for (int i = 1; i <= K; i++) {
    rep(j, N) {
      if (i - a.at(j) >= 0 && !dp.at(i - a.at(j))) {
        dp.at(i) = true;
      }
    }
  }

  if (dp.at(K)) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = list(input())

keep = []
flag = False
start, end = 0, 0
while start < N and end < N:
    if flag:
        if S[end] == "1": end += 1
        else:
            keep.append(end - start)
            start = end
            flag = False
    else:
        if S[start] == "1":
            keep.append(start - end)
            flag = True
            end = start + 1
        else:
            start += 1
if flag: keep.append(end - start)
else: keep.append(start - end)

stand = len(keep) // 2
if len(keep) % 2 == 1: 
    stand += 1
    keep.append(0)

if stand <= K: print(N)
else:
    maxL = sum(keep[:2*K])
    length = maxL
    for i in range(1, stand - K+1):
        length += keep[2*(K+i-1)]+keep[2*(K+i-1)+1] - keep[2*(i-1)]
        if i >= 2: length -= keep[2*(i-1)-1]
        maxL = max(maxL, length)
    print(maxL)



Measured memory_bytes: 5176
#include<math.h>
#include<stdio.h>
#define min(a,b) (a)<=(b)?(a):(b)
int main()
{   int n,i,cnt3=0,cnt5=0,cnt7=0,ans=0,start=1;
    scanf("%d",&n);
    if(n>=777777753){
        printf("26484");
        return 0;
    }
           if(n>=100000000&&n<=300000000){
                printf("8334");
                return 0;
            }
            if(n>300000000&&n<=400000000){
                ans=8334;
                start=300000000;
            }
            if(n>400000000&&n<=500000000){
                printf("14384");
                return 0;
            }
            if(n>500000000&&n<=600000000){
                ans=14384;
                start=500000000;
            }
            if(n>600000000&&n<=700000000){
                ans=20434;
                return 0;
            }
            if(n>700000000&&n<=800000000){
                ans=20434;
                start=700000000;
            }
    int s=min(n,777777753);
        for(i=start;i<=s;i++){
            
        cnt3=0;cnt5=0;cnt7=0;
        int num=i;
        while(num>0){if(num%10==3)cnt3++;
        
        else if(num%10==5)cnt5++;
        else if(num%10==7)cnt7++;
        else break;
        num/=10;
        }
        if(num==0&&cnt3>0&&cnt5>0&&cnt7>0)ans++;
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N, C;
    cin >> N >> C;

    vector<int> s(N), t(N), c(N);
    for (int i = 0; i < N; i++) cin >> s[i] >> t[i] >> c[i], c[i]--;

    vector<vector<pair<int, int>>> channels(C, vector<pair<int, int>>());
    for (int i = 0; i < N; i++) channels[c[i]].push_back(make_pair(s[i], t[i]));
    for (int i = 0; i < C; i++) sort(channels[i].begin(), channels[i].end());

    vector<vector<pair<int, int>>> new_channels(C, vector<pair<int, int>>());
    for (int i = 0; i < C; i++) {
        pair<int, int> p = make_pair(-1, -1);
        for (int j = 0; j < channels[i].size(); j++) {
            if (p == make_pair(-1, -1)) p = channels[i][j];
            else {
                if (p.second == channels[i][j].first) p = make_pair(p.first, channels[i][j].second);
                else new_channels[i].push_back(p), p = channels[i][j];
            }
        }
        if (p != make_pair(-1, -1)) new_channels[i].push_back(p);
    }

    vector<int> imos(100010, 0);
    for (int i = 0; i < C; i++) for (auto time: new_channels[i]) imos[time.first - 1] += 1, imos[time.second] -= 1;
    for (int i = 1; i < imos.size() - 2; i++) imos[i] += imos[i - 1];

    int ans = *max_element(imos.begin(), imos.end());
    cout << ans << endl;

}

































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

using namespace std;

int main(){
	int n;
  	cin >> n;
	map<string, set<pair<int, int>>> mp;
  	string s;
  	int p;
  	for(int i = 1; i <= n; ++i){
    	cin >> s >> p;
      	mp[s].insert(make_pair(-p, i));
    }
  	
  	for(auto const & kv : mp){
    	for(auto val : kv.second){
        	cout << val.second << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int ans[1000];
int pos;
void func(int res, int ub) {
    if (res==0) {
        for (int i=0; ;i++) {
            printf("%d%c",ans[i],ans[i+1]==0?'\n':' ');
            if (ans[i+1]==0) break;
        }
    } else {
        for (int i=min(res,ub); i>=1; i--) {
            ans[pos]=i;
            pos++;
            func(res-i,i);
            pos--;
            ans[pos]=0;
        }
    }
}
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (!n) break;
        func(n,n);
    }
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<functional>

using namespace std;

const int MX=100011,MXT=262333;
int n,q;
struct X{
	int A,B;
	X(int _A=0,int _B=0):A(_A),B(_B){}
}x[MX];
int c[MX];
int s[MX];
struct Iv{
	int s,e,id;
	Iv(int _s=0,int _e=0,int _id=0):s(_s),e(_e),id(_id){}
	inline bool operator<(const Iv &x)const{return e<x.e;}
}e[MX];
struct cmp{
	inline bool operator()(const Iv &x,const Iv &y){return x.s>y.s;}
};
int ans[MX];
int hedA[MX],nxtA[MX],hedB[MX],nxtB[MX],vis[MX];
int sg[MXT];

inline void add(int no,int l,int r,int ll,int rr,int d){
	if(ll<=l&&rr>=r)sg[no]+=d;
	else{
		int mid=(l+r)>>1;
		if(ll<=mid)add(no<<1,l,mid,ll,rr,d);
		if(rr>mid)add(no<<1|1,mid+1,r,ll,rr,d);
	}
}
inline int que(int no,int l,int r,int x){
	if(l==r)return sg[no];
	else{
		int mid=(l+r)>>1;
		return (x<=mid?que(no<<1,l,mid,x):que(no<<1|1,mid+1,r,x))+sg[no];
	}
}

void wk(){
	for(int i=0;i<=n;i++)add(1,0,n,0,i,1);
	int tans=0;
	for(int i=1;i<=n;i++){
		if(x[i].A>n){
			if(x[i].B>n){memset(ans,-1,sizeof(int)*(n+1));return;}
			else add(1,0,n,0,x[i].B,-1),++tans;
		}else add(1,0,n,0,x[i].A,-1);
	}
	priority_queue<Iv,vector<Iv>,cmp>q;while(!q.empty())q.pop();
	for(int i=1;i<=n;i++)if(x[i].A<=n&&x[i].B<x[i].A){
		e[i]=Iv(x[i].B+1,x[i].A,i);
		nxtB[i]=hedB[x[i].B+1],hedB[x[i].B+1]=i;
		nxtA[i]=hedA[x[i].A],hedA[x[i].A]=i;
	}
	for(int i=n;i>=0;i--){
		for(int j=hedA[i];j;j=nxtA[j])q.push(e[j]);
		while(que(1,0,n,i)<0){
			if(q.empty()){memset(ans,-1,sizeof(int)*(n+1));return;}
			Iv cur=q.top();q.pop();
			vis[cur.id]=1;add(1,0,n,cur.s,cur.e,1);
			++tans;
		}
	}
	priority_queue<Iv>qr;while(!qr.empty())qr.pop();
	for(int i=0;i<=n;i++){
		for(int j=hedB[i];j;j=nxtB[j])if(!vis[e[j].id])qr.push(e[j]);
		while(que(1,0,n,i)<=0){
			if(qr.empty()){memset(ans+i,-1,sizeof(int)*(n+1-i));return;}
			Iv cur=qr.top();qr.pop();
			add(1,0,n,cur.s,cur.e,1);
			++tans;
		}
		ans[i]=tans;
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&x[i].A,&x[i].B);
	for(int i=1;i<=n+1;i++)scanf("%d",&c[i]);
	sort(c+1,c+n+2);
	#define V(x) (lower_bound(c+1,c+n+2,x)-c-1)
	for(int i=1;i<=n;i++)x[i].A=V(x[i].A),x[i].B=V(x[i].B);
	wk();
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int D,E;scanf("%d%d",&D,&E);
		D=V(D),E=V(E);
		if(D>n){
			if(E>n)puts("-1");
			else printf("%d\n",ans[E]==-1?-1:n-ans[E]);
		}else{
			if(E>n)printf("%d\n",ans[D]==-1?-1:n-ans[D]+1);
			else printf("%d\n",ans[E]==-1?(ans[D]==-1?-1:n-ans[D]+1):(ans[D]==-1?n-ans[E]:max(n-ans[E],n-ans[D]+1)));
		}
	}
	return 0;
}


Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

ll n, l, t;
ll X[MX];
ll cnt;

ll norm(ll x, ll r){
    if(x>=0) return x%r;
    return (r-abs(x)%r)%r;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>l>>t;
    for(int i=1; i<=n; i++){
        ll x, w;
        cin>>x>>w;
        if(w==1){
            cnt+=(x+t)/l;
            X[i]=(x+t)%l;
        }
        else{
            if(x-t<0)
                cnt-=(abs(x-t)+l-1)/l;
            X[i]=(x-t + (t + l-t%l))%l;
        }
    }
    sort(X+1, X+n+1);
    cnt=norm(cnt, n);
    for(int i=1+cnt; i<=n+cnt; i++){
        int j=(i-1)%n+1;
        cout<<X[j]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	if(s.back() == 's'){
		s += "es";
	}
	else{
		s+= "s";
	}
	cout << s << endl;
	return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
        cout << "Possible" << endl;
    }
    else cout << "Impossible" << endl;
    return 0;
}


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

int N = 0;
int X = 0;
int material[120] = {0};

void input() {
  cin >> N >> X;
  for (int i = 0; i < N; i++) {
    cin >> material[i];
  }
}

int solve() {
  int total = 0;
  int minimum = material[0];
  for (int i = 0; i < N; i++) {
    total += material[i];
    minimum = min(minimum, material[i]);
  }
  int remain = X - total;
  return N + (remain / minimum);
}

int main() {
  input();
  printf("%d\n", solve());
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FORR(i,a,b) for (int i=a; i>=b; i--)

typedef long long ll;

#define mod 100000

int dp[100][100][4]={};
// 0:rr 1:ru 2:ur 3:uu

int main(void) {
    int n,m;
    while(cin >> n >> m && n>0){
    REP(i,n){
        dp[i][0][0]=1;
    }
    REP(i,m){
        dp[0][i][3]=1;
    }
    FOR(i,1,n-1){
        FOR(j,1,m-1){
            dp[i][j][0]=dp[i-1][j][0]+dp[i-1][j][2];
            dp[i][j][3]=dp[i][j-1][1]+dp[i][j-1][3];
            dp[i][j][1]=dp[i][j-1][0];
            dp[i][j][2]=dp[i-1][j][3];
            REP(k,4){
                dp[i][j][k]%=mod;
            }
        }
    }
    
    int ans=0;
    REP(i,4){
        ans = ans+dp[n-1][m-1][i];
    }
    ans %= mod;
    
    cout << ans << endl;
}

    return 0;
}

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

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;
}

using namespace std;

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;

  char c = sa[0];
  int indexA = 1;
  int indexB = 0;
  int indexC = 0;

  while (true) {
    if (c == 'a') {
      if (indexA >= sa.length()) {
        cout << 'A' << endl;
        return 0;
      }
      c = sa[indexA];
      indexA++;
    }
    if (c == 'b') {
      if (indexB >= sb.length()) {
        cout << 'B' << endl;
        return 0;
      }
      c = sb[indexB];
      indexB++;
    }
    if (c == 'c') {
      if (indexC >= sc.length()) {
        cout << 'C' << endl;
        return 0;
      }
      c = sc[indexC];
      indexC++;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import collections

H,W = map(int, input().split())
grid = [0]*(H*W)
black = collections.deque()
for i in range(H):
  A_i = input()
  for j in range(W):
    grid[W*i + j] = 0 if A_i[j] == '#' else -1
    if A_i[j] == '#':
      black.append(W*i + j)

ans = 0
while True:
  black_new = collections.deque()
  while len(black) > 0:
    i = black.pop()
    if i - W >= 0:
      if grid[i - W] == -1:
        grid[i - W] = ans + 1
        black_new.append(i-W)
    if i - 1 >= 0 and i%W != 0:
      if grid[i - 1] == -1:
        grid[i - 1] = ans + 1
        black_new.append(i-1)
    if i + 1 <= H*W-1 and i%W != W-1:
      if grid[i + 1] == -1:
        grid[i + 1] = ans + 1
        black_new.append(i+1)
    if i + W <= H*W-1:
      if grid[i + W] == -1:
        grid[i + W] = ans + 1
        black_new.append(i+W)
  black = black_new
  if len(black) == 0:
    print(ans)
    break
  ans += 1

Measured memory_bytes: 97244
#include <stdio.h>

int main(void) {
        int h,w;
        int i,j;
        char blank;
        char buf;
        scanf("%d %d", &h, &w);
        char array0[h][w];
        int skip_h[h];
        int skip_w[w];

        for (i=0; i<h; i++) {
                scanf("%c",&blank);
                for (j=0; j<w; j++) {
                        scanf("%c", &buf);
                        if (buf == '.')
                                array0[i][j] = 0;
                        else
                                array0[i][j] = 1;
                }
        }

        //get skip lines
        for (i=0; i<h; i++) {
                skip_h[i] = 0;
                for (j=0; j<w; j++) {
                        skip_h[i] += array0[i][j];
                }
        }
        for (j=0; j<w; j++) {
                skip_w[j] = 0;
                for (i=0; i<h; i++) {
                        skip_w[j] += array0[i][j];
                }
        }

        //output
        for (i=0; i<h; i++) {
                if (skip_h[i] != 0) {
                        for (j=0; j<w; j++) {
                                if(skip_w[j] != 0) {
                                        if (array0[i][j] == 1)
                                                printf("#");
                                        else
                                                printf(".");
                                }
                        }
                        printf("\n");
                }
        }

        return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split(" ");
		for(String s : line){
			System.out.print(s.charAt(0));
		}
		System.out.println();
	}
}


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

int main()
{
  ll N; cin >> N;
  vector<ll> L(N);
  for (int i=0; i<N; i++){
    cin >> L[i];
  }
  sort(L.begin(),L.end());

  ll ans = 0;
  for (int i=N-1; i>=0; i--) {
    for (int j=i-1; j>=0; j--) {
      ll a = L[i];
      ll b = L[j];
      auto itr = lower_bound(L.begin(), L.end(), a+b);
      ll x = L.end() - itr;
      ans += N - 1 - i - x;
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int n, h[mx2];

int main()
{
    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> h[i];

    int ans = 0;

    while(1){

        vector<int> v;
        for(int i = 1; i <= n; i++){
            if(!h[i])
                continue;

            v.Pb(i);
            h[i]--;
        }

        int L = v.size();

        if(!L)
            break;

        int x = 1;
        for(int i = 1; i < L; i++)
            if(v[i] - v[i - 1] > 1)
                x++;

        ans += x;
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3608
from itertools import product

N = int(raw_input())
A = map(int, raw_input().split())
ans = 0

for p in product((-1, 0, 1), repeat=N):
    B = A[:]
    for i in xrange(N):
        B[i] += p[i]
    if sum(b % 2 == 0 for b in B) > 0:
        ans += 1

print ans


Measured memory_bytes: 33384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, k, ans;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> k;
    map<int, int> mem;
    vector<Pii> cnt;
    rep(i, 0, n) {
        int p; cin >> p;
        mem[p]++;
    }
    for (auto itr = mem.begin(); itr != mem.end(); ++itr) {
        cnt.pb(mp(itr->second, itr->first));
    }
    sort(all(cnt));
    int i = 0;
    while(cnt.size() - i > k) {
        ans += cnt[i].first;
        ++i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11764
#include <iostream>
using namespace std;
int main()
{
    int n;string s;cin>>n>>s; int coun=0;

    for(int i=0;i<n-1;i++){

        if(s[i]==s[i+1]) continue;

         coun++;

    }

cout<<coun+1<<endl;

    return  0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int power(int a, int b){ int S = 1; while(b--)S *= a; return S;}

int32_t main(){
	int n;
	cin >> n;
	int a[n] = {0};
	int x;
	for(int i = 1; i < n; i++){
		cin >> x;
		a[x-1]++;
	}
	for(int i = 0; i < n; i++){
		cout << a[i] << "\n" ;
	}
	return 0;
}



Measured memory_bytes: 5184
#include <stdio.h>

int lp(int y){
	if((y%400==0) || (y%4==0 && y%100!=0)) return 1;
	else return 0;
}

int main(void){
	int a , b , i , flag , cnt = 0;
	while(1){
		flag = 0;
		scanf("%d %d" , &a , &b);
		if(a == 0 && b == 0) break;
		if(cnt!=0) printf("\n");
		for(i=a;i<=b;i++){
			if(lp(i)){
				printf("%d\n" , i);
				flag = 1;
			}
		}
		if(flag == 0) printf("NA\n");
		cnt++;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define MINUS(a) memset(a,0xff,sizeof(a))

long long N, K;
vector<long long> A;

int cnt[44];
long long dp[44][2];

long long rec(int digit, bool strict) {

  if (digit < 0) return 0;

  auto& ret = dp[digit][strict];
  if (ret != -1) return ret;

  long long mask = 1LL << digit;

  long long score0 = mask * cnt[digit], score1 = mask * (N - cnt[digit]);

  if (strict) {
    if (K & mask) {
      // 1に遷移した場合, strict = true
      // 0に遷移した場合, strict = false
      return ret = max(rec(digit - 1, true) + score1, rec(digit - 1, false) + score0);
    } else {
      // 0にしか遷移できず, strict = true
      return ret = rec(digit - 1, true) + score0;
    }
  } else {
      // 0と1どちらに遷移しても良い (strict = false)
      return ret = rec(digit - 1, false) + max(score1, score0);
  }

}

signed main() {

  cin >> N >> K;
  A.resize(N); for (auto& e: A) cin >> e;

  MINUS(dp);

  for (int i = 0; i < 44; ++i) for (auto& e: A) if (e & (1LL << i)) ++cnt[i];

  cout << rec(43, true) << endl;

}


Measured memory_bytes: 1024
N = int(input())

dp = [False for i in range(N + 1)]
prices = [4, 7]
dp[0] = True

for p in prices:
    for j in range(N + 1):
        if not dp[j]:
            continue
        idx = j + p
        if idx > N:
            break
        dp[idx] = True
if dp[N]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int w;
    cin >> w;
    int x = 0;
    while(x<(int)s.size()){
        cout << s[x];
        x+=w;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include<cstdio>
#include <cmath>
using namespace std;


int main()
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	if (a + b > c + d)
		cout << "Left" << endl;
	else if (a + b == c + d)
		cout << "Balanced" << endl;
	else
		cout << "Right" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Map<String, Integer> map = new HashMap<>();
        String color1=sc.next();
        String color2=sc.next();
        map.put(color1, sc.nextInt());
        map.put(color2, sc.nextInt());
        String tmp=sc.next();
        map.put(tmp, map.get(tmp)-1);
        System.out.println(map.get(color1)+" "+map.get(color2));
        
    }
}


Measured memory_bytes: 21844
while True:
    w, h = map(int, input().split())
    if w == 0: break
    goal = (w,h)
    vart = []
    hori = []
    for i in range(2*h-1):
        if i % 2 == 0:
            vart.append(list(map(int, input().split())))
        else:
            hori.append(list(map(int, input().split())))
    node = [[0 for i in range(h)] for i in range(w)]
    queue = [(0,0,1)]
    while queue:
        p = queue.pop(0)
        x, y, z = p[0], p[1], p[2]
        node[x][y] += 1
        if y-1 >= 0 and hori[y-1][x] == 0 and node[x][y-1] == 0:
            node[x][y-1] = node[x][y]
            queue.append((x,y-1,z+1))
        if y+1 < h and hori[y][x] == 0 and node[x][y+1] == 0:
            node[x][y+1] = node[x][y]
            queue.append((x,y+1,z+1))
        if x-1 >= 0 and vart[y][x-1] == 0 and node[x-1][y] == 0:
            node[x-1][y] = node[x][y]
            queue.append((x-1,y,z+1))
        if x+1 < w and vart[y][x] == 0 and node[x+1][y] == 0:
            node[x+1][y] = node[x][y]
            queue.append((x+1,y,z+1))
    print(node[w-1][h-1])

Measured memory_bytes: 7616
N = int(input())
A = list(map(int,input().split()))
# solve
x = 0
for i in range(N):
    if i%2==0:
        x+=A[i]
    else:
        x-=A[i]
ans = [x]
for i in range(N-1):
    x = ans[i]
    ans.append(2*A[i]-x)
print(*ans)

Measured memory_bytes: 14028
#include<stdio.h>
char s[1000];

int f(int i,char *c,char *p)
{
	int j;
	for(j=0;j<5;j++)
		if(s[i+j]!=c[j])
			return i+1;
	for(j=0;j<5;j++)
		s[i+j]=p[j];
	return i+5;
}

int main()
{
	int i=0;

	while(scanf("%c",&s[i])!=EOF)
		i++;
	i=0;
	while(s[i])
	{
		switch(s[i])
		{
				case'a':i=f(i,"apple","peach");break;
				case'p':i=f(i,"peach","apple");break;
				default:i++;
		}
	}
	printf("%s",s);
	return 0;
}

Measured memory_bytes: 540
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();

		Arrays.sort(s);
		Arrays.sort(t);

		String ans = "No";

		for (int i = 0, j = t.length - 1; i < s.length || j >= 0; i++, j--) {
			if (i >= s.length && j >= 0) {
				ans = "Yes";
				break;
			}
			if (i < s.length && j < 0) {
				break;
			}
			if (s[i] < t[j]) {
				ans = "Yes";
				break;
			}
			if (s[i] > t[j]) {
				break;
			}
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 22740
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;

int wa(long a){
  char num[16];
  int len,ii,wa=0;
  sprintf(num,"%ld",a);
  len = strlen(num);
  for(ii=0;ii<len;ii++){
	wa += num[ii] - '0';
  }
  return wa;
}
int main(){
  long n;
  long a,b,ii,tmp;
  long min = 100000;
  cin >> n;
  
  for(ii=1;ii<n;ii++){

	a=ii;
	b=n-a;
	
	tmp = wa(a)+wa(b);
	if(tmp < min){
	  min = tmp;
	}
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

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

	vector<ll> p (N);
	rep (i, N) {
		cin >> p[i];
	}

	int count = 0;

	rep (i, N) {
		if (i + 1 == p[i]) {
			continue;
		}

		if (count <= 1) {
			++count;
			continue;
		}

		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
}



Measured memory_bytes: 256
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353

dp = [[1] + [0] * s for _ in range(n + 1)]
ans = 0
for i in range(n):
    for j in range(s + 1):
        dp[i + 1][j] += dp[i][j]
        dp[i + 1][j] %= MOD
        if j + a[i] <= s:
            dp[i + 1][j + a[i]] += dp[i][j]
            dp[i + 1][j + a[i]] %= MOD
    ans += dp[i + 1][s]
    ans %= MOD

print(ans)


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

int main(){
    string S;
    cin >> S;
    int result = 0 ;
    for(int i=0; i < S.length(); i++){
        if (S[i] == '+'){
            result++;
        }
        else if(S[i] == '-'){
            result--;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3564
// string::substr
#include <iostream>
#include <string>
using namespace std;
 
int main ()
{
  string str;

 cin >> str;
                                           // (quoting Alfred N. Whitehead)
 
  string str2 = str.substr (0,4);     // "think"
  string str3 = str.substr (4);     // get from "live" to the end
 
  cout << str2 << ' ' << str3 << '\n';
 
  return 0;
}

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

int main(){
  ll a,b;
  vector <ll> da;
  vector <ll> db;

  scanf("%lld %lld", &a, &b);

  ll d;
  da.push_back(1);
  db.push_back(1);

  for(d = 2;d*d <= a;d++){

    if(a % d == 0){
      da.push_back(d);

      while(a % d == 0){
        a = a/d;
      }
    }
  }

  if(a != 1) da.push_back(a);

  for(d = 2;d*d <= b;d++){
    if(b % d == 0){
      db.push_back(d);

      while(b % d == 0){
        b = b/d;
      }
    }
  }

  if(b != 1) db.push_back(b);


  int i = 0;
  int j = 0;
  int ans = 0;

  while(i < da.size() && j < da.size()){
    if(da[i] == db[j]){
      ans++;
      i++;
      j++;
    }

    else if(da[i] > db[j]) j++;

    else i++;
  }

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int K;
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
    cin >>K;
    cout << a[K-1];

}


Measured memory_bytes: 256
import java.util.Scanner;
     
public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        if (s.equals("AAA") || s.equals("BBB")) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    map<string, int> mp;

    for (size_t i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
    }

    int mx_cnt = 0;
    for (auto &&m : mp)
    {
        mx_cnt = max(m.second, mx_cnt);
    }

    for (auto &&m : mp)
    {
        if (m.second == mx_cnt)
        {
            cout << m.first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define boost		          ios_base::sync_with_stdio(0);
#define eb                    emplace_back
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1e9+7
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()
#define iscn(num)             scanf("%d",&num);
#define scn(num)              scanf("%lld",&num);
#define scn2(num,num2)        scanf("%lld%lld",&num,&num2);
using namespace std;


int main()
{
	int n,l,sum = 0;
	scanf("%d%d",&n,&l);
	vector <int > v(n);
	
	for(int i = 0  ; i < n; i++)
		v[i] = l+i,sum += v[i];
	
	
	int ans = sum;
	sort(all(v));
	for(int i = 0 ; i < n; i++){

		if(i==n-1)
			ans = sum-v[i];
		else if(v[i] >= 0){
			ans = sum-v[i];
			break;
		}
	}
	
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
long long aaa(long long a,long long b){
	while(1){
		a=a%b;
		if(a==0)break;
		swap(a,b);
	}
	return b;
}

int main(){
	long long a,b;
	while(scanf("%lld%lld",&a,&b)!=EOF){
		long long t=aaa(a,b);
		cout<<t<<" "<<a/t*b<<endl;
	}
	return 0;
}

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

int main(){
	bool is_prime[1000000];

	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}

	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];

	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}

	while(true){
		int n;
		cin>>n;

		if(cin.eof())
			break;

		cout<<n_prime[n]<<endl;
	}
	return 0; 
}


Measured memory_bytes: 7936
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in).useDelimiter("[,\n]");
		
		int rect = 0;
		int diam = 0;
		
		while (true)
		{
			try
			{
				int a = sc.nextInt();
				int b = sc.nextInt();
				int c = sc.nextInt();
				if (a * a + b * b == c * c)
					rect++;
				else if (a == b)
					diam++;
			}
			catch (Exception e)
			{
				break;
			}
		}
		System.out.println(rect);
		System.out.println(diam);
	}
}

Measured memory_bytes: 12000
import java.util.*;

import javax.swing.plaf.synth.SynthSplitPaneUI;
public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int r = scanner.nextInt();
        int D = scanner.nextInt();
        int x = scanner.nextInt();

        for(int i=0;i<10;i++){
            x = r*x - D;
            System.out.println(String.valueOf(x));
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
#define ll long long

#define sondos ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;



int main() {

    sondos
      
    double  a;
    cin >> a;
  
   double   z = (a / 3);
   printf("%lf", z*z*z);

    return 0;
}
 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#define LL long long
#define LD long double
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;

long long d[10000001];

void f(long long n)
{
	for(long long i=1; i<=n; i++)
	{
		for(long long j=i; j<=n; j+=i) d[j]++;
	}
}

int main()
{
	FIO;
	long long n, sum=0; cin>>n, f(n);
	for(long long i=1; i<=n; i++) sum+=i*d[i];
	cout<<sum<<endl;
}

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

int main(){
	long long n,m; cin>>n>>m;
	long long ans;
	if(n==1 && m==1) ans=1;
	else if(n==1) ans=m-2;
	else if(m==1) ans=n-2;
	else ans=n*m-(2*n+2*m-4);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    
    vector<int> count(4);
    for ( int i = 0; i < N; ++i ){
        string s;
        cin >> s;
        
        if ( s == "AC"){
            count.at(0)++;
        } else if ( s == "WA"){
            count.at(1)++;
        } else if ( s == "TLE"){
            count.at(2)++;
        } else if ( s == "RE"){
            count.at(3)++;
        } 
    
    }
    cout << "AC x "<< count.at(0) << endl;
    cout << "WA x "<< count.at(1) << endl;
    cout << "TLE x "<< count.at(2) << endl;
    cout << "RE x "<< count.at(3) << endl;
 
    
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b;
  cin >> a >> b;
  if (a > 9 || b > 9) {
    cout << -1 << endl;
  } else {
    cout << a * b << endl;
  }

  return 0;
}


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

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> data(h,vector<char>(w));
    vector<int> H(h);
    vector<int> W(w);

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> data.at(i).at(j);
            if(data.at(i).at(j) == '#') H.at(i) = 1;
        }
    }

    for(int i=0; i<w; i++){
        for(int j=0; j<h; j++){
            if(data.at(j).at(i) == '#') W.at(i) = 1;
        }
    }

    for(int i=0; i<h; i++){
        if(H.at(i) == 0) continue;
        for(int j=0; j<w; j++){
            if(W.at(j) == 0) continue;
            cout << data.at(i).at(j);
        }
        cout << endl;
    }


}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int n,x,A[1111];

int main(){
    ____();
    cin >> x >> n;
    set<int> S;
    for(int i = 1; i <= n; i++){
        int x; cin >> x;
        S.insert(x);
    }
    int ret = 1111111;
    for(int i = -1; i <= 200; i++){
        if(S.count(i)) continue;
        if(abs(i-x)<abs(ret-x) or (abs(i-x)==abs(ret-x) and i<ret)) ret = i;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin>>n>>m;
  vector<vector<ll>> mat1(n,vector<ll>(m)),mat2(n,vector<ll>(m)),mat(n,vector<ll>(m));
  for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
      cin>>mat1[i][j];
 for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
      cin>>mat2[i][j];
 for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
      mat[i][j] = abs(mat1[i][j] - mat2[i][j]);
  vector<vector<vector<bool>>> dp(n,vector<vector<bool>>(m,vector<bool>(6400)));
  dp[0][0][mat[0][0]] = true;
  for(ll i=0;i<n;i++){
    for(ll j=0;j<m;j++){
      for(ll k=0;k<6400;k++){
        if(i+1<n && k+mat[i+1][j]<6400 && dp[i][j][k])
          dp[i+1][j][k+mat[i+1][j]] = true;
        if(i+1<n && dp[i][j][k])
          dp[i+1][j][abs(k-mat[i+1][j])] = true;
        if(j+1<m && k+mat[i][j+1]<6400 && dp[i][j][k])
          dp[i][j+1][k+mat[i][j+1]] = true;
        if(j+1<m && dp[i][j][k])
          dp[i][j+1][abs(k-mat[i][j+1])] = true;
      }
    }
  }
  ll i =0;
  for(i =0;i<6400;i++)
    if(dp[n-1][m-1][i])
      break;
  cout<<i<<endl;
}
 

Measured memory_bytes: 8904
#include "bits/stdc++.h"
using namespace std;
long long a[1001];
int main()
{
	long long n, total = 1, mod = 1000000007;
	scanf("%lld", &n);
	for(long long i = 1, j; i <= n; ++i)
	{
		j = i;
		for(long long k = 2; k <= sqrt(j + 0.01); )
		{
			if(j % k)
			{
				++k;
			}
			else
			{
				j /= k;
				++a[k];
			}
		}
		++a[j];
	}
	for(long long i = 2; i <= 1000; ++i)
	{
		(total *= (a[i] + 1)) %= mod;
	}
	printf("%lld\n", total);
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll c[2][100010];

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long Q;
  scanf("%lld", &Q);
  std::string S;
  std::cin >> S;
  std::vector<long long> l(Q);
  std::vector<long long> r(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &l[i]);
    scanf("%lld", &r[i]);
  }

  rep(i, 1, N) {
    c[0][i] = c[0][i - 1] + (S[i] == 'C' && S[i - 1] == 'A');
    c[1][i] = c[1][i - 1] + (S[N - 1 - i] == 'A' && S[N - i] == 'C');
  }

  ll all = c[0][N - 1];
  rep(i, 0, Q) {
    int left = l[i];
    int right = r[i];
    put(all - c[0][left - 1] - c[1][N - right]);
  }
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


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

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

    int l[n+10];
    for (int i=0; i<n; i++) {
        cin >> l[i];
    }

    sort(l, l+n, greater<int>());
    int sum = 0;
    for (int i=0; i<k; i++) {
        sum += l[i];
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
import copy
 
INF = 10000000000
def merge(A, left, mid, right):
    count = 0
    L = A[left:mid] + [(INF,INF)]
    R = A[mid:right] + [(INF,INF)]
     
    i, j = 0, 0
    for k in range(left, right):
        count = count + 1
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
    return count
 
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        countL = mergeSort(A, left, mid)
        countR = mergeSort(A, mid, right)
        return merge(A, left, mid, right) + countL + countR
    return 0
def partition(a,p,r):
    x=a[r][1]
    i=p-1
    for j in range(p,r):
        if a[j][1]<=x:
            i+=1
            a[i],a[j]=a[j],a[i]
    a[i+1],a[r]=a[r],a[i+1]
    return i+1
def quickSort(a,p,r):
    if p<r:
        q=partition(a,p,r)
        quickSort(a,p,q-1)
        quickSort(a,q+1,r)
n = int(input())
A = [None for i in range(n)]
for i in range(n):
    a, b = input().split()
    A[i] = (a, int(b))

B = copy.deepcopy(A)
quickSort(A, 0, n-1)
mergeSort(B, 0, n)
if A == B:
    print("Stable")
else:
    print("Not stable")
ans = [str(x[0]) +" "+str(x[1]) for x in A]
ans = '\n'.join(ans)
print(ans)


Measured memory_bytes: 24628
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define maxn 0x3f3f3f3f

using namespace std;

int m,n,mapp[205][205],e[15][15],vis[15],dis[15];

int dij(int u)
{
	int minn,v;
	
	for (int i = 0; i < 10; i++)
	{
		dis[i] = e[u][i];
	}
	
	vis[u] = 1;
	
	for (int i = 0; i < 9; i++)
	{
		minn = maxn;
		
		for (int j = 0; j <= 9; j++)
		{
			if (!vis[j] && dis[j] < minn)
			{
				v = j;
				minn = dis[j];
			}
		}
		
		vis[v] = 1;
		
		for (int k = 0; k < 10; k++)
		{
			dis[k] = min(dis[k],dis[v]+e[v][k]);
		}
	}
	return dis[1];
}

int main()
{
	int sum = 0,t,p;
	scanf("%d%d",&m,&n);
	
	memset(vis,0,sizeof(vis));
	memset(dis,maxn,sizeof(dis));
	
	for (int x = 0; x < 10; x++)
	{
		for (int y = 0; y < 10; y++)
		{
			scanf("%d",&e[x][y]);
		}
	}
	
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			scanf("%d",&mapp[i][j]);
		
			if (mapp[i][j] != -1 && mapp[i][j] != 1)
			{
				t = mapp[i][j];
				p = dij(t);
				sum = sum + p;
				memset(vis,0,sizeof(vis));
				memset(dis,maxn,sizeof(dis));
			}
		}
	}
	
	cout<<sum<<endl;
	
	return 0;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

constexpr int N = 1009, C = -9;
int n, m, vis[N];
vector<int> g[N], stk;

void print_ans(vector<int>& cycle) {
  int ss = cycle.size();
  vector<bool> doomed(ss);
  for(int i = 0; i < ss; ++i) {
    int u = cycle[i];
    for(int v : g[u]) {
      if(vis[v] != C) continue;
      if(v == cycle[(i + 1) % ss]) continue;
      for(int j = (i + 1) % ss; ; j = (j + 1) % ss) {
        if(cycle[j] == v) break;
        doomed[j] = true;
        vis[cycle[j]] = 2;
      }
      vector<int> new_cycle;
      for(int i = 0; i < ss; ++i) {
        if(!doomed[i]) new_cycle.push_back(cycle[i]);
      }
      print_ans(new_cycle);
    }
  }
  cout << ss << '\n';
  for(int x : cycle) cout << x << '\n';
  exit(0);
}

void dfs(int u) {
  vis[u] = 1;
  stk.push_back(u);

  for(int v : g[u]) {
    if(vis[v] == 0) dfs(v);
    else if(vis[v] == 1) {
      vector<int> cycle;
      for(auto it = stk.rbegin(); ; ++it) {
        cycle.push_back(*it);
        vis[*it] = C;
        if(*it == v) break;
      }
      reverse(cycle.begin(), cycle.end());
      print_ans(cycle);
    }
  }
  
  stk.pop_back();
  vis[u] = 2;
}

int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
  }

  for(int i = 1; i <= n; ++i) {
    if(vis[i] == 0) {
      dfs(i);
    }
  }
  cout << -1 << '\n';
}


Measured memory_bytes: 384