akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

void step(string& s) {
  string t(s.size()-1, '0');
  REP(i, s.size()-1) {
    t[i] += abs(s[i]-s[i+1]);
  }
  swap(s, t);
}

// 1-stepすすめると0, 1, 2だけになる
//

int comb_parity(int64 a, int64 b) {
  int64 ret = 1;
  while (a) {
    if (a%2 == 0 && b%2) ret = 0;
    a /= 2;
    b /= 2;
  }
  return ret;
}

bool is_palindrome(const string& s) {
  REP(i, s.size()/2) {
    if (s[i] != s[s.size()-i-1]) return 0;
  }
  return 1;
}

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

  int64 H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  REP(i, H) cin >> S[i];

  int64 res = INF_LL;
  REP(i, 1 << (H-1)) {
    int64 ret = 0;
    ret += __builtin_popcount(i);
    vector<int64> now(__builtin_popcount(i)+1, 0);
    bool ok = 1;
    REP(j, W) {
      vector<int64> sum(__builtin_popcount(i)+1, 0);
      int64 h = 0;
      REP(k, H) {
        if (S[k][j] == '1') {
          sum[h]++;
        }
        if (k < H-1 && (i >> k & 1)) h++;
      }
      bool oru = 0;
      REP(k, sum.size()) {
        if (sum[k] > K) {
          ok = 0;
          break;
        } else if (sum[k] + now[k] > K) {
          oru = 1;
        }
      }
      ret += oru;
      REP(k, sum.size()) {
        now[k] = now[k] * (!oru) + sum[k];
      }
    }
    if (ok) {
      chmin(res, ret);
    }
  }
  cout << res << endl;
}


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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    string c[3];
    rep(i, 3) cin >> c[i];

    rep(i, 3) cout << c[i][i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
#define pb push_back
#define skip continue
//scanf("%lld",&a);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    vector<long long>u,v;
    pair<long long, long long>n;
    set<string>y;
    long long a,b,c,d=0,e=0,i,f=0,g=0,j,k=0,l=0,r=0,z,m,h,p;
    string t,s,x,q;
    double w;
    cin>>a;
    if(a>=30){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 3588
import sys

A = []

for i in range(3):

    x,y,z = map(int,input().split())
    A += [x,y,z]

N = int(input())

for i in range(N):

    b = int(input())

    for j in range(9):

        if A[j] == b:
            A[j] = 0

#print (A)

for i in range(3):

    i *= 3
    if A[i] == A[i+1] == A[i+2] == 0:
        print ("Yes")
        sys.exit()

for i in range(3):

    if A[i] == A[i+3] == A[i+6] == 0:
        print ("Yes")
        sys.exit()

if (A[2] == A[4] == A[6] == 0)or(A[0] == A[4] == A[8] == 0):
    print ("Yes")
    sys.exit()

print ("No")


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main()
{
    int n;
    int c0=0;
    int c1=0;
    int c2=0;
    int c3=0;
    string s;
    cin >> n;
    if(1>n || n >100000){
        return 0;
    }
    for(int i=0;i<n;i++){
            cin >> s;
            if(s=="AC"){
                c0++;
            }
            else if(s=="WA"){
                c1++;
            }
            else if(s=="TLE"){
                c2++;
            }
            else if(s=="RE"){
                c3++;
            }
            else
                return 0;

        }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;

    return 0;
}


Measured memory_bytes: 3524
a, b, c = map(int, input().split())
k = int(input())

if max(a,b,c) == a:
    ans = b + c + a*(2**k)
elif max(a,b,c) == b:
    ans = a + c + b*(2**k)
elif max(a,b,c) == c:
    ans = a + b + c*(2**k)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    int count=0;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
    	cin>>s[i];
    	for(int j=0;j<w;j++){
    		if(s[i][j]=='#')count++;
    	}
    }
    bool maki[h][w];
    int dis=-1;
    memset(maki,0,sizeof(maki));
    ll dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
    queue<pair<int,pair<int,int> > > q;//y,x
    q.push(make_pair(1,make_pair(0,0)));
    while(!q.empty()){
    	int d=q.front().first;
    	int i=q.front().second.first;
    	int j=q.front().second.second;
    	if(i==h-1&&j==w-1){
    		dis=d;
    		break;
    	}
    	for(int k=0;k<4;k++){
    		int x=j+dx[k];
    		int y=i+dy[k];
    		if(x>=w||x<0||y>=h||y<0)continue;
    		if(s[y][x]=='#')continue;
    		if(maki[y][x])continue;
    		maki[y][x]=true;
    		q.push({d+1,{y,x}});
    	}
    	q.pop();
    }
    if(dis==-1){
    	cout << -1<<endl;
    	return 0;
    }
    cout << h*w-count-dis <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int q, i, j, a, b;
    char c[1001], x[1001], order[8];
    
    scanf("%s\n %d\n", c, &q);

    for(i=0; i<q; i++){
        scanf("%s %d %d", order, &a, &b);
        
        if(!strcmp(order, "print")){
            for(j=a; j<=b; j++){
                printf("%c", c[j]);
                if(j==b){
                    puts("");
                }
            }
        }
        
        if(!strcmp(order, "replace")){
            scanf("%s", x);
            for(j=0; j<=b-a; j++){
                c[a+j] = x[j];
            }
        }
            
        if(!strcmp(order, "reverse")){
            for(j=a; j<=b; j++)
            x[b-j] = c[j];
            for(j=a; j<=b; j++)
            c[j] = x[j-a];
        }
    }
    return 0;
}



