akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#define PI  3.141592653589

int main()
{
  double x = 0, y = 0;
  int d, a, angle = 90;
  int ans_x, ans_y;

  while (1) {
    scanf("%d,%d", &d, &a);

    if (d == 0 && a == 0)
      break;

    x += cos(angle * PI / 180.0) * d;
    y += sin(angle * PI / 180.0) * d;

    angle -= a;
  }

  ans_x = x;
  ans_y = y;

  printf("%d\n%d\n", ans_x, ans_y);

  return 0;
}

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

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

  int n = s.size();

  int t = 0;
  for(int i = 0; i < (n / 2); i++){
    if(s[i] != s[n - 1 - i]){
      t++;
    }
  }

  cout << t << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
int lenof(int src)
{
    bool leaf=1;
    if(dp[src]!=-1)
    {
        return dp[src];
    }
    int bestchild=0;
    for(auto child:graph[src])
    {
        leaf=0;
        bestchild=max(bestchild,lenof(child));

    }
    return dp[src]=leaf?0:1+bestchild;
}
int main() {
    memset(dp,-1,sizeof(dp));
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {   int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
    
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,lenof(i));
    }
    cout<<ans;
}


Measured memory_bytes: 11324
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int A[3]={0};
  int min=100, max=0;

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

  int ans=0;

  for(int i=0; i<3; i++){
    if(A[i]>max) max=A[i];
    if(A[i]<min) min=A[i];
  }

  ans = max - min;

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


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

