akhauriyash/Code-Regression huggingface dataset:
#if 0
AOJ??????accepted??????????????????
???????????????60??????????????§?????????

pair???????????????????????¨
????????¨?????????pair?????????????????????????????¨?????????????????????????????????
#endif

#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int P[10010];
void init(int N){//?????????
  for (int i=0; i<=N; ++i)
    P[i]=i;
}

int root(int a){//a???root????±???????
  if(P[a]==a)
    return a;
  return (P[a]=root(P[a]));
}

bool is_same_set(int a,int b){//??????set?????????
  return root(a)==root(b);
}

void unite(int a,int b){
  P[root(a)]=root(b);
}

int main(){
  int N;
  cin>>N;
  int A[N][N];
  
  for(int i=0; i<N;i++){//????????????
    for(int j=0;j<N;j++){
      cin>>A[j][i];
    }
  }

  int M = 0; // ????????????????????°
  int num=N*N;
  int cost[num];
  int src[num],dst[num];
  for (int r=0; r<N;r++){
    for (int c=0; c<r;c++){
      if (A[r][c] > -1) {
	cost[M] = A[r][c];
	src[M] = r;
	dst[M] = c;
	M += 1;
      }
    }
  }

  pair<int,int> edge[100000+10];//?§??????????????????¢????????????
  for(int i=0; i<M;i++){
    edge[i]=make_pair(cost[i],i);
  }
  sort(edge,edge+M);

  int edges[M][3];
  for(int i=0; i<M;i++){//?????????????????????
    edges[i][0]=edge[i].first;
    edges[i][1]=src[edge[i].second];
    edges[i][2]=dst[edge[i].second];
  }
  /*
  check!
  for(int i=0; i<M;i++){
    cout<<"news cost="<<edges[i][0]<<" ,"<<edges[i][1]<<"-"<<edges[i][2]<<endl;
  }
  */




  init(N);
  int sum=0;
  for(int i=0; i<M;i++){//???????????????????????????
    if(is_same_set(edges[i][1],edges[i][2])==0){
      unite(edges[i][1],edges[i][2]);
      sum=sum+edges[i][0];
    }
  }
    cout<<sum<<endl;
}

Measured memory_bytes: 3940
#include <algorithm>
#include <cstdio>
#include <vector>

int main() {
  using namespace std;
  int best = 0x3f3f3f3f, n, m, x;

  scanf("%d%d%d", &n, &m, &x);
  vector<int> cost(n);
  vector<vector<int> > addition(n, vector<int>(m));

  for (int i = 0; i < n; ++i) {
    scanf("%d", &cost[i]);
    for (int j = 0; j < m; ++j) scanf("%d", &addition[i][j]);
  }

  for (int i = 0, e = 1 << n; i < e; ++i) {
    [&](int v) {
      int cur = 0;
      vector<int> ability(m);
      for (int i = 0; i < n; ++i)
        if (v >> i & 1) {
          cur += cost[i];
          if (cur >= best) return;
          for (int j = 0; j < m; ++j) ability[j] += addition[i][j];
        }
      for (int i = 0; i < m; ++i)
        if (ability[i] < x) return;
      best = min(cur, best);
    }(i);
  }

  printf("%d\n", best == 0x3f3f3f3f ? -1 : best);
}

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

lst = [0] * 8
s = 0

for i in a:
    if i >= 3200:
        s += 1
    else:
        i //= 400
        lst[i] += 1

colour = 0
for i in lst:
    if i >= 1:
        colour += 1

m = max(1, colour)
M = colour + s

print(m, M)


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

