akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
struct edge{ll v,a,b;};

int main() {
    ll s,t;
    cin>>n>>m>>s>>t;
    vector<vector<edge>> e(n, vector<edge>());
    REP(i,m){
        ll u,v,a,b;
        cin>>u>>v>>a>>b;
        e[u-1].push_back(edge{v-1,a,b});
        e[v-1].push_back(edge{u-1,a,b});
    }
    vi dy(n, INF);
    vi ds(n, INF);
    priority_queue<P,vector<P>,greater<P>> que;
    dy[s-1]=0;
    que.push(P{0,s-1});
    while(!que.empty()){
        P p=que.top();que.pop();
        if(dy[p.second]<p.first)continue;
        REP(i,e[p.second].size()){
            ll x=e[p.second][i].v;
            ll a=p.first+e[p.second][i].a;
            if(dy[x]>a){
                dy[x]=a;
                que.push(P{a,x});
            }
        }
    }

    ds[t-1]=0;
    que.push(P{0,t-1});
    while(!que.empty()){
        P p=que.top();que.pop();
        if(ds[p.second]<p.first)continue;
        REP(i,e[p.second].size()){
            ll x=e[p.second][i].v;
            ll b=p.first+e[p.second][i].b;
            if(ds[x]>b){
                ds[x]=b;
                que.push(P{b,x});
            }
        }
    }

    vi anss(n);
    ll ans=INF;
    RREP(i,n){
        if(ans>dy[i]+ds[i]){
            ans=dy[i]+ds[i];            
        }
        anss[i]=ans;
    }
    REP(i,n){
        printf("%lld\n",(ll)10e14-anss[i]);
    }
    return 0;
}

Measured memory_bytes: 13560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> ans(n), cnt(n, 1);
	ans[0] = 1;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		if (ans[x] == 0) {
			cnt[x]--;
			cnt[y]++;
		} else {
			if (cnt[x] == 1) {
				ans[x] = 0;
				cnt[x] = 0;
				ans[y] = 1;
				cnt[y]++;
			} else {
				cnt[x]--;
				ans[y] = 1;
				cnt[y]++;
			}
		}
	}
	cout << accumulate(ans.begin(), ans.end(), 0) << endl;
	return 0;	
}

Measured memory_bytes: 1024
from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR, S):  # 幅優先探索  # キュー
    ans[S] = c.pop()
    que, frag = deque([S]), set([S])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            ans[i] = c.pop()
            que.append(i), frag.add(i)
    return ans


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
c = sorted(map(int, input().split()))

ans = [0] * n
near = nearlist(n, ab)
print(sum(c) - max(c))
print(*bfs(near, 0))


Measured memory_bytes: 80048
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main()
{
	int n, i;
	double a[1010],ans=0;
	scanf("%d", &n);
	for (i = 0;i < n;i++)
	{
		scanf("%lf", &a[i]);
		ans += (1 / a[i]);
	}
	printf("%lf\n", 1 / ans);
	return 0;
}

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

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e3+5 ;
int n ,m ,a ,b ,ch ,tar ;
long long mem[N][1<<12];
pair<int,int> msk[N] ;
long long solve(int i,int mask){
    if(i==m){
        if(mask!=tar) return 1e16 ;
        return 0 ;
    }
    long long&ret = mem[i][mask] ;
    if(~ret) return ret;
    return ret = min(solve(i+1,mask) ,solve(i+1,mask|msk[i].second) + msk[i].first);
}
int main(){
    scanf("%d%d",&n,&m);
    tar = (1<<n)-1 ;
    for(int i=0;i<m;++i){
        scanf("%d%d",&a,&b);
        int mask = 0 ;
        while(b--){
            scanf("%d",&ch);
            --ch ;
            mask |= 1<<ch ;
        }
        msk[i] = {a,mask};
    }
    memset(mem,-1,sizeof mem);
    if(solve(0,0) > 1e11) return cout << -1,0;
    cout << solve(0,0) ;
    return 0;
}