Measured memory_bytes: 2056
def combi(a,b):
  s=fac[a]
  t=fac[b]        
  u=fac[a-b]
  ans = ( s*pow(t,p-2,p)*pow(u,p-2,p) )%p
  return ans
############################################ 
N,K=map(int,input().split())
p=10**9+7
fac=[1,1]
for i in range(2,N+1):
  a= fac[-1]*i % p
  fac.append(a)
    
for i in range(1,K+1):
  if N-K < i-1:
    #print("err")
    ans=0
  else:
    q= N-K-(i-1) #ボールの数
    r = i #仕切りの数
    ans = ( combi(K-1,i-1)*combi(q+r,q) )%p
    #print(1,combi(K-1,i-1),combi(q+r,q))
  print(ans)

Measured memory_bytes: 3444
def main():
    H, W = (int(i) for i in input().split())
    if H == 1 or W == 1:
        return print(1)
    li = (W+1)//2
    ro = ((H+1)//2)
    print(li*ro + (W//2)*(H//2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import re

s = input()
t = input()

for i in range(len(s)-len(t), -1, -1):
    for j in  range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        s = s[:i] + t + s[i+len(t):]
        break
else:
    print('UNRESTORABLE')
    exit(0)

res = s.replace('?', 'a')

print(res)


Measured memory_bytes: 3188
/*
Aldew
PROB: Save Konoha
CLASSIFICATION: Priority Queue
DIFFICULTY:
*/

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <cmath>
#include <string>
#include <map>
#include <math.h>
#include <cstdio>
#include <stack>
#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;

using namespace std;

//void io()
//{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
//}

vector <int> factors(int x) {
    vector <int> result;
    int i = 1;
    while(i*i <= x) {
        if(x % i == 0) {
            result.push_back(i);
            if(x/i != i) {
                result.push_back(x/i);
            }
        }
        i++;
    }
    return result;
}

int decimalToBinary(int N)
{

    // To store the binary number
    ull B_Number = 0;
    int cnt = 0;
    while (N != 0) {
        int rem = N % 2;
        ull c = pow(10, cnt);
        B_Number += rem * c;
        N /= 2;

        // Count used to store exponent value
        cnt++;
    }

    return B_Number;
}

int binaryToDecimal(int n)
{
    int num = n;
    int dec_value = 0;

    // Initializing base value to 1, i.e 2^0
    int base = 1;

    int temp = num;
    while (temp) {
        int last_digit = temp % 10;
        temp = temp / 10;

        dec_value += last_digit * base;

        base = base * 2;
    }

    return dec_value;
}

ll myXOR(ll x, ll y)
{
    ll res = 0; // Initialize result

    // Assuming 32-bit Integer
    for (int i = 31; i >= 0; i--)
    {
       // Find current bits in x and y
       bool b1 = x & (1 << i);
       bool b2 = y & (1 << i);

        // If both are 1 then 0 else xor is same as OR
        bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);

        // Update result
        res <<= 1;
        res |= xoredBit;
    }
    return res;
}



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

    vector<int> a;
    ll it;

    ll s = -1;
    for (ll i = 0; i < n; i++){
        cin >> it;

        if (s != -1){
            s = myXOR(s, it);
        }
        else s = it;
        a.push_back(it);
    }

    ll val;
    for (ll i = 0 ; i < n; i++){

        val = myXOR(s, a[i]);

        cout << val << " ";
    }
    cout << endl;


    return 0;
}


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

int Q;
priority_queue<int> q_left;
priority_queue<int,vector<int>,greater<int>> q_right;
int f = 1;
long long cum = 0;

void add(){
   int a,b;cin >> a >> b;
   cum += (long long)b;
   if(f){ //最初だけは両方にaをpushしておく
      q_left.push(a);
      q_right.push(a);
      f = 0;
   }else{
      int left_max = q_left.top();
      int right_min = q_right.top();
      if(left_max <= a and a <= right_min){
         //最大値は変わらないし、left,right両方にaを追加すればよい
         q_left.push(a);q_right.push(a);
      }else if(a < left_max){
         //left_max - aだけ最小値は増える
         cum += (long long)(left_max - a);
         //q_leftに2回aをpushし、新しい最大値をq_rightに移し替える
         q_left.push(a);q_left.push(a);
         q_right.push(q_left.top());
         q_left.pop();
      }else{
         cum += (long long)(a - right_min);
         q_right.push(a);q_right.push(a);
         q_left.push(q_right.top());
         q_right.pop();
      }
   }
}
void getmin(){
   cout << q_left.top() << " " << cum << endl;
}

int main(void){
   cin >> Q;
   for(int i = 0;i < Q;i++){
      int com;cin >> com;
      (com == 1) ? add() : getmin ();
   }
   return 0;
}

Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
#define int long long

signed main() { 
        int n, x;
        cin >> n >> x;
        vector<int> a(n);
        rep(i, n) cin >> a[i];
        vector<int> b(n);
        rep(i, n) b[i] = a[i];
        int ans = INFL;
        rep(k, n) {
                int res = 0;
                rep(i, n) {
                        b[i] = min(b[i], a[(i - k + n) % n]);
                        res += b[i];
                }
                amin(ans, res + x * k);
        }
        cout << ans << endl;
        return 0;
}               



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
int B[200100];
int main(){
    int n, a,i;
    cin >> n;
    for(i=1;i<n;i++){
        cin >> a;
        B[a]++;
    }
    for(i=1;i<=n;i++){
        cout <<B[i] << '\n';
    }
}


Measured memory_bytes: 4376
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<string> S;
    for(int i=0; i<N; i++)
    {
    	string s;
    	cin >> s;
    	S.push_back(s);
    }

    long int cnt[5] = {};
    for(int i=0; i<N; i++)
    {
    	if(S[i][0]=='M') cnt[0]++;
    	else if(S[i][0]=='A') cnt[1]++;
    	else if(S[i][0]=='R') cnt[2]++;
    	else if(S[i][0]=='C') cnt[3]++;
    	else if(S[i][0]=='H') cnt[4]++;
    }

    long int sum = 0;
    for(int i=0; i<5; i++)
    {
       for(int j=i+1; j<5; j++)
       {
           for(int k=j+1; k<5; k++)
           {
           	   sum += cnt[i]*cnt[j]*cnt[k];
           }
       }
    }

    cout << sum << endl;

	return 0;
}

