akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long n,k,mun,m=1,a,b;
	cin>>n>>k;
	int d[n];
	for(int i=0;i<n;++i)cin>>d[i];
	mun=d[0];
	for(int i=0;i<n-1;++i){
		if(d[i+1]<mun){
		     mun=d[i+1];
			m=(i+2);
		}
		
	}
	/*if(min((n-m),(m-1))>=(k-1)){
	if((m-1)%(k-1)==0){
		a=(m-1)/(k-1);
	}
	else{
		a=(m-1)/(k-1)+1;
	}
	if((n-m)%(k-1)==0){
		b=(n-m)/(k-1);
	}
	else{
		b=(n-m)/(k-1)+1;
	}
	cout<<a+b<<endl;
	}
	else{
		if((n-1)%(k-1)==0){
		    cout<<(n-1)/(k-1)<<endl;	
		}
		else{
			cout<<(n-1)/(k-1)+1<<endl;
		}
	}*/

	    if((n-1)%(k-1)==0){
		cout<<(n-1)/(k-1)<<endl;
	}
	else{
		cout<<(n-1)/(k-1)+1<<endl;
	}	
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
multiset<int>ms[N];
void solve(){
	int n, m;
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		int x, y;
		cin>>x>>y;
		ms[x].in(y);
	}
	for(auto i:ms[1]){
		auto it = *ms[i].lower_bound(n);
		if(it==n){
			cout<<"POSSIBLE";
			return;
		}
	}
	cout<<"IMPOSSIBLE";
}
signed main(){
	speed;
	int t=1;
	//cin>>t;
	while(t--)solve();
}

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

int main()
{
    int n,q;
    cin>>n>>q;
    priority_queue<int>a[n];
    REP(i,q)
    {
        int x,y,z;
        cin>>x>>y;
        if(x==0)
        {
            cin>>z;
            a[y].push(z);
        }
        if(x==1)
        {
            if(a[y].empty()==0)cout<<a[y].top()<<endl;
        }
        if(x==2)
        {
            if(a[y].empty()==0)a[y].pop();
        }
    }
}


Measured memory_bytes: 4008
a,b,c,d,e = (int(x) for x in input().split())

if a == 0:
  print(1)
  
elif b == 0:
  print(2)
  
elif c == 0:
  print(3)
  
elif d == 0:
  print(4)
  
else:
  print(5)

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

using namespace std;

