akhauriyash/Code-Regression huggingface dataset:
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
  ll a, b, n;
  cin >> a >> b >> n;
  if(b <= n) {
    cout << (a * (b - 1)) / b << endl;
  } else {
    cout << (a * (n)) / b << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int mod, a[N];
int powmod(int a, int b)
{
	int ans = 1;
	while(b)
	{
		if(b&1) ans = 1ll*ans*a%mod;
		a = 1ll*a*a%mod;
		b >>= 1;
	}
	return ans;
}
int inv(int x)
{
	return powmod(x, mod-2);
}
vector<int> mul(vector<int> p, int t) //return p*(x-t) O(n)
{
	int deg = (int)p.size();
	vector<int> r(deg+1, 0);
	for(int i=0; i<deg; i++) r[i+1] = (r[i+1] + p[i])%mod;
	for(int i=0; i<deg; i++) r[i] = (r[i] + 1ll*p[i]*t%mod)%mod;
	return r;
}
vector<int> div(vector<int> p, int t) //return p/(x-t) O(n)
{
	int deg = (int)p.size();
	vector<int> r(deg-1, 0);
	for(int i=deg-1; i>0; i--)
	{
		p[i-1] = (p[i-1] + 1ll*t*p[i]%mod)%mod;
		r[i-1] = p[i];
	}
	return r;
}
int get(vector<int> f, int x) //return f(x) O(n)
{
	int ans = 0, tmp = 1, deg = (int)f.size();
	for(int i=0; i<deg; i++)
	{
		ans = (ans + 1ll*f[i]*tmp%mod)%mod;
		tmp = 1ll*tmp*x%mod;
	}
	return ans;
}
int main()
{
	scanf("%d", &mod);
	int p = mod;
	for(int i=0; i<p; i++) scanf("%d", &a[i]);
	vector<int> t = {0, 1}; //x
	for(int i=1; i<p; i++) t = mul(t, i);
	vector<int> f(p, 0);
	for(int i=0; i<p; i++)
	{
		if(!a[i]) continue;
		vector<int> g = div(t, i);
		int cur = inv(get(g, i));
		for(int i=0; i<(int)g.size(); i++) f[i] = (f[i] + 1ll*g[i]*cur%mod)%mod;
	}
	for(int x : f) printf("%d ", x);
	return 0;
}

Measured memory_bytes: 3768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iM = int.Parse(sS[1]);
            List<ClsSmp> lstMem = new List<ClsSmp>();           // 人
            List<ClsSmp> lstChk = new List<ClsSmp>();           // CK
            for (int i = 0; i < iN; i++) { sS = Console.ReadLine().Trim().Split(' '); lstMem.Add(new ClsSmp() { iX = int.Parse(sS[0]), iY = int.Parse(sS[1]) }); }
            for (int i = 0; i < iM; i++) { sS = Console.ReadLine().Trim().Split(' '); lstChk.Add(new ClsSmp() { iX = int.Parse(sS[0]), iY = int.Parse(sS[1]) }); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            for (int i = 0; i < lstMem.Count; i++)
            {
                List<ClsDif> lstDif = new List<ClsDif>();           // 距離
                for (int j = 0; j < lstChk.Count; j++)
                {
                    int iDid = Math.Abs(lstMem[i].iX - lstChk[j].iX) + Math.Abs(lstMem[i].iY - lstChk[j].iY);
                    lstDif.Add(new ClsDif() { iC = j , iD = iDid });
                }
                if (lstDif.Count > 1) { lstDif.Sort(delegate (ClsDif mca1, ClsDif mca2) { return (int)(mca1.iD - mca2.iD) == 0 ? (mca1.iC - mca2.iC) : (mca1.iD - mca2.iD); }); }     // iDの昇順 の iCの昇順
                lstMem[i].iC = lstDif[0].iC + 1;
            }

            //出力
            for (int i = 0; i < lstMem.Count; i++)
            {
                Console.WriteLine("{0}", lstMem[i].iC.ToString().Trim());
            }

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
        private class ClsSmp
        {
            public int iX { get; set; } = 0;
            public int iY { get; set; } = 0;
            public int iC { get; set; } = 0;            // 最短CK No.
        }

        private class ClsDif
        {
            public int iC { get; set; } = 0;            // CK No.
            public int iD { get; set; } = 0;            // 距離
        }
}


Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for ( int i = 0; i < n; i++ ) cin >> R[i];

  int maxv = -2000000000; // ???????°??????????????????????????¨????
  int minv = R[0];

  for ( int i = 1; i < n; i++ ) {   // ????????§?????? R[i] ?????????????????°??????????????????
    maxv = max(maxv, R[i] - minv);  // ?????§????????´??°
    minv = min(minv, R[i]);         // ???????????§???????°?????????????????????????
  }

  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 1940
#include <iostream>

using namespace std;

long long cub(int x) {
    return 1ll * x * x * x;
}

int main() {
    int n, k;
    cin >> n >> k;
    if (k & 1) {
        cout << cub(n/k) << endl;
    } else {
        k /= 2;
        cout << cub((n+k)/k/2) + cub(n/k/2) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
S=list(input())
pas=0
kai=0
for i in range(len(S)):
    if S[i]=='a':
        if pas<A+B:
            print('Yes')
            pas+=1
        else:
            print('No')
    elif S[i]=='b':
        kai+=1
        if pas<A+B and kai<=B:
            print('Yes')
            pas+=1
        else:
            print('No')
    else:
        print('No')


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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)1e5) + 5;

int n;
int arr[N];
int narr[N];
int ans;
map<int,int> ind;

int main ()
{
	scanf("%d",&n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d",&arr[i]);
		narr[i] = arr[i];
		ind[arr[i]] = i % 2;
	}
	sort(narr + 1, narr + n + 1);
/*	for (int w = 1; w <= 100; w++)
	{
		for (int i = 1; i <= n; i++)
		{
			if (arr[i + 2] == -1)
				break;
			if (arr[i] > arr[i + 2])
				swap(arr[i],arr[i + 2]);
		}
	}*/
	for (int i = 1; i <= n; i++)
	{
		if (ind[narr[i]] != ind[arr[i]])
		{
			ans++;
		}
	}
	if (ans == 0)
		return printf("0"),0;
	printf("%d",ans / 2);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
 
#define MOD 1000000007
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int x;
	cin >> x;
    vector<int> vec(500000);
    for(int i=1; i<100; i++){
      for(int j=1; j<150; j++){
        for(int k=1; k<200; k++){
          int n = k*k + j*j + i*i +k*j +j*i +i*k;
          vec.at(n) += 1;
        }
      }
    }
    for(int i=1; i<=x;i++){
      cout << vec.at(i) << endl;
    }
  
}

Measured memory_bytes: 5308
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
bool isPrime(ll n); // 素数か
vector<ll> primes(ll n); // 素因数分解
int ctoi(char c){return c - '0';}

const ll COM_MAX = (ll)(1e6+100); // combinationの最大値
vector<ll> fac(COM_MAX),finv(COM_MAX),inv(COM_MAX);
void comb_init(); // 初期化
ll comb(ll n,ll k); // nCk


template<typename T>bool isOk(int key,T value){
  return key <= value.fi;
}
template<typename T>T binary_search(vector<pair<int,int>> a,T key){
  T ok = a.size();
  T ng = -1;
  while(abs(ok - ng) > 1){
    T mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

// TODO: write
int main() { 
  int n;cin>>n;
  ll ans = 0;
  rep(i,n)ans += i;
  print(ans);
  return 0;
}




void comb_init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<COM_MAX;++i){
    fac[i]=fac[i-1]*i%INF;
    inv[i]=INF-inv[INF%i]*(INF/i)%INF;
    finv[i]=finv[i-1]*inv[i]%INF;
  }
}

ll comb(ll n,ll k){
  if(n<k)return 0;
  if(n<0||k<0)return 0;
  return fac[n]*(finv[k]*finv[n-k]%INF)%INF;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}


/* 二分探索の時に使う
template<typename T>bool isOk(T key,T value){
  return key <= value;
}
template<typename T>T binary_search(vector<T> a,T key){
  T ok = a.size();
  T ng = -1;
  while(abs(ok - ng) > 1){
    T mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}
*/

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        n=n/10;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <math.h>

using namespace std;

int main(){
  int N, Nbuf;
  cin >> N; Nbuf = N;
  int har = 0;
  int i;

  while(N != 0){
    har += N % 10;
    N /= 10;
  }

  //cout << N << " " << Nbuf << endl;                                  

  if( Nbuf % har == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,m,ans=0;
int a[1000],b[1000];
bool flag[10];
vector<int>con[10];
void dfs(int d,int w){
    if(w==n){
        ans++;
        return;
    }
    int l=con[d].size();
    rep(i,l){
        if(flag[con[d][i]]==false){
            flag[con[d][i]]=true;
            dfs(con[d][i],w+1);
            flag[con[d][i]]=false;
        }
    }
    return;
}
signed main(){
    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i];
        con[a[i]].push_back(b[i]);
        con[b[i]].push_back(a[i]);
    }
    flag[1]=true;
    dfs(1,1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    int64_t K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, 0, N) cin >> A.at(i);
    vector<int> B = {1};
    vector<bool> C(N, true);
    vector<int64_t> D(N, 0);
    int64_t i = 0, loop;
    while(true){
        int j = B.at(i) - 1;
        if (C.at(j)){
            B.push_back(A.at(j));
            C.at(j) = false;
            D.at(j) = i;
            i++;
        }
        else {
            loop = j;
            break;
        }
    }
    int64_t L;
    if (K > i){
        L = (K - D.at(loop)) % (i - D.at(loop));
        cout << B.at(L + D.at(loop)) << endl;
    }
    else{
        L = K;
        cout << B.at(L) << endl;
    }
    //cout << K - D.at(loop) << " " << i - D.at(loop) << endl;
}

Measured memory_bytes: 6692
n = int(input())
As = list(map(int, input().split()))
flag = True

for a in As:
    if a%2 == 0:
        if a%3 == 0 or a%5 == 0:
            pass
        else:
            flag = False
if flag:
    print('APPROVED')
else:
    print('DENIED')

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

int main() {
  
  int N;
  cin>>N;
    
  for(int i=0;i<N;i++){
    string a;
    cin>>a;
    
      if(a=="Y"){
        cout<<"Four";
        break;
      }
    
      if(i==N-1){
      cout<<"Three";
      }
   
   }
  
    cout<<endl;
  
}


Measured memory_bytes: 256
n=int(input())

X=list(map(int,input().split()))
Y=[]
for i in range(n):
    Y.append(X[i]-(i+1))
Y.sort()
res_1=0

if n%2==1:
    m=Y[int((n-1)/2)]
    for j in range(n):
        res_1+=abs(Y[j]-m)
else:
    m=(Y[int(n/2)-1]+Y[int(n/2)])//2
    for j in range(n):
        res_1+=abs(Y[j]-m)
        

        
print(res_1)


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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(), a.end());
	ll mx=a[sz(a)-1];
	if(n==2){
		cout<<mx;
	}
	else{
		ll ans=mx;
		ll kerek=n-2;
		kerek/=2;
		int i;
		for(i=n-2;i>=1;i--){
			ans+=2*a[i];
			kerek--;
			if(kerek==0)break;
		}
		if((n-2)&1)ans+=a[--i];
		cout<<ans;
	}

}