Measured memory_bytes: 6132
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
 
#define LIMIT 20
 
struct Puzzle {
  int cont[25];
  int space[2];
};
 
int limit;
 
Puzzle puzzle;
 
int tx[12]={0,1,2,3,0,1,2,3,4,1,2,3};
int ty[12]={0,1,1,1,2,2,2,2,2,3,3,3};
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
 
int heuris[12][25];
 
int getHeuristic(){
  int res=0;
  for(int i=0;i<25;i++){
    if(puzzle.cont[i]==-1||puzzle.cont[i]==0)continue;
    res+=heuris[puzzle.cont[i]][i];
  }
  return res;
}
 
bool dfs(int depth,int prev0,int prev1){
   
  int heuri;
  heuri=getHeuristic();
  /*
  cout<<depth<<' '<<heuri<<endl;
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      if(puzzle.cont[i*5+j]!=-1)printf("%3d",puzzle.cont[i*5+j]);
      else cout<<"???";
    }
    cout<<endl;
  }
  */
  if(heuri==0){
    cout<<depth<<endl;
    return true;
  }
  if(depth + heuri>limit)return false;
 
  int px,py,nx,ny;
  Puzzle tmp=puzzle;
 
  py=puzzle.space[0]/5;
  px=puzzle.space[0]%5;
  for(int i=0;i<4;i++){
    if(max(prev0,i)-min(prev0,i)==2)continue;
    ny=py+dy[i];nx=px+dx[i];
    if(ny<0||ny>=5||nx<0||nx>=5)continue;
    if(puzzle.cont[ny*5+nx]==-1)continue;
    if(puzzle.cont[ny*5+nx]==0)continue;
    puzzle.cont[py*5+px]=puzzle.cont[ny*5+nx];
    puzzle.cont[ny*5+nx]=0;
    puzzle.space[0]=ny*5+nx;
    if(dfs(depth+1,i,-100))return true;
    puzzle=tmp;
  }
 
  py=puzzle.space[1]/5;
  px=puzzle.space[1]%5;
  for(int i=0;i<4;i++){
    if(max(prev1,i)-min(prev1,i)==2)continue;
    ny=py+dy[i];nx=px+dx[i];
    if(ny<0||ny>=5||nx<0||nx>=5)continue;
    if(puzzle.cont[ny*5+nx]==-1)continue;
    if(puzzle.cont[ny*5+nx]==0)continue;
    puzzle.cont[py*5+px]=puzzle.cont[ny*5+nx];
    puzzle.cont[ny*5+nx]=0;
    puzzle.space[1]=ny*5+nx;
    if(dfs(depth+1,-100,i))return true;
    puzzle=tmp;
  }
  return false;
}
 