Measured memory_bytes: 32512
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

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

    string S;
    cin >> S;
    int N = S.size();
    long long total = 0;
    int A = 0;

    for (int i = 0; i < N; i++)
        if (S[i] == 'A') {
            A++;
        } else if (S[i] == 'B') {
            if (i == N - 1)
                break;

            if (S[i + 1] == 'C') {
                total += A;
                i++;
            } else {
                A = 0;
            }
        } else if (S[i] == 'C') {
            A = 0;
        }

    cout << total << '\n';
}


Measured memory_bytes: 720
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(void) {
	long int n,k,max=0,temp=0;
	long int a[200010];

	scanf("%ld %ld", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%ld", &a[i]);
		temp += a[i];
		if (i - k > 0) {
			temp -= a[i-k];
		}
		if (max <= temp) max = temp;
	}
	printf("%.10Lf", (long double)(max + k) / 2);
	return 0;
}


Measured memory_bytes: 1664
// Problem : E - Count Median
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define all(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    ll n;
    cin >> n;
    
    vector<pair<ll,ll>> a(n) , b(n);
    for(ll i = 0 ; i < n ; i++){
    	cin >> a[i].ff >> a[i].ss;
    	b[i] = a[i];
    }
    
    sort(all(a));
    sort(all(b) , [](pair<ll,ll> x , pair<ll,ll> y){
    	return x.ss < y.ss;
    });
    
    
    if(n % 2 == 1){
    	ll start = a[n/2].ff , end = b[n/2].ss;
    	// debug(start);
    	// debug(end);
    	cout << end - start + 1 << endl;
    }
    else{
    	ll start = a[n/2].ff + a[n/2 - 1].ff , end = b[n/2].ss + b[n/2-1].ss;
    	// debug(start);
    	// debug(end);
    	cout << end - start + 1 << endl;
    }
    return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n, k; cin >> n >> k;
    vector<int> h(n);
    REP(i, n) cin >> h[i];
    DESC(h);

    ll ans = 0;
    FOR(i, k, n) ans += h[i];

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N = 3030;
#define ll long long
const int mod = 1e9+7;
//O(n*k^2) algo 
const int K = 1e5+10;
ll pf[K];
void add_self(int &a,int b){
    a += b;
    if(a>=mod)a -= mod;
}
void sub_self(int &a,int b){
    a -= b;
    if(a<0)a += mod;
}
int n,k;
int main(){
  scanf("%d%d",&n,&k);
  vector<int> dp(k+1,0);
  dp[0] = 1;
  for(int c = 0;c<n;++c){
      int up;
      cin>>up;
      vector<int> pf(k+1);
      for(int used=k;used>=0;--used){
          int tmp = dp[used];
          int l = used+1;
          int r = used+min(up,k-used);
          if(l<=r){
              add_self(pf[l],tmp);
              if(r+1<=k)sub_self(pf[r+1],tmp);
          }
        //   for(int here = 1;here<=min(up,k-used);++here){
        //       add_self(dp[used+here],dp[used]);
        //   }
      }
      int pfs =0;
      for(int i=0;i<=k;++i){
         add_self(pfs,pf[i]);
         add_self(dp[i],pfs);
      }
  }
  cout<<(dp[k])<<endl;
  return 0;
}

Measured memory_bytes: 1024
using System;

class MinMax {  
  static void Main() {  
    
     string[] str = Console.ReadLine().Split();
     
     int N = int.Parse(str[0]);
     int R = int.Parse(str[1]);
     if(N < 10){
       Console.WriteLine(R + 100*(10-N));
     }else{
       Console.WriteLine(R);
     }
  }
}

Measured memory_bytes: 11092
N, M = map(int, input().split())
A = []
for _ in range(0,M):
    A.append(int(input()))
S = set(A)

dp = [0] * (N+1)
dp[0] = 1

DIVISOR = 1000000007

for i in range(1,N+1):
    # print(i)
    back1 = i-1
    back2 = i-2
    sum = 0
    # the step exists and is not broken
    if back2 >= 0 and back2 not in S:
        sum += dp[back2]
        sum %= DIVISOR
    if back1 >= 0 and back1 not in S:
        sum += dp[back1]
        sum %= DIVISOR
    # print(sum)
    sum %= DIVISOR
    dp[i] = sum

print(dp[N])

Measured memory_bytes: 13216
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b){
  if (b == 0){
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long lcm(long long a, long long b){
  return a / gcd(a, b) * b;
}
int main(){
  int N;
  cin >> N;
  long long ans = 1;
  for (int i = 0; i < N; i++){
    long long T;
    cin >> T;
    ans = lcm(ans, T);
  }
  cout << ans;
}

Measured memory_bytes: 256
from collections import Counter

N=int(input())
C=Counter(list(map(int,input().split())))

f=True
if N%2==0:
    for i in range(1,N+1,2):
        if C[i]!=2:
            f=False
            ans=0
            break
    if f:
        ans=(2**(N//2))%(10**9+7)
elif N%2==1:
    if C[0]!=1:
        f=False
        ans=0
    else:
        for i in range(2,N+1,2):
            if C[i]!=2:
                f=False
                ans=0
                break
    if f:
        ans=(2**((N-1)//2))%(10**9+7)

print(ans)

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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

int n, m;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;
#endif
  cin >> n >> m;
  if (n % m == 0) cout << 0 << endl;
  else cout << 1 << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}


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

using namespace std;

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

    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    sort(b.begin(), b.end(), greater<>());
    int aMax = *max_element(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (HP <= 0 || b[i] < aMax) break;
        HP -= b[i];
        ans++;
    }

    if (HP > 0) ans += (HP + aMax - 1) / aMax;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
//#define int long long
#define fi first
#define se second
using namespace std;

int sum[3][1100][1100];

signed main(){
    int h, w, q;
    cin >> h >> w >> q;
    vector<string> s;
    string t;
    rep(i, 0, h){
        cin >> t;
        s. push_back(t);
    }
    rep(i, 0, h){
        rep(j, 0, w){
            if(s[i][j] == 'J'){
                sum[0][i + 1][j + 1] = 1;
            }else if(s[i][j] == 'O'){
                sum[1][i + 1][j + 1] = 1;
            }else if(s[i][j] == 'I'){
                sum[2][i + 1][j + 1] = 1;
            }
        }
    }
    rep(i, 0, h + 1){
        rep(j, 1, w + 1){
            rep(k, 0, 3){
                sum[k][i][j] += sum[k][i][j - 1];
            }
        }
    }
    rep(i, 0, w + 1){
        rep(j, 1, h + 1){
            rep(k, 0, 3){
                sum[k][j][i] += sum[k][j - 1][i];
            }
        }
    }
    rep(i, 0, q){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int ans[3];
        rep(j, 0, 3){
            ans[j] = sum[j][c][d] - sum[j][c][b - 1] - sum[j][a - 1][d] + sum[j][a - 1][b - 1];
            cout << ans[j];
            if(j != 2) cout << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 15712
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  string s;
  cin >> s;
  (s[2]==s[3] and s[4]==s[5]) ? cout << "Yes": cout << "No";
  return 0;
} //good night.

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;

int n;
string s[1024];

int rec(int a,int b,int c){
	int res=0;
	if(c)res=1;
	for(int i=a;i<n&&b<s[i].size();i++){
		if(s[i][b]=='.')continue;
		int x=s[i][b]-'0';
		if(s[i][b]=='*')x=rec(i+1,b+1,1);
		if(s[i][b]=='+')x=rec(i+1,b+1,0);
		if(c)res*=x;
		else res+=x;
	}
	return res;
}

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		REP(i,n)cin>>s[i];
		cout<<rec(0,0,0)<<endl;
	}
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


inline void solve(){


    string s;
    cin >> s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])
        cout << "Bad\n";
    else
        cout <<"Good\n";
  
        

    

}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ((int)(x).size())

using namespace std;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef long long ll;

int main() {
  int X;
  cin >> X;
  cout << 10 - X / 200 << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a,b;
	cin >> a >> b;
	cout << (b - a) * (b - a + 1) / 2 - b << endl; 
	return 0;
}

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

int main() {
    int c[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> c[i][j];
        }
    }
    bool ok = true;
    int b0 = c[0][0]*2 - c[0][1] - c[0][2];
    int b1 = c[1][0]*2 - c[1][1] - c[1][2];
    int b2 = c[2][0]*2 - c[2][1] - c[2][2];

    int a0 = c[0][0]*2 - c[1][0] - c[2][0];
    int a1 = c[0][1]*2 - c[1][1] - c[2][1];
    int a2 = c[0][2]*2 - c[1][2] - c[2][2];

    if(b0 != b1 || b1 != b2 || b2 != b0 || a0 != a1 || a1 != a2 || a2 != a0){
        ok = false;
    }

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

    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

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


			int n = sc.nextInt();
			int k = sc.nextInt();

			int[] pArray = new int[n];
			long[] cArray = new long[n];

			for(int i = 0 ; i < n ; i++ ) {
				pArray[i] = sc.nextInt();
			}

			for(int i = 0 ; i < n ; i++ ) {
				cArray[i] = sc.nextLong();
			}

			long max = Long.MIN_VALUE;
			//calc by start point
			for(int i = 0 ; i < n ; i++ ) {

				int cnt = 0;
				int po = i;
				long score = 0;
				long iMax = Long.MIN_VALUE;
				
				while(cnt < k) {
					//next position
					po = pArray[po] - 1;
					cnt++;
					score += cArray[po];
					if ( score > max ) {
						max = score;
					}
					if ( score > iMax) {
						iMax = score;
					}
					if ( po == i ) {
						//found loop
						if ( score >= 0 ) {							
							int loopCnt = k / cnt;
							long addedScore = score * (loopCnt-1);
							score += addedScore;
							cnt += (loopCnt-1) * cnt;
							if ( iMax + addedScore > max ) {
								max = iMax + addedScore;
							}
							if ( score > max ) {
								max = score;
							}
							
						}
						else {
							//loop total is negative, repetition is waste
							break;
						}
					}
				}
			}
			
			System.out.println(max);

		}
	}

}

Measured memory_bytes: 48484
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String n = sc.next();
		String nArr[] = n.split("",0);
		
		for (int i = 0; i < 3; i++) {
			if (nArr[i].equals("1")) {
				nArr[i] = "9";
			} else {
				nArr[i] = "1";
			}
		}
		
		System.out.println(nArr[0] + nArr[1] + nArr[2]);
	}
}

Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main() {
    int n,k,x,y,a,b,c,d,e,f,g,h;
    a=0;
    b=0;
    c=0;
    cin >>n>>k>>x>>y;
    if(n<=k){
        a=n*x;
    }
    else{
        b=k*x;
        c=(n-k)*y;
        a=b+c;
    }
    cout<<a;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int x, y;
  int z = 0;
  int w = 0;
  scanf("%d %d", &x, &y);
  int a[7] = { 1, 3, 5, 7, 8, 10, 12};
  int b[4] = { 4, 6, 9, 11};
  for(int i = 0; i < 7; i++){
    if(a[i] == x) z = 1;
    if(a[i] == y) w = 1;
  }
  for(int i = 0; i < 4; i++){
    if(b[i] == x) z = 2;
    if(b[i] == y) w = 2;
  }

  if(z == w) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#define long long long
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;


signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  set<int> U;
  int Q;

  cin >> Q;
  while(Q--) {
    int com, x, y;
    cin >> com;

    switch(com) {
    case 0:
      cin >> x;
      U.insert(x);
      cout << U.size() << LF;
      break;

    case 1:
      cin >> x;
      cout << U.count(x) << endl;
      break;

    case 2:
      cin >> x;
      U.erase(x);
      break;

    default:
      cin >> x >> y;
      for (auto it = U.lower_bound(x), end=U.upper_bound(y); it != end; ++it) {
        cout << *it << LF;
      }
    }
  }

  return 0;
}




