akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 100000000;

int dp[102][102][500];

int main()
{
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        int p[102];
        int charge[102] {0};
        for(int i = 1; i <= n; i++){
            cin >> p[i];
            charge[i] = charge[i - 1] + (6000 - p[i]) % 1000;
        }
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++){
                for(int k = 0; k < 500; k++){
                    dp[i][j][k] = INF;
                }
            }
        }
        for(int i = 0; i <= n; i++){
            for(int k = 0; k < 500; k++){
                dp[i][0][k] = 0;
            }
        }
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= n; j++){
                for(int k = 0; k < 500; k++){
                    dp[i][j][k] = min(dp[i - 1][j][k] + p[i], INF);
                    if((6000 - p[i]) % 1000 <= k){
                        dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - (6000 - p[i]) % 1000]);
                    }
                    if(j > 0 && charge[i - 1] - k - (j - 1) * 500 + (6000 - p[i]) % 1000 >= 500){
                        dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j - 1][k] + p[i]);
                    }
                }
            }
        }
        int j = 0;
        for(; j <= n; j++){
            if(dp[n][j][0] == INF) break;
        }
        int ans = INF;
        for(int k = 0; k < 500; k++) ans = min(ans, dp[n][j - 1][k]);
        cout << j - 1 << " " << ans << endl;
    }
}


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

/* debug macros */
#ifdef WAFDAYO
#define DBG_PRINT(s, t, u) { std::cerr << s << " \e[2m=\e[m \e[1m" << t << "\e[m" << u; }
#else
#define DBG_PRINT(s, t, u) {}
#endif
#define dbg(x) DBG_PRINT(#x, x, std::endl)
#define dbgc(x) DBG_PRINT(#x, x, ", ")
#define idbg(x, i) DBG_PRINT(#x "[" << i << "]", x[i], std::endl)
#define idbgc(x, i) DBG_PRINT(#x "[" << i << "]", x[i], ", ")

/* IO utilities */
struct read_item { read_item() {}; template<class T> operator T() { T t; std::cin >> t; return t; } };

/* types and constants */
typedef long long i64;
const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

int main() {

	const int h = read_item();
	const int w = read_item();
	const int n = read_item();
	const int d = max(h, w);

	const int ans = (n + d - 1) / d;
	printf("%d\n", ans);

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 long double a,b,h,m;
  cin>>a>>b>>h>>m;
  long double c,d,x;
  x=60*h+m;
  c=x/(12*60);
  d=x/60;
  long double ans;
  ans=a*a+b*b-2*a*b*cosl((c-d)*2*M_PI);
  cout<<std::fixed<<std::setprecision(12)<<sqrt(ans)<<endl;
  }

Measured memory_bytes: 4172
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"

using namespace std;
typedef long long ll;

int main()
{
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n + 1 - h) * (n + 1 - w) << "\n";
}

Measured memory_bytes: 256
//cnt0 += s[i] == '0';
#include <bits/stdc++.h>
# define ll long long 
# define all(vc) vc.begin(),vc.end()
# define str string 
# define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
stack <char> stk;
vector <int> vc;
vector <char> A;
set <ll> B;
ll a,b,c,d,e,f,g,h,cnt,bnt,p,sum;
str s,cal;
map <char,ll> mp;
ll arr[1000][6];
char ch;
bool ok=true;
int main(){
	speed;
	cin>>a>>b;
	if(a%2==0){
		if(a/2>=b) cout<<"YES\n";
		else cout<<"NO\n";
	}
	else {
		if((a/2)+1>=b) cout<<"YES\n";
		else cout<<"NO\n";
	}
	time;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
motoS = input()
S = list(motoS)
start = 0
end = 0
for i in range(N):
    if S[i] == '(':
        end += 1
    else:
        end -= 1
    if end < 0:
        start += 1
        end = 0
print('('*start+motoS+')'*end)

Measured memory_bytes: 9180
#include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define NIL -1

int n;
struct node
{
    int parent, left, right;
};

node nd[25];

int getRoot()
{
    int k = 0;
    while (nd[k].parent > NIL)
    {
        k = nd[k].parent;
    }
    return k;
}

void Preorder(int r)
{
    printf(" %d", r);
    if (nd[r].left > NIL)
        Preorder(nd[r].left);
    if (nd[r].right > NIL)
        Preorder(nd[r].right);
}

void Inorder(int r)
{
    if (nd[r].left > NIL)
        Inorder(nd[r].left);
    printf(" %d", r);
    if (nd[r].right > NIL)
        Inorder(nd[r].right);
}

void Postorder(int r)
{
    if (nd[r].left > NIL)
        Postorder(nd[r].left);
    if (nd[r].right > NIL)
        Postorder(nd[r].right);
    printf(" %d", r);
}

int main()
{
    int x, l, r;
    cin >> n;
    for (int i = 0; i < n; i++)
        nd[i].parent = NIL;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> l >> r;
        nd[x].left = l;
        nd[x].right = r;
        if (l > NIL)
            nd[l].parent = x;
        if (r > NIL)
            nd[r].parent = x;
    }

    int root = getRoot();

    printf("Preorder\n");
    Preorder(root);
    printf("\n");
    printf("Inorder\n");
    Inorder(root);
    printf("\n");
    printf("Postorder\n");
    Postorder(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 3212
#include<stdio.h>
int main(void){
  int h,w,t,y=0;
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0&&w==0)break;
    for(t=0;t<h;t++){
      for(y=0;y<w;y++){
	if(t==0||t==h-1||y==0||y==w-1){
	  printf("#");
	}else{
	  printf(".");
	}
      }
      puts("");
    }
    puts("");
    }   
  return 0;
}



