akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>

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


int main() {
    int n, m; cin >> n >> m;
    int min, max;
    vector<int> l(m), r(m);
    rep(i,m){
        cin >> l[i] >> r[i];
        if (i == 0){
            min = l[0];
            max = r[0];
            continue;
        }
        if (min < l[i]){
            min = l[i];
        }
        if (max > r[i]){
            max = r[i];
        }
    } 
    if (max - min < 0){
        cout << 0 << endl;
    }else{
        cout << max - min + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
queue<char> Q;

void qpush(char a,int n){
	REP(i,n){
		Q.push(a);
	}
	return;
}

int main(){

	int N;SCD(N);
	char s[102];
	getchar();

	REP(i,N){
		char x;
		scanf("%c",&s[i]);
	}
	
	int bal = 0;
	int sc = 0;
	int rmcount = 0;
	
	REP(i,N){
		if (s[i] == '('){
			bal++;
		}else{
			bal--;
		}
		
		rmcount = min(rmcount,bal);
	}
	
	rmcount = (-1) * rmcount;

	qpush('(',rmcount);
	REP(i,N){
		Q.push(s[i]);
	}
	bal = rmcount + bal;
	qpush(')',bal);
	
	while(!Q.empty()){
		char x = Q.front();
		printf("%c",x);
		Q.pop();
	}
	
	printf("\n");
	return 0;
}

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

const long double PI = acos(-1);
 
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); }

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

    for(int i = 0; i < n; i++){
        ans += s[i];
        ans += t[i];
    }

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

Measured memory_bytes: 256
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N, L;
    cin >> N >> L;

    int min = 10000000;
    int sum = 0;
    int minAji = 10000000;
    for(int i=0;i<N;i++){
        int aji = L + i;
        if(abs(aji) < min){
            min = abs(aji);
            minAji = aji;
        }
        sum += aji;
    }
    cout << sum-minAji << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <bitset>

using namespace std;
typedef long long LL;
const int maxn = 1005;
const int N = 3;
const int S = 32000;
const int mod = 1e9+7;

int tr[N][N]={{2,2,1},{1,1,1},{1,0,1}};
int bd[N][N]={{1,2,1},{0,1,1},{0,0,1}};
int mat[S+1][N][N],mat2[S][N][N],cur[N],n,m;

void mulcur(int a[N][N]) {
	int a00=a[0][0],a01=a[0][1],a02=a[0][2];
	int a10=a[1][0],a11=a[1][1],a12=a[1][2];
	int a20=a[2][0],a21=a[2][1],a22=a[2][2];
	int c0=cur[0],c1=cur[1],c2=cur[2];
	cur[0]=((LL)c0*a00+(LL)c1*a10+(LL)c2*a20)%mod;
	cur[1]=((LL)c0*a01+(LL)c1*a11+(LL)c2*a21)%mod;
	cur[2]=((LL)c0*a02+(LL)c1*a12+(LL)c2*a22)%mod;
}
void mul(int a[N][N],int b[N][N],int c[N][N]) {
	for (int i=0;i<N;i++)
	for (int j=0;j<N;j++) {
		LL res=0;
		for (int k=0;k<N;k++)
			res+=(LL)b[i][k]*c[k][j];
		a[i][j]=res%mod;
	}
}
int main()
{
	#ifdef Amberframe
		freopen("agc013e.in","r",stdin);
		freopen("agc013e.out","w",stdout);
	#endif
	scanf("%d %d",&n,&m);
	mat[0][0][0]=mat[0][1][1]=mat[0][2][2]=1;
	mat2[0][0][0]=mat2[0][1][1]=mat2[0][2][2]=1;
	cur[0]=1;
	
	for (int i=1;i<=S;i++)
		mul(mat[i],mat[i-1],tr);
	for (int i=1;i<S;i++)
		mul(mat2[i],mat2[i-1],mat[S]);
		
	int pos=0;
	for (int x,i=1;i<=m;i++)
	{
		scanf("%d",&x);int d=x-pos-1;
		if (d>=S) mulcur(mat2[d/S]);
		mulcur(mat[d%S]);
		mulcur(bd);pos=x;
	}
	int d=n-pos-1;
	if (d>=S) mulcur(mat2[d/S]);
	mulcur(mat[d%S]);
	printf("%d",((LL)cur[0]+cur[1]+cur[2])%mod);
	return 0;
}

Measured memory_bytes: 2560
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'
 return'S'
n=int(input())
f=lambda x,y:(x,int(y))
A=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]
k(A,0,n-1)
for e in[[s(A)+'table']]+A:print(*e[:2])


Measured memory_bytes: 21120
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

char s[55][55];