void solve(){
  Puzzle tmp=puzzle;
  for(limit=getHeuristic();limit<=LIMIT;limit+=2){
    puzzle=tmp;
    if(dfs(0,-100,-100))return;
  }
  cout<<"NA"<<endl;
}
 
int main(){
  int x,y,c=0;
 
  for(int i=1;i<=11;i++){
    for(int j=0;j<25;j++){
      y=j/5;
      x=j%5;
      heuris[i][j]=abs(tx[i]-x)+abs(ty[i]-y);
    }
  }
  /*
  for(int i=1;i<=11;i++){
    for(int j=0;j<5;j++){
      for(int k=0;k<5;k++){
    cout<<heuris[i][j*5+k]<<' ';
      }
      cout<<endl;
    }
    cout<<endl;
  }
  */
 
 
  while(1){
    c=0;
    for(int i=0;i<25;i++)puzzle.cont[i]=-1;
 
    cin>>puzzle.cont[2];
    if(puzzle.cont[2]==-1)break;
    if(puzzle.cont[2]==0)puzzle.space[c++]=2;
     
     
    for(int i=6;i<=8;i++){
      cin>>puzzle.cont[i];
      if(puzzle.cont[i]==0)puzzle.space[c++]=i;
    }
    for(int i=10;i<=14;i++){
      cin>>puzzle.cont[i];
      if(puzzle.cont[i]==0)puzzle.space[c++]=i;
    }
     
    for(int i=16;i<=18;i++){
      cin>>puzzle.cont[i];
      if(puzzle.cont[i]==0)puzzle.space[c++]=i;
    }
     
    cin>>puzzle.cont[22];
    if(puzzle.cont[22]==0)puzzle.space[c++]=22;
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <list>
#include <string>
using namespace std;
int main()
{
	int i = 0, j = 0, p = 0, q = 0, ans = 0;
	ifstream fin("input.txt");
	int N, M;
	cin >> N >> M;
	vector<vector<char> >matrix (N,vector<char>(N));

	vector<vector<char> >sub(M, vector<char>(M));
	for (i = 0; i < N; i++)
		for (j = 0; j < N; j++)
			cin>>matrix[i][j];

	for (i = 0; i < M; i++)
		for (j = 0; j < M; j++)
			cin >> sub[i][j];


	for (i=0; i <= N - M; i++)
	{
		for (j=0; j <= N - M; j++)
		{
			ans = 0;
			for (p=0; p < M; p++)
			{
				for (q=0; q < M; q++)
				{
					if (matrix[i+p][j+q] == sub[p][q])
						ans++;


				}
			}
			if (ans == M*M)
			{
				cout << "Yes" << endl;
				return 0;
			}
			
				
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
4,5,6,7,8,9,10
a, b , k = map(int, input().split())
if k > (b-a)//2:
  for i in range(a, b+1):
    print(i)
else:
  for i in range(a, a+k):
    print(i)
  for j in range(b-k+1,b+1):
    print(j)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back

void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;




template< typename T >
vector<T> dijkstra(WG<T> &g,int s){
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(),lim);
  using Pi = pair<T,int>;
  priority_queue<Pi,vector<Pi>,greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s],s);
  while(!q.empty()){
    T cost;
    int idx;
    tie(cost,idx) = q.top();
    q.pop();
    if(dist[idx] < cost) continue;
    for( auto &e : g[idx]){
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to],e.to);
    }
  }
  return dist;
}

int t;
map<P,int> mp;

int f(int a,int b){
  if(!mp[P(a,b)])
    mp[P(a,b)]=t++;

  return mp[P(a,b)];
}

WG<int> es(510000);

main(){
  int n,m;
  cin>>n>>m;
  
  t=n+1;
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    int x=f(a,c);
    int y=f(b,c);

    es[a].PB(edge<int>(x,1));
    es[b].PB(edge<int>(y,1));
    es[x].PB(edge<int>(a,1));
    es[x].PB(edge<int>(y,0));
    es[y].PB(edge<int>(x,0));
    es[y].PB(edge<int>(b,1));
  }

  vector<int> v=dijkstra(es,1);

  cout<<(v[n]==INT_MAX?-1:v[n]/2)<<endl;
}



Measured memory_bytes: 60284
#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a*b>c*d){
		printf("%d",a*b);
	}else{
		printf("%d",c*d);
	}

	return 0;
}

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


int main() 
{
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	sort(a, a + n);
	
	int min = a[k - 1] - a[0];
	for(int i = 1; i <= n - k; i++)
	{
		if(a[i + k - 1] - a[i] < min)
		{
			min = a[i + k - 1] - a[i];
		}
	}
	
	cout << min;
	
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N-1);
    rep(i,N-1) {
        cin >> B.at(i);
    }
    A.at(0)=B.at(0);
    for(int i=1;i<=N-2;i++){
        A.at(i)=min(B.at(i-1),B.at(i));
    }
    A.at(N-1)=B.at(N-2);
    int ans=0;
    rep(i,N) ans+=A.at(i);
    cout << ans << endl;
    return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn=2e5+100;