Measured memory_bytes: 12500
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

l,r,d = readInts()

print(r//d-(l-1)//d)

Measured memory_bytes: 9448
s = list(input())
s.reverse()
s.append('0')

dp = [[1000000000] * 2 for _ in range(1000005)]
dp[0][0] = 0
n = len(s)
for i in range(n):
    for j in range(2):
        x = int(s[i])
        x += j
        if x < 10:
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)
        if x > 0:
            dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))

ans = dp[n][0]
print(ans)

Measured memory_bytes: 179808
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

def dist(start,goal):
    return abs(start[0]-goal[0])+abs(start[1]-goal[1])

n=int(input())
T=[0]
XY=[[0,0]]
for _ in range(n):
    t,x,y=map(int,input().split())
    T.append(t)
    XY.append([x,y])
for i in range(n):
    dxy=dist(XY[i],XY[i+1])
    dt=T[i+1]-T[i]
    if dxy>dt or dxy%2!=dt%2:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 20324
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,a;
  vector<int> v;
  map<int,int> d;
  int q,b,c,sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    sum+=a;
    d[a]++;
    if(d[a]==1) v.push_back(a);
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>b>>c;
    sum+=((c-b)*d[b]);
    d[c]+=d[b];
    d[b]=0;
    cout<<sum<<"\n";
  }
}

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