int main()
{
	int h,w,vis;
	while(~scanf("%d %d",&h,&w))
	{
		for(int i = 1;i <= h;i++)
		{
			getchar();
			for(int j = 1;j <= w;j++)
			{
				scanf("%c",&s[i][j]);
			}
		}
		vis = 0;
		for(int i = 2;i < h;i++)
		{
			for(int j = 2;j < w;j++)
			{
				if(s[i][j] == '#')
				{
					vis = 1;
					if(j < w&& s[i][j + 1] == '#') vis = 0;
					if(j > 1&& s[i][j - 1] == '#') vis = 0;
					if(i < h&& s[i + 1][j] == '#') vis = 0;
					if(i > 1&& s[i - 1][j] == '#') vis = 0;
				}
				if(vis == 1) break;
			}
			if(vis == 1) break;
		}
		if(vis == 0) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 5005, MOD = 1e9 + 7;
int a[N], col[N], used[N], ct[N];
ll dp[N][N];
bool finished[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

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

    int cc = 0;

    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            vector<int> v;
            int x = i;

            while (x != -2 && !used[x]) {
                v.push_back(x);
                used[x] = 1;
                x = a[x];
            }

            int cur = ((x == -2 || used[x] == 1) ? cc++ : col[x]);

            if (x == -2 || used[x] == 1)
                finished[cur] = (used[x] == 1);

            for (const int &y : v) {
                col[y] = cur;
                ct[cur]++;
                used[y] = 2;
            }

            // for (const int &y : v) {
            //     cout << y << " ";
            // }
            // cout << "\n";
        }
    }

    ll ans = 0, all_ways = 1, anime = 1;

    vector<int> not_fin;

    // for (int i = 0; i < n; i++) {
    //     cout << col[i] << "\n";
    // }

    for (int i = 0; i < cc; i++) {
        if (finished[i]) {
            ans++;
        }
        else {
            all_ways = all_ways * (n - 1) % MOD;
            not_fin.push_back(ct[i]);
        }
    }

    for (int i = 0; i + 1 < not_fin.size(); i++)
        anime = anime * (n - 1) % MOD;

    for (int i = 0; i < not_fin.size(); i++)
        ans = ans * (n - 1) % MOD;

    for (const int &y : not_fin)
        ans = (ans + anime * (y - 1)) % MOD;

    dp[0][0] = 1;

    for (int i = 0; i < not_fin.size(); i++) {
        for (int j = 0; j <= i; j++) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * (n - 1)) % MOD;
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * not_fin[i]) % MOD;
        }
    }
    

    ll fac = 1;

    for (int i = 2; i <= not_fin.size(); i++) {
        ans = (ans + dp[not_fin.size()][i] * fac) % MOD;
        fac = (fac * i) % MOD;
    }

    ans = (n * all_ways - ans + MOD) % MOD;

    cout << ans;

    return 0;
}

Measured memory_bytes: 120408
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k){
	while(u != NIL && k!= u->key){
		if(k < u->key)
			u = u->left;
		else
			u = u->right;
	}
	return u;
}

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if(y == NIL)
		root = z;
	else{
		if(z->key < y->key){
		y->left = z;
	}
	else
		y->right = z;
	}
}

