akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

H,W,h,w = inpl()
MAP = [[0]*W for i in range(H)]

pl = mn = 0
tmp = 0
for y in range(H):
	for x in range(W):
		if (y+1)%h==0 and (x+1)%w==0:
			MAP[y][x] -= (h*w-1)*1000 +1
			mn += 1
			tmp -= (h*w-1)*1000 +1
		else:
			MAP[y][x] = 1000
			pl += 1
			tmp += 1000

if tmp <= 0:
	print('No')
else:
	print('Yes')
	for m in MAP:
		print(' '.join(map(str,m)))


Measured memory_bytes: 11444
D = [[-1, 0], [1, 0], [0, -1], [0, 1]]

def puyo_rensa(old, cnt)
  check = 14.times.map{ [false] * 8 }
  res = 0
  (1..12).each do |i|
    (1..6).each do |j|
      unless check[i][j] || old[i][j] == 'O' || old[i][j] == '.'
        puyo_connector(i, j, old){ |arr|
          if arr.size >= 4
            arr.each do |s, t|
              D.each do |x, y|
                p, q = s + x, t + y
                check[p][q] = true if old[p][q] == 'O'
              end
              check[s][t] = true
            end
            res = 1
          end
        }
      end
    end
  end
  fld = puyo_eraser(old, check)
  if res == 1 then puyo_rensa(fld, cnt + 1)
  else cnt
  end
end

def puyo_connector(i, j, fld)
  check = 14.times.map{ [false] * 8 }
  arr = [[i, j]]
  ret = [[i, j]]
  check[i][j] = true
  until arr.empty?
    i, j = arr.shift
    D.each do |x, y|
      p, q = i + x,  j + y
      if !check[p][q] && fld[i][j] == fld[p][q]
        check[p][q] = true
        arr << [p, q]
        ret << [p, q]
      end
    end
  end
  yield(ret)
end

def puyo_eraser(fld, check)
  nfld = 14.times.map{ |i| fld[i].dup }
  pos = [0] * 7
  13.downto(0) do |i|
    (1..6).each do |j|
      if check[i][j]
        (1..i).each do |k|
          nfld[k + pos[j]][j] = fld[k - 1][j]
        end
        nfld[pos[j]][j] = '.'
        pos[j] += 1
      end
    end
  end
  nfld
end

gets.to_i.times do
  fld = 14.times.map{ ['.'] * 8 }
  12.times do |i|
    gets.chomp.split('').each_with_index do |c, j|
      fld[i+1][j+1] = c
    end
  end
  p puyo_rensa(fld, 0)
end

Measured memory_bytes: 9276
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    int N;
    cin >> N;
    if(N%2==0) cout << N/2;
    else cout << (N+1)/2;
    return 0;
}



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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    ll n,m;cin>>n>>m;

    if(n==1&&m==1){
        cout<<1<<endl;
    }

    else if(n==1){
        cout<<m-2<<endl;
    }

    else if(m==1){
        cout<<n-2<<endl;
    }

    else{
        cout<<(n-2)*(m-2)<<endl;
    }

}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
   ll n; cin>>n;
   ll ans=1;
   for(int i=1;i<=n;i++){
       ans*=i;
       ans%=mod;
   } 
   cout<<ans<<endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	//cout<<1<<endl;
	cin>>n;
	//cout<<1<<endl;
	vector<ll> g;
	//cout<<1<<endl;
	ll b=sqrt(n);
	for (ll i=1;i<=b;i++)
	{	//cout<<1<<endl;
		ll f=n%i;
		if (f == 0)
		{
			ll a=n/i;
			ll b=i;
			ll c=a+b-2;
			g.push_back(c);
		}
	}
	sort(g.begin(),g.end());
	cout<<g[0]<<endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.*;

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

      int N=sc.nextInt();

      int[] p = new int[N];

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

      int cnt=0;

      for(int i=0;i<N;i++){
        if(p[i]!=i+1){
          cnt++;
        }
      }

      if(cnt==0 || cnt==2){
        System.out.println("YES");
      }
      else{
        System.out.println("NO");
      }







    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
#define P 1000000007
using namespace std;