Measured memory_bytes: 4776
#include <iostream>
#define MAXN 100001

using namespace std;

int height[MAXN];

int getCost(int a,int b){
	return abs(height[a]-height[b]);
}

int main()
{	
	int n, k;
	cin >> n >> k;

	for (int i=0; i<n; i++)
	{
		cin >> height[i];
	}

 	int dp[n];
	dp[0]=0;
	int loops=0;

 	for (int i=1; i<n; i++)
 	{	

 		if (i<k){
 			loops=i;
 		}else {
 			loops=k;
 		}

 		dp[i] = getCost(i-1,i) + dp[i-1];
		for (int j=1; j<loops+1; j++){
 			dp[i] = min(dp[i],getCost(i,i-j) + dp[i-j]);
 		}

 		//cout << dp[i] << endl;
 	}

 	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 4348
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = III()

d = defaultdict(list)
for i in range(N):
    A[i] = format(A[i],'b').zfill(20)
    for j,k in enumerate(A[i]):
        if k=='1':
            d[i].append(j)

used = [False]*20
l = 0
r = 0
ans = 0
for j in d[0]:
    used[j] = True

while l<=N-1:
    ans += r-l+1
    for i in range(r+1,N):
        if all([used[j]==False for j in d[i]]):
            for j in d[i]:
                used[j] = True
            r += 1
            ans += 1
        else:
            break
    for j in d[l]:
        used[j] = False
    l += 1
    if l>r:
        r = l
        for j in d[l]:
            used[j] = True
    
print(ans)

Measured memory_bytes: 132080
A,B,K = map(int,input().split())
l = set()

for i in range(K):
    if A+i <= B :
       l.add(A+i)
    else:
       continue
for j in range(K):
    if B-j >= A:
       l.add(B-j)
    else:
       continue
list = list(l)
list.sort()
for i in range(len(list)):
    print(list[i])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, K;
  cin >> N >> K;
  if (K % 2 == 1) {
    int p = N / K;
    cout << p * p * p << "\n";
  } else {
    int p = N / K;
    int q = (N + K / 2) / K;
    cout << p * p * p + q * q * q << "\n";
  }
  // print();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, k;
    cin >> n >> k;

    int64_t ans = 0;
    for (auto i : irange(0L, n)) {
        int64_t x;
        cin >> x;
        if (abs(x) < abs(x - k)) {
            ans += 2 * abs(x);
        } else {
            ans += 2 * abs(x - k);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
l = np.array(list(map(int,input().split())))

counter = 0
lenl = len(l)
for i in range(lenl):
  for j in range(i+1,lenl):
    for k in range(j+1,lenl):
      if l[i] == l[j] or l[j] == l[k] or l[i] == l[k]:
        continue
      if max([l[i],l[k],l[j]]) >= l[i]+l[k]+l[j]-max([l[i],l[k],l[j]]):
        continue
      else:
        counter += 1
print(counter)

Measured memory_bytes: 27168
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	ll X;
	scanf("%lld",&X);

	ll num = 100;
	int ans = 0;

	while(true){

		if(num >= X)break;

		num = num+num/100;
		ans++;
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3824
#!/usr/bin/env python3
import sys


def solve(N: int, A: str, B: str, C: str):
    ret = 0
    for i in range(N):
        if A[i] == B[i] == C[i]:
            ret += 0
        elif A[i] == B[i] or B[i] == C[i] or A[i] == C[i]:
            ret += 1
        else:
            ret += 2
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = next(tokens)  # type: str
    B = next(tokens)  # type: str
    C = next(tokens)  # type: str
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

vector<ll> inv,fac;

void inverse(ll n){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}

void inverse_u(ll n){
    //要素数:n+1 (0~n)
    for(ll i=2;i<=n;i++){
        inv[i]=(inv[i]*inv[i-1])%MOD;
    }
}

void factorial(ll n){
    //要素数:n+1 (0~n)
    fac[0]=1;
    fac[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=(fac[i-1]*i)%MOD;
    }
}

ll nCr(ll n,ll r){
    return fac[n]*inv[r]%MOD*inv[n-r]%MOD;
}

ll proinverse(ll x,ll m){
    ll res=1,M=m-2;
    while(M>0){
        if(M&1) res=res*x%m;
        x=x*x%m;
        M>>=1;
    }
    return res;
}

void init_nCr(ll n){
    inv.assign(n+1,0);
    fac.assign(n+1,0);
    inverse(n); inverse_u(n);
    factorial(n);
}

int main(){
    init_nCr(2000001);
    ll r1,c1,r2,c2,ans=0; cin>>r1>>c1>>r2>>c2;
    for(ll i=r1+1;i<=r2+1;i++){
        ans=(ans+nCr(i+c2,c2)-nCr(i+c1-1,c1-1))%MOD;
    }
    cout<<(MOD+ans)%MOD<<endl;
}


Measured memory_bytes: 34152
from collections import deque, defaultdict
n, x, y = map(int, input().split())
 
edges = defaultdict(lambda: [])
for i in range(1, n):
    edges[i].append(i+1)
    edges[i+1].append(i)
edges[x].append(y)
edges[y].append(x)
 
# 幅優先
counter = [0 for i in range(n)]
for i in range(1, n+1):
    d = deque()
    dist = [-1 for _ in range(n+1)]
    d.append((i, -1))
    while len(d) > 0:
        e, pre_dist = d.popleft()
        if dist[e] > -1:
            continue
        else:
            dist[e] = pre_dist + 1
            for next_e in edges[e]:
                if dist[next_e] == -1:
                    d.append((next_e, pre_dist+1))
    for j in range(i+1, n+1):
        counter[dist[j]] += 1
print("\n".join(list(map(str, counter[1:]))))

Measured memory_bytes: 49500
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n,m; cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        ll d; cin>>d;
        mp[d]++;
    }
    cin>>m;
    bool ok=true;
    rep(i,m){
        ll t; cin>>t;
        mp[t]--;
    }
    for(auto x:mp) if(x.second<0) ok=false;
    if(ok) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 16152
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++) {
    s[i] = (s[i] - 'A' + n) % 26 + 'A';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        
        selection_sort A = new selection_sort(a);
        int[] ans = A.C;
        for(int i=0;i<N-1;i++){
            System.out.print(ans[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(A.Nswap);
        
        
        
        
    }
    
}

class selection_sort{
    int[] C;
    int Nswap = 0;
    selection_sort(int[] C){
        for(int i = 0; i<C.length; i++){
            int mini = i;
            for(int j = i; j<C.length; j++){
                if(C[j]<C[mini]){
                   mini = j; 
                }
            }
            if(mini!=i){
                int tmp = C[i];
                C[i] = C[mini];
                C[mini] = tmp;
                Nswap++;
            }
        }
        this.C = C;
        
    }
}

Measured memory_bytes: 24420
#include<stdio.h>

int main(){
    int S;

    scanf("%d",&S);

    if((S/100==0 || S/100>12) && (S%100==0 || S%100>12)) printf("NA");
    else if((S/100==0 || S/100>12) && (S%100>=1 || S%100<=12)) printf("YYMM");
    else if((S/100>=1 || S/100<=12) && (S%100==0 || S%100>12)) printf("MMYY");
    else printf("AMBIGUOUS");



    return 0;
}

Measured memory_bytes: 128
"use strict"

const Main = (nyuuryoku)=>{
const Array=nyuuryoku.split(/\n/)
const N=Array[0]-0
const cardNumber=Array[1].split(" ").map((ele)=>{return ele-0}).sort((a,b)=>{return b-a})

let AliceScore=0
let BobScore=0

for(let i=0;i<=cardNumber.length-1;i+=1){
 (i%2==0)?  AliceScore+=cardNumber[i] : BobScore+=cardNumber[i] 
 }

console.log(AliceScore - BobScore)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
n = gets.to_i
a = gets.split().map(&:to_i)
b = gets.split().map(&:to_i)

c = 0
(0..n-1).each do |i|
  if b[i] >= a[i]
    c += a[i]
    b[i] -= a[i]
    if b[i] >= a[i+1]
      c += a[i+1]
      a[i+1] = 0
    else
      c += b[i]
      a[i+1] -= b[i]
    end
  else
    c += b[i]
  end
end

puts c

Measured memory_bytes: 15396
function main (input) {
    var N = input.split('\n')[0];
    var card = input.split('\n')[1].split(' ')
                    .map(function(e){return Number(e);})
                    .sort(function(a,b){return a-b;});
    var a = 0;
    var b = 0;
    for (var n = 0; n < N; n++) {
        if (n%2 === 0){
            a = a + card[card.length-1];
            card.pop();
        } else {
            b = b + card[card.length-1];
            card.pop();
        }
    }
    console.log(Math.abs(a-b));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>
 
using namespace std;
 
#define BUF_SIZE 1024
#define ARRAY_SIZE 100
 
int main(){
 
    char buf[BUF_SIZE] = {0};
    int n = atoi(fgets(buf,BUF_SIZE,stdin));
 
    int array[ARRAY_SIZE] = {0};
 
    for(int i = 0; i < n; i++){
        cin >> array[i];
    }
 
    for(int k = 0;k < n; k++){
        if(k != n-1){
            printf("%d ",array[k]);
        }else{
            printf("%d\n",array[k]);
        }
    }
 
    int v = 0;
    int j = 0;
    for(int i = 1; i < n; i++){
        v = array[i];
        j = i-1;
        while(j >= 0 && array[j] > v){
            array[j+1] = array[j];
            j--;
        }
        array[j+1] = v;
        for(int k = 0;k < n; k++){
            if(k != n-1){
                printf("%d ",array[k]);
            }else{
                printf("%d\n",array[k]);
            }
        }
    }
 
}


Measured memory_bytes: 3232
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/services/room.html#ACPC2018Day2/problems/A>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll P; cin >> P;
    cout << P/500*500 << endl;
    return 0;
}



Measured memory_bytes: 3204
#include<iostream>
#include<string>
 
using namespace std;
 
int main()
{
  int a, b;
  string op;
   
  while(true)
    {
      cin >> a >> op >> b;
       
      if (op == "+")
        cout << a + b << endl;
      else if (op == "-")
        cout << a - b << endl;
      else if (op == "*")
        cout << a * b << endl;
      else if (op == "/")
        cout << a / b << endl;
      else if (op == "?")
        break;
    }
  return 0;
}

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

using namespace std;

#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

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

const int N = 200200;
ll h,w,H,W,ans[505][505];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>h>>w>>H>>W;
	int forevery=1e9-1;
	if(H*W==1)
		return cout<<"No",0;
	if(h%H==0&&w%W==0)
		return cout<<"No", 0;
	forevery/=(H*W-1);
	int mxi=0,mxj=0;
	for(int i=0;i<=h;i+=H)
	{	
		for(int j=0;j<=w;j+=W)
		{	
			ans[i][j]=-1e9;
		    mxj=j;
		}
		mxi=i;
	}
	fo(i,mxi)
		fo(j,mxj)
			if(!ans[i][j])
				ans[i][j]=forevery;
	for(int row=mxi;row<=h;row++)
	{
		ll sum=0;
		int cnt=0;
		fo(i,H)
			fo(j,W)
			{
				sum+=ans[row-i+1][w-j+1];
				if(ans[row-i+1][w-j+1]==0)
					++cnt;
			}
		if(cnt>0)
		{
			int forevery = (-sum-1)/cnt;
			fo(i,H)
				fo(j,W)
		    		if(ans[row-i+1][w-j+1]==0)
		    			ans[row-i+1][w-j+1] = forevery;
		}
	}
	for(int col=mxj;col<=w;col++)
	{
		ll sum=0;
		int cnt=0;
		fo(i,H)
			fo(j,W)
			{
				sum+=ans[h-i+1][col-j+1];
				if(ans[h-i+1][col-j+1]==0)
					++cnt;
			}
		if(cnt>0)
		{
			int forevery = (-sum-1)/cnt;
			fo(i,H)
				fo(j,W)
		    		if(ans[h-i+1][col-j+1]==0)
		    			ans[h-i+1][col-j+1] = forevery;
		}
	}
	ll s = 0;
	fo(i,h)fo(j,w)
		s+=ans[i][j];
	if(s<=0)
		return cout<<"No", 0;
	cout<<"Yes\n";
	fo(i,h)
	{
		fo(j,w)
			cout<<ans[i][j]<<' ';
		cout<<"\n";
	}
	return 0;
}


Measured memory_bytes: 4864
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk; 
     cin>>n;
     cout<<pow(n,1)+pow(n,2)+pow(n,3)<<endl;
	 
} 

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

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

  while (1)
  {
    S.pop_back();

    string s1 = S.substr(0, (S.size() / 2));
    string s2 = S.substr(S.size() / 2);
    if (s1 == s2)
    {
      cout << S.size() << endl;
      return 0;
    }
  }
}


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

int main()
{
    int N;
    string S;
    int dp[1006][8] = {};
    map < char, int > mp;
    mp['J'] = 1, mp['O'] = 2, mp['I'] = 4;

    cin >> N >> S;
    dp[0][1] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 8; j++) {
            for(int k = 0; k < 8; k++) {
                if(k & j && mp[S[i]] & k) (dp[i + 1][k] += dp[i][j]) %= 10007;
            }
        }
    }
    cout << accumulate(dp[N], dp[N + 1], 0) % 10007 << endl;
    return (0);
}