void inorder(Node *u){
	if(u == NIL)
		return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u){
	if(u == NIL)
		return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n, i, x;
	string com;

	scanf("%d", &n);

	for(i = 0; i < n; i++){
		cin >> com;
		if(com[0] == 'f'){
			scanf("%d", &x);
			Node *t = find(root, x);
			if(t != NIL)
				printf("yes\n");
			else
				printf("no\n");
		}
		else if(com == "insert"){
			scanf("%d", &x);
			insert(x);
		}
		else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N, M;
    cin >> N >> M;
    map<int, bool> fst, snd;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        if(a == 1) {
            fst[b] = true;
        }
        if(b == N) {
            snd[a] = true;
        }
    }
    FOR(i, 2, N) {
        if(fst[i] && snd[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}



Measured memory_bytes: 18944
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long long int> VLL;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    io;
    int x, n;
    cin >> x >> n;
    VI a(n);
    for (auto& y : a)
        cin >> y;

    if (n == 0) {
        cout << x << "\n";
    } else {
        unordered_set<int> data;
        for (auto x : a)
            data.insert(x);

        int diff = INT_MAX, ans = 0;

        FOR (i, 0, 102) {
            if (data.find(i) != data.end())
                continue;
            if (abs(i - x) < diff) {
                diff = abs(i-x);
                ans = i;
            }
        }
        cout << ans << "\n";
    }
}   
//check for edge cases in limits
//printing double may print 1.223232e9 like values, beware of that


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

int main(){
  int N,x=0,y=0;
  cin >> N;
  for(int i=0; i<N; i++){
    int a,b;
    cin >> a >> b;
    x=b-a+1;
    y+=x;
  }
  cout << y << endl;
}

Measured memory_bytes: 256
//ABC097A
#include<stdio.h>

main() {
	int a, b, c, d, i, j, k;

	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	i = abs(c - a);
	j = abs(b - a);
	k = abs(c - b);

	if (i <= d) {
		printf("Yes");
	
	}else if (j <= d && k <= d){
		printf("Yes");

	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int n;
	cin >> n;
	cout << 800 * n - (n / 15) * 200 << endl;

	return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
int bit[70];
ll dp[71][2][2][2];

int main(void){
	scanf("%lld",&n);
	ll nn=n;
	int cnt=0;
	while(nn>0){
		bit[cnt]=nn&1;
		nn>>=1;
		cnt++;
	}
	dp[0][0][0][0]=1;
	for(int i=0;i<cnt;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				for(int l=0;l<2;l++){
					int nk,nl,nj;
					for(int nx=0;nx<=1;nx++){
						for(int ns=0;ns<=1;ns++){
							if(nx==1 && ns==0)continue;
							if(nx==1 && ns==1){
								ns+=j;
								if(bit[i]<nx)nk=1;
								if(bit[i]==nx)nk=k;
								if(bit[i]>nx)nk=0;
								nj=(ns>=2)?1:0;
								if(bit[i]<ns-nj*2)nl=1;
								if(bit[i]==ns-nj*2)nl=l;
								if(bit[i]>ns-nj*2)nl=0;
								dp[i+1][nj][nk][nl]+=dp[i][j][k][l];
								dp[i+1][nj][nk][nl]%=MOD;
								ns-=j;
							}
							if(nx==0 && ns==0){
								ns+=j;
								if(bit[i]<nx)nk=1;
								if(bit[i]==nx)nk=k;
								if(bit[i]>nx)nk=0;
								nj=(ns>=2)?1:0;
								if(bit[i]<ns-nj*2)nl=1;
								if(bit[i]==ns-nj*2)nl=l;
								if(bit[i]>ns-nj*2)nl=0;
								dp[i+1][nj][nk][nl]+=dp[i][j][k][l];
								dp[i+1][nj][nk][nl]%=MOD;
								ns-=j;
							}
							if(nx==0 && ns==1){
								ns+=j+1;
								if(bit[i]<nx)nk=1;
								if(bit[i]==nx)nk=k;
								if(bit[i]>nx)nk=0;
								nj=(ns>=2)?1:0;
								if(bit[i]<ns-nj*2)nl=1;
								if(bit[i]==ns-nj*2)nl=l;
								if(bit[i]>ns-nj*2)nl=0;
								dp[i+1][nj][nk][nl]+=dp[i][j][k][l];
								dp[i+1][nj][nk][nl]%=MOD;
								ns-=j+1;
							}
						}
					}
				}
			}
		}
	}
	printf("%lld\n",dp[cnt][0][0][0]);
	return 0;
}


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

const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    int n,m;
    cin >> n >> m;
    if(m>n)swap(n,m);
    vector<mint> fact(n+1);
    fact[0] = 1;
    rrep(i,n){
        fact[i] = fact[i-1]*i;
    }
    if(n==m){
        mint t = fact[n]*fact[n]*2;
        cout << t.x <<endl;
    }
    else if(n-m==1){
        mint t = fact[n]*fact[m];
        cout << t.x << endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	cin >> a;
	int s=1000000, z=-100;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'A') {
			s = i;
			break;
		}
	}
	for (int i = a.size() - 1; i > -1; i--) {
		if (a[i] == 'Z') {
			z = i;
			break;
		}
	}
	cout << z - s + 1 << endl;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int i=0;i<(n);i++)        //repeat n times
