akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n;
    cin >> n;
    string ans;
    if(n % 10 == 3) ans = "bon";
    else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) ans = "pon";
    else ans = "hon";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

int main() {
    ll N, K, S;
    vector<ll>ans;

    cin >> N >> K >> S;

    for (int i = 0; i < K; i++) {
        ans.push_back(S);
    }

    for (int i = 0; i < N-K; i++) {
        if (S == 1000000000) {
            ans.push_back(S-1);
        } else {
            ans.push_back(1000000000);
        }
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}



Measured memory_bytes: 2292
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		int C=stdIn.nextInt();
		if(C-(A-B)<0)
			System.out.println(0);
		else
			System.out.println(C-(A-B));
	}
}

Measured memory_bytes: 22100
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())

priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

void solve(){
    llint n;
    cin >> n;
    string alpha="";
    for(char c='a';c<='z';c++)alpha+=c;
    string ans="";
    while(n!=0){
        n--;
        ans+=alpha[n%26];
        n/=26;
    }
    reverse(ans);
    cout << ans << endl;
}

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




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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	*/
	string s;
	string t;
	cin>>s>>t;

	long long int n=s.length();
	long long int m=t.length();

	long long int dp[n+1][m+1];

	for(long long int i=0;i<=n;i++) {
		for(long long int j=0;j<=m;j++) {
			if(i==0 || j==0) {
				dp[i][j]=0;
			}
			else if(s[i-1]==t[j-1]) {
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else {
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	//cout<<dp[n][m]<<"\n";

	long long int i=n,j=m;
	long long int len=dp[n][m];

	vector <char> ans;

	while(i>0 && j>0 && len>0) {
		if(s[i-1]==t[j-1]){
			ans.push_back(s[i-1]);
			i--,j--,len--;
		}
		else if(dp[i-1][j]>dp[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	reverse(ans.begin(),ans.end());
	for(auto x:ans)
		cout<<x;
	cout<<"\n";
}

Measured memory_bytes: 70656
s = list(input())
t = list(input())
n = len(s)
m = len(t)
if n < m:
    print('UNRESTORABLE')
else:
    f2 = False
    for i in range(n, m-1 , -1):
        f = True
        num = i
        for j in range(1,m+1):
            if s[i-j] != t[-j] and s[i-j] != '?':
                f = False
                break
        if f:
            f2 = True
            break
    if f2:
        for j in range(1, m+1):
            s[num-j] = t[-j]
        for i in range(n):
            if s[i] =='?':
                s[i]= 'a'
        print(''.join(s))
    else:
        print('UNRESTORABLE')

Measured memory_bytes: 38256
n = int(input())
testimony = []  # 各iの証言

for i in range(n):
    t = []
    for _ in range(int(input())):
        x, y = map(int, input().split())
        t.append((x - 1, y)) 
    testimony.append(t)


best = 0  # 正直者の最大人数

# 「<<」はビット演算を表す
# 1 << 1 ならば　0001 → 0010　なので 2
# 1 << 2 ならば　0001 → 0100　なので 4
# 1 << 3 ならば　0001 → 1000　なので 8
# 3人なら 000, 001, 010, 011, 100, 101, 110, 111 の8通りが考えられる
# 1の部分が正直者、0が不親切者、111だと3人とも正直者
# honest=0 ならば 正直者は0、honest=1　ならば　正直者は1(index=0)
# honest=2 ならば 正直者は2(index=1)、honest=3　ならば　正直者は1と2(011 2進数)
for honest in range(1 << n):  # 正直者をあらかじめ仮定して破綻を確認する
    for i in range(n):  # 証言者i
        if not (honest >> i) & 1:  # iが不親切な人なら証言を聞かない
            continue # 「continue」はfor文スキップを表す
        for j, t in testimony[i]:  # iによるjに対する証言t
            if (honest >> j) & 1 != t:  # jに対する仮定とtが食い違えば破綻
                break # for文を抜ける
        else:
            continue
        break
    else:  # 全ての正直者に話を聞いて破綻が無ければ更新
        best = max(best, bin(honest).count('1'))

print(best)

Measured memory_bytes: 3064
n = int(input())

def dfs(val, A):
    if val > n:
        return
    A.append(val)
    dfs(10 * val + 3, A)
    dfs(10 * val + 5, A)
    dfs(10 * val + 7, A)

A = []
dfs(3, A)
dfs(5, A)
dfs(7, A)

cnt = 0
for v in A:
    if len(set(list(str(v)))) == 3:
        cnt += 1
print(cnt)

Measured memory_bytes: 43228
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int add = A + B;
		int sub = A - B;
		int mul = A * B;
		
		int ans = add;
		if(sub > ans) {
			ans = sub;
		}
		if(mul > ans) {
			ans = mul;
		}
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int M,Nmin,Nmax;
    cin >> M >> Nmin >> Nmax;
    while(M){
        vector<int> V(M);
        rep(i,0,M)cin >> V[i];
        int maxd = 0,maxi;
        rep(i,Nmin-1,Nmax){
            if(maxd <= V[i] - V[i+1]){
                maxd = V[i] - V[i + 1];
                maxi = i + 1;
            }
        }
        cout << maxi << endl;
        cin >> M >> Nmin >> Nmax;
    }
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VL;

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

    int a[5], k;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;

    bool ans = true;
    for (int i = 0; i < 4; ++i) {
      for (int j = i + 1; j < 5; ++j) {
        if (abs(a[i] - a[j]) > k) {
          ans = false;
        }
      }
    }

    if (ans) {
      cout << "Yay!" << endl;
    } else {
      cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9+5;
vector<int>v[100002];
void dfs(int node,int dp[],bool vis[])
{
    vis[node]=true;
    for(int i=0;i<v[node].size();i++){
        if(!vis[v[node][i]]){
            dfs(v[node][i],dp,vis);
        }
        dp[node]=max(dp[node],1+dp[v[node][i]]);
        //cout<<dp[node]<<" "<<dp[v[node][i]]<<endl;
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
    }
    bool vis[n+1];
    memset(vis,false,sizeof(vis));
    int dp[n+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i,dp,vis);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8960
n = int(input())
d = [[0, 0] for _ in range(n)]
for i in range(n):
    d[i] = list(map(int, input().split()))
d = [[dd[0], dd[1], dd[0]+dd[1]] for dd in d]
d.sort(key=lambda x: x[2])
ans = 0
target = d[0][2]
for dd in d:
    if dd[0] - dd[1] < target:
        ans += 1
    else:
        target = dd[2]
print(n-ans+1)


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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n;
    cin >> n;
    int mod = pow(10, 9) + 7;
    long long res = 1;
    for (int i = 2; i <= n; i++) {
        res = ((res % mod) * (i % mod)) % mod;
    }
    cout << res;
}


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

int main(void){
  int n,fib,f[44],i,f1=1,f2=1;

  scanf("%d",&n);

  if(n == 0 || n == 1){
    fib = 1;
  }
  else {
    for(i = 1 ; i < n ; i++){
      fib = f1 + f2;
      f1 = f2;
      f2 = fib;
    }
  }
  printf("%d\n",fib);

  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define read(x) scanf("%d",&x)
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
const int N = 1233333, mo = 1e9+7;
int n,res,fac[N],ifac[N];
void exgcd(int a, int b, int &x, int &y) {
	if(!b) {x=1; y=0; return;}
	exgcd(b,a%b,y,x); y-=a/b*x;
}
int inv(int a) {int x,y; exgcd(a,mo,x,y); return x>=0?x:x+mo;}
int C(int n, int m) {
	if (m<0||m>n) return 0;
	return 1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo;
}
int f(int k) {return 1LL*fac[k]*fac[n-1-k]%mo*C(k-1,n-k-1)%mo;}
int main() {
	read(n); ll res=0;
	fac[0]=1;rep(i,1,n) fac[i]=1LL*fac[i-1]*i%mo;
	ifac[n]=inv(fac[n]); per(i,n-1,0) ifac[i]=1LL*ifac[i+1]*(i+1)%mo;
	res=1LL*fac[n-1]*(n-1)%mo;
	rep(i,0,n-2) res=(res-f(i)+mo)%mo;
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 8960
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define N (500000+1000)
#define INF (10000000)
using namespace std;

struct Edge{int to,next;}edge[N<<2];
int n,k,a[N],pos[N],Segt[N<<2];
int head[N],num_edge,Ind[N];
priority_queue<int,vector<int>,greater<int> >q;

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
	Ind[v]++;
}

void Build(int now,int l,int r)
{
	if (l==r){Segt[now]=INF; return;}
	int mid=(l+r)>>1;
	Build(now<<1,l,mid); Build(now<<1|1,mid+1,r);
	Segt[now]=min(Segt[now<<1],Segt[now<<1|1]);
}

int Query(int now,int l,int r,int l1,int r1)
{
	if (r<l1 || l>r1) return INF;
	if (l1<=l && r<=r1) return Segt[now];
	int mid=(l+r)>>1;
	return min(Query(now<<1,l,mid,l1,r1),Query(now<<1|1,mid+1,r,l1,r1));
}

void Update(int now,int l,int r,int x,int k)
{
	if (l==r) {Segt[now]=k; return;}
	int mid=(l+r)>>1;
	if (x<=mid) Update(now<<1,l,mid,x,k);
	else Update(now<<1|1,mid+1,r,x,k);
	Segt[now]=min(Segt[now<<1],Segt[now<<1|1]);
}

void Toposort()
{
	int cnt=0;
	for (int i=1; i<=n; ++i) if (!Ind[i]) q.push(i);
	while (!q.empty())
	{
		int x=q.top(); q.pop(); a[x]=++cnt;
		for (int i=head[x]; i; i=edge[i].next)
		{
			Ind[edge[i].to]--;
			if (!Ind[edge[i].to]) q.push(edge[i].to);
		}
	}
	for(int i=1; i<=n; ++i) printf("%d\n",a[i]);
}

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1; i<=n; ++i)
		scanf("%d",&a[i]),pos[a[i]]=i;;
	Build(1,1,n);
	for (int i=n; i>=1; --i)
	{
		int x=Query(1,1,n,pos[i]+1,min(pos[i]+k-1,n));
		if (x!=INF) add(pos[i],pos[x]);
		int y=Query(1,1,n,max(pos[i]-k+1,1),pos[i]-1);
		if (y!=INF) add(pos[i],pos[y]);
		Update(1,1,n,pos[i],i);
	}
	Toposort();
}

Measured memory_bytes: 26240
N = int(input())
A = [int(i) for i in input().split()]

l, r = A[0], sum(A[1:])
mi = abs(l - r)
for a in A[1:N - 1]:
    l, r = l + a, r - a
    mi = min(mi, abs(l - r))
print(mi)

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

#define ll long long int
#define endl '\n'

void solve()
{
    ll d,t,s;
    cin>>d>>t>>s;
    if(d <= (t*s))
    	cout<<"Yes";
    else
    	cout<<"No";
    
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef JAY
        freopen("C:/Users/jayra/Desktop/cp/input.txt","r",stdin);
        freopen("C:/Users/jayra/Desktop/cp/output.txt","w",stdout);
    #endif

    
        solve();
  
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define ll long long
#define LL ll
#define mem(arry,x) memset(arry,x,sizeof(arry))
const int maxn=1e2+10;
const int INF=0x3f3f3f3f;
const double eps=1e-6;
int k,n,m,cnt,head[maxn*2],Rank[maxn*2],S,T,xx[2*maxn],yy[2*maxn];
struct Edge
{
    int v,f,next;
}edge[maxn*maxn*maxn];
void init()
{
    mem(head,-1);
    cnt=0;
    S=0;
    T=2*n+1;
}
void add(int u,int v,int f)
{
    edge[cnt].next=head[u];
    edge[cnt].f=f;
    edge[cnt].v=v;
    head[u]=cnt++;
}
bool ok(int a,int b)
{
    if(xx[a]<xx[b]&&yy[a]<yy[b]) return true;
    return false;
}
bool Bfs()
{
    mem(Rank,-1);
    queue<int> q;
    q.push(S);
    Rank[S]=1;
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=head[x];i!=-1;i=edge[i].next){
            int v=edge[i].v,f=edge[i].f;
            if(!f||Rank[v]!=-1) continue;
            Rank[v]=Rank[x]+1;
            q.push(v);
        }
    }
    if(Rank[T]==-1) return false;
    return true;
}
int dfs(int x,int mark)
{
    int used=0;
    if(x==T) return mark;
    for(int i=head[x];i!=-1;i=edge[i].next){
        int v=edge[i].v,f=edge[i].f;
        if(Rank[v]!=Rank[x]+1||!f) continue;
        int c=dfs(v,min(mark-used,f));
        edge[i].f-=c;
        edge[i^1].f+=c;
        used+=c;
        if(used==mark) break;
    }
    if(!used) Rank[x]=-1;
    return used;
}
int Dinic()
{
    int res=0;
    while(Bfs()){
        while(int x=dfs(S,INF)) res+=x;
    }
    return res;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        init();
        for(int i=1;i<=2*n;i++) scanf("%d%d",xx+i,yy+i);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(ok(i,j+n)){
                    add(i,j+n,1);
                    add(j+n,i,0);
                }
            }
        }
        for(int i=1;i<=n;i++) add(S,i,1),add(i,S,0);
        for(int i=n+1;i<=2*n;i++) add(i,T,1),add(T,i,0);
        int res=Dinic();
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

typedef long long ll;
using namespace std;

int pot (ll q, ll w){
	ll qw = q;
	q = 1;
	for (int i = 0; i<w; i++)
		q*= qw;
	return q;
}

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

ll n,k,x,d=0;

cin >> n >> k;

x = n%k;
ll px = x;
while (d == 0){
	x -= k;
	x = abs(x);
	if (x<px)
		px = x;
	else 
		d = 1;
}

cout << px;
return 0;
}



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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<tuple>
#include<set>

using namespace std;

int main(){
  for(int M,N;cin>>M>>N,M;){
    int D,ns;
    cin>>D>>ns;
    int k[21][21]={};
    for(int i=0;i<ns;i++){
      char H,d;
      int V;
      cin>>H>>d>>V;
      cin>>k[H-'a'][V];
    }
    int nc;
    cin>>nc;
    bool uc[21][21][21][21]={};
    while(nc--){
      char H1,d1,H2,d2;
      int V1,V2;
      cin>>H1>>d1>>V1>>H2>>d2>>V2;
      uc[H1-'a'][V1][H2-'a'][V2]=uc[H2-'a'][V2][H1-'a'][V1]=true;
    }
    int nj;
    cin>>nj;
    int jam[21][21][21][21]={};
    while(nj--){
      char H1,d1,H2,d2;
      int V1,V2,d;
      cin>>H1>>d1>>V1>>H2>>d2>>V2>>d;
      jam[H1-'a'][V1][H2-'a'][V2]=jam[H2-'a'][V2][H1-'a'][V1]=d;
    }
    char H1,d1,H2,d2;
    int V1,V2;
    cin>>H1>>d1>>V1>>H2>>d2>>V2;
    set<tuple<int,int,int,int> > s;
    s.insert(make_tuple(0,H1-'a',V1,1));
    for(auto e:s){
      if(get<1>(e)==H2-'a'&&get<2>(e)==V2){
	cout<<get<0>(e)<<endl;
	break;
      }
      for(int i=1;i<=3;i++){
	int nd=(get<3>(e)+i+2)%4;
	static int dy[]={-1,0,1,0};
	static int dx[]={0,1,0,-1};
	int sy=get<1>(e);
	int sx=get<2>(e);
	int ny=sy+dy[nd];
	int nx=sx+dx[nd];
	if(ny<0||M<=ny||nx<1||N<nx||uc[sy][sx][ny][nx])continue;
	int nt=get<0>(e)+D+jam[sy][sx][ny][nx];
	if(k[ny][nx]&&nt%(2*k[ny][nx])<k[ny][nx]==nd%2)continue;
	s.insert(make_tuple(nt,ny,nx,nd));
      }
    }
  }
}

    

Measured memory_bytes: 6060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const double PI = 3.14159265358979323846;

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    if (h >= 12) h = h - 12;
    double radL = m * 6.0;
    double radS = (h * 60.0 + m) * 0.5;
    double rad = abs(radS - radL);
    rad = min(rad, 360 - rad);
    double ans = a * a + b * b - 2 * a * b * cos(PI / 180.0 * rad);
    cout << fixed << setprecision(10) << sqrt(ans) << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
  #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
  #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<string, int> mp;
    int n; cin >> n;
    rep (i, n) {
        string s; cin >> s;
        mp[s]++;
    }
    int m; cin >> m;
    rep (i, m) {
        string s; cin >> s;
        mp[s]--;
    }
    int ans = 0;
    for (auto [s, x] : mp) chmax(ans, x);
    cout << ans << "\n";
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

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

int main(){
    string S;
    bool flag=true;
    cin >> S;
    if(S.size()%2==1){
	cout << "No" << endl;
	return 0;
    }
	

    for(int i=0; i<S.size(); i+=2){
	if(S[i]=='h' && S[i+1]=='i')
	    ;
	else
	    flag=false;
    }

    cout << (flag? "Yes": "No") << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define pb push_back;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<char, char> c_c;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
const int INF = 1000000007;
const ll LLINF = 1000000000000000007LL;

int r, s, p;

int jan(char c){
    if(c == 'r') return p;
    if(c == 's') return r;
    else return s;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    

    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;
    for(int i=0; i<n; i++){
        if(k < i+1){
            if(t.at(i) != t.at(i-k)) ans += jan(t.at(i));
            else t.at(i) = 'a';
        }
        else ans += jan(t.at(i));
        //cout << ans << endl;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int A,B,M;
    cin>>A>>B>>M;
    int P[A];
    for(int i=0;i<A;i++){
        cin>>P[i];
    }
    int Q[B];
    for(int i=0;i<B;i++){
        cin>>Q[i];
    }
    int a,b,c;
    int S[M];
    for(int i=0;i<M;i++){
        cin>>a>>b>>c;
        S[i]=P[a-1]+Q[b-1]-c;
    }
    int min1=100000,min2=1000000;
    for (int i=0;i<A;i++){
        if(min1>P[i]){
            min1=P[i];
        }
    }
    for(int i=0;i<B;i++){
        if(min2>Q[i]){
            min2=Q[i];
        }
    }
    int min=min1+min2;
    for(int i=0;i<M;i++){
        if(min>S[i]){
            min =S[i];
        }
    }
    cout<<min<<endl;
}


Measured memory_bytes: 1408
import java.util.Scanner;
import java.io.BufferedInputStream;
import java.lang.Math;

public class Main{
    public static void main(String [] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int N = sc.nextInt();
        int M = sc.nextInt();
        int [] cnt = new int [N];
        boolean ok = false;
        for(int i = 0; i < M; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            if((x == 0) || (y == 0)) {
                cnt[x+y] += 1;
                if(cnt[x+y] == 2) {
                    ok = true;
                }
            }
            if((x == N-1) || (y == N-1)) {
                cnt[x+y-N+1] += 1;
                if(cnt[x+y-N+1] == 2) {
                    ok = true;
                }
            }
        }
        if(ok) {
            System.out.println("POSSIBLE");
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 94832
n = int(input())
A = list(map(int, input().split()))

maxlen = max(A)

C1 = [0] * (maxlen + 1)

for a in A:
  C1[a] += 1

for i in range(0, len(C1)-1):
  C1[i+1] += C1[i]

B = [0] * n
for i in range(n-1, -1, -1):
  C1[A[i]] -= 1
  B[C1[A[i]]] = A[i]

print (' '.join(map(str, B)))


Measured memory_bytes: 240576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int w = Integer.parseInt(in[1]);

        int[] W = new int[n];
        long[] V = new long[n];

        for(int i=0;i<n;i++){
            in = br.readLine().split(" ");
            W[i] = Integer.parseInt(in[0]);
            V[i] = Long.parseLong(in[1]);
        }
        long[][] dp = new long[n][w+1];

        for(int i=0;i<n;i++){
            for(int j=1;j<w+1;j++){
                if(i==0){
                    if(j>=W[0])
                        dp[i][j] = V[0];
                    continue;
                }
                dp[i][j] = dp[i-1][j];
                if(j-W[i]>=0){
                    dp[i][j] = Math.max(dp[i][j],V[i]+dp[i-1][j-W[i]]);
                }
            }
        }
//        for(int i=0;i<n;i++){
//            for(int j=0;j<w+1;j++){
//                System.out.print(dp[i][j]+" ");
//            }
//            System.out.println();
//        }
        System.out.println(dp[n-1][w]);
    }
}


Measured memory_bytes: 126164
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    pair<pair<string, int>, int> rest[N];
    for(int i = 0; i < N; i++){
        string S;
        int P;
        cin >> S >> P;
        rest[i] = {{S, -P}, i + 1};
    }
    sort(rest, rest + N);
    for(int i = 0; i < N; i++){
        cout << rest[i].second << endl;
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0;i<n;++i) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());

    int m_min = 0, m_max = 0;
    if(n % 2) {
        m_min = 2 * a[n/2];
        m_max = 2 * b[n/2];
        cout << (m_max/2 - m_min/2 +1) << endl;
    } else {
        m_min = a[n/2-1] + a[n/2];
        m_max = b[n/2-1] + b[n/2];
        cout << (m_max - m_min + 1) << endl;
    }
    
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){
    
    int N;cin>>N;
    ll C;cin>>C;
    vector<ll> X(N),V(N),A(N,0),B(N,0);
    for(int i=0;i<N;i++){
        cin>>X[i]>>V[i];
        A[i]=V[i]-X[i];
        B[i]=V[i]-(C-X[i]);
    }
    ll ma1=A[0],ma2=B[N-1];
    for(int i=1;i<N;i++){
        A[i]=A[i]+A[i-1]+X[i-1];
    }
    for(int i=1;i<N;i++){
        if(A[i]>ma1){
            ma1=A[i];
        }else{
            A[i]=ma1;
        }
    }
    for(int i=N-2;i>=0;i--){
        B[i]=B[i]+B[i+1]+(C-X[i+1]);
    }
    for(int i=N-2;i>=0;i--){
        if(B[i]>ma2){
            ma2=B[i];
        }else{
            B[i]=ma2;
        }
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        ans=max(ans,max(A[i],B[i]));
    }
    for(int i=0;i<N-1;i++){
        ll a=A[i]+B[i+1]-X[i];
        ans=max(ans,a);
    }
    for(int i=N-1;i>=1;i--){
        ll a=B[i]+A[i-1]-(C-X[i]);
        ans=max(ans,a);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
N, B = map(int, input().split())
ana = []
dp = [0] * (N+2)

for i in range(B):
    ana.append(int(input()))

mod = 1000000007

dp[N] = 1
for i in reversed(range(N)):
    if len(ana) >= 1 and i == ana[-1]:
        dp[i] = 0
        if len(ana) != 0:
            ana.pop(-1)
        continue
    dp[i] = dp[i + 1] + dp[i + 2]
print(dp[0] % mod)

Measured memory_bytes: 460020
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    string s;
    cin >> s;
    ll bcnt = 0;
    ll ans = 0;
    for(const auto &c : s) {
        if (c == 'B') bcnt++;
        else ans+= bcnt;
    }
    cout << ans << endl;
}

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


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

int main(void){
 int N;
  cin >> N;
  vector<int> X(N);
  vector<int> S(N);
  for(int i = 0; i < N; i++){
    int temp;
    cin >> temp;
    X[i] = temp;
    S[i] = temp;
  }
  sort(S.begin(), S.end());
  int center = S[N / 2 - 1];
  int cp = S[N / 2];
  for(int i = 0; i < N; i++){
    if(X[i] <= center){
      cout << cp << endl;
    }
    else cout << center << endl;
  }
  
  
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long 
#define F(n) for(int i = 0; i < n; ++i)
#define Debug cout<<endl<<"I AM IRONMAN"<<endl

int main ()
{
    fastio;
    unordered_map<int,bool> map;
    int t;
    cin >> t;
    while(t--)
    {
        int a;
        cin >> a;
        if(map[a]==true)
        {
            map.erase(a);
            continue;
        }
        map[a]=true;
    }
    cout << map.size();
    return 0;
}

Measured memory_bytes: 7292
"""
○ 角速度 = θ / t [rad/s]
・時針
ω = θ / t
  = math.radians(360) / (12 * 60 * 60) [rad/s]
・分針
ω = θ / t
  = math.radians(360) / (60 * 60) [rad/s]
"""

import math

def colon():
    # 入力
    A, B, H, M = map(int, input().split())
    # 時針と分針の角速度
    angular_velocity_h = math.radians(360) / (12 * 60 * 60)
    angular_velocity_m = math.radians(360) / (60 * 60)
    # 0時を基準に時針が何度傾いたか
    radian_h = angular_velocity_h * ((H * 60 * 60) + (M * 60))
    # 0時を基準に分針が何度傾いたか
    radian_m = angular_velocity_m * (M * 60)
    # 時針と分針の間の角度
    radian_hm = abs(radian_h - radian_m)
    if radian_hm > math.pi:
        radian_hm = 2 * math.pi - radian_hm
    elif radian_hm == math.pi:
        return A + B
    elif math.pi > radian_hm:
        pass
    # 端点の距離
    distance = math.sqrt((A**2 + B**2) - (2 * A * B * math.cos(radian_hm)))
    # 戻り値
    return distance

result = colon()
print(result)

Measured memory_bytes: 9532
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<29;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;cin>>n;
  string s[n];
  cout<<0<<endl;
  cin>>s[0];
  if(s[0]=="Vacant")return 0;
  int left=0,right=n,mid;
  while(true){
    mid=(left+right)/2;
    cout<<mid<<endl;
    cin>>s[mid];
    if(s[mid]=="Vacant")break;
    if(s[left]==s[mid]&&(mid-left)%2==1)
    {right=mid;continue;};
    if(s[left]!=s[mid]&&(mid-left)%2==0)
      {right=mid;continue;};
    left=mid;
    }
  return 0;
  }

Measured memory_bytes: 1620
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  char a, b, c, d, e, f, g, h, i;
  cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
  cout << a << e << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n,x[110],cnt,ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(x[i]);
	ans=(1e9);
	for (int i=0;i<=100;i++) {
		cnt=0;
		for (int j=1;j<=n;j++) cnt+=(x[j]-i)*(x[j]-i);
		ans=min(ans,cnt);
	}
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

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


int main() {
    long long n,m,t;
    cin >> n >> m;
    while(m--)
    {
        cin >> t;
        n-=t;
    }
    if (n<0)
        cout << -1;
    else
        cout << n;
    return 0;
}

Measured memory_bytes: 3668
import math

def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)

k = int(input())

c = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        for h in range(1, k + 1):

            t = gcd(i, j, h)

            c += t

print (c)


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

int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int na = min(k,a);
	k-=na;
	int nb = min(b, k);
	k-=nb;
	int nc = min(c, k);
	k-=nc;
	cout<<na-nc;
  return 0;
}

Measured memory_bytes: 3644
N = int(input())
Ds = []
for _ in range(N):
    D = list(map(int, input().split()))
    Ds.append(D)

count = 0
for one, two in Ds:
    if not one == two:
        count = 0
        continue

    count += 1
    if count == 3:
        print("Yes")
        break

if not count == 3:
    print("No")

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

int main()
{
    string S,T;
    cin>>S>>T;
    int l=S.size();
    int t=T.size();
    if(l!=t)
    {
        cout<<"No"<<endl;
        return 0;
    }
    else
    {
        for(int i=0;i<l;i++)
        {
            std::rotate(S.begin(), S.begin()+1, S.end());
            if(S==T)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

#[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>();
    let mut aseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read::<i32>();
    }
    let mut bseq = VecDeque::<i32>::new();
    for i in 0..n {
        if i % 2 == 0 {
            bseq.push_back(aseq[i]);
        } else {
            bseq.push_front(aseq[i]);
        }
    }
    if n % 2 == 1 {
        bseq = bseq.into_iter().rev().collect::<VecDeque<i32>>();
    }
    for i in 0..n {
        if i != 0 {
            print!(" ");
        }
        print!("{}", bseq[i]);
    }
    println!("");
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

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

int decode(const string& str,unordered_map<char,int>& table){
    int res=0,b=1;
    for(int i=str.size()-1; i>=0; --i){
        res+=table[str[i]]*b;
        b*=10;
    }
    return res;
}

int permutation(int n){
    int res=1;
    for(int i=1; i<=n; ++i) res*=i;
    return res;
}

void solve(){
    while(true){
        int n;
        cin >> n;
        if(n==0) break;

        vector<string> strs(n);
        int max_length=0;
        for(int i=0; i<n; ++i){
            cin >> strs[i];
            if(i!=n-1) max_length=max(max_length,(int)strs[i].size());
        }
        if(max_length>strs.back().size()){
            cout << 0 << endl;
            continue;
        }

        vector<int> weight(26);
        vector<bool> not0(26,false);
        const char A='A';
        for(int i=0; i<strs.size(); ++i){
            const string& str=strs[i];
            if(str.size()!=1) not0[str[0]-A]=true;
            int b=1;
            for(int j=str.size()-1; j>=0; --j){
                if(i==n-1) weight[str[j]-A]-=b;
                else weight[str[j]-A]+=b;
                b*=10;
            }
        }

        vector<char> appear;
        for(string& str:strs) for(char ch:str) appear.push_back(ch);
        sort(appear.begin(),appear.end());
        appear.erase(unique(appear.begin(),appear.end()),appear.end());

        vector<int> num;
        rep(i,0,10) num.emplace_back(i);
        int ans=0;
        do{
            string perm;
            int sum=0;
            bool ok=true;
            rep(i,0,appear.size()){
                sum+=weight[appear[i]-A]*num[i];
                if(num[i]==0 and not0[appear[i]-A]){
                    ok=false;
                    break;
                }
            }
            if(ok and sum==0) ++ans;
        }while(next_permutation(num.begin(),num.end()));
        cout << ans/permutation(10-appear.size()) << endl;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
    solve();
	return 0;
}

Measured memory_bytes: 3032
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+5 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
int a[N] ;
int vis[N] ;
void solve(){
	int n , k ;
	cin >> n >> k ;
	vi a(n) ;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i] ;
	}
	int cur = 1 ;
	int mn = min(k,N) ;
	k -= mn ;
	while(mn){
		cur = a[cur] ;
		mn-- ;
	}
	if(k==0){
		cout << cur << endl ;
		return ;	
	}
	int cyc = 0 ;
	while(!vis[cur]){
		vis[cur] = 1 ;
		cyc++ ;
		cur = a[cur] ;
	}
	k %= cyc ;
	while(k){
		cur = a[cur] ;
		k-- ;
	}
	cout << cur << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 6480
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long res = 1000000000009;
    for(long long int i = 1;i<=sqrt(n);i++){
        if(n%i ==0){
            long long divisor = n/i;
            long long temp_ans = divisor-1 + i-1;
//            cout<<i<<" "<<temp_ans<<endl;
            res = min(res, temp_ans);
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    
    long long m1 = a * c;
    long long m2 = a * d;
    long long m3 = b * c;
    long long m4 = b * d;
    
    cout << max(max(m1,m2), max(m3,m4));
    
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, C, K;
	cin >> N >> C >> K;
	vector<int> T(N);
	for (auto& x : T) cin >> x;
	sort(T.begin(), T.end());
	int r = 0;
	int n = 0, s = -1;
	for (auto x : T) {
		if (n == 0 || s + K < x || n == C) {
			n = 1;
			s = x;
			++ r;
		} else {
			++ n;
		}
	}
	cout << r << endl;
}


Measured memory_bytes: 640
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, M, X, Y = mi()
    x = list(mi())
    y = list(mi())
    for z in range(-100, 101):
        if max(x) < z <= min(y) and X < z <= Y:
            print('No War')
            return

    print('War')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <string.h>

#define pb push_back
#define MAX 110

using namespace std;

int ans;
int num[MAX];
int n;
long long dp[MAX][22];

//long long enzan(int sum,int i);

int main(void)
{
	int i1,i2;
	long long c;

	cin>>n;
	vector<int> v(n);
	for(i1=0;i1<n-1;i1++){
		cin>>num[i1];
	}
	cin>>ans;
	memset(dp,0,sizeof(dp));
	dp[0][num[0]]=1;
	//cout<<enzan(0,0)<<endl;

	for(i1=1;i1<n;i1++){
		for(i2=0;i2<=20;i2++){
			if(dp[i1-1][i2]!=0){
				if((i2+num[i1])<=20) dp[i1][i2+num[i1]]+=dp[i1-1][i2];
				if((i2-num[i1])>=0) dp[i1][i2-num[i1]]+=dp[i1-1][i2];
			}
		}
	}

	/*for(i1=0;i1<n;i1++){
		for(i2=1;i2<=20;i2++){
			cout<<dp[i1][i2]<<" ";
		}
		cout<<endl;
	}*/

	cout<<dp[n-2][ans]<<endl;
	return 0;

}

/*long long enzan(int sum,int i)
{
	if(i==n){
		if(sum==ans) return 1;
		else return 0;
	}
	if(0>sum || sum>20) return 0;
	if(dp[sum][i]!=0) return dp[sum][i];

	long long c=0; 
	c+=enzan(sum+num[i+1],i+1);
	c+=enzan(sum-num[i+1],i+1);
	dp[sum][i]=c;
	return c;
}*/

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<string>> s(h, vector<string>(w));
  rep(i, h) rep(j, w) cin >> s[i][j];

  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == "snuke") {
        char ans = 'A' + j;
        cout << ans << i + 1 << endl;
      }
    }
  }


  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
LL calc(LL *a) {
    sort(a, a+N);
    if (N % 2) return a[N/2];
    return (a[N/2] + a[N/2-1]) / 2;

}

LL A[200011], B[200011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) {
	scanf("%lld%lld", A+i, B+i);
    }

    if (N % 2 == 0) {
	REP (i, N) {
	    A[i] *= 2;
	    B[i] *= 2;
	}
    }


    LL mid_a = calc(A);
    LL mid_b = calc(B);

    printf("%lld\n", mid_b - mid_a + 1);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 6972
n = int(input())
h = list(map(int, input().split()))
count = 1
for i in range(1,n):
    can = True
    for j in range(i):
        if h[i] < h[i-j-1]:
            can = False
            break
    if can:
        count+=1
    else:
        continue
print(count)

Measured memory_bytes: 3060
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb1=new StringBuilder();
		StringBuilder sb2=new StringBuilder();
		String b=" ",n="\n";
        String[] rc=br.readLine().split(b);
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r+1][c+1];
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		sb1.append(h[i][j]+b);
        		if(i==r-1){
        			h[r][c]+=h[r][j];
        			sb2.append(h[r][j]+b);
        		}
        	}
        	sb1.append(h[i][c]+n);
        }
        sb1.append(sb2).append(h[r][c]);
        System.out.println(sb1);
	}
}

Measured memory_bytes: 25472