akhauriyash/Code-Regression huggingface dataset:
A= list(input())
p_c = 0
total = 0 
g_c = 0
for i in A:
    if i == "g" and p_c+1 <= g_c:
        total += 1
        p_c += 1
    elif i == "p" and p_c+1 <= g_c:
        p_c += 1
    elif i == "g":
        g_c += 1
    else:
        g_c += 1
        total -= 1
print(total)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n, d1, d2, c=0, a=0;
  cin >> n;
  
  rep(i,n) {
    cin >> d1 >> d2;
    if (d1 == d2) {
      c++;
    }
    else {
      c=0;
    }
    if (c == 3) {
      a=1;
      cout << "Yes" << endl;
      break;
    }
  }
  
  if (a == 0) {
    cout << "No" << endl;
  }
}

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

dp = [[0,0] for i in range(n+1)]

dp[0][0]= 0 
dp[0][1]= -10**10

for i in range(1,n+1):
    dp[i][1]= max(dp[i-1][0]-a[i-1], dp[i-1][1]+a[i-1])
    dp[i][0]=max(dp[i-1][0]+a[i-1], dp[i-1][1]-a[i-1])


print(dp[n][0])

Measured memory_bytes: 25600
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,x;
	cin>>a>>b>>x;
	cout<<(a+b<x||x<a?"NO":"YES")<<endl;
}


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

int main(){
  int s, sum;
  sum = 0;
  cin >> s;
  while(s != 0){
    if(s%10 == 1){sum += 1;}
    s = s / 10;
  }
  cout << sum << endl;
  return 0;
}

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

int n,a[200005];

inline bool check(const int &k){
    if((a[n-1]<=k&&a[n]<=k)||(a[n]<=k&&a[n+1]<=k))return 1;
    if((a[n-1]> k&&a[n]> k)||(a[n]> k&&a[n+1]> k))return 0;
    for(int i=1;i<n-1;i++){
        if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))return 1;
        if((a[n+i]> k&&a[n+i+1]> k)||(a[n-i]> k&&a[n-i-1]> k))return 0;
    }
    return a[1]<=k;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<n<<1;i++)scanf("%d",a+i);
    int l=1,r=(n<<1)-1;
    while(l<r){
        int mid=l+r>>1;
        if(check(mid))r=mid;
        else l=mid+1;
    }
    printf("%d",l);
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>

using namespace std;

int table[10+1][10000];
int memo[10];

void numnum (int size, int depth, int sum )
{
	if (size + 1 == depth ) {
		table[size][sum]++;
	}else{
		for (int i = 0; i <= 9; ++i ){
			if ( memo[i] == 0 ) {
				memo[i] = 1;
				numnum (size, depth + 1, sum + i*depth );
				memo[i] = 0;
			} // end if
		} // end for
	} // end if
}

