akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> ans(N);

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


  for(int i=0;i<N;i++){
    ans.at(A.at(i)-1)=i+1;
  }
  for(int i=0;i<N;i++){
    cout << ans.at(i);
    if (i!=(N-1)) cout << ' ';
  }
  
    cout << endl;
  
}


Measured memory_bytes: 1664
#include <stdio.h>

#define Max 1000000001

int main(void){
  long i,j,min=Max,min_id=0;

  long n;
  scanf("%ld",&n);

  long a,color[n+1];

  for(i=0;i<=n;i++){
    color[i]=-1;
  }

  for(i=0;i<n;i++){
    scanf("%ld",&a);

    if(a<=min){
      min=a;
      color[min_id++]=a;
    }else{
      for(j=0;j<=n;j++){
        if(a>color[j]){
          color[j]=a;
          if(j==min_id-1){
            min=a;
          }
          break;
        }
      }
    }
  }

  printf("%ld\n",min_id);

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
long long int powermod(long long int x, unsigned long long int y, long long int p){long long int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}

#define mod 1000000007
using namespace std;
#define inf 1e18
const ll INF = 1e18L + 5;
const ll maxn = 1e5 + 5;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };


int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
   ll n,i,j,k;
   string s;
   cin>>n;
   cin>>s;
   map <char,ll> mp[n+5];
   mp[n-1][s[n-1]]++;
   for(i=n-2;i>=0;i--)
   {
       for(auto it:mp[i+1])
        mp[i][it.fi]=it.se;
      mp[i][s[i]]++;
   }
   ll sum=0;
   for(i=0;i<n;i++)
   {
       for(j=i+1;j<n-1;j++)
       {
           if(s[i]!=s[j])
           {
                char a=s[i],b=s[j],r,g;
                if(b<a)
                swap(a,b);
                pair<char, char> p = {a, b};
                
                for(k=1;k<=3;k++)
                {
                    if(k==1)
                    {
                        r = 'R', g = 'G', b = 'B';
                    }
                    else if(k==2)
                    {
                        b='B',g='R',r='G';
                    }
                    else
                    {
                        b='G',g='R',r='B';
                    }
                    
                    if (p == make_pair(b, g))
                    {
                        sum += mp[j + 1][r];
                        ll diff = j - i;
                        if (j + diff < n and s[j + diff] == r)
                            sum--;
                    }
                }                
            
           }
       }
   }
   cout<<sum;
   return 0;
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
typedef long long ll;

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


int main() {
  int N;
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  
  int pmax[1000001];
  for (int i = 0; i < 1000001; i++) {
    pmax[i] = 0;
  }
  
  for (int i = 0; i < N; i++) {
    ll n = a[i];
    ll p = 2;
    int q = 0;
    while (p * p <= a[i] && n >= 1) {
      if (n % p == 0) {
        q++;
        n /= p;
        if (n == p) {
          q++;
          pmax[p] = max(pmax[p], q);
          q = 0;
          break;
        }
      } else {
        pmax[p] = max(pmax[p], q);
        q = 0;
        if (n == 1) {break;}
        p++;
      }
    }
    pmax[n] = max(pmax[n], 1);
  }
  
  ll lcm = 1;
  for (ll p = 2; p <= 1000000; p++) {
    for (int i = 0; i < pmax[p]; i++) {
      lcm = (lcm * p) % M;
    }
  }
  
  
  ll b[N];
  for (int i = 0; i < N; i++) {
    b[i] = (lcm * modinv(a[i], M)) % M;
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans = (ans + b[i]) % M;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

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

int main(){
    ll h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.'){
                ll cnt=0;
                rep(k,8){
                    ll x=j+dx[k],y=i+dy[k];
                    if(x>=0&&x<w&&y>=0&&y<h&&s[y][x]=='#') cnt++;
                }
                s[i][j]='0'+cnt;
            }
        }
    }
    rep(i,h) cout<<s[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

const int MAX = 1000005;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, Y;
    cin >> X >> Y;
    long double ratio = Y/X;
    long double ratio2 = X/Y;
    COMinit();
    if ((X+Y)%3==0 && ratio<=2 && ratio2<=2) {
        cout << COM((X+Y)/3,((X+Y)/3*2-X)) << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 23680
//lec04
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h> 
#include<queue>
#include<string.h>
#include<stack>


using namespace std;

#define N 8
bool board[N][N];
bool col[N],dpos[2*N-1],dneg[2*N-1];
int row[N];


void print_board(){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(board[i][j]&&row[i]!=j){
				return;
    		}
    	}
    }
    for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(board[i][j]||row[i]==j)cout<<"Q";
      		else cout<<".";
		}
		cout<<endl;
	}
}