int par[maxn],sum[maxn];
int N,K,p,tot;

void init(int n)
{
    for(int i=0;i<=n;i++)
        par[i]=i;
}

int find(int x)
{
    if(par[x]==x)
        return x;
    return par[x]=find(par[x]);
}
void unit(int x,int y)
{
    int fx=find(x),fy=find(y);
    if(fx!=fy)
        par[fx]=fy;
}
bool same(int x,int y)
{
    return find(x)==find(y);
}
int main()
{
    while(~scanf("%d%d",&N,&K))
    {
        int ans=0;
        memset(sum,0,sizeof(sum));
        memset(par,0,sizeof(par));
        tot=0;
        init(N);
        int t;
        scanf("%d",&t);
        sum[t]++;
        p=t;
        tot++;
        for(int i=2;i<=N;i++)
        {
            scanf("%d",&t);
            sum[t]++;
            if(!same(t,p))
            {
                tot++;
                unit(t,p);
            }
        }
        sort(sum,sum+N+1);
        if(tot<=K)
            ans=0;
        else
        {
            int cnt=tot-K;
            int pos=lower_bound(sum,sum+N+1,1)-sum;
            while(cnt--)
                ans+=sum[pos++];       
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int answer=0;
  
  if(s.at(0)=='1' ){
    answer ++;
  }
  if(s.at(1)=='1' ){
    answer ++;
  }
  if(s.at(2)=='1' ){
    answer ++;
  }
  
  cout << answer <<endl;
}

Measured memory_bytes: 764
import sys
a = {}
ma = 0
m = []
for u in sys.stdin:
    i = int(u)
    if not (i in a):
        a[i] = 1
    else:
        a[i] += 1
    # ???????????§????????±???
    if ma <= a[i]:
        if ma < a[i]:
            ma = a[i]
            m.clear()
        m.append(i)
m = sorted(m)
for k in m:
    print(k)

Measured memory_bytes: 7512
#include<stdio.h>
#include<string.h>
int main()
{
    char s1[1001],s2[1001];
    int len1,len2,count=0,i,j,max;
    scanf("%s %s",s1,s2);
    len1=strlen(s1);
    len2=strlen(s2);
    max=0;
    for(i=0;i<(len1+1)-len2;i++){
        count=0;
        for(j=0;j<len2;j++){
            if(s1[i+j]==s2[j]){
                  count++;
            }
        }
        if(max<count)
            max=count;
    }
    printf("%d\n",(len2-max));
    return 0;
}


Measured memory_bytes: 1684
from collections import defaultdict as d
dico = d(int)
n = int(input())
for x in range(1,101):
  for y in range (1, 101):
    for z in range (1,101):
      s = x**2+y**2+z**2+x*y+x*z+y*z
      if s > n:break
      dico[s]+=1
for i in range(1, n+1):
  print(dico[i])

Measured memory_bytes: 9848
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

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

	REP(i, (int)s.size() - 8) cout << s[i];

	cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
int main() {
  int w, n;
  cin >> w >> n;
  vector<int> a(n), b(n), x(w);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cin.ignore(numeric_limits<unsigned>::max(), ',');
    cin >> b[i];
  }
  for (int i = 0; i < w; i++)
    x[i] = i + 1;
  for (int i = 0; i < n; i++)
    swap(x[a[i] - 1], x[b[i] - 1]);
  for (int i = 0; i < w; i++)
    cout << x[i] << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    string s, t;
    cin >> s >> t;

    string ans = "Yes";
    for (int i=0; i<s.size(); i++) {
        if (s.at(i) != t.at(i)) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

int main(){
	char text[200001];
	text[0] = '\0';
	long int len=0;
	long int Bcount=0;
	long int Wcount=0;
	long int a=0;
	long int b=0;
	long long int answer=0;
	scanf("%s",text);
	len = strlen(text);
	for (int i = 0; i < len; i++){
		if (strncmp(&text[i],"B",1) == 0){
			Bcount++;
		}
	}
	Wcount = len - Bcount;
	//printf("%d %d %d\n",len,Bcount,Wcount);
	if (Bcount >= Wcount){
		a = Wcount;
	for (int i = 0; i < len; i++){
		if (strncmp(&text[i],"B",1) == 0){
			answer += (a - i);
			//printf("%d\n",answer);
			a++;
		}
	}
}
	if (Bcount < Wcount){
	for (int i = 0; i < len; i++){
		if (strncmp(&text[i],"W",1) == 0){
			answer += i - b;
			//printf("%d %d\n",answer,i);
			b++;
		}
	}
}
	//printf("%s\n",text);
	printf("%ld\n",answer);
	return 0;
}

Measured memory_bytes: 384
def main():
    W, H, x, y = list(map(int, input().split(' ')))
    split_num = 0
    if 2 * x == W and 2 * y == H:
        split_num = 1
    area = W * H / 2
    print('{} {}'.format(area, split_num))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
# coding: utf-8
# Your code here!
s = input()

if s[0] != "A":
    print("WA")
    exit()
if s[2:-1].count("C") != 1:
    print("WA")
    exit()

if s.replace("A","a").replace("C","c").islower():
    print("AC")
else:
    print("WA")


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] t = new int[n];
		for(int i=0;i<n;i++){
			t[i] = scanner.nextInt();
		}
		int m = scanner.nextInt();

		for(int i=0;i<m;i++){
			int p = scanner.nextInt()-1;
			int x = scanner.nextInt();
			int tmp = t[p];
			t[p] = x;
			int count = 0;
			for(int j=0;j<n;j++){
				count += t[j];
			}
			System.out.println(count);
			t[p] = tmp;
		}
	}

}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)


