akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<P> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//Warshall-floyd
ll dp[310][310];//dpテーブルには辺がないところにはINF、i==jには０を入れておく
void warshallfloyd(ll n){
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
}

//入力
ll n,m,r;
vector<ll>machi;



int main(){
    cin >> n >> m >> r;
    machi.resize(r);
    rep(i,r){
        cin>>machi[i];
        machi[i]--;
    }
    rep(i,n)rep(j,n)dp[i][j]=INF;
    rep(i,n)dp[i][i]=0;
    rep(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        dp[a][b]=c;
        dp[b][a]=c;
    }
    warshallfloyd(n);//ここまで全点間最短距離を求める
    ll ans = INF;
    vector<ll>one_case;
    rep(i,r){
        one_case.emplace_back(i);
    }
    do{
        ll res = 0;
        rep(i,r-1){
            ll now = one_case[i];
            ll nx = one_case[i+1];
            ll from = machi[now];
            ll to = machi[nx];
            res += dp[from][to];
        }
        chmin(ans,res);
    } while (next_permutation(one_case.begin(),one_case.end()));
    cout << ans << endl;
    return 0;
}

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

const int N=200000;
int a[N];
int b[N];
int c[N];

int dp[3][N];

int main(){
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>a[i];
        cin>>b[i];
        cin>>c[i];
    }
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    
    for(int i=1;i<n;i++){
        
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
        dp[2][i]=max(dp[1][i-1],dp[0][i-1])+c[i];
        
    }
    
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
}

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
typedef long double ld;
typedef long long int ll;
const ll INF = (1LL << 63);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0; i < n;i++)
const int MAX = 1000000010;
const ll MOD = 1000000007;
int n, m,k,sum = 0; string s;
int main() {
    cin >> n >> k; vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    rep(i, k) {
        sum += a[i];
    }cout << sum << endl;
}

Measured memory_bytes: 256
from itertools import accumulate

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())

dp = [1] + [0] * K
for a in A:
    S = [0] + list(accumulate(dp))
    for i in range(K + 1):
        dp[i] = (S[i + 1] - S[max(0, i - a)]) % mod

print(dp[K])

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

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