int main()
{
    multiset <int> m;
    int q;
    cin>>q;
    while(q--)
    {
        int a;
        cin>>a;
        if(a==0)
        {
            int x;
            cin>>x;
            m.emplace(x);
            cout<<m.size()<<endl;
        }
        else if(a==1)
        {
            int x;
            cin>>x;
            cout<<m.count(x)<<endl;
        }
        else if(a==2)
        {
            int x;
            cin>>x;
            m.erase(x);
        }
        else
        {
            int l,r;
            cin>>l>>r;
            auto p=m.lower_bound(l);
            while(p!=m.end()&&*p<=r)
            {
                cout<<*p<<endl;
                p++;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 12284
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> a(s.size() + 1);
    irep(i, s.size())
    {
        if (i == 0) {
            a[i] = 0;
        } else {
            a[i] = a[i - 1] + (s[i - 1] == 'g' ? 1 : -1);
        }
    }

    cout << a[s.size()] / 2 << endl;

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m,a[100][100],b[100],c;
  ll ans=0;
  cin>>n>>m>>c;
  for(int i=0;i<m;i++)cin>>b[i];
  for(int i=0;i<n;i++){
    ll cnt=c;
    for(int j=0;j<m;j++){
      cin>>a[i][j];
      cnt+=a[i][j]*b[j];
    }
    if(cnt>0)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll mod = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int n,l; cin>>n>>l;
    int mini=INF;
    int lsum=n*l-n+n*(n+1)/2;
    int sagaku=0;
    rep(i,1,n+1){
        if(mini>=abs(l+i-1)){
            mini=min(mini,abs(l+i-1));
            sagaku=l+i-1;
        }
    }
    cout<<lsum-sagaku<<endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

int N, Z, W;
int a[2005];

/*==================================================*/

/*==================================================*/

int main() {
    cin>>N>>Z>>W;
    REP(i,0,N) cin>>a[i];
    if(N > 1){
        cout<<max(abs(a[N-1]-W), abs(a[N-2]-a[N-1]))<<endl;
    }else{
        cout<<abs(a[0]-W)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

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

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

ull next(ull x){
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    return x;
}

int main(){
    ull n, k, x0;
    while(cin >> n >> k >> x0){
        if(x0 == 0) {
            cout << 0 << endl;
            continue;
        }
        k--;
        const int B = 12; // 2^10

        int cnt[1 << B] = {};
        ull x = x0;
        for(int i = 0; i < n; i++){
            cnt[x >> (64 - B) ^ (1 << (B - 1))]++;
            x = next(x);
        }
        ull A = 0;
        for(ull s = 0; s < 1 << B; s++){
            if(k < cnt[s]) {
                A = s ^ (1 << (B - 1));
                break;
            }
            k -= cnt[s];
        }

        vector<ll> v;
        x = x0;
        for(int i = 0; i < n; i++){
            if(x >> (64 - B) == A) v.push_back((ll)x);
            x = next(x);
        }
        sort(v.begin(), v.end());
        cout << v[k] << endl;
    }

    return 0;
}

Measured memory_bytes: 1524
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v: Vec<usize> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (n, m) = (v[0], v[1]);

    let ans = std::cmp::min(m / 2, (2 * n + m) / 4);
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    long[] a = sc.nextLongArray(n);
    long result = 1000L;
    for (int i = 1; i < n; i++) {
      if (a[i] > a[i - 1]) {
        long stock = result / a[i - 1];
        result += stock * (a[i] - a[i - 1]);
      }
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 32712
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int ans = 0;
    if(a[0] == 0){
        swap(a[0], a[1]);
        ++ ans;
    }
    if(a[n-1] == n-1){
        swap(a[n-2], a[n-1]);
        ++ ans;
    }

    for(int i=1; i<n-1; ++i){
        if(a[i] == i){
            ++ ans;
            if(a[i+1] == i+1)
                ++ i;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main(void) {
    string s;
    int K;
    cin >> s >> K;
    size_t N = s.size();
    set<string> st;
    for(int i=0; i<N; i++) {
        for(int j=1; i+j<=N && j<=5; j++) {
            st.insert(s.substr(i, j));
        }
    }
    auto itr = st.begin();
    cout << *next(itr, K-1) << endl;
    return 0;
}


Measured memory_bytes: 1664
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=303;
int n,m,dp[N][N],cst[N][N],ans;
char ss[N][N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
inline int goon(int t)
{
	for(RG int i=0;i<=n;i++) for(RG int j=0;j<=n;j++) cst[i][j]=0, dp[i][j]=2e9;
	for(RG int i=n;i>=0;i--)
	 for(RG int j=n;j>=0;j--)
	  if(i==n || j==n) cst[i][j]=0;
	  else cst[i][j]=cst[i+1][j+1]+ (ss[n-i][t]==ss[n-j][t+1]);
	dp[0][0]=0;
	for(RG int i=0;i<=n;i++)
	 for(RG int j=0;j<=n;j++)
	 {
		if(i) dp[i][j]=mi(dp[i][j],dp[i-1][j]+cst[i-1][j]);
		if(j) dp[i][j]=mi(dp[i][j],dp[i][j-1]+cst[i][j-1]);
	 }
	return dp[n][n];
}
int main()
{
//	freopen("Friction.in","r",stdin);
	read(n,m);
	for(RG int i=1;i<=n;i++) scanf("%s",ss[i]+1);
	for(RG int i=1;i<m;i++) ans+=goon(i);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int B=1000000;
int main(){
      int h,w,n;
      while(cin>>h>>w>>n&&(h||w||n)){
            bool fld[w][h];
            REP(i,h)REP(j,w)cin>>fld[j][i];
            int cnt[w][h];
            memset(cnt,0,sizeof(cnt));
            cnt[0][0]=n-1;
            REP(i,h)REP(j,w){
                  if(fld[j][i]){
                        if(j<w-1)cnt[j+1][i]+=(cnt[j][i]+1)/2;
                        if(i<h-1)cnt[j][i+1]+=cnt[j][i]/2;
                  }else{
                        if(j<w-1)cnt[j+1][i]+=cnt[j][i]/2;
                        if(i<h-1)cnt[j][i+1]+=(cnt[j][i]+1)/2;
                  }
            }
            REP(i,h)REP(j,w){
                  //printf("%2d%c",cnt[j][i],j==w-1?'\n':' ');
                  if(cnt[j][i]%2==1)fld[j][i]^=1;
            }
            int x=0,y=0;
            while(x<w&&y<h){
                  if(fld[x][y])x++;
                  else y++;
            }
            cout<<y+1<<" "<<x+1<<endl;
      }
}

Measured memory_bytes: 6048
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 998244353
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
bool isp[114514];
int sum[114514];
signed main(){
	for(int i=2;i<=100000;i++){
		isp[i] = true;
	}
	for(int i=2;i<=100000;i++){
		if( isp[i] ){
			for(int j=2;i*j<=100000;j++){
				isp[i*j] = false;
			}
		}
	}
	for(int i=1;i<=100000;i++){
		sum[i] = sum[i-1];
		if( i % 2 == 1 && isp[i] && isp[(i+1)/2] ) sum[i]++;
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int lef,rig;
		cin>>lef>>rig;
		cout<<sum[rig] - sum[lef-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int N;
        //HashMap<Integer,Integer> list = new HashMap()<Integer,Integer>();
        ArrayList<Integer> v = new ArrayList<Integer>();
        ArrayList<Integer> c = new ArrayList<Integer>();
        ArrayList<Integer> list = new ArrayList<Integer>();

        Scanner sc = new Scanner(System.in);

        N=sc.nextInt();

        for(int i=0;i<N;i++){
            v.add(sc.nextInt());
        }
        
        for(int i=0;i<N;i++){
            c.add(sc.nextInt());
        }
        //Collections.sort(list);

        int ans = 0;
        for(int i=0;i<N;i++){
            if(v.get(i)-c.get(i)>0)
                ans += v.get(i)-c.get(i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21460
import sys
import math

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))

    solve(N)

def solve(N: int):
    # Symmetry, a<=b, a<=math.sqrt(N)
    N_max = min(N, 1000000000000)
    a_max = int(math.sqrt(N_max))
    tmp_list = []
    for a in range(1, a_max+1):
        if N%a == 0:
            b = int(N/a)
            tmp_list.append((a, b))

    if tmp_list:
        answer = tmp_list[0][0] + tmp_list[0][1]

    for i_tp in tmp_list:
        tmp = i_tp[0] + i_tp[1]

        if tmp < answer:
            answer = tmp

    print(answer - 2)
    return

 
if __name__ == "__main__":
    propare()

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main(void)
{
	int n, t = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n - 2; i++)
	{
		if (s.substr(i, 3) == "ABC")
		{
			t++;
		}
	}
	cout << t << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;
ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= M;
	if(k&1LL){
		ret *= x; ret %= M;
	}
	return ret;
}
ll FAC[200010];
void init_FAC(){
	FAC[0] = 1;
	rep1(i,200000){
		FAC[i] = FAC[i-1]*i;
		FAC[i] %= M;
	}
}

int main(){
	init_FAC();
	static int n,x,y;
	static int c[200010],w[200010];
	scanf("%d%d%d",&n,&x,&y);
	rep1(i,n){
		scanf("%d%d",&c[i],&w[i]);
	}
	
	static vector<int> vec[200010];
	rep1(i,n){
		vec[c[i]].pb(i);
	}
	static int minw[200010];
	rep1(i,n){
		minw[i] = INF;
		for(int id: vec[i]){
			minw[i] = min( minw[i] , w[id] );
		}
	}
	
	P minc[2] = {P(INF,INF),P(INF,INF)};
	rep1(i,n){
		if(minc[1] > P(minw[i],i)){
			minc[1] = P(minw[i],i);
			if(minc[0] > minc[1]){
				swap(minc[0],minc[1]);
			}
		}
	}
	
	vector<int> vec_;
	rep1(i,n){
		if(vec[i].size() == 0)continue;
		int mw_ex = minc[0].fr;
		if(minc[0].sc == i)mw_ex = minc[1].fr;
		if(mw_ex+minw[i] > y)continue;
		int cnt = 0;
		for(int id: vec[i]){
			if(w[id]+mw_ex <= y || w[id]+minw[i] <= x)cnt ++;
		}
		vec_.pb(cnt);
	}
	
	ll ret = 1;
	ll sum = 0;
	for(int i: vec_){
		sum += i;
		ret *= modpow(FAC[i],M-2);
		ret %= M;
	}
	ret *= FAC[sum];
	ret %= M;
	cout << ret << endl;
}

Measured memory_bytes: 13824
L=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
N=int(input())
S=list(input())
S=[L[L.index(i)+N] for i in S]
print("".join(S))

Measured memory_bytes: 65128
#11
n,m = map(int,input().split())
ab = []
cd = []
for i in range(n):
    ab.append(list(map(int,input().split())))
for i in range(m):
    cd.append(list(map(int,input().split())))
    
for i in range(n):
    Max = [0,float("inf")]
    for j in range(m):
        l = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if Max[1]>l:
            Max = [j+1,l]
    print(Max[0])
    
    

Measured memory_bytes: 9116
#include <iostream>
using namespace std;
 
int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  int x = 0;
  int max = 0;
  for (int i=0; i<N;i++){
  	if (S[i]=='I') x++;
    else x--;
  	if (x > max) max = x;
  }
  cout << max;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 999999
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node T[MAX];

/* プロトタイプ宣言 */
int getSib(int u);
void doPrint (int u);
int getDepth(int u);

int n, D[MAX], H[MAX];

int getSib(int u){
  if ( T[u].p == NIL ) return NIL;
  if ( T[T[u].p].r != u && T[T[u].p].r != NIL ) return T[T[u].p].r;
  if ( T[T[u].p].l != u && T[T[u].p].l != NIL ) return T[T[u].p].l;
  
  return NIL;
}

int getDepth(int u){
  int dep = 0;
  while(1){
    u = T[u].p;
    if ( u == NIL ) break;
    dep++;
  }
  return dep;
}


void doPrint(int u){
	int d = 0;
  printf("node %d: ", u);

  printf("parent = %d, ", T[u].p);
  printf("sibling = %d, ", getSib(u));

  if ( T[u].l != NIL ) d++;
  if ( T[u].r != NIL ) d++;
  printf("degree = %d, ", d);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].p == NIL ){
    printf("root\n");
  } else if ( T[u].l == NIL && T[u].r == NIL ){
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main(){
  int i, v, l, r;
  
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ){
  	H[i] = 0;
    D[i] = getDepth(i);
  }

  for ( i = 0; i < n; i++ ){
    if ( T[i].l == NIL && T[i].r == NIL ) {
      H[i] = 0;
      int p = T[i].p;
      
      int c = 1;
      while(1){
	if ( p == NIL ) break;
	if ( H[p] < c ) H[p] = c;
	c++;
	p = T[p].p;
      }
    }
  }

  for ( i = 0; i < n; i++ ) doPrint(i);
  return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(void){
    int N,cnt=0;
    cin>>N;
    VI p(N),cp(N);
    rep(i,N){
        cin>>p[i];
        cp[i]=p[i];
    }
    sort(cp.begin(),cp.end());
    rep(i,N){
        if(p[i]!=cp[i])cnt++;
    }
    if(cnt>2)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


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

using namespace std;

const int N = 1234567;

int n;
int a[N];

long long solve(int sgn) {
  long long sum = 0;
  int s;
  long long ret = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (sum < 0) s = -1;
    if (sum == 0) s = 0;
    if (sum > 0) s = 1;
    if (s != sgn) {
      if (sgn == -1) {
        ret += abs(-sum - 1);
        sum = sgn;
      } else {
        ret += abs(-sum + 1);
        sum = sgn;
      }
    }
    sgn *= -1;
  }
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  long long ans = min(solve(-1), solve(1));
  printf("%lld\n", ans);
  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  map<int, int> MA;
  multiset<int> MS;
  for (int i = 0; i < W; i++) MA[i] = i, MS.insert(0);
  for (int h = 1, A, B; cin >> A >> B; h++) {
    auto it = MA.lower_bound(--A);
    int tmp = -1;
    while (it != MA.end() && it -> first <= B) {
      tmp = max(tmp, it -> second);
      MS.erase(MS.find(it -> first - it -> second));
      MA.erase(it++);
    }
    if (tmp != -1 && B < W) MA[B] = tmp, MS.insert(B - tmp);
    cout << ((MS.size()) ? *MS.begin() + h : -1) << "\n";
  }
}

Measured memory_bytes: 22276
/*input
8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2


*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
//void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;

int solve(int n,int m,int cost[],vector<vector<int>> &arr,int start ,int k,vector<int> &level,int final_cost ){
	int flag = 0;
	for(int i=0;i<m;i++){
		if(level[i]<k){
			flag=1;
		}
	}
	if(flag==0){
		return final_cost;
	}
	if(start==n){
		for(auto i:level){
			if(i<k) return INT_MAX;
		}
		return final_cost;
	}
	int ans = INT_MAX;
	for(int i = start;i<n;i++){
		for(int j=0;j<m;j++){
			level[j]+=arr[i][j];
		}
		ans  = min(solve(n,m,cost,arr,i+1,k,level,final_cost+cost[i]),ans);
		for(int j=0;j<m;j++){
			level[j]-=arr[i][j];
		}
		ans = min(ans,solve(n,m,cost,arr,i+1,k,level,final_cost));
	}
	return ans;
}

int32_t main() {
    IOS;
	int n,m,k;cin>>n>>m>>k;
	int cost[n];
	vector<vector<int>> arr(n,vector<int> (m,0));
	for(int i=0;i<n;i++){
		cin>>cost[i];
		for(int j=0;j<m;j++){
			cin>>arr[i][j];
		}
	}
	vector<int> level(m,0);
	int ans = 0;
	ans = solve(n,m,cost,arr,0,k,
		level,0);
	if(ans == INT_MAX)cout<<"-1"<<endl;
	else 
	cout<<ans<<endl;
	return 0;
}






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

int main() {
  int d;

  while(cin>>d){
    int a=1;
    while(true){
      if(d==0) break;
      if(d%2==1) {
	cout<<a;
	d--;
	if(d>0) cout<<" ";
      }
      d/=2;
      a*=2;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
int i = 1;
while(1)
{
int x;
scanf("%d",&x);
if(x == 0) break;
printf("Case %d: %d\n",i,x);
i += 1;
}
return 0;
} 


Measured memory_bytes: 3108
using System;
using System.Linq;
using System.Collections.Generic;


namespace Test1 {



    class ClassMain {


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = ints[0];
                int n = int.Parse(line);
                if(n==0){break;}

                int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                HashSet<int> prev = new HashSet<int>();
                HashSet<int> newly = new HashSet<int>();
                for (int i = 0; i < n; i++) {
                    foreach (int ele in prev) {
                        newly.Add(ele + ints[i]);
                    }
                    newly.Add(ints[i]);
                    foreach (int ele in newly) { prev.Add(ele); }
                }

                int allsum=0; for(int i=0; i<n;i++){allsum+=ints[i];}
                for (int i = allsum / 2; i > 0; i--) {
                    if (newly.Contains(i)) {
                        int aiteSenryoku = allsum - i;
                        Console.WriteLine(aiteSenryoku - i);
                        break;
                    }
                }



            }
            
        }

        
    }

    

    
}

Measured memory_bytes: 9968
#include<bits/stdc++.h>
using namespace std;
#define lld double
lld n;
vector<lld> arr;
vector<vector<lld> > dp;
lld dfs(lld idx,lld heads){
	if(heads<0)
		return 0.0;
	if(idx==0){
		return heads==0;
	}
	if(dp[idx][heads]!=-1){
		return dp[idx][heads];
	}
	lld x=0;
	x=arr[idx]*dfs(idx-1,heads-1)+((1.0-arr[idx])*dfs(idx-1,heads));
	dp[idx][heads]=x;
	return dp[idx][heads];
}
int main(){
	cin>>n;
	arr.push_back(0);
	for(int i=1;i<=n;i++){
		double data;
		cin>>data;
		arr.push_back(data);
	}
	dp.resize(n+2,vector<lld>(n+2,-1));
	lld total=0;
	for(int i=0;i<=n;i++){
		int tails=n-i;
		if(i>tails){
			total+=dfs(n,i);
		}
	}
	cout<<setprecision(9)<<fixed<<total<<"\n";
}

Measured memory_bytes: 71040
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ld a, b;
    cin>>a>>b;
    cout<<(ll)floor(a*b);
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 3728
/*
AizuOnline A0093
Leap Year
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int a,b;
int flag;
//
int isLeap(int y)
{
  if(y % 4)return(0);
  if(y % 400 ==0)return(1);
  if(y % 100 ==0)return(0);
  return(1);
}
main()
{
  int i;
  int startf;

  startf=1;

  while(EOF != scanf("%d %d",&a,&b) && (a && b))
    {
      if(startf)
	startf=0;
      else 
	printf("\n");

      flag=0;
      for(i=a;i<=b;i++)
	if(isLeap(i))
	  {
	    printf("%d\n",i);
	    flag = 1;
	  }

      if(flag == 0)
	printf("NA\n");


    }
return(0);
}

Measured memory_bytes: 616
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut entered = vec![false; n + 1];
    for i in (1..n + 1).rev() {
        let mut temp = 0;
        for j in 2..n + 1{
            let k = j * i;
            if k > n {
                break;
            }
            if entered[k] {
                temp += 1;
            }
        }
        if temp % 2 != a[i - 1] {
            entered[i] = true;
        }
    }
    assert!(entered[0] == false);
    let mut answers = vec![];
    for i in 0..n + 1 {
        if entered[i] {
            answers.push(i);
        }
    }
    println!("{}", answers.len());
    if !answers.is_empty() {
        print_array(&answers);
    }
}
fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main(void){
    int H,W,i,j;
    while(true){
        cin >> H;
        cin >> W;
    
        if(H == 0 && W == 0){
            break;
        }
        for(i = 0;i < H;i++){
            for(j = 0;j < W;j++){
                cout << "#" ;
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3084
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//236
	int n,m;
	cin>>n>>m;
	vi arr(n+1,0);
	set<int> broken;
	while(m--){
		int val;
		cin>>val;
		broken.insert(val);
	}
	arr[0]=1;
	if(broken.count(1)==0)arr[1]=1;
	REP(i,2,n) {
		if(broken.count(i))arr[i]=0;
		else arr[i]+=(arr[i-1]+arr[i-2])%MOD;
	}
	cout<<arr[n];
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 8272
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
ll N, A;

// x個連続で作る、k回食べる時に目標値Nを達成できるか
bool check(ll x, ll k){
    return ceil(pow(N, 1.0 / (k + 1))) <= x;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    cin >> N >> A;
    ll ret = N;
    
    // k回食べるときに、x個以上連続で作れば初めてN個を達成できるかを二分探索
    rep(k, 42){
        ll l = -1, x = N;
        while(x - l > 1){
            ll mid = (l + x) / 2;
            if(check(mid, k)) x = mid;
            else l = mid;
        }
//        cout << k << ": " << x << endl;
        
        rep(i, k + 1){
            // i回(x - 1)個づつ作って、(k - i + 1)回x個づつ作ってN個を達成できるかを全探索
            bool ok = false;
            ll cur = 1;
            rep(j, i) cur *= x - 1;
            rep(j, k - i + 1) cur *= x;
            
            if(cur >= N) ok = true;
            if(ok) {
                ret = min(A * k + i * (x - 1) + (k - i + 1) * x, ret);
            }
        }
    }
    
    
    

    
    output(ret);
    
    
    return 0;
}

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

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n, a, b;
   cin >> n >> a >> b;
   string s;
   cin >> s;
   int aq = 0;
   int bq = 0;
   vector<string> ans(n);
   for (int i = 0; i < n; i++) {
      if (s[i] == 'a') {
         if (aq + bq < a + b) {
            ans[i] = "Yes";
            aq++;
         }
         else ans[i] = "No";
      }
      else if (s[i] == 'b') {
         if (aq + bq < a + b && bq < b) {
            ans[i] = "Yes";
            bq++;
         }
         else ans[i] = "No";
      }
      else ans[i] = "No";
   }
   for (int i = 0; i < n; i++) {
      cout << ans[i] << '\n';
   }
   return 0;
}

Measured memory_bytes: 6224
n,m=map(int,input().split())
s=[[0]*m for _ in range(2)]
for k in range(m):
	i,j=map(int,input().split())
	s[1][k]=i
	s[0][k]=j

u=sorted([list(x) for x in list(zip(*s))])
#print(u)
s0=0
ans=0
for i in range(m):
	if s0<=u[i][1]:
		s0=u[i][0]
		ans+=1
print(ans)


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	if(s == "SUN")
		cout << 7;
	else if(s == "MON")
		cout << 6;
	else if (s == "TUE")
		cout << 5;
	else if (s == "WED")
		cout << 4;
	else if (s == "THU")
		cout << 3;
	else if (s == "FRI")
		cout << 2;
	else if (s == "SAT")
		cout << 1;

	return 0;
}

Measured memory_bytes: 256
class WeightedUnionFind:
    def __init__(self, n):
        self.par=[i for i in range(n+1)]
        self.rank=[0]*(n+1)
        self.weight=[0]*(n+1)
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            y=self.find(self.par[x])
            self.weight[x]+=self.weight[self.par[x]]
            self.par[x]=y
            return y
    def unite(self,x,y,w):
        rx=self.find(x)
        ry=self.find(y)
        if self.rank[rx]<self.rank[ry]:
            self.par[rx]=ry
            self.weight[rx]=w-self.weight[x]+self.weight[y]
        else:
            self.par[ry]=rx
            self.weight[ry]=-w-self.weight[y]+self.weight[x]
            if self.rank[rx]==self.rank[ry]:
                self.rank[rx]+=1
    def same_check(self,x,y):
        return self.find(x)==self.find(y)
    def diff(self,x,y):
        return self.weight[x]-self.weight[y]

n,m=map(int,input().split())
uf=WeightedUnionFind(n)
for _ in range(m):
    l,r,d=map(int, input().split())
    if uf.same_check(l,r):
        if uf.diff(l,r)!=d:
            print("No")
            exit()
    else:
        uf.unite(l,r,d)
print("Yes")

Measured memory_bytes: 10236
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints

puts N.to_s(K).length


Measured memory_bytes: 14420
import Control.Monad
import Data.List

find_2 :: [Int] -> Int -> Int -> Int
find_2 arr a b = sides !! mod (get_value (findIndex (==b) sides) + 1) 4
  where sides = side_view arr a
    
-- get_value :: Maybe Int -> Int
get_value (Just x) = x
get_value Nothing = 0

side_view :: [Int] -> Int -> [Int]
side_view (a:b:c:d:e:f) x 
  | a == x = [b, c, e, d]
  | b == x = [a, d, f!!0, c]
  | c == x = [a, b, f!!0, e]
  | d == x = [a, e, f!!0, b]
  | e == x = [a, c, f!!0, d]
  | otherwise = [b, d, e, c]


main = do
  line <- getLine :: IO String
  let arr = map read (words line) :: [Int]
  nio <- getLine
  let n = read nio :: Int
  dicestr <- replicateM n getLine
  let dice = map (map read . words) dicestr :: [[Int]]
  forM_ dice $ \x -> do
    print $ find_2 arr (x!!0) (x!!1)

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
typedef complex<double> CP;
int n, L;
double ang[3005];
int main() {
	scanf("%d%d", &n, &L);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		ang[i] = PI * 2.0 * x / L;
	}
	CP ps = 0, ans = 0;
	for (int i = 1; i < n; i++) {
		ps += CP(cos(0.5 * (ang[i - 1] - PI)), sin(0.5 * (ang[i - 1] - PI)));
		for (int j = i + 1; j < n; j++) {
			ans += CP(cos(0.5 * (ang[i] + ang[j])), sin(0.5 * (ang[i] + ang[j]))) * (double)i;
			ans += 2.0 * sin((ang[j] - ang[i]) * 0.25) * ps * CP(cos((ang[i] + ang[j]) * 0.25), sin((ang[i] + ang[j]) * 0.25));
		}
	}
	ans /= (double)(1ll * n * (n - 1) * (n - 2) / 6);
	printf("%.12lf %.12lf\n", ans.real(), ans.imag());
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout<<"debuglandınız\n";

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int i,j;
	string s1, s2;
	cin >> s1 >> s2;
	int n=s1.length(), m=s2.length();
	int dp[n+1][m+1];
	for(i=0;i<=n;i++)for(j=0;j<=m;j++){
		if(i && j){
			if(s1[i-1]==s2[j-1])dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
		else
			dp[i][j]=0;
	}
	stack<char>cugaram;
	i--;j--;
	while(i&&j){
		if(dp[i][j]==dp[i-1][j]){
			i--;
			continue;
		}
		else if(dp[i][j]==dp[i][j-1]){
			j--;
			continue;
		}
		else{
			cugaram.push(s1[i-1]);
			i--;
			j--;
		}
	}
	while(cugaram.size()){
		cout<<cugaram.top();
		cugaram.pop();
	}
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
int x;

int a[200010];

int main(){

  n = in();
  x = in();

  if( x == 1 or x == 2*n-1 ){
    puts( "No" );
    return 0;
  }

  a[n-2] = x-1;
  a[n-1] = x;
  a[n] = x+1;

  int it = 2*n-1;
  REP( i , 2*n-1 ){
    if( n-2 <= i and i <= n ){
      continue;
    }
    while( x-1 <= it and it <= x+1 ){
      it--;
    }
    a[i] = it--;
  }

  puts( "Yes" );
  REP( i , 2*n-1 ){
    printf( "%d\n" , a[i] );
  }
  
  return 0;
}


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

#define int long long
#define max(a,b) max((signed)a,(signed)b)
#define mn(a,b) min((signed)a,(signed)b)

using namespace std;

signed main(){
	int n,k;
	cin>>n;
	int freq[100005]={0};
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>k;
		sum += k;
		freq[k]++;
	}
	int q;
	cin>>q;
	while(q--){
		int b,c;
		cin>>b>>c;
		int remove,add;
		remove = b*freq[b];
		add = c*freq[b];
		freq[c] += freq[b];
		freq[b]=0;
		sum = sum-remove+add;
		cout<<sum<<"\n";
	}
}

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

// int n; cin >> n;
// cout << n << endl;
int main() {
  int n; cin >> n;
  vector<int> p(n);
  rep(i, n) {
    cin >> p.at(i);
  }
  int smallest = p.at(0);
  int sum = 0;
  rep(i, n) {
    if (smallest >= p.at(i)) {
      sum++;
      smallest = p.at(i);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1024
/*
  Contest 065
  B - Trained?
  Rakesh Kumar --> 31/08/2020
b*/

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int n = 0;
    std::cin >> n;
    std::vector<int> deep_maala(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        int p = 0;
        std::cin >> p;
        deep_maala[i] = p;
    }

    int curr = 1, next = 0;
    int dabana = 0;
    while (1) {
        ++dabana;
        if (deep_maala[curr] == 2) {
            std::cout << dabana << std::endl;
            break;
        }
        if (deep_maala[curr] == 0) {
            std::cout << -1 << std::endl;
            break;
        }
        next = deep_maala[curr];
        deep_maala[curr] = 0;
        curr = next;
    }

    return 0;
}


Measured memory_bytes: 3716
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let n: u64 = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut memo = HashMap::<&u64, u64>::new();
    for ai in a.iter() {
        let count = memo.entry(ai).or_insert(0);
        *count += 1;        
    }

    let mut sum = 0;
    for (_key, value) in &memo {
        sum += if value % 2 == 0 {
            value / 2 * (value-1)
        } else {
            (value-1) / 2 * value
        }
    }
    for ai in a.iter() {
        let kazu = memo.get(ai).unwrap();
        println!("{}", sum-kazu+1);
    }
}


Measured memory_bytes: 17176
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n; cin >> n;
    lli cnt = ceil(n/2.0);
    cout << 1.0 * cnt / n << endl;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

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>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

int main()
{
	fast;
	int n;
	cin >> n;
	cout << (10000 - n) % 1000 << en;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int X;
  cin>>X;
  if(X<1200) cout<<"ABC"<<endl;
  else if(X<2800) cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl;
}

Measured memory_bytes: 256