void solve(int i){
	if(i==N){
		print_board();
		return;
	}
	for(int j=0;j<N;j++){
		if(col[j]||dpos[i+j]||dneg[i-j+N-1])continue;
    	col[j]=dpos[i+j]=dneg[i-j+N-1]=1;
    	row[i]=j;
    	solve(i+1);
    	row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=0;
	}
}



int main(){

	int k=0;
	int a=0,b=0;
	cin>>k;
	for(int i=0;i<k;i++){
		cin>>a>>b;
		board[a][b]=1;
	}
	solve(0);
	return 0;
}





Measured memory_bytes: 3104
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

type pair struct {
	p, b int
}

func (p *pair) total() int {
	return p.p + p.b
}

var N, X int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &N, &X)

	current := pair{0, 0}
	for N >= 0 {
		current.b++
		if current.total() == X {
			break
		}

		// left
		if current.total()+Sum(N-1) == X {
			current.b += B(N - 1)
			current.p += P(N - 1)
			break
		} else if current.total()+Sum(N-1) > X {
			// go deeper
			N--
			continue
		} else {
			current.b += B(N - 1)
			current.p += P(N - 1)
		}

		// center
		current.p++
		if current.total() == X {
			break
		}

		// right
		if current.total()+Sum(N-1) == X {
			current.b += B(N - 1)
			current.p += P(N - 1)
			break
		} else if current.total()+Sum(N-1) > X {
			// go deeper
			N--
			continue
		} else {
			current.b += B(N - 1)
			current.p += P(N - 1)
		}

		current.b++
		if current.total() == X {
			break
		}
	}

	fmt.Println(current.p)
}

func Sum(level int) int {
	return P(level) + B(level)
}

func P(level int) int {
	if level == 0 {
		return 1
	}
	return int(math.Pow(float64(2), float64(level+1))) - 1
}

