akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main()
{
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(i,w+2) {
        cout << "#";
    }
    cout << endl;
    rep(i,h) {
        cout << "#";
        cout << s[i];
        cout << "#" << endl;
    }

    rep(i,w+2) {
        cout << "#";
    }
    cout << endl;
    return 0;
}


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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll INF=1e17;
const int mod=1000000007;


ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}

int main(){
  int n;
  string s;
  char c='0';
  cin>>n>>s;
  queue<char> q;
  rep(i,n){
  if(c!=s[i]){q.push(s[i]);}
  c=s[i];
  }
  cout<<q.size()<<endl;
return 0;
}

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

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w;
  cin >> h >> w;
  
  vector<vector<char> > a(h+2, vector<char>(w+2));
  rep(i, 0, h+2) {
    rep(j, 0, w+2) {
      if(i==0 or j==0 or i==h+1 or j==w+1)
        a[i][j] = '#';
      else
        cin >> a[i][j];
    }
  }
  rep(i, 0, h+2) {
    rep(j, 0, w+2) {
      cout << a[i][j];
    }
    cout << "\n";
  }
}

Measured memory_bytes: 256
from collections import deque
n,q=map(int,input().split())
E=[[]for _ in range(n)]
P=[0]*n
V=[False]*n
for i in range(n-1):
   a,b=map(int,input().split())
   E[a-1].append(b-1)
   E[b-1].append(a-1)
for i in range(q):
   p,x=map(int,input().split())
   P[p-1]+=x
que=deque([0])
while que:
   s=que.popleft()
   V[s]=True
   for ni in E[s]:
      if V[ni]==False:
         P[ni]+=P[s]
         que.append(ni)
print(*P)

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

#define fori(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int num;
    cin >> num;
    int result = num + num * num + num * num * num;
    cout << result << "\n";
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 52
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n, a, b;
ll v[N];
ll comb[N][N];
int main() {
	cin>>n>>a>>b;
	for (int i = 0; i < n; ++i) {
		cin>>v[i];
	}
	if (a > b) {
		cout<<0<<endl;
		cout<<0<<endl;
		return 0;
	}
	for (int i = 0; i <= n; ++i) {
		comb[i][0] = 1;
		for (int j = 1; j <= i; ++j) {
			comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
		}
	}
	sort(v, v+n);
	reverse(v, v+n);
	double ave = 0.0;
	for (int i = 0; i < a; ++i) {
		ave += v[i];
	}
	ave /= (double)a;
	printf("%.7lf\n", ave);
	int cnt1=0;
	int cnt2=0;
	for (int i = 0; i < n; ++i) {
		if (v[i] == v[a-1]) {
			cnt1++;
			if (i < a) {
				cnt2++;
			}
		}
	}
	ll tot=0;
	if (cnt2 == a) {
		for (int i = a; i <= b; ++i) {
			tot += comb[cnt1][i];
		}
	} else {
		tot += comb[cnt1][cnt2];
	}
	cout<<tot<<endl;
	return 0;
}

Measured memory_bytes: 256
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com