Measured memory_bytes: 3168
#include<stdio.h>

int main(){
	long long int n;
	long long int a;
	scanf("%lld", &n);
	long long int c = 0;
	for(long long int i = 1; i <= n; i++){
		a = i;
		if(i % 3 == 0 || i % 5 == 0 || i % 15 == 0){
			a = 0;
		}
		c = c + a;
	}
	printf("%lld", c);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


int main(){
    
    fastio;
    
    string s;
    cin >> s;
    if (cpresent(s, '7')){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }

    return 0;
}


Measured memory_bytes: 3652
n = gets.to_i

candidate = { 
    1 => '.,!? ',
    2 => 'abc',
    3 => 'def',
    4 => 'ghi',
    5 => 'jkl',
    6 => 'mno',
    7 => 'pqrs',
    8 => 'tuv',
    9 => 'wxyz',
}

n.times {
    gets.chomp.scan(/([^0]+)0+/).flatten(1).each{|s|
        cs = candidate[s[0].to_i]
        print cs[(s.size-1) % cs.size]
    }   
    puts
}

Measured memory_bytes: 6104
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
a.sort(reverse=True)
sm = 0
for i in range(1,n):
    sm += a[i//2]
print(sm)


Measured memory_bytes: 94060
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> A(N), B(M);
    rep(i, N) {
        cin >> A[i].first;
        A[i].second = i;
    }
    rep(i, M) {
        cin >> B[i].first;
        B[i].second = i;
    }
    sort(all(A), greater<pair<int, int>>());
    sort(all(B), greater<pair<int, int>>());

    int h = 0, w = 0;
    vector<int> hset(N), wset(M);
    ll ans = 1;
    for (int n = N * M, i = 0, j = 0; n > 0; --n) {
        if (i < N && n == A[i].first && j < M && n == B[j].first) {
            h++; w++;
            i++; j++;
        }
        else if (i < N && n == A[i].first) {
            ans = ans * w % MOD;
            h++;
            i++;
        }
        else if (j < M && n == B[j].first) {
            ans = ans * h % MOD;
            w++;
            j++;
        }
        else {
            ans = ans * (h * w - (N * M - n)) % MOD;
        }
    }

    write(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using ll = long long;
const ll MOD=1e9+7;
const long long INF = 1LL<<60;

int main() {
    int n;
    cin >> n;

    cout << (n + 2 - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int maxn=2050;
ll dp[maxn];
int n;

void solve(){
	scanf("%d",&n);
	dp[0]=1;
	for(int i=3;i<=n;i++){
		for(int j=3;j<=i;j++){
			dp[i]=(dp[i]+dp[i-j])%MOD;
		}
	}
	printf("%lld\n",dp[n]);
}
int main(){
	solve();
	return 0;
}

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

const int N = 3000, mod = 1e9 + 7;

int n;
double ans = 0, a[N], dp[N][N];

signed main() {
	int n;
	cin >> n;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		dp[i][0] = dp[i - 1][0] * (1 - a[i]);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1 - a[i]);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (i > n - i) {
			ans += dp[n][i];
		}
	}
	printf("%.9f\n", ans);
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if (s.front() != '1' || s.back() != '0'){
        cout << - 1 << endl;
        return 0;
    }
    for (int i = 0; i < n - 1; i++){
        if (s[i] != s[n - i - 2]){
            cout << - 1 << endl;
            return 0;
        }
    }
    int now = 1;
    for (int i = 0; i < n - 1; i++){
        cout << now << " " << i + 2 << endl;
        if (s[i] == '1') now = i + 2;
    }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    string s;
    cin>>s;
    int p=1;
    bool ok=1;
    if(s.back()=='1'||s[0]=='0') ok=0;
    for(int i=0;i<s.length()-1;i++)
    {
        if(s[i]!=s[s.length()-2-i]) ok=0;
    }
    if(!ok) print(-1);
    else{
        for(int i=0;i<s.length()-1;i++)
        {
            if(s[i]=='1')
            {
                cout<<p<<" "<<i+2<<'\n';
                p=i+2;
            }
            else{
                cout<<p<<" "<<i+2<<'\n';
            }
        }
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  if(B / K > (A - 1) / K) cout << "OK" << endl;
  else cout << "NG" << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void print(){cout;}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    println(forward<Tail>(tail)...);
}

void solve(){
    int x; 
    cin >> x;
    if (x) println(0);
    else println(1);
}

void test(ll num = 0, bool verbose = false){
    rep(i, max(1LL, num)){
        ll t = clock();
        if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
        solve();
        if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef _LOCAL
        test(6, true);
    #else
        ll t = 0;
        if (multiple_queries) cin >> t;
        test(t, false);
    #endif
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        Arrays.sort(array);
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum += array[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 38844
import java.util.*;

public class Main{
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		for(int i = 0; i < N; i++) {
			int input = sc.nextInt();
			X[i] = input;
			Y[i] = input;
		}
		Arrays.sort(X);
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] != Y[i])count++;
		}
		System.out.println((count <= 2)?"YES":"NO");
		}
}

Measured memory_bytes: 21844
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Integer[] array = new Integer[m];
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		List<Integer> list_x=new ArrayList<Integer>();
		List<Integer> list_y=new ArrayList<Integer>();
		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list_x.add(a);
		}
		for(int i=0;m>i;i++) {
			int a = sc.nextInt();
			list_y.add(a);
		}

		for(int i=x+1;y+1>i;i++) {
			int x_max = Collections.max(list_x);
			int y_min = Collections.min(list_y);
			if(i>x_max&&i<=y_min) {
				System.out.println("No War");
				//System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println("War");
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b;
    cin>>k>>a>>b;
   if(a%k==0||b%k==0)
   {
       cout<<"OK"<<endl;
   }
   else
   {
       int m=a/k;
       if((m+1)*k>b)
        cout<<"NG"<<endl;
       else
        cout<<"OK"<<endl;
   }

}

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

using namespace std;

/*
 * 2 ** 39 < 10 ** 12 < 2 ** 40
 */

int main()
{
  long long h;
  cin >> h;

  int k_min = 0;
  for (int k = 0; k < 41; k++)
  {
    if (pow(2, k) > h)
    {
      k_min = k;
      break;
    }
  }

  vector<long long> s(k_min + 1, 1);
  for (int k = 0; k < k_min; k++)
  {
    s[k + 1] = 2 * s[k] + 1;
  }

  cout << s[k_min - 1] << endl;

}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let T: usize = sc.get();
    let mut AB = Vec::new();
    for _ in 0..N {
        let A: usize = sc.get();
        let B: usize = sc.get();
        AB.push((A, B));
    }
    AB.sort_by_key(|&(a, _)| a);
    let mut dp = vec![vec![0; T]; N+1];
    for i in 0..N {
        let (A, B) = AB[i];
        for t in 0..T {
            if t >= A {
                dp[i+1][t] = max(dp[i+1][t], dp[i][t-A] + B);
            }
            dp[i+1][t] = max(dp[i+1][t], dp[i][t]);
        }
    }
    let mut ans = 0;
    for i in 0..N {
        let (_, B) = AB[i];
        ans = max(ans, dp[i][T-1] + B);
    }
    println!("{}", ans);
}


Measured memory_bytes: 72636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
        
        int counta = 0;
        for (int i = n - 1; i >= 0; i--) {
            char c = str.charAt(i);
            
            if (c == ')') {
                counta++;
            } else {
                if (counta > 0) {
                    counta--;
                }
            }
        }
        
        String stra = "";
        while (counta-- > 0) {
            stra += "(";
        }
        
        counta = 0;
        for (int i = 0; i < n; i++) {
            char c = str.charAt(i);
            
            if (c == '(') {
                counta++;
            } else {
                if (counta > 0) {
                    counta--;
                }
            }
        }
        
        String strb = "";
        while (counta-- > 0) {
            strb += ")";
        }       
        
        System.out.println(stra + str + strb);
    }
}


Measured memory_bytes: 21972