akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1000000007;

struct mint
{
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

mint fact(ll n)
{
  if (n < 0)
    return mint(0);
  mint ret = 1;
  for (ll i = 1; i <= n; ++i)
    ret *= mint(i);
  return ret;
}
mint nCk(ll n, ll k)
{
  if (n < k || n < 0 || k < 0)
    return mint(0);
  return fact(n) * fact(n - k).inv() * fact(k).inv();
}

int main()
{
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  ll red = N - K;
  mint pre = 0;
  for (ll i = 1; i <= K; ++i)
  {
    cout << nCk(N - K + 1, i) * nCk(K - 1, i - 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> dp(n+1, 0);

    int x;
    cin >> x;
    while(--x >= 0){
        string s;
        int p;
        cin >> s >> p;
        if(s == "D"){
            for(int i=1; i<=n; ++i)
                dp[i-1] = max(dp[i-1], dp[i] + p);
        }
    }

    int y;
    cin >> y;
    while(--y >= 0){
        string s;
        int p;
        cin >> s >> p;
        if(s == "DD"){
            for(int i=2; i<=n; ++i)
                dp[i-2] = max(dp[i-2], dp[i] + p);
        }
    }

    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1208
#include <iostream>

using namespace std;

class dice {
public:
    int face[6];
    void rotate(char dir) {
        int temp;
        switch(dir) {
        case 'N':
            temp = face[0];
            face[0] = face[1];
            face[1] = face[5];
            face[5] = face[4];
            face[4] = temp;
            break;
        case 'E':
            temp = face[0];
            face[0] = face[3];
            face[3] = face[5];
            face[5] = face[2];
            face[2] = temp;
            break;
        case 'W':
            temp = face[0];
            face[0] = face[2];
            face[2] = face[5];
            face[5] = face[3];
            face[3] = temp;
            break;
        case 'S':
            temp = face[0];
            face[0] = face[4];
            face[4] = face[5];
            face[5] = face[1];
            face[1] = temp;
            break;
        }
    }
    bool rotateto(int top, int front) {
        const char *dir = "EEENWWWS";
        for(int i=0; i<24; i++) {
            if(face[0]==top && face[1]==front) return true;
            rotate(dir[i%8]);
        }
        return false;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    dice d;
    for(int i=0; i<6; i++) {
        cin >> d.face[i];
    }
    int n, t, f;
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>t>>f;
        d.rotateto(t, f);
        cout<<d.face[2]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 1192
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST

import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parse :: Parser (Int, Int, [(Int,Int)])
parse = do
    n <- parseInt
    w <- parseInt
    fmap ((,,) n w) (replicateM n parseInt2)

main = do
    (n,w,wvs) <- fromJust.evalStateT parse <$> B.getContents
    print $ f n w wvs

f n w wvs = runST $ do
    dp <- newArray ((0,0),(n,100000)) maxBound :: ST s (STUArray s (Int,Int) Int)
    writeArray dp (0,0) 0
    forM_ [(i,wi,vi,j)|(i,(wi,vi))<-zip [1..] wvs,j<-[0..100000]] $ \(i,wi,vi,j) ->
        writeArray dp (i,j) =<< if j-vi < 0 then readArray dp (i-1,j)
        else min.(+wi).min (maxBound-wi)<$>readArray dp (i-1,j-vi)<*>readArray dp (i-1,j)
    maximum.map fst.filter((<=w).snd)<$>mapM(fmap<$>(,)<*>readArray dp.(,) n)[0..100000]


Measured memory_bytes: 95868
#-------------------------------------------------------------------
MOD = 10**9+7
#-------------------------------------------------------------------

N = int(input())
A = [int(i) for i in input().split()]

from itertools import accumulate
B = list( accumulate(A) )

ans = 0
for i in range(N-1):
  ans += ((B[-1]-B[i]) % MOD) * (A[i] % MOD)
  ans %= MOD

print(ans % MOD)



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

using namespace std;

int main(void) {

    int nums[3];
    cin >> nums[0] >> nums[1] >> nums[2];

    for (int i = 2; i >= 1; --i) {
        for (int j = i - 1; j >= 0; --j) {
            if (nums[i] < nums[j]) {
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
            }
        }
    }

    printf("%d %d %d\n", nums[0], nums[1], nums[2]);

    return 0;
}

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

const int MAX_N = 1e5 + 10;

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main()
{
	int a = 0, b = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i)
	{
		if (i % 2 == 0)
		{
			if (s[i] == '0')
			{
				++a;
			}
			else
			{
				++b;
			}
		}
		else
		{
			if (s[i] == '0')
			{
				++b;
			}
			else
			{
				++a;
			}
		}
	}
	if (a < b)
	{
		cout << a << endl;
	}
	else
	{
		cout << b << endl;
	}
}

Measured memory_bytes: 512
n=int(input())
t=list(map(int,input().split()))
m=int(input())
p=[list(map(int,input().split())) for i in range(m)]
x=0
while x<m:
  z=t[p[x][0]-1]-p[x][1]
  print(sum(t)-z)
  x=x+1

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <string>

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORN(i, n, s) for (int i = s; i < n; i++)
#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;
#define PACK(a, n) \
  for (int i = 0; i < n; i++) cin >> a[i];
#define PACKN(a, n, s) \
  for (int i = s; i < n; i++) cin >> a[i];
#define LIST(a, n) \
  for (int i = 0; i < n; i++) cout << "[" << i << "] " << a[i] << endl;

using namespace std;

int main() {
  int NUM[3];
  PACK(NUM, 3);
  int max = 0;
  FOR(i, 3) {
    FOR(j, 3) {
      if (i == j) continue;
      FOR(k, 3) {
        if (j == k || i == k) continue;
        int comb = stoi(to_string(NUM[j]) + to_string(NUM[k]));
        if (comb + NUM[i] > max) max = comb + NUM[i];
      }
    }
  }
  OUT(max);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define rrep(i, n) for (i = n; i >= 0; i--)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)

int main() {
    long long s, c;
    scanf("%lld %lld", &s, &c);

    long long ans = min(s, c / 2);
    c -= ans * 2;
    ans += c / 4;
    printf("%lld\n", ans);
    return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int a,b ,k; cin >> a >> b >> k;
    k--;
    int div = 1;
    int counter = 0;
    vector<int> ans;
    while(div<=max(a,b))
    {
        if(a%div==0 && b%div==0)
        {
            ans.push_back(div);
        }
        div++;
    }
    sort(ans.begin(),ans.end(), greater<int>());    

    cout << ans[k] << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
deque < long long > q;
long long sm=0;
int main()
{
	int n,k;
	cin>>n>>k;
	int a;
	if(k>=n)
	{
		cout<<"0";
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		cin>>a;
		q.push_back(a);
	}
	sort(q.begin(),q.end());
	for(int i=0;i<n-k;i++)
	{
		sm+=q[i];
	}
	cout<<sm;
	return 0;
}

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

using namespace std;

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

int main(){
    ll n;
    cin>>n;
    ll ans = 0LL;
    for(ll i=1; i<=n; i++){
        ans += calc(i);
    }

    for(ll i=0; i<n-1; i++){
        int u, v;
        cin>>u>>v;
        if(u>v){
            ll t = u;
            u = v;
            v = t;
        }
        assert(u<=v);
        ans -= u*(n-v+1);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, n; cin >> k >> n;
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) cin >> a[i];
  a[n] = a[0] + k;
  vector<int> d(n);
  for (int i = 0; i < n; i++) d[i] = a[i+1] - a[i];
  cout << k - *max_element(d.begin(), d.end()) << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int m, f, r;//??????????¨?????????°, ??????????¨?????????°, ???????¨?????????°
	
	while(true){
		
		scanf("%d %d %d", &m, &f, &r);
	
		if(m == -1 && f == -1 && r == -1){
			break;
		}
		
		if(m == -1 || f == -1 || m + f < 30){
			printf("F\n");
		}
		else if(m + f >= 80){
			printf("A\n");
		}
		else if(65 <= m + f){
			printf("B\n");
		}
		else if(50 <= m + f){
			printf("C\n");
		}
		else if(30 <= m + f){
			if(r >= 50){
				printf("C\n");
			}
			else{
				printf("D\n");
			}
		}
		
	}
}

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[105];
void InsertSort(int a[], int n)
{
    int i, j;
    int tmp;
    for(int i=1; i<n; i++)
    {
        tmp = a[i];
        for(j = i; j >0 && a[j-1]>tmp; j--)
        {
            a[j] = a[j-1];
        }
        a[j] = tmp;
        for(int k=0; k<n; k++)
            printf(k==0?"%d":" %d", a[k]);
        printf("\n");
    }

}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);

    for(int k=0; k<n; k++)
        printf(k==0?"%d":" %d", a[k]);
    printf("\n");

    InsertSort(a, n);
    return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

const int mod = 2019;
const int INF = 1e16;
int main() {
	ll l, r;
	cin >>l >>r;
	ll ans(INF);
	for (ll i = l; i < r; ++i) {
		for (ll j = l + 1; j <= r; ++j) {
			ll ii = i % mod;
			ll jj = j % mod;
			ll can = ii * jj;
			can %= mod;
			ans = min(ans, can);
			if (ans == 0) {
				cout << 0;
				return 0;
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3520
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    multiset<int> ms;
    for(int i=0; i<n; ++i){
        auto it = ms.lower_bound(a[i]);
        if(it != ms.begin()){
            -- it;
            ms.erase(it);
        }
        ms.insert(a[i]);
    }
    cout << ms.size() << endl;

    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


string s, t;
set<char> c[26], cc[26];

int main(){
	cin >> s >> t;
	
	bool ans = 0;
	for(int i = 0; i < s.size();i++){
		c[(char)s[i]-'a'].insert(t[i]);
		cc[(char)t[i]-'a'].insert(s[i]);
		if(c[(char)s[i]-'a'].size() > 1 || cc[(char)t[i]-'a'].size() > 1) ans = 1;
	}
	if(ans) cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 776
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=1e5+10;
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0;
	char a;
	cin>>a;
	if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
		puts("vowel");
	else puts("consonant");
	return 0;
}

Measured memory_bytes: 256
def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()
if x > 2*y or y > 2 * x:
    print(0)
    exit()

# 以下の連立方程式を解いて、代入
# n + 2m  = X
# 2n+ m = Y
# (n+m)Cn
print(nCr((x + y)//3, (-x+2*y)//3))


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

int main() {
  long long n, k; cin >> n >> k;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  long long cou = 0;
  vector<int> f(n);
  long long i = 0, it = 0;
  vector<long long> p(n);
  while(f.at(i)!=1){
    f.at(i)=1;
    p.at(i)=cou;
    cou++;
    it = i;
    i = a.at(i) - 1;
  }
  long long wa = p.at(it) - p.at(i) + 1;
  if(k <= p.at(i)){
    for(int j = 0; j < n; j++){
      if(p.at(j) == k){
        cout << j + 1;
    //    return 0;
      }
    }
  }else{
    long long amari = (k-p.at(i))%wa;
    long long ima = i;
    for(int j = 0; j < amari; j++){
      ima = a.at(ima)-1;
      if(j == amari-1){
        cout << ima+1;
        return 0;
      }
    }
    cout << i+1;
  }
}

Measured memory_bytes: 7204
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a;
	cin >> b;
	if (a < b){
		cout << "a < b" << endl;
	}else if(a > b){
		cout << "a > b" << endl;
	}
	else if (a == b){
		cout << "a == b" << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}


int main() {
  int n,k;
  cin >> n >> k;
  vector<int> P(n);
  rep(i,n) cin >> P[i];
  sort(P.begin(),P.end());
  cout << accumulate(P.begin(),P.begin()+k,0) << endl;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main()
{
  int n; cin >> n;
  vi p(n); rep(i,n) cin >> p[i];
  
  vi a(n),b(n);
  rep(i,n){
    int pos;
    rep(j,n) if(p[j] == i + 1) pos = j;
    a[i] = 30000 * i + pos + 1;
    b[i] = 30000 * (n - i);
  }

  rep(i,n-1) cout << a[i] << " ";
  cout << a[n-1] << endl;
  rep(i,n-1) cout << b[i] << " ";
  cout << b[n-1] << endl;
}

Measured memory_bytes: 1152
from datetime import datetime
while 1:
 try:y,m,d=map(int,input().split())
 except:break
 dt = (datetime(y,m,d)-datetime(1868,9,8)).days
 if dt<0:print('pre-meiji')
 elif dt<16030:print('meiji',y-1867,m,d)
 elif dt<21291:print('taisho',y-1911,m,d)
 elif dt<43951:print('showa',y-1925,m,d)
 else:print('heisei',y-1988,m,d)


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

int main(){
    int a, b, k, count=0, ans[100];
    cin >> a >> b >> k;
    for(int i=1; i<=100; i++){
        if(a%i==0 && b%i==0){
            ans[count]=i;
            count++;
        }
    }
    cout << ans[count-k] << endl;
}

Measured memory_bytes: 256
n = int(input())
s = {2}
s.remove(2)
for i in range(n):
    order = list(map(str, input().split()))
    if (order[0][0] == 'i'):
        s.add(order[1])
    else:
        if order[1] in s:
            print('yes')
        else:
            print('no')
        


Measured memory_bytes: 30988
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

class Pos {
public:
	int node;
	int hand;

	bool operator < (const Pos &p) const {
		if (node != p.node)return node < p.node;
		else return hand < p.hand;
	}
};

struct edge {
	Pos to;
	double dist;
};

typedef priority_queue<pair<double, Pos>, vector<pair<double, Pos>>, greater<pair<double, Pos>>> Que;

void Dijkstra(map<Pos, vector<edge>> graph, Pos start, map<Pos, double> &cost) {
	Que Q;

	cost[start] = 0;

	Q.push(mp(0, start));	// (cost, index)

	while (!Q.empty()) {
		double d = Q.top().first;
		Pos pos = Q.top().second;
		Q.pop();
		rep(i, graph[pos].size()) {
			if (cost.find(graph[pos][i].to) == cost.end() || 
				cost[graph[pos][i].to] > cost[pos] + graph[pos][i].dist) {
				cost[graph[pos][i].to] = cost[pos] + graph[pos][i].dist;
				Q.push(mp(cost[graph[pos][i].to], graph[pos][i].to));
			}
		}
	}
}

int main() {
	cout << fixed << setprecision(14);
	while (true) {
		int N, M, P, a, b;
		cin >> N >> M >> P >> a >> b;
		if (N == 0)break;
		a--; b--;
		vi t(N);
		rep(i, N) {
			cin >> t[i];
		}
		map<Pos, vector<edge>> G;

		rep(i, P) {
			int x, y, z;
			cin >> x >> y >> z;
			x--; y--;
			rep(j, 1 << N) {
				rep(k, N) {
					if ((j&(1 << k)) != 0) {
						// ?????±??????k????????£?????????
						G[Pos{ x, j }].push_back(edge{ Pos{ y, j ^ (1 << k) }, (double)z / t[k] });
						G[Pos{ y, j }].push_back(edge{ Pos{ x, j ^ (1 << k) }, (double)z / t[k] });
					}
				}
			}
		}
		map<Pos, double> cost;

		Dijkstra(G, Pos{ a, (1 << N) - 1 }, cost);

		bool goal = false;
		double ans = INF;

		rep(j, 1 << N) {
			if (cost.find(Pos{ b,j }) != cost.end()) {
				goal = true;
				ans = min(ans, cost[Pos{ b,j }]);
			}
		}
		if (!goal) {
			cout << "Impossible" << endl;
		}
		else {
			cout << ans << endl;
		}
	}

	return 0;
}

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

using namespace std;

const int MOD = 1e9+7;
const int Nmax = 1e5+5;
ifstream f("1.in");

int n;
vector <int> v[Nmax];

int mul(int a, int b)
{
    return (long long) a*b%MOD;
}

pair <int, int> dfs(int a, int parent)
{
    int all_white=1, sth_is_blck=0;
    for (auto b:v[a])
    {
        if(b != parent)
        {
            pair <int, int> p=dfs(b, a);
            int memo=all_white;
            all_white=mul(all_white, p.second);
            sth_is_blck=(mul(memo, p.first)+
                         mul(sth_is_blck, (p.first+p.second)))%MOD;
        }
    }
    return make_pair(all_white, (all_white+sth_is_blck)%MOD);
}


int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    pair <int, int> p=dfs(1, 0);
    cout << (p.first+p.second)%MOD;
    return 0;
}


Measured memory_bytes: 12672
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////

int main() {

	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	rep(i, M)cin >> A[i];

	long long sum = 0;
	rep(i, M)sum += A[i];

	if (sum > N)cout << -1 << endl;
	else cout << N - sum << endl;
}


Measured memory_bytes: 3196
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define inver(a) power(a,mod-2)
using namespace std;
inline char nc()
{
    return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
typedef long long ll;
const int maxk=100+5;
const int maxn=100+5;
int mod;
int n,m,k;
int fac[maxn];
int inv[maxn];
int f[maxk][maxn][maxn][2];
inline int sub(int x) {return x<0?x+mod:x;}
inline void upd(int &x,int y) {x+=y; if(x>=mod) x-=mod;}
ll power(ll x,ll y)
{
    ll re=1;
    while(y)
    {
        if(y&1) re=re*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return re;
}
void init(int n)
{
    fac[0]=1;
    for(int i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod;
    inv[n]=inver(fac[n]);
    for(int i=n;i>=1;--i) inv[i-1]=(ll)inv[i]*i%mod;
}
int main()
{
    read(n),read(m),read(k),read(mod);
    f[1][0][0][0]=1;
    init(max(n,m));
    for(int t=1;t<=k;++t)
    {
        for(int i=0;i<=n;++i) 
        {
            int a=1,b=1,c=power(k-t+1,m);
            int w=inver(k-t+1);
            for(int j=m;j>=0;--j)
            {
                int r=(ll)sub(a-b)*c%mod;
                if(f[t][i][j][0]) 
                {
                    // debug("%d %d %d %d %d\n",t,i,j,0,f[t][i][j][0]);
                    upd(f[t][i][j][1],f[t][i][j][0]);
                    for(int x=1,coe=1;x+i<=n;++x)
                    {
                        coe=(ll)coe*r%mod;
                        upd(f[t][i+x][j][1],(ll)f[t][i][j][0]*coe%mod*inv[x]%mod);
                    }
                }
                a=(ll)a*t%mod;
                b=(ll)b*(t-1)%mod;
                c=(ll)c*w%mod;
            }
        }
        for(int j=0;j<=m;++j) 
        {
            int a=1,b=1,c=power(t,n);
            int w=inver(t);
            for(int i=0;i<=n;++i)
            {
                int r=(ll)sub(a-b)*c%mod;
                if(f[t][i][j][1]) 
                {
                    // debug("%d %d %d %d %d\n",t,i,j,1,f[t][i][j][1]);
                    upd(f[t+1][i][j][0],f[t][i][j][1]);
                    for(int x=1,coe=1;x+j<=m;++x)
                    {
                        coe=(ll)coe*r%mod;
                        upd(f[t+1][i][j+x][0],(ll)f[t][i][j][1]*coe%mod*inv[x]%mod);
                    }
                }
                a=(ll)a*(k-t+1)%mod;
                b=(ll)b*(k-t)%mod;
                c=(ll)c*w%mod;
            }
        }
    }
    printf("%lld\n",(ll)f[k+1][n][m][0]*fac[n]%mod*fac[m]%mod);
    return 0;
}

Measured memory_bytes: 8960
#B問題
W,H,N = map(int,input().split())

R = 0
L = W
U = 0
D = H
for i in range(N):
    x,y,a = map(int,input().split())
    
    if a == 1:
        R = max(R,x)
    if a == 2:
        L = min(L,x)
    if a == 3:
        U = max(U,y)
    if a == 4:
        D = min(D,y)
        
dw = max(0,L-R)
dh = max(0,D-U)
print(dw*dh)
    

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct e{int from,to,cost;}e;
int N,M,p[105],R,i,j,t,mx,mn;
e E[5000];
void in()
{
	int i;
	for(i=0;i<105;i++)p[i]=i;
}

int pa(int n)
{
	return p[n]==n?n:pa(p[n]);
}

int sa(int a,int b)
{
	return pa(a)==pa(b);
}

int co(const void *a,const void *b)
{
	e *x=(e*)a,*y=(e*)b;
	return x->cost<y->cost;
}

int main()
{
	for(;scanf("%d%d",&N,&M),N|M;)
	{
		memset(E,0,sizeof(E));
		for(i=0;i<M;i++)
		{
			scanf("%d%d%d",&E[i].from,&E[i].to,&E[i].cost);
		}
		qsort(E,M,sizeof(e),co);
		R=1<<25;
		for(i=0;i<M;i++)
		{
			in();
			mx=-(1<<25),mn=(1<<25);
			for(j=i;j<M;j++)
			{
				if(!sa(E[j].from,E[j].to))
				{
					mx=mx<E[j].cost?E[j].cost:mx;
					mn=mn>E[j].cost?E[j].cost:mn;
					p[pa(E[j].from)]=pa(E[j].to);
				}
			}
			for(j=1;j<=N;j++)
				if(pa(j)!=pa(1))
					break;
			if(j==N+1)
				R=R<mx-mn?R:mx-mn;
		}
		printf("%d\n",R==1<<25?-1:R);
	}
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi x(n),y(n);
  vi xori(n),yori(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    xori[i]=x[i];
    yori[i]=y[i];
  }
  sort(ALL(x));
  sort(ALL(y));
  ll ans=llINF*5;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int ii=0;ii<n;ii++){
	for(int jj=ii+1;jj<n;jj++){
	  ll lex=x[i],rix=x[j];
	  ll ley=y[ii],riy=y[jj];
	  ll cnt=0;
	  for(int po=0;po<n;po++){
	    if(lex<=xori[po]&&xori[po]<=rix&&ley<=yori[po]&&yori[po]<=riy)
	      cnt++;
	  }
	  if(cnt>=k)
	    ans=min(ans,(rix-lex)*(riy-ley));
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<queue>
using namespace std;
const int N=1000010;
vector<int>e[N],f[N];
int n,m;
struct edge
{
	int x,y,c;
	bool operator < (const edge a)const
	{
		return c<a.c;
	}
}q[N];
int col[N],now[N],cnt,fi=N,la=N;
int qu[N<<1];
int dis[N];
void newnode(int x,int c)
{
	now[x]=++cnt; col[x]=c;
	e[x].push_back(cnt); f[x].push_back(1);
	e[cnt].push_back(x); f[cnt].push_back(0);
}
void bfs()
{
	memset(dis,0,sizeof(dis));
	qu[fi]=1; 
	while(fi<=la)
	{
		int x=qu[fi++];//printf("%d\n",x);
		for(int i=0;i<e[x].size();i++)
			if((!dis[e[x][i]] || dis[e[x][i]]>dis[x]+f[x][i]) && e[x][i]!=1)
			{
				dis[e[x][i]]=dis[x]+f[x][i];
				if(f[x][i]==0)
					qu[--fi]=e[x][i];
				else
					qu[++la]=e[x][i];
			}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d%d",&q[i].x,&q[i].y,&q[i].c);
	sort(q+1,q+m+1);
	cnt=n;
	for(int i=1;i<=m;i++)
	{
		int x=q[i].x,y=q[i].y,c=q[i].c;
		if(col[x]!=c)
			newnode(x,c);
		if(col[y]!=c)
			newnode(y,c);
		e[now[x]].push_back(now[y]);
		f[now[x]].push_back(0);
		e[now[y]].push_back(now[x]);
		f[now[y]].push_back(0);
	}
	bfs();
	if(dis[n])
		printf("%d\n",dis[n]);
	else
		printf("-1\n");
	return 0;
}


Measured memory_bytes: 96512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int C=A%500;
  
  if (C==0){
    cout<<"Yes"<<endl;
  }
  else if (C!=0){
    if (B>=C){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  }

Measured memory_bytes: 3500
#include<iostream>
using namespace std;
int a,b,c,x,ans;
int main ()
{
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a and 500*i<=x;++i) for(int j=0;j<=b and 100*j+500*i<=x;++j) for(int k=0;k<=c and 50*k+100*j+500*i<=x;++k) if(500*i+100*j+50*k==x) ans++;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int n, p;

int main() {
	while (cin>>n>>p, n|p){
		int wan = p;//椀に石を入れる
		int ans = -1;
		int vl[50] = {0};//町長候補を手ぶらにする
		for (int i = 0; i < 10000000; i++){
			if (wan > 0){//椀に石があるとき
				vl[i%n]++;//手持ちを増やす
				wan--;//椀の石を減らす
				if (vl[i%n] == p){//もし全て持っていたら
					ans = i%n;//町長候補をアンサーに入れる
					break;
				}
			}
			else{//石がないとき
				wan=vl[i%n];//椀に返す
				vl[i%n] = 0;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	int N; cin>>N;
	int num[N];
	for(int i=0; i<N; i++) cin>>num[i];
	sort(num,num+N);

	int series=1;
	int result=0;
	for(int i=1; i<N; i++) {
		if(num[i-1]==num[i]) 
			series++;
		else {
			if(series%2) result++;
			series=1;
		}
	}
	if(series%2) result++;
	cout<<result<<endl;
}


Measured memory_bytes: 640
/**
 * File              : E.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 09.02.2020
 * Last Modified Date: 09.02.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const AL = 26;

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size()+1, vector<int>(AL, s.size()));
    for (int i = (int)s.size() - 1; i >= 0; --i) {
        for (int j = 0; j < AL; j++) {
            dp[i][j] = dp[i + 1][j];
        }
        dp[i][s[i] - 'a'] = i;
    }
    ll ans = 0;
    int j = 0;
    while (j < (int)t.size()) {
        int pos = 0;
        if (pos == 0 && dp[pos][t[j] - 'a'] == (int)s.size()) {
            cout << -1;
            return 0;
        }
        while (j < (int)t.size() && pos != (int)s.size()) {
            pos = dp[pos][t[j] - 'a'];
            if (pos != (int)s.size()) {
                j++;
                pos++;
            }
        }
        ans += pos;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 13696
a,b,c,d,e,f = map(int, input().split())
waters = []
for i in range(31):
    for j in range(31):
        v = 100*a*i + 100*b*j
        if v <= f and v != 0:
            waters.append(v)

waters = list(set(waters))
ans_vol, ans_sug = waters[0], 0
for w in waters:
    rem = f - w
    max_s = e*w//100
    max_s = min(rem, max_s)
    for c_cnt in range(max_s//c+1):
        cs = c_cnt*c
        rem_d = max_s - cs
        d_cnt = rem_d//d
        ds = d_cnt*d
        sug = cs+ds
        vol = sug + w
        if ans_sug*vol < sug*ans_vol:
            ans_vol, ans_sug = vol, sug

print(ans_vol, ans_sug)
        

Measured memory_bytes: 63760
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;
const int MAX = 100001;
int v[MAX][3];
int dp[MAX][3];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n;i++)
	for (int j = 0; j < 3; j++)
	{
		cin >> v[i][j];
		dp[i][j] = v[i][j];
	}

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3;k++)
			if (k == j)	continue;
			else
				dp[i][j] = max(dp[i][j], v[i][j] + dp[i - 1][k]);
		}
	}

	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#define rep(i,n) for(int i=0; i<n; ++i)

int min(int a,int b){
  int temp;
  if(a>b)return b;
  if(a<=b)return a;
}


int main(){

  int d,g;
  scanf("%d%d",&d,&g);

  int p[11];
  int c[11];

  rep(i,d){
    scanf("%d",&p[i]);
    scanf("%d",&c[i]);
  }

  int ans = 1000000000;
  for(int bit=0; bit < (1<<d) ; ++bit){
    int sum = 0, num = 0, rest_max = -1;
    for(int i=0; i < d ; i++){
      if(bit >> i & 1){
        sum += 100 * (i+1) * p[i] + c[i];
        num += p[i];
      }else{
        rest_max = i;
      }
    }
    if(sum < g){
      int s1 = 100 * (rest_max + 1);
      int need = (g - sum + s1 -1) / s1;
      if(need >= p[rest_max]){
        continue;
      }
      num += need;
    }
    ans = min(ans,num);  
  }

  printf("%d",ans);


  return 0;
}


Measured memory_bytes: 128
h, w = STDIN.gets.split.map(&:to_i)
c = h.times.map { STDIN.gets.split.map(&:to_i) }
dp = (h+1).times.map { (w+1).times.map { 0 } } 

(1..h).each do |i| 
  (1..w).each do |j| 
    if c[i-1][j-1] == 0
      dp[i][j] = [dp[i-1][j-1], dp[i-1][j], dp[i][j-1]].min + 1 
    else
      dp[i][j] = 0 
    end 
  end 
end

puts dp.flatten.max**2

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


#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ll long long


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

    int a, b;
    cin >> a >> b;

    cout << (a <= 8 and b <= 8 ? "Yay!\n" : ":(\n");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100005];
ll T[100005];
ll A[100005];
int N;

const ll MOD = 1000000007LL;
ll mult( ll a, ll b ){
  return (a * b)%MOD;
}

bool check(){
  for(int i=0;i<N;i++){
    if( i == N-1 || A[i] != A[i+1] ){
      if( A[i] > T[i] ) return false;
    }
  }
  for(int i=N-1;i>-1;i--){
    if( i == 0 || T[i] != T[i-1] )
      if( T[i] > A[i] ) return false;
  }
  return true;
}
int main(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> T[i];
  for(int i=0;i<N;i++) cin >> A[i];

  if( !check() ) {
    cout << 0 << endl;
    return 0;
  }  
  if( N < 3 ) {
    cout << 1 << endl;
    return 0;
  }
  
  dp[0] = 1;
  for(int i=1;i<N-1;i++){
    if( T[i] != T[i-1] || A[i] != A[i+1] ){
      dp[i] = dp[i-1];
    } else {
      ll mini = min( T[i],A[i] );      
      dp[i] = mult( dp[i-1], mini );
    }
  }
  cout << dp[N-2] << endl;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <map>
#include <utility>

using namespace std;

int main(void) {
    int n,q;
    string s;
    cin >> n >> q >> s;

    vector<int> cnt(n,0);
    for (int i=1; i<n; i++) {
        cnt[i] = cnt[i-1];
        if (s[i-1] == 'A' && s[i] == 'C') cnt[i]++;
    }

    for (int i=0; i<q; i++) {
        int l,r;
        cin >> l >> r;
        cout << cnt[r-1] - cnt[l-1] << endl;
    }
}


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

int main() {
    int n;
    cin >> n;
    int R[200000];
    for (int i = 0; i < n; i++)
        cin >> R[i];
    int maximum = -2000000000;
    int minimum = R[0];
    for(int i = 1; i < n; i++)
    {
        maximum = max(maximum, R[i] - minimum);
        minimum = min(minimum, R[i]);
    }
    cout << maximum << endl;
    return 0;
}



Measured memory_bytes: 3872
#pragma GCC optimize(2) 
#include<bits/stdc++.h>
#define rg register
#define il inline
using namespace std;
typedef long long ll;
const int mod=1e9+7,O=1000010;
struct Data{
	int fa,id;
	il void init(int x){fa=x;id=-1;}
}a[O];
il int gi(){
	rg int o=0,fl=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')fl=-1,ch=getchar();
	while(isdigit(ch))o=o*10+ch-'0',ch=getchar();
	return fl*o;
}
int n,m,k,cnt,dis[O];
vector<pair<int,int> >g1[O];
vector<int>g2[O];
queue<int>Q;
il int find(int x){return x==a[x].fa?x:a[x].fa=find(a[x].fa);}
int main(){
	cnt=n=gi(),m=gi();
	for(int i=1;i<=m;++i){
		int a=gi(),b=gi(),c=gi();
		g1[c].push_back(make_pair(a,b));
		k=max(k,c);
	}
	for(int s=1;s<=k;++s){
		if(g1[s].empty())continue;
		for(unsigned int i=0;i<g1[s].size();++i){
			a[g1[s][i].first].init(g1[s][i].first);
			a[g1[s][i].second].init(g1[s][i].second);
		}
		for(unsigned int i=0;i<g1[s].size();++i){
			int X=find(g1[s][i].first),Y=find(g1[s][i].second);
			if(X!=Y)a[Y].fa=X;
		}
		for(unsigned int i=0;i<g1[s].size();++i){
			int p1=g1[s][i].first,p2=g1[s][i].second;
			int x=find(p1);
			if(a[x].id==-1)a[x].id=++cnt;
			g2[a[x].id].push_back(p1);
			g2[p1].push_back(a[x].id);
			x=find(p2);
			if(a[x].id==-1)a[x].id=++cnt;
			g2[a[x].id].push_back(p2);
			g2[p2].push_back(a[x].id);
		}
	}
	memset(dis,-1,sizeof(dis));
	Q.push(1);dis[1]=0;
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(unsigned int i=0;i<g2[u].size();++i){
			int v=g2[u][i];
			if(dis[v]==-1){
				dis[v]=dis[u]+1;
				Q.push(v);
			}
		}
	}
	if (dis[n]==-1)puts("-1");
	else printf("%d\n",dis[n]>>1);
	return 0;
}


Measured memory_bytes: 69504
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>

using namespace std;

int n[4];
int num;

bool isUsed[4];

bool doSearch(int d)
{
	if (d == 4)
	{
		if (num == 1974)
			return true;
		else
			return false;
	}
	
	for (int i = 0 ; i < 4 ; i++)
	{
		if (isUsed[i] == false)
		{
			isUsed[i] = true;
			num = num * 10 + n[i];
			if (doSearch(d + 1) == true)
				return true;
			num = num / 10;
			isUsed[i] = false;
		}
	}
	
	return false;
}

int main()
{
	for (int i = 0 ; i < 4 ; i++)
	{
		scanf("%d", &(n[i]));		
		isUsed[i] = false;
	}
		
	num = 0;
	if (doSearch(0))
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	
	
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;
typedef vector<ll> vll;
ll mod = 1000000007;
// ll gcd(ll a, ll b){if (b==0){return a;}return gcd(b, a%b);}
// for (ll i=0;i<n;i++) {
// sort(.begin(),.end());
int main(){
  ll n,m;
  cin >> n >> m;
  vector<bool> no(n+1);
  for (ll i = 0; i < m; i++) {
    ll a;
    cin >> a;
    no[a] = true;
  }
  
  vll dp(n+1);
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (no[i]) continue;
    for (int j = 1; j <= 2; j++) {
      if (i - j >= 0 && !no[i - j]) {
        dp[i] += dp[i - j];
      }
    }
    dp[i] %= mod;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(src,dst)    for(int i=src; i<dst;  i++)
#define rep2(src,dst)   for(int j=src; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 1000000007 //1e9+7
#define PI  acos(-1)
#define ll long long
template<typename T> inline void cMin(T* a, T* b)  {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  div(T a, T b)     {return ((a+b-1)/b);}
template<typename T> inline bool eoVerify(T a)     {return (!(a&1)? true : false );}

int main(){
    int n; cin >> n;
    ll ans=0;
    vector<ll> a(n);
    rep(0,n) cin >> a[i];

    rep(1,n){
        if(a[i] < a[i-1]){
            ans += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4816
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N=0,Q=0,t=0,x=0,d=0;
    int flag=0;


    vector<int> apple(1005);
    vector<int> capa(1005);


    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>capa[i];
    }

    cin>>Q;

    for(int i=0;i<Q;i++){
        cin>>t>>x>>d;

        if(t==1){
            apple[x]+=d;
            if(apple[x]>capa[x]){
                if(flag==0)flag=x;
            }else{
                 
            }
        }else{
            apple[x]-=d; 
            if(apple[x]<0){
                if(0==flag)flag=x;             
            }else{
            }
        }
    }

        cout<<flag<<endl;

    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(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 chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans =2 * (n / 11);
    if(n % 11 > 0 && n % 11 <= 6) ans++;
    else if(n % 11 > 6 && n % 11 < 11) ans += 2;
    cout << ans << endl;
}

Measured memory_bytes: 256