int main() {
  int A, B, C, D;
  string s;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    s = "Left";
  }
  else if (A + B == C + D) {
    s = "Balanced";
  }
  else {
    s = "Right";
  }
  cout << s << endl;
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    int target = 1;
    int count = 0;
    REP(i, N) {
        if (target == a[i]) {
            target++;
            count++;
        }
    }
    if (count == 0) {
        print(-1);
    } else {
        print(N-count);
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 1024
n,a,b,c,d = map(int,input().split())
x = int((b-a+d*(n-1))/(c+d))
if x < 0 or x > n-1: s='NO'
else:
 z = c * x - d * (n-1-x)
 if z<=b-a<=z+(d-c)*(n-1):s='YES'
 else:s='NO'
print(s)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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; }

int main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  vi cnt(n);
  for(int i = n-1; 0 <= i; i--){
    int sum = 0;
    for(int j = i; j < n; j += i+1) sum ^= cnt[j];
    cnt[i] = sum^a[i];
  }
  vi ans;
  rep(i,n) if(cnt[i]) ans.push_back(i+1);
  cout << ans.size() << "\n";
  if(ans.size()) for(auto x : ans) cout << x << " ";
  cout << "\n";
  return 0;
}


Measured memory_bytes: 5412
n, w = list(map(int, input().split()))