int main()
{
  ll n,a[100000];
  cin>>n;
  rep(i,n) cin>>a[i];

  //偶数回出てくるものは消える
  sort(a,a+n);

  int tmp,cnt=1,ans=0;
  rep(i,n)
  {
    if(i==0) tmp=a[0];

    else
    {
      if(a[i]==tmp) cnt++;
      else
      {
        if(cnt%2==1) ans++;
        cnt=1;
        tmp=a[i];
      }
    }

    if(i==n-1)
    {
      if(cnt%2==1) ans++;
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    string in; cin >> in;
    if(in.substr(0, 4) == "YAKI"){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h[100005];
int ab(int a) {
    return a<0? -a : a;
}
int dp[100005];
int main()
{
    int n,k;
    cin >> n >> k;
    for(int i=1;i<=n;i++) {
        cin >> h[i];
        dp[i] = 2e9;
    }
    dp[1]=0;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=k&&j+i<=n;j++)
        dp[i+j]=min(dp[i+j],dp[i]+ab(h[i+j]-h[i]));
    }
    cout << dp[n];
}



Measured memory_bytes: 1024
n,m=map(int,input().split())
keys=[None]*m
INF = 10**10
dp=[INF]*(2**n)
dp[0]=0
for i in range(m):
  a,b=map(int,input().split())
  c=list(map(int,input().split()))
  cond=0
  for j in c:
    cond+=2**(j-1)
  keys[i]=[a,cond]
for key in keys:
  for sta in range(2**n):
        dp[sta|key[1]]=min(dp[sta|key[1]],dp[sta]+key[0])
print(dp[-1] if dp[-1] != INF else -1)


Measured memory_bytes: 76592
#include <iostream>
#include <vector>
#include <numeric>
#include <string>

using namespace std;


int main()
{
    int N;
    N = 3;

    vector<int> A(N);

    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    

    string result = "No";

    if (A.at(0) == A.at(1) && A.at(1) == A.at(2))
    {
        result = "Yes";
    }
    
    cout << result;

    return 0;
}


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

int main() {
  int Expence_Money, One_Yen;
  int CheckFiveHundred ;
  int FiveHundred_Yen = 500;
  
  cin >> Expence_Money >> One_Yen;
  if (Expence_Money <= One_Yen) {
    cout << "Yes" << endl;
  }
  else {
    // 500円で割ったときの余り
    CheckFiveHundred = Expence_Money % FiveHundred_Yen;
    if( CheckFiveHundred <= One_Yen) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
i_str = input()
K,N = map(int,i_str.split())
i_str = input()
As = list(map(int,i_str.split()))
A_range = []
As_b = 0
for i,A in enumerate(As):
    A_range.append(A - As_b)
    As_b = A
A_range[0] = (K - As[len(As)-1] + A_range[0])
A_range_max = max(A_range)
print(K - A_range_max)

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

int a,b,c;

int main()
{
    scanf("%d%d%d",&a,&b,&c);
    if(a+b>=c)
    {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for( i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9 + 7;
int INF = 1e6;

ll n, m;



int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> k;
	ll ans = 0, flg = 0;
	for (i = 1; i <= pow(10, 7); i++) {
		ans = 10 * ans + 7;
		ans %= k;
		if (ans == 0) {
			flg = 1;
			break;
		}

	}
	if (flg)
		cout << i;
	else
		cout << -1;




	return 0;
}

Measured memory_bytes: 3612
# coding: utf-8
import sys
from collections import deque

output_str = deque()
data_cnt =  int(input())  

for i in range(data_cnt):
    in_command = input().rstrip().split(" ")
    
    if in_command[0] == "insert":
        output_str.appendleft(in_command[1])
    elif in_command[0] == "delete":
        if output_str.count(in_command[1]) > 0:
            output_str.remove(in_command[1])
    elif in_command[0] == "deleteFirst":
        output_str.popleft()
    elif in_command[0] == "deleteLast": 
        output_str.pop()

print(" ".join(output_str))

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

int main() {
	int s[3];
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
	}
	int m;
	for (int j = 0; j < 2; j++) {
		for (int k = j + 1; k < 3; k++) {
			if (s[j] > s[k]) {
				m = s[j];
				s[j] = s[k];
				s[k] = m;
			}
		}
	}
	cout << s[0] + s[1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,T;
  cin >> N >> T;
 vector<int> c(N);
  vector<int> t(N);
  
  for(int i = 0; i< N; i++){
    cin >> c.at(i);
    cin >> t.at(i);
  }
  int ans = 1100;
  int count = 0;
  for(int i = 0; i< N; i++){
    if(t.at(i) <= T){
      ans = min(ans,c.at(i));
    }
  }
  if(ans != 1100) cout << ans << endl;
  else cout << "TLE" << endl;
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

map<ll, int> factorize(ll n) {
    map<ll, int> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res[i] = 0;
        while (n % i == 0) {
            n /= i;
            res[i]++;
        }
    }

    if (n != 1) res[n] = 1;
    return res;
}

ll comb(ll l, ll r) {
    map<ll, ll> factors;
    for (ll j = l; j > (l - r); j--) {
        auto fs = factorize(j);
        for (auto f : fs) {
            factors[f.first] += f.second;
        }
    }

    for (ll j = 1; j <= r; j++) {
        auto fs = factorize(j);
        for (auto f : fs) {
            factors[f.first] -= f.second;
        }
    }

    ll s = 1;

    for (auto e : factors) {

        for (int k = 0; k < e.second; k++) {
            s *= e.first;
        }
    }

    return s;
}
int main() {
    int n, p;
    cin >> n >> p;
    vector<int> as(n);
    rep(i, n) cin >> as[i];

    int zero = 0, one = 0;
    for (int a : as) if (a % 2 == 0) zero++; else one++;

    if (p == 0) {
        ll pz = pow(2, zero);
        ll ans = 0;
        rep(i, one + 1) {
            if (i % 2 == 0)ans += comb(one, i) * pz;
        }
        cout << ans << endl;
    } else {
        ll pz = pow(2, zero);
        ll ans = 0;
        rep(i, one + 1) {
            if (i % 2 == 1)ans += comb(one, i) * pz;
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
int num1[60],num2[60],ans[60];
void cheng()
{
	if(num2[0]==1&&num2[1]==0)
	{
		memset(num1,0,sizeof(num1));
	}
	if(num1[0]>20) return ;
	memset(ans,0,sizeof(ans));
	int t=0;
	for(int i=1;i<=num1[0]+num2[0]+2;++i)
	{
		ans[i]=t;
		for(int j=1;j<=i;++j)
			ans[i]+=num1[j]*num2[i-j+1];
		t=ans[i]/10;
		ans[i]%=10;
	}
	ans[0]=num1[0]+num2[0]+3;
	while(ans[ans[0]]==0&&ans[0]>0) ans[0]--;
	for(int i=0;i<=ans[0];++i) num1[i]=ans[i];
};
int main()
{
	num1[0]=num1[1]=1;
	int n;
	cin>>n;
	num1[0]=1;
	for(int i=1;i<=n;++i)
	{
		memset(num2,0,sizeof(num2));
		string b;
		cin>>b;
		num2[0]=b.length();
		for(int j=0;j<num2[0];++j)
			num2[num2[0]-j]=b[j]-'0';
		cheng();
	}
	if(num1[0]>19) 
	{
		cout<<-1;
		return 0;
	}
	if(num1[0]==19)
	{
		for(int i=18;i>=1;--i)
		if(num1[i])
		{
			cout<<-1;
			return 0;
		}
	}
	int flag=1;
	for(int i=num1[0];i>=1;--i) cout<<num1[i],flag=0;
	if(flag) cout<<0;
	return 0;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;

  int ans[501][501];
  function< void(int,int,int) > rec =
  [&](int left,int right,int level){
    if(right - left <= 1) return;
    int mid = (left + right) / 2;
    for(int i = left; i < mid; i++){
      for(int j = mid; j < right; j++){
        ans[i][j] = level;
      }
    }
    rec(left,mid,level+1);
    rec(mid,right,level+1);
  };
  rec(0,n,1);

  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      cout << ans[i][j] << " ";
    }
    cout << "\n";
  }

  return 0;
}


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

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)
#define endl '\n'

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int H, int W) { return y >= 0 && x >= 0 && y < H && x < W; }
inline int in() { int x; std::cin >> x; return x; }
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << '\n';
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

#define int long long
signed main()
{
  int n, a, b;
  int ans = 0;
  cin >> n >> a >> b;
  vi x(n);
  rep(i, n) cin >> x[i];

  reps(i, 1, n) {
    ans += min((x[i] - x[i - 1]) * a, b);
  }

  print(ans);

  return (0);
}

Measured memory_bytes: 640
#include <cstdio>

static const size_t n_max = 20, m_max = 2000;
bool dp[m_max + 1];

int main() {
  size_t n, q;
  scanf("%zu", &n);
  dp[0] = true;
  for (size_t i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    for (int j = m_max - a; j >= 0; j--)
      if (dp[j])
        dp[j + a] = true;
  }
  scanf("%zu", &q);
  for (size_t i = 0; i < q; i++) {
    int m;
    scanf("%d", &m);
    puts(dp[m] ? "yes" : "no");
  }
  return 0;
}

Measured memory_bytes: 2664
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  rep (i, n) cin >> v[i];
  sort(all(v));
  double val = v[0];
  rep (i, 1, n) val = (val + v[i]) / 2;
  cout << val << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  int n;
  string s;
  cin >> n >> s;

  int l = 0, r = n - 1;
  int cnt = 0;
  while (l < r) {
    while (l < n && s[l] != 'W') ++l;
    if (l >= n) break;
    while (r >= 0 && s[r] != 'R') --r;
    if (r < 0) break;
    if (l >= r) break;
    ++l;
    --r;
    ++cnt;
  }

  cout << cnt << endl;
}

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

  solve();
  return 0;
}


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

using namespace std;

typedef long long ll;

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

    if ((n&1)) {
        for (int i=n-1; i>=0; i-=2) cout << a[i] << " ";
        for (int i=1; i<n-1; i+=2) cout << a[i] << " ";
    } else {
        for (int i=n-1; i>=0; i-=2) cout << a[i] << " ";
        for (int i=0; i<n-1; i+=2) cout << a[i] << " ";
    }
    cout << endl;
}

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

long long to10(string two){
  long long sum = 0;
  for ( int i = 0; i < two.length(); i++){
    if(two[two.length()-i-1] == '1'){
      sum += pow(2, i);
    }
  }
  return sum;
}

void count( long long x, int X[41]){
  stringstream ss;
  ss << bitset<40>(x);
  string s = ss.str();
  for ( int i = 0; i < s.length()-1; i++){
    int j = s.length() - i - 1;
    X[j] = s[i] == '1' ? (to10(s.substr(i+1, j)) + 1) % 2 : 0;
//    cout << s.substr(i+1, j) << " " << to10(s.substr(i+1, j)) + 1 << " ";
  }
  X[0] = (x/2 + x%2 )% 2;
}

int main(){
  long long a, b, sum = 0;
  cin >> a >> b;
  ostringstream oss;
  oss << b;
  int A[41], B[41];
  count(a, A);
  count(b, B);
  for ( int i = 0; i < 40; i++){
     stringstream ss;
     ss << bitset<40>(a);
     string s = ss.str();
 //    cout << B[i] << " ";
     if ( (B[i] + A[i] + (s[40-i-1] - '0') ) % 2 == 1 ){
       sum += pow(2, i);
     }
  }

  cout << sum << endl;

  return 0;
}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a[5];
  char c;
  while (cin >> a[0]) {
    for (int i = 1; i < 5; i++) {
      cin >> c >> a[i];
    }
    sort(a, a + 5);
    map<int, int> mp;
    for (int i = 0; i < 5; i++) {
      mp[a[i]]++;
    }
    int cnt = 0;
    for (auto i : mp) cnt = max(cnt, i.second);
    if (mp.size() == 2 && cnt == 4) {
      cout << "four card" << endl;
    } else if (mp.size() == 2 && cnt == 3) {
      cout << "full house" << endl;
    } else if (mp.size() == 3 && cnt == 3) {
      cout << "three card" << endl;
    } else if (mp.size() == 3 && cnt == 2) {
      cout << "two pair" << endl;
    } else if (mp.size() == 4) {
      cout << "one pair" << endl;
    } else {
      bool flag = true;
      for (int i = 1; i + 1 < 5; i++) {
        flag &= a[i + 1] - a[i] == 1;
      }
      if (flag && ((a[0] == 1 && a[1] == 10) || (a[1] - a[0] == 1))) {
        cout << "straight" << endl;
      } else {
        cout << "null" << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
	int n;
	int total = 0;
	bool flag = true;

	cin >> n;

	vector<int> a(n);

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

	sort(a.begin(), a.end());

	for (int i = n - 1; i >= 0; i--) {
		if (flag) {
			total += a[i];
			flag = false;
		}
		else {
			total -= a[i];
			flag = true;
		}
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
#5618213
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)
  
for b,c in bc:
  a.extend([c]*b)
  if len(a) > n*2:
    break
a.sort(reverse=True)
print(sum(a[:n]))

Measured memory_bytes: 34888
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<pair<int,int>>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i).first;
		v.at(i).second=i;
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		cout<<v.at(i).second+1<<" ";
	}
	cout<<endl;
}


Measured memory_bytes: 1664