akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int n;
void dfs(string s, char mx){
    if(s.length()==n){
        cout<<s<<endl;
        return;
    }
    for(char c='a';c<=mx+1;c++){
        string t=s;
        t+=c;
        dfs(t, max(mx, c));
    }
}
int main(){
    fast_io
    
    cin>>n;
    dfs("",'a'-1);
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int, vector<int>, greater<int>> q;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    q.push(a);
  }
  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    p.at(i) = make_pair(c, b);
  }
  sort(p.begin(), p.end());
  bool f = false;
  for(int i = M - 1; i > -1; i--) {
    int b, c;
    tie(c, b) = p.at(i);
    while (b > 0) {
      if (q.top() >= c) {
        f = true;
        break;
      }
      q.pop();
      q.push(c);
      b--;
    }
    if (f) {
      break;
    }
  }
  long long int count = 0;
  for (int i = 0; i < N; i++) {
    count += q.top();
    q.pop();
  }
  printf("%lld\n", count);
}

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

int a,b;
double ans;

int main()
{
    scanf("%d %d",&a,&b);
    if(a<=5)
        ans = 0;
    else if(a >= 6 && a <= 12)
        ans = b/2;
    else
        ans = b;
    printf("%.0f\n",ans);
    return 0;
}


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

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//s.find(w[i])==string::npos
//findの使い方

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)

long long int n,cnt=0,ans=0,a[100000],b[100000],c,cmp[100000],data[100000],m,h,x,y,bsum,bsumm=0;

string s,w;

int main(void){
     cin >> n >> h;
     rep(i,n){
         cin >> a[i] >> b[i];
         bsumm+=b[i];
     }
      c=h-bsumm;
      
     sort(a,a+n);
     reverse(a,a+n);
     sort(b,b+n);
     reverse(b,b+n);
      
      while(1){
              rep(i,n){
                  if(b[i]<=a[0]){
                      x+=a[0];
                      ans++;
                  }
                  
                  else {
                      bsum+=b[i];
                      cnt++;
                      b[i]=0;
                  }
                   if(x+bsum>=h){
                      cout << ans+cnt << endl;
                      return 0;
                  }
          }
              
      }
            
     
return 0;
}


Measured memory_bytes: 1792
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize, m: usize,
        ab: [(isize, isize); n],
        cd: [(isize, isize); m],
    }

    let mut ans = vec![];
    for i in 0..n {
        let min_of_cd = cd.iter().map(|x| (x.0 - ab[i].0).abs() + (x.1 - ab[i].1).abs()).min().unwrap();
        for j in 0..m {
            if (cd[j].0 - ab[i].0).abs()+(cd[j].1 - ab[i].1).abs() == min_of_cd {
                ans.push(j+1);
                break
            }
        }
    }

    println!("{}", ans.iter().join("\n"));
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  int n;
  cin >> n;
  char march[] = "MARCH";
  vector<vector<string>> names(5);
  for (int i = 0; i < n; ++i) {
    string name;
    cin >> name;
    for (int j = 0; j < 5; ++j) {
      if (name[0] == march[j]) {
        names[j].emplace_back(move(name));
      }
    }
  }
  uint64_t counts[5] = {0, 0, 0, 0, 0};
  for (int i = 0; i < 5; ++i) {
    counts[i] = names[i].size();
  }
  uint64_t ans = 0;
  ans += counts[0] * counts[1] * counts[2];
  ans += counts[0] * counts[1] * counts[3];
  ans += counts[0] * counts[1] * counts[4];
  ans += counts[0] * counts[2] * counts[3];
  ans += counts[0] * counts[2] * counts[4];
  ans += counts[0] * counts[3] * counts[4];
  ans += counts[1] * counts[2] * counts[3];
  ans += counts[1] * counts[2] * counts[4];
  ans += counts[1] * counts[3] * counts[4];
  ans += counts[2] * counts[3] * counts[4];
  cout << ans << "\n";
}