int main(){
	int E,Y;
	cin >> E >> Y;

	switch(E){
	case 0:
		if(1868<=Y&&Y<=1911){
			cout << 'M' << Y-1867 << endl;
		}else if(1912<=Y&&Y<=1925){
			cout << 'T' << Y-1911 << endl;
		}else if(1926<=Y&&Y<=1988){
			cout << 'S' << Y-1925 << endl;
		}else if(1989<=Y&&Y<=2016){
			cout << 'H' << Y-1988 << endl;
		}
		break;
	case 1:
		cout << Y+1867 << endl;
		break;
	case 2:
		cout << Y+1911 << endl;
		break;
	case 3:
		cout << Y+1925 << endl;
		break;
	case 4:
		cout << Y+1988 << endl;
		break;
	}	

	return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<vector>

using namespace std;

int main(void) {

	/*
	double x[3] = { 0,0,0 };
	double y[3] = { 0,0,0 };
	double xp = 0, yp = 0;
	int flag[3] = { 0,0,0 };

	while (cin >> x[0]>> y[0]>> x[1]>> y[1]>> x[2]>> y[2]>> xp>> yp) {
		for (int i = 0; i < 3; i++) {
			int temp1 = (i + 1) % 3;
			int temp2 = (i + 2) % 3;
			double checkI = (y[temp1] - y[i]) * (x[temp2] - x[i]) - (x[temp1] - x[i]) * (y[temp2] - y[i]);
			double checkP = (y[temp1] - y[i]) * (xp - x[i]) - (x[temp1] - x[i]) * (yp - y[i]);

			if (checkI * checkP > 0) {
				flag[i] = 1;
			}
		}
		if (flag[0] == 1 && flag[1] == 1 && flag[2] == 1) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		flag[0] = 0;
		flag[1] = 0;
		flag[2] = 0;
	}
	*/
	int input_num;
	vector<int> train_num;
	while (cin >> input_num) {
		if (input_num == 0) {
			cout << train_num.back() << endl;
			train_num.pop_back();
		}
		else if (input_num >= 1 && input_num <= 10) {
			train_num.push_back(input_num);
		}
	}

	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	int K; scanf("%d", &K);

	auto dp = make_v<int>(s.size() + 1, 2, K + 2); dp[0][0][0] = 1;
	for(int i = 0; i < s.size(); i++) {
		const int D = s[i] - '0';

		for(int j = 0; j < 2; j++) {
			for(int d = 0; d <= (j ? 9 : D); d++) {
				for(int k = 0; k < K + 1; k++) {
					dp[i + 1][j | (d < D)][k + !!d] += dp[i][j][k];
				}
			}
		}
	}
	
	printf("%lld\n", dp[s.size()][0][K] + dp[s.size()][1][K]);
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz,b;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        b.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        b[x]+=b[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

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

int H,W;
string S[444];

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>S[i];

    UnionFindTree uf(H*W);
    rep(i,H)rep(j,W)uf.b[i*W+j]=S[i][j]=='#';
    rep(i,H)rep(j,W){
        rep(d,4){
            int ny=i+dy[d];
            int nx=j+dx[d];
            if(ny<0||ny>=H||nx<0||nx>=W||S[i][j]==S[ny][nx])continue;
            uf.unite(i*W+j,ny*W+nx);
        }
    }

    int ans=0;
    rep(i,H*W)if(uf.find(i)==i)ans+=uf.b[uf.find(i)]*(uf.sz[uf.find(i)]-uf.b[uf.find(i)]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    
    int array[n];
    for (int i=0; i<n; i++) scanf("%d", &array[i]);
    
    for  (int i=n-1; i>0; i--) printf("%d ", array[i]);
    printf("%d\n", array[0]);
}


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

int N, T;

long long int calc(int x) {
    long long int t = 1LL;
    for (int i = 0; i < x; i++) {
        t *= N;
        if (t * T > 1e9) break;
    }

    return t * T;
}

int main() {
    cin >> N >> T;
    string str;
    cin >> str;

    str+="+";

    vector<string> vs;
    for (int i = 0, pre = -1; i < (int)str.size(); i++) {
        if (str[i] == '+' ) {
            vs.push_back(string(str.begin() + pre + 1, str.begin() + i));
            pre = i;
        }
    }

    long long int sum = 0;
    for (int i = 0; i < (int)vs.size(); i++) {
        sum += calc(vs[i][2] - '0');
        if (sum > 1e9) break;
    }

    if (sum <= 1e9) {
        cout << sum << endl;
    }
    else {
        cout << "TLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <algorithm>
using namespace std;
static const int INFTY = (1 << 29);
static const int MAXN = 1000000;
static const int LEN = 182;
int T[MAXN+1], T2[MAXN+1];

int main()
{
    int arr[LEN];
    int i = 0, sum = 0;
    while(sum <= MAXN) {
        arr[i] = sum;
        i++;
        sum = i*(i+1)*(i+2) / 6;
    }
    int N;
    for (int i = 0; i <= MAXN; i++) T[i] = T2[i] = INFTY;
    T[0] = T2[0] = 0;
    T[1] = T2[1] = 1;

    for(int i = 2; i < MAXN; i++){
       for(int j = 1; arr[j] <= i; j++){
            T[i] = min(T[i], T[i-arr[j]]+1);
            if(arr[j] % 2 != 0){
                T2[i] = min(T2[i], T2[i-arr[j]]+1);
            }
        }
    }

    for (; ; ) {
        scanf("%d", &N);
        if (N == 0) break;
        printf("%d %d\n", T[N], T2[N]);
    }

    return 0;
}



Measured memory_bytes: 10500
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
#include <bits/stdc++.h>
int main(){
  ll a,b,aa,aaa,bbb,bb,x;
  std::cin >> a>>b>>x;
  aa=a/x;
  aaa=a%x;
  bb=b/x;
  bbb=b%x;
  ll ans=bb-aa;
  if(aaa==0)ans++;
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int i;
  int N;
  rd(N);
  for(i=(1);i<(10);i++){
    int j;
    for(j=(1);j<(10);j++){
      if(i*j==N){
        wt_L("Yes");
        wt_L('\n');
        return 0;
      }
    }
  }
  wt_L("No");
  wt_L('\n');
  return 0;
}
// cLay varsion 20191027-1

// --- original code ---
// {
//   int N;
//   rd(N);
//   rep(i,1,10) rep(j,1,10) if(i*j==N) wt("Yes"), return 0;
//   wt("No");
// }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)


int memo[10000001];

int main(){

	int N;
	cin>>N;
	vector<int> arr(N);
	REP(i,N){
		cin>>arr[i];

		memo[arr[i]] = 1;
	}


	sort(arr.begin(),arr.end());
	int tmp = 0;
	REP(i,N){
		if(tmp == arr[i]){
			memo[arr[i]] = 0;
			continue;
		}
		int val = arr[i];

		while(val <= arr[N-1]){
			val += arr[i];
			memo[val] = 0;
		}
		tmp = arr[i];
	}

	int ans = 0;
	REP(i,N){
		if(memo[arr[i]] == 1)ans++;
	}
	cout<<ans<<endl;

	return 0;

}



Measured memory_bytes: 11792
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
int vector_finder(vector<int> vec, int number) {        //数値判定
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
int a_1(int a) {										//素数判定
	int x = 0;
	for (int i = 2; i < a; i++) {
		if (a % i == 0)x++;
	}
	if (x == 0) {
		return 0;//素数であるとき
	}
	if (x != 0) {
		return 1;//素数でないとき
	}
}
int gcd(int a, int b) {
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
int main() {
	int ans, x;
	cin >> x;
	int a = lcm(360, x);
	cout << a / x << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
using namespace std;
long long n,k,a0,a1,ans;
int main()
{
	cin>>n>>k;
	ans=0;
	/*
	a1=0;
	for(int i=1;i<=n;i++)if(!(i%k))a1++;
	//*/
	///*
	a1=n/k;
	//*/
	ans+=(a1*a1*a1);
	if(!(k&1))
	{
		a0=(k>>1);
		a1=0;
		///*
		for(int i=0;i<=(n-a0);i++)if(!(i%k))a1++;
		//*/
		/*
		a1=((n-a0)/k)+1;
		//*/
		ans+=(a1*a1*a1);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    string S;
    int cp, cm;
    cin >> S;
    cp = count(S.begin(), S.end(), '+');
    cm = count(S.begin(), S.end(), '-');
    cout << cp - cm << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e11;
const long double PI = (acos(-1));

int N, M, Q;
vector<int>a, b, c, d;
int ans = 0;

void dfs(vector<int>A) {
	if (A.size() == N + 1) {
		int score = 0;
		rep(i, Q)if (A[b[i]] - A[a[i]] == c[i])score += d[i];
		chmax(ans, score);
		return;
	}

	int num = A.back();
	for (int i = num; i <= M; i++) {
		vector<int>tmp = A;
		tmp.push_back(i);
		dfs(tmp);
	}
}

signed main() {
	cin >> N >> M >> Q;
	a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
	rep(i, Q)cin >> a[i] >> b[i] >> c[i] >> d[i];
	vector<int>v(1, 1);
	dfs(v);
	cout << ans;
}

Measured memory_bytes: 3604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class ELogs {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n,k;
        in >> n >> k;

        vector<double> a(n);
        double ma=0.;
        rep(i,n){
            in >> a[i];
            ma = max(a[i],ma);
        }
        double l=0.,r=ma;
        out << setprecision(16);
        while(r-l>1e-6){
            double t = (r+l)/2.;
            int c=0;
            rep(i,n){
                if(a[i]>t){
//                    c+=ceil(a[i]/t);
                    c+=int(a[i]/t);
                }
            }
            if(c<=k){
                r=t;
            }else{
                l=t;
            }
        }
        out << ceil((r+l)/2.) << endl;
	}
};


int main() {
	ELogs solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int x, a, b;
    cin >> x >> a >> b;

    if ( abs(x - a) < abs(x - b) ) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
from collections import Counter
N, M = map(int, input().split())
A = tuple(map(int, input().split()))

cumA = [0] * (N + 1)
for i in range(N):
    cumA[i + 1] = A[i] + cumA[i]
    cumA[i + 1] %= M

c = Counter(cumA)
ans = 0
for k, v in c.items():
    ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 16600
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
 ll n;
  cin >> n;
 vvll G(n);
 rep(i,0,n-1){
  ll a,b;
   cin >> a >> b;
   --a;
   --b;
   G[a].eb(b);
   G[b].eb(a);
 }
 vll c(n),deg(n);
 queue<ll> que; 
  rep(i,0,n) {
    cin >> c[i];
    deg[i]=G[i].size();
    if(deg[i]==1) que.push(i); 
  }
  sort(all(c));
  
  ll res=0;
  vll ans(n);
  
  rep(i,0,n){
    ll v=que.front();
    que.pop();
    ans[v]=c[i];
    if(i+1<n) res+=c[i];
    rep(j,0,G[v].size()){
     ll t=G[v][j];
     deg[t]--;
     if(deg[t]==1) que.push(t);  
    }
  }

  cout << res << endl;
  rep(i,0,n-1) cout << ans[i] << " ";
  cout << ans[n-1] << endl; 
}

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

Measured memory_bytes: 1280
#include <stdio.h>

int main()
{
	int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	int n;
	
	scanf("%d",&n);
	
	printf("%d\n",a[n-1]);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
#define PI 3.1415927
int main()
{
	int i,max=0,n,ans=0,x;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x;
		if(x>=max)
		{
			max = x;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3160
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        a: [u64;n],
    }

    let mut ans = 0;

    for i in 0..n {
        if i % 2 == 0 && a[i] % 2 == 1 {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2128
#include<stdio.h>
int main(void) {
	int n, i, c, max;
	scanf("%d", &n);
	int a[n];
	for (i = 0; i<n; i++) {
		scanf("%d", &a[i]);
	}
	int b[n];
	for (i = 0; i < n; i++) {
		b[i] = 0;
	}
	for (i = 0; i<n; i++) {
		if (a[i] % 2 == 0) {
			c = a[i];
			do {
				c = c / 2;
				b[i]++;
			} while (c % 2 == 0);
		}
		else {
			b[i] = 0;
		}
	}
	max = b[0];
	for (i = 0; i<n; i++) {
		if (max>b[i]) {
			max = b[i];
		}
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 128
#import queue
import heapq
inf = float('inf')
N = int(input())
paths = [{} for i in range(N+1)]
for i in range(N-1):
    s,t = list(map(int, input().split()))
    paths[s][t] = 1
    paths[t][s] = 1

def dijkstra(start, nodes, N):
    cost = [inf] * (N + 1)
    cost[start] = 0
    q = []
    heapq.heappush(q, (0, start))
#    q.put((0, start))
    while q: #q.empty() == False:
        w, x = heapq.heappop(q)
        if cost[x] < w: continue
        for y in nodes[x]:
            if cost[x] + paths[x][y] < cost[y]:
                cost[y] = cost[x] + paths[x][y]
#                q.put((cost[y], y))
                heapq.heappush(q, (cost[y], y))
    return cost

# それぞれの位置からの到達コストを調べている
score_f = dijkstra(1, paths, N)
score_s = dijkstra(N, paths, N)

score = 0
for i in range(1, N+1):
    if score_f[i] > score_s[i]:
        score -= 1
    else:
        score += 1

if score > 0:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 47936
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[100100];

int main() {
	ll n,q;
	cin>>n>>q;
	string s1;
	cin>>s1;
	string s = "X";
	s += s1;
	s += "X";
	rep(i,0,s.sz-1){
		if(s[i]=='A'&&s[i+1]=='C')d[i] = 1;
	}
	rep(i,1,s.sz){
		d[i] += d[i-1];
	}
	rep(i,0,q){
		ll a,b;
		cin>>a>>b;
		ll ans = d[b-1]-d[a-1];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

const int INF = 1LL << 60;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class DirectedGraph {
    struct edge {
        int to;
        int cost;
    };

public:
    int V;
    vector<vector<edge>> G;

    DirectedGraph(int v) : G(v), V(v) {}

    void add_edge(int u, int v, int cost) {
        G[u].push_back({v, cost});
    }

    // O(E * logV)
    vector<int> dijkstra(int s) {
        vector<int> d(V, INF);
        d[s] = 0;

        priority_queue<P, vector<P>, greater<>> que;
        que.push({0, s});

        while (!que.empty()) {
            P  p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;

            for (edge e : G[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push({d[e.to], e.to});
                }
            }
        }

        return move(d);
    }
};

signed main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;

    DirectedGraph g1 = DirectedGraph(n);
    DirectedGraph g2 = DirectedGraph(n);

    for (int i = 0; i < m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;

        g1.add_edge(u, v, a);
        g1.add_edge(v, u, a);
        g2.add_edge(u, v, b);
        g2.add_edge(v, u, b);
    }

    vector<int> d1 = g1.dijkstra(s);
    vector<int> d2 = g2.dijkstra(t);

    int ret = INF;
    int base = (int)pow(10, 15);
    vector<int> ans;
    for (int i = n - 1; i >= 0; i--) {
        ret = min(ret, d1[i] + d2[i]);
        ans.push_back(base - ret);
    }

    for (int i = n - 1; i >= 0; i--) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 19964
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n;
	cin >> n;
	map<string, int>mpp;
	string prev = "";
	int len = 0;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (!i)
		{
			mpp[s]++;
			prev = s;
			len = (int)prev.size();
		}
		else
		{
			if (mpp[s])return cout << "No\n", 0;
			else
			{
				if (s[0] != prev[len - 1])
					return cout << "No\n", 0;
				else
				{
					mpp[s]++;
					prev = s;
					len = (int)prev.size();
				}
			}
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	H, N := sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	sum := 0
	for i := 0; i < N; i++ {
		sum += A[i]
	}

	if H <= sum {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
	wtr.Flush()
}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int x = min(a, k);
	k = k - x;
	if (k == 0)
	{
		cout << x;
		return 0;
	}

	int y = min(b, k);
	k = k - y;
	if (k == 0)
	{
		cout << x;
		return 0;
	}

	int z = min(c, k);
	cout << x - z;
}

Measured memory_bytes: 3620
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int r,l;
    r=c+d;
    l=a+b;
    cout<<(r==l?("Balanced"):(r<l)?("Left"):("Right"))<<endl;

return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, D, L, R, K, X;
ll A;
ll B;
ll ans;
string S;
ll cost[10][10];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	cin >> H >> W;
	rep(i, 0, 10)rep(j, 0, 10)cin >> cost[i][j];
	rep(i, 0, 10) {
		rep(j, 0, 10) {
			rep(k, 0, 10) {
				cost[j][k] = min(cost[j][k],cost[j][i] + cost[i][k]);
			}
		}
	}
	rep(i, 0, H) {
		rep(j, 0, W) {
			ll A;
			cin >> A;
			if (A == -1)continue;
			ans += cost[A][1];
		}
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
if w == 1:
    print(1)
    exit()
mod = 10 ** 9 + 7

def fibo(w):
    if w == 0:
        return 1
    if w == 1:
        return 1
    elif w == 2:
        return 2
    else:
        return fibo(w - 1) + fibo(w - 2)

dp = []
for i in range(w + 1):
    dp.append([])
for i in range(w + 1):
    for j in range(h + 1):
        dp[i].append(0)
for i in range(w + 1):
    if i == 1:
        dp[i][1] = fibo(w - 1)
    elif i == 2:
        dp[i][1] = fibo(w) - fibo(w - 1)
for j in range(2, h + 1):
    for i in range(1, w + 1):
        if i == 1:
            dp[i][j] = (dp[i][j - 1] * fibo(w - 1) + dp[i + 1][j - 1] * (fibo(w) - fibo(w - 1))) % mod
        elif i == w:
            dp[i][j] = (dp[i - 1][j - 1] * (fibo(w) - fibo(w - 1)) + dp[i][j - 1] * fibo(w - 1)) % mod
        else:
            dp[i][j] = (dp[i - 1][j - 1] * (fibo(i - 2) * fibo(w - i)) + dp[i][j - 1] * (fibo(i - 1) * fibo(w - i)) + dp[i + 1][j - 1] * (fibo(i - 1) * fibo(w - i - 1))) % mod
print(dp[k][h] % mod)

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

bool nibu(vector<vector<int>> &G) {
    vector<int> color(G.size(), -1);
    color[0] = 0;
    function<bool(int)> dfs = [&](int cur) {
        bool res = true;
        for(auto &to : G[cur]) {
            if(color[to] != -1) {
                if(color[cur] == color[to]) return false;
            } else {
                color[to] = color[cur] ^ 1;
                res &= dfs(to);
            }
        }
        return res;
    };
    return dfs(0);
}

int solve() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i, 0, N) rep(j, 0, N) {
        char a; cin >> a;
        if(a == '1') G[i].push_back(j);
    }
    if(!nibu(G)) return -1;
    int ans = 0;
    rep(s, 0, N) {
        queue<int> Q; Q.push(s);
        vector<int> dist(N, -1); dist[s] = 0;
        while(!Q.empty()) {
            int cur = Q.front(); Q.pop();
            for(auto &to : G[cur]) {
                if(dist[to] != -1) continue;
                Q.push(to);
                dist[to] = dist[cur] + 1;
                ans = max(ans, dist[to]);
            }
        }
    }
    return ans + 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << solve() << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int t[100010], a[100010];

ll solve() {
    ll dt[n], da[n];
    dt[0] = -t[0];
    for (int i = 1; i < n; i++) {
        if (t[i-1] < t[i]) {
            dt[i] = -t[i];
        } else {
            dt[i] = t[i];
        }
    }
    da[n-1] = -a[n-1];
    for (int i = n-2; i >= 0; i--) {
        if (a[i] > a[i+1]) {
            da[i] = -a[i];
        } else {
            da[i] = a[i];
        }
    }

    ll res = 1;
    for (int i = 0; i < n; i++) {
        if (dt[i] < 0 && da[i] < 0) {
            if (dt[i] != da[i]) return 0;
        } else if (dt[i] < 0) {
            if (-dt[i] > da[i]) return 0;
        } else if (da[i] < 0) {
            if (-da[i] > dt[i]) return 0;
        } else {
            res = (res * min(dt[i], da[i])) % mod;
        }
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> t[i];
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}

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

using namespace std;

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

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969ll
#define MAXN 1013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, M;
bitset<MAXN> grid[MAXN];
ll dp[MAXN][MAXN];

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	FOR(i, 0, N)
	{
		string temps; cin >> temps;
		FOR(j, 0, M)
		{
			grid[i][j] = (temps[j] == '.');
		}
	}
	dp[0][0] = 1;
	FOR(i, 0, N)
	{
		FOR(j, 0, M)
		{
			if (i + 1 < N && grid[i + 1][j])
			{
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= INF;
			}
			if (j + 1 < M && grid[i][j + 1])
			{
				dp[i][j + 1] += dp[i][j];
				dp[i][j + 1] %= INF;
			}
		}
	}
	cout << dp[N - 1][M - 1] << '\n';
	return 0;
}


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

int main() {

	int a, b, c;
   	cin >> a >> b >> c;
  
  if (a + b >= c){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

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

#define N 200123
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define fastio ios::sync_with_stdio(false); cin.tie(0)

int main(){
	fastio;
    int n, pre[101], a, ans = 1000000;
    pre[0] = 0;
    cin >> n;

    for(int i = 1 ; i <= n ; i++){
    	cin >> a;
    	pre[i] = pre[i-1]+a;
    }

    for(int i = 1 ; i < n ;i++)
    	ans = min(ans, abs(pre[n] - 2*pre[i]));
    
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import heapq as hq
mod = 10**9+7
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())

def onon():
    n = onem()

    a = l()

    b = l()

    t = []

    for i in range(n):
        if b[i] != a[i]:
            hq.heappush(t,(-b[i],i))
    co = 0
    while t:
        k = hq.heappop(t)
        k = (-k[0],k[1])
        q,w = divmod(k[0] - a[k[1]], b[(k[1] - 1) % n] + b[(k[1] + 1) % n])
        co += q
        if q == 0:
            return -1
        w = a[k[1]] + w
        b[k[1]] = w
        if b[k[1]] != a[k[1]]:
            hq.heappush(t,(-w,k[1]))
    return co
print(onon())

Measured memory_bytes: 122008
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

string s,t;
cin >> s >> t;

int n = s.size();
rep(i,n){
    rotate(s.rbegin(),s.rbegin()+1,s.rend());
    if(s == t){
        cout << "Yes\n";
        return 0;
    }
}

cout << "No\n";

return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
res = []
for i in range(n):
    for j in range(len(a))[::-1]:
        # print(j)
        if a[j] > j+1:
            print(-1)
            quit()
        elif a[j] == j+1:
            res.append(a[j])
            del a[j]
            break
    # print(a)
for i in range(n)[::-1]:
    print(res[i])



Measured memory_bytes: 39148
def resolve():
    N, K, Q = [int(i) for i in input().split()]
    A = [int(input()) for _ in range(Q)]
    point = [K - Q] * N
    for a in A:
        point[a - 1] += 1
    for p in point:
        if p > 0:
            print("Yes")
        else:
            print("No")


resolve()


Measured memory_bytes: 10500
#include<iostream>
#include<algorithm>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

typedef struct{
    int number;
    int num;
}ARRAY;
bool compare( ARRAY a, ARRAY b);
int main(){
    ULL N,K;
    int i;
    ULL x;
    ARRAY *array;

    cin >> N >> K;
    array = new ARRAY[N];
    for(i=0;i<N;i++){
        cin >> array[i].number >> array[i].num;
    }
    sort(array,array+N,compare);
    x = 0;
    for(i=0;i<N;i++){
        if( x < K && K <= x + array[i].num ){
            cout << array[i].number << endl;
            break;
        }
        x += array[i].num;
        //cout << array[i].number << " " << array[i].num << endl;
    }
    return 0;
}
bool compare( ARRAY a, ARRAY b){
    if( a.number < b.number){
        return true;
    }else{
        return false;
    }
}


Measured memory_bytes: 1024
using System;

namespace atcoder {
	class MainClass {
		public static void Main(){
			int N = int.Parse(Console.ReadLine());
			long[] A = new long[N];
			var input = Console.ReadLine().Split(' ');
			int k = 0;
			foreach (string a in input){
				A[k] = long.Parse(a);
				k++;
			}
			int count = 0;
			bool flag = true;
			while(true){
				for(int i=0;i<N;i++){
					if (A[i]%2==1){
						flag = false;
						break;
					}
					else{
						A[i] /= 2;
					}
				}
				if (flag==false){
					break;
				}
				else{
					count++;
				}
			}
			Console.WriteLine(count);
        }
	}
}


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

MAX_N = max(A)+ 1
cnt = [0] * MAX_N
for a in A:
    for i in range(a, MAX_N, a):
        if cnt[i] <= 2: 
            cnt[i] += 1
            
ans = 0
for a in A:
    if cnt[a] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 32092
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
ll A[200005];

int main() {
  INCANT;
  cin >> N;
  rep(i, N) cin >> A[i];
  if (A[0]!=0) {
    cout << -1 << "\n";
    return 0;
  }
  ll cnt=0;
  rep(i, N) {
    if (i==0) continue;
    if (A[i]> A[i-1]+1) {
      cout << -1 << "\n";
      return 0;
    } else if (A[i]==A[i-1]+1) cnt++;
    else cnt+=A[i];
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>

bool vis[30];
char s[30];
int n;


void a()
{
	for(int i=1;i<=n;i++)
		vis[s[i]-'a']=1;
	printf("%s",s+1);
	for(int i=0;i<26;i++)
		if(!vis[i]){printf("%c\n",'a'+i);break;}
}
void b()
{
	bool flag=0;
	for(int i=n;i;i--)
	{
		int x=s[i]-'a';
		for(int k=1;x+k<26;k++)
			if(vis[x+k])
			{
				for(int j=1;j<i;j++)
					printf("%c",s[j]);
				printf("%c\n",s[i]+k);
				flag=1;
				break;
			}
		vis[x]=1;
		if(flag)break;
	}

	if(!flag)printf("-1\n");
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);

	if(n<26)a();
	else b();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

struct graph_t {
	int n;           // |V|, index begins with 0
	int m;           // |E|
	vector<P> edges; // E
	vector<ll> cost; // cost or distance
	vector<ll> cap;  // capacity
};

class Bellmanford {
private:
	struct node {
		int id; bool done; vi to; vll cost; int from; ll d;
	};
	vector<node> nodes;
	int n, source;
	bool negative_cycle;
public:
	Bellmanford(graph_t G, int start) {
		n = G.n;
		nodes.resize(n);
		Loop(i, n) nodes[i] = { i, false,{},{}, -1, INFLL };
		Loop(i, G.edges.size()) {
			nodes[G.edges[i].first].to.push_back(G.edges[i].second);
			nodes[G.edges[i].first].cost.push_back(G.cost[i]);
		}
		source = start;
		nodes[start].d = 0;
		Loop(k, n) {
			Loop(i, n) {
				node *a = &nodes[i];
				Loop(j, a->to.size()) {
					node *b = &nodes[a->to[j]];
					if (a->d != INFLL && a->d + a->cost[j] < b->d) {
						b->d = a->d + a->cost[j];
						b->from = a->id;
						if (k == n - 1) {
							negative_cycle = true;
							return;
						}
					}
				}
			}
		}
		negative_cycle = false;
		return;
	}
	vi get_path(int v) {
		int a = v;
		stack<int> stk;
		stk.push(v);
		while (nodes[a].from != -1) {
			stk.push(nodes[a].from);
			a = nodes[a].from;
		}
		if (stk.top() != source) return{ -1 };
		vi ret;
		while (stk.size()) {
			ret.push_back(stk.top());
			stk.pop();
		}
		return ret;
	}
	ll get_dist(int v) {
		return nodes[v].d;
	}
	bool is_negative_cycle() {
		return negative_cycle;
	}
};

// bellmanford sample
int main() {
	graph_t G;
	cin >> G.n >> G.m;
	int start; cin >> start;
	Loop(i, G.m) {
		int s, t, c; cin >> s >> t >> c;
		G.edges.push_back({ s, t });
		G.cost.push_back(c);
	}
	Bellmanford bellmanford(G, start);
	if (bellmanford.is_negative_cycle()) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		Loop(i, G.n) {
			ll ans = bellmanford.get_dist(i);
			if (ans == INFLL) cout << "INF" << endl;
			else cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3292
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	int n, m;
	cin >> n >> m;

	vi dp(100030, INF);
	dp[0] = 0;
	for (int i = 0; i < m; i++) {
		int coin;
		cin >> coin;
		for (int j = 0; j + coin <= n; j++) {
			dp[j + coin] = min(dp[j + coin], dp[j] + 1);
		}
	}

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

Measured memory_bytes: 3364