a = []
for i in range(n):
    a.append(list(map(int, input().split())))

vMax = 0
wMax = 0
for i in range(n):
    vMax = max(vMax, a[i][0])
    wMax = max(wMax, a[i][1])

if n <= 30:
    val = []
    if a[0][1] <= w:
        val.append(a[0])

    for i in range(1, n):

        j = 0
        valTemp = val[:]
        while j < len(valTemp):
            k = 0
            if valTemp[j][1] + a[i][1] <= w:
                temp = [valTemp[j][0] + a[i][0], valTemp[j][1] + a[i][1]]
                while k < len(val):
                    if val[k][0] == temp[0]:
                        if temp[1] < val[k][1]:
                            val[k] = temp
                        break
                    elif val[k][0] > temp[0]:
                        if temp[1] < val[k][1]:
                            val.insert(k, temp)
                        break

                    k += 1
                else:
                    val.append(temp)
            j += 1

        if a[i][1] <= w:
            temp = a[i]
            j = 0
            while j < len(val):
                if val[j][0] == temp[0]:
                    if temp[1] < val[j][1]:
                        val[j] = temp
                    break
                elif val[j][0] > temp[0]:
                    if temp[1] < val[j][1]:
                        val.insert(j, temp)
                    break

                j += 1
            else:
                val.append(temp)
        
        j = len(val) - 2

        while j >= 0:
            if val[j][1] >= val[j + 1][1]:
                del val[j]
            j -= 1

    print(val[len(val) - 1][0])