Measured memory_bytes: 5748
#include<bits/stdc++.h>
#define f(i,n) for(long int i = 0; i<(long int)n; i++)
#define testcase ll tt; cin >> tt; while(tt--)
#define F first
#define S second
#define ll long long
#define pb push_back
#define vll vector<ll>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int main(){
  ll n; cin>>n;
  vll v(n); f(i,n) cin>>v[i];
  ll ans = 0, max = v[0];
  f(i,n) {
    if(v[i]<max) ans+=max-v[i];
    else max = v[i];
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 4784
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  dchar[] s; readV(s);
  writeln(s.uniq.walkLength-1);
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

vi c;
vi cc;
map<int, int> t_r;
vector<bool> memo;

int calc_c(int node) {
  if (memo[node]) {
    return c[node];
  }
  if (t_r[node] == 0) {
    c[node] = cc[node];
  } else {
    c[node] = cc[node] + calc_c(t_r[node]);
  }
  // printf("node=%d\n", node);
  memo[node] = true;
  return c[node];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vi a(n), b(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < n - 1; i++) {
    t_r[b[i]] = a[i];
  }
  cc = vi(n + 1, 0);
  memo = vector<bool>(n + 1, false);
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    cc[p] += x;
  }

  c = vi(n + 1, 0);

  for (int i = 1; i < n + 1; i++) {
    calc_c(i);
  }

  for (int i = 1; i < n + 1; i++) {
    printf("%d ", c[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 14976
s = input()
#s = str(1213)

s1 = s[:2]
s2 = s[2:]

#print(s1)
#print(s2)

i1 = int(s1)
i2 = int(s2)

i1MM = True
i2MM = True

if i1 > 12 or i1 == 0:
    i1MM = False
if i2 > 12 or i2 == 0:
    i2MM = False

if i1MM and i2MM:
    print("AMBIGUOUS")

if not i1MM and i2MM:
    print("YYMM")

if i1MM and not i2MM:
    print("MMYY")

if not i1MM and not i2MM:
    print("NA")


Measured memory_bytes: 3060
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    ans = 0
    A = [0] * (N + 1)
    for i in range(1, N + 1):
        A[i] += 1
        ans += A[i] * i
        for j in range(2 * i, N + 1, i):
            A[j] += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


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


#define uli         unsigned long long int
#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li cnt[66][2];

int main() {
    li n;
    cin >> n;
    rin{
        li a;
        cin >> a;
        rep(j, 60) {
            cnt[j][(a >> j) & 1]++;
        }
    }
    li res = 0;
    rep(i, 60) {
        res = (res + (cnt[i][0] * cnt[i][1] % MOD) * (bit(i) % MOD) % MOD) % MOD;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

char s[111];
int ans;

int main(){
	scanf("%s" , s);
	for(int i = 0 ; s[i] != 0 ; ++i){
		if(ans == 1 && s[i] == 'F') ++ans;
		if(ans == 0 && s[i] == 'C') ++ans;
		if(ans > 1) break;
	}
	printf("%s\n" , ans == 2 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n;
char s[1000010];
char t[1000010];
queue<int>q;
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	bool flag=true;
	for(int i=1;i<=n;i++)
		if(s[i]!=t[i])flag=false;
	if(flag){
		printf("0\n");
		return 0;
	}
	int ans=1;
	int now=n;
	for(int i=n;i>=1;i--)
	{
		if(t[i]==t[i-1])continue;
		while(now>0&&(now>i||t[i]!=s[now]))
			now--;
		if(now<=0){
			printf("-1\n");
			return 0;
		}
		while(!q.empty()&&q.front()-(q.size()-1)>i)
			q.pop();
		if(now!=i)q.push(now);
		ans=max(ans,(int)q.size()+1);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<string>
#define loi long int 
using namespace std;

// Problem https://atcoder.jp/contests/abc098/tasks/arc098_a

loi solver(loi MEMBER,string DIRECTWAY){
    loi result=3*100000;
    vector<int> eastWay(MEMBER);
    vector<int> westWay(MEMBER);
    for(loi j=0;j<MEMBER;j++){
        if(DIRECTWAY.at(j) == 'E'){
            eastWay.at(j) = 1;
            westWay.at(j) = 0;
        }
        if(DIRECTWAY.at(j) == 'W'){
            eastWay.at(j) = 0;
            westWay.at(j) = 1;
        }
    }
    // TEST1
    /**
    cout << "EAST: ";
    for(loi j=0;j<MEMBER;j++){
        cout << eastWay.at(j) << " ";
    }
    cout << endl;
      cout << "WEST: ";
    for(loi j=0;j<MEMBER;j++){
        cout << westWay.at(j) << " ";
    }
    cout << endl;**/
    // TEST1 END 
    vector<loi> accEastWay;
    vector<loi> accWestWay;
    accEastWay.clear();
    accWestWay.clear();
    // 最初は0
    accEastWay.push_back(0);
    accWestWay.push_back(0);
    for(loi j=0;j<MEMBER;j++){
        accEastWay.push_back(accEastWay.at(j)+eastWay.at(j));
        accWestWay.push_back(accWestWay.at(j)+westWay.at(j));
    }
    // TEST2
/**    cout << "ACCEAST: ";
    for(loi j=0;j<=MEMBER;j++){
        cout << accEastWay.at(j) << " ";
    }
    cout << endl;
      cout << "ACCWEST: ";
    for(loi j=0;j<=MEMBER;j++){
        cout << accWestWay.at(j) << " ";
    }
    cout << endl;**/
    // TEST2 END
    vector<loi> answer;
    answer.clear();
    for(loi j=0;j<MEMBER;j++){
        answer.push_back(accWestWay.at(j)+accEastWay.at(MEMBER)-accEastWay.at(j+1)
        );
    }
    for(loi j=0;j<MEMBER;j++){
        if(answer.at(j) < result){
            result = answer.at(j);
        }
  //      cout << answer.at(j) << " ";
    }
    return result;
}

int main(void){
    loi answer=0;
    loi N=0;
    cin >> N;
    string S;
    S.clear();
    cin >> S;
    answer = solver(N,S);
    cout << answer << endl;
    return 0;
}

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define vi vector <ll>
#define hell 1000000007
#define pii pair <ll,ll>
#define inf (ll)(1e16)
#define pb push_back
#define p 31

using namespace std;

ll ans,W;

ll helper(vi &w,vi &v,ll s,ll V,vector < vi > &dp)
{
    if(V==0)
        return 0;
    if(s>=w.size())
        return inf;
    if(dp[s][V]!=-1)
        return dp[s][V];
    dp[s][V]=min(w[s]+helper(w,v,s+1,V-v[s],dp),helper(w,v,s+1,V,dp));
    if(dp[s][V]<=W)
        ans=max(ans,V);
   // cout<<s<<" "<<dp[s][V]<<"\n";
    return dp[s][V];
}

void solve()
{
    ans=0;
    ll n;
    cin>>n>>W;
    vi v,w;
    rep(i,0,n)
    {
        ll x,y;
        cin>>x>>y;
        w.pb(x);
        v.pb(y);
    }
    ll V=n*(*max_element(begin(v),end(v)));
    vector <vi> dp(n+1,vi(V+1,-1));
    sep(i,V+1,1)
        helper(w,v,0,i,dp);
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

int main()
{
 ll x,k,d;
  cin>>x>>k>>d;
  x=abs(x);
  ll ans=x/d; ll ans1=x%d;
  if(ans<=k)
  { k=k-ans;
   if(k&1)
  { cout<<min(abs(ans1-d),abs(ans1+d));
  }
  else cout<<ans1;}
  else
  {cout<<x-(k*d);
  }
}

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

int main(){
  int N;
  int a;
  int count=0;
  cin >> N;
  //vector<int> t(N);
  for(int i=1;i<=N;i++){
    cin >>a;
    if((i%2==1)&&(a%2==1)){
      count++;
    }
  }
  cout << count << endl;
  return(0);
}


Measured memory_bytes: 3620
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	//ll a[200000] = {};
	//ll b[200000] = {};
	ll v[3] = {};
	ll *a, *b, *x;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	

	//char p;
	cin >> v[0] >> v[1] >> v[2] ;
	//cin >> S;

	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(N+1);
	//vector<bool> flag(N);
	
	//count--;
	//	cout << X << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(v.begin(), v.end());
	if (v[0] >= v[1] && v[0] >= v[2])
		cout << v[0] * 10 + v[1] + v[2] << endl;
	else if (v[0] <= v[1] && v[1] >= v[2])
		cout << v[1] * 10 + v[0] + v[2] << endl;
	else if (v[0] <= v[2] && v[1] <= v[2])
		cout << v[2] * 10 + v[0] + v[1] << endl;

	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/

	
	
	
	//cout << sum << endl;

	
	

	



	


	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define ll long long int 
#define PI 3.1415926535897932384626

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int temp=n;
	int c=0;
	while(n>0)
	{
	     c++;
	     n-=1000;
	}
	cout<<c*1000-temp;
	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string s;
int n;

int ct[1000]={};

priority_queue<string> t;
priority_queue<string, vector<string>, greater<string>> h;

void ANS(){
    set<string> ans;
    while(!h.empty()){
        ans.insert(h.top());
        h.pop();
    }
    while(!t.empty()){
        ans.insert(t.top());
        t.pop();
    }
    for(string a:ans) cout << a << endl;
}

void IN(){
    h.push(s);
    if(h.size()>5) h.pop();
    t.push(s);
    if(t.size()>5) t.pop();
}

set<set<int>> num;
set<int> change;

void dfs(int x){
    if(x == n){
        num.insert(change);
        IN();
        return;
    }

    if(s[x]=='a'){
        if(ct['b']==0){
            s[x] = 'b';
            ++ct[s[x]];
            change.insert(x);
            dfs(x+1);
            change.erase(x);
            --ct[s[x]];
            s[x] = 'a';
        }

        ++ct[s[x]];
        dfs(x+1);
        --ct[s[x]];
    }
    else{
        if(ct[s[x]]>0){
            ++ct[s[x]];
            dfs(x+1);
            --ct[s[x]];
        }

        if(s[x]!='z'){
            char c = s[x]+1;
            if(ct[c]==0){
                ++s[x];
                ++ct[s[x]];
                change.insert(x);
                dfs(x+1);
                change.erase(x);
                --ct[s[x]];
                --s[x];
            }
        }
    }
}

void solve(){
    num.clear();
    change.clear();
    n = s.size();
    change.insert(-1);
    dfs(0);

    cout << num.size() << endl;
    ANS();
}

int main(){
    while(cin >>s,s!="#") solve();
    return 0;
}



Measured memory_bytes: 17588
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,count=0,ans=0;
  cin>>n;
  vector<int> a(n),b(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  count+=a[0]+vec_sum(b);
  ans=count;
  rep(i,n-1){
    ans=max(ans,count+a[i+1]-b[i]);
    count+=a[i+1]-b[i];
  }
  cout<<ans<<endl;
}


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

class Team {
	int n,score;

	Team(int n) {
		this.n = n;
	}

	void AddScore(int s) {
		this.score = s;
	}

	int match(int m[]) {
		for (int i=0;i<100;i++)
			if (this.score==m[i]) return i+1;
		return -1;
	}
}

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			Team team[] = new Team[101];
			int m[] = new int[101];
			int tp = 0;
			int mp = 0;
			for (int i=0;i<=100;i++) m[i] = 0;
			while ((buf = br.readLine()).equals("0,0")==false) {
				StringTokenizer st = new StringTokenizer(buf,",");

				team[tp] = new Team(Integer.parseInt(st.nextToken()));
				int d = Integer.parseInt(st.nextToken());
				team[tp++].AddScore(d);
				if (mp==0) {
					m[0] = d;
					mp++;
				}
				for (int i=0;i<=mp;i++) {
					if (d>m[i]) {
						for (int j=mp;j>i;j--) {
							int t = m[j-1];
							m[j-1] = m[j];
							m[j] = t;
						}
						m[i] = d;
						mp++;
						break;
					} else if (d==m[i]) break;
				}
			}
			while ((buf = br.readLine())!=null) {
				for (int i=0;i<=100;i++) {
					if (team[i].n==Integer.parseInt(buf)) {
						System.out.println(team[i].match(m));
						break;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16876
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,m;
vector<int>g[1005],g2[1005];
vector<int>ans(1005,0);
int dist[1005],dist2[1005],pre[1005],pre2[1005];
queue<int>q;
vector<pair<int,int> >Gen_G;
void bfs(int st){
	memset(dist,inf,sizeof dist);
	memset(pre,-1,sizeof pre);
	dist[st]=0;q.push(st);
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=0;i<g[x].size();i++){
			if(dist[g[x][i]]>dist[x]+1){
				dist[g[x][i]]=dist[x]+1;
				pre[g[x][i]]=x;
				q.push(g[x][i]);
			}
		}
	}
	memset(dist2,inf,sizeof dist2);
	memset(pre2,-1,sizeof pre2);
	dist2[st]=0;q.push(st);
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=0;i<g2[x].size();i++){
			if(dist2[g2[x][i]]>dist2[x]+1){
				dist2[g2[x][i]]=dist2[x]+1;
				pre2[g2[x][i]]=x;
				q.push(g2[x][i]);
			}
		}
	}
}
vector<int>calc(int from,int to){
	set<int>ret;
	while(~from){
		ret.insert(from);
		from=pre[from];
	}
	while(~to){
		ret.insert(to);
		to=pre2[to];
	}
	return vector<int>(ret.begin(),ret.end());
}
void solve(int st){
	for(int i=0;i<Gen_G.size();i++){
		int from=Gen_G[i].first,to=Gen_G[i].second;
		if(dist[from]+dist2[to]+1<ans.size()){
			ans=calc(from,to);
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int a,b;cin>>a>>b;
		g[a].push_back(b);
		g2[b].push_back(a);
		Gen_G.push_back(make_pair(a,b));
	}
	for(int st=1;st<=n;st++){
		bfs(st);
		solve(st);
	}
	if(ans.size()>1000){
		cout<<-1<<endl;
	}else{
		cout<<ans.size()<<endl;
		for(int i=0;i<ans.size();i++){
			cout<<ans[i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
long p[111111],a[111111],b[111111];
int compare(const void *c, const void *d) {
    return a[*(long*)c] - a[*(long*)d];
}
int main() {
    long n, m, i,ans=0;
    scanf("%ld%ld", &n, &m);
    for (i = 0; i < n; i++) {
        scanf("%ld%ld", &a[i], &b[i]);
        p[i] = i;
    }
    qsort(p, n, sizeof(long), compare);
    i=0;
    while (1) {
        if (b[p[i]] < m) {
            ans += a[p[i]] * b[p[i]];
            m -= b[p[i]];
        }
        else {
            ans += a[p[i]] * m;
            printf("%ld\n", ans);
            return 0;
        }
      i++;
    }
    return 0;
}

Measured memory_bytes: 3324
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC162D
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            long[] dR = new long[N];
            long[] dG = new long[N];
            long[] dB = new long[N];
            for (int i = s.Length - 2; i >= 0; i--)
            {
                dR[i] = dR[i + 1];
                dG[i] = dG[i + 1];
                dB[i] = dB[i + 1];
                if (s[i + 1] == 'R') dR[i]++;
                if (s[i + 1] == 'G') dG[i]++;
                if (s[i + 1] == 'B') dB[i]++;
            }

            long ans = 0;
            for (int i = 0; i < N - 2; i++)
            {
                if (s[i] == 'R') ans += dG[i] * dB[i];
                else if (s[i] == 'G') ans += dB[i] * dR[i];
                else if (s[i] == 'B') ans += dR[i] * dG[i];
            }

            for (int i = 0; i < N - 2; i++)
            {
                for (int j = i + 1;  j < N - 1; j++)
                {
                    int final = 2 * j - i;
                    if (final >= N) break;

                    if (s[i] == 'R' && s[j] == 'G' && s[final] == 'B') ans--;
                    if (s[i] == 'R' && s[j] == 'B' && s[final] == 'G') ans--;
                    if (s[i] == 'G' && s[j] == 'B' && s[final] == 'R') ans--;
                    if (s[i] == 'G' && s[j] == 'R' && s[final] == 'B') ans--;
                    if (s[i] == 'B' && s[j] == 'G' && s[final] == 'R') ans--;
                    if (s[i] == 'B' && s[j] == 'R' && s[final] == 'G') ans--;
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 17540
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def bit_indexes(x):
    i = 0
    while x != 0:
        if x%2 != 0:
            yield i
        x //= 2
        i += 1
    

def solve():
    H, W, K = read_ints()
    C = []
    black_count = 0
    for i in range(H):
        C.append(input().strip())
        black_count += C[-1].count('#')
    ans = 0
    for i in range(2**H):
        for j in range(2**W):
            count = black_count
            for i0 in bit_indexes(i):
                for j0 in range(W):
                    if C[i0][j0] == '#':
                        count -= 1
            for j0 in bit_indexes(j):
                for i0 in range(H):
                    if C[i0][j0] == '#':
                        count -= 1
            for i0 in bit_indexes(i):
                for j0 in bit_indexes(j):
                    if C[i0][j0] == '#':
                        count += 1
            if count == K:
                ans += 1
    return ans


if __name__ == '__main__':
    print(solve())


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

int main() {
 int a,b,c,d;
  cin >>a;
  b=a/100;
  c=(a-b*100)/10;
  d=a-b*100-c*10;
  cout <<b+c+d<<endl;// ここにプログラムを追記
}

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

typedef long long ll;

set<pair<int, string>> s;

vector<pair<ll, ll>> p[1111000], w[1111000];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //Älä käytä, jos tehtävä on interaktiivinen!
    int n;
    cin >> n;
    for (int i=1; i<=n; ++i){
        string s1;
        cin >> s1;
        s.insert({s1.size(), s1});
    }
    ll ans=0;
    ll z=2;
    for (auto u:s){
        string a=u.second;
        ll k=1;
        int t[29]={};
        for (int i=0; i<a.size(); ++i){
            t[a[i]-'a']++;
        }
        bool b=1;
        ll i1;
        for (int i=a.size(); b; --i){
            for (auto v:p[k]){
                if (t[v.first]) ans++;
            }
            t[a[i-1]-'a']--;
            ll l=0;
            for (auto v:w[k]){
                if (v.first==(a[i-1]-'a')) l=v.second;
            }
            if (l) k=l;
            else {
                b=0;
                i1=i;
            }
        }
        i1--;
        while (i1!=0){
            w[k].push_back({a[i1]-'a', z});
            k=z;
            z++;
            i1--;
        }
        p[k].push_back({a[0]-'a', z++});
    }
    cout << ans << "\n";
}






Measured memory_bytes: 89288
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int mod=1000000007;
    int n,m;
    char s[210];
    fgets(s,210,stdin);
    int len=strlen(s);
    for (int i=0;i<len;i++) {
        if (islower(s[i])) {
            s[i]=toupper(s[i]);
        }
    }
    printf("%s",s);
    return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X[i];

  vector<int> X_cp = X;

  sort(all(X_cp));
  int l = X_cp[N / 2 - 1];
  int r = X_cp[N / 2];

  rep(i, N) {
    if (X[i] <= l) {
      cout << r << endl;
    } else {
      cout << l << endl;
    }
  }
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(void){
    long long N,M;
    cin>>N>>M;
    vector<pair<int,int>> store(N);
    for(int i=0;i<N;i++){
        long long A,B;
        cin>>A>>B;
        store[i] = make_pair(A,B);
    }
    sort(store.begin(),store.end());
    long long ans = 0;
    long long count = 0;
    for(int i=0;count < M;i++){
        if(store[i].second > M - count){
            ans += store[i].first * (M - count);
            count = M;
        }
        else{
            count += store[i].second;
            ans += store[i].first * store[i].second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3676
from itertools import product
import bisect

N = int(input())
L = []

for i in range(3, 10):
  for A in product(["3", "5", "7"], repeat = i):
    if len(set(A)) == 3:
      x = int("".join(A))
      L.append(x)

ans = bisect.bisect(L, N)

print(ans)

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<int> v(n);
		for(int i = 0; i < n; i++) cin >> v[i];
		int ans = -100000;		
		for(int i = 0; i < n; i++) {
			int sum = 0;
			for(int j = i; j < n; j++) {
				sum += v[j];
				if(ans < sum) ans = sum;			
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

int Partition(int A[] ,int ,int );
int A[MAX];

int main(){

  int n,x,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);

  x = Partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    if(i==x) printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
 
  printf("\n");

  return 0;
}
int Partition(int A[] ,int p,int r){

  int x,tmp,i,j;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp; 
    }
  }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;

    return i+1;
}

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

int main(){
	string w , t;
	int count=0;
	cin>>w;
	transform(w.begin() , w.end() , w.begin() , ::toupper);
	while(1){	
		cin>>t;
		if (t.find("END_OF_TEXT")!=string::npos) break;
		transform(t.begin() , t.end() , t.begin() , ::toupper);
		if (t==w) count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <cstdint>
#include <cctype>
#include <string>
#include <array>
#include <algorithm>
#include <iterator>

int main() {
  std::array<std::string, 3> s;
  std::copy_n(std::istream_iterator<std::string>(std::cin), 3, s.begin());
  std::array<char, 3> acronym;
  std::transform(s.begin(), s.end(), acronym.begin(), [](const std::string& s_i) {
    return std::toupper(s_i[0]);
  });
  std::cout << std::string(acronym.begin(), acronym.end()) << std::endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
l=len(s)
mod = 10**9+7
dp=[[0]*13 for _ in range(l+1)]

dp[0][0]=1 #初期値設定
for i in range(l):
  if s[i]!="?":
    for k in range(13):
      dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod
  else:
    for j in range(10):
      for k in range(13):
        dp[i+1][(k*10+j)%13]+=dp[i][k]%mod
        
print(dp[-1][5]%mod)


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b; cin>>a>>b;
  (2*b>a)?cout<<0<<endl:cout<<a-2*b<<endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
X = list(map(int,input().split()))

if M == 1 and N > 0:
    print(0)
    exit()
if M <= N:
    print(0)
    exit()


X = sorted(X)
s = []
for i in range(len(X) - 1):
    s.append(abs(X[i+1]- X[i]))
ans = sum(s)
s = sorted(s)
for i in range(1,N):
    ans -= s[-i]
print(ans)


Measured memory_bytes: 13960
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> count(1000000);
  set<int> s;
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    count.at(a.at(i)-1)++;
    s.insert(a.at(i));
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (count.at(a.at(i)-1) > 1) continue;
    bool f = true;
    s.erase(a.at(i));
    for (int j = 1; j * j <= a.at(i); ++j) {
      if (a.at(i) % j == 0 && (s.find(j) != s.end() || s.find(a.at(i) / j) != s.end())) {
        f = false;
        break;
      }
    }
    s.insert(a.at(i));
    if (f) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;cin>>N;
    long double x[N];
    string u[N];
    long double ans=0;
    for(int i=0;i<N;i++){
        cin>>x[i];
        cin>>u[i];
        if(u[i]=="JPY"){
            ans=ans+x[i];
        }
        else{
            ans=ans+x[i]*380000.0;
        }
    }
    cout<<ans;
    return 0;
}

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

string shuffle(string cards, int h) {
    string head = cards.substr(0, h);
    string tail = cards.substr(h, cards.size() - h);
    return tail + head;
}

int main() {
    string cards;
    int m, h;
    
    
    while (true) {
        cin >> cards;
        
        if (cards == "-") break;
        
        cin >> m;
    
        for (int i = 0; i < m; i++) {
            cin >> h;
            cards = shuffle(cards, h);
        }
    
        cout << cards << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 3200
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    x = list(map(int,ipt().split()))
    print(x.index(0)+1)


    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9580
inputs = gets.split
a = inputs[0].to_i
b = inputs[1].to_i
x = inputs[2].to_i

def trapezoid?(x, a, b)
  if x > (a * a * b) / 2
    true
  else
    false
  end
end

def result_of_triangle(x, a, b)
  a_dash = x.to_f * 2 / (b * a)
  c = Math.sqrt((a_dash ** 2) + (b ** 2))
  Math.acos(a_dash/c) / Math::PI * 180
end

def result_of_trapezoid(x, a, b)
  d = ((x.to_f * 2) / (a ** 2)) - b
  c = Math.sqrt ((b - d) ** 2) + (a ** 2)
  Math.acos(a/c) / Math::PI * 180
end

def angle(x, a, b)
  if trapezoid?(x, a, b)
    result_of_trapezoid(x, a, b)
  else
    result_of_triangle(x, a, b)
  end
end

puts angle(x, a, b)

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

int n,m;
vector<int> adj[100001];
vector<int> pathlen(100001);
bool visited[100001];

void dfs(int vertex)
{
    visited[vertex] = 1;
    pathlen[vertex] = 0;
    for(int child : adj[vertex])
    {
        if(!visited[child])
            dfs(child);
        pathlen[vertex] = max(pathlen[vertex] , 1+pathlen[child]);
    }
}

int main()
{   
    cin>>n>>m;
    while(m--)
    {
        int x,y;    
        cin>>x>>y;
        adj[x].push_back(y);
    }

    for(int i=1 ; i<=n ; i++)
    {
        dfs(i);
    }
    int ans = 0;
    for(int i=1 ; i<=n ; i++)
        ans = max(ans , pathlen[i]) ;


    cout<<ans;

}

Measured memory_bytes: 11732
#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 endl "\n"

using ll = long long;
using P = pair<int,int>;

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

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

    cout << n * (n + 1) / 2 << endl;


    return 0;
}

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

int main() {
	char num[1002], c[2] = {'\0'};
	int l, i, sum;
	while(1) {
		sum = 0;
		fgets(num, 1002, stdin);
		if (num[0] == '0') break;
		l = strlen(num) - 1;
		for (i = 0; i < l; ++i) {
			c[0] = num[i];
			sum += atoi(c);
		}
		printf("%d\n", sum);
	}
	return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int gcd(int a, int b){
  if(a % b == 0) return b;
  return gcd(b, a%b);
}

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = a[0];
  for(int i = 1; i < n; i++){
    ans = gcd(ans,a[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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 <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int H,W,M; cin >> H >> W >> M;
    VI h(M),w(M);
    map<int,LL> hc,wc;
    set<PII> se;
    LL hmax = -1, wmax = -1;
    REP(i,M) {
        cin >> h[i] >> w[i];
        se.insert(PII(h[i],w[i]));
        
        hc[h[i]]++;
        chmax(hmax, hc[h[i]]);
        wc[w[i]]++;
        chmax(wmax, wc[w[i]]);

    }
    VI h_cand, w_cand;
    for(auto p : hc){
        if(p.second == hmax) h_cand.eb(p.first);
    }

    for(auto p : wc){
        if(p.second == wmax) w_cand.eb(p.first);
    }

    for(int i : h_cand){
        for(int j : w_cand){
            if(se.find(PII(i,j)) == se.end()){
                cout << hmax + wmax << endl;
                return 0;
            }
        }
    }
    cout << hmax + wmax - 1 << endl;

}

Measured memory_bytes: 61248
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mem[10][10][2][2];
char str[10];
ll dp(int pos, int lst, bool s, bool f)
{
    if(pos==10)return 1ll;
    if(mem[pos][lst][s][f]!=-1)
    return mem[pos][lst][s][f];
    mem[pos][lst][s][f]= 0;
    if(!f)
    {
        mem[pos][lst][s][f]+= dp(pos+1, lst, s|(str[pos]-48>0), f);
        for(int i=1; i<10; i++)
        if(s || str[pos]-48>=i)mem[pos][lst][s][f]+= dp(pos+1, i, s|(str[pos]-48>i), 1);
    }
    else
    {
        if(lst!=0 && (s || str[pos]-48>=(lst-1)))mem[pos][lst][s][f]+= dp(pos+1, lst-1, s|(str[pos]-48>(lst-1)), f);
        if(lst!=9 && (s || str[pos]-48>=(lst+1)))mem[pos][lst][s][f]+= dp(pos+1, lst+1, s|(str[pos]-48>(lst+1)), f);
        if(s || str[pos]-48>=lst)mem[pos][lst][s][f]+= dp(pos+1, lst, s|(str[pos]-48>lst), f);
    }
    return mem[pos][lst][s][f];
}
void setstring(ll n)
{
    int sz= 0;
    while(n)
    {
        str[sz++]= (n%10ll)+'0';
        n/= 10ll;
    }
    for(int i=sz; i<10; i++)str[i]= '0';
    reverse(str, str+10);
    return;
}
int main()
{
    int k;
    scanf("%d", &k);
    k++;
    ll lo= 1, hi= 9999999999ll, res;
    while(lo<=hi)
    {
        ll mid= (lo+hi)>>1;
        memset(mem, -1, sizeof mem);
        setstring(mid);
        if(dp(0, 0, 0, 0)>=k)res= mid, hi= mid-1;
        else lo= mid+1;
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 3788
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll x[55],y[55];

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

  cin>>n;
  rep(i,n)cin>>x[i]>>y[i];

  if(n==1){
    cout<<1<<endl;
    return 0;
  }

  ll res=INF;
  rep(i,n)rep(j,n){
    if(i==j)continue;
    ll p=x[j]-x[i];
    ll q=y[j]-y[i];
    ll sum=n;
    rep(k,n)repl(l,k+1,n){
      if((x[k]-x[l]==p&&y[k]-y[l]==q)||(x[l]-x[k]==p&&y[l]-y[k]==q))sum--;
    }
    minch(res,sum);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
	int a;
	while (std::cin >> a,a){
		int change = 1000 - a;
		int coin[] = { 500, 100, 50, 10, 5, 1 };
		int ans = 0;
		for (int i = 0; i < 6; ++i){
			while (change >= coin[i]){
				ans++;
				change -= coin[i];
			}
		}
		std::cout << ans << std::endl;
	}
	
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;


int main(){

	long long int Z,left,right,m,z_3,limit,pow3_Table[1111],maximum,tmp_max,tmp;

	for(int i = 1; i <= 1110; i++){
		pow3_Table[i] = pow(i,3);
	}

	while(true){
		scanf("%lld",&Z);
		if(Z == 0)break;

		z_3 = pow(Z,3);


		maximum = -1;
		for(int i = 1; i <= Z-1; i++){
			limit = z_3 - pow(i,3);

			left = 1, right = Z-1;
			m = (left + right)/2;
			tmp_max = -1;

			while(left <= right){
				if(pow3_Table[m] <= limit){
					tmp_max = max(tmp_max,m);
					left = m+1;
				}else{
					right = m-1;
				}
				m = (left + right)/2;
			}

			tmp = pow(i,3)+pow3_Table[tmp_max];
			maximum = max(maximum,tmp);
		}

		printf("%lld\n",z_3-maximum);
	}


	return 0;
}

Measured memory_bytes: 2944
# [A, B] = list(map(int, input().split(' ')))
#
# answer = 0
# for n in range(A, B + 1):
#     answer = answer ^ n
#
# print(answer)


[A, B] = list(map(int, input().split(' ')))

answer = 0

A1_digit = len(bin(A - 1)) - 2
Abit_list = []
Amin_bit = 1 if 1 <= (A - 1) % 4 <= 2 else 0
Abit_list.append(Amin_bit)

for i in range(2, A1_digit + 1):
    rem = (A - 1) % 2 ** i
    A_bit = 0 if rem < 2 ** (i - 1) or (rem - 2 ** (i - 1)) % 2 == 1 else 1
    Abit_list.append(A_bit)

B_digit = len(bin(B)) - 2
Bbit_list = []
Bmin_bit = 1 if 1 <= B % 4 <= 2 else 0
Bbit_list.append(Bmin_bit)
for i in range(2, B_digit + 1):
    rem = B % 2 ** i
    B_bit = 0 if rem < 2 ** (i - 1) or (rem - 2 ** (i - 1)) % 2 == 1 else 1
    Bbit_list.append(B_bit)

Abit_list.reverse()
Bbit_list.reverse()
# print(Abit_list)
# print(Bbit_list)
Axor = 0
for v in Abit_list:
    Axor = Axor << 1
    if v == 1:
        Axor = Axor + 1

Bxor = 0
for v in Bbit_list:
    Bxor = Bxor << 1
    if v == 1:
        Bxor = Bxor + 1

# print(bin(Axor ^ Bxor))
# print(bin(435))
print(Axor ^ Bxor)


Measured memory_bytes: 3064