using namespace std;
long long calc(long long buy, long long sell, long long val)
{
	long long nr=val/buy;
	long long rest=val%buy;
	
	return nr*sell+rest;
}
long long n,i,j,d,ans;
long long a[85];
long long dp[85];
long long mini[85][85];
int main(int argc, char **argv)
{
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
		
	for(d=0;d<n;d++)
	{
		for(i=1;i+d<=n;i++)
		{
			if(d==0)
				mini[i][i+d]=a[i];
			else
				mini[i][i+d]=min(mini[i+1][i+d], a[i]);
		}
	}
	
	dp[0]=1000;
	
	for(i=2;i<=n;i++)
	{
		dp[i]=1000;
		dp[i]=max(dp[i], calc(mini[1][i-1], a[i], 1000));
		
		for(j=2;j<i-1;j++)
		{
			dp[i]=max(dp[i], calc(mini[j+1][i-1], a[i], dp[j]));
		}
	}
	
	ans=1000;
	for(i=2;i<=n;i++)
		ans=max(ans, dp[i]);
		
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(k,i,n) for(int i = (k); i < (int)(n); i++)
typedef long long ll;
typedef pair<double,double> Pdd;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<max(a-b*2,0);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int h=sc.nextInt();
		int w=sc.nextInt();
		int ah=H-h;
		int aw=W-w;
		int ans=ah*aw;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(c>=a&&c<=b)
    {
        printf("Yes\n");
    }
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    int N,M,C;cin >> N >> M >> C;
    vector<int> B;
    for(int a = 0;a < M;a++){
        int b;cin >> b;
        B.push_back(b);
    }
    int ans = 0;
    for(int a = 0;a < N;a++){
        int ins = C;
        for(int b = 0;b < M;b++){
            int w;cin >> w;
            ins += B.at(b)*w;
        }
        if(ins > 0)ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n,f=0;
  cin>>n;
  for(int i=0;i<n;i++){
     int x;
    cin>>x;
    if(x%2==0){
    if((x%3)!=0 && (x%5)!=0 )
     {
      f=1;
     }
    }
  }
  if(f==1){
  cout<<"DENIED";
  }
  else
    cout<<"APPROVED";
}

Measured memory_bytes: 3568
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, a, ans = INF;
	cin >> n;
	while (n--) {
		cin >> a;
		int c = 0;
		while (a % 2 == 0) {
			a /= 2;
			c++;
		}
		ans = min(ans, c);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 3; i++)
	{
		if (i != a && i != b)
		{
			cout << i << endl;
		}
	}
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    string s, t;
    int ans = 0;
    cin >> s >> t;
    for (int i = 0, l = s.size(); i < l; ++i) {
        if (s[i] != t[i]) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3920
#include<utility>
#include<vector>
#include<functional>
#include<algorithm>
#include<iostream>

using namespace std;

struct Edge{
	int from,to; //if you want cost, etc., you should care //about the "emplace_back(line36,line118).
	Edge(int f,int t){
		from=f;
		to=t;
	}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

pair<vector<int>,Edges> bridge(const Graph& g){
	const int n=g.size();
	int idx=0,s=0,t=0,k=0;
	vector<int>ord(n,-1),onS(n),stk(n),roots(n),cmp(n);
	Edges brdg;
	function<void(int,int)> dfs = [&](int v,int u){
		ord[v]=idx++;
		stk[s++]=v;
		onS[v]=true;
		roots[t++]=v;
		for(auto& e:g[v]){
			int w=e.to;
			if(ord[w]==-1)dfs(w,v);
			else if(u != w && onS[w])
			       while(ord[roots[t-1]]>ord[w])-t;
		}
		if(v==roots[t-1]){
			brdg.emplace_back(u,v);
			while(true){
				int w=stk[--s];
				onS[w]=false;
				cmp[w]=k;
				if(v==w)break;
			}
			--t;
			++k;
		}
	};
	for(int u=0;u<n;++u){
		if(ord[u]==-1){
			dfs(u,n);
			brdg.pop_back();
		}
	}
	return make_pair(cmp,brdg);
}

vector<int>ArticulationPoint(const Graph& g){
	int n=g.size(),idx;
	vector<int>low(n),ord(n),art;
	function<void(int)>dfs=[&](int v){
		low[v]=ord[v]=++idx;
		for(auto& e:g[v]){
			int w=e.to;
			if(ord[w]==0){
				dfs(w);
				low[w]=min(low[v],low[w]);
				if((ord[v]==1 && ord[w]!=2)||(ord[v]!=1 && low[w]>=ord[v]))
					art.push_back(v);
			}else
				low[v]=min(low[v],ord[w]);
		}
	};
	for(int u=0;u<n;++u){
		if(ord[u]==0){
			idx=0;
			dfs(u);
		}
	}
	return art;
}

vector<int> tarjan(const Graph& g){
	int n=g.size(),idx=0,k=0,s=0;
	vector<int>ord(n,-1),low(n),onS(n),cmp(n),stk(n);
	function<void(int)>dfs;
	dfs=[&](int v){
		ord[v]=low[v]=idx++;
		stk[s++]=v;
		onS[v]=true;
		for(auto &e:g[v]){
			int w=e.to;
			if(ord[w]==-1){
				dfs(w);
				low[v]=min(low[v],low[w]);
			}else if(onS[w]){
				low[v]=min(low[v],ord[w]);
			}
		}
		if(low[v]==ord[v]){
			while(1){
				int w=stk[--s];
				onS[w]=false;
				cmp[w]=k;
				if(w==v)break;
			}
			++k;
		}
	};
	for(int v=0;v<n;++v)
		if(ord[v]==-1)dfs(v);
	return cmp;
}

vector<int> kosaraju(const Graph& g){
	int n=g.size(),sz=0;
	Graph rg(n);
	vector<int>stk,cmp(n,-1),added(n),visited(n),ord(n);
	for(auto &es:g){
		for(auto &e:es)rg[e.to].emplace_back(e.to,e.from);
		sz+=es.size();
	}
	stk.resize(n+sz);
	sz=0;
	for(int i=0;i<n;++i){
		if(visited[i])continue;
		int s=0;
		stk[s++]=i;
		while(s!=0){
			int v=stk[s-1];
			visited[v]=true;
			bool pushed=false;
			for(auto &e:g[v]){
				int to=e.to;
				if(!visited[to]){
					stk[s++]=to;
					pushed=true;
				}
			}
			if(pushed)continue;
			int t=stk[s-1];
			if(!added[t]){
				added[t]=true;
				ord[n-++sz]=t;
			}
			--s;
		}
	}
	int k=0;
	for(int &u:ord){
		if(cmp[u]!=-1)continue;
		int s=0;
		stk[s++]=u;
		while(s!=0){
			int v=stk[--s];
			cmp[v]=k;
			for(auto &e:rg[v]){
				int t=e.to;
				if(cmp[t]==-1)stk[s++]=t;
			}
		}
		++k;
	}
	return cmp;
}

int main(){
	int V,E;
	cin>>V>>E;
	Graph g(V);
	for(int i=0;i<E;++i){
		int s,t;cin>>s>>t;
		g[s].emplace_back(s,t);
	}
	int Q;cin>>Q;
	vector<int>SCC=tarjan(g);
	for(int i=0;i<Q;++i){
		int u,v;cin>>u>>v;
		cout<<(SCC[u]==SCC[v])<<endl;
	}
}

Measured memory_bytes: 4336
#include<iostream>
using namespace std;
int main (void)
{
  int i,j,k,n,MOD=1000000007;
  long long int a[200000],sum,ans,c;
  
  cin>>n;
  for(i=0;i<n;i++){cin>>a[i];}
  ans=0;sum=0;
  
  for(i=0;i<n;i++){sum+=a[i];}
  
  for(i=0;i<n;i++)
  {
    sum=sum-a[i];
    c=sum%MOD;
    a[i]=a[i]%MOD;
    ans=ans+a[i]*c;
    ans=ans%MOD;
    
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5100
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#define ll long long
using namespace std;
int ishui(string s){
	int n=s.size();
	for(int i=0;i<s.size()/2;i++){
		if(s[i]!=s[s.size()-i-1]){
			return 0;
		}
	}
	return 1;
}
int main(){
	ll a,b;
	cin>>a>>b;
	int ans=0;
	for(ll i=a;i<=b;i++){
		string s=to_string(i);
		if(ishui(s)){
			ans++;
		}
	} 
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#126_D
import sys
sys.setrecursionlimit(500000)

n=int(input())
edges=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    edges[u-1].append((v-1,w))
    edges[v-1].append((u-1,w))
visit=[False for _ in range(n)]
d=[0 for i in range(n)]

def dfs(i):
    visit[i]=True
    for v,w in edges[i]:
        if visit[v]==False:
            d[v]=(d[i]+w)%2
            dfs(v)
            
dfs(0)
print(*d,sep='\n')

Measured memory_bytes: 80260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

ll f(ll x)
{
    ll ans = 0;
    ll cnt = 0;
    while (1)
    {
        ans = ans + cnt;
        if (ans >= x)
        {
            if (ans == x)
            {
                return cnt;
            }
            else
            {
                return cnt - 1;
            }
        }
        cnt++;
    }
    return 0;
}

int main()
{
    ll n, NUM;
    ll ans = 0;
    cin >> n;
    NUM = n;
    vector<ll> primes;

    ll cnt = 0;

    for (ll i = 2; i * i <= NUM; ++i)
    {
        cnt = 0;
        while (n % i == 0)
        {
            cnt++;
            // x.at(i)++;
            n /= i;
        }
        if (cnt)
        {
            // cout << i << " " << cnt << endl;
            ans += f(cnt);
        }
    }

    if (n != 1)
    {
        // x.at(num)++;
        ans++;
    }

    // for (int i = 2; i <= n; i++)
    // {
    //     ans += f(x.at(i));
    // }
    // if (num != 1)
    // {
    //     ans++;
    // }

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


Measured memory_bytes: 3592
import bisect

s = input()
t = input()

li = [[] for _ in range(26)]
for i in range(len(s)):
    li[ord(s[i]) - ord('a')].append(i)

count = [0,-1]

for i in range(len(t)):
    t1 = t[i]
    num = ord(t1) - ord('a')
    if not li[num]:
        print(-1)
        exit()
    else:
        if count[1] >= li[num][-1]:
            count[0] += 1
            count[1] = li[num][0]
        else:
            idx = bisect.bisect_right(li[num], count[1])
            count[1] = li[num][idx]

print(count[0] * len(s) + count[1] + 1)


Measured memory_bytes: 7540
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int64_t N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    for(int i=0; i<N; i++) {
        cin >> a[i] >> b[i];
    }
    int64_t m = *max_element(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    int i;
    for(i=0; i<N; i++) {
        if(b[i] >= m) {
            H -= b[i];
            if(H <= 0) {
                cout << i+1 << endl;
                return 0;
            }
        } else {
            break;
        }
    }
    cout << i + (H+m-1)/m << endl;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
M = 10**9+7
if A[0] != 0:
    print(0)
    exit()
ans = 1
g0 = 0
g1 = 0
g2 = 0
for a in A:
    if g0==g1==g2:
        if a == g0:
            ans = (ans*3)%M
            g0 += 1
        else:
            ans = 0
    elif g0==g1:
        if a == g0:
            ans = (ans*2)%M
            g0 += 1
        elif a == g2:
            g2 += 1
        else:
            ans = 0
    elif g1==g2:
        if a == g0:
            g0 += 1
        elif a == g1:
            ans = (ans*2)%M
            g1 += 1
        else:
            ans = 0
    else:
        if a == g0:
            g0 += 1
        elif a == g1:
            g1 += 1
        elif a == g2:
            g2 += 1
        else:
            ans = 0
print(ans%M)

Measured memory_bytes: 14396
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>

using namespace std;


int main(void)
{
    long int L,R;
    cin>>L>>R;
    if(R-L>2019){
        cout<<0<<endl;
    }
    else{
        int min=9999;
        for(int i=L;i<R;i++){
            for(int j=i+1;j<=R;j++){
                if(((i%2019)*(j%2019))%2019<min){
                    min=((i%2019)*(j%2019))%2019;
                }
            }
        }
        cout<<min<<endl;
    }
    
    
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF 1000000000
#define EPS      1e-10
#define MOD      1000000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

string str;
int n;

int dfs(string s, int pre){
    int now = 0;
    int ret = 0;
    while(true){
        while('A' <= s[now] && s[now] <= 'Z'){
            ret++;
            if(n == ret+pre){
                cout << s[now] << endl;
                return -1;
            }
            now++;
            if(now == s.size()){
                return ret;
            }
        }
        int num = 0;
        while('0' <= s[now] && s[now] <= '9'){
            num = num*10+s[now]-'0';
            now++;
        }
        string foo;
        int kakko = 0;
        while(true){
            now++;
            if(s[now] == ')') kakko--;
            if(s[now] == '(') kakko++;
            if(kakko < 0){
                int d = dfs(foo,ret+pre);
                if(d == -1) return -1;
                if(ret+pre+num*d >= n){
                    n -= (ret+pre);
                    n %= d;
                    if(n == 0) n = d;
                    dfs(foo,0);
                    return -1;
                }
                ret += num*d;
                break;
            }
            foo.push_back(s[now]);
        }
        now++;
        if(now == s.size()) return ret;
    }
    return ret;
}

int main(){
    while(cin >> str >> n){
        if(str == "0" && n == 0) break;
        n++;
        string tmp;
        rep(i,str.size()){
            if('A' <= str[i] && str[i] <= 'Z'){
                if(i != 0 && ('0' <= str[i-1] && str[i-1] <= '9')){
                    tmp.push_back('(');
                    tmp.push_back(str[i]);
                    tmp.push_back(')');
                } else{
                    tmp.push_back(str[i]);
                }
            } else{
                tmp.push_back(str[i]);
            }
        }
        str = tmp;
        if(dfs(str,0) != -1){
            cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 2996
n =int(input())
a = list(map(int,input().split()))

seta = sorted(list(set(a)))

resn = max(seta)
resr = seta[0]
for sa in seta:
    sabun = abs(resn / 2 - sa)
    if sabun < abs(resn / 2 - resr):
        resr = sa

print(str(resn) + " " + str(resr))

Measured memory_bytes: 15708
n= int(input())
import math
INF = 10**12
ans =INF
for i in range(math.floor(n**0.5)):
  if n%(i+1)==0:
    if ans > (i+1)+(n/(i+1)):
      ans = (i+1)+(n/(i+1))
print(int(ans-2))

Measured memory_bytes: 3064
n, m = map(int, input().split())

prefectures = []
for i in range(m):
    p, y = map(int, input().split())
    prefectures.append({'i': i, 'p': p, 'y': y})

prefectures.sort(key=lambda x: (x['p'], x['y']))

ans = []
cnt = 1
for i in range(len(prefectures)):
    if i != 0:
        if prefectures[i-1]['p'] == prefectures[i]['p']:
            cnt += 1
        else:
            cnt = 1
    s = str(prefectures[i]['p']).zfill(6)+str(cnt).zfill(6)
    ans.append({'i': prefectures[i]['i'], 'p': s})


ans.sort(key=lambda x: x['i'])

for x in ans:
    print(x['p'])


Measured memory_bytes: 126040
n = int(input())
a = list(map(int, input().split()))

flag = False
ans = 0
b = [0] * n

# 報告があっているか
if n % 2 == 0:
    for i in range(0, n, 2):
        b[i] = i + 1
        b[i + 1] = i + 1
else:
    for i in range(1, n, 2):
        b[i] = i + 1
        b[i + 1] = i + 1

if b == sorted(a):
    ans = (2 ** (n // 2)) % (10 ** 9 + 7)

print(ans)


Measured memory_bytes: 14008
//137 B - One Clue 2019/08/10

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int k , x; cin >> k >> x;
    set<int> st;
    //set<int>::iterator itr;
    for(int i=x;i<=x+k-1;++i){
        st.insert(i);
    }
    for(int i=x-k+1;i<=x;++i){
        st.insert(i);
    }
    for(auto itr=st.begin();itr!=st.end();++itr){
        cout << *itr << " ";
    }
    
    cout << endl;
}

Measured memory_bytes: 256
mod = 10**9+7
N, K = map(int,input().split())
A = sorted(list(map(int,input().split())))

p = 1
n = 0
ans = 1
cnt = 0
while cnt < K-1:
  if A[n]*A[n+1] > A[-p]*A[-p-1]:
    ans = ans*A[n]*A[n+1]%mod
    n += 2
    cnt += 2
    
  else:
    ans = ans*A[-p]%mod
    p += 1
    cnt += 1
    
if cnt == K-1:
  ans = ans*A[-p]%mod
  
if A[-1]<0 and K%2==1:
  ans = 1
  for i in A[N-K:]:
    ans = ans*i%mod

print(ans)

Measured memory_bytes: 33300
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
using namespace std;

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[2] * 10 + a[1] + a[0];
	return 0;
}

Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
import Data.Int (Int64)
import qualified Data.ByteString.Char8 as BS

main = do
  s <- BS.getLine
  k <- readLn :: IO Int64
  let ss = BS.group s
  let l = length ss
  let result | l == 1 = k * fromIntegral (BS.length s) `quot` 2
             | BS.head s == BS.last s = let ss0 = head ss
                                            ssz = last ss
                                        in fromIntegral (BS.length ss0 `quot` 2) + k * fromIntegral (sum $ map (\t -> BS.length t `quot` 2) $ init $ tail ss) + fromIntegral (BS.length ssz `quot` 2) + (k-1) * fromIntegral ((BS.length ss0 + BS.length ssz) `quot` 2)
             | otherwise = k * fromIntegral (sum $ map (\t -> BS.length t `quot` 2) ss)
  print result


Measured memory_bytes: 508
/*
 * main.c
 *
 *  Created on: 2019/01/12
 *      Author: family
 */


#include <stdio.h>
#include <stdlib.h>

int lessthan(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
	int n_problem = 0;
	int n_problem_max = 0;
	int a_low_point = 0;
	int b_high_point = 0;
	int p_point[101] = {0};
	int i = 0;
	int j = 0;
	int count[3] = {0};


	scanf("%d", &n_problem);
	n_problem_max = n_problem;
	scanf("%d %d", &a_low_point, &b_high_point);
	for(i = 0; i < n_problem; i++) {
		scanf("%d", &p_point[i]);
	}

	i = 0;
    j = 0;
    for(i = 0; i < n_problem; i++) {
    	if (p_point[i] <= a_low_point) {
    		count[0]++;
    	}
    }
    for(i = 0; i < n_problem; i++) {
    	if ((p_point[i] > a_low_point) && (p_point[i] <= b_high_point)) {
    		count[1]++;
    	}
    }
    for(i = 0; i < n_problem; i++) {
    	if (p_point[i] > b_high_point) {
    		count[2]++;
		}
    }

    if (count[0] > count[1]) {
    	if (count[1] > count[2]) {
    		i = count[2];
    	} else {
    		i = count[1];
    	}
    } else {
    	if (count[0] > count[2]) {
    		i = count[2];
    	} else {
    		i = count[0];
    	}

    }

    printf("%d",i);

    return 0;
}



Measured memory_bytes: 128
/*
  A - Remaining Time
  Contest 057
  Rakesh Kumar --> 20/08/2020
 */

#include <bits/stdc++.h>

using ll = long long int;

struct Point {
    Point(ll a, ll b) : x(a), y(b) {}
    ll x = 0;
    ll y = 0;
};

inline ll dist(const Point& a, const Point& b) {
    return std::abs(a.x - b.x) + std::abs(a.y - b.y);
}

inline int pos(const Point& pos, const std::vector<Point>& checkpoints) {
    ll min = dist(pos, checkpoints[0]);
    int p = 1;
    for (std::size_t i = 1; i < checkpoints.size(); ++i) {
        const ll d = dist(pos, checkpoints[i]);
        if (d < min) {
            p = i + 1;
            min = d;
        }
    }
    return p;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int n = 0, m = 0;
    std::cin >> n >> m;
    std::vector<Point> students;
    while (n--) {
        ll a = 0, b = 0;
        std::cin >> a >> b;
        students.emplace_back(Point(a, b));
    }
    std::vector<Point> checkpoints;
    while (m--) {
        ll a = 0, b = 0;
        std::cin >> a >> b;
        checkpoints.emplace_back(Point(a, b));
    }

    for (const Point& p : students)
        std::cout << pos(p, checkpoints) << std::endl;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s = to_string(n);
	string rs = s;
	reverse(rs.begin(),rs.end());
	// cout << s << endl << rs << endl;
	if(s == rs)
		cout << "Yes" <<endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
/*input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
    os << x << " ";
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

/******************************** START *********************************/
const int N = 100005;
vector < vector < int > > v;
int dp[N][4];

int func(int n, int prev)
{
  if(n == 0) {
    return 0;
  }
  if(dp[n][prev] > -1) {
    return dp[n][prev];
  }

  int res = 0;
  for(int i = 0; i < 3; i ++) {
    if(i == prev) continue;
    res = max(res, v[n - 1][i] + func(n - 1, i));
  }
  return dp[n][prev] = res;
}

int main()
{
  ifalse;
  int n;
  cin >> n;
  v.assign(n, vector < int >(3, 0));
  cin >> v;

  memset(dp, -1, sizeof(dp));
  cout << func(n, 3);
  return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  REP(i, (SZ(s) / 2)) {
    if (s[i] != s[SZ(s) - 1 - i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;

//ここから編集する

int main() {
    int n;
    ll a[51];

    cin >> n;

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

    ll all = 1;
    ll result = 0;
    while(all > 0){
        all = 0;
        for(int i = 1; i<= n; i++){
            all += a[i]/n;
            a[i] = a[i] % n - a[i]/n;
        }
        for(int i = 1; i<= n; i++){
            a[i] += all;
        }
        result += all;
    }

    cout << result << endl;


    return 0;
}

Measured memory_bytes: 256
n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)

even_arr = []
odd_arr = []

n.times do |i|
  if (i + 1) % 2 == 0
    even_arr << a[i]
  else
    odd_arr << a[i]
  end
end

# 偶数個のとき
if n % 2 == 0
  puts even_arr.reverse.push(odd_arr).flatten
else
  puts odd_arr.reverse.push(even_arr).flatten
end

Measured memory_bytes: 26980
n = int(input())
A = list(map(int, input().split()))
A.sort()
#print(A)
m = max(A)
dp = [0] * (m + 1)

for a in A:
    if dp[a] >= 1:
        dp[a] += 1
    for i in range(2 * a, m + 1, a):
        dp[i] += 2
    dp[a] += 1
print(dp.count(1))


Measured memory_bytes: 32228
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N;

vector<int> each_digit(ll S) {
    int n_len = 0, n_dig[16];
    while (S > 0) {
        n_dig[n_len++] = S % 10;
        S /= 10;
    }
    vector<int> ret(n_dig, n_dig + n_len);
    reverse(ret.begin(), ret.end());
    return ret;
}

void solve() {
    vector<int> dig = each_digit(N);
    int max_dig = -1, second_dig = -1;
    REP(i, dig.size()) {
        if (dig[i] != 9) {
            if (max_dig == -1) max_dig = i;
            else if (second_dig == -1) second_dig = i;
        }
    }
    int ans = 0;
    if (dig.size() == 1) ans = dig[0];
    else if (max_dig == -1) {
        REP(i, dig.size()) ans += 9;
    } else if (max_dig == 0) {
        if (second_dig == -1) {
            REP(i, dig.size()) ans += dig[i];
        } else {
            REP(i, dig.size()) {
                if (i == 0)ans += dig[0] - 1;
                else ans += 9;
            }
        }
    } else {
        REP(i, dig.size()) {
            if (i == max_dig - 1) ans += dig[i] - 1;
            else if (i < max_dig) ans += dig[i];
            else ans += 9;
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    solve();
    return 0;
}

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

int main() {
    int r, d;
    int x[11];
    cin >> r >> d >> x[0];
    for(int i = 0; i < 10; i++){
        x[i + 1] = r * x[i] - d;
        cout << x[i + 1] << endl;
    }
    return (0);
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 998244353;

int primes[784500]; int cnt;
short g[1000006];
void sve(int n) {
	memset(g, 0x3f, sizeof g);
	g[0] = 0;
	g[1] = 1;
	iter(i, 2, n+1) {
		if(g[i] == 0x3f3f) {
			primes[cnt++] = i;
			g[i] = -1;
		}
		for(int j=0; j<cnt && i*primes[j]<=n; j++) {
			int v = i*primes[j];
			if(i%primes[j]) {
				g[v] = -g[i];
			} else {
				g[v] = 0;
				break;
			}
		}
	}
}

int T[1000004];
int inv[1000006];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N; gi(N);
	int ans = 0;
	rep(i, N) {
		int a, d; gi(a);
		ans -= a;
		if(ans < 0) ans += MOD;
		for(d=1; d*d < a; d++) {
			if(a%d) continue;
			T[d] += a;
			if(T[d] >= MOD) T[d] -= MOD;
			T[a/d] += a;
			if(T[a/d] >= MOD) T[a/d] -= MOD;
		}
		if(d*d == a) {
			T[d] += a;
			if(T[d] >= MOD) T[d] -= MOD;
		}
	}
	inv[0] = 0; inv[1] = 1;
	iter(i, 2, 1000001) inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
	sve(1000001);
	rep1(d, 1000000) {
		if(!g[d]) continue;
		ll t = 0; int li = 1000000/d;
		for(int k = 1; k <= li; k++) t = (t + 1ll * T[k*d]*T[k*d]%MOD * inv[k]) % MOD;
		ans = (ans + t*(MOD+g[d])) % MOD;
	}
	print(1ll*ans*inv[2]%MOD);
}


Measured memory_bytes: 14592
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }
    var ans = 0
    var count = 0
    for (i in 1 until n) {
        if (a[i - 1] >= a[i]) {
            count++
            ans = Math.max(ans, count)
        } else {
            count = 0
        }
    }
    println(ans)
}

Measured memory_bytes: 59688
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e6+5 ,mod = 1e9+7 ;

string s ;
int mem[N][2] ;
int solve(int i,bool lst){
    if(i==s.size()) return 1;
    if(i+1==s.size() && !lst) return 1;
    int&ret = mem[i][lst] ;
    if(~ret) return ret;
    ret = 0 ;
    if(s[i]=='1'){
        ret = (ret + solve(i+1,1))%mod ;
        ret = (ret + solve(i+1,lst)*2%mod)%mod ;
    }
    else{
        ret = (ret + solve(i+1,lst))%mod ;
        ret = (ret + solve(i+1,0)*2%mod)%mod;
    }
    return ret;
}
int main(){
    cin >> s ;
    reverse(s.begin(),s.end());
    memset(mem,-1,sizeof mem);
    cout << solve(0,1);
    return 0;
}


Measured memory_bytes: 14592
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> p(n+1), b(n+1);
    p[0] = 1;
    b[0] = 0;
    string bar = "|";
    for(int i =1; i <= n; i++){
       p[i] = p[i-1]*2 + 1;
       b[i] = b[i-1]*2 + 2;
       //bar = "0" + bar + "|" + bar + "0";
       //cout << "level" << i << ":" << bar << endl;
    }


    int i = 1;
    ll res = 0;
    ll start = 1;
    if(x > (p[n]+b[n])/2){
        res += p[n-1]+1;
        start += (p[n]+b[n])/2;
        //cout << "av:" << res << "& start" << start << endl;
    }
    while(i <= n && start <= x){
        if(p[n-i]+b[n-i] + start <= x){
            res += p[n-i];
            start += p[n-i] + b[n-i];
            if(start == x || start >= p[n]+b[n] - n)break;
            res++;
            start++;
            if(i==n && start < x){
                res++;
                start++;
            }
            //cout << "in:" << n-i << "&" << start <<endl;
        }
        if(start == x)break;
        i++;
        start++;
    }
    //cout << start << endl;
    cout << res << endl;
    //rep(i, n+1)cout << "p:" << p[i] << "b:" << b[i] << endl;
 }

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        sc.nextLine();
        int number[] = new int[30];
 
        for(int i = 0;i<m;i++){
            int tmp = sc.nextInt();
            for(int j = 0;j<tmp;j++){
                number[sc.nextInt()-1]++;
            }
            if(i != n-1){
                sc.nextLine();
            }
        }
        int count = 0;
        for(int i = 0;i<n;i++){
            if(number[i] == m){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23636
#include <stdio.h>

int main(void){
    int a,b;
    scanf("%d %d\n", &a, &b);
    
    if (a==b){printf("a == b\n");}
    if (a > b){printf("a > b\n");}
    if (a < b){printf("a < b\n");}
    
    return 0;
}



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

#define int long long
#define double long double

using namespace std;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
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; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e9;

signed main() {

	int n, m;
	cin >> n >> m;

	int ans = 0;

	int nt = 1, mt = 1;
	rep(i, n){
		nt *= (n - i);
		nt %= mod;
	}
	rep(i, m){
		mt *= (m - i);
		mt %= mod;
	}

	ans = (nt * mt) % mod;

	if(n == m) {
		ans = (ans * 2) % mod;
	}else
	if(abs(n-m) == 1){

	}else{
		ans = 0;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
struct node{
    node *l,*r;
    int tag;
    int a,b;
    int sum;
    node(int _a,int _b):l(NULL),r(NULL),a(_a),b(_b),tag(0),sum(0){
    }
}*root;
int Sum(node *n){
    return n->tag?n->b-n->a+1:n->sum;
}
void pull(node *n){
    n->sum=Sum(n->l)+Sum(n->r);
}
void build(node *n){
    if(n->a==n->b)return ;
    int mid=(n->a+n->b)/2;
    n->l=new node(n->a,mid);
    n->r=new node(mid+1,n->b);
    build(n->l);
    build(n->r);
}
void add(node *n,int l,int r,int k){
    if(n->a>=l&&n->b<=r){
        n->tag+=k;
        return ;
    }
    if(n->b<l||n->a>r)return ;
    add(n->l,l,r,k);
    add(n->r,l,r,k);
    pull(n);
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    root = new node(1,n);
    //if(n>200||m>200)return 0;
    int a[200005];
    int cnt[200005];
    fill(cnt,cnt+n+1,0);
    for(int i = 1;i<=n;i++){
        scanf("%d",&a[i]);
        cnt[a[i]]++;
    }
    root = new node(1,n);
    build(root);
    for(int i = 1;i<=n;i++){
        if(cnt[i]){
            add(root,i-cnt[i]+1,i,1);
        }
    }
    for(int i = 0;i<m;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        add(root,a[x]-cnt[a[x]]+1,a[x],-1);
        cnt[a[x]]--;
        if(cnt[a[x]]){
            add(root,a[x]-cnt[a[x]]+1,a[x],1);
        }
        a[x]=y;
        if(cnt[y]){
            add(root,y-cnt[y]+1,y,-1);
        }
        cnt[y]++;
        add(root,y-cnt[y]+1,y,1);
        printf("%d\n",n-Sum(root));
    }
}
/*
2 6
5 7
7 5
4 3
6 4
7 3
6 5
5 7
3 6
4 7
*/
//a+a+1=10a+1
//3a+2=10a+2

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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() {
  string s;
  cin >> s;
  bool flag = false;
  rep(i, 0, 2) {
    if (s[i] == s[i+1] && s[i+1] == s[i+2]) {
      flag = true;
      break;
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  int ans=n*2;
  bool f;
  for(int i=0;i<n;i++){
    f=true;
    for(int j=0;i+j<n&&f;j++){
      if(s[i+j]!=t[j]) f=false;
    }
    if(f){
      ans=i+n;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[300005];

int main() {
    scanf("%d", &n);
    forn(i, 3 * n) scanf("%d", a + i);
    sort(a, a + (3 * n), greater<int>());
    LL ans = 0;
    for (int i = 1; i < 2 * n; i += 2) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


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

void solve(long long N, long long x, vector<long long> a){
	long long res = 0;
	if(a[0] > x) {
		res += a[0] - x;
		a[0] = x;
	}
	for(int i = 0; i < N - 1; ++i) {
		if(a[i] + a[i + 1] > x) {
			int t = a[i] + a[i + 1] - x;
			res += t;
			a[i + 1] = max(0LL, a[i + 1] - t);
		}
	}
	cout << res << endl;
}

int main(){	
	long long x;
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	scanf("%lld",&x);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, x, a);
	return 0;
}



Measured memory_bytes: 1792
N = int(input())
A = ["AC", "WA", "TLE", "RE"]
ans = [0, 0, 0, 0]

for i in range(N):
  s = str(input())
  p = A.index(s)
  ans[p] += 1
  
for i in range(4):
  print(A[i], "x", ans[i])


Measured memory_bytes: 9184
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = MI()

def med(arr):
    n = N
    arr.sort()
    if n % 2 == 0:
        return (arr[n//2-1] + arr[n//2]) / 2
    else:
        return arr[n//2]

meda = med(A)
medb = med(B)
if N % 2 != 0:
    print(int(max(meda, medb) - min(meda, medb) + 1))
else:
    print(int(2 * medb - 2 * meda + 1))

Measured memory_bytes: 74812
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    if n == 1 {
        println!("Hello World");
    } else {
        let a = read::<usize>();
        let b = read::<usize>();
        println!("{}", a + b);
    }
}


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

int main() {
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  
  if (U == S) {
    A -= 1;
  } else if (U == T) {
    B -= 1;
  }
  
  cout << A << ' ' << B << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define tcn cin.tie(0);
#define tct cout.tie(0);
#define pb push_back
#define ll long long
#define fr first
#define se second
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long N = 2e3 + 7;
const ll mod = 1e6 + 7;
ll n , m , a , b , c ,d ;
long double p = 3.141592653589793;
string s;
char ch;
vector<int>v ,v1;
int main()
{
    TIME tcn tct
    cin >> n;
    cout << n * (2 * p);
}


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

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(9)<<fixed;
	
	int n;
	cin>>n;
	string s;
	while(n>0)
	{
		int t1=n%26;
		char c='a'+t1-1;
		if(t1==0)
		{
			s+='z';
			n-=26;
		}
		else
			s+=c;
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
 
int f[26];
#define MOD 1000000007
 
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) {
     f[s[i]-'a']++;
  }
  long long ans = 1;
  for (int i = 0; i < 26; i++) {
    ans = (ans*(f[i]+1))%MOD;
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<stack>
#include<algorithm>
#include<string>
#include<string.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int N = 1e5;
ll A[N + 5], B[N + 5];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; cin >> t;
	while(t--){
		int n, d; cin >> n >> d;
		int ans = d;
		while(n > 1){
			n--;
			ans += 127 - d;
			d = 127^d;
			ans += d;
		}
		cout << ans << endl;
	}
	
}

Measured memory_bytes: 256