int powmp(long long x,long long n){
	const long long p = 1000000007;
	if(n==0) return 1;
	long long y = x%p;
	if(n==1) return y;
	long long tmp = (powmp(y,n/2))%p;
	if(n%2==0) return (tmp*tmp)%p;
	else return (powmp(y,n-1)*y)%p;
}



int main(int argc, char const *argv[])
{
	int n,m;
	cin >> n >> m;
	int a[n+1];
	int b[n+1];
	int num[n+1];
	int aa[m];
	fill(a,a+n+1,0);
	fill(b,b+n+1,0);
	REP(i,n){
		cin >> num[i+1];
		a[num[i+1]]++;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<a[i];j++){
			int c = max(0,i-j);
			b[c]++;
		}
	}
	int ans = 0;
	REP(i,n){
		if(b[i+1]==0) ans++;
	}
	REP(i,m){
		int x,y;
		cin >> x >> y;
		int t = x;
		x = num[x];
		num[t] = y;
		int fx = max(0,x-a[x]+1);
		int ex = b[fx];
		a[x]--;
		b[fx]--;
		int fy = 0;
		fy = max(0,y-a[y]);
		int ey = b[fy];
		
		/*if(fx==fy){
			aa[i] = ans;
		}*/
		if(ex>1||fx==0){
			if(ey>0||fy==0) aa[i] = ans;
			else{
				ans--;
				aa[i] = ans;
			}
		}
		else if(ex==1&&fx!=0){
			if(ey==0&&fy!=0) aa[i] = ans;
			else{
				ans++;
				aa[i] = ans;
			}
		}
		a[y]++;
		b[fy]++;
	}
	REP(i,m) cout << aa[i] <<"\n";
	return 0;
}	

Measured memory_bytes: 4608
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

S,T=get
a,b=get_i
U=gets.chomp
if S==U
  a-=1
elsif T==U
    b-=1
end
puts [a,b].join(" ")

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 1100
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
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;



int main() {
	int N, M;
	int ans[nmax_def][10000];
	cin >> N >> M;
	ans[0][0] = 0;
	rep(i, M + 1) {
		rep(j, pow(2, N)) {
			if (i == 0 && j == 0)
				continue;
			ans[i][j] = pow(10, 9);
		}
	}
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		int atmp = 0;
		rep(j, b) {
			int c;
			cin >> c;
			c--;
			atmp += pow(2, c);
		}
		rep(j, pow(2, N)) {
			int j_or_atmp = j | atmp;
			ans[i + 1][j_or_atmp] = min(ans[i + 1][j_or_atmp], ans[i][j] + a); // iを使うべきか
		}
		rep(j, pow(2, N)) {
			ans[i + 1][j] = min(ans[i + 1][j], ans[i][j]); // iを使わないものと比較
		}
	}
	int ansans = ans[M][(int)pow(2, N) - 1];
	if (ansans == pow(10, 9))
		ansans = -1;
	cout << ansans << endl;
	return 0;
}

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

typedef long long ll;
const int N = 3e5;

int cnt[N+5];
int n;
vector<int> ada;
int jaw[N+5];
int ps[N+5];

int cari(int l, int r, int x){
	int ans = r+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(ada[mid] < x){
			ans = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return ans;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int i=1;i<=n;i++){
		if(cnt[i] > 0) ada.push_back(cnt[i]);
	}
	sort(ada.begin(),ada.end());
	reverse(ada.begin(),ada.end());
	for(int i=ada.size()-1;i>=0;i--){
		if(i==ada.size()-1) ps[i] = ada[i];
		else ps[i] = ps[i+1] + ada[i];
	}
	for(int i=0;i<ada.size();i++){
		int sisa = ps[i+1];
//		cout << ">> " << sisa << endl;
		int l = 1;
		int r = n;
		int ans = 0;
		while(l<=r){
			int mid = (l+r)/2;
			int kanan = cari(0,i,mid);
			ll butuh = ps[kanan] - ps[i+1];
			butuh = (ll)(i - kanan + 1) * (ll)(mid) - butuh;
//			cout << " >> kanan " << kanan << endl;
//			cout << " >> " << mid << " " << butuh << endl;
			if(butuh <= sisa){
				ans = mid;
				l = mid+1;
			} else {
				r = mid-1;
			}
		}
		jaw[i] = ans;
	}
	for(int i=0;i<n;i++){
		printf("%d\n",jaw[i]);
	}
	return 0;
}


