akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define STREAM_FAST ios::sync_with_stdio(false)
 
using namespace std;
const int maxn = 2e5+7;
struct node {int v,flow,nxt;}e[maxn];
int tot=1,head[maxn],dep[maxn];
// tot starting from 1
void add(int u,int v,int w)
{
    ++tot;
    e[tot].v=v;e[tot].flow=w;e[tot].nxt=head[u];
    head[u]=tot;
}
 
bool bfs(int S,int T)
{
    MEM(dep,0);
    dep[S]=1;
    queue<int>q;
    q.push(S);
    while (!q.empty())
    {
        int u=q.front();q.pop();
        for (int i=head[u];i;i=e[i].nxt)
        {
            int v=e[i].v;
            if (e[i].flow && !dep[v])
            {
                dep[v]=dep[u]+1;
                q.push(e[i].v);
            }
        }
    }
    return dep[T];
}
 
int aim;
int dfs(int now,int flow)
{
    if (now==aim) return flow;
    int f=0;
    for (int i=head[now];i;i=e[i].nxt)
    {
        int v=e[i].v;
        if (e[i].flow && dep[v]==dep[now]+1)
        {
            int x=dfs(v,min(flow,e[i].flow));
            e[i].flow-=x;e[i^1].flow+=x;flow-=x;f+=x;
        }
    }
    if (!f) dep[now]=-2;
    return f;
}
 
int maxflow(int S,int T)
{
    aim=T;int res=0;
    while (bfs(S,T)) res+=dfs(S,1<<30);
    return res;
}
 
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    int S=1000,T=1001;
    
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            char c;scanf(" %c",&c);
            if (c=='o') 
            {
                add(i,j+n,1);add(j+n,i,1);
            }
            else if (c=='S')
            {
                add(S,i,1e8);add(i,S,0);
                add(S,j+n,1e8);add(j+n,S,0);
            }
            else if (c=='T')
            {
                add(i,T,1e8);add(T,i,0);
                add(j+n,T,1e8);add(T,j+n,0);
            }
        }
    }
    
    int ans=maxflow(S,T);
    printf("%d\n",ans>=1e8?-1:ans);
    
    return 0;
}

Measured memory_bytes: 1280
H,W,D = [int(x) for x in input().split()]

d = {}

masu = [[int(x) for x in input().split()] for _ in range(H)]


for y in range(H):
    for x in range(W):
        v=masu[y][x]
        d[v-1] = (x,y)

mpDict = {}

for i in range(D):
    
    modD = i
    mpDict[modD] = {}
    index = modD
    acc = 0
    mpDict[modD][i] = 0
    index+=D
    while index<H*W:
        #print()
        #print("i",i)
        #print(index)
        prev = d[index-D]
        #print(prev)
        nxt = d[index]
        #print(nxt)
        acc += abs(prev[0]-nxt[0])+abs(prev[1]-nxt[1])
        mpDict[modD][index] = acc
        index+=D



Q = int(input())

for _ in range(Q):
    f,t = [int(x) for x in input().split()]
    modD = (f-1)%D
    mp = mpDict[modD][t-1] - mpDict[modD][f-1]
    print(mp)


Measured memory_bytes: 60216
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define iter(el, arr) for(auto& el : arr)
#define ALL(a) a.begin(), a.end()

#define ld long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll,ll>
#define MP make_pair
#define MT make_tuple
#define SZ(a) ll((a).size())
#define X first
#define Y second

#define endl '\n'
#define PB push_back
#define has(i, m) (m.find(i) != m.end())

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define vch vector<char>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define pdd pair<ld, ld>
#define vpll vector<pll>
#define vpdd vector<pdd>
#define pq priority_queue
#define mod 1000000007
using namespace std;

const ll INF = 1e18;
const ll MAXN = 100001;

ll power(ll n, ll to, ll m = mod)
{
	ll res = 1;
	while (to)
	{
		if (to & 1)
			res = (res*n) % m;
		n = (n*n) % m;
		to >>= 1;
	}
	return res;
}

int n;
string s1;
string s2;

map<int, ll> m;