func B(level int) int {
	if level == 0 {
		return 0
	}
	return int(math.Pow(float64(2), float64(level+1))) - 2
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X;
    cin >> X;

    int happy = 0;

    int num500,num5;

    num500 = X / 500;
    num5 = (X % 500)/5;

    happy = 1000 * num500 + 5 * num5;

    cout << happy << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
typedef int64_t ll;
const int MAX_N = 10000;
const int INF = 1000000000;


int main() {
	int N;
	cin >> N;
	vector<int> a(N+1);
	for (int i = 1; i <=N ; i++)
	{
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0) {
			ans += a.at(i);	
			
		}
		else {
			ans -= a.at(i);
			
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3576
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
count=0
N=int(input())
for i in range(1,N+1):
	for j in range(i,N+1):
		for k in range(j,N+1):
			if i==j and j==k and k==i:
				count+=(gcd_list([i,j,k]))
			elif i==j or j==k or i==k:
				count+=(gcd_list([i,j,k]))*3
			else:
				count+=(gcd_list([i,j,k]))*6

print(count)

Measured memory_bytes: 9636
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

void add_self(int &a,int b)
{
    a+=b;
    if(a>=mod)
    {
        a-=mod;
    }
}
void sub_self(int &a,int b)
{
    a-=b;
    if(a<=0)
    {
        a+=mod;
    }
}
int dp[100025];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,k;
    scanf("%d%d",&n,&k);
    dp[0] = 1;
    for(int child = 0;child < n; ++child)
    {
        int up_to;
        scanf("%d",&up_to);
        vector<int> sum(k+1);
        for(int used = k;used>=0;--used)
        {
            int tmp = dp[used];
            int L = used+1;
            int R = used+min(k-used,up_to);
            if(L<=R)
            {
                add_self(sum[L],tmp);
                if(R+1<=k)
                {
                sub_self(sum[R+1],tmp);
                }
            }
//            for(int here = 1;here<=min(up_to,k-used);++here)
//            {
//                add_self(dp[used+here],dp[used]);
//            }
        }
        int presum = 0;
        for(int i = 0;i<=k;++i)
        {
            add_self(presum,sum[i]);
            add_self(dp[i],presum);
        }
    }
    printf("%d\n",dp[k]);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
void print(int a[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        if(i>0)
            cout<<" ";
        cout<<a[i];

    }
    cout<<endl;
}
void insertSort(int a[],int n)
{
    int i,j,v;
    for(i=1;i<n;i++)
    {
        v=a[i];
        j=i-1;
        while(j>=0&&a[j]>v)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        print(a,n);
    }
}
int main()
{
    int N,A[101];
    cin>>N;
    for(int i=0;i<N;i++)
    {
        cin>>A[i];
    }
    print(A,N);
    insertSort(A,N);
    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n, d;
    cin >> n >> d;
    int res = 1;
    for(int i=0; i<n; i++){
        if(n > res * (2 * d + 1)){
            res++;
        }else{
            break;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#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 IMAX 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long llong;

int main() // 140-C
{
	int N;
	cin >> N;
	int B[N-1];

	REP(idx, N-1) {
		cin >> B[idx];
	}

	int sum = 0;
	// 最初
	sum += B[0];
	// 中間は隣り合ったmin
	REP(idx, N-2) {
		if (B[idx] < B[idx + 1]) {
			sum += B[idx];
		} else {
			sum += B[idx + 1];
		}
	}
	// 最後
	sum += B[N-2];

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)


int main() {
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
        return 0;
    }
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;

int main()
{
    int n;
    string s;

    cin >> n >> s;

    ll res = 0;

    for (int i = 0; i < (1 << n); i++)
    {
        string lr = "", lb = "";

        for (int j = 0; j < n; j++)
        {
            if (i & (1 << j))
                lr += s[j];
            else
                lb += s[j];
        }

        ll dp[40][20];
        memset(dp, 0, sizeof(dp));

        dp[n * 2][0] = 1;

        for (int j = n * 2 - 1; j >= n; j--)
        {
            for (int k = 0; k <= lr.size(); k++)
            {
                dp[j][k] += (k > 0) * dp[j + 1][k - 1] * (s[j] == lr[k - 1]);
                dp[j][k] += dp[j + 1][k] * (s[j] == lb[(n * 2 - j) - k - 1]);
            }
        }

        res += dp[n][lr.size()];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
t = ns()
ans = 0
for i in range(len(s)):
    if s[i] != t[i]:
        ans += 1

print(ans)

Measured memory_bytes: 9380
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 16
using namespace std;

int x[MAX_N][MAX_N];
int y[MAX_N][MAX_N];
int a[MAX_N];

int counter2(int x){
    if(x == 0) return 0;
    return counter2(x >> 1) + (x & 1);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    for(int i =1; i<=n; i++){
        cin>>a[i];
        for(int j = 1 ;j<=a[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }

    int ans = 0;
    for(int bit = 1; bit < (1 << n); bit++){
        bool flag = true;
        for(int i = 1; i <= n; i++){
            if(!(bit&(1<<(i-1)))) continue;
            for(int j = 1; j <= a[i]; j++){
                if(((bit >> (x[i][j]-1))&1) ^ y[i][j]) flag = false; 
            }
        }
        if(flag) ans = max(ans, counter2(bit));
    }
    cout<< ans <<endl;
}


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

int main() {

    int a, b, m=0,DeltaVal;
    cin >> a >> b;
    DeltaVal = b - a;
    for (int i = 0; i < DeltaVal+1; i++)
    {
        m = m + i;
    }

    DeltaVal = m - b;
    cout << DeltaVal;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define DEBUG cout<<"shllhs"<<endl;
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 20
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-10
#define pi acos(-1.0)
using namespace std;
int a[N];
int dp[N];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        FOR(i,1,n)cin>>a[i];
        ll ans = 0;
        int lft = 0;
        FOR(i,1,n)
        {
            ans+=(a[i]+lft)/2;
            lft = (a[i]+lft)%2;
            if(a[i] == 0)lft = 0;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int n,i,max,min,a[1000];
    scanf("%d\n",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    max=a[0];
    min=a[0];
    for(i=0;i<n;i++){
        if(max<a[i]){
            max=a[i];
        }
    }
    for(i=0;i<n;i++){
        if(a[i]<min){
            min=a[i];
        }
    }
    printf("%d",max-min);
}

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

int main() {
  long long int a, b, c;
  cin >> a >> b >> c;
  if( c > a + b + 1 ) {
    cout << a + (b * 2) + 1 << endl;
  } else {
    cout << b + c << endl;
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))

dic = {}
for i in range(N):
    tmp = A[i]
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1

for _ in range(M):
    B, C = map(int, input().split())
    if C in dic:
        dic[C] += B
    else:
        dic[C] = B

dic = sorted(dic.items(), reverse=True)

ans, cnt = 0, 0
i = 0
while True:
    k, v = dic[i]
    cnt += v
    if cnt < N:
        ans += k*v
    elif cnt == N:
        ans += k*v
        break
    else:
        ans += k*(v - (cnt-N))
        break
    i += 1

print(ans)

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

using namespace std;

struct Dice
{
    int s[7];
    void roll(char c)
    {
        int tmp;
        if (c == 'E')
        {
            tmp = s[1];
            s[1] = s[4];
            s[4] = s[6];
            s[6] = s[3];
            s[3] = tmp;
        }
        if (c == 'W')
        {
            tmp = s[1];
            s[1] = s[3];
            s[3] = s[6];
            s[6] = s[4];
            s[4] = tmp;
        }
        if (c == 'N')
        {
            tmp = s[1];
            s[1] = s[2];
            s[2] = s[6];
            s[6] = s[5];
            s[5] = tmp;
        }
        if (c == 'S')
        {
            tmp = s[1];
            s[1] = s[5];
            s[5] = s[6];
            s[6] = s[2];
            s[2] = tmp;
        }
        if (c == 'R')
        {
            tmp = s[3];
            s[3] = s[2];
            s[2] = s[4];
            s[4] = s[5];
            s[5] = tmp;
        }
    }
    int top()
    {
        return s[1];
    }
    int left()
    {
        return s[4];
    }
    int right()
    {
        return s[3];
    }
    int front()
    {
        return s[2];
    }
    int bot()
    {
        return s[6];
    }
};

bool same(Dice d1, Dice d2){
    for(int i = 1;i<7;i++){
        if(d1.s[i]!=d2.s[i]) return false;
    }
    return true;
}
int main()
{
    Dice d1, d2;
    bool f = false;
    for (int i = 1; i < 7; i++)
    {
        scanf("%d", &d1.s[i]);
    }
    for (int i = 1; i < 7; i++)
    {
        scanf("%d", &d2.s[i]);
    }
    for(int i = 0;i<4;i++){
        d2.roll('N');
        for(int j = 0;j<4;j++){
            d2.roll('R');
            if(same(d1,d2)){
                f = true;
                printf("Yes\n");
                return 0;
            }
        }
    }
    d2.roll('E');
    for(int i = 0;i<4;i++){
        d2.roll('R');
        if(same(d1,d2)){
            f = true;
            printf("Yes\n");
            return 0;
        }
    }
    d2.roll('W');
    d2.roll('W');
    for(int i = 0;i<4;i++){
        d2.roll('R');
        if(same(d1,d2)){
            f = true;
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    
}


Measured memory_bytes: 3164
def d_dice_in_line():
    N, K = [int(i) for i in input().split()]
    P = [int(i) for i in input().split()]

    def experience(x):
        return (x + 1) / 2  # 1からxまで出るサイコロの出目の期待値

    ans = []
    tmp = 0
    for i in range(K):
        tmp += experience(P[i])
    ans.append(tmp)
    for i in range(K, N):
        tmp -= experience(P[i - K])
        tmp += experience(P[i])
        ans.append(tmp)
    return max(ans)

print(d_dice_in_line())

Measured memory_bytes: 25188
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	n = n % 10;
	if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) printf("hon\n");
	else if(n == 0 || n == 1 || n == 6 || n == 8 || n == -1) printf("pon\n");
	else if(n == 3 || n == 1 || n == 6 || n == 8 || n == -1) printf("bon\n");
	return 0;
}

Measured memory_bytes: 3768
//
// Created by pavao on 9/22/2019.
//

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string input;
    cin >> input;
    for (int i = 0; i < input.size(); i++) {
        if (i % 2 == 0 && input[i] == 'L') {
            cout << "No";
            return 0;
        }
        if (i % 2 == 1 && input[i] == 'R') {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
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};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {if(b<0) return 0;ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



string s;
int res, la, lq, rc, rq;

signed main() {
	cin >> s;
	rc = count(all(s),'C'), rq = count(all(s),'?');
	each(i,s) {
		if (i=='C') rc--;
		if (i=='?') rq--;
		if (i=='B' || i=='?') {
			int l = (la*mop(3,lq) + lq*mop(3,lq-1))%mod,
				r = (rc*mop(3,rq) + rq*mop(3,rq-1))%mod;
			(res += l*r) %= mod;
		}
		if (i=='A') la++;
		if (i=='?') lq++;
	}
	cout << res << ln;
}

Measured memory_bytes: 512
N = int(input())
l = [0 for i in range(N)]
for i in range(N):
    A,B = map(int, input().split())
    l[i] = [B,A]

l.sort()
tmp = 0
for i in range(N):
    tmp += l[i][1]
    if tmp > l[i][0]:
        print("No")
        exit()
print("Yes")

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

int main(){
  int K,N,j=0;
  cin>>K>>N;
  vector<int> A(N);
  for(int &i:A)
    cin>>i;
  for(int i=0;i<N;i++)
    j=max(j,(A.at((i+1)%N)+K-A.at(i))%K);
  cout<<K-j<<endl;
}

Measured memory_bytes: 1024
def resolve():
    '''
    code here
    '''
    N, A, B = [int(item) for item in input().split()]
    X_list = [int(item) for item in input().split()]

    memo = 0

    for i in range(N-1):
        w_cost = A * (X_list[i+1] - X_list[i])
        memo = min(memo + w_cost, memo + B)       
    
    print(memo)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 14252
N = int(input())
S = input()

tmp = []
f = []
dada = ""
for i in range(N - 2):
    s = []
    first = S[i]
    if S[i] in f:
        continue
    f.append(first)
    for j in range(i + 1, N - 1):
        t = []
        second = first + S[j]
        if S[j] in s:
            continue
        s.append(S[j])
        for k in range(j + 1, N):
            third = second + S[k]
            if S[k] in t:
                continue
            t.append(S[k])
            if third not in tmp:
                tmp.append(third)
# print(tmp)
print(len(tmp))


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

int main() {

    int n, k, q;

    cin >> n >> k >> q;

    vector<int> a(q);

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

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

    int tmp_num = 0;
    for ( int i = 0; i < q; i++ ) {
//        cout << a[i] << endl;
        tmp_num = a[i] - 1;
        p[tmp_num]++;
//        cout << p[tmp_num] << endl;
    }

    for ( int i = 0; i < n; i++ ) {
//        cout << p[i] << endl;
        if ( q - p[i] >= k ) {
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ", trim(fgets(STDIN)));
  $ki = [];
  $gu = [];
  for($i=0; $i<$n; $i++){
      $type[$a[$i]]++;
      if($a[$i]%2 == 0){
          $gu[] = $a[$i];
      }else{
          $ki[] = $a[$i];
      }
  }
  if(count($type)== 1){
      echo $a[0];
      exit;
  }
  if(empty($ki)){
      sort($gu);
      echo gcd($gu[1],$gu[0]);
      exit;
  }else{
      sort($ki);
  }
  
  if(empty($gu)){
      sort($ki);
      echo gcd($ki[1],$ki[0]);
      exit;
  }else{
      sort($gu);
  }
//   print_r($ki);
//   print_r($gu);
  
  echo gcd($ki[0],$gu[0]);
  
  function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);
     
    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}

Measured memory_bytes: 23284
#include <iostream>
#include <vector>
#include <math.h>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;


int main() {
	int n;
	int ba = 0, bb = 0, bt = 0;
	bool flag = true;
	cin >> n;
	rep(i, n) {
		int t, a, b, len, dt;
		cin >> t >> a >> b;
		len = abs(a - ba) + abs(b - bb);
		dt = t - bt;
		if ((len > dt) || (len % 2 != dt % 2)) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int tab[10][7]={
    {1,1,1,1,1,1,0},
    {0,1,1,0,0,0,0},
    {1,1,0,1,1,0,1},
    {1,1,1,1,0,0,1},
    {0,1,1,0,0,1,1},
    {1,0,1,1,0,1,1},
    {1,0,1,1,1,1,1},
    {1,1,1,0,0,1,0},
    {1,1,1,1,1,1,1},
    {1,1,1,1,0,1,1}
};
int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==-1) break;
        int now[7];
        for(int i=0;i<7;i++){
            now[i]=0;
        }
        int m;
        for(int i=0;i<n;i++){
            scanf("%d",&m);
            for(int j=6;j>=0;j--){
                printf("%d",now[j]^tab[m][j]);
                now[j]=tab[m][j];
            }
            printf("\n");
        }
    }
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    ans += a - 1;
    if(b >= a) ans++;
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <fstream>
#include <algorithm>
//#define LOCAL
using namespace std;
typedef long long ll;
const int mx=1e3+10;
ll num[mx];

int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll n;
cin>>n;
for(ll i=1;i<=n;i++) cin>>num[i];

ll qn;
cin>>qn;
for(ll i=1;i<=qn;i++){
    ll a, b;
    cin>>a>>b;
    reverse(num+a+1, num+b+1);
}

for(ll i=1;i<=n;i++){
    if(1==i) printf("%lld", num[i]);
    else printf(" %lld", num[i]);
}
puts("");

#ifdef LOCAL
fin.close();
#endif // LOCAL
}




Measured memory_bytes: 3232
n=int(input())
li=list(map(int,input().split()))
ans=0
li.sort()
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if(li[i]+li[j]>li[k] and len(set([li[i],li[j],li[k]]))>2):
        # print(li[i],li[j],li[k])
        ans+=1
print(ans)

Measured memory_bytes: 9200
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		List<Integer> D = new ArrayList<Integer>();
		for(int i=0;i<K;i++) {
			 D.add(scanner.nextInt());
		}
		for(int m = N;m<=99999;m++) {
			if(check(D,m)) {
				System.out.println(m);
				break;
			}
		}
		scanner.close();
	}
	public static boolean check(List<Integer> d, int n) {
		String num = String.valueOf(n);
		for(int i=0;i<num.length();i++) {
			int s = Character.getNumericValue(num.charAt(i)) ;
			if(d.contains(s)) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 26620
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */

#define MAXN (100000)
#define MOD (1000000007)

uint64_t dp[61][2][2][2];

int main(void)
{
    uint64_t l,r,ans;
    scanf("%ld %ld",&l, &r);

    //dp[桁][L<=X][Y<=R][先頭ビットが出た]
    dp[60][0][0][0] = 1;
    for(int i=59;i>=0;i--)
    {
        int lb = (l>>i)&1;
        int rb = (r>>i)&1;
        for(int j=0;j<2;j++)for(int k=0;k<2;k++)for(int s=0;s<2;s++)
        {
            for(int x=0;x<2;x++)for(int y=0;y<2;y++)
            {
                int nj = j, nk = k, ns = s;
                if(x && !y) continue;
                if(!s && (x!=y)) continue;
                if(!s &&  x && y) ns = 1;
                if(!j && !x && lb) continue;
                if(!j && x && !lb) nj = 1;
                if(!k && y && !rb) continue;
                if(!k && !y && rb) nk = 1;

                dp[i][nj][nk][ns] += dp[i+1][j][k][s];
                dp[i][nj][nk][ns] %= MOD;
            }
        }

    }
    ans = 0;
    for(int j=0;j<2;j++)for(int k=0;k<2;k++)for(int s=0;s<2;s++)
    {
        ans = (ans + dp[0][j][k][s])%MOD;
    }
    printf("%ld\n",ans);
    return 0;
}





Measured memory_bytes: 128
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

// https://atcoder.jp/contests/abc167/tasks/abc168_a
func main() {

	data := readLines()

	num, _ := strconv.Atoi(data[0][0])
	words := data[1][0]
	if len(words) > num {
		fmt.Print(words[0:num])
		fmt.Print("...")
	}else {
		fmt.Print(words)
	}


}

func readLines() [][]string {
	var result [][]string
	for i := 0; ; i++ {
		line, e := readLine()
		if e != nil {
			break
		}
		result = append(result, strings.Split(line, " "))
	}
	return result
}

func readLine() (string, error) {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			return "", e
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf), nil
}


Measured memory_bytes: 1964
#include <stdio.h>

int main(){
    double a,b,c,d,e,f;
    double x,y;
    
    while (scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF) {
        
        x=(c*e-b*f)/(a*e-b*d);
        y=(c*d-a*f)/(b*d-a*e);
        if(a*e-b*d==0||b*d-a*e==0){
            return 1;
        }
        if(x==-0)
            x=0;
        if(y==-0)
            y=0;
        printf("%.3f %.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <string>
#include <set>
using namespace std;

string revstr(const string& str)
{
	string ret;
	for (int i = str.length() - 1; i >= 0; i--) {
		ret += str[i];
	}
	return ret;
}

int main()
{
	int m;
	string str;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> str;
		set<string> setstr;
		setstr.insert(str);
		for (int ite = 1; ite < str.length(); ite++) {
			string str1 = str.substr(0,ite);
			string str2 = str.substr(ite, str.length() - ite);
			setstr.insert(revstr(str1) + str2);
			setstr.insert(str1 + revstr(str2));
			setstr.insert(revstr(str1) + revstr(str2));
			setstr.insert(str2 + str1);
			setstr.insert(str2 + revstr(str1));
			setstr.insert(revstr(str2) + str1);
			setstr.insert(revstr(str2) + revstr(str1));
		}
		cout << setstr.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  sort(h.begin(),h.end());
    long long sum;
  if(n>k){  
  sum=accumulate(h.begin(),h.begin()+n-k,0LL);
  }
  else sum=0;
      cout<<sum<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,x=0;
        cin>>n;
        ll a[n],b[n];

        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            x=x^a[i];
        }
        for(int i=0;i<n;i++)
        {
            b[i]=a[i]^x;
        }
        oa(b,n);
    }
    
}   

Measured memory_bytes: 6720
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,top,dp[N][4];
char s[N],t[N];
int solve()
{
    vector<int>v;
    int sum=0;
    for(int i=1;i<=top;i++)
        if(t[i]=='1') sum++;
        else if(sum) v.push_back(sum),sum=0;
    if(sum) v.push_back(sum);
    int ans=0;
    dp[0][2]=-1e9;
    for(int i=1;i<v.size();i++)
    {
        dp[i][2]=dp[i][3]=-1e9;
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
        dp[i][0]=max(dp[i][0],dp[i-1][2]);
        dp[i][0]=max(dp[i][0],dp[i-1][3]);
        dp[i][1]=dp[i-1][0]+max(v[i],v[i-1]);
        dp[i][1]=max(dp[i][1],dp[i-1][2]+max(v[i-1]-1,v[i]));
        dp[i][1]=max(dp[i][1],dp[i-1][3]+v[i]);
        if(v[i]>=2)
        {
            dp[i][2]=dp[i-1][0]+v[i-1];
            dp[i][2]=max(dp[i][2],dp[i-1][2]+v[i-1]-1);
            dp[i][2]=max(dp[i][2],dp[i-1][3]+1);
            dp[i][3]=dp[i-1][0]+max(v[i-1],v[i]-1);
            dp[i][3]=max(dp[i][3],dp[i-1][2]+max(v[i-1]-1,v[i]-1));
            dp[i][3]=max(dp[i][3],dp[i-1][3]+v[i]-1);
        }
        ans=max(ans,dp[i][0]);
        ans=max(ans,dp[i][1]);
        ans=max(ans,dp[i][2]);
    }
    return ans;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    n=strlen(s+1);
    int ans=0;
    for(int i=1;i<=n;i++)
    if(top==0||s[i]=='1'||t[top]!='0') t[++top]=s[i];
    else
    {
        ans+=solve();
        top=0;
    }
    ans+=solve();
    printf("%d\n",ans);
}
/*
111111111011111111101101111111111111
9 9 2 13

*/


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int N;
    cin >> N;
    int sum = 0;
    while(N!=0){
        sum += N;
        N--;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
#define endl "\n"
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const long long MOD = 998244353;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {int operator()(int x) const { return x ^ RANDOM; }};
string toString(long long x){stringstream ss;ss << x;string str = ss.str();return str;}
long long fastpow(long long x,long long k){if(!k)return 1;if(k & 1)return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
long long ans = fastpow(x,k/2);ans %= MOD;ans *= ans;ans %= MOD;return ans;}
long long sumF(long long x){int s = 0;while(x)s += x%10,x /= 10;return s;}
bool isS(char c){return (c >= 'a' && c <= 'z');}
bool isB(char c){return (c >= 'A' && c <= 'Z');}
bool isD(char c){return (c >= '0' && c <= '9');}
bool isSqrt(long long x){ long long f = sqrt((long double)x + 0.5); return f*f == x;}
bool isCubic(long long x) {long long f = cbrt((long double)x + 0.5); return f*f*f == x;}
long long lcm(long long a,long long b){return a * (b / __gcd(a,b));}
vector<long long> divisorsVector(long long x){vector<long long> tmp;for(long long i = 1;1LL*i*i <= x;i++){if(x % i == 0){tmp.push_back(i);if(x / i != i)
tmp.push_back(x / i);}}sort(tmp.begin(),tmp.end());return tmp;}
long long countDiv(long long L,long long R,long long C){return ((R/C) - ((L-1)/C));}
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
int nextLeft[100005];
int beforeRight[100005];
int32_t main()
{
    IO;
    string s;
    cin >> s;
    int pos = 0;
    for(int i = 0;i < s.length();i++)
    {
        if(s[i] == 'R')
            pos = i;
        if(s[i] == 'L')
            beforeRight[i] = pos;
    }
    for(int i = s.length() - 1;i >= 0;i--)
    {
        if(s[i] == 'L')
            pos = i;
        if(s[i] == 'R')
            nextLeft[i] = pos;
    }
    vector<int> ans(s.length(),0);
    for(int i = 0;i < s.length();i++)
    {
        if(s[i] == 'L')
        {
            int walked = i - beforeRight[i] - 1;
            if(walked % 2 != 0)
                ans[beforeRight[i]]++;
            else
                ans[beforeRight[i]+1]++;
        } else if(s[i] == 'R')
        {
            int walked = nextLeft[i] - i - 1;
            if(walked % 2 != 0)
                ans[nextLeft[i]]++;
            else
                ans[nextLeft[i]-1]++;
        }
    }
    for(int i = 0;i < s.length();i++)
        cout << ans[i] << " ";
    return 0;
}


Measured memory_bytes: 3024
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

vector<int> V[110000];

int N,a,b;
ll dis[110000],dis2[110000];

void dfs(int x){
  for(int i=0;i<(int)V[x].size();i++){
    int nx=V[x][i];

    if(dis[nx]==-1){
      dis[nx]=dis[x]+1;
      dfs(nx);
    }
  }
}

void dfs2(int x){
  for(int i=0;i<(int)V[x].size();i++){
    int nx=V[x][i];

    if(dis2[nx]==-1){
      dis2[nx]=dis2[x]+1;
      dfs2(nx);
    }
  }
}

int main(){
  cin>>N;
  //cout<<"unko"<<endl;
  for(int i=0;i<N-1;i++){
    cin>>a>>b;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  for(int i=0;i<110000;i++) dis[i]=-1;
  dis[1]=0;
  dfs(1);

  for(int i=0;i<110000;i++) dis2[i]=-1;
  dis2[N]=0;
  dfs2(N);
  int count=0;
  for(int i=1;i<=N;i++){
    if(dis[i]<=dis2[i]) count++;
    //cout<<dis[i]<<" "<<dis2[i]<<endl;
  }
  if(count*2<=N) cout<<"Snuke"<<endl;
  else cout<<"Fennec"<<endl;
}


Measured memory_bytes: 12288
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        //input
        Scanner sc = new Scanner(System.in);

        ArrayDeque<Integer> stack = new ArrayDeque<Integer>();
        ArrayList<Integer>  ar    = new ArrayList<Integer>();

        int i;
        while(sc.hasNext()){
        	i = sc.nextInt();
        	if  (i == 0){ar.add(stack.pop());  }
        	else        {stack.push(i);}
        }

        //output
        for(int j:ar){System.out.println(j);}
    }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;


vector<string> ans;
vector<int> p;


int n,m;
int a[maxN];
int main()
{
	scanf("%d%d",&n,&m);
	ll sum = 0;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		sum += a[i];
	}
	ll ans = n-sum;
	if(ans < 0)
	{
		puts("-1");
	}
	else
	{
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3828
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        es: [(usize1, usize1, usize); m]
    }
    let mut d = vec![vec![1 << 60; n]; n];
    for &(a, b ,c) in &es {
        d[a][b] = c;
        d[b][a] = c;
    }
    for i in 0..n {
        d[i][i] = 0;
    }
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    let mut ans = m;
    for &(a, b, c) in &es {
        for i in 0..n {
            if i == a {
                continue;
            }
            if d[a][i] == d[b][i] + c {
                ans -= 1;
                break;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <bits/stdc++.h>
     
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 1.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m, k;
    cin >> n >> m >> k;
    int a[k];
    rep(i, 0, k)
        cin >> a[i];
    vector<pair<int, int> > pos;
    rep(i, 0, n)
        if (i % 2 == 0)
            rep(j, 0, m)
                pos.push_back({i, j});
        else
            repb(j, m - 1, -1)
                pos.push_back({i, j});
    int ans[n][m];
    int p = 0;
    rep(i, 0, k)
        rep(j, 0, a[i])
        {
            ans[pos[p].fi][pos[p].se] = i + 1;
            p++;
        }
    rep(i, 0, n)
    {
        rep(j, 0, m)
            cout << ans[i][j] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 640