Measured memory_bytes: 2024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    char a;
    bool contain = false;
    rep(i, 3){
        cin >> a;
        if(a == '7'){
            contain = true;
        }
    }

    if(contain) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
 
int main(){
    int A,B;
    cin >> A >> B;
    if(A >= 10 || B >= 10) pr("-1");
    else pr(A*B);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}
 
// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    ll n , x , y ; cin >> n;
    vpll A;
    for(int i = 0 ;i < n ; i++){
        cin >> x >> y;
        A.pb(mp(x , y));
    }
    sort(all(A));
    
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    ll cost = 100;
    for(int i = 0 ;i < n; i++){
        
        for(int j = i+1 ; j < n ; j++){
            ll no = 0;
            int x = A[j].F-A[i].F , y = A[j].S - A[i].S; 
            for(int k = 0 ; k < n; k++){
                for(int l = k+1 ; l < n ; l++ ){
                    if( (A[l].F == A[k].F + x) && (A[l].S == A[k].S + y ))
                        no++;
                }
            }
            
            cost = min(cost , n-no);
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import functools
import math
import sys

INF = float('inf')


def solve(K: int):

    @functools.lru_cache(maxsize=K**3)
    def gcd(a: int, b: int) -> int:
        return math.gcd(a, b)

    return sum([gcd(ab, c+1) for ab in [gcd(a+1, b+1) for a in range(K) for b in range(K)] for c in range(K)])


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    print(f'{solve(K)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 245484
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;









ll e[300][300];
ll r[300];
ll d[300][300];

void floyd(int N) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}



ll p[100005];


int main() {
	ll N;
	cin >> N;
	string S1, S2;

	cin >> S1 >> S2;



	ll ans = 1;
	ll init = 0;
	int pretype = 0;
	if (S1[0] == S2[0]) {
		ans = 3;
		init = 1;
		pretype = 1;
	}

	else {
		ans = 6;
		init = 2;
		pretype = 2;
	}

	int i = init;
	while(i < N) {
		if (S1[i] == S2[i] && pretype == 1) {

			ans = (ans * 2) % mod;
			pretype = 1;
			i++;
		}

		else if (S1[i] == S2[i] && pretype == 2) {
			
			pretype = 1;
			i++;
		}

		else if (S1[i] != S2[i] && pretype == 2) {

			ans = (ans * 3) % mod;
			i += 2;
			pretype = 2;
		}
		else {
			ans = (ans * 2) % mod;
			i += 2;
			pretype = 2;

		}


	}


	cout << ans % mod << endl;


	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

using namespace std;

unsigned GetDigit(unsigned num) {
    unsigned digit = 0;
    while (num != 0) {
        num /= 10;
        digit++;
    }
    return digit;
}

int main()
{
    int a, b;
    cin >> a >> b;
    for (size_t i = 1; i <= 10000; i++)
    {
        int p = pow(10, GetDigit(b));
        int tmp = a * p + b;
        if (tmp == i * i)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 384
// g++ -std=gnu++1y -O2 -I/opt/boost/gcc/include -L/opt/boost/gcc/lib -o ./a.out ./X.cpp & a.out //
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long


using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);	
    cin.tie(NULL); cout.tie(NULL);
    
    int n, k; cin >> n >> k;
    
    set<int> snacks[102];
    
    for(int i = 1; i < k+1; i++)
    {
		int d; cin >> d;
		for(int j = 0; j < d; j++)
		{
			int x; cin >> x;
			snacks[x].insert(i);
		}
	}
    int ans = 0;
	for(int i = 1; i<n+1; i++)
    {
		if(snacks[i].empty()) ans++;
	}
	
	cout << ans << '\n';
    
    return 0;
}



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

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



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const int inf=1<<30;
bool used[100010];
vector<int> g[100010];
vector<int> tree[100010];
int main(){
	int n,m;
	cin>>n>>m;
	while(m--){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	used[1]=true;
	int l=1,r=1;
	while(true){
		//cout<<l<<" "<<r<<endl;
		bool up=true;
		for(int i=0;i<g[l].size();i++){
			if(!used[g[l][i]]){
				tree[l].push_back(g[l][i]);
				tree[g[l][i]].push_back(l);
				l=g[l][i];
				used[l]=true;
				up=false;
			}
		}
		for(int i=0;i<g[r].size();i++){
			if(!used[g[r][i]]){
				tree[r].push_back(g[r][i]);
				tree[g[r][i]].push_back(r);
				r=g[r][i];
				used[r]=true;
				up=false;
			}
		}
		if(up)break;
	}
	//cout<<"ok"<<endl;
	vector<int> ans;
	ans.push_back(l);
	while(l!=r){
		used[l]=false;
		for(int i=0;i<tree[l].size();i++){
			if(used[tree[l][i]]){
				ans.push_back(tree[l][i]);
				l=tree[l][i];
				break;
			}
		}
	}
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<" ";
	}
	return 0;
} 

Measured memory_bytes: 11772
#include<iostream>
using namespace std;
 
int main(){
  int a, b, c, d ,e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(b - a > k){
    cout << ":(";
  }
  else if(c - a > k){
    cout << ":(";
  }
  else if(d - a > k){
    cout << ":(";
  }
  else if(e - a > k){
    cout << ":(";
  }
  
  else if(c - b > k){
    cout << ":(";
  }
  else if(e - b > k){
    cout << ":(";
  }
  else if(d - b > k){
cout << ":(";
  }
  else if(d - c > k){
    cout << ":(";
  }
  else if(e - c > k){
    cout << ":(";
  }
  else if(e - d > k){
    cout << ":(";
  }
  else{
    cout << "Yay!";
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
void YES(bool anser){
    if(anser)printf("YES\n");
    else printf("NO\n");
}
void Yes(bool anser){
    if(anser)printf("Yes\n");
    else printf("No\n");
}
void yes(bool anser){
    if(anser)printf("yes\n");
    else printf("no\n");
}
int n,p=1000000000;
int m[105][105],x[1005],y[1005],h[1005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>h[i];
    for(int i=0;i<n;i++)p=min(p,h[i]);
    if(p!=0){
        for(int i=0;i<n;i++)h[i]=h[i]-p+1;
    }
    if(p==0)p++;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(int k=1;k<=200;k++){
                bool o=true;
                for(int l=0;l<n;l++){
                    if(max(k-abs(y[l]-i)-abs(x[l]-j),0)!=h[l])o=false;
                }
                if(o){
                    cout<<j<<' '<<i<<' '<<k+p-1<<endl;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int a, b, c; cin >> a >> b >> c&&a;) {
		int N; cin >> N;
		vector<int> f(a + b + c, 2);
		vector<int> p(N), q(N), r(N), s(N);
		rep(i, 0, N) {
			cin >> p[i] >> q[i] >> r[i] >> s[i]; p[i]--, q[i]--, r[i]--;
			if (s[i])f[p[i]] = f[q[i]] = f[r[i]] = 1;
		}
		rep(i, 0, N) {
			int cnt = 0;
			if (f[p[i]] == 1)cnt++;
			if (f[q[i]] == 1)cnt++;
			if (f[r[i]] == 1)cnt++;
			if (cnt == 3)continue;
			if (cnt == 2) {
				if (f[p[i]] != 1)f[p[i]] = 0;
				if (f[q[i]] != 1)f[q[i]] = 0;
				if (f[r[i]] != 1)f[r[i]] = 0;
			}
		}
		rep(i, 0, a + b + c) {
			cout << f[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3140
import sys
readline = sys.stdin.readline
class Node:
    __slots__ = ['value', 'left', 'right']
    def __init__(self, value=None):
        self.value = value
        self.left = None
        self.right = None
class BinTree:
    __slots__ = ['_tree', 'result']
    def __init__(self):
        self._tree = None
    def insert(self, value):
        p = None
        c = self._tree
        while c is not None:
            p = c
            if value < c.value:
                c = c.left
            else:
                c = c.right
        if p is None:
            self._tree = Node(value)
        elif value < p.value:
            p.left = Node(value)
        else:
            p.right = Node(value)
    def find(self, value):
        c = self._tree
        while c is not None:
            if value == c.value:
                return True
            elif value < c.value:
                c = c.left
            else:
                c = c.right
        return False
    def delete(self, value):
        p = None
        c = self._tree
        while c.value != value:
            p = c
            if c is None:
                return
            if value < c.value:
                c = c.left
            else:
                c = c.right
        if c.left is None:
            if p.left == c:
                p.left = c.right
            else:
                p.right = c.right
        elif c.right is None:
            if p.left == c:
                p.left = c.left
            else:
                p.right = c.left
        elif c.right.left is None:
            c.right.left = c.left
            if p.left == c:
                p.left = c.right
            else:
                p.right = c.right
        else:
            q = c.right
            while q.left.left is not None:
                q = q.left
            c.value = q.left.value
            q.left = q.left.right
        return
    def preoder_walk(self):
        self.result = []
        def preoder(node):
            if node is not None:
                self.result.append(node.value)
                preoder(node.left)
                preoder(node.right)
        preoder(self._tree)
        print(" " + " ".join(map(str, self.result)))
    def inorder_walk(self):
        self.result = []
        def inorder(node):
            if node is not None:
                inorder(node.left)
                self.result.append(node.value)
                inorder(node.right)
        inorder(self._tree)
        print(" " + " ".join(map(str, self.result)))
n = int(input())
tree = BinTree()
for _ in range(n):
    com = readline().split()
    if com[0] == "insert":
        tree.insert(int(com[1]))
    elif com[0] == "find":
        print("yes" if tree.find(int(com[1])) else "no")
    elif com[0] == "delete":
        tree.delete(int(com[1]))
    else:
        tree.inorder_walk()
        tree.preoder_walk()



Measured memory_bytes: 77188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
//コピーここから
struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n,-1) {}
  void init(int n) { par.assign(n,-1); }
  //木の根であれば連結する頂点数×(-1),そうでなければ親ノードのID
  int root(int x){
    if(par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x==y) return;//既に連結
    
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return;
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int size(int x){
    return -par[root(x)];
  }
};
//コピーここまで
int main(void){
  ll n,m,i,j,k,result=0;
  ll a,b;
  
  cin >> n >> m;
  UnionFind uf(n);
  result = n-1;
  rep(i,m){
    cin >> a >> b;
    a--;
    b--;
    if(!uf.same(a,b)) result--;
    uf.unite(a,b);
  }
  cout << result << endl;
  return 0;
}

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

int main(void)
{
    int n; cin >> n;
    int a;
    bool flag = true;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a % 2 == 0)
        {
            if (a % 3 != 0 && a % 5 != 0)
                flag = false;
        }
    }
    if (flag)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> pipii;

int N,M;
vector<pipii> V;
int now;
int bit[300010] = {0};
int ans[100010] = {0};
int yet = 0;

int sum(int i)
{
    int res = 0;
    while(i > 0)
    {
        res += bit[i];
        i -= i & -i;
    }
    return res;
}

void add(int i,int x)
{
    while(i <= M)
    {//printf("  %d",i);
        bit[i] += x;
        i += i & -i;
    }//printf("\n");
    return;
}

int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < N; i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        V.push_back(make_pair(r - l + 1,make_pair(l,r)));
    }
    sort(V.begin(),V.end());
    now = 0;
    for(int i = 1; i <= M; i++)
    {
        int res;
        while(yet != V.size() && V[now].first < i)
        {
            add(V[now].second.first,1);
            add(V[now].second.second + 1,-1);
            now++;
            yet++;
        }
        res = V.size() - yet;
        for(int j = i; j <= M; j += i)
        {
            res += sum(j);
        }
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 8560
#include <cstdio>
#include <cstring>

const int p=1000000007;

int c[300][300],g[100],h[100];
char b[100];
int i,j,k,l,m,n,r,s,t;

inline void pre()
{
	scanf("%d%d",&n,&m);
	scanf("%s",b+1);
	for (i=0;i<=250;i++)
		for (j=0;j<=i;j++)
			if ((j==0) || (j==i))
				c[i][j]=1;
			else
				c[i][j]=(c[i-1][j]+c[i-1][j-1])%p;
	return;
}

inline void calc()
{
	for (i=1;i<=n;i++)
		h[i]=g[i];
	t=0;
	for (i=1,k=1,l=1;i<=m;i++)
		if ((b[i]=='r') && (h[k]>0))
			h[k]--,k++;
		else
		if ((b[i]=='b') && (h[l]>0) && (l<k))
			h[l]--,t=t+h[l],l++;
		else
		if (t>0)
			t--;
	if ((h[k]) || (h[l]) || (t))
		return;
	r=1;
	for (i=1;g[i];i=j)
	{
		for (j=i;g[i]==g[j];j++);
		r=1LL*r*c[j-1][i-1]%p;
		if (g[i]==1)
			t=t+j-i;
		else
			t=t+(j-i)*(2*g[i]-3);
	}
	t=t+k-2;
	if (n-t<0)
		return;
	s=(s+1LL*r*c[n+2*l-1][t+2*l-1])%p;
	return;
}

inline void dfs(int w,int x,int y,int z)
{
	if (w<0)
		return;
	if (z)
		calc();
	if (x)
	{
		g[z+1]=1,dfs(w-1,x-1,1,z+1);
		for (int i=2;(i<=x) && (i<=y);i++)
			g[z+1]=i,dfs(w-2*i+3,x-i,i,z+1);
		g[z+1]=0;
	}
	return;
}

int main()
{
	pre();
	dfs(n,m,m,0);
	printf("%d",(s+1)%p);
	return 0;
}

Measured memory_bytes: 512
n = int(input())
card = [[0]*13 for _ in range(4)]
suits = ['S','H','C','D']

for _ in range(n):
    suit,num = input().split()
    suit = suits.index(suit)
    num = int(num)
    card[suit][num-1] = 1

for i in range(4):
    for j in range(13):
        if not card[i][j]:
            print(suits[i],j+1)


Measured memory_bytes: 5600
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

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

    std::vector<long long> x(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i];
    }

    long long ans = std::numeric_limits<long long>::max();

    for (int i = 0; i < n - k + 1; i++) {
        ans = std::min(ans, std::abs(x[i]) + std::abs(x[i] - x[i + k - 1]));
    }

    for (int i = n - 1; i >= k - 1; i--) {
        ans = std::min(ans, std::abs(x[i]) + std::abs(x[i] - x[i - k + 1]));
    }

    std::cout << ans << std::endl;
}


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

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int> pii32;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

int64 n, a, b;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> a >> b;
	if (a > b)
		return cout << 0 << "\n", 0;
	if (n == 1) {
		if (a == b)
			return cout << 1 << "\n", 0;
		return cout << 0 << "\n", 0;
	}
	cout << (n - 2) * (b - a) + 1 << "\n";
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int d = scanner.nextInt();
			if (d == 0)
				break;
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			NavigableSet<Integer> set = new TreeSet<Integer>();
			set.add(0);
			for (int i = 0; i < n - 1; i++)
				set.add(scanner.nextInt());
			set.add(d);
			Integer[] p = set.toArray(new Integer[0]);
			int ans = 0;
			for (int i = 0; i < m; i++) {
				int k = scanner.nextInt();
				int pos = Arrays.binarySearch(p, k);
				if (pos < 0) {
					pos = -pos  -2;
					int c = Math.min(k - p[pos], p[pos + 1] - k);
					ans += c;
				}
			}
			System.out.println(ans);
		}
	}
}

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

int main(){
  int x,y;
  cin >> x >> y;
  
  if((4*x)<y){
    cout << "No" << endl;
  }
  else if(y%2!=0){
    cout << "No" << endl;
  }
  else if((2*x)>y){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3636
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \|     |//  `.
            /  \|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            pass the Test!
*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;
ll N;

int main(){
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    //Acount[i]はA以下で(?&(1<<i))となる?の個数の偶奇
    vector<ll> Acount(50,0LL);
    vector<ll> Bcount(50,0LL);
    if(A>0)
    for(ll i=0;i<50;i++){ll a;
        if(i==0){
            a=A%4;
            if(a==0||a==1)Acount[0]=0LL;
            else Acount[0]=1LL;
            continue;
        }
        else {a=(ll)A%(1LL<<(i+1));
        Acount[i]=(ll)max(0LL,a-(1LL<<i))%2;}
    ;}
    for(ll i=0;i<50;i++){ll a;
        if(i==0){
            a=(B+1)%4;
            if(a==0||a==1)Bcount[0]=0;
            else Bcount[0]=1;
            continue;
        }
        else a=(ll)(B+1)%(1LL<<(i+1));
        Bcount[i]=(ll)max(0LL,a-(1LL<<i))%2;
    ;}
    ll ans=0;
    for(ll i=0;i<50;i++){
        if(Acount[i]!=Bcount[i])ans+=(1LL<<i);
        //cout<<ans<<endl;
    ;}
    cout<<ans<<endl;
    /*for(ll i=0;i<5;i++){
        cout<<Acount[i]<<endl;
    ;}cout<<endl;
    for(ll i=0;i<5;i++){
        cout<<Bcount[i]<<endl;
    ;}*/
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
struct seg { int le, ri,num; ll hei; };
int main() {
	int n; cin >> n; ll h[100];
	rep(i, n) {
		cin >> h[i];
	}
	ll res = 1;
	if (n == 1) {
		cout << mod_pow(2, h[0], MOD) << endl; return 0;
	}
	rep(i, n) {
		if (i == 0) {
			if (h[0] > h[1]) {
				(res *= mod_pow(2, h[0] - h[1],MOD)) %= MOD;
				h[0] = h[1];
			}
		}
		else if (i == n - 1) {
			if (h[n - 2] < h[n - 1]) {
				(res *= mod_pow(2, h[n - 1] - h[n - 2],MOD)) %= MOD;
				h[n - 1] = h[n - 2];
			}
		}
		else {
			ll mh = max(h[i - 1], h[i + 1]);
			if (h[i] > mh) {
				(res *= mod_pow(2, h[i] - mh, MOD)) %= MOD;
				h[i] = mh;
			}
		}
	}
	seg a[1000];
	vector<int> G[1000];
	queue<seg> q; int sum = 0;
	q.push({ 0, n ,0,0 });
	while (!q.empty()) {
		seg nex = q.front(); q.pop();
		int le = nex.le; int ri = nex.ri; ll hei = nex.hei;
		int num = nex.num;
		ll mi = INF;
		Rep(i, le, ri) {
			mi = min(mi, h[i]);
		}
		a[num] = { le,ri,0,mi - hei };
		int now = le;
		Rep(i, le, ri) {
			if (mi == h[i]) {
				if (i - now > 0) {
					sum++;
					G[num].push_back(sum);
					q.push({ now, i, sum, mi });
				}
				now = i + 1;
			}
		}
		if (ri-now>0) {
			sum++;
			G[num].push_back(sum);
			q.push({ now,ri,sum,mi });
		}
	}
	LP dp[1000];
	per(i, sum+1) {
		int len = G[i].size();
		ll he = a[i].hei;
		int le = a[i].le; int ri = a[i].ri;
		if (len == 0) {
			dp[i].first = mod_pow(2, he, MOD);
			dp[i].second = mod_pow(2, ri - le, MOD);
			(dp[i].second += dp[i].first) %= MOD;
			(dp[i].second += MOD - (ll)2) %= MOD;
		}
		else {
			ll nex1 = mod_pow(2, he, MOD);
			int wei = ri - le;
			rep(j, len) {
				seg nod = a[G[i][j]];
				wei -= (nod.ri - nod.le);
			}
			ll nex2 = mod_pow(2, wei, MOD);
			rep(j, len) {
				int v = G[i][j];
				(nex1 *= dp[v].first) %= MOD;
				(nex2 *= (dp[v].first + dp[v].second) % MOD) %= MOD;
			}
			ll cnex = mod_pow(2, he, MOD);
			(cnex += MOD - (ll)2) %= MOD;
			rep(j, len) {
				int v = G[i][j];
				(cnex *= dp[v].first) %= MOD;
			}
			(nex2 += cnex) %= MOD;
			dp[i] = { nex1,nex2 };
		}
	}
	cout << res * dp[0].second % MOD << endl;
	return 0;
}

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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

int n, a, b;

int x, y, z;

int main() {
  cin >> n >> a >> b;
  REP(i, n) {
    int t;
    cin >> t;
    if (t <= a) x++;
    else if (t >= a + 1 && t <= b) y++;
    else z++;
  }
  cout << min(x, min(y, z)) << endl;
  return 0;
}


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

int main() {
	int n, t;
	vector<int> v;
	cin>>n>>t;
        int arr[n];
        for(int i=0 ; i<n ; i++)
            cin>>arr[i];
            
        vector<int> res(arr, arr+n);
            
        int x,y;
        
        while(t--){
            int x = *min_element(res.begin(), res.end());
            for(int i=0 ; i<res.size() ; i++){
                if(x == res[i])
                    y = i;
            }
            v.push_back(x);
            res.erase(res.begin() + y);
        }
    
    int sum = 0;
    
    for(int i=0 ; i<v.size() ; i++){
        sum += v[i];
    }
    
    cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 3640
V = int(input())

def has_odd(L):
    for l in L:
        if l % 2 != 0:
            return True
    return False

def dev2(l):
    return l // 2

nums = list(map(int, input().split()))
times = 0
while not has_odd(nums):
    nums = list(map(dev2, nums))
    times += 1
print(times)


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){

  ll n,a,b;cin>>n>>a>>b;
  COMinit();

  ll sum=1;
  rep(i,0,a){
    sum*=(n-i);
    sum%=mod;
  }
  
  sum*=(modinv(fac[a],mod)%mod);
  sum%=mod;
  
  ll sumb=1;
  rep(i,0,b){
    sumb*=(n-i);
    sumb%=mod;
  }
  sumb*=(modinv(fac[b],mod)%mod);
  sumb%=mod;

  ll ans=(myPow(2,n,mod)-1-sum-sumb)%mod;

  if(ans<0)out(mod+ans);
  else out(ans);




  return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define ll long long
const ll INF = 1e15;


int A, B, Q;
vector<ll> s, t, x;

int get_s_index(ll x_i){
	int prev = 0;
	int cur = A/2;
	int next = A;
	while(!(s[cur] < x_i && x_i < s[cur+1])){
		if(x_i < s[cur]){
			next = cur;
			cur = (prev+cur-1)/2;
		}else{
			prev = cur;
			cur = (cur+next+1)/2;
		}
	}
	return cur;
}

int get_t_index(ll x_i){
	int prev = 0;
	int cur = B/2;
	int next = B;
	while(!(t[cur] < x_i && x_i < t[cur+1])){
		if(x_i < t[cur]){
			next = cur;
			cur = (prev+cur-1)/2;
		}else{
			prev = cur;
			cur = (cur+next+1)/2;
		}
	}
	return cur;
}


void sub_solve(int i){
	int index_s = get_s_index(x[i]);
	int index_t = get_t_index(x[i]);

	ll a = x[i] - min(s[index_s], t[index_t]);
	ll b = max(s[index_s+1], t[index_t+1]) - x[i];
	ll c = 2*(x[i]-s[index_s]) + t[index_t+1]-x[i];
	ll d = 2*(x[i]-t[index_t]) + s[index_s+1]-x[i];
	ll e = 2*(s[index_s+1] - x[i]) + x[i]-t[index_t];
	ll f = 2*(t[index_t+1] - x[i]) + x[i]-s[index_s] ;

	cout << min({a,b,c,d,e,f}) << endl;
}

void solve(){
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	
	for(int i=0;i<Q;i++){
		sub_solve(i);
	}
}

int main(){
	cin >> A >> B >> Q;
	s.resize(A); t.resize(B); x.resize(Q);
	for(int i=0;i<A;i++){
		cin >> s[i];
	}
	for(int i=0;i<B;i++){
		cin >> t[i];
	}
	for(int i=0;i<Q;i++){
		cin >> x[i];
	}
	s.push_back(INF);s.push_back(-INF);
	t.push_back(INF);t.push_back(-INF);

	solve();
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

int n, a;
int x[55] = {};
// dp[i][j][k] := i 個あるうち j 個を選んで合計を k にする数
// ans = dp[n][j][j*a] (1 <= j <= n)
ll dp[55][55][2525] = {};

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

	cin >> n >> a;
    rep(i, n) cin >> x[i];
    
    dp[0][0][0] = 1;
    rep(i, n) rep(j, n) rep(k, 2525) {
        // i+1 個目を選ばない
        dp[i+1][j][k] += dp[i][j][k];
        // i+1 個目を選ぶ
        if(k-x[i] >= 0) {
            dp[i+1][j+1][k] += dp[i][j][k-x[i]];
        }
    }
    ll ans = 0;
    REP(j, 1, n+1) {
        ans += dp[n][j][a*j];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 54528
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll h, w;
  cin >> h >> w;
  string s[h];
  REP(i, h) cin >> s[i];
  REP(i, h) cout << s[i] << endl << s[i] << endl;
  return 0;
}


Measured memory_bytes: 256
program ccc
implicit none

integer(8) :: n, i, one, two, gl, gr, g, res
integer(8),allocatable,dimension(:) :: a, l, r

read*, n
allocate(a(n),l(0:n+1),r(0:n+1))
read*, a

l=0
r=0
l(1)=a(1)
r(n)=a(n)

do i=2,n
one=l(i-1)
two=a(i)
call gcd(one,two,gl)
l(i)=gl
end do

do i=n-1,1,-1
one=r(i+1)
two=a(i)
call gcd(one,two,gr)
r(i)=gr
end do

res=0
g=0
do i=1,n
gl=l(i-1)
gr=r(i+1)
if(gl==0) gl=gr
if(gr==0) gr=gl
call gcd(gl,gr,g)
res=max(res,g)
end do

write(*,'(i0)') res

end program

subroutine gcd(a,b,ans)
integer(8) :: a, b, aa, bb, m, ans

aa=max(a,b)
bb=min(a,b)
a=aa
b=bb
m=1

do while(m/=0)
 m=mod(a,b)
 a=b
 b=m
end do
ans=a
end subroutine gcd

Measured memory_bytes: 3200
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    vector<ll> v(3);
    ll k;cin>>v[0]>>v[1]>>v[2]>>k;
    sort(v.begin(),v.end());
    cout<<v[0]+v[1]+(v[2]<<k)<<endl;
}


Measured memory_bytes: 256
n, l = map(int, input().split())
lst_l = list(range(l, l + n))
if 0 in lst_l:
    print(sum(lst_l))
else:
    if max(lst_l) > 1:
        print(sum(lst_l[1:]))
    else:
        print(sum(lst_l[:-1]))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

struct Team {
	int id;
	int time;
};
bool operator < (const Team& t1, const Team& t2) { return t1.time < t2.time; }

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		Team* teams = new Team[n];
		for (int i=0; i<n; i++) {
			int id, m1, s1, m2, s2, m3, s3, m4, s4;
			std::cin >> id >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			teams[i].id = id;
			teams[i].time = 60*(m1+m2+m3+m4) + s1+s2+s3+s4; 
		}
		std::sort(teams, teams + n);
		std::cout << teams[0].id << std::endl;
		std::cout << teams[1].id << std::endl;
		std::cout << teams[n-2].id << std::endl;
		delete[] teams;
	}
	return 0;
}



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

int main(){
  int n;
  int p[3],d[2];

  for(int i=0;i<3;i++)cin >> p[i];
  for(int i=0;i<2;i++)cin >> d[i];

  int ans = 10000;
  for(int i=0;i<3;i++)
    for(int j=0;j<2;j++)ans = min(ans,p[i]+d[j]-50);

  cout << ans << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans="Yes";
    if(n%2==0){
        rep(i, n/2){
            if(s[i]!=s[n/2+i]){
                ans = "No";
                break;
            }
        }
    }else{
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll X, Y;
  cin >> X >> Y;

  cout << X + Y / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
 #include <cmath>
using namespace std;

 unsigned GetDigit(unsigned num){
    return std::to_string(num).length();
}
 
int main()
{	unsigned int n = 0;
 	int sum = 0;
 	int keta =0;
 	cin>>n;
    keta = GetDigit(n);
  
    int start = 0;
    if(keta%2==1){
        
for(int i = keta - 2;i>0;i-=2){
    sum = sum + pow(10,i -1)*9;
   
}
sum = sum + n - pow(10,keta - 1) + 1;

    }else{
        for(int i = keta - 1;i>0;i-=2){
    sum += pow(10,i -1)*9;
   
}
    }
cout<<sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
/* Data Structure */
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define debug cerr << "======= GOT_HERE ======\n"
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef map<int,int> mii;
typedef map<long long,long long> mll;
typedef set<int> si;
typedef set<long long> sll;

long long n,k;

string s,t,u;

int a,b;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s==u)
		a--;
	else 
		b--;
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using ll=long long;
using namespace std;
const auto mod=1e9+7;

template <typename T>
using GPQ=priority_queue<T,vector<T>,greater<T>>;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int a,b; cin >> a >> b;
  cout << max(a-2*b,0) << endl;
}

Measured memory_bytes: 896
#include<stdio.h>
int main(void){
    int a;
    int b;
    int c;
    scanf("%d%d%d",&a,&b,&c);
    int f = 0;
    if(a > b){
        f ++;
    }
    if(b > c){
        f += 2;
    }
    if(a > c){
        f += 3;
    }
    if(f == 0){
        printf("%d %d %d\n",a,b,c);
    }
    if(f == 1){
        printf("%d %d %d\n",b,a,c);
    }
    if(f == 2){
        printf("%d %d %d\n",a,c,b);
    }
    if(f == 4){
        printf("%d %d %d\n",b,c,a);
    }
    if(f == 5){
        printf("%d %d %d\n",c,a,b);
    }
    if(f == 6){
        printf("%d %d %d\n",c,b,a);
    }
    return 0;
}

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

using namespace std;

int main(){
 long N,K;
  cin>>N>>K;
  vector<long> v(N);
  for(auto &x:v){
    cin>>x;
  }
  sort(v.begin(),v.end());
  long ans=0;
  for(int i=N-1;i>=0;i--){
    if(K>0){
      K--;
    }else{
      ans+=v[i];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll pow_mod(ll a, ll n, ll m)
{
    if(n == 0) return 1;
    ll x = pow_mod(a, n/2, m);
    long long ans = (long long)x * x % m;
    if(n % 2 == 1) ans = ans *a % m;
    return ans;//
}
int sum[600000];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        int v;
        scanf("%d",&v);
        sum[v]++;
        if(sum[v]>=3)
        {
            printf("0\n");//不符合情况一
            return 0;
        }
    }
    if(n&1)
    {
        //非0
        if(sum[0]!=1)
        {
            //0只能出现一次
            printf("0\n");
            return 0;
        }
    }
    if(!(n%2))
    {
        //n为偶数
        if(sum[0])
        {
            //0的个数不为0不符合条件
            printf("0\n");
            return 0;
        }
    }
    printf("%lld\n",pow_mod(2,n/2,mod));
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dp[5002][5002];
int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	for(ll i=s.size()-1;i>=0;i--){
		for(ll j=s.size()-1;j>=0;j--){
			if(s[i]==s[j]){
				dp[i][j]=1+dp[i+1][j+1];
			}
			if(i+dp[i][j]-1<j){
				ans=max(ans,dp[i][j]);
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
int num[1<<18];
int main()
{
    int n;scanf("%d",&n);
    rep(i,0,1<<n)scanf("%d",&num[i]);
    sort(num,num+(1<<n),greater<int>());
    priority_queue<int> pq;
    int flag=1;vector<int> tmp;
    tmp.push_back(n);
    rep(i,1,(1<<n))
    {
        if(num[i]!=num[i-1])
        {
            for(int k:tmp)pq.push(k);
            tmp.clear();
        }
        if(pq.empty()){flag=0;break;}
        int x=pq.top();pq.pop();
        if(x!=1)tmp.push_back(x-1),pq.push(x-1);
    }
    if(flag)printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 2044
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X, A, B = list(map(int, sys.stdin.buffer.readline().decode().split()))
    if B - A > X:
        print('dangerous')
    elif A >= B:
        print('delicious')
    else:
        print('safe')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940