ll solve(int i, bool a1, bool a2, bool b1, bool b2, bool c1, bool c2)
{
	if (m[a1 + 2 * a2 + 4 * b1 + 8 * b2 + 16 * c1 + 32 * c2 + i*64] != 0)
		return m[a1 + 2 * a2 + 4 * b1 + 8 * b2 + 16 * c1 + 32 * c2 + i*64];

	if (i >= n)
		return 1;

	ll res = 0;
	if (s1[i] == s2[i])
	{
		if (a1&&a2)
			res +=  solve(i + 1, 0, 0, 1, 1, 1, 1);
		if (b1&&b2)
			res +=  solve(i + 1, 1, 1, 0, 0, 1, 1);
		if (c1&&c2)
			res +=  solve(i + 1, 1, 1, 1, 1, 0, 0);		
	}
	else
	{
		if (a1&&b2)
			res +=  solve(i + 2, 0, 1, 1, 0, 1, 1);

		if (a1&&c2)
			res += solve(i + 2, 0, 1, 1, 1, 1, 0);

		if (b1&&a2)
			res += solve(i + 2, 1, 0, 0, 1, 1, 1);

		if (b1&&c2)
			res += solve(i + 2, 1, 1, 0, 1, 1, 0);

		if (c1&&a2)
			res += solve(i + 2, 1, 0, 1, 1, 0, 1);

		if (c1&&b2)
			res += solve(i + 2, 1, 1, 1, 0, 0, 1);

	}
	m[a1 + 2 * a2 + 4 * b1 + 8 * b2 + 16 * c1 + 32 * c2 + i*64] = res%mod;
	return res%mod;
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);	
	//freopen("Out.txt", "w", stdout);

	cin >> n;
	cin >> s1 >> s2;
	cout << (solve(0, 1, 1, 1, 1, 1, 1) % mod);
	//cin >> n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n, ans = 0;
    cin >> n;
    vector<pair<int, int>> p(n);
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(ALL(p));
    ans = p[0].first;
    for (int i = 1; i < n; i++)
    {
        ans += min(p[i].first - p[i - 1].first, p[i - 1].second - p[i].second);
    }
    ans += p[n - 1].second;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int a[3];

int main() {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3592
h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]


for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][k]+c[k][j], c[i][j])
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += c[a[i][j]][1]
print(ans)


Measured memory_bytes: 9464
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int M[200005];

int main()
{
    int K,N;
    long long Count=0;
    cin >> N >> K;
    if(K<N)
    {
       for(int i=0;i<N;i++)
            cin>>M[i];
        sort(M,M+N);
        for(int i=0;i<N-K;i++)
        Count+=M[i];
        cout << Count;
    }
    else
        cout<<0<<endl;
}


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