elif wMax <= 1000:
    w = min(w, wMax * n)
    dp = [0 for _ in range(w + 1)]
    for i in range(n):
        for j in range(w, a[i - 1][1] - 1, -1):
            dp[j] = max(dp[j], dp[j - a[i - 1][1]] + a[i - 1][0])

    print(max(dp))
else:
    m = n + vMax
    dp = [0 for _ in range(m + 1)]
    for i in range(n):
        for j in range(m , a[i - 1][0] - 1, -1):
            dp[j] = min(dp[j], dp[j - a[i - 1][0]] + a[i - 1][1])

    ans = 0
    for i in range(n * vMax):
        if dp[n][i] != 0:
            ans = max(ans, i)
 
    print(ans)


Measured memory_bytes: 6020
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::string n;
  std::cin >> n;
  std::transform(n.begin(), n.end(), n.begin(), [](const char c) { return c == '1' ? '9' : '1'; });
  std::cout << n << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  string s;

  cin >> s;
  sort(s.begin(), s.end());

  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    int s = 0, m = 0;
    for(int i = 0; i < n; i++){
        p[i]++;
    }
    queue<int> A;
    for(int i = 0; i < n; i++){
        s += p[i];
        A.push(p[i]);
        if(A.size() > k){
            s -= A.front();
            A.pop();
        }
        if(A.size() == k){
            m = max(s, m);
        }
    }
    double a = m / 2.0;
    cout << fixed << setprecision(12) << a << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_map>
using namespace std;

vector<vector<long long> > comb(int n, int r) {
  std::vector<std::vector<long long> > v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k])%1000000007;
    }
  }
  return v;
}

const int MAX_N = 2000;
const int MAX_M = 2000;
long long  memo[MAX_N + 1][MAX_M + 1];

long long p(long long n, long long  m)
{
    long long  ret;

    if (memo[n][m] >= 0)
        return memo[n][m];

    if(n == 0 || m == 1)
        return 1;

    ret = p(n, m - 1);
    if(n >= m)
        ret += p(n - m, m);

    return memo[n][m] = ret;
}


int main(){
  int N,K;
  cin>>N>>K;
  vector<vector<long long> > vcomb;
  vcomb = comb(2001,2001);
  for(long long i=1; i<=K; i++){
    //cout<<N-K+1<<" "<<i<<" "<<K-1<<endl;
    cout<<((vcomb[N-K+1][i]%1000000007)*(vcomb[K-1][i-1]%1000000007))%1000000007<<endl;
  }
  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

using namespace std;

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7;
const double pi = acos(-1);


void solve() {
	//soln
	string s;
	string t;
	cin >> s >> t;
	t.pop_back();
	cout << (s == t ? "Yes" : "No") << endl;	
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}


Measured memory_bytes: 3628
# 2019-11-28 00:55:58(JST)
import sys
def main():
    s = sys.stdin.readline().rstrip()

    t = 'keyence'
    for i in range(8):
        if t[:i] == s[:i] and t[i:] == s[-(7-i):]:
            ans = 'YES'
            break
    else:
        ans = 'NO'

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import scala.collection.mutable.{HashMap => MMap}
object Main{
  def main(args:Array[String]):Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val m = sc.nextInt
    val map : MMap[Int,Int] = MMap.empty
    for(i <- 1 to n){
      val k = sc.nextInt
      for(j <- 1 to k){
        val like = sc.nextInt
        val count = map.getOrElse(like,0)
        map.put(like, count+1)
      }
    }

    println(map.values.count(_ == n))

  }
}