Measured memory_bytes: 5488
import sys

L,R,d = map(int, sys.stdin.readline().split())
#N = int(sys.stdin.readline())

ans = 0
for i in range(1,int(R/d) + 1):
    if d * i < L:
        continue
    if d * i > R:
        break

    ans += 1

print(ans)


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	repi(i,a,b+1){
		if(i%k==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
bool vec[2010];
int main(){
ll N,K; cin >> N >> K; vector<ll> A(N);

  for(ll i = 0; i < N; i++){ cin >> A[i]; }
                            
  ll cnt = 0;
  for(ll i = 0; i < N-1; i++){
    for(ll j = i+1; j < N; j++){ if( A[i] > A[j]){ cnt++;}}}
    //A一つあたりの転倒数を求める
   cnt %= MOD;
   cnt *= K; cnt %= MOD; 
  
  sort(A.begin(),A.end());
  ll count = 0;
 
  for(ll i = 0; i < N; i++){ ll res = 0;
    for(ll j = 0; j < N; j++){
      if(A[j] > A[i]){ res++;}}
      count += res; count %= MOD;}
  ll a = (K*(K-1))/2; a %= MOD; count *= a; count %= MOD;
  
  cnt += count; cnt %= MOD;
                           
    
    cout << cnt << endl; return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(i=1 ; i < (n); ++i)
#define rrep(i,n) for(i  1; i <= (n); ++i)
#define drep(i,n) for(i  (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//./a.exe

bool isPrime(int x){
    int i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
  int A,B,K,s=1,x[100];
  cin >> A >> B >> K;
    if(A>=B){
       for(int i=A;i>0;i--){
			if(A%i==0 && B%i==0){
			x[s] = i;
            s++;
            }
       }     
    }   
    
    
       else{
        for(int i=B;i>0;i--){
            if(A%i==0 && B%i==0){
                x[s]=i;
                s++;
            }
        }
    }
    s=K;
    cout << x[s] << endl;

  



//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
class combnk_mod(object):
    # pが素数かつaとpが互いに素であるとき
    # フェルマーの小定理より以下が成り立つ.
    # 1 / a = a ** (p - 2) (mod p)
    # これを使って (1 / k!) mod p を計算する.
    def __init__(self, maxn, p):
        self.maxn = maxn
        self.p = p
        self.x = [1] # 分母にあたる数 1 / n! mod p
        self.y = [1] # 分子にあたる数. n! mod p
        for i in range(1, self.maxn + 1):
            self.x.append(self.x[-1] * pow(i, self.p - 2, self.p) % self.p)
            self.y.append(self.y[-1] * i % self.p)

    def combnk(self, n, k):
        return (self.x[n - k] * self.x[k] * self.y[n]) % self.p

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
c = combnk_mod(n, MOD)
for i in range(1, k + 1):
    if n - k + 1 < i:
        print(0)
    else:
        ans = c.combnk(n - k + 1, i) * c.combnk(k - 1, i - 1)
        print(ans % MOD)


Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int imos[100010];

signed main() {
    int n; cin >> n;
    rep(i,0,n) {
        int a, b; cin >> a >> b;
        imos[a]++;
        imos[b+1]--;
    }
    int ans = 0;
    rep(i,1,100010) {
        imos[i] += imos[i-1];
        if(imos[i] >= i-1) ans = i-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
typedef long long ll;
using namespace std;
 
 
int main(){
    string s; cin >> s;
    if(s.length()%2==1) cout << "No" << endl;
    else{
    for(int i=0; i<s.length(); i=i+2){
        if(s[i]!='h' || s[i+1]!='i'){
            cout << "No" << endl;
            break;
        }
        if(i==s.length()-2) cout << "Yes" << endl;
    }
    }
return 0;
}

Measured memory_bytes: 256
n = input()
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
   
def bfs(u):
  for i in range(n):
    if v[u][i] == 1:
      if d[i] > d[u] + 1:
         d[i] = d[u] + 1
         bfs(i)
    else:
      continue        
def _(): 
 d[0] = 0
 for i in range(n):
   bfs(i)
 for i in range(n):
   if d[i] == 99999:
      d[i] = -1
 for i in range(n):
   print '{0} {1}'.format(i+1, d[i])


for i in range(n):
  G = map(int, raw_input().split())
  for j in range(G[1]):
    v[G[0]-1][G[2+j]-1] = 1

_()

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n, a, b;
vector<int> h;

bool calc(int mid){
    vector<int> t = h;
    rep(i, 0, n) t[i] -= b * mid;
    rep(i, 0, n){
        if(t[i] > 0) mid -= (t[i] + a - b - 1) / (a - b);
    }
    return mid >= 0;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> a >> b;
    h.resize(n);
    rep(i, 0, n){
        cin >> h[i];
    }
    int l = 0, r = 1e9 + 10;
    rep(i, 0, 50){
        int mid = (l + r) / 2;
        if(calc(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		Boolean inside = true;
		if((x - r) < 0) inside = false;
		if((x + r) > W) inside = false;
		if((y - r) < 0) inside = false;
		if((y + r) > H) inside = false;
		System.out.println(inside ? "Yes" : "No");
	}
}



Measured memory_bytes: 26400
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#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 srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  ull n;
  cin >> n;

  auto f = [=](ull t){ull cnt = n/t;return (cnt*(cnt+1)/2);};

  ull ans {};

  srep(i,1,n+1) {
    ans += i*f(i);
  }
  cout << ans << '\n';
}


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

int main(){
  int *A;
  int H, i;

  scanf("%d",&H);
  A = malloc(sizeof(int)*(H+1));
  for(i = 1; i < H+1; i++) scanf("%d",&A[i]);

  for(i = 1; i < H+1; i++){
    printf("node %d: key = %d, ",i,A[i]);

    if(((i/2) >= 1) && ((i/2) < H)) printf("parent key = %d, ",A[i/2]);
    if(((i*2) > 1) && ((i*2) <= H)) printf("left key = %d, ",A[i*2]);
    if(((i*2+1) > 2) && ((i*2+1) <= H)) printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  
  free(A);
  
  return 0;
}



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

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main()
{
    char s[4];
    map<char, int> mp;
    cin >> s;
    rep(i, 4)
    {
        ++mp[s[i]];
    }
    int ans=0;
    for(auto ele : mp){
        if(ele.second == 2){
            ++ans;
        }
    }
    if(ans == 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N; cin>>N;
    vei d(N);
    rep(i,N) cin >> d[i];
    sort(d.rbegin(),d.rend());
    int cnt = 1;
    rep(i,N-1) if(d[i] > d[i + 1]) cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;
int main(){
  ll n,ans=1;cin>>n;
  vll a(n);
  rep(i,0,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  rep(i,0,n){
    if(a[i]>(long double)1000000000000000000/ans){ans=-1;break;}
    ans*=a[i];
    if(ans==0){break;}
  }
  cout<<ans<<endl;
  
}


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

public class Main {
    public static int dpSolution(int n,int k,int a[]){
       int dp[] = new int[n+1];
        Arrays.fill(dp,-1);
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = Math.abs(a[1]-a[2]);
        for(int i=3;i<=n;i++){
            int j= i-k;
            int val = Integer.MAX_VALUE;
            if(j<=0) {
                j = 1;
            }
            for(;j<i;j++){
                 val = Math.min(val,dp[j]+Math.abs(a[i]-a[j]));
                 //System.out.println(i+" "+j+" "+dp[j]+" "+val);

            }
            dp[i] = val;
        }
        return dp[n];
    }
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int a[] = new int[n+1];
        for(int i=1;i<=n;i++){
            a[i] = sc.nextInt();
        }

        System.out.println(dpSolution(n,k,a));

    }
}


Measured memory_bytes: 50692
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, x, t;
    cin >> n >> x >> t;

    if (n % x == 0) {
        cout << t * (n / x) << endl;
    }
    else {
        cout << t * (n / x + 1) << endl;
    }
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

ll mx = 1e18;

int main(){
    int n;
    cin >> n;
    ll ans = 1;
    bool oror = false;
    rep(i, n) {
        ll a;
        cin >> a;
        if (a == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (oror || mx/ans < a || mx < a * ans) {
            oror = true;
        }
        ans *= a;
    }
    if(oror) cout << "-1" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
int main(){
	string s;
	cin>>s;
	ll cur = 0,p = 1,ans = 0;
	ll cnt[2020] = {0};
	cnt[0] = 1;
	int len = s.length() - 1;
	for(int i = len ;i>=0;i--){
		cur = (cur + (ll)(s[i]-'0')*p)%2019;
		ans+=cnt[cur]++;
		p = p*10%2019;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=19,O=1000000007;
int f[1<<N];
int a[N+2][N];
int main(){
	int n=ni-1,m=ni;
	memset(a,-1,sizeof(a));
	for(int tot=ni,u,v;tot--;u=ni,v=ni-1,a[u][v]=ni);
	memset(f,0,sizeof(f));
	f[0]=1;
	for(int i=1;i<=m;i++){
		for(int j=0;j<n;j++){
			for(int s=(1<<n)-1;s>=0;s--){
				int F=f[s];
				if(F){
					f[s]=((s>>j)&1)==0&&a[i][j]!=1?F:0;//go left
					if(a[i][j]!=0){//go right
						if((s>>j)&1){
							f[s]=F;
						}else{
							int lo=s&((1<<j)-1),t=s^lo;
							(f[(t^(t&-t))|(1<<j)|lo]+=F)%=O;
						}
					}
				}
			}
		}
	}
	lint ans=0;
	for(int s=0,ts=1<<n;s<ts;s++){
		ans+=f[s];
	}
	printf("%lld\n",ans%O);
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<cstdio>
#include<map>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 2e5+7;
int a[maxn];
int p[maxn],q[maxn],r[maxn];
int found1(int x)
{
    return x==p[x]?x : p[x] = found1(p[x]);
}
int found2(int x)
{
    return x==q[x]?x : q[x] = found2(q[x]);
}
int main()
{
    int n,l,k;
    cin >> n >> k >> l;
    int a,b;
    for(int i = 0; i < n; i ++)
    {
        p[i] = i;
        q[i] = i;
    }
    for(int i = 0; i < k; i ++)
    {
        scanf("%d%d",&a,&b);
        int x = found1(a),y = found1(b);
        if(x!=y)
        {
            p[x] = y;
        }
    }
    for(int i = 0; i < l; i ++)
    {
        scanf("%d%d",&a,&b);
        int x = found2(a),y = found2(b);
        if(x!=y)
        {
            q[x] = y;
        }
    }
    for(int i = 1; i <= n; i ++)
    {
        found1(i);
        found2(i);
    }
    map<pair<int,int>,int>mp;
    for(int i = 1; i <= n; i ++)
    {
        mp[make_pair(p[i],q[i])]++;
    }
    for(int i = 1; i <= n; i ++)
    {
        cout << mp[make_pair(p[i],q[i])] << " ";
    }
    cout <<endl;
    return 0;
}


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b){
  return (a % b == 0) ? b : gcd(b, a % b);
}

int main(){
  int N;
  ll M;
  while(cin >> N >> M){
    vector<ll> a(N);
    vector<int> p(N);
    REP(i, N) cin >> a[i];
    REP(i, N) cin >> p[i];
    static ll F[1 << 20] = {};
    // 包除原理 (チャレンジブック p.264)
    FOR(S, 1, 1 << N){
      int sign = (__builtin_popcount(S) % 2 == 0) ? -1 : 1;
      ll lcm = 1;
      for (int i = 0; i < N; i++) if(S >> i & 1){
        lcm /= gcd(lcm, a[i]);
        if(LLONG_MAX / lcm < a[i]){
          lcm = LLONG_MAX;
          break;
        }
        lcm *= a[i];
      }
      F[S] = sign * (M / lcm);
    }
    // 高速ゼータ変換 (http://topcoder.g.hatena.ne.jp/iwiwi/20120422/1335065228)
    REP(i, N)REP(S, 1 << N){
      if(0 == (S & (1 << i))){
        F[S | 1 << i] += F[S];
      }
    }
    double ans = 0;
    REP(S, 1 << N){
      double prob = 1;
      REP(i, N) {
        if(S >> i & 1) prob *= p[i] / 100.0;
        else prob *= (100.0 - p[i]) / 100.0;
      }
      ans += prob * F[S];
    }
    printf("%.8lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 9432
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int X;

	cin >> X;

	int ans = 0;


	ans += (X / 500) * 1000;
	X = X % 500;
	ans += (X / 5) * 5;

	cout << ans << endl;

	

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] ND = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            int cnt = 0;
            for(int i = 0; i < ND[0]; i++)
            {
                long[] XY = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
                if(Math.Sqrt(Math.Pow((double)XY[0],(double)2)+ Math.Pow((double)XY[1], (double)2)) <= (double)ND[1])
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 46920
//#pragma Gbb optimize("Ofast") 
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<time.h>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

long long x, y;

int main()
{
	cin >> x >> y;
	long long z = x * y;
	if ((x == 1) || (y == 1)) cout << 1;
	else
	{
		if (z % 2 == 0) cout << z / 2;
		else cout << z / 2 + 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x,n) memset(x,n,sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=l.begin();it!=l.end();it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> pii;
typedef pair<pii,int> piii;
const int inf=(1<<30);
const LL llinf=(1ll<<60);
const double eps=(1e-10);
//const double pi=2*acos(0.0);
//const double GOLD=((1+sqrt(5))/2);
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};
const int kx[8]={1,1,2,2,-1,-1,-2,-2};
const int ky[8]={2,-2,1,-1,2,-2,1,-1};

/* \( Â·wÂ·)~ Clapie ~(Â·wÂ· )/ */

int N,W;
int memo[105][100005];
int val[105],wei[105];

int dp(int idx,int ber){
	if(ber==0) return 0;
	if(ber<0||idx==N) return inf;
	
	if(memo[idx][ber]!=-1) return memo[idx][ber];
	
	return memo[idx][ber]=min(dp(idx+1,ber),dp(idx+1,ber-val[idx])+wei[idx]);
}

int main(){
	scanf("%d%d",&N,&W);
	for(int i=0;i<N;i++){
		scanf("%d%d",&wei[i],&val[i]);
	}
	mem(memo,-1);
	for(int i=100000;i>=0;i--){
		int ans=dp(0,i);
		if(ans<=W){
			printf("%d\n",i);
			return 0;
		}
	}
}

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

int main(){
	int n, x, y,t = 0, maxy, maxx;
	cin >> n;
	bool bl = true;
	for( int i = 0; i < n; ++i ){
		cin >> t >> x >> y;

		int tot = x+y;
		//cout << t << " " << tot << endl;
		if( tot%2 != t%2 || tot > t ){
			bl = false;
		}
		if( !bl ) break;
	}
	if( bl )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
 
int main(){
  int a,b,t;
  cin >>a >> b >> t;
  cout << (t/a)*b;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	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;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	ll n,q;
	string s;
	in(n);
	in(q);


	vll ans(q,0),l(q),r(q);
	vll cntAc(n , 0);
	in(s);

	rep(i, 1, n) {
		cntAc[i] = cntAc[i - 1];
		if (s[i-1] == 'A' && s[i] == 'C') {
			cntAc[i]++;
		}
	}

	rep(i, 0, q) {
		in(l[i]);
		in(r[i]);
	}

	rep(i, 0, q) {
		outn(cntAc[r[i] - 1]-cntAc[l[i]-1]);

	}


	return 0;

}


Measured memory_bytes: 4224
#include<cstdio>
using namespace std;
int gcd(int x,int y){
	int r;
	while(y)
	{
		r=x%y;
		x=y;
		y=r;
	}
	return x;
}
int main()
{
//	freopen("A.in","r",stdin);
	int n,k;
	int mx=0,r,x;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(i==1) r=x;
		else
			r=gcd(r,x);
		if(x>mx) mx=x;
	}
	if(mx<k) printf("IMPOSSIBLE\n");
	else
	{
		if((mx-k)%r)
			printf("IMPOSSIBLE\n");
		else
			printf("POSSIBLE\n");
	}
	return 0;
}


Measured memory_bytes: 128
fn main() {
    proconio::input! {
        n: usize,
        mut k: usize,
        a: [i32;n],
    }
    let mut x=vec![];
    let mut y=vec![];
    let mut z=0;
    for a in a {
        if a>0 {
            x.push(a as u64);
        }
        else if a<0 {
            y.push((-a)as u64);
        }
        else {
            z+=1;
        }
    }
    x.sort();
    y.sort();
    let mut r;
    if x.len()>0 {
        if x.len()+y.len()<k {
            r=0;
        }
        else if x.len()+y.len()==k {
            let odd=y.len()&1==1;
            if z>0 && odd {
                r=0;
            }
            else {
                r=1;
                for a in x {
                    r=r*a%MOD;
                }
                for a in y {
                    r=r*a%MOD;
                }
                if odd {
                    r=(MOD-r)%MOD;
                }
            }
        }
        else {
            r=1;
            if k&1==1 {
                r=x.pop().unwrap();
                k-=1;
            }
            let mut i=x.len();
            let mut j=y.len();
            while k>0 {
                let f = if i>1 && j>1 {
                    x[i-2]*x[i-1]>y[j-2]*y[j-1]
                }
                else {
                    i>1
                };
                if f {
                    r=x[i-2]*x[i-1]%MOD*r%MOD;
                    x.pop();x.pop();
                    i-=2;
                }
                else {
                    r=y[j-2]*y[j-1]%MOD*r%MOD;
                    y.pop();y.pop();
                    j-=2;
                }
                k-=2;
            }
        }
    }
    else {
        if y.len()<k || (k&1==1 && z>0) {
            r=0;
        }
        else if k&1==1 {
            r=1;
            for &a in &y[0..k] {
                r=r*a%MOD;
            }
            r=(MOD-r)%MOD;
        }
        else {
            y.reverse();
            r=1;
            for &a in &y[0..k] {
                r=r*a%MOD;
            }
        }
    }
    println!("{}",r);
}
const MOD: u64=1000000007;

Measured memory_bytes: 6864
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        divisors.sort()
        return divisors

    a,b,k = map(int,input().split())
    a_list = make_divisors(a)
    b_list = make_divisors(b)

    ans = []
    for i in range(len(a_list)):
        if a_list[i] in b_list:
            ans.append(a_list[i])

    ans.reverse()
    print(ans[k-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 13428
fun main(args: Array<String>) {
    var (k, n)=readLine()!!.split(' ').map { it.toInt() }
    var a=readLine()!!.split(' ').map { it.toInt() }

    var max=0
    for(i in 0 until n){
        if (i!=n-1){
            if(a[i+1]-a[i]>max){
                max=a[i+1]-a[i]
            }
        }else{
            if(k-a[i]+a[0]>max){
                max=k-a[i]+a[0]
            }
        }
    }
    println(k-max)
}

Measured memory_bytes: 82724
import sys

N,M = map(int, input().split())

if (N == 1 and M == 0):
    print(0)
    sys.exit()

A = [-1]*N
for i in range(M):
    s,c = map(int, input().split())
    if A[s-1] == -1:
        A[s-1] = c
    elif A[s-1] != c:
        print('-1')
        sys.exit()

if A[0] == -1:
    A[0] = 1

ans = ""
for a in A:
    if a == -1:
        ans += "0"
    else:
        ans += str(a)

ng = ""
if N != 1:
    for _ in range(N):
        ng += "0"

if ng == ans:
    print('-1')
else:
    print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long N, A[200001], i, max=0, max2=0, maxcount=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];

        if(max < A[i]){
            max = A[i];
        }
    }

    for(i=1; i<=N; i++){
        if(max2 < A[i] && A[i] != max){
            max2 = A[i];
        }

        else if(A[i] == max){
            maxcount++;
        }
    }

    for(i=1; i<=N; i++){
        if(A[i] == max){
            if(maxcount == 1){
                cout << max2 << endl;
            }

            else{
                cout << max << endl;
            }
        }

        else{
            cout << max << endl;
        }
    }

    return 0;
}

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

int main()
{
    long long n;
    cin>>n;
    long long heights[n];
    long long dp[n];
    for(int i=0;i<n;i++)
    {
        cin>>heights[i];
        dp[i]=50000;
    }
    dp[0]=0;
    dp[1]=abs(heights[0]-heights[1]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(heights[i]-heights[i-1]),dp[i-2]+abs(heights[i]-heights[i-2]));
    }
    cout<<dp[n-1]<<endl;
}


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

const int N = 1005, mod = 1000 * 1000 * 1000 + 7;

int a[N];
int b[N];
bool markr[N * N];
bool markc[N * N];

int main() {
	int n, m, r = 0, c = 0;
	bool rp = false;
	long long ans = 1;
	cin >> n;
	cin >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (markr[a[i]])
			rp = true;
		markr[a[i]] = true;
	}
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		if (markc[a[i]])
			rp = true;
		markc[a[i]] = true;
	}
	if (rp)
		cout << 0 << endl;
	else {
		for (int i = n * m; i >= 1; i--) {
	//		cout << i << " " << markr[i] << " " << markc[i] << " " << ans << endl;
			if (markr[i]) {
				r++;
				if (markc[i]) {
		//			ans *= (n - r) * (m - c);
					c++;
				}
				else {
					ans *= c;
				}
			}
			else {
				if (markc[i]) {
					ans *= r;
					c++;
				}
				else {
					int x = r * c - n * m + i;
					ans *= x;
				}
			}
			ans %= mod;
		}
		cout << ans << endl;
	}

	return 0;
}


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

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int N;
    unordered_map<string, int> m;
    cin >> N;

    // count
    int max_cnt = 0;
    rep(i, 0, N)
    {
        string S;
        cin >> S;
        ++m[S];

        max_cnt = max(max_cnt, m[S]);
    }

    // extract
    vector<string> res;
    for (auto item: m)
    {
        if (item.second == max_cnt)
            res.push_back(item.first);
    }

    // sort
    sort(res.begin(), res.end());
    // output
    for (auto r: res)
        cout << r << endl;
    return 0;
}


Measured memory_bytes: 28612
#include<bits/stdc++.h>
using namespace std;
int ans[1000006], n, m, k;
int main() {
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i ++)
        for (int j = 0; j <= m; j ++) {
            ans[i * m + j * n - 2 * i * j] = 1;
        }
    cout << (ans[k] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 4096
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = list(map(lambda x:int(x)*2 , input().split()))
se = 0
for i in range(n):
    se = A[i] - se
    #print(se)
x = se//2
cur = x
ans = []
for i in range(n):
    ans.append(cur)
    cur = A[i] - cur
print(*ans)


Measured memory_bytes: 14308
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpr make_pair
#define mt make_tuple
 
using namespace std;
 
const ll N = 1010;
const ll mod = 1e9 + 7;
ll power(ll x, ll   y, ll p){ ll res = 1; x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;} return res; }
ll dp[N][N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    string s;
    vector<string> board;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>s;
        board.pb(s);
    }
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i == 0 && j == 0)    continue;
            if(board[i][j] != '#'){
                dp[i][j] = (i > 0) ? dp[i-1][j] : 0;
                dp[i][j] += (j > 0) ? dp[i][j-1] : 0;
                dp[i][j] = dp[i][j]%mod;
            }
            else    dp[i][j] = 0;
        }
    }
    cout<<dp[n-1][m-1]<<endl;
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	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;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll N, A, B, C;
	cin >> N >> A >> B >> C;

	vll l(N);
	rep(i, 0, N) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());

	set<pair<ll, vll>> st({ {0,l} });
	ll cnter = 0;
	ll ans = ll_max;
	for (auto x:st) {
		cnter++;
		if (cnter > 10000) {
			cnter = 0;
		}
		l = x.second;
		ll cnt = x.first;
		N = l.size();
		if (2<N && cnt < ans) {
			rep(i, 0, N - 2) {
				rep(j, i + 1, N - 1) {
					rep(k, j + 1, N) {
						ans = min(ans, cnt + abs(l[i] - C) + abs(l[j] - B) + abs(l[k] - A));
					}
				}
			}
			rep(i, 1, (1LL << N)) {
				vll m;
				ll val = 0;
				ll num = -1;
				rep(j, 0, N) {
					if (i & (1LL << j)) {
						val += l[j];
						num++;
					}
					else {
						m.push_back(l[j]);
					}
				}
				if (num > 0) {
					m.push_back(val);
					sort(m.begin(), m.end());
					st.insert({ cnt + num * 10,m });
				}
			}
		}
	}

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


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

int main() {
	int N,K,X,Y;
  	cin >> N >> K >> X >> Y ;
  
  	if(N > K){
      cout << K*X+(N-K)*Y <<endl;
    }
    else{
      cout << N*X <<endl;
    }
}


Measured memory_bytes: 3508