int main() {
  long long a, b;
  cin >> a >> b;
  
  if(a == b) cout << a << endl;
  else if(a + 1 == b){
    cout << (a ^ b) << endl;
  }
  else if(a % 2 == 0){
    if(b % 2 == 1){
      cout << ((b - a + 1) / 2) % 2 << endl;
    }
    else{
      cout << ((((b - a + 1) / 2) % 2) ^ b) << endl;
    }
  }
  else{
    if(b % 2 == 1){
      cout << (((b - a) / 2) % 2 ^ a) << endl;
    }
    else{
      cout << ((((b - a - 1) / 2) % 2) ^ a ^ b) << endl;
    }
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<algorithm>
#include<limits.h>
#define rep(i,l,p) for(int i=l; i<=p; i++)
#define drep(i,p,l) for(int i=p; i>=l; i--)
using namespace std;

int a,b;
int main(){
	scanf("%d%d",&a,&b);
	int ans = a*b;
	if ( ans % 2 == 0) printf("Even");
	else printf("Odd");
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll dp[105][100100],v[105];
int w[105];

int main(void){
	int n,wmax,i,j;
	ll ans = -INFLL;
	fill(dp[0],dp[105],-INFLL);
	dp[0][0] = 0ll;
	cin >> n >> wmax;
	for(i=0; i<n; ++i){
		cin >> w[i] >> v[i];
	}
	for(i=0; i<n; ++i){
		for(j=0; j<=wmax; ++j){
			dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
			if(j+w[i]<=wmax){
				dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
			}
		}
	}
	for(j=0; j<=wmax; ++j){
		ans = max(ans,dp[n][j]);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n=1,x=1,cnt=0;
  while(1){
    cin >> n >> x;
    if(n==0 && x==0) break;
    else{
      for(int i=1;i<=(n-2);i++){
        for(int j=i+1;j<=(n-1);j++){
          for(int k=j+1;k<=n;k++){
            if(i+j+k==x) cnt++;
          }
        }
      }
      cout << cnt << endl;
      cnt=0;
    }
  }
}


Measured memory_bytes: 3088
import math  # noqa: F401
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def main(N: int, K: int):
    if N == K:
        print(0)
        return

    if N > K:
        N -= N // K * K

    N = min((N, abs(N - K)))
    print(N)


if __name__ == "__main__":
    N, K = map(int, input().split())
    main(N, K)


Measured memory_bytes: 10232
#include<stdio.h>



int main()
{
	int W,H,x,y,r;

	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

	if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H) printf("Yes\n");
		
		else printf("No\n");
	
	



return 0;
}

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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define PRINTARR(a,b) for(int i=0;(a+i)!=(b);i++){cout << *(a+i) << " ";}PN();
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define MT make_tuple

typedef pair<int, int> PII;
typedef tuple<int, int, int> T3I;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d", &head);
    RI(tail...);
}
void RLL() {}
template<typename... T>
void RLL( LL& head, T&... tail ) {
    scanf("%lld", &head);
    RLL(tail...);
}
void print() {putchar('\n');}
template<typename T, typename... U>
void print(T head, U... tail) {
    cout << head << " ";
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 100005


int main()
{
    int n, m, k;
    RI(n, m, k);
    REP(i, n+1) {
        REP(j, m+1) {
            if(k == i * j + (n-i) * (m-j)) {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}


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

int main() {
  int X;
  cin>>X;
  bool ans=false;
  for(int i=X;i>0;i--){
    for(int j=1;j<35;j++){
      for(int l=2;l<10;l++){
        int test=pow(j,l);
        if(test==i){
          cout<<i<< endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 4012
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
 
 typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
 
const int hell= 1000000007;
 
 int power(int a,int b)
 {
  if(b==0)return 1LL;
  if(b==1)return a;
  int t=power(a,b/2);
  t*=t;
  t%=hell;
  if(b&1)return (t*a)%hell;
  else return t;
 }

 int inverse(int a)
 {
    return power(a,hell-2);
 }
 
int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;
    a%=10000000000LL;}
  return a;
}
 
int gcd(int a,int b)
{   
  if(b==0)return a;
  return gcd(b-a%b,a%b);
} 



int solve()
{

 string a,b;
 cin>>a>>b;
 int n=a.size(),m=b.size();
 int f[n+1][m+1][3];

rep(i,0,n+1)
{
  rep(j,0,m+1)
  {
    if(i==0||j==0){
      f[i][j][0]=0;
      f[i][j][1]=0;
      f[i][j][2]=0;
    }
    else if(a[i-1]==b[j-1])
      {
        f[i][j][0]=f[i-1][j-1][0]+1;
        f[i][j][1]=i-1;
        f[i][j][2]=j-1;
      }
    else 
      {
        if(f[i-1][j][0]>f[i][j-1][0])
        {
          f[i][j][0]=f[i-1][j][0];
          f[i][j][1]=f[i-1][j][1];
          f[i][j][2]=f[i-1][j][2];
        }
        else
        {
          f[i][j][0]=f[i][j-1][0];
          f[i][j][1]=f[i][j-1][1];
          f[i][j][2]=f[i][j-1][2];
        }  
      }
  }
}

int k=f[n][m][0];
int i=n,j=m;
 string ans="";
while(k!=0)
{
  int x=f[i][j][1];
  int y=f[i][j][2];
  i=x,j=y;
  ans+=a[i];
  k--;
}
reverse(all(ans));
cout<<ans;

 
return 0;
}
 
signed main()
{  int t=1;
//pri();
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    
     
 
  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
// cin>>t;
 
    int k=1;
     
   while(t--)
     {
      //cout<<"Case #"<<k<<":"<<" ";k++;
      solve();
     }
        exit(0);
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
 
  }


Measured memory_bytes: 211328
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if ( A == B ) cout << "Draw" << endl;
    else if (A == 1 || A > B && B != 1) cout << "Alice" << endl;
    else if (B == 1 || B > A) cout << "Bob" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	static int N, M, S, T, dp[][];
	static List<ArrayList<Integer>> to;
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		N = fs.nextInt();
		M = fs.nextInt();
		to = new ArrayList<>();
		for(int i=0;i<N;i++)to.add(new ArrayList<Integer>());
		for(int i=0;i<M;i++) {
			int u = fs.nextInt()-1, v = fs.nextInt()-1;
			to.get(u).add(v); 
		}
		S = fs.nextInt()-1;
		T = fs.nextInt()-1;
		
		dp = new int[N][3];//i番目の頂点にj%3歩で到達するときの最短手数
		int INF = Integer.MAX_VALUE/2;
		for(int t[]:dp) Arrays.fill(t, INF);
		
		//BFS
		Queue<Integer> q = new ArrayDeque<>(); 
		q.add(S);
		dp[S][0]=0;

		while(!q.isEmpty()) {
			int now = q.poll();
			for(int next : to.get(now)) {
				for(int i=0;i<3;i++) {
					int cnt = dp[now][i];
					if(cnt==INF)continue;
					if(i==0) cnt ++;
					if(dp[next][(i+1)%3]==INF) {
						dp[next][(i+1)%3]=cnt;
						q.offer(next);
					}else continue;
				}

			}
		}
		System.out.println(dp[T][0]==INF? -1:dp[T][0]);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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


int main(){
  unsigned long long int a,b,x,ans;
  cin>>a>>b>>x;
  if(a!=0)ans = b/x+1-(a-1)/x-1;
  else ans = b/x+1;

  cout<<ans<<endl;

}


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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;
#define sorti(x) sort(x.begin(), x.end())

const int MAX = 100010;
vector<pair<int, int> > edge[MAX];
int visited[MAX];
int d[MAX];

void dfs(int next, int cost) {
  visited[next] = true;
  d[next] = cost;
  for (auto to : edge[next]) {
    if (!visited[to.first]) dfs(to.first, cost + to.second);
    else {
      if (d[to.first] != cost + to.second) {
        cout << "No" << endl;
        exit(0);
      }
    }
  }
}

int main() {
  int n,m; cin >> n >> m;
  rep(i,m) {
    ll l,r,d; cin >> l >> r >> d;
    edge[l].pb({r,d});
    edge[r].pb({l,-d});
  }
  repr(i,n+1,1) {
    if(!visited[i]) dfs(i,0);
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 11392
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, S = 0;;
  std::cin >> N;
  std::vector<ll> A(N+1);
  ll now = -1, idx = -1;
  for(int i=1;i<=N;i++) {
    std::cin >> A[i];
    S+=A[i];
    if(now<A[i]) now = A[i], idx = i;
  }
  multimap<ll, ll, greater<ll> > front;
  multiset<ll> back;
  ll eq = 1;
  for(int i=1;i<idx;i++) front.emplace(A[i], i);
  for(int i=idx+1;i<=N;i++){
    if(A[i]==A[idx]) eq++;
    else back.insert(A[i]);
  }
  std::vector<ll> ans(N+1, 0);
  while(idx!=1){
    while(true){
      if((*front.begin()).second>idx) {
        back.insert((*front.begin()).first);
        front.erase(front.begin());
      }else break;
    }
    ll next_num = (*front.begin()).first;
    ans[idx]+=eq*(A[idx]-next_num);
    while(true){
      auto itr = back.lower_bound(next_num);
      if(itr==back.end()) break;
      eq++,ans[idx]+=(*itr)-next_num;
      back.erase(itr);
    }
    eq++;
    idx = (*front.begin()).second;
    front.erase(front.begin());
  }
  for(int i=1;i<=N;i++) S-=ans[i];
  for(int i=1;i<=N;i++) std::cout << (i==1?S:ans[i]) << "\n";
  return 0;
}


Measured memory_bytes: 8960
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[200005];
llint dp[200005][3];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = 0; i <= n+1; i++){
		for(int j = 0; j < 3; j++){
			dp[i][j] = -inf;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < n+1; i++){
		for(int j = 0; j < 3; j++){
			if(i+2 <= n+1) chmax(dp[i+2][j], dp[i][j] + a[i+1]);
			if(j+1 < 3) chmax(dp[i+1][j+1], dp[i][j]);
		}
	}
	cout << dp[n+1][n%2+1] << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define N 100010
#define M 200010
#define endl "\n"

ll gcd(ll a_,ll b_){if(b_>a_)swap(b_,a_);return (b_==0?a_:gcd(b_,a_%b_));}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	string s;
	
	cin >> s;
	
	s += '0';
	
	for(int i = 0; i < s.size() - 2; i++){
		if(s[i] == s[i + 1]){
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if(s[i] == s[i + 2]){
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	
	cout << -1 << " " << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
   
    int a;
   cin >> a;
    
    cout << a+ a*a + a*a*a << endl;
   




 return 0;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        
        if(A*B%2==0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 22608
package main

import "fmt"

func main() {
	var N uint
	var M int
	fmt.Scan(&N, &M)
	var nm [10][10]bool
	for i := 0; i < M; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a--
		b--
		nm[a][b] = true
		nm[b][a] = true
	}
	var full uint
	full = 1<<N - 1
	var ans int
	var dfs func(uint, uint)
	dfs = func(used uint, from uint) {
		if used == full {
			ans++
			return
		}
		for i := uint(0); i < N; i++ {
			if nm[from][i] {
				if !((used & (1 << i)) > 0) {
					n := used | (1 << i)
					dfs(n, i)
				}
			}
		}
	}
	dfs(1, 0)
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
using namespace std;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
inline int read() {
	rint s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
LL n,t;
int main() {
	rint i,j;
	scanf("%lld",&n);
	while(n) n>>=1,++t;
	printf("%lld",(1ll<<t)-1);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline
INF = pow(10,10)
# @njit
def solve(n,a):
  res = INF
  x = 0
  y = sum(a)
  for i in range(n-1):
    x += a[i]
    y -= a[i]
    res = min(res,abs(x-y))
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 30824
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  vector<int> A(4);
  for(int i=0;i<6;i++){
    int a;
    cin>>a;
    A[a-1]++;
  }
  for(int i:A)
    if(i==3){
      puts("NO");
      return 0;
    }
  puts("YES");
}

Measured memory_bytes: 3620
fn main() {
    let mut s = String::new();

    std::io::stdin().read_line(&mut s);
    let mut ss = s.trim().chars().collect::<Vec<char>>();
    let mut answer  = true;
    for i in 0..ss.len() {
        if i % 2== 0 {
            if ss[i] == 'L' {
                answer = false;
            }
        } else {
            if ss[i] == 'R' {
                answer = false;
            }
        }
    }
    if answer {
        println!("Yes")
    } else {
        println!("No")
    };
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define test lli t;cin>>t;while(t--)
#define arrin lli n;cin>>n;lli a[n];for(lli i=0;i<n;i++)cin>>a[i]
#define floop for(lli i=0;i<n;i++)
#define mod 1000000007
#define defvec vector<lli>v
#define ub upper_bound
#define pb push_back
#define bs binary_search
#define endl '\n'
using namespace std;
lli merge(lli a[],lli l,lli mid,lli r)
{
  lli i=l,j=mid,k=0;
  lli temp[r-l+1];
  lli ans=0;
 while(i<mid&&j<=r)
{
   if(a[i]<=a[j])
{
   temp[k++]=a[i++];
}
else
{
   temp[k++]=a[j++];
   ans+=mid-i;
}
}
while(i<mid)
temp[k++]=a[i++];
while(j<=r)
temp[k++]=a[j++];
for(lli i=l,k=0;i<=r;i++,k++)
{
  a[i]=temp[k];
}
return ans;
}
lli merge_sort(lli a[],lli l,lli r)
{  lli count=0;
  if(l<r)
{
   lli mid=l+(r-l)/2;
   lli right_count=merge_sort(a,mid+1,r);
   lli left_count=merge_sort(a,l,mid);
   lli mergingcount=merge(a,l,mid+1,r);
   return right_count+left_count+mergingcount;
}
return count;
}

int main()
{  
  lli n;
  cin>>n;
  lli a[n];
  for(lli i=0;i<n;i++)
  cin>>a[i];
  sort(a,a+n);
  double ans=0;
  double flag=a[0];
  for(lli i=1;i<n;i++)
  {   
      
          flag=(flag+a[i])/2*(1.0);
         
  }
  cout<<flag<<endl;
}

Measured memory_bytes: 256
main(I,O,J,L,d){
    scanf("%d%d%*d%d%d",&I,&O,&J,&L);
    printf("%lld",(long long)O+I+J+L-(I&&J&&L?(d=I%2+J%2+L%2)>1?3-d:d:I%2+J%2+L%2));
}

Measured memory_bytes: 128
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;

int n;
string id;
int m;
vector<int> a;
vector<int> wcard;
int dp[20][20];

inline int f(int n) {
    if(n<10) return n;
    int ret = n%10;
    ret += n/10;
    return ret;
}
inline bool ok(string s) {
    int sum = 0;
    int cnt=1;
    for(int i=s.size()-1;i>=0;i--) {
        if(cnt%2==0) {
            sum+=f((s[i]-'0')*2);
        }
        else {
            sum+=s[i]-'0';
        }
        cnt++;
    }
    return sum%10==0;
}
int64_t dfs(string s,int depth,int sum) {
    if(depth == wcard.size()) return sum%10==0;
    if(dp[depth][sum%10]!=-1) return dp[depth][sum%10];
    int64_t ret = 0;

    rep(i,a.size()) {
        char c = s[wcard[depth]];
        s[wcard[depth]] = a[i]+'0';
        int t;
        if((id.size()-wcard[depth])%2==0) {
            t=f(a[i]*2);
        }
        else {
            t=a[i];
        }
        ret += dfs(s,depth+1,sum+t);
        s[wcard[depth]] = c;
    }
    return dp[depth][sum%10] = ret;

}
int fsum(string s) {
    int sum = 0;
    rep(i,s.size()) {
        if(s[i]=='*') continue;
        if((id.size()-i)%2==0) {
            sum+=f((s[i]-'0')*2);
        }
        else {
            sum+=s[i]-'0';
        }
    }
    return sum;
}
int main() {
    rep(i,20) rep(j,20) dp[i][j]=-1;
    cin>>n;
    cin>>id;
    cin>>m;
    a.resize(m);
    rep(i,m) cin>>a[i];
    rep(i,id.size()) if(id[i]=='*') wcard.pb(i);
    int sum = fsum(id);
    int64_t ans = dfs(id,0,sum);
    cout<<ans<<endl;
    return 0;
}

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

typedef long long                   ll;
typedef long double                 ld;
typedef pair<ll,ll>                 pll;
typedef pair<ld,ld>                 pld;


#define all(x)          (x).begin(),(x).end()
#define Sort(x)         sort(all(x))
#define sep             ' '

#define endl            '\n'
#define tab             '\t'
#define X               first
#define Y               second
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define set_random      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 1e9 + 7,
         MAXN= 1e6+10,
         INF=1e18;
ll l,r,ans=INF;
int main()
{
    fast_io;
    cin>>l>>r;
    if((l<=2019 && r>=2019) || (r-l+1>=2019))return cout<<0<<endl,0;
    for(ll i=l;i<=r;i++){
        for(ll j=i+1;j<=r;j++){
            ans=min(ans,i*j%2019);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  long long x,y; cin>>x>>y;
  if(x==1 && y==1) cout<<1;
  else if(x==1 || y==1) cout<<max(x,y)-2;
  else cout<<(x-2)*(y-2);
  cout<<endl;
}


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

int N;
int S[210][210];

void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       
    for (int i = 0; i < n; i++) {    
      for (int j = 0; j < n; j++) {  
        S[i][j] = min(S[i][j], S[i][k] + S[k][j]);
      }
    }
  }
}

using Graph = vector<vector<int>>;

vector<int> color;
bool dfs(const Graph &G, int v, int cur = 0) {
    color[v] = cur;
    for (auto next_v : G[v]) {
        if (color[next_v] != -1) {
            if (color[next_v] == cur) return false; 
            continue;
        }

        if (!dfs(G, next_v , 1 - cur)) return false;
    }
    return true;
}

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

    Graph G(N);
    for (int i = 0; i < N; i++) {
        string line;
        cin >> line;
        for (int j = 0; j < N; j++) {
            if (i == j) {
                S[i][j] = 0;
            }
            else if (line[j] == '1') {
                S[i][j] = 1;
                G[i].push_back(j);
            }
            else {
                S[i][j] = 1.0e9;
            }
        }
    }

    color.assign(N, -1);
    bool is_bipartite = true;
    for (int v = 0; v < N; v++) {
        if (color[v] != -1) continue; 
        if (!dfs(G, v)) is_bipartite = false;
    }

    if (is_bipartite) {
        warshall_floyd(N);

        int max_s = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                max_s = max(max_s, S[i][j]);
            }
        }

        cout << max_s + 1 << endl;
    }
    else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 640
import bisect
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    T = input()
    N = len(S)
    idx = defaultdict(list)
    for i, s in enumerate(S):
        idx[s].append(i)

    # 直前にみたx
    x = -1
    n_loop = 0
    for t in T:
        arr = idx[t]
        if len(arr) == 0:
            print(-1)
            return

        x += 1
        i = bisect.bisect_left(arr, x)
        if i < len(arr):
            x = arr[i]
        else:
            n_loop += 1
            x = arr[0]

    print(n_loop * N + x + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,c;
	cin>>n>>c;
	vector<int> d;
	int tmp = 0;
	d.push_back(tmp);
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		tmp+=a;
		d.push_back(tmp);
	}
	int sum = 0;
	for(int i=0;i<=n;i++)
	{
		int a = d[i];
		if(a<=c)
		{
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

int main() {
  ll n, k; cin >> n >> k;
  vll a(n); REP(i, n) cin >> a.at(i);
  vll dp(100005, 0);
  rep(i, 1, k+1) {
    rep(j, 0, n) {
      if (i-a.at(j)>=0 && dp.at(i-a.at(j))==0) dp.at(i)=1;
    }
  }
  if (dp.at(k) == 1) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string x;
  int cnt = 0;

  cin >> x;

  for(int i = 0;i < x.size() - 1;i++){
    if(x[i] != x[i + 1]) cnt++;
  }

  cout << cnt << endl;
  return 0;
}


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

class Node():
    def __init__(self, parent = -1, left = -1, right = -1):
        self.parent = parent
        self.left = left
        self.right = right

binary_tree = [Node() for _ in range(N)]
for _ in range(N):
    node_input = input()
    id, left, right = map(int, node_input.split())

    binary_tree[id].left = left
    binary_tree[id].right = right

    if left != -1:
        binary_tree[left].parent = id
    if right != -1:
        binary_tree[right].parent = id


def set_depth(id, depth):
    if id == -1:
        return

    D[id] = depth
    set_depth(binary_tree[id].left, depth+1)
    set_depth(binary_tree[id].right, depth+1)

def set_height(id):
    h1, h2 = 0, 0
    if binary_tree[id].left != -1:
        h1 = set_height(binary_tree[id].left) + 1
    if binary_tree[id].right != -1:
        h2 = set_height(binary_tree[id].right) + 1
    H[id] = max(h1, h2)
    return H[id]


D = [0 for i in range(N)]
H = [0 for i in range(N)]
for id in range(N):
    if binary_tree[id].parent == -1:
        set_depth(id, 0)
        set_height(id)
        break



def get_sibling(id):
    parent_id = node.parent
    if parent_id == -1:
        return -1
    if binary_tree[parent_id].left != id:
        return binary_tree[parent_id].left
    else:
        return binary_tree[parent_id].right

def get_degree(node):
    degree = 0
    if node.left != -1:
        degree += 1
    if node.right != -1:
        degree += 1
    return degree

def get_type(node, dgree):
    if node.parent == -1:
        return "root"
    if degree == 0:
        return "leaf"
    return "internal node"

for id in range(N):
    node = binary_tree[id]
    parent_id = node.parent
    sibling_id = get_sibling(id)
    degree = get_degree(node)
    node_type = get_type(node, degree)
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(id, parent_id, sibling_id, degree, D[id], H[id], node_type))


Measured memory_bytes: 5624
#include<stdio.h>
int main(){
  int n,m,a,b[100010],c=0,i,k;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%d",&k);
    while(k--){
      scanf("%d",&a);
      b[a]++;
    }
  }
  for(i=1;i<=m;i++){
    if(b[i]==n)c++;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        aa[x]++;
        aa[y]++;
        
    }
    for(int i=0;i<n;i++){
        C aa[i+1] E;
    }
    
    
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false);
      int a,b,flag;
      char ch;
      cin>>a>>b;
      for(int i= 0;i<a;i++){
            flag = -1;
            for(int j = 0 ; j < b;j++){
                  cin >> ch;
                  if(ch == 'c'){
                        cout << '0';
                        flag = 0;
                  }else{
                        if (flag == -1)cout << flag;
                        else cout << ++flag;
                 }
                  if(j!=b-1)cout << ' ';
            }
            cout<<endl;
      }
}

Measured memory_bytes: 1196
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"10
ZABCDBABCQ"# => r#"2"#,

r#"19
THREEONEFOURONEFIVE"# => r#"0"#,

r#"33
ABCCABCBABCCABACBCBBABCBCBCBCABCB"# => r#"5"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        _n: usize,
        s: String,
    }

    s.matches("ABC").count().to_string()
}

Measured memory_bytes: 4352
//shara's here
//私は大きな男の子
//SPEEEEEEEEEED IS KEEEEEEEEEEY
#include <bits/stdc++.h>
using namespace std;
//fold
typedef double w;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
#if defined(BANYANYA)
#include "/home/a/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//endfold
bool isPrime(ll x){
	for(ll i=2;i*i<=x;i++){
		if(x%i==0){
			return false;
			}
		}
		return true;
	}
int main(){
	ll x;
	cin>>x;
	bool ok=isPrime(x);
	if(ok)cout<<x<<endl;
	else{
		bool f=false;
		while(!f){
			x++;
			f=isPrime(x);
			}
			cout<<x<<endl;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
from collections import deque

n, q = map(int, input().split())
links = [[] for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)

ans = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    ans[p - 1] += x

deq = deque([0])
seen = [False] * n
while deq:
    parent = deq.popleft()
    link = links[parent]
    for v in link:
        if not seen[v]:
            ans[v] += ans[parent]
            deq.append(v)
    seen[parent] = True

print(*ans)

Measured memory_bytes: 56080
// A - Plural Form
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    string s;
    cin >> s;
    int len = s.size();
    if(s[len-1] == 's') s = s+"es";
    else s = s+"s";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int maxn=(1e5+10);
int n,frst=-1,cnt[maxn];
vector<int> edge[maxn],vv;
void dfs(int v,int par)
{
	cnt[v]=1;
	vv.push_back(v);
	if(v==n-1)
		frst=vv[((int)vv.size()+1)/2];
	for(int i=0;i<edge[v].size();i++)
	{
		int to=edge[v][i];
		if(par==to)
			continue;
		dfs(to,v);
		cnt[v]+=cnt[to];
	}
	vv.pop_back();
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		--a,--b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	dfs(0,0);
	bool win=cnt[frst]*2<n;
	puts(win?"Fennec":"Snuke");
	return 0;
}

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

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

    int M=abs(a[1]-a[0]);
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            M=max(M,abs(a[i]-a[j]));
        }
    }

    cout<<M<<endl;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  int n, m; rd(n, m);
  auto g=new int[][](n, 0);
  foreach(_; 0..m){
    int a, b; rd(a, b);
    a--; b--;
    g[a]~=b; g[b]~=a;
  }

  auto c=new int[](n);
  fill(c, -1);
  bool dfs(int i, int w, int p=-1){
    c[i]=w;
    bool ret=true;
    foreach(j; g[i])if(j!=p){
      if(c[j]==-1) ret&=dfs(j, w^1, i);
      if((c[j]^w)==0) ret=false; 
    }
    return ret;
  }

  if(dfs(0, 0)){
    long w=0;
    foreach(e; c)if(e==0) w++;
    writeln(w*(long(n)-w)-m);
  }else{
    writeln(long(n)*(n-1)/2-m);
  }

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  bool front = true;
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }

  for(int i = n - 1; i >= 0; i -= 2) cout << a[i] << " ";
  for(int i = (n & 1); i < n; i += 2) cout << a[i] << " ";
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

void solve(){
    int N, p, ans = 0;
    cin >> N;
    vector<int> a(N+1, 0);
    a[0] = -1;
    FOR(i,1,N+1){
        cin >> a[i];
    }
    FOR(i,1,N+1){
        if(a[a[i]] == i){
            ans++;
        }
    }
    cout << ans/2 << endl;
}

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

    solve();
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
char a[7],b[7];
int main()
{
    cin>>a>>b;
    strcat(a,b);
    int ai=atoi(a);
    for(int i=1;i*i<=ai;i++)
        if(i*i==ai)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        //String temp = scan.nextLine();
        double A = 0;
        for(int i = 0 ; i < N ; i++){
            A = A + 1 / scan.nextDouble();
        }
        System.out.println(1 / A);
    }
}


Measured memory_bytes: 24404
#include <bits/stdc++.h>
#define i64 long long
#define maxn (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
	int n; cin>>n;
	int V[n], C[n];
	for(int i=0;i<n;i++) cin>>V[i];
	for(int i=0;i<n;i++) cin>>C[i];
	
	int dif, maxDif = INT_MIN;
	for(int i=0;i<(1<<n);i++){
		int total_val = 0, total_cost = 0;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				total_val+=V[j];
				total_cost+=C[j];
			}
		}
		maxDif = max(maxDif, total_val-total_cost);
	}
	printf("%d\n",maxDif);
	return 0;
}

Measured memory_bytes: 256