int main()
{
	memset(table, 0, sizeof (table ) );

	for (int i = 1; i <= 10; ++i ) {
		memset (memo, 0, sizeof (memo ) );
		numnum (i, 1, 0 );
	} // end for

	int n, s;
	while ( cin >> n >> s ) {
		cout << table[n][s] << endl;
	} // end while

	return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=10000;

LL dfs(LL N,LL x,LL sum){
    if(N%x==0){
        return sum+=N*2-x;
    }
    if(N>x) return dfs(x,N%x,sum+N/x*2*x);
    else return dfs(x,N,sum+x);
}

int main(){
    LL N,x;
    cin >> N >> x;
    if(x%(N-x)==0){
        cout << x*3 << endl;
    }
    else if(x>N-x) cout << dfs(N-x,x%(N-x),x/(N-x)*(N-x)*2+N) << endl;
    else cout << dfs(N-x,x,x/(N-x)*(N-x)*2+N) << endl;
    return 0;
}

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


#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

//素数num以下のふるい
void sosuu(int num,vector<bool>& Find){
//	bool Find[num] ; // 探索リスト
    for(int i = 2; i <= num; i++){
//        Find[i] = true;
        if(i%2==0) Find[i] = false;
    }
    for(int i = 2; i*i < num; i++){
        if(Find[i] == false) continue; // すでに除いた数は飛ばす
        for(int j = i * 2; j< num; j += i) {
            if(Find[j]) Find[j] = false;
        }
    }
    Find[2]= true;
}

int main(void){

int n;
	vector<bool> ssu(50100,true);
	sosuu(50100,ssu);
	vector<int> ss2;
	rep(i,50100) if(ssu[i]) ss2.push_back(i);
	while(cin >> n){
		if( cin.eof() || n ==0 ) break;
		int cnt = 0;
		int zx = min(n, (int)ss2.size());
		rep2(i,2,zx){
			if(ss2[i] > n - ss2[i]) break;
			if(ssu[n-ss2[i]] )	cnt++;
			}
		cout << cnt << endl;
	}
	return 0;
	
	
}

Measured memory_bytes: 1284
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array(lr())
sum = A.sum()
# Aiが1以上のため、answerはsumの約数

def make_divisors(n): # nの約数を列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

B = make_divisors(sum)

for x in B[::-1]:
    c = A % x
    c.sort()
    d = x - c
    c_cum = c.cumsum()
    d_cum = d.cumsum()
    
    for i in range(N):
        y = c_cum[i]
        z = d_cum[N-1] - d_cum[i]
        if y > K or z > K:
            continue
        result = (y + z) // 2
        if result <= K:
            print(x)
            exit()


Measured memory_bytes: 21884
n=int(input())
h=list(map(int, input().split()))
dp=[0 for i in range(n)]
#dp[1]=abs(h[1]-h[0])
for i in range(n):
    if i<1:
        dp[i+1]=abs(h[i+1]-h[i])+dp[i]
    elif i==n-1:
        dp[i]=min(dp[i], abs(h[i]-h[i-1])+dp[i-1])
    else:
        dp[i+1]=min(abs(h[i+1]-h[i])+dp[i],abs(h[i+1]-h[i-1])+dp[i-1])
print(dp[n-1])
#print(dp)

Measured memory_bytes: 14356
#include<stdio.h>
#include<ctype.h>
char StrToUpper(char s[])
{
	int i;
    char p[200];
    for (i=0; s[i]!='\0'; i++){
		p[i] = toupper(s[i]);
		printf("%c",p[i]);
	}
	printf("\n");
}
/*toUpperを使う場合*/
int main(){
	char str[200];
	gets(str);
	StrToUpper(str);
		return 0;
}

Measured memory_bytes: 520
'use strict'

function main(input) {
  const inputList = input.split(' ');
  const n = Number(inputList[0])
  const k = Number(inputList[1])
  
  let pattern = k
  for (let i=1; i<n; i++) {
    pattern = pattern * (k-1)
  }
  console.log(pattern)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

s = input()
# question_count = s.count("?")
# max_str = {"point":0,"str":""}

# for i in range(2**question_count):
#     swap_str = ""
#     for j in range(question_count):
#         if ((i>>j)&1):
#             swap_str += "P"
#         else:
#             swap_str += "D"
#     check_str = str(s)
#     for char in range(question_count):
#         check_str = check_str.replace("?",swap_str[char],1)
    
#     point = 0
#     point += check_str.count("D")
#     point += check_str.count("PD")
#     if max_str["point"] < point:
#         max_str["point"] = point
#         max_str["str"] = check_str
#     print(point,check_str)
# print(max_str["str"])
print(s.replace("?","D"))

Measured memory_bytes: 9224
//此程序使用了qt专属名称，请勿模仿。侵权必究！！！
//我真是太菜了啊……
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=101;
ll n,m=0,a[N];
ll ans,f[N][2][2];
inline ll read()
{
	ll sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())
	{
		if(c=='-')
		{
			flag=-1;
		}
	}
	for(;c>='0'&&c<='9';c=getchar())
	{
		sum=(sum<<3)+(sum<<1)+c-'0';
	}
	return sum*flag;
}
inline ll dp(int len)
{
	int t=len/2;
	ll cnt=0;
	memset(f,0,sizeof(f));
	f[0][0][0]=1;
	for(int i=0;i<t;++i)
	{
		for(int j=0;j<=1;++j)
		{
			for(int k=0;k<=1;++k)
			{
				if(f[i][j][k])
				{
					for(int p=0;p<=9;++p)
					{
						int sum=p+a[i+1]+k,res=sum%10,x=j*10+p-res-a[len-i],y=sum/10;
						if(x==0||x==1)
						{
							if(i||(res&&p))
							{
								f[i+1][x][y]+=f[i][j][k];
							}
						}
					}
				}
			}
		}
	}
	if(len&1)
	{
		for(int j=0;j<=1;++j)
		{
			for(int k=0;k<=1;++k)
			{
				if(f[t][j][k])
				{
					for(int p=0;p<=9;++p)
					{
						int sum=p+a[t+1]+k;
						if(sum%10==p&&sum/10==j)
						{
							cnt+=f[t][j][k];
						}
					}
				}
			}
		}
	}
	else
	{
		cnt=f[t][0][0]+f[t][1][1];
	}
	return cnt;
}
int main()
{
//	freopen("mirrored.in","r",stdin);
//	freopen("mirrored.out","w",stdout);
	n=read();
	while(n)
	{
		a[++m]=n%10;
		n/=10;
	}
	for(int i=m;i<=m*2;++i)
	{
		ans+=dp(i);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    h, w, d = ns()
    pos = dict()
    for i in range(h):
        a = na()
        for j, ai in enumerate(a):
            pos[ai - 1] = (i, j)

    cum = [[0] for _ in range(d)]

    for i in range(d):
        x, y = pos[i]
        num = i + d
        while num < h * w:
            xi, yi = pos[num]
            tmp = abs(xi - x) + abs(yi - y)
            cum[i].append(cum[i][-1] + tmp)
            x, y = xi, yi
            num += d

    q = ni()
    for _ in range(q):
        l, r = ns()
        l, r = l - 1, r - 1
        tmp = cum[l % d][r // d] - cum[l % d][l // d]
        print(tmp)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31456
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

ll mod = 1e9+7;

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

    Vl A(X),B(Y),C(Z),tmp(X*Y),ans;
    REP(i,X) cin >> A[i];
    REP(i,Y) cin >> B[i];
    REP(i,Z) cin >> C[i];

    sort(A.rbegin(),A.rend());
    sort(B.rbegin(),B.rend());
    sort(C.rbegin(),C.rend());
    REP(i,X) {
        REP(j,Y) {
            tmp[i*Y+j] = A[i]+B[j];
        }
    }
    sort(tmp.rbegin(),tmp.rend());

    ll m = 0,count = 0;
    REP(i,Z) {
        REP(j,min(K,X*Y)) {
            ll t = C[i]+tmp[j];
            if (count>=K && m>t) {
                break;
            }
            count++;
            m = min(t,m);
            ans.push_back(t);
        }
    }
    sort(ans.rbegin(),ans.rend());
    REP(i,K) cout << ans[i] << endl;
}

Measured memory_bytes: 42600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, u, v;
llong a, b;
vector<llong> to_edge[100005];
llong dp[2][100005];

void dfs(int u, int idx, int par) {
    dp[u][idx] = dp[u][par] + 1;
        
    for (auto &e:to_edge[idx]) {
        if (e == par) continue;
        dfs(u, e, idx);
    }
}

int main() {
    cin >> n >> u >> v;
    for (int i = 0; i < n - 1; i++) {
        cin >> a >> b;
        to_edge[a].push_back(b);
        to_edge[b].push_back(a);
    }

    dp[0][u] = -1;
    dp[1][v] = -1;
    dfs(0, u, -1);
    dfs(1, v, -1);

    llong ans = 0;
    for (int i = 1; i <= n; i++) {
        if (dp[0][i] < dp[1][i]) {
            ans = max(dp[1][i], ans);
        }
    }

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


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 10000005

ll n;

ll s(ll n){
    return (n * (n + 1)) / 2;
}

int main()
{
    _FastIO;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
            ll k = n / i;
            ll sum = i * s(k);
            ans += sum;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
//#define MOD (ll)(998244353)
#define MOD (ll)(1e9+7)
#define INF (1e17)
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}
pii exgcd(int a,int b){
    if(a%b==0) return pii(0,1);
    pii p=exgcd(b,a%b);
    return pii(p.S,p.F-a/b*p.S);
}
int modinv(int n,int mod,bool prime){
    if(prime) return fpow(n,mod-2);
    int x=exgcd(n,mod).F;
    return (x+mod)%mod;
}
int fac(int n){
	int ans=1;
	For(i,1,n) ans=(ans*i)%MOD;
	return ans;
}

int32_t main() {
#ifdef LOCAL_TEST
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\input.in","r",stdin);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\output.out","w",stdout);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	int x,y; cin>>x>>y;
	int a=(x*2-y)/3;
	int b=(y*2-x)/3;
	if((x+y)%3 || a<0 || b<0){
		cout<<0<<"\n";
		return 0;
	}
	cout<<((fac(a+b)*modinv(fac(a),MOD,true)%MOD)*modinv(fac(b),MOD,true)%MOD)<<"\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long[] H = new long[N + 1];
        for (int i = 1; i <= N; i++) {
            H[i] = sc.nextLong();
        }
        HashMap<Integer, Long> highA = new HashMap<>();
        HashMap<Integer, Long> highB = new HashMap<>();

        for (int i = 0; i < M; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            if (!highA.containsKey(A) || highA.get(A) < H[B]) {
                highA.put(A, H[B]);
            }
            if (!highB.containsKey(B) || highB.get(B) < H[A]) {
                highB.put(B, H[A]);
            }

        }

        int ans = 0;
        for (int i = 1; i <= N; i++) {
            long highH = H[i];
            if (!highA.containsKey(i) && !highB.containsKey(i)) {
                ans++;
            } else if (highA.containsKey(i) && !highB.containsKey(i)) {
                if (highA.get(i) < H[i]) {
                    ans++;
                }
            }else if(!highA.containsKey(i)&&highB.containsKey(i)){
                if(highB.get(i)<H[i]){
                    ans++;
                }
            }else if(highA.containsKey(i)&&highB.containsKey(i)){
                if(highA.get(i)<H[i]&&highB.get(i)<H[i]){
                    ans++;
                }
            }

        }
        System.out.println(ans);

    }

    
}


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

int main(){
  long long n,sum=0,ans=0;
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  long long dp[n+1][sum+256]={};
  for(int i=0;i<=n;i++){
    dp[i][0]=1;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=sum;j++){
      if(dp[i][j]>0){
        dp[i+1][j+a[i]]=1;
        dp[i+1][j]=1;
      }
    }
  }
  for(ll i=0;i<=sum;i++){
    if(dp[n][i]>0 and i%10){
      ans=max(ans, i);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back

const int N = 1e5 + 5;
int n, q;
vector <int> g[N], col[N], cost[N];
int dep[N], siz[N], son[N], top[N], id[N], cnt;
int dfn[N], on[N], tme, fa[N], fae[N];
vector <int> occ[N];
vector <int> sum[N];
int sum_cost[N];

void dfs0(int u, int p, int pi) {
	if (~p) dep[u] = dep[p] + 1;
	siz[u] = 1; son[u] = -1; fa[u] = p; fae[u] = pi;
	for (int i = 0; i < g[u].size(); ++ i) {
		int v = g[u][i];
		if (v != p) {
			dfs0(v, u, i);
			siz[u] += siz[v];
			if (!~son[u] || siz[v] > siz[son[u]]) son[u] = v;
		}
	}
}

void dfs1(int u, int p) {
	id[u] = cnt;
	dfn[u] = tme; on[tme ++] = u;
	if (!~top[cnt]) top[cnt] = u;
	if (~son[u]) dfs1(son[u], u);
	for (int i = 0; i < g[u].size(); ++ i) {
		int v = g[u][i];
		if (v != p && v != son[u]) {
			++ cnt;
			dfs1(v, u);
		}
	}
}

int main() {
	scanf("%d %d", &n, &q);
	for (int i = 1; i < n; ++ i) {
		int u, v, w, c;
		scanf("%d %d %d %d", &u, &v, &c, &w);
		-- u; -- v; -- c;
		g[u].pb(v); col[u].pb(c); cost[u].pb(w);
		g[v].pb(u); col[v].pb(c); cost[v].pb(w);
	}
	memset(top, -1, sizeof(top));
	dfs0(0, -1, -1); dfs1(0, -1);
	for (int i = 0; i < n; ++ i) {
		int u = on[i];
		if (!u) continue;
		occ[col[fa[u]][fae[u]]].pb(i);
		int lst = sum[col[fa[u]][fae[u]]].empty() ? 0 : sum[col[fa[u]][fae[u]]].back();
		sum[col[fa[u]][fae[u]]].pb(lst + cost[fa[u]][fae[u]]);
		sum_cost[i] = (i ? sum_cost[i - 1] : 0) + cost[fa[u]][fae[u]];
	}
	while (q --) {
		int c, w, u, v;
		scanf("%d %d %d %d", &c, &w, &u, &v);
		-- u; -- v; -- c;
		int dis = 0, cnt = 0, res = 0;
		while (id[u] != id[v]) {
			if (dep[top[id[u]]] < dep[top[id[v]]]) swap(u, v);
			dis += sum_cost[dfn[u]] - (dfn[top[id[u]]] ? sum_cost[dfn[top[id[u]]] - 1] : 0);
			int L = lower_bound(occ[c].begin(), occ[c].end(), dfn[top[id[u]]]) - occ[c].begin();
			int R = upper_bound(occ[c].begin(), occ[c].end(), dfn[u]) - occ[c].begin() - 1;
			cnt += R - L + 1;
			if (L <= R) res += sum[c][R] - (L ? sum[c][L - 1] : 0);
			u = fa[top[id[u]]];
		}
		if (dep[u] > dep[v]) swap(u, v);
		dis += sum_cost[dfn[v]] - sum_cost[dfn[u]];
		int L = upper_bound(occ[c].begin(), occ[c].end(), dfn[u]) - occ[c].begin();
		int R = upper_bound(occ[c].begin(), occ[c].end(), dfn[v]) - occ[c].begin() - 1;
		cnt += R - L + 1;
		if (L <= R) res += sum[c][R] - (L ? sum[c][L - 1] : 0);
		printf("%d\n", dis - res + cnt * w);
	}
	return 0;
}


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

int dp(int n, int m[]){
    if(m[n-3] == 0) dp(n-3,m);
    if(m[n-1] == 0) dp(n-1,m);
    m[n] = (m[n-3] + m[n-1]) % 1000000007;
    return 0;
}

int main(){
    int nom[2000] = {0,};
    nom[3] = nom[4] = nom[5] = 1;
    int n;
    cin >> n;
    if(n < 6) cout << nom[n];
    else{
        dp(n,nom);
        cout << nom[n];
    }
}

Measured memory_bytes: 3636
A, B = map(int, input().split())
count_target = 0

for i in range(A, B + 1):
    str_i = str(i)
    reversed_i = ''
    for n_th_i in reversed(range(len(str_i))):
        reversed_i += str_i[n_th_i]

    if str_i == reversed_i:
        count_target += 1

print(count_target)

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

#define int long long
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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int x; cin >> x;
    //vector<int> ab(2*1e4+1);
    //vector<int> ab(2*1e4+1);
    vector<int> ab(2*1e2+1);
    for(int i=0; i<1e4; i++) ab.PB(pow(i,5));
    for(int i=0; i<1e4; i++) ab.PB(pow(i,5)*-1);
    sort(all(ab));
    rep(i,ab.size()){
        int a=x+ab[i];
        auto itr=lower_bound(all(ab),a);
        if(*itr-ab[i]==x) {
            if(*itr<0){
                *itr*=-1;
                cout<<-1*pow(*itr,1.0/5.0)<<' ';
            }else{
                cout<<pow(*itr,1.0/5.0)<<' ';
            }

            if(ab[i]<0){
                ab[i]*=-1;
                
                cout<<pow(ab[i],1.0/5.0)*-1<<endl;
                return 0;
            }else{
                
                cout<<pow(ab[i],1.0/5.0)<<endl;
                return 0;
            }
            //cout<<*itr<<' '<<ab[i]<<endl;
        }
    }


    /*
    for(int i=0; i<ab.size(); i++){
        ab[i]=pow(i,5);
    }
    rep(i,ab.size()){
        int a=x-ab[i];
        int b=x+ab[i];
        auto itr1=lower_bound(all(ab),a);
        auto itr2=lower_bound(all(ab),b);
        if(*itr1-ab[i]==x) {cout<<*itr1<<' '<<ab[i]<<endl; return 0;}
        if(*itr1*-1-ab[i]==x) {cout<<*itr1*-1<<' '<<ab[i]<<endl; return 0;}
        if(*itr1*-1+ab[i]==x) {cout<<*itr1*-1<<' '<<-1*ab[i]<<endl; return 0;}
        if(*itr1*+ab[i]==x) {cout<<*itr1*-1<<' '<<ab[i]*-1<<endl; return 0;}
        if(*itr2-ab[i]==x) {cout<<*itr2<<' '<<ab[i]<<endl; return 0;}
        if(*itr2*-1-ab[i]==x) {cout<<*itr2*-1<<' '<<ab[i]<<endl; return 0;}
        if(*itr2*-1+ab[i]==x) {cout<<*itr2*-1<<' '<<-1*ab[i]<<endl; return 0;}
        if(*itr2*+ab[i]==x) {cout<<*itr2*-1<<' '<<ab[i]*-1<<endl; return 0;}

    }
    */
    /*
    for(int i=0; i<1e4; i++){
        ab[i]=-1*pow(i,5);
    }
    for(int i=1e4; i<2*1e4; i++){
        ab[i]=pow(i/1e4,5);
    }
    sort(all(ab));
    rep(i,ab.size()){
        int a=x-ab[i];
        auto itr=lower_bound(all(ab),a);
        if(*itr-ab[i]==x) {
            cout<<*itr << ' ' << ab[i]<<endl;
            return 0;
        }
    }
    */


}

Measured memory_bytes: 4320
N, K = map(int, input().split())
Alist = list(map(int, input().split()))

# ループする数を求める
loop_num = 2 * 10 ** 5
loop_start_point = -1
point = 1
count_list = [-1] * N

for i in range(K):
    #print("point:", point)
    count_list[point - 1] = i
    nextPoint = Alist[point - 1]

    if count_list[nextPoint - 1] != -1:
        loop_start_point = nextPoint
        loop_num = i - count_list[loop_start_point - 1] + 1
        break
    
    point = nextPoint

if loop_start_point == -1:
    print(point)
else:
    point = loop_start_point
    progress_num = (K - count_list[loop_start_point-1]) % loop_num
    for i in range(progress_num):
        point = Alist[point - 1]
    #print("pro:", progress_num)
    #print("ls:", loop_start_point)
    #print("ln:", loop_num)
    print(point)

Measured memory_bytes: 32292
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-(x)))
#define mid ((l+r)>>1)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define ull unsigned long long
using namespace std;
ull sed = 131;
const int maxn = 5e3 + 50;
ull ha[maxn], p[maxn];
int n;
ull get_hash(int l, int r){
    //cout<<ha[r]<<" "<<ha[l]<<endl;
    return ha[r]-ha[l-1]*p[r-l+1];
}
map<ull, int> mp;
bool check(int len){
    mp.clear();
    for(int i = 1; i <= n-len+1; ++i){
        ull temp = get_hash(i, i+len-1);
        if(mp.find(temp) == mp.end()){
            //cout<<"len:"<<len<<" i:"<<i<<" temp:"<<temp<<endl;
            mp[temp] = i;
        }
        else {
            int pos = mp[temp];
            if(pos + len <= i) return true;
        }
    }
    return false;
}
char s[maxn];
int main()
{
    p[0] = 1;
    for(int i = 1; i < maxn; ++i) p[i] = p[i-1]*sed;
    cin>>n;
    scanf("%s", s+1);
    for(int i = 1; i <= n; ++i) ha[i] = ha[i-1]*sed + s[i]-'a';
    int l = 1, r = n/2;
    int ans = 0;
    while(l <= r){
        if(check(mid)) ans = mid, l = mid+1;
        else r = mid-1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int time[10001];
  int n,m,t,a,ans=0;
  bool b=false;
  for(int i=0;i<10001;i++){
    time[i]=0;
  }
  cin>>n>>m>>t;
  for(int i=0;i<n;i++){
    cin>>a;
    time[a]=1;
    for(int j=a;j>=0 && abs(a-j)<=m;j--){
      time[j]=2;
    }
    for(int j=a;j<10001 && abs(a-j)<=m;j++){
      time[j]=2;
    }
  }
  for(int i=0;i<t+1;i++){
    if(time[i]==0 && b){
      ans+=2;
      b=false;
    }
    else if(time[i]==0) ans++;
    else b=true;
  }
  if(b) cout<<ans<<endl;
  else cout<<ans-1<<endl;
  return 0;
}



Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main() { 
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	ll ans = 0;
	for(int i = 0; i < (1 << (s.size() - 1)); i++) { //全探索(2^n - 1)
		ll num = s[0] - '0';
		for (int j = 0; j < s.size() - 1; j++) {
			if (i & (1 << j)) {
				ans += num;
				num = 0;
			}
			num = num * 10 + s[j + 1] - '0';
		}
		ans += num;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String coffeeString = scanner.next();
        if (coffeeString.length() == 6) {

            if (coffeeString.charAt(2) == coffeeString.charAt(3) && coffeeString.charAt(4) == coffeeString.charAt(5)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }


    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

typedef long long LL;
using namespace std;
const int maxn = 610, mod = 1e9 + 7;

int read()
{
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

int g[maxn], cnt[maxn][maxn], dp[maxn][maxn], a[maxn];

int main()
{

	int n = read() * 2, K = read();
	for(int i = 1; i <= K; ++i)
	{
		int x = read(), y = read();
		a[x] = y; a[y] = x;
	}

	g[0] = 1;
	for(int i = 2; i <= n; i += 2) g[i] = (LL)g[i - 2] * (i - 1) % mod;
	for(int i = 1; i <= n; ++i)
		for(int j = i; j <= n; ++j)
			cnt[i][j] = cnt[i][j - 1] + (a[j] ? 0 : 1);

	int ans = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = i; j <= n; ++j)
		{
			if((j - i + 1) & 1) continue;
			for(int k = i; k <= j; ++k)
				if(a[k] && (a[k] < i || a[k] > j)) goto nxt;
			dp[i][j] = g[cnt[i][j]];
			for(int k = i; k < j; ++k)
				(dp[i][j] -= (LL)dp[i][k] * g[cnt[k + 1][j]] % mod) %= mod;
			(ans += (LL)dp[i][j] * g[cnt[1][i - 1] + cnt[j + 1][n]] % mod) %= mod;
			nxt:;
		}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;


int main()
{
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    bool con = x*2 == W and y*2 == H;
    cout << setprecision(21) << (ld)W * H / 2.0 << ' ' << con << endl;
}


Measured memory_bytes: 256
n, *a = map(int, open(0).read().split())

set_a = set(a)
set_a = sorted(set_a)

ans = 'No'

if len(set_a) == 1 and a[0] == 0:
    ans = 'Yes'

if len(set_a) == 2 and n%3 == 0 and a.count(0) == n//3 and a.count(set_a[1]) == 2*n//3:
    ans = 'Yes'

if len(set_a) == 3 and n%3 == 0:
    if set_a[0] ^ set_a[1] ^ set_a[2] == 0:
        ans = 'Yes'
        for i in range(3):
            if a.count(set_a[i]) != n//3:
                ans = 'No'
                break
print(ans)

Measured memory_bytes: 14484
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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



void solve(long long x){
    if(x==0){
        cout<<1<<endl;

    }else{
        cout<<0<<endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long x;
    scanf("%lld",&x);
    solve(x);
    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
    int n;
    string s, r, temp;
    cin>>s;
    int flag = 0;
    n = s.length();

    temp = s;
    reverse(temp.begin(), temp.end());
    if(temp == s)
        flag++;

    r = s.substr(0, (n-1)/2);
    temp = r;
    reverse(temp.begin(), temp.end());
    if(temp == r)
        flag++;

    r = s.substr((n+3)/2 - 1);
    temp = r;
    reverse(temp.begin(), temp.end());
    if(temp == r)
        flag++;

    if(flag==3)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


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

int main (){
    char str1[100], str2[100], str3[100];
    scanf("%s %s %s", str1,str2, str3);

    int length1 = strlen (str1);
    int length2 = strlen (str2);
    for(int i = 0; i < 10; i++){
        if(str1[length1 - 1] == str2[0] && str2[length2 - 1]== str3[0]){
            printf("YES");
            break;
        }
        else{
            printf("NO");
            break;
        }
    }
    return 0;
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

// End of Template //



int main() {

    int N;
    cin >> N;

    cou((N - 1) / 2);

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	register int a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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--)
int main(){
	int N;
	cin>>N;
	int ans=0;
	REP(i,N){
	   ans+=i+1;
	}
        cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N; 
cin >> N;
int A[50010] = {}; 
int B[50010] = {}; 
int C[100010] = {}; 
int D[100010] = {}; 
int E[100010] = {}; 
int F[100010] = {}; 
for(int i = 0; i < N/2; i++){
cin >> A[i] >> B[i]; 
C[A[i]] ++; 
D[B[i]] ++;
E[A[i]] ++; 
F[B[i]] ++;
}

sort(E, E+100001, greater<int>()); 
sort(F, F+100001, greater<int>()); 

int G[100010] = {}; 
int H[100010] = {}; 
int count = 0; 
for(int i = 1; i <= 100000; i++){
if(C[i] == E[0]){G[i] ++; 
}
if(D[i] == F[0]){H[i] ++; 
}
if(G[i] + H[i] == 2){count ++;}
}

int S = 0, T = 0; 
for(int i = 1; i <= 100000; i++){
S += G[i]; 
T += H[i]; 
}

if(S == 1 && T == 1 && count == 1){
cout << min(N - E[0] - F[1], N - E[1] - F[0]) << endl; 
}
else{
cout << N - E[0] - F[0] << endl;
}
}

Measured memory_bytes: 3072
import sys
from collections import defaultdict

N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

ll = defaultdict(list)

if N == 1 and M == 0:
    print(0)
    sys.exit()

for s, c in SC:
    ll[s - 1].append(c)
    if N != 1 and s == 1 and c == 0:
        print(-1)
        sys.exit()

ans = 0
for k, v in ll.items():
    if len(v) == 1:
        ans += v[0] * 10**(N - k - 1)
    elif len(list(set(v))) == 1:
        ans += v[0] * 10**(N - k - 1)
    else:
        print(-1)
        sys.exit()

if len(str(ans)) < N:
    ans += 10**(N - 1)

print(ans)


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            C();
        }

        static void C()
        {
            var N = ReadInt();
            var An = ReadSplitInt();
            var list = new int[N+1];
            var list2 = new int[N + 1];

            for (int i = 0; i < N; i++)
                list[i+1] = Gcd(list[i], An[i]);

            for (int i = N-1; i >= 0; i--)
                list2[i] = Gcd(list2[i+1], An[i]);

            var ans = 0;
            for (int i = 0; i < N; i++)
                ans = Max(ans, Gcd(list[i], list2[i + 1]));

            Println(ans);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b)
        {
            if (a < b)
                return Gcd(b, a);

            while (b != 0)
            {
                var tmp = a % b;
                a = b;
                b = tmp;
            }
            return a;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

typedef long long int ll;

ll n,k;
ll arr[105];
ll dp[100005];

ll solve(ll i){
	//cout<<i<<endl;
	if(i<=0)return 0;
	
	if(dp[i]==-1){
		
		ll z = 0;
		for(ll j=0;j<n;++j){
			if(arr[j]<=i)
			z |= solve(i-arr[j])^1; 
			
		}
		dp[i] = z;
	}
	return dp[i];
}

int main(){
	
	memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    
    for(ll i=0;i<n;i++)cin>>arr[i];
    
    solve(k) ? cout<<"First"<<endl : cout<<"Second"<<endl;
    

}

Measured memory_bytes: 4096
N, M, K = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
s = 0
for i, a in enumerate(A):
    if s + a > K:
        break
    s += a
else:
    i += 1
for j, b in enumerate(B):
    if s + b > K:
        break
    s += b
else:
    j += 1

ans = i + j
while i:
    i -= 1
    s -= A[i]
    while j < M and s + B[j] <= K:
        s += B[j]
        j += 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 40948
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            long M = in.nextLong();
            long[] a = in.nextLongArray(N);

            for (int i = 0; i < N; i++) {
                a[i] /= 2;
            }
            int t = f(a[0]);
            for (int i = 0; i < N; i++) {
                if (t != f(a[i])) {
                    out.println(0);
                    return;
                }
                a[i] >>= t;
            }
            M >>= t;

            long lcm = 1;
            for (int i = 0; i < N; i++) {
                lcm = lcm(lcm, a[i]);
                if (lcm > M) {
                    out.println(0);
                    return;
                }
            }
            M = M / lcm;
            long ans = (M + 1) / 2;
            out.println(ans);
        }

        int f(long a) {
            int ret = 0;
            while (a % 2 == 0) {
                ret++;
                a /= 2;
            }
            return ret;
        }

        long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        long lcm(long a, long b) {
            return a / gcd(a, b) * b;
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

        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: 38920
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

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

    map<int, vector<P>> mm;
    rep(i, m){
        int p, y;
        cin >> p >> y;

        if(mm.find(p) == mm.end()){
            mm[p] = vector<P>();
        }
        mm[p].emplace_back(y, i);
    }

    vector<P> ans(m);
    for(pair<int, vector<P>> p : mm){
        sort(p.second.begin(), p.second.end());

        int num = 0;
        for(P pp : p.second){
            ans[pp.second] = {p.first, num++};
        }
    }

    rep(i, m){
        printf("%06lld%06lld\n", ans[i].first, ans[i].second+1);
    }

    return 0;
}


Measured memory_bytes: 13952
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        if (360 % X == 0) {
            System.out.println(360/X);
            return;
        }
        int lcm = lcm(360, X);
        System.out.println(lcm/X);
    }
    private int gcd(int x, int y) {
        if (y == 0) {
            return x;
        }
        return gcd(y, x % y);
    }
    private int lcm(int x, int y) {
        int gcd = gcd(x, y);
        return x / gcd * y;
    }
}


Measured memory_bytes: 35376
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int a[200001],b[200001];
void solve()
{
	int n, maxi = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	for (int i = 0; i < n; i++)
	{
		if (a[i] == b[n - 1])
		{
			cout << b[n - 2] << "\n";
		}
		else
			cout << b[n - 1] << "\n";
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}


Measured memory_bytes: 3200
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A, B = sorted(A), sorted(B)
m1 = A[N//2] + A[(N-1)//2]
m2 = B[N//2] + B[(N-1)//2]
print((m2 - m1) // (N % 2 + 1) + 1)

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

using namespace std;


int main () {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  
  string s; cin >> s;
  stack<char> ss;
  for (int i = 0; i < (int) s.size(); ++i) {
    if (s[i] == 'B') {
      if (ss.size()) {
        ss.pop();
      }
    }else {
      ss.push(s[i]);
    }
  }string ans = "";
   while (ss.size()) {
     ans += ss.top();
     ss.pop();
   }

   reverse(ans.begin(), ans.end());
   cout << ans << '\n';

  return 0;
}




Measured memory_bytes: 3648
import java.util.Scanner;

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

	long A, B, K;
	A = sc.nextLong();
	B = sc.nextLong();
	K = sc.nextLong();

	if (A > K) {
	    A -= K;
	} else {
	    K -= A;
	    A = 0;
	    if (B > K) {
		B -= K;
	    } else {
		K -= B;
		B = 0;
	    }
	}

	System.out.println(A + " " + B);
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll f[1000009],fi[1000009],inv[1000009],D[1000009];
ll mod = 1e9 + 7;
ll C(int n, int m){
    if(m < 0 ||m > n) return 0;
    return f[n] * fi[m] % mod * fi[n -m]% mod;
}

main(){
   int n, m;
   cin >> n >> m;
   D[1] = 0;
   D[0] = 1;
   for(int i = 2; i <= m; i++)
        D[i] = (i - 1) * (D[i-1] + D[i-2]) % mod;
   for(int i = 1; i <= n; i++){

   }
   f[0] = 1; f[1] = 1;
   fi[0] =1 ; fi[1] = 1;
   inv[1] = 1;
   for(int i = 2; i <= m; i++){
        f[i] = f[i-1] * i % mod;
        inv[i] = inv[mod % i] * (mod - mod/ i) % mod;
        fi[i]= fi[i-1] * inv[i] % mod;
   }
   ll ans = 0;
   for(int i = 0; i <= n; i++){
        ll sgn;
        if(i % 2 == 0) sgn = 1;
        else sgn = mod - 1;
        ans = (ans + sgn * C(n, i) % mod * C(m, i) % mod * C(m-i, n -i) % mod * C(m - i, n - i) % mod * f[i] % mod * f[n-i] % mod * f[n-i]) % mod;
   }
   cout << ans << endl;
}

Measured memory_bytes: 19028
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()


int main() {
    int N;
    string s[10000];
    cin >> N;
    REP(i, N) cin >> s[i];

    int ans = 0, asum = 0, bsum = 0;
    REP(i, N) {
        if (s[i][0] == 'B') bsum++;
        if (s[i][s[i].length() - 1] == 'A') asum++;
        REP(j, s[i].length() - 1) {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++;
        }
    }
    if (asum == bsum && asum > 0) {
        bool ba = true;
        REP(i, N) {
            if (s[i][0] == 'B' || s[i][s[i].length() - 1] == 'A') {
                if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A');
                else {
                    ba = false;
                    break;
                }
            }
        }
        if (ba) ans--;
    }
    cout << min(asum, bsum) + ans << endl;
    return 0;
}

Measured memory_bytes: 768