Measured memory_bytes: 27464
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    int h,w;
    cin>>h>>w;
    int k=__gcd(h,w);
    h/=k;w/=k;
    if(h==w){
      cout<<1<<" "<<0<<endl;
      continue;
    }
    if((h*w)%2){
      cout<<(h*w)/2+1<<" "<<(h*w)/2<<endl;
    }else{
      cout<<1<<" "<<1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef pair<int,int> P;

int main(){
    int N,M;
    vector<int> A(3);
    cin >> N >> M;
    for(int i=0;i<3;i++) cin >> A[i];
    vector<vector<int>> g(N);
    vector<vector<P>> g2(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }
    
    auto bfs = [&](int s){
        vector<vector<int>> vis(N,vector<int>(101,0));
        queue<P> Q;
        Q.push(P(s,0));
        vis[s][0] = 1;
        while(!Q.empty()){
            P now = Q.front(); Q.pop();
            for(auto& e:g[now.first]){
                if(!vis[e][now.second+1]){
                    vis[e][now.second+1] = 1;
                    if(now.second+1<100) Q.push({e,now.second+1});
                }
            }
        }
        for(int i=0;i<N;i++) for(int j=0;j<3;j++) if(vis[i][A[j]]){
            g2[s].push_back(P(i,j));
        }
    };

    for(int i=0;i<N;i++) bfs(i);
    int inf = 1e9;
    vector<int> dp(N,inf);
    dp[N-1] = 0;
    while(true){
        bool update = false;
        for(int i=0;i<N;i++){
            vector<int> mi(3,inf);
            for(auto& e:g2[i]){
                mi[e.second] = min(mi[e.second],dp[e.first]);
            }
            int res = 0;
            for(int j=0;j<3;j++) res = max(res,mi[j]+1);
            if(dp[i]>res){
                update = true;
                dp[i] = res;
            }
        }
        if(!update) break;
    }
    if(dp[0]==inf) cout << "IMPOSSIBLE" << endl;
    else cout << dp[0] << endl;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rt register int
#define all(it) it.begin(), it.end()
#define rep(it, f, e) for (rt it = f; it <= e; ++it)
#define per(it, f, e) for (rt it = f; it >= e; --it)
const int MAXN = 2e5 + 10;
ll dp[MAXN];
int h[MAXN];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n;
	cin >> n;
	rep (i, 1, n) {
		cin >> h[i];
	}
	dp[2] = abs(h[2] - h[1]);
	rep (i, 3, n) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n] << endl; 
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void){
    int cnt_same;
    int cnt_str;
    char S[26];
    scanf("%s", S);

    cnt_same = 0;
    cnt_str = 0;
    for(int i=0; S[i]; i++){
        for(int j=0; S[j]; j++){
            if(S[i] == S[j])
                cnt_same++;
        }
        cnt_str++;
    }
    if(cnt_str == cnt_same)
        printf("yes\n");
    else
        printf("no\n");
    return 0;
}

Measured memory_bytes: 2064
N = int(input())
A, A_sorted = [], []
for i in range(N):
    x = int(input())
    A.append(x)
    A_sorted.append(x)
A_sorted.sort()
vmax, vmax2 = A_sorted[-1], A_sorted[-2]

for i in range(N):
    x = A[i]
    if vmax == x:
        print(vmax2)
    else:
        print(vmax)


Measured memory_bytes: 14120
#include <stdio.h>

int pn[1000000];

int main(void)
{
	int n;
	int i, j;
	int total;
	
	for (i = 2; i < 1000000; i++){
		//printf("%d\n", i);
		if (pn[i] == 0){
			for (j = i + i; j < 1000000; j += i){
				//if (j % i == 0){
					pn[j] = 1;
				//}
			}
		}
	}
	while (scanf("%d", &n) != EOF){
		total = 0;
		for (i = 2; i <= n; i++){
			if(pn[i] == 0){
				total++;
			}
		}
		printf("%d\n", total);
	}
	
	return (0);
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int N;
   long double D;
   cin>>N>>D;
  long long int ct=0;
   while(N--)
   {  
      
      long long int x,y;
      cin>>x>>y;
      long double R;
      R=(x*x+y*y);
      if(R<=D*D)
        ct++;
   }
  cout<<ct<<endl;
}

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


#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 n;
li a[100100];

int main() {
    cin >> n;
    rin{cin >> a[i];}
    li res = a[0];
    repp(i, 1, n) {
        res = __gcd(res, a[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
s = gets.chomp
K = gets.to_i

list = [""]

(s.length-1).downto(0) do |i|
  i.upto([s.length-1, i+K-1].min) do |j|
    tmp = s.slice(i..j)
    break if list[K] != nil && tmp > list[K]

    1.upto(K) do |k|
      if list[k] == nil || tmp < list[k]
        list.insert(k,tmp)
        break
      elsif tmp == list[k]
        break
      end
    end
  end
end

puts list[K]


Measured memory_bytes: 1788
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++)
    cin >> L[i];
  sort(L.begin(), L.end());
  if(accumulate(L.begin(), L.end(), 0) > 2 * L[N-1])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

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

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

int nanko(string s,Int n,Int i){
    Int length = min(n - i - 1,i);
    Int ans = 0;
    for (int k = i-length;k < i;k++){
        if (s.at(k) == 'R' && s.at(i +  (i - k) == 'B')) ans++;
    }
    return ans;
}

struct datas{
    Int x;

};


int main() {
    Int n , k;
    cin >> n >> k;
    vector<Int> a(n);
    REP(k,i){
        Int d;
        cin >> d;
        REP(d,k){
            Int x;
            cin >> x;
            x--;
            a.at(x)++;
        }
    }
    Int ans = 0;
    REP(n,i){
        if (a.at(i) == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;

ll divceil(ll x, ll y) {
    assert(y);
    return (x+y-1)/y;
}

void print(vector<ll> a) {
    for (ll x: a) cout<<x<<" ";
    cout<<endl;
}

ll n;
vector<ll> a;

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

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

    // Operations are order invariant, so if an element is > n-1, we know it'll eventually
    // be the largest in the set, and be hit with -n.

    

    ll iter = 0;
    while (*max_element(a.begin(),a.end()) > n-1) {
	//watch(*max_element(a.begin(),a.end()));
	for (int i=0; i<n; i++) {
	    if (a[i] >= n) {
		ll go = a[i]/n;
		a[i] %= n;
		iter += go;
		for (int j=0; j<n; j++) {
		    if (i==j) continue;
		    a[j] += go;
		}
	    }
	}
    }
    
    cout<<iter<<endl;    
    return 0;
}


Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	mod int = 1e9 + 7
)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := getInt()
	fmt.Println(n * n * n)
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
import java.util.Scanner;

/**
 * String Palindrome
 * 
 * https://atcoder.jp/contests/abc159/tasks/abc159_b
 */
public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) throws Exception {
        String S = sc.next();
        int N = S.length();

        for (int i = 1; i <= (N - 1) / 2; i++) {
            if (S.charAt(i - 1) != S.charAt(N - i)) {
                System.out.println("No");
                return;
            }

            if (S.charAt(i - 1) != S.charAt((N - 1) / 2 - i)) {
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }

}


Measured memory_bytes: 35792
#include <bits/stdc++.h>
using namespace std;
 int main(){
    string S;
    cin>>S;
    int count=0;
    for(int i=0;i<3;i++){
        for(int j=1;j<4;j++){
            if(S.at(i)==S.at(j) && i<j){
                count++;
            }
        }
        }
    if(count==2){
        cout<<"Yes"<<endl;
    }
    else{cout<<"No"<<endl;
    }
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll a,b,t;cin>>a>>b>>t;
    cout<<t/a*b<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include"iostream"
using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int a[510][510];
	int check[250250][4];
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w-1; j++)
		{
			if (a[i][j] % 2 == 1)
			{
				check[ans][0] = i;
				check[ans][1] = j;
				check[ans][2] = i;
				check[ans][3] = j + 1;
				ans++;
				a[i][j + 1] ++;
			}
		}
	}

	for (int i = 0; i < h-1; i++)
	{
		if (a[i][w - 1] % 2 == 1)
		{
			check[ans][0] = i;
			check[ans][1] = w - 1;
			check[ans][2] = i + 1;
			check[ans][3] = w - 1;
			ans++;
			a[i + 1][w - 1]++;
		}
	}
	cout << ans << endl;
	for (int i = 0; i < ans; i++)
	{
		cout << check[i][0] + 1 << " " << check[i][1] + 1 << " " << check[i][2] + 1 << " " << check[i][3] + 1 << endl;
	}
}

Measured memory_bytes: 6912