ll N;
ll A[100000];
ll M = 1e18;

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    bool f = false;
    for(int i=0;i<N;i++){
        if(A[i] == 0) f = true;
    }
    if(f){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(int i=0;i<N;i++){
        if(M / A[i] < ans){
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
        if(ans > M){
            cout << -1 << endl;
            return 0;
        }
        if(ans < 0){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4452
import sys
sys.setrecursionlimit(10000000)
p = 10**9+7
def power(a,b):
    if b == 0:
        return 1
    elif b%2 == 0:
        return (power(a,b//2)**2)%p
    else:
        return (a*power(a,b//2)**2)%p
def fact(a):
    if a <= 0:
        return 1
    else:
        return (a*fact(a-1))%p
H,W,A,B = map(int,input().strip().split(" "))
a,b = fact(H+B-A-1)%p,fact(W+A-B-1)%p
c,d = H-A-1,W-B-1
m = max(H-1,W-1)
mods = [1]*(m+1)
mods[m] = power(fact(m),p-2)
for i in range(m):
    mods[m-i-1] = (mods[m-i]*(m-i))%p
ans = 0
for i in range(min(c,d)+1):
    ans = (ans+a*b*mods[A+i]*mods[B+i]*mods[c-i]*mods[d-i])%p
print(ans)

Measured memory_bytes: 131444
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct node{
    int x;
    int y;
    int s;
};
int main(){
    int h,m,i,j,k,c=0;
    cin>>h>>m;
    char ch;
    int arr[50][50]={0};
    for(i=0;i<h;i++){
        getchar();
        for(j=0;j<m;j++){
            ch=getchar();
            if(ch=='#'){
              arr[i][j]=1;
              c++;
            }
        }
    }
    struct node que[2500];
    int book[50][50]={0};
    int next[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
    int head=0,tail=0,tx,ty,flag=0;
    que[tail].x=0;
    que[tail].y=0;
    que[tail++].s=1;
    book[0][0]=1;
    while(head<tail){
        for(k=0;k<4;k++){
            tx=que[head].x+next[k][0];
            ty=que[head].y+next[k][1];
            if(tx<0||tx>=h||ty<0||ty>=m)
                continue;
            if(arr[tx][ty]==0&&book[tx][ty]==0){
                book[tx][ty]=1;
                que[tail].x=tx;
                que[tail].y=ty;
                que[tail++].s=que[head].s+1;
            }
            if(tx==h-1&&ty==m-1){
                flag=1;
                break;
            }
        }
        if(flag) break;
        head++;
    }
    if(flag) cout<<h*m-c-que[tail-1].s;
    else cout<<-1;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int i,j,p,n,q,a[9]={5,7,5,7,7,-1},d[50];char s[50];main(){
for(;scanf("%d\n",&n),n;){for(i=0;i<n;)d[++i]=strlen(gets(s));
for(i=1;;i++){for(p=i,j=0,q=0;q>=0;){q=a[j];for(j++;q>0;p++)q-=d[p];}if(j>5)break;}
printf("%d\n",i);
}}

Measured memory_bytes: 1204
#include<iostream>
#include<stack>
#include<cstdlib>
#include<string>
#include <utility>
#include<queue>
#include<algorithm>

using namespace std;



int main(){

  int n = 0;
  int q = 0;
  int t = 0;

  int ruiseki = 0;
  int diff = 0;

  string name;
  queue<pair<string,int> > Q;
  pair<string,int> temp;

  cin >> n >> q;

  for(int i=0;i<n;i++){
    cin >> name >> t;
    Q.push(make_pair(name,t));
  }


  while(!Q.empty()){
   temp = Q.front();
   Q.pop();
   diff = min(q,temp.second);

   ruiseki += diff;
   temp.second -=diff;
   if(temp.second>0){
     Q.push(temp);
   }
   else{
     cout << temp.first << " " << ruiseki << endl;
   }
   
  }

  return 0;
}


Measured memory_bytes: 6340
#include <cstdio>
#include <iostream>

inline int read() {
	int x = 0; char ch = getchar();
	while(ch > '9' || ch < '0') ch = getchar();
	do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
	return x;
}

typedef long long ll;
const int MAXN = 200001;
const int MAXM = 8001;
const int base = 2002;
const int mod = 1000000007;

int n,a[MAXN],b[MAXN];
ll map[MAXM][MAXM];

ll fac[MAXM],invfac[MAXM];

ll Quick_Pow(ll a,ll b) {
	ll res = 1;
	while(b) {
		if(b & 1) res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return res;
}

void Init() {
	fac[0] = 1;
	for(int i = 1;i <= MAXM;i++) fac[i] = fac[i - 1] * i % mod;
	invfac[MAXM] = Quick_Pow(fac[MAXM],mod - 2);
	for(int i = MAXM - 1;i >= 0;i--) invfac[i] = invfac[i + 1] * (i + 1) % mod;
}

ll C(int n,int m) {
	return fac[n] % mod * invfac[m] % mod * invfac[n - m] % mod;
}

int main() {
	n = read();
	Init();
	for(int i = 1;i <= n;i++) {
		a[i] = read(), b[i] = read();
		map[-a[i] + base][-b[i] + base]++;
	}
	for(int i = 1;i <= 4002;i++)
		for(int j = 1;j <= 4002;j++)
			map[i][j] = (map[i][j] + map[i - 1][j] + map[i][j - 1]) % mod;
	ll ans = 0;
	for(int i = 1;i <= n;i++) {
		ans = (ans + map[a[i] + base][b[i] + base]) % mod;
		ans = ((ans - C(2 * a[i] + 2 * b[i],2 * a[i])) % mod + mod) % mod;
	}
	std::printf("%lld\n",((ans * invfac[2]) % mod + mod) % mod);
	return 0;
}


Measured memory_bytes: 253440
// VSCF.cpp : Defines the entry point for the console application.
//
#include <iomanip>
#include <string>
#include <ctime>
#include <random>
#include <functional>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <set>
#include <deque>
#include <map>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

#define MP make_pair
#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) decltype(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define int long long

#undef int 
int main() {
#define int long long
	int w, h;
	cin >> w >> h;
	vector<int> p(w);
	vector<int> q(h);
	int sump = 0;
	REP(i, w) {
		cin >> p[i];
		sump += p[i];
	}
	
	REP(i, h) {
		cin >> q[i];
	}
	sort(ALL(p));
	reverse(ALL(p));
	vector<int> prefixSum(w + 1);
	REP(i, w) {
		prefixSum[i + 1] = prefixSum[i] + p[i];
	}
	int res = sump;
	REP(i, h) {
		int palka = q[i];
		int l = 0;
		int r = w;
		while (l < r) {
			int m = (l + r + 1) / 2;
			if (p[m - 1] > palka) {
				l = m;
			} else {
				r = m - 1;
			}
		}
		int suma = prefixSum[r];
		int sprzed = r * palka;
		res += palka;
		res += sump;
		res -= suma;
		res += sprzed;
	}
	cout << res << endl;
}



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

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  if(B-A+1>=2*K){
    rep(i,K){
      cout<<A+i<<endl;
    }
    for(int i=K-1;i>=0;i--){
      cout<<B-i<<endl;
    }
  }else{
    for(int i=A;i<=B;i++){
      cout<<i<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, s, a[100010];

int main() {
    cin >> n >> s;
    rep(i, n) cin >> a[i];

    int ans = INF;
    int r = 0;
    int sum = 0;
    for (int l = 0; l < n; l++) {
        while (r < n && sum < s) {
            sum += a[r];
            r++;
        }
        if (sum >= s) chmin(ans, r-l);
        if (r == l) r++;
        else sum -= a[l];
    }
    if (ans == INF) ans = 0;
    cout << ans << endl;
}



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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;

  if (s.find('9') == s.npos) cout << "No\n";
  else cout << "Yes\n";
  
  return (0);
}

Measured memory_bytes: 3652
#include <iostream>
#define MAX_P 1000000
using namespace std;
int g;
int minx=0;
/*
void price(int a,int b,int c){
	if(a/5*1520+a%5*380+b/4*1870+b%4*550+c/3*2244+c%3*850<minx)
		minx=a/5*1520+a%5*380+b/4*1870+b%4*550+c/3*2244+c%3*850;
	return; 
}

void shop(int g,int a,int b,int c){
	if(g==0){
		price(a,b,c);
		return;
	}else if(g<0){
		return;
	}
	shop(g-200,a+1,b,c);
	shop(g-300,a,b+1,c);
	shop(g-500,a,b,c+1);
	return;
}

int main(){
	while(1){
		cin >> g;
		if(g==0)break;
		minx=MAX_P;	
		shop(g,0,0,0);
		cout << minx << endl;
	}
	return 0;
}
*/
int main(){
	while(1){
		cin >> g;
		if(g==0)break;
		minx=MAX_P;
		for(int i=0;i<=25;i++){
			for(int j=0;j<17;j++){
				if(i*200+j*300>g)continue;
				for(int k=0;k<=10;k++){
					if(i*200+j*300+k*500>g)continue;
					if(i*200+j*300+k*500==g){
						if(i/5*1520+i%5*380+j/4*1870+j%4*550+k/3*2244+k%3*850<minx)
							minx=i/5*1520+i%5*380+j/4*1870+j%4*550+k/3*2244+k%3*850;
					}
				}
			}
		}
		cout << minx << endl;
	}
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

bool ok(vector<int> a,int n,int k,ll m){
  ll count = 0LL;
  
  for(int i = 0;i<n;i++){
    if(a[i] > m){
      count += (a[i]+m-1)/m -1;
    }
  }
  
  return count <= k;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i,n){
    cin >> a[i];
  }
  ll rb = 1000000001LL;
  ll lb = 0;
  ll mid;
  while(rb - lb>1){
    mid = (rb + lb)/2;
    //k回以下になるかどうか
    if(ok(a,n,k,mid)){
      rb = mid;
    }else{
      lb = mid;
    }
  }
  
  cout << rb << endl;
 
  
  return 0;
}


Measured memory_bytes: 4732
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
//#define mod 998244353
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modinv(ll a){
	return powm(a,mod-2)%mod;
}

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    t=1;
    //cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	set<string>s;
    	for(int i=0;i<n;i++)
    	{
    		string k;cin>>k;
    		s.insert(k);
    		
		}
		cout<<(int)s.size();

    }

}

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

ans = 0

if a[0] > x:
    ans += a[0] -x
    a[0] = x

for i in range(n-1):
    if a[i] + a[i+1] > x:
        ans += a[i]+a[i+1] -x
        a[i+1] = x - a[i]

print(ans)


Measured memory_bytes: 63984
#include <iostream>

using namespace std;

int main()
{
  while(1){
    int n;
    int a[5000];
    cin >> n;
    if(n == 0)
      break;
    else{
      for(int i = 0; i < n; i++)
	cin >> a[i];
      int ans = a[0], num;
      for(int i = 0; i < n; i++){
	num = 0;
	for(int j = i; j < n; j++){
	  num += a[j];
	  ans = (num > ans) ? num : ans;
	}
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch MonstersBattleRoyale | diff MonstersBattleRoyale.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address MonstersBattleRoyale.cpp && ./a.out

/*
 
 2/28/2019
 
 15:36-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

LL gcd(LL a, LL b) { return b==0?a:gcd(b,a%b); }
void solve() {
  LL g=A[0];
  REP(i,N) g=gcd(g,A[i]);
  cout<<g<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int N,K,min = 99999999,f,count = 0;
  cin >> N >> K;
  vector<int> a(N);
  froop1(0,N){
    cin >> a.at(i);
    if(a.at(i) < min){
      min = a.at(i);
      f = i;
    }
  }
      count += (N - 1) / (K - 1);
      if((N - 1) % (K - 1) != 0) count++;
  cout << count << endl;
return 0;
}

Measured memory_bytes: 640
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
inf = 10**9+7

n,W = map(int, input().split())
dp = [[0 for j in range(W+1)] for i in range(n+1)] # i個まで選んだ時の最大値

for i in range(n):
    w, v = map(int, input().split())
    for j in range(W):
        if j+1-w >= 0:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i][j+1-w]+v)
        else:
            dp[i+1][j+1] = dp[i][j+1]
print(dp[n][W])

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

#define INF 2147483646

int matrixChainOrder(int d[], int size) {
    int n = size-1;
    int i,j,k,l, temp;
    int m[n+1][n+1];
    
    for (i = 1; i <= n; i++)
        m[i][i] = 0;
    
    for (l = 2; l <= n; l++)
        for (i = 1; i <= n-l+1; i++) {
            j = i+l-1;
            m[i][j] = INF;
            
            // loop through different k
            for (k = i; k <= j-1; k++) {
                temp = m[i][k] + d[i-1]*d[k]*d[j] + m[k+1][j];
                
                // minimization
                if (temp < m[i][j])
                    m[i][j] = temp;
            }
            
//            printf("minimum of m[%d][%d] = %d\n", i, j, m[i][j]);
        }
    
//            printf("RESULT of m[%d][%d] = %d\n", n, n, m[n][n]);
    return m[1][n];
}

void printArray(int array[], int length) {
    for (int i = 0; i < length; i++) {
        if (i) printf(", ");
        printf("%d", array[i]);
    }
}

int main(int argc, char** argv) {
    int nMatrix;
    scanf("%d", &nMatrix);
    
    int dimensions[nMatrix+1]; // p array
    int nRows;
    
    for (int i = 0; i < nMatrix; i++) {
        scanf("%d", &nRows);
        
        // reading p array
        if (i == 0)
            dimensions[0] = nRows;
//        else if (dimensions[i] != nRows)
//            return EXIT_FAILURE;
        
        scanf("%d", &dimensions[i+1]);
    }
//    printArray(dimensions, nMatrix+1);
//    printf("\n");
    
    printf("%d\n",matrixChainOrder(dimensions, nMatrix+1));

    return (EXIT_SUCCESS);
}




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

int main(void)
{
    char str[20], ans[20];
    int len, i;
    
    scanf("%s", str);
    len = strlen(str);
    
    for(i=0; i<len; i++) {
        printf("%c", str[len-i-1]); //-1は最後のEOFの分
    }
    puts("");
    
    return 0;
}


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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
    innn(a, b, c);
    out(a + b == c || a + c == b || b + c == a ? "Yes" : "No");
    return 0;
}


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

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

	int year = stoi(s.substr(0,4));
	int month = stoi(s.substr(5,2));
	int day = stoi(s.substr(8,2));

	string ans = "Heisei";
	if (year == 2019) {
		if (4 < month) {
			ans = "TBD";
		}
	} else if (2019 < year) {
		ans = "TDB";
	}

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


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

int main(){
  int N;
  double ans = 0.0, den = 0.0, A;
  cin >> N;
  for(int i = 1; i <= N; i++){
    cin >> A;
    den += 1.0 / A;
  }
  
  ans = 1.0 / den;
  cout << setprecision(16) << ans << endl;
  
}

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

int main(){
    int n, m;
    cin >> n;
    
    string blue[110];
    string red[110];
    
    for(int i = 0; i < n; i++){
        cin >> blue[i];
    }
    
    cin >> m;
    for(int i =0; i < m; i++){
        cin >> red[i];
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        int score = 0;
        for(int j = 0; j < n; j++){
            if(blue[j] == blue[i]){
                score++;
            }
        }
        for(int j = 0; j < m; j++){
            if(red[j] == blue[i]){
                score--;
            }
        }
     ans = max(ans, score);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

dp = [[0]*10 for i in range(10)]
s = ''
slen = 0

def get_dp(i, j):

    if i>j:
        return 0
    if dp[i][j]!=0:
        return dp[i][j]


    ans = 0
    for k in range(i, j+1):
        ans += int(s[i:k+1]) *  (1 <<max(0,(j-k-1))) + get_dp(k+1,j)

    
    dp[i][j] = ans
    return ans



def solve():
    global s, slen
    s = input()

    slen = len(s)

    print(get_dp(0, slen-1))

solve()


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

int main()
{
    string arf = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";//ここでごまかす。
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<=s.size();i++)
    {
        for(int j=0;j<26;j++)
        {
            if(s[i]==arf[j])
            {
                s[i]=arf[j+n];
                break;
            } 
        }
    }

    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
H,W,D = map(int,input().split())

max_value = H*W

position = [0]*(max_value+1)

root_cost = [0]*(max_value+1)

for y in range(H):
    A = list(map(int,input().split()))
    for x in range(W):
        position[A[x]] = (x+1,y+1)

for i in range(1,max_value+1):
    if 0 < i-D:
        x1,y1 = position[i-D]
        x2,y2 = position[i]
        root_cost[i] = root_cost[i-D]+(abs(x2-x1)+abs(y2-y1))

Q=int(input())

for i in range(Q):
    L,R = map(int,input().split())
    print(root_cost[R]-root_cost[L])

Measured memory_bytes: 82056
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        int len = s.length();

        if(len<=k){
            System.out.println(s);
        }else{
            char[] moji = s.toCharArray();
            for(int i = 0;i<k;i++){
                System.out.print(moji[i]);
            }
            System.out.println("...");
        }


    }
}

Measured memory_bytes: 35764
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<iomanip>
#include<cstring>
#define reg register
#define EN std::puts("")
#define LL long long
inline int read(){
	register int x=0;register int y=1;
	register char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return y?x:-x;
}
int num[200006];
int main(){
	int n=read();
	for(reg int i=1;i<n;i++) num[read()]++;
	for(reg int i=1;i<=n;i++) std::printf("%d\n",num[i]);
	return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    string s; cin >> s;

    string ans = "";
    rep(i, s.size()){
        if(s[i]=='B'){
            if(ans.size()!=0){
                ans.erase(ans.size()-1);
            }
        }
        else{
            ans.push_back(s[i]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
N,K=map(int,input().split())
h=[]
for i in range(N):
    h.append(int(input()))

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged
h=merge_sort(h)
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))


Measured memory_bytes: 87896
N,K = map(int,input().split())
mochi = set([])
zenbu = set(list(range(1,N+1)))

for k in range(K):
    di = int(input())
    AAi = list(map(int,input().split()))
    for a in AAi:
        mochi.add(a)
        
print(len(zenbu - mochi))

Measured memory_bytes: 67708
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    T=readline().strip()

    d=dict()
    for i in range(len(S)):
        if S[i] not in d:
            d[S[i]]=T[i]
        else:
            if d[S[i]]!=T[i]:
                print("No")
                break
    else:
        li=list(d.items())
        d2=dict()
        for cs in li:
            c1=cs[0]
            c2=cs[1]
            if c2 not in d2:
                d2[c2]=c1
            else:
                if d2[c2]!=c1:
                    print("No")
                    break
        else:
            print("Yes")
if __name__=="__main__":
    main()

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <math.h>
#include <limits.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n){
        int tmp=0;
        int s1=0, t1=0;
        for(int i=0;i<n;i++){
            cin>>tmp;
            s1+=tmp*tmp;
            t1+=tmp;
        }
        int avg=t1/n;
        int res=min(n*avg*avg-2*t1*avg+s1, n*(avg+1)*(avg+1)-2*t1*(avg+1)+s1);
        cout<<res<<endl;
    }
    return 0;
}


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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N, K;
  cin >> N >> K;

  double ret = 0;

  for(int i = 1; i <= N; i++){
    double tmp = 1.0 / N;
    int now = i;
    while(now < K){
      now *= 2;
      tmp /= 2;
    }
    ret += tmp;
  }

  cout << setprecision(12) << ret << endl;

  return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    string S;
    cin >> S;
    ll N = std::min(K, (ll)S.length());
    REP(i, N) {
        cout << S[i];
    }
    if (S.length() > N) {
        cout << "...";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			TreeSet<Integer>TS=new TreeSet<Integer>(); 
			for(int i=1;i<n;i++)
				TS.add((i*i)%n);
			int a[]=new int[TS.size()];
			int k=0;
			for(int p:TS)
				a[k++]=p;
			int c[]=new int[k*(k-1)];
			int x=0;
			for(int i=0;i<k;i++)
				for(int j=0;j<k;j++)
				{
					if(i==j)
						continue;
					int rem=a[i]-a[j];
					if(rem<0)
						rem+=n;
					if(rem>(n-1)/2)
						rem=n-rem;
					c[x++]=rem;
				}
			int b[]=new int[(n-1)/2+1];
			for(int i=0;i<k*(k-1);i++)
				b[c[i]]++;
			for(int i=1;i<=(n-1)/2;i++)
				System.out.println(b[i]);
		}
	}
}

Measured memory_bytes: 239132
/*
    Problem 24
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_B
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 102;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
vector<int> d(MAX), f(MAX), deg(MAX), cur(MAX);
int t = 1;
/* function */
void dfs(int st) {
    stack<int> S;
    S.push(st);
    d[st] = t++;
    while (!S.empty()) {
        int from = S.top();
        if (cur[from] >= deg[from]) {
            f[from] = t++;
            S.pop();
            continue;
        }
        int to = G[from][cur[from]++];
        if (d[to] != 0) continue;
        d[to] = t++;
        S.push(to);
    }
}
/* main */
int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k, v;
        cin >> u >> k;
        u--;
        deg[u] = k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }

    // dfs
    for (int i = 0; i < n; i++) {
        if (d[i] == 0) dfs(i);
    }

    for (int i = 0; i < n; i++)
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << '\n';
}


Measured memory_bytes: 3160
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
    long[][] vertexes = new long[n][];
    long answer = 0;
    for(long i = 0; i < n; i++)
    {
      vertexes[i] = new long[3];
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      vertexes[i][0] = nums[0];
      vertexes[i][1] = nums[1];
      vertexes[i][2] = nums[0] + nums[1];
    }
    Array.Sort(vertexes, (a, b) => b[2].CompareTo(a[2]));//和が大きい順

    for(int i = 0; i < n; i++)
    {
      if(i % 2 == 0) answer += vertexes[i][0];
      else answer -= vertexes[i][1];
    }

		Console.WriteLine(answer);
	}
}

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

using namespace std;

void solve() {
    int k; cin >> k;
    if (k <= 9) {
        cout << k; return;
    }
    queue<long long> q;
    for (int i = 1; i <= 9; i++) {
        q.push(i);
    }
    while (!q.empty()) {
        long long v = q.front(); q.pop();
        k--;
        if (!k) {
            cout << v; return;
        }
        int last = v % 10;
        if (last - 1 >= 0)
            q.push(v * 10 + last - 1);
        q.push(v * 10 + last);
        if (last + 1 <= 9)
            q.push(v * 10 + last + 1);
    }
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
using ll = long long;

int main() {
	ll n, a[101], max = 0, min = 100, i, tukare, min_tai = 10000000000;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (max < a[i] || i == 0)
			max = a[i];
		if (min > a[i] || i == 0)
			min = a[i];
	}

	for (i = min; i <= max; i++) {
		tukare = 0;
		for (int j = 0; j < n; j++) {
			tukare += (a[j] - i) * (a[j] - i);
		}
		if (i == min)
			min_tai = tukare;
		if (min_tai > tukare)
			min_tai = tukare;
	}


	cout <<  min_tai << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int a,b,c;
      cin>>a>>b>>c;
      if((a==5)&&(b==5)&&(c==7))
        cout<<"YES";
      else if((a==7)&&(b==5)&&(c==5))
        cout<<"YES";
      else if((a==5)&&(b==7)&&(c==5))
        cout<<"YES";
      else
        cout<<"NO";
      return 0;
    }

Measured memory_bytes: 764
N, M = map(int, input().split())

lights = list()
for i in range(M):
   swithes = list(map(int, input().split()))
   lights.append(swithes[1:])

light_on_condition = list(map(int, input().split()))

ans = 0
for mask in range(1<<N):
    swithes_status = [0] * M
    for i in range(N):
        if mask & (1<<i) >= 1:
            # push switch
            for j, light in enumerate(lights):
                if (i+1) in light:
                    swithes_status[j] += 1
    full_on = True
    for condition, status in zip(light_on_condition, swithes_status):
        if condition != status % 2:
            full_on = False
            break
    if full_on:
        ans += 1

print(ans)


Measured memory_bytes: 41840
#include <iostream>
#include <string.h>
using namespace std;

const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int field[101][101];

int xs,ys,xg,yg;

void SetBlock(int c,int d,int x,int y)
{
	if(d==0){//横なが
		for(int ay=0;ay<2;++ay){
			for(int ax=0;ax<4;++ax){
				field[y+ay][x+ax] = c;
			}
		}
	}
	if(d==1){//縦なが
		for(int ay=0;ay<4;++ay){
			for(int ax=0;ax<2;++ax){
				field[y+ay][x+ax] = c;
			}
		}
	}
}

bool dfs(int x,int y)
{
	int c = field[y][x];
	field[y][x] = 0;
	if(x == xg && y == yg) return true;
	for(int i=0;i<4;++i){
		if(c==field[y+dy[i]][x+dx[i]])if(dfs(x+dx[i],y+dy[i]))return true;
	}
	return false;
}

int main(void)
{
	while(1){
		int w,h;
		int n;
		memset(field,0,sizeof(field));
		cin >> w >> h;
		if(w==0&&h==0)
			return 0;
		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;
		for(int i=0;i<n;++i){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			SetBlock(c,d,x,y);
		}
		if(field[ys][xs] == 0)
			cout << "NG" << endl;
		else
		{
			if(dfs(xs,ys))
				cout << "OK" << endl;
			else
				cout << "NG" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
import sys
x=sys.stdin.read()
x=x.lower()
final=[0 for i in range(26)]
for i in x:
    k=ord(i)-97
    if k>=0 and k<=25:
        final[k]+=1
for i,v in enumerate(final):
    print(chr(i+97)+' : '+str(v))



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

int main(){
  long long int n, k, a;

  cin >> n >> k;
  vector<int> H;
  long long int sum = 0;

  for (int i = 0; i < n; i++){
    cin >> a;
    H.push_back(a);
  }

  sort(H.begin(), H.end(), greater<int>());


  if (n <= k) cout << "0" << endl;
  else {
    for(int i = k; i < n; i++){
      sum += H[i];
    }
    cout << sum << endl;
  }

  return 0;
}


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

int main(){
  string s;
  cin>>s;
  rep(i,0,3){
    if(s[i]=='1') cout<<9;
    else cout<<1;
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MAXN = 1e5;
using namespace std;

char s[MAXN + 5];
int n, cnt[26];

void init() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  init();
  
  for (int i = 1; i <= n; ++i) {
    ++cnt[s[i] - 'a'];
    for (int j = i + 1; j <= min(i + 3, n); ++j) {
      ++cnt[s[j] - 'a'];
      if (cnt[s[j] - 'a'] * 2 > j - i + 1) {
        printf("%d %d\n", i, j);
        return 0;
      }
    }
    for (int j = i; j <= min(i + 3, n); ++j) {
      --cnt[s[j] - 'a'];
    }
  }
  
  puts("-1 -1");
  return 0;
}

Measured memory_bytes: 384
from math import atan2, degrees

N = int(input())
holes = [tuple(map(int, input().split())) for i in range(N)]

for x, y in holes:
    slopes = []
    for x2, y2 in holes:
        if x == x2 and y == y2: continue
        slopes += [degrees(atan2(y2 - y, x2 - x))]

    aRange = [(0, 360)]
    for slope in slopes:
        f1 = (slope + 90) % 360
        t1 = (slope - 90) % 360
        if t1 == 0: t1 = 360

        if f1 <= t1:
            fts = [(f1, t1)]
        else:
            fts = [(0, t1), (f1, 360)]

        aRange2 = []
        for f, t in fts:
            for aFr, aTo in aRange:
                if aFr <= f: aFr = f
                if t <= aTo: aTo = t
                if aFr <= aTo:
                    aRange2 += [(aFr, aTo)]
        aRange = aRange2

    ans = 0
    for aFr, aTo in aRange:
        ans += (aTo - aFr) / 360
    print(ans)


Measured memory_bytes: 3444
using System;
using System.Linq;

namespace comp
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var inputs = Console.ReadLine();
			var interval = int.Parse(Console.ReadLine());

			var result = "";

			foreach (var it in inputs.Select((obj, index) => new { obj, index })) {
				if (it.index == 0 || it.index % interval == 0) {
					result += it.obj;
				}
			}

			Console.WriteLine (result);
		}
	}
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int MAX_N = 100;

int N;
vi G[MAX_N];
int d[MAX_N];
int f[MAX_N];

void dfs(int v=0)
{
    static int t=1;
    d[v] = t++;
    for(auto u:G[v]){
        if (d[u]>0) continue;
        dfs(u);
    }
    f[v] = t++;
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N;
    rep(i,N){
        int u,k; cin>>u>>k; u--;
        rep(i,k){
            int v; cin>>v; v--;
            G[u].pb(v);
        }
    }
    rep(i,N)if(d[i]==0){
        dfs(i);
    }
    rep(i,N){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main() {
  
  int N ;
  cin >> N ;
  vector<int> A(N);
  rep(i,N) cin >> A.at(i);
  priority_queue<int> pq;
  rep(i,N) pq.push(A.at(i));
  int X = pq.top();
  pq.pop();
  int Y = pq.top();
  rep(i,N) {
    if( A.at(i) == X ) cout << Y << endl;
    else cout << X << endl;
  }
}

   

Measured memory_bytes: 3316
s = input()
ans = []

for i in range(len(s)):

	if s[i] == "B" and len(ans) >= 1:
		ans.pop(-1)
	elif s[i] == "0":
		ans.append("0")
	elif s[i] == "1":
		ans.append("1")

print("".join(ans))

Measured memory_bytes: 3060
import sys
readline = sys.stdin.readline

def merge(A, B):
    N = len(A)
    res = [B[A[i]] for i in range(N)]
    return res

N = int(readline())

X = list(map(int, readline().split()))
M, K = map(int, readline().split())
A = list(map(lambda x:int(x)-1, readline().split()))
Y = [x2 - x1 for x1, x2 in zip(X, X[1:])]

 
P = list(range(N))
for a in A:
    P[a], P[a+1] = P[a+1], P[a]
stack = [P]
for _ in range(65):
    stack.append(merge(stack[-1], stack[-1]))

E = list(range(N))
for i in range(K.bit_length()):
    if (1<<i) & K:
        E = merge(E, stack[i])

Ans = [0]*N
Ans[0] = X[0]
for i in range(1, N):
    Ans[i] = Ans[i-1] + Y[E[i]-1]
print('\n'.join(map(str, Ans)))

Measured memory_bytes: 146944
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  n <- unsafeSignedDecimal <$> T.getLine :: IO Int
  as <- sequence . replicate n $ unsafeSignedDecimal <$> T.getLine :: IO [Int]
  let
    ls = scanl max 0 . init $ as
    rs = scanr max 0 . tail $ as
  mapM_ print $ zipWith max ls rs

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 81276
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

Int n, c[501], s[501], f[501];

int main(){
	cin >> n;
	for(int i = 0; i < n-1; i++){
		cin >> c[i] >> s[i] >> f[i];
	}
	
	for(int i = 0; i < n ; i++){
		int j = i, time = 0;
		while(j < n-1){
			if(time <= s[j]){
				time = s[j] + c[j];
			}
			else{
				int a = 1;
				for(a = 1; time > s[j] + f[j]*a; a++){}
				time = s[j] + f[j] * a + c[j];
			}
			j++;
		}
		cout << time << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    rep(i, N) {
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }
    
    int ans = 1e9;
    rep(bit, 1 << N) {
        vector<int> S;
        rep(i, N) {
            if (bit & (1 << i)) S.push_back(i);
        }
        vector<int> res(M, 0);
        for (int i : S) {
            rep(j, M) res[j] += A[i][j];
        }
        bool judge = true;
        rep(i, M) {
            if (res[i] < X) judge = false;
        }
        if (judge) {
            int cost = 0;
            for (int i : S) cost += C[i];
            ans = min(ans, cost);
        }
    }
    if (ans == 1e9) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636