#define REP2(i,s,n) for(int i=(s);i<(n);i++)   //repeat from s to n 
#define REPD(i,n) for(int i=(n);i>=0;i--)      //repeat from n to 0
#define REPD2(i,s,e) for(int i=(s);i>=(e);i--) //repeat from s to e
#define RANGE(i,v) for(auto &i:v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<LL,LL>;
using Pdd = P<double,double>;
using Psi = P<string,double>;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int X,Y;
    cin>>X>>Y;
    
    REP(i,X+1){
        REP(j,X-i+1){
            if(i+j != X) continue;
            if(i*4+j*2 == Y){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;

    return 0;
}

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


using namespace std;


int N, M, Q;
vector<vector<int>> q;
vector<int> seq;


using ull = unsigned long long;


void print() {
    for (auto e : seq) {
        cout << e << " ";
    }
    cout << endl;
}


ull check() {
    ull ret = 0;
    for (auto e : q) {
        if (seq[e[1] - 1] - seq[e[0] - 1] == e[2]) {
            ret += e[3];
        }
    }
    return ret;
}


ull ans = 0;
void gen_seq(int d) {
    if (d == N) {
        // print();
        // cout << check() << endl << endl;

        ans = max(ans, check());
        return;
    }
    int start = seq.size() == 0 ? 1 : seq.back();
    for (int i = start; i <=M; i++) {
        seq.push_back(i);
        gen_seq(d + 1);
        seq.pop_back();
    }
}


int main() {
    cin >> N >> M >> Q;
    q.resize(Q);
    for (int i = 0; i < Q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        q[i].push_back(a);
        q[i].push_back(b);
        q[i].push_back(c);
        q[i].push_back(d);
    }
    gen_seq(0);
    cout << ans << endl;
}


Measured memory_bytes: 3632
/*
１つの整数 x を読み込んで、x の３乗を計算し結果を出力するプログラムを作成して下さい。
 */

#include <stdio.h>

int main(void)
{
    int x, cube;

    scanf("%d", &x);
    cube = x * x * x;
    printf("%d\n", cube);
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int a[100005];
 
int32_t main()
{
    fast;
    int n, c = 0; cin >> n;
    Rep(i, 1, n) cin >> a[i];

    Rep(i, 1, n) {
        if(a[a[i]] == i) c++;
    }

    cout << c/2;

    
    
    
    return 0;
}

Measured memory_bytes: 4244
N,K,L = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        # size of n.
        self.n = n
        # n's parent. default is -1.
        self.parents = [-1] * n

    def find_root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find_root(self.parents[x])
            return self.parents[x]

    def union_merge(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # You shouldn't use these below for optimization.
    # Use only find_root to compare if you need.
    def union_size(self, x):
        # Root value's index has its size with negative.
        return -self.parents[self.find_root(x)]

    def is_same_union(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def same_union_members(self, x):
        root = self.find_root(x)
        return [i for i in range(self.n) if self.find_root(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def union_count(self):
        return len(self.roots())

    def all_unions(self):
        return [self.same_union_members(r) for r in self.roots()]

road = UnionFind(N)
rail = UnionFind(N)

for i in range(K):
    p, k = map(int, input().split())
    road.union_merge(p-1, k-1)

for i in range(L):
    r, s = map(int, input().split())
    rail.union_merge(r-1, s-1)

root_combinations = []
for i in range(N):
    root_combinations.append((road.find_root(i), rail.find_root(i)))

from collections import Counter
same_combinations = Counter(root_combinations)
result = [same_combinations[root_combination] for root_combination in root_combinations]

ans = ' '.join(map(str, result))
print(ans)


Measured memory_bytes: 57464
#include <bits/stdc++.h>
using namespace std;
int main( ){
    int x;
    cin>> x ;
    int h = x / 3600;
    int m =( x % 3600 ) /60;
    int s = x % 60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
using namespace std;
int main() {
	long long int a, b, x;
	cin >> a >> b;
	if (a > b) {
		for (long long int i = a / 2; i > 0; i--) {
			if (a % i == 0 && b % i == 0) {
				x = i;
				break;
			}
		}
	}
	else if (b > a) {
		for (long long int i = b / 2; i > 0; i--) {
			if (a % i == 0 && b % i == 0) {
				x = i;
				break;
			}
		}
	}
	else if (a == b) {
		x = a;
	}
	cout << x * (a / x) * (b / x) << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
#i番目駅からのスタート
for i in range(n):
  #時間
  t = 0
  for j in range(i,n-1):
    c,s,f = l[j]
    if t>=s:
      if t%f!=0:
        t += -(t%f)+f
      else:
        t += 0
    else:
      t += (s-t)
      if t%f!=0:
        t += -(t%f)+f
      else:
        t += 0
    t += c
  print(t)

Measured memory_bytes: 3188
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

	int n,m;
	cin >> n >> m; 
	int ct =0;
	double aux = 1.0 / (4*m);
	double sum = 0;
	vector<int> v(n);
	for(int i =0; i <n; ++i)
	{
		int x;
		cin >> x;
		v[i] = x;
		sum+=x;
	}
	aux = 1.0*sum*aux;
	for(int i =0; i< n; ++i)
	{
		if(1.0*v[i] >= aux)
		{
			ct++;
		}
	}
	if(ct >= m)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	
    return 0;
}

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

int main(){
    int n,x[200000],y[200000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(y,y+n);
    int xr=y[n/2],xl=y[n/2-1];
    for(int i=0;i<n;i++){
        if(x[i]<xr)cout<<xr<<endl;
        else cout<<xl<<endl;
    }
}


Measured memory_bytes: 3712
n,k=map(int,raw_input().split())
a=[0]*(n+1)
for i in range(k):
    d=input()
    b=map(int,raw_input().split())

    for j in range(d):
        a[b[j]]=1

    
a[0]=1
c=0
for i in range(len(a)):
    if a[i]==0:
        c+=1
print c

Measured memory_bytes: 69724
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define dame {cout<< "NO" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll dp[210][100010]; //小さい方からNこ見て最初の値がyのときの答え
//--MAIN-----------------------------------
void Main() {
    ll N,X; cin>>N>>X;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    SORT(A);
    rep(i,100010) dp[0][i]=i;
    rep(i,N){
        rep(j,100005){
            dp[i+1][j]+=dp[i][j]*i;
            dp[i+1][j]+=dp[i][j%A[i]];
            dp[i+1][j]%=MOD;
        }
    }
    cout<< dp[N][X]<<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;


#define PI 3.14159265
#define int long long


main(){


	int n; cin >> n;

	vector <int> a(n);

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

	set <int> ans;

	map <int, int> m;

	for(int i = n - 1; i >= 0; i--){
		int temp = i + 1;
		if(m[temp] % 2 != a[i] % 2){
			for(int j = 1; j * j <= temp; j++){
				if(temp % j == 0){
					if(j == temp / j){
						m[j]++;
					}else{
						m[j]++;
						m[temp / j]++;
					}
				}
			}
			ans.insert(temp);
		}
	}


	cout << ans.size() << endl;

	for(int e : ans){
		cout << e << " ";
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 19840
#include<cstdio>
#include<queue>
using namespace std;
const int mod=1000000007;
inline long long sqr(long long n){return n*n%mod;}
long long pow(long long a,int n)
{
	if(!n)return 1;
	if(n&1)return sqr(pow(a,n>>1))*a%mod;
	return sqr(pow(a,n>>1));
}
const int half=pow(2,mod-2);
struct state
{
	int a,b,c;
	state(long long x,long long y,long long z):a(x),b(y),c(z){}
	state operator+(const state &x)const{return {1ll*a*x.a%mod,(1ll*a*x.b+1ll*b*x.a)%mod,(1ll*a*x.c+1ll*b*x.b+1ll*b*x.c+1ll*c*x.a+1ll*c*x.b+1ll*c*x.c)%mod};}
	void operator+=(const state &x){*this=*this+x;}
	void adjust(){a=(a+c)%mod;c=0;}
};
int n;
vector<int> w[233333];
deque<state> q[233333];
void dp(int u)
{
	size_t maxs=0;
	for(int i:w[u])
	{
		dp(i);
		if(q[i].size()>q[u].size())swap(q[i],q[u]);
		maxs=max(maxs,q[i].size());
		for(int j=0;j<q[i].size();j++)q[u][j]+=q[i][j];
		q[i].clear();
	}
	q[u].push_front({half,half,0});
	for(int i=0;i<=maxs;i++)q[u][i].adjust();
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int p;
		scanf("%d",&p);
		w[p].push_back(i);
	}
	dp(0);
	long long ans=0;
	for(auto i:q[0])ans+=i.b;
	printf("%lld\n",ans%mod*pow(2,n+1)%mod);
	return 0;
}


Measured memory_bytes: 211200
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length.toLong()
    val k = readLine()!!.toLong()

    if (s.toSet().size == 1) {
        println(n * k / 2)
        return
    }

    val count = mutableListOf<Pair<Char,Long>>()
    var si = 0
    var first = 0L
    while (si < n) {
        var to = si + 1
        while (to < n && s[to] == s[si]) to++
        val diff = to - si
        count.add(Pair(s[si], diff.toLong()))
        si = to

        first += diff / 2
    }

    if (count.first().first == count.last().first) {
        val firstCount = count.first().second
        val lastCount = count.last().second
        val second = first - firstCount / 2 - lastCount / 2 + (firstCount + lastCount) / 2
        println(first + second * (k - 1))
    } else {
        println(first * k)
    }
}

Measured memory_bytes: 33844
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009
typedef long long int ll;
using namespace std;


int main(int argc, char const *argv[]) {
  ll x, y, H, W, flag;
  std::cin >> H >> W;
  std::vector<string> a(H);
  range(i, H) std::cin >> a[i];
  a[0][0] = '.';
  for(int i=0;i<1<<(H+W-2);i++){
    x = y = 0, flag = 1;
    for(int j=0;j<(H+W-2);j++){
      ll tes = ((i + (1<<(H+W-2))) >> (H+W-3-j));
      if(tes%2==0){
        x++;
        if(y>=W||x>=H) {
          flag = 0;
          continue;
        }
        if(a[x][y] != '#') flag = 0;
      }else{
        y++;
        if(y>=W||x>=H) {
          flag = 0;
          continue;
        }
        if(a[x][y] != '#') flag = 0;
      }
    }
    if(flag==1){
      x = y = 0;
      for(int j=0;j<(H+W-2);j++){
        ll tes2 = ((i + (1<<(H+W-2))) >> (H+W-3-j));
        if(tes2%2==0){
          x++;
          a[x][y] = '.';
        }else{
          y++;
          a[x][y] = '.';
        }
      }
    }
  }
  flag = 1;
  range(i, H) range(j, W) if(a[i][j]=='#') flag = 0;
  std::cout << (flag==1?"Possible":"Impossible") << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;
typedef unsigned long long ULL;
typedef struct{
    int number;
    int num;
}P_NUM;
void process( P_NUM p_num[50], int num_of_p, int divide, int pos,int *ans);
int main(){
    ULL N;
    P_NUM p_num[50];
    int num_of_p;
    int i,j;
    int temp;
    int ans;
    
    cin >> N;
    p_num[0].number = 2;
    p_num[0].num = 0;
    num_of_p = 0;
    for(i=2;i<=N;i++){
        temp = i;
        for(j=0;j<num_of_p;){
            if( temp % p_num[j].number == 0){
                temp /= p_num[j].number;
                p_num[j].num++;
            }else{
                j++;
            }
        }
        if( i == temp){
            p_num[num_of_p].number = temp;
            p_num[num_of_p++].num = 1;
        }
    }
    /*
    cout << num_of_p << endl;
    for(i=0;i<num_of_p;i++){
        cout << p_num[i].number << ":" << p_num[i].num << endl;
    }
     */
    process(p_num,num_of_p,1,0,&ans);
    cout << ans << endl;
    
    return 0;
}
void process( P_NUM p_num[50], int num_of_p, int divide, int pos,int *ans){
    int i;
    if( pos == num_of_p){
        if( divide == 75 ){
            *ans += 1;
        }
        return;
    }
    if( divide > 75 ){
        return;
    }
    for(i=0;i<=p_num[pos].num;i++){
        process(p_num,num_of_p,divide*(i+1),pos+1,ans);
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100100
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++) 
#define Fore(i,a,b) for(int i=a;i>=b;i--) 
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e9+9
#define Vector Point
#define fir first
#define sec second
#define fxx(a) cout<<fixed<<setprecision(a)
#define flu cout.flush()
typedef pair<int,int> pii;
const int Mod=1000000007;
typedef unsigned long long ull;
typedef long long ll;
const int base=227;
const int base1=123;
const int maxn=2005;
int dcmp(double x) {
	if(fabs(x)<=eps) return 0;
	return x<0?-1:1;
}
void solve() {
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b))<<endl;
}
int main(){
	iossy;
	int t=1;
	For(i,1,t) solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long;
using lli = long long int;

void ABC079D()
{
	int H, W;
	cin >> H >> W;
	vector<vector<int> > cij(10, vector<int>(10));
	for (auto& x : cij)
	{
		for (auto& y : x)
			cin >> y;
	}

	vector<vector<int> > dist(cij);
	for (int k = 0; k < 10; ++k)
	{
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
			{
			
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	vector<int> d(10);
	for (int i = 0; i < 10; ++i)
		d[i] = dist[i][1];

	vector<vector<int> > Aij(H, vector<int>(W));
	for (auto& x : Aij)
	{
		for (auto& y : x)
			cin >> y;
	}

	int sum = 0;
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			if (Aij[i][j] >= 0)
			{
				sum += d[Aij[i][j]];
			}
		}
	}
	cout << sum << endl;

}
int main()
{
	ABC079D();
	return 0;
}

Measured memory_bytes: 384
/*
      @author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

int N, M;
const int X = 1e5 + 5;
vector<int> adj_list[X];
int dp[X];

int Backtrack(int node) {

    if(dp[node] != -1) return dp[node];

    int max_path = 0;
    for(int i : adj_list[node]) {
        max_path = max(max_path, 1 + Backtrack(i));
    }
    return (dp[node] = max_path);
}

int solution() {
    int longest_path = 0;
    for(int i = 1; i <= N; ++i) {
        longest_path = max(longest_path, Backtrack(i));
    }
    return longest_path;
}

int32_t main() {
      IOS;
      memset(dp, -1, sizeof(dp));
      cin >> N >> M;
      for(int i = 0; i < M; ++i) {
        int x, y; cin >> x >> y;
        adj_list[x].push_back(y);
      }
      cout << solution() << endl;
}

Measured memory_bytes: 8576
import java.util.Scanner;


public class Main{
	public static void main(String []args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??£?¨?
		int count = 0;
		//?????? W???????????????
		String W = sc.next();
		
		//??°?????????
		while(true){
			
			//?????? T??????????????????
			String T = sc.next();
			//END_OF_TEXT????????????????????????
			if(T.equals("END_OF_TEXT")){
				break;
			}
			//?????? W??¨?????????????????????
			if(W.equalsIgnoreCase(T)){
			//??????W??¨??????T???????????°????????????
				count ++;
			}
		}
		//??????????????????????????¨???
		System.out.println(count);
	}
}

Measured memory_bytes: 26116
#include <stdio.h>
int main(){
  int N, count, safe=0, A;
  scanf("%d%d", &N, &A);
  while (A%2==0){
      safe++;
      A/=2;
    }
  count=safe;
  for (int i=1; i<N ;i++){
    scanf("%d", &A);
    safe=0;
    while (A%2==0){
      safe++;
      A/=2;
    }
    if (safe<count){
      count=safe;
    }
  }
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int A = scan.nextInt();
		int B = scan.nextInt();
		
		int atai = -1;
		
		int[] c = new int[1001];
		int[] d = new int[1001];
		
		for(int i=1; i<=1000; i++){
			c[i] = (int)(i*0.08);
			
			if(c[i]==A){
				for(int j=1; j<=1000; j++){
					d[j] = (int)(j*0.10);
					
					if(d[j] == B){
						if(i==j){
							atai = i; 
							System.out.println(atai);
							System.exit(0);
							
						}
					}
				}
			}
		}
	
		System.out.println(atai);
	}
}

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

int main(){
	int h,w;
  	cin>>h>>w;
  	vector<char> s(w);
  for (int j=0;j<h;j++){
    
  	for (int i=0;i<w;i++){
    	cin>>s.at(i);
    }
    
  	for (int i=0;i<w;i++){
    	cout<<s.at(i);
    }
  		cout<<endl;
    
  	for (int i=0;i<w;i++){
    	cout<<s.at(i);
    }
  		cout<<endl;
  }
}    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

const uint64_t MOD = 1000 * 1000 * 1000 + 7;

template <uint8_t max_value, uint8_t mod_value>
struct index_mod {
  uint8_t mod[max_value];
  constexpr index_mod() : mod() {
    for (size_t i = 0; i < max_value; ++i) {
      mod[i] = i % mod_value;
    }
  }
};

template <uint8_t mod_value>
struct sub_index {
  uint8_t index[mod_value][mod_value - 10];
  constexpr sub_index() : index() {
    auto value = 0;
    uint8_t in[mod_value] = {0};
    for (size_t i = 0; i < mod_value; ++i) {
      value += 10;
      for (size_t j = 0; j < mod_value - 10; ++j) {
        // index[i][j] = (value + j) % mod_value;
        auto v = (value + j) % mod_value;
        index[v][in[v]] = i;
        ++in[v];
      }
    }
  }
};

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

  // i番目の文字を見た時に13との剰余がnになる個数を数え上げる
  std::vector<uint64_t> dp(2 * 13);

  constexpr index_mod<13 * 10, 13> imod;
  constexpr sub_index<13> sindex;

  // for (size_t i = 0; i < 13; ++i) {
  // for (size_t j = 0; j < 3; ++j) {
  //   std::cout << (int)sindex.index[i][j] << ",";
  // }
  // std::cout << std::endl;
  // }

  uint64_t row_sum = 0;

  {  // テーブル初期化
    int val = -1;
    if (s[0] != '?') val = s[0] - '0';
    if (val == -1) {
      for (size_t i = 0; i < 10; ++i) {
        dp[i % 13] = 1;
      }
      row_sum = 10;
    } else {
      dp[val % 13] = 1;
      row_sum = 1;
    }
    // % 13は不要だけど定義に帰るため
  }

  for (size_t i = 1, e = s.length(); i < e; ++i) {
    int val = -1;
    if (s[i] != '?') val = s[i] - '0';
    if (val == -1) {
      for (size_t pre = 0; pre < 13; ++pre) {
        auto temp_sum = row_sum + 3 * MOD;
        for (size_t j = 0; j < 3; ++j) {
          temp_sum -= dp[sindex.index[pre][j]];
        }
        dp[13 + pre] = temp_sum;
      }
    } else {
      for (size_t pre = 0; pre < 13; ++pre) {
        auto &here_dp = dp[13 + imod.mod[pre * 10 + val]];
        const auto &pre_dp = dp[pre];
        here_dp = pre_dp;
      }
    }

    row_sum = 0;
    for (size_t i = 0; i < 13; ++i) {
      dp[i] = dp[13 + i] % MOD;
      row_sum += dp[i];
      // dp[i] = dp[13 + i];
      dp[13 + i] = 0;
    }
    row_sum %= MOD;
  }

  std::cout << dp[5] % MOD << std::endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n],dp[n]; for(int i=0;i<n;i++) cin>>arr[i],dp[i]=arr[i];
    dp[1]=abs(dp[1]-dp[0]);
    dp[0]=0;
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
// Problem : D - Prediction and Restriction
// Contest : AtCoder - AtCoder Beginner Contest 149
// URL : https://atcoder.jp/contests/abc149/tasks/abc149_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,k;
    cin>>n>>k;
    int r,sc,p;
    cin>>r>>sc>>p;
    string s;
    cin>>s;
    map<char,int> m;
    m['r'] = p;
    m['s'] = r;
    m['p'] = sc;
    vi win(n);
    int ans = 0;
    for(int i=0;i<k;i++){
        for(int j=i;j<n;j+=k){
            if(j-k < 0 || !win[j-k] || s[j] != s[j-k]) {
                ans += m[s[j]];
                win[j] = 1;
            } else win[j] = 0;
        }
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4240
import sys
from collections import deque, defaultdict
import copy
import bisect
#input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

n = int(input())
v = list(map(int, input().split()))

dict0 = defaultdict(int)
dict1 = defaultdict(int)

for i in range(n//2):
	dict0[v[2*i]] += 1
	dict1[v[2*i + 1]] += 1

list0 = [(0, 0)]
list1 = [(0, 0)]
for num in dict0:
	bisect.insort(list0, (dict0[num], num))
for num in dict1:
	bisect.insort(list1, (dict1[num], num))

if list1[-1][1] != list0[-1][1]:
	print(n - list1[-1][0] - list0[-1][0])
else:
	print(min(n - list1[-1][0] - list0[-2][0], n - list1[-2][0] - list0[-1][0]))

Measured memory_bytes: 67016
#include<cstdio>
#include<algorithm>
using namespace std;

int rec[100100];

int main()
{
    int n,k,i;
    int ans=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",rec+i);
    sort(rec,rec+n);
    for(i=0;i<k;i++)
        ans+=rec[i];
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1732
N, M = map(int, input().split())
drinks = [None] * N
for i in range(N):
    drinks[i] = tuple(map(int, input().split()))
drinks.sort()
cans = M
cost = 0
for a_cost, num in drinks:
    if cans <= 0:
        break
    dr = min(cans, num)
    cost += dr * a_cost
    cans -= dr

print(cost)


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;

ll solve(ul num) {
    ul pop = __builtin_popcount(num);
    if (pop == 0) {
        return 0;
    }
    return solve(num % pop) + 1;
}

int main() {
    ll n;
    string x;
    cin >> n >> x;

    ll pop = 0;
    rep(i, n) {
        if (x[i] == '1') {
            pop++;
        }
    }

    ll mod_memo[2];
    ll base_memo[2][n];
    rep(i, 2) {
        ll pop_temp = pop;
        if (i == 0)
            pop_temp++;
        else
            pop_temp--;

        if (pop_temp == 0) {
            mod_memo[i] = 0;
            continue;
        }

        ul base = 1;
        ll mod = 0;
        rep(j, n) {
            ll index = n - j - 1;
            base_memo[i][index] = base;
            if (x[index] == '1') {
                mod += base;
                mod %= pop_temp;
            }
            base *= 2;
            base %= pop_temp;
        }
        mod_memo[i] = mod;
    }

    rep(i, n) {
        ll mod_temp;
        ll pop_temp = pop;

        if (x[i] == '0') {
            pop_temp++;
            mod_temp = mod_memo[0] + base_memo[0][i];
            mod_temp %= pop_temp;
        } else {
            pop_temp--;
            if (pop_temp == 0) {
                cout << 0 << endl;
                continue;
            }
            mod_temp = mod_memo[1] - base_memo[1][i] + pop_temp;
            mod_temp %= pop_temp;
        }
        cout << solve(mod_temp) + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 6844
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int> score(n,k-q);
  for(int i=0;i<q;i++){
    int r;
    cin>>r;
    ++score[r-1];
  }
  for(int i=0;i<n;i++){
    if(score[i]>0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

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

typedef long long ll;

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        int h[n+1], w[m+1];
        h[0] = w[0] = 0;
        for(int i = 1; i <= n; i++) cin >> h[i], h[i] += h[i-1];
        for(int j = 1; j <= m; j++) cin >> w[j], w[j] += w[j-1];

        map<int,int> height, width;
        
        for(int i = 1; i <= n; i++){
            for(int j = i; j <= n; j++){
                height[h[j]-h[i-1]]++;
            }
        }

        for(int i = 1; i <= m; i++){
            for(int j = i; j <= m; j++){
                width[w[j]-w[i-1]]++;
            }
        }

        ll ans = 0;
        for(pair<int,int> p : height){
            if(width.count(p.first))    ans += (ll)(p.second) * width[p.first];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 29864
#include<stdio.h>
int A[1000000],n;

int binarySearch(int key){
  int left = 0;
  int right = n;
  int mid;
  while(left<right){
    mid = (left + right) / 2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main(){
  int i,q,k,sum = 0;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&k);
    if(binarySearch(k)) sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2144
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int):
    k = 1
    while(N >= k*2):
        k *= 2
    print(k)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

int main(){
    int A,B,T; cin >> A >> B >> T;
    // string B; cin >> B;
    // int n; cin >> n;
    // int C[n]; rep(i,n) cin >> C[i];
    
    cout << (T/A)*B << endl;
}


Measured memory_bytes: 256