#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
typedef long long int LL;
typedef unsigned long long int ULL;
int main()
{
    fast;
    int i,j,k,n,m,l,s=0,y,tc=1,c=0;
    LL x=0;
    while(cin>>n>>m)
    {
        x=m;
        rep(i,n)
        {
            cin>>c;
            if(i>0)
            {
                y=abs(c-y);
                if(y>m) x+=m;
                else x+=y;
            }
            y=c;
        }
        cout<<x<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int n,k,ans=1;
int main()
{
	scanf("%d%d",&n,&k);
	while(n--)
	{
		ans+=min(ans,k);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main() {
	char W[10], T[1000];
	int i, j=0;
	scanf("%s", W);
	while (1) {
		scanf("%s", T);
		if (strcmp(T, "END_OF_TEXT")==0) {
			break;
		}
		for (i = 0;i < strlen(W);i++) {
			W[i] = tolower(W[i]);
		}
		for (i = 0;i < strlen(T);i++) {
			T[i] = tolower(T[i]);
		}
		if (strcmp(W, T)==0) {
			j++;
		}
	}
	printf("%d\n", j);
	return 0;
}

Measured memory_bytes: 552
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std ;
const long long mod = 998244353 ;
int n,a[200007] ;
map<int,long long>dp[200007] ;
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
        cin>>a[i];
	for(int i=1;i<=n;++i)
        dp[i][1]=a[i];
    for(int i=3;i<=n;++i){
		for(int j=max(2,i/2-3);j<=min(n,i/2+3);++j){
		   long long max1=-1e18;
		   for(int k=max(1,i-5);k<=i-2;++k){
                if(dp[k].count(j-1)==0)
                    continue;
                max1=max(max1,dp[k][j-1]+a[i]);
		   }
		   if(max1<-1e17)
                continue;
		   dp[i][j]=max1;
		}
	}
	long long ans = -1e18 ;
	for(int i=max(1,n-10);i<=n;++i)
        if(dp[i].count(n/2))
            ans=max(ans,dp[i][n/2]);
	cout<<ans;
	return 0 ;
}


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

int n , x ; 

int f(int a , int b)
{
	if(a>b)
		swap(a , b) ; 
	if(b%a==0)
		return (b/a)*a*2-a ; 
	else
		return (b/a)*a*2 + f(b%a , a) ; 
}

int32_t main()
{
	cin >> n >> x ; 
	cout << n + f(n-x , x) << endl ;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
using in = int64_t;

int check(int w[],int i,int n){
   int sum1=0;
  int sum2=0;
  for(int j=0;j<=i;j++){sum1+=w[j];}
  for(int j=i+1;j<n;j++){sum2+=w[j];}
  int sa = abs(sum1-sum2);
  return sa;
}

int main(){
  int n;
  cin>>n;
  int w[110];
  rep(i,n) cin>>w[i];
  
  int a=0;
  for(int i=0;i<n;i++) a+=w[i];
  for(int i=0;i<n-1;i++){
    a=min(check(w,i,n),a);
  }
  cout<<a;
}


Measured memory_bytes: 256
/*
 * AtCoder AGC038 B Sorting a Segment
*/
#include <bits/stdc++.h>
using namespace std;
int n,k,a[200005],go[200005];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    int ans=0;
    go[0]=0;
    for(int i=2;i<=n;i++){
        if(a[i]>a[i-1])go[i]=go[i-1]+1;
        else go[i]=0;
        if(go[i]>=k-1)ans=1;
    }
    set<int> ss;
    for(int i=1;i<=k;i++)ss.insert(a[i]);
    if(go[k]!=k-1)ans++;
    for(int i=k+1;i<=n;i++){
        ss.insert(a[i]);
        if(*ss.begin()!=a[i-k]||*ss.rbegin()!=a[i]){
            if(go[i]<k-1){
                ans++;
            }
        }
        ss.erase(a[i-k]);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 11136
s = input()
l = len(s)
a,b = 0,0
for i in range(l):
    if s[i] == "A":
        a = i+1
        break
for i in range(l):
    if s[-(i+1)] == "Z":
        b = i+1
        break
print(l-(a-1)-(b-1))

Measured memory_bytes: 3516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
	string s; cin >> s;
	bool f=true;

	if (s[0] != 'A') f=false;

	int cnt = 0;
	for (int i = 2; i <= s.length() - 2; i++) {
		if (s[i] == 'C') cnt++;
	}

	for (int i = 0; i<s.length(); i++) {
		if (s[i] == 'A' || s[i] == 'C') continue;

		if (tolower(s[i]) != s[i]) f=false;
	}

	if (f==true && cnt == 1) cout << "AC" << endl;
	else cout << "WA" << endl;
	return 0;
}


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


int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n,t,a;
    cin>>n;
    cin >> t>>a;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    int dest = -1;
    double diff = -1.0;
    rep(i,n){
        double temp = h[i]*0.006;
        temp = t-temp;
        if(abs(temp-a)<diff || diff==-1.0){
            diff = abs(temp-a);
            dest = i;
        }
    }

    cout << dest+1 <<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // メインプログラムここから
    ll n; cin >> n;
    vector<ll> A(n);
    REP(i, n) {
        cin >> A[i];
    }
    // ΣA[i] を求める
    ll sum = 0;
    REP(i, n) {
        sum += A[i];
    }
    // 1回の操作で取り除く個数
    ll K = n * (n+1) / 2;
    // 後で1つでも条件を満たさなかったらfalseにする
    bool ans = true;
    // 必要条件
    if (sum % K == 0) {
        // 合計操作回数
        ll T = sum / K;
        REP(i, n) {
            // 隣との差を埋められるか
            ll d = T + A[i] - A[(i+1)%n];
            if (d < 0 || d % n != 0) {
                ans = false;
            }
        }
    }
    else {
        ans = false;
    }
    // 出力
    if (ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<bitset>
#include<map>
#include<vector>
#include<set>
#define ll long long
#define db double
#define si short int
#define mem(a) memset(a,0,sizeof(a))
#define maxn 20
#define maxm
#define inf 0x7fffffff
#define mod
#define eps
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
ll read(){
	ll a=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){a=a*10+c-'0';c=getchar();}
	return a*f;
}
ll n,a[maxn],x[maxn][maxn],y[maxn][maxn],ans,st[maxn]; 
void Check(){
	ll tmp=0;
	for(int i=1;i<=n;i++){
		if(!st[i])continue;
		for(int j=1;j<=a[i];j++){
			if(st[x[i][j]]!=y[i][j])return;
		}
		tmp++;
	}
	ans=Max(ans,tmp);
}
void Dfs(ll x){
	if(x==n+1){
		Check();
		return;
	}
	st[x]=1;Dfs(x+1);
	st[x]=0;Dfs(x+1);
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		for(int j=1;j<=a[i];j++){
			x[i][j]=read();
			y[i][j]=read();
		}
	}
	Dfs(1);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

map<ll, ll> m;
vector<ll> s;
vector<P> p;
ll ans = 0, t[210000];
int main() {
	ll n;
	cin >> n;
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		p.push_back(P(a, b));
		s.push_back(a);
		s.push_back(b);
	}
	sort(ALL(s));
	s.erase(unique(ALL(s)), s.end());
	REP(i, s.size())m[s[i]] = i;
	REP(i, n) {
		t[m[p[i].first]]++;
		t[m[p[i].second] + 1]--;
	}
	REP(i, 200000)t[i + 1] += t[i];
	REP(i, 210000) {
		ans = max(ans, t[i]);
	}
	cout << ans << endl;
}





Measured memory_bytes: 20076
v=input
r=range
a=[list(map(int,v().split()))for i in r(int(v()))]
b=[[[0 for i in r(10)]for j in r(3)]for k in r(4)]
for i in a:b[i[0]-1][i[1]-1][i[2]-1]+=i[3]
f=0
for i in b:
  if f:print('#'*20)
  else:f=1
  for j in i:print('',*j)

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

bool prime(int num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if( num % 2 == 0) return false;

    double sqrtnum = sqrt(num);
    for(int i = 3; i <= sqrtnum; i += 2){
        if(num % i == 0){
            return false;
        }
    }
    return true;
}

int checkPrime(int num){
    bool flag = false;
    while(flag == false){
        if(prime(num)){
            flag = true;
        }
        else{
            num +=2;
        }
    }
    return num;
}

int main(){
    int X; cin >> X;
    if(X % 2 == 0){
        if(X == 2){
            cout << 2 << endl;
        }
        else{
            cout << checkPrime(X+1) << endl;
        }
    }
    else{
        cout << checkPrime(X) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<ll> lucas(N + 1);
  lucas[0] = 2;
  lucas[1] = 1;
  for(int i = 2; i <= N; ++i) {
    lucas[i] = lucas[i - 1] + lucas[i - 2];
  }
  cout << lucas[N] << endl;
  return 0;
}

Measured memory_bytes: 256
let swap(a,b)=(b,a)and s=ref(Scanf.scanf"%d %d %d %d %d %d
"(fun a b c d e f->[(a,f);(b,e);(c,d)]));;Bytes.iter(fun c->s:=match!s with[x;y;z]->(match c with|'N'->[y;swap x;z]|'S'->[swap y;x;z]|'E'->[swap z;y;x]|'W'->[z;y;swap x]|_->[])|_->[])(Scanf.scanf"%s"(fun l->l));Printf.printf"%d
"(fst(List.nth!s 0))

Measured memory_bytes: 2404
import math
import fractions
from functools import reduce
import sys
input = sys.stdin.readline


def main():
    n, m = input_list()
    s = input()
    t = input()
    baisuu = lcm_base(n, m)
    ans = {}
    for i in range(1, n+1):
        index = (i - 1) * (baisuu//n) + 1
        ans[index] = s[i-1]

    for i in range(1, m+1):
        index = (i - 1) * (baisuu//m) + 1
        w = t[i-1]
        if index in ans:
            if ans[index] != w:
                print(-1)
                exit(0)
        else:
            ans[index] = w

    print(baisuu)


def input_list():
    return list(map(int, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if __name__ == "__main__":
    main()


Measured memory_bytes: 83304
#include<iostream>
#include<vector>
#include<cctype>
#include<numeric>
using namespace std;

int n, pos;
vector<string> v;

int f(int d){
    if(isdigit(v[pos].back())){
        int ret =  v[pos].back()-'0';
        pos++;
        return ret;
    }else{
        char op = v[pos].back();
        pos++;
        vector<int> child;
        while(pos < n && v[pos].length() == d+1){
            child.push_back(f(d+1));
        }
        if(op == '+'){
            return accumulate(child.begin(), child.end(), 0);
        }else{
            int ret = 1;
            for(int x : child)  ret *= x;
            return ret;
        }
    }
}

int main(){
    while(cin >> n, n){
        v.clear();
        v.resize(n);
        for(int i = 0; i < n; i++)  cin >> v[i];
        pos = 0;
        cout << f(1) << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,k = mi()

a = li()
min_cost = 10**9 * 16

for i in range(2**n):
    select = []
    a2 = a.copy()
    for j in range(n):
        if (i >> j)&1:
            select.append(j)

    if(len(select) != k):
        continue

    cost = 0
    b_max = a2[0]
    for j in range(1,n):
        if j in select:
            if(a2[j] <= b_max):
                cost += b_max+1 - a2[j]
                a2[j] = b_max+1
        b_max = max(b_max, a2[j])
    min_cost = min(min_cost, cost)

print(min_cost)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

bool dfs(VI a){
    int n = a.size();
    int e = 0, o;
    REP(i,n) e += (a[i] % 2 == 0);
    if (e % 2 == 1) return true;
    o = n - e;
    if (o != 1) return false;
    REP(i,n){
        if (a[i] % 2 == 1){
            if (a[i] == 1) return false;
            a[i]--;
        }
    }
    int d = gcd(a[0],a[1]);
    REP(i,n) d = gcd(d, a[i]);
    REP(i,n) a[i] /= d;
    return dfs(a) ^ 1;
}

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) scanf("%d", &a[i]);
    sort(ALL(a));

    cout << (dfs(a) ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int P[114514],Q[114514];
    cin >> N;
    REP(i,N){
        cin >> P[i];
        Q[P[i]]=i+1;
    }
    int Ans=0;
    set<int> G;
    
    G.insert(-1);G.insert(0);
    G.insert(N+1);G.insert(N+2);
    G.insert(Q[N]);
    RREP(k,N){
        if(k==0)continue;
        int i=Q[k];
        int w,x,y,z;
        decltype(G)::iterator it;
        it=--G.lower_bound(i);x=*it;
        it=--G.lower_bound(x);w=*it;
        it=G.lower_bound(i);y=*it;
        it=++G.lower_bound(i);z=*it;
        
        w=max(0ll,w);x=max(0ll,x);
        y=min(N+1,y);z=min(N+1,z);
        
        int p=(x-w)*(y-i)+(i-x)*(z-y);
        //cout << w MM x MM y MM z MM "" MM i MM p << endl; 
        Ans+=k*p;
        
        G.insert(i);
    }
    cout << Ans << endl;
  return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cstdio>
#include <cmath>
#include <deque>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int cost[10][10];
int a[200][200];
ll ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w;
	cin >> h >> w;
	REP(i, 10){
		REP(j, 10){
			cin >> cost[i][j];
		}
	}

	REP(k, 10){
		REP(i, 10){
			REP(j, 10){
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}

	REP(i, h){
		REP(j, w){
			int t;
			cin >> t;
			if(t != -1)
				ans += cost[t][1];
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll n,k;
  cin >> n >> k;
  ll ans = 0;

  for (int i = 0; i <= min(k, n); ++i) {
    ll cnt = COM(n, i) * COM(n-1, i);
    ans += cnt;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 12160
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int N,Q;

int a[200010];
int b[200010];
int p[200010];
int x[200010];

int cnt[200010];

vector<int> graph[200010];

queue<int> q;
int v[200010]={};

int cur=0;





int main(void)
{
	int i;
	cin >> N >> Q;

	for(i=0;i<N-1;i++)
	{
		cin >> a[i] >> b[i];
	}

	for(i=0;i<Q;i++)
	{
		cin >> p[i] >> x[i];
	}

	for(i=0;i<N-1;i++)
	{
		graph[a[i]].push_back(b[i]);	
		graph[b[i]].push_back(a[i]);
	}

	for(i=0;i<N-1;i++)
	{
		graph[a[i]].push_back(b[i]);	
		graph[b[i]].push_back(a[i]);
	}

	for(i=0;i<Q;i++)
	{
		cnt[p[i]]+=x[i];
	}
	q.push(1);
	v[1]=1;
	while(!q.empty())
	{
		cur=q.front();
		q.pop();
		
		for(i=0;i<graph[cur].size();i++)
		{
			int nxt=graph[cur][i];
			if(v[nxt]==0)
			{
				cnt[nxt]+=cnt[cur];
				q.push(nxt);
				v[nxt]=1;
			}

		}

			
	}
	
	for(i=1;i<=N;i++)
	{
		cout << cnt[i] << " ";
	}
	 cout  << endl;

}



Measured memory_bytes: 20608
x = int(input())
import math
from collections import defaultdict

res = 0
value = defaultdict(int)
def isprime(n):
    if n <= 1:
        return 0
    m = int(math.sqrt(n)) + 1
    for i in range(2, m):
        if n % i == 0:
            return 0
    return 1
if isprime(x):
    print(1)
else:
    def bprime(n):
        cnt = 2
        m = int(math.sqrt(n)) + 1
        while n != 1 and cnt < m:
            while n % cnt == 0:
                n //= cnt
                value[cnt] += 1
            cnt += 1
        if cnt == m and n != 1:
            value[n] += 1
    def cal(n):
        if n <= 2:
            return 1
        j = 1
        cnt = 0
        while n >= j:
            n -= j
            j += 1
            cnt += 1
        return cnt
    bprime(x)
    for key in value.keys():
        res += cal(value[key])
    print(res)

Measured memory_bytes: 9488
/**
*    created: 07.07.2020 02:04:58
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    deque<int> b;
    int n; cin >> n;
    rep(i,n) {
        int a; cin >> a;
        if (i % 2 == 0) b.push_back(a);
        else b.push_front(a);
    }
    if (n % 2 == 0) {
        rep(i,n) {
            int t = b.front(); b.pop_front();
            cout << t << " ";
        }
        cout << endl;
    } 
    else {
        rep(i,n) {
            int t = b.back(); b.pop_back();
            cout << t << " ";
        }
        cout << endl;
    } 
    return 0;
}

Measured memory_bytes: 5184
#include <algorithm>
#include <cstring>
#include <cstdio>
long long dp[100005], mn = 1e18;
int arr[100005], que[100005];
int main()
{
	// freopen("AGC007-D.in", "r", stdin);
	int n, e, t, he = 0, ta = 0;
	scanf("%d%d%d", &n, &e, &t);
	for (int i = 1; i <= n; i++)
		scanf("%d", arr + i);
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 1, pos = 0; i <= n; i++)
	{
		while (pos < i && (arr[i] - arr[pos + 1] << 1) >= t)
		{
			if (he <= ta && que[he] <= pos)
				he++;
			mn = std::min(mn, dp[pos] - (arr[pos + 1] << 1));
			pos++;
		}
		dp[i] = mn + (arr[i] << 1);
		if (he <= ta)
			dp[i] = std::min(dp[i], dp[que[he]] + t);
		while (he <= ta && dp[que[ta]] >= dp[i])
			ta--;
		que[++ta] = i;
	}
	printf("%lld\n", dp[n] + e);
	return 0;
}


Measured memory_bytes: 1664
<?php

//?¨??????\???????????\??????????????????
$inputLine = trim(fgets(STDIN));

//????§???????????????§?????????
list($comparison1, $comparison2) = explode(" ", $inputLine);

//??????????????´???
if ($comparison1 == $comparison2) {

	echo "a == b";

//1??????1??????????????§????????´???
} elseif ($comparison1 > $comparison2){

	echo "a > b";

//??\???
} else {

	echo "a < b";
}

?>

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

int main() {
	int n,m;cin>>n>>m;
	vector<vector<int>> a(n,vector<int>(0));
	vector<int> k(n);
	vector<int> like(m+1,0);
	for(int i=0;i<n;i++){
		cin>>k[i];
		for(int j=0;j<k[i];j++){
			int num;cin>>num;
			a[i].push_back(num);
			like[num]++;
		}
	}
	int ans=0;
	for(auto x:like){
		if(x==n){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int N; cin >> N; int A; vector<int> b;
  b.push_back(-1);
  for(int i=0; i<N; i++){
    cin >> A;
    int wh = distance(b.begin(), upper_bound(b.begin(), b.end(), A, std::greater<int>()));
    if (wh < b.size()) b[wh] = A;
    else b.push_back(A);
  }
  cout << b.size() << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
typedef long long int ll;
// #define int long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define debug(x) cout << #x << " is: " << (x) << endl;
#define debugx(x) cout << #x << " is: " << (x) << endl; exit(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;i<n;i++)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define INF 1000111000111000111LL
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<vector<ll>> matrix;
ll dx[] = {0, 1, 0, -1};
ll dy[] = {-1, 0, 1, 0};
const ll N = 3e4+5;
// ll a[N], b[N], dp[N], level[N], vis[N], in[N], out[N];
// vl g[N];
ll n, m;


void solve() {
    ld d, dis, x, y;
    cin >> n >> d;
    ll res = 0;
    f(i, n){
        cin >> x >> y;
        if((x*x + y*y) <= (d*d)){
            res++;
        }
    }
    cout << res << endl;
}


int32_t main() {
    IOS
    solve();
    cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n';
    return 0;
}

Measured memory_bytes: 3808
public class Main {
    public static void main(String args[]) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        int dp[][] = new int[n + 1][h + 1];
        dp[0][0] = 0;
        for (int j = 1; j <= h; j++) {
            dp[0][j] = INF;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= h; j++) {
                dp[i][j] = Math.min(dp[i - 1][j], dp[i][Math.max(0, j - a[i - 1])] + b[i - 1]);
            }
        }
        System.out.println(dp[n][h]);
    }
    public static final int INF = 1000000000;
}

Measured memory_bytes: 80740
package main

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

// Scan Standard Input
var sc = bufio.NewScanner(os.Stdin)

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

type Process struct {
	name string
	time int
}

const MAX_LEN = 100000

type Queue struct {
	container [MAX_LEN]Process
	head      int
	tail      int
}

func (q *Queue) isEmpty() bool {
	return q.head == q.tail
}

func (q *Queue) enqueue(name string, time int) {
	q.container[q.tail] = Process{name: name, time: time}
	q.tail = (q.tail + 1) % MAX_LEN // Overflowしないように最大値で余剰
}

func (q *Queue) dequeue() Process {
	if q.isEmpty() {
		fmt.Println("Empty")
	}
	process := q.container[q.head]
	q.head = (q.head + 1) % MAX_LEN // Overflowしないように最大値で余剰
	return process
}

func main() {
	q := Queue{head: 0, tail: 0}
	s := strings.Split(nextLine(), " ")

	n, _ := strconv.Atoi(s[0])
	time_slice, _ := strconv.Atoi(s[1])

	for i := 0; i < n; i++ {
		str := strings.Split(nextLine(), " ")
		name := str[0]
		time, _ := strconv.Atoi(str[1])

		q.enqueue(name, time)
	}

	cpu := 0

	for {
		if q.isEmpty() {
			break
		}

		processing := q.dequeue()
		if processing.time <= time_slice {
			cpu += processing.time
			fmt.Printf("%s %d\n", processing.name, cpu)
		} else {
			q.enqueue(processing.name, processing.time-time_slice)
			cpu += time_slice
		}
	}

}



Measured memory_bytes: 6940
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let l: usize = scan(tokens);
    let mut d = vec![vec![l + 1; n]; n];
    for i in 0..n {
        d[i][i] = 0;
    }
    for _ in 0..m {
        let a: usize = scan(tokens);
        let b: usize = scan(tokens);
        let c: usize = scan(tokens);
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }
    for i in 0..n {
        for j in 0..n {
            for k in 0..n {
                d[j][k] = std::cmp::min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    let inf = 1000;
    let mut e = vec![vec![inf; n]; n];
    for i in 0..n {
        for j in 0..n {
            if i == j {
                e[i][j] = 0;
            } else if d[i][j] <= l {
                e[i][j] = 1;
            }
        }
    }
    for i in 0..n {
        for j in 0..n {
            for k in 0..n {
                e[j][k] = std::cmp::min(e[j][k], e[j][i] + e[i][k]);
            }
        }
    }
    let q: usize = scan(tokens);
    for _ in 0..q {
        let s: usize = scan(tokens);
        let t: usize = scan(tokens);
        let ans = e[s - 1][t - 1];
        if ans == inf {
            println!("-1");
        } else {
            println!("{}", ans - 1);
        }
    }
}


Measured memory_bytes: 6652
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26116
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <stack>
#define mp make_pair
#define MIN(a,b) (a>b?b:a)
//#define MAX(a,b) (a>b?a:b)
typedef long long ll;
typedef unsigned long long ull;
const int MAX=1e5+5;
const int INF=1e8+5;
using namespace std;
//const int MOD=1e9+7;
typedef pair<ll,int> pii;
typedef pair<ll,ll> pll;
const double eps=0.00000001;
ll n,c[MAX],m=INF,ans;
vector<pll> edge[MAX];
void calc(ll C,ll P)//current pre
{
    c[C]=1;//先算上自己这个点
    for(auto &X : edge[C])
    {
        ll T,V;tie(T,V)=X;
        if(T==P)//不能往回走
            continue;
        calc(T,C);
        c[C]+=c[T];
    }
}
void solve(ll C,ll P,ll L)//current pre len
{
    ans+=2*L*min(c[C],n-c[C]);//为对应于这条边的S
    pll mx={-1,-1};
    for(auto &X:edge[C])
    {
        ll T,V;tie(T,V)=X;
        if(T==P)
            continue;
        mx=max(mx,{c[T],V});
    }
    mx=max(mx,{n-c[C],L});//mx记录这个点的所有子树中的最大子树 及连向该子树的边的权值
    if(2*mx.first==n)
        m=min(m,mx.second);
    else if(2*mx.first<n)//最大子树节点个数小于n/2 则找最短的连接边
    {
        for(auto &X:edge[C])
            m=min(m,X.second);
    }
    for(auto &X:edge[C])
    {
        ll T,V;tie(T,V)=X;
        if(T==P)//不回头走
            continue;
        solve(T,C,V);
    }
}
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<n;i++)
    {
        ll A,B,C;
        scanf("%lld %lld %lld",&A,&B,&C);
        edge[A].push_back({B,C});
        edge[B].push_back({A,C});
    }
    calc(1,0);
    solve(1,0,0);
    printf("%lld\n",ans-m);
    return 0;
}


Measured memory_bytes: 13952
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, X) = Slice2<long>();
            var mi = new long[N];
            for (var i = 0; i < N; ++i)
                mi[i] = Sarray()[0];
            WriteLine(N + (X - mi.Sum()) / mi.Min());
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
const ll maxs = (ll)1e6+5;
const ll mod = (ll)1e9+7;
const ll oo = (ll) 1e18;
 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
 
int main() 
{
    fastio();
    ll t=1;
    //cin>>t;
    while(t--)
    {
      char ch;
      cin>>ch;
        if(ch == 'z')
            ch = 'a';
        else
            ch++;
        cout << ch;
    
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp[5],tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    rep(i,3)cin>>tmp[i];
    sort(tmp,tmp+3);
    Cout(tmp[0]+tmp[1]);
    return 0;
}


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


int main()
{
    int n;
    std::string s;
    std::cin >> n >> s;
    int max = 0, x = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'I')x++;
        else x--;
        max = std::max(x,max);
    }
    std::cout << max << std::endl;
}

Measured memory_bytes: 256
import collection.mutable.Queue


object Main {
  case class Task(name: String, time: Int)

  def main(args: Array[String]): Unit = {
    val tasks = Queue[Task]()

    val sc = new java.util.Scanner(System.in);
    val n = sc.nextInt
    val q = sc.nextInt

    for (_ <- 1 to n) tasks enqueue Task(sc.next, sc.nextInt)

    var time = 0

    while (tasks.nonEmpty) {
      val task = tasks.dequeue
      if (task.time > q) {
        time = time + q
        tasks enqueue task.copy(time = task.time - q)
      } else {
        time = time + task.time
        println(s"${task.name} $time")
      }
    }
  }
}

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

#define endl '\n'

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}
int A[200005]; 
int B[200005] ;
int mark[200005] ;
int main(int argc,char* argv[]) { 
    io() ;
    int n ;
    cin >> n ;
    for(int i = 1; i <= n; i++){
        cin >> A[i] ;
    }
    for(int i = n ; i >= 1 ; i -= 2){
        mark[i] = 1 ;
        cout << A[i] << " " ;
    }
    for(int i = 1; i <= n; i++){
        if(!mark[i]){
            cout << A[i] << " " ;
        }
    }
    return 0 ; 
}

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

#define int long long

//ax+by=1を満たす(x,y)
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
const long long LINF=1e18;

signed main(){
  /*
  for(int i=2;i<=10;i++)
    for(int j=2;j<=10;j++)
      if(__gcd(i,j)==1)cout<<i<<" "<<j<<" "<<F(i,j)<<endl;
  return 0;
  */
  int n;cin>>n;n*=2;
  vector<int> v;
  for(int i=2;i*i<=n;i++){
    if(n%i)continue;
    int cnt=1;
    while(n%i==0){
      n/=i;
      cnt*=i;
    }
    v.push_back(cnt);
  }
  if(n>1)v.push_back(n);
  int S=v.size();
  int ans=LINF;
  //for(int p:v)cout<<p<<" ";cout<<endl;
  for(int bit=0;bit<(1<<S);bit++){
    int one=1,two=1;
    for(int i=0;i<S;i++){
      if((bit>>i)&1)one*=v[i];
      else two*=v[i];
    }
    if(one==1){
      chmin(ans,two);
      continue;
    }
    if(two==1){
      chmin(ans,one-1);
      continue;
    }
    int x,y;
    extGCD(one,two,x,y);
    //cout<<one<<" "<<two<<" "<<x<<" "<<y<<endl;
    if(x<=0)x=two-x;
    //cout<<one*x-1<<endl;
    chmin(ans,one*x-1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  while (C > 0) {
    ans++;
    C -= A;
    if (ans % 7 == 0) {
      C -= B;
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 3108
// #include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
// #include <iostream>
// #include <iomanip>
// #include <sstream>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fr(_iii_, 0, 66)cerr<<'>';cerr<<" in\n"
#define deb(x) fr(_iii_, 0, 66)cerr<<'>';cerr<<#x"="<<x<<"\n"
#define deb_array(a, _iiii_, n) fr(_iii_, _iiii_, 66)cerr<<'>'; cerr<<'\n';fr(_iii_,_iiii_,n)cerr<<a[_iii_]<<(_iii_==n-1?"\n":" ");fr(_iii_, _iiii_, 66)cerr<<'>'; cerr<<"\n"
#define deb_matrix(a, h, w) fr(_iii_, 0, 66)cerr<<'>'; cerr<<'\n';fr(_iii_, 0, h){fr(j, 0, w) {cerr << a[_iii_][j] << ' ';}cerr << '\n';}fr(_iii_, 0, 66)cerr<<'>'; cerr<<"\n"
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
//bitmask
int on_bit(int x, int pos) {x |= (1 << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(int x, int pos) {return ((x & (1 << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int on_bit_all(int x, int pos) {x = (1 << pos)-1; return x;}
//constants
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
//moves
const int dx1[] = {0, 1, 0, -1};
const int dy1[] = {1, 0, -1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy2[] = {-1, 0, 1, -1, 1, -1, 0, 1};

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

bool ok(int x){
	int k = x % 10;
	x /= 10;
	while(x){
		if(x % 10 != k) return false;
		x /= 10;
	}
	return true;
}

int main() {
	int n;
	sf("%d",&n);
	while(1){
		if(ok(n++))break;
	}
	pf("%d\n",n-1);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = 505;
int x[N];
int a[N * N];

pair <int, int> p[N];


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &x[i] );
		x[i]--;
		p[i] = make_pair(x[i], i);
	}
	memset(a, -1, sizeof a);
	for (int i = 0; i < n; i++)
		a[x[i] ] = i;
	sort(p, p + n);
	int ptr = 0;
	for (int _i = 0; _i < n; _i++)
	{
		int i = p[_i].second;
		for (int j = 0; j < i; j++)
		{
			while (a[ptr] != -1) ptr++;
			a[ptr++] = i;
			if (ptr > x[i] )
			{
				printf("No\n");
				return 0;
			}
		}
	}
	eprintf("!!!!\n");
	ptr = n * n - 1;
	for (int _i = n - 1; _i >= 0; _i--)
	{
		int i = p[_i].second;
		for (int j = 0; j < n - i - 1; j++)
		{
			while (a[ptr] != -1) ptr--;
			a[ptr--] = i;
			if (ptr < x[i] )
			{
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");
	for (int i = 0; i < n * n; i++)
		printf("%d ", a[i] + 1);
	printf("\n");

	return 0;
}



Measured memory_bytes: 2176
n, m = map(int, input().split())
list = sorted([list(map(int, input().split())) for _ in range(n)])
money = 0
i = 0

while m > 0:
    money += list[i][0]
    m -= 1
    list[i][1] -= 1
    if list[i][1] == 0:
        i += 1

print(money)

Measured memory_bytes: 28652
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int K = scan.nextInt();
    int[] H = new int[N];
    for(int i=0; i<N; i++) {
      H[i] = scan.nextInt();
    }
    scan.close();

    Arrays.sort(H);

    long sum = 0;
    for(int i=0; i<N-K; i++) {
      sum += H[i];
    }

    System.out.println(sum);
  }
}

Measured memory_bytes: 64956
from copy import deepcopy
import itertools

A, B, C, D, E, F = map(int, input().split())

qA = [i // 100 for i in range(0, F + 1, A * 100)]
qB = [i // 100 for i in range(0, F + 1, B * 100)]
qC = [i for i in range(0, F + 1, C)]
qD = [i for i in range(0, F + 1, D)]

W = set(qA + qB)
for i in range(F // min(A, B)):
    nW = deepcopy(W)
    for w in W:
        if (w + A) * 100 <= F:
            nW.add(w + A)
        if (w + B) * 100 <= F:
            nW.add(w + B)

    if len(W) == len(nW):
        break
    W = deepcopy(nW)

W = nW

S = set(qC + qD)
for i in range(F // min(C, D)):
    nS = deepcopy(S)
    for s in S:
        if (s + C) <= F:
            nS.add(s + C)
        if (s + D) <= F:
            nS.add(s + D)

    if len(S) == len(nS):
        break
    S = deepcopy(nS)
S = nS

M = 0
Ms = 0
Mw = A
for w, s in itertools.product(W, S):
    if w != 0 and s <= w * E and s + 100 * w <= F:
        if M < s / (w * 100 + s):
            M = s / (w * 100 + s)
            Ms = s
            Mw = w

print(Ms + Mw * 100)
print(Ms)


Measured memory_bytes: 9824
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
   int a, b;
   int c;

   cin >> a >> b;

    for (c = 1; c <= 3; c++){
        if(a * b * c % 2 == 1){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

}

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

using namespace std;
#define mp make_pair
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;


ll sum(ll k, ll n){
    // k + 2*k + ... x*k , x*k <= n
    // k*(1+...+x)
    ll x = n/k;
    return k*(((x+1)*x)/2);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = sum(1,n);
    ans -= sum(3,n);
    ans -= sum(5,n);
    ans += sum(15,n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648