akhauriyash/Code-Regression huggingface dataset:
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, k; cin >> n >> k;
    vector<char> d(k);
    rep(i, k) cin >> d[i];
    int ans = INF;
    for (int i=n; i<=10*n; ++i) {
        bool ok = true;
        string num = to_string(i);
        rep(j, num.size()) {
            bool flag = false;
            rep(l, d.size()) {
                if (num[j]==d[l]) {flag = true; break;}
            }
            if (flag) {ok=false; break;}
        }
        if (ok) {cout << i << endl; return 0;}
    }
    return 0;
}

Measured memory_bytes: 256
N =int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.insert(0,-100)
ans = sum(B)
for i in range(N):
    if A[i+1]-1 == A[i]:
        ans += C[A[i]-1]

print(ans)

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

int main(){
	int N;
	cin >> N;
	vector<vector<pair<int,int>>> a;
	vector<pair<string,int>> city;
	string S;
	int P;
	for(int i=0;i<N;i++){
		cin >> S >> P;
		bool pro =false;
		for(int j=0;j<city.size();j++){
			if(city.at(j).first==S){
				pro=true;
				a.at(city.at(j).second).push_back(make_pair(P,i+1));
				break;
			}
		}
		if(!pro){
			vector<pair<int,int>> b;
			b.push_back(make_pair(P,i+1));
			a.push_back(b);
			city.push_back(make_pair(S,a.size()-1));
		}
	}
	sort(city.begin(),city.end());
	for(int i=0;i<city.size();i++){
		sort(a.at(city.at(i).second).begin(),a.at(city.at(i).second).end());
		reverse(a.at(city.at(i).second).begin(),a.at(city.at(i).second).end());
		for(int j=0;j<a.at(city.at(i).second).size();j++){
			cout<<a.at(city.at(i).second).at(j).second<<endl;
		}
	}
	
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std; 
 
long long int C[5001];
int P[5001];
vector <int> adj[5001];
long long int visited[5001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int n,t;
	long long int k,K;
 
	cin >> n >> k;
	K = k;
	for(int i=1;i<=n;i++)
	{
		cin >> t;
		P[i] = t;
		adj[i].push_back(t);
	}
 
	for(int i=1;i<=n;i++)
	{
		cin >> C[i];
	}
 
	long long int res = -1e18;
 
	for(int i=1;i<=n;i++)
	{
		memset(visited,-1,sizeof(visited));
		queue <int> que;
		que.push(i);
		visited[i] = 0;
		int point = -1;
		int cnt = 0;
		k = K;
		while(!que.empty())
		{
			int now = que.front();
			que.pop();
			cnt++;
			for(auto next : adj[now])
			{
				if(visited[next]==-1)
				{
					visited[next] = visited[now] + 1;
					que.push(next);
				}
				else
				{
					//cout << i << ' ' << now << ' ' << next << '\n';
					point = next;
					break;
				}
			}
		}
		int x = cnt;		
		k = K;
		if(k <= x)
		{
			long long int score = 0;
			int now = i;
			int cnt = 0;
			while(1)
			{
				if(cnt==k)
				{
					break;
				}
				cnt++;
				score += C[P[now]];
				res = max(res,score);
				now = P[now];
			}
		}
		else
		{
			long long int score = 0;
			long long int sum = 0;
			int pp = i;
			for(int j=0;j<x;j++)
			{
				sum += C[P[pp]];
				res = max(res,sum);
				pp = P[pp];
			}
			//cout << sum << '\n';
			long long int temp = 0;
			pp = i;
			for(int j=0;j<x;j++)
			{
				temp += C[P[pp]];
				res = max(res,score + ((k/x)-1)*sum + temp);
				pp = P[pp];
			}
			score += (k/x)*sum;
			//cout << score << '\n';
			res = max(res,score);
			k%=x;
			pp = i;
			for(int j=0;j<k;j++)
			{
				score += C[P[pp]];
				res = max(res,score);
				pp = P[pp];
			}
		}
	}
 
	cout << res << '\n';
 
	return 0;
}

Measured memory_bytes: 3960
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: i64, k: i64,
    }
    let mut pass = 0;
    let mut fail = k + 1;
    while fail - pass > 1 {
        let mid = (fail + pass) / 2;
        let mut sum = 0;
        let mut cur = mid;
        for _ in 0..min(n, 60) {
            sum += cur;
            cur /= 2;
        }
        if sum <= k {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    puts!("{}\n", pass);
    
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



Measured memory_bytes: 1176
#include <stdio.h>
#include <stdlib.h>

#define TRI_NORMAL 0
#define TRI_CHOKKAKU 1
#define TRI_EIKAKU 2
#define TRI_DONKAKU 3
#define TRI_NONE 4
#define TRI_MAX 5

int check_triangle(int a, int b, int c)
{
  int t;
  if ( a > b ) {
    t = a;
    a = b;
    b = t;
  }
  if ( a > c ) {
    t = a;
    a = c;
    c = t;
  }
  if ( b > c ) {
    t = b;
    b = c;
    c = t;
  }

  if ( a + b <= c )
    return TRI_NONE;

  a = a * a + b * b;
  c = c * c;

  return ( a == c ) ? TRI_CHOKKAKU : (a < c) ? TRI_DONKAKU : TRI_EIKAKU;
}

int main()
{
  int count[TRI_MAX];
  char line[256];
  int a, b, c, i, type;

  for (i = 0; i < TRI_MAX; i ++) count[i] = 0;
  while (fgets(line, 256, stdin)) {
    if ( sscanf(line, "%d %d %d", &a, &b, &c) == 3 ) {
      type = check_triangle(a, b, c);
      if ( type == TRI_NONE )
	break;
      count[type] ++;
      count[TRI_NORMAL] ++;
    } else {
      break;
    }
  }
  printf("%d %d %d %d\n",
	 count[TRI_NORMAL],
	 count[TRI_CHOKKAKU],
	 count[TRI_EIKAKU],
	 count[TRI_DONKAKU]);
  return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next(), s2 = sc.next(), s3 = sc.next();
		String ss1 = s1.substring(0, 1), ss2 = s2.substring(1, 2), ss3 = s3.substring(2);
		System.out.println(ss1 + ss2 + ss3);
		sc.close();
	}
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<int> x(n + 1);
  
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      x.at(a)++;
    }
  }
  
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (x.at(i) == 0) ans++;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  ll N, K; cin >> N >> K;
  vvi num(N, vi(2));
  rep(i,N) cin >> num[i][0] >> num[i][1];
  
  sort(all(num));
  ll counter = 0;
  rep(i,N){
    counter += num[i][1];
    if(counter >= K) {cout << num[i][0] << endl; return 0;}
  } 
  return 0;
}

Measured memory_bytes: 8700
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 1; i <= N; i+= 2){
        ll tmp = 0;
        for(ll j = 1; j <= i; j++) if(i % j == 0) tmp++;
        if(tmp == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
 
#define LIMIT 330
 
int cnt[11][LIMIT+1];
bool used[11];
 
void make(int k, int N, int sum)
{
    if(sum > LIMIT) return;
 
    if (N == 0) {
	cnt[k][sum]++;
	return;
    }
 
    for (int i = 0; i <= 9; i++) {
	if (!used[i]) {
	    used[i] = true;
	    make(k + 1, N - 1, sum + (k + 1) * i);
	    used[i] = false;
	}
    }
}
 
void init()
{
    for (int i = 0; i <= 10; i++) {
	memset(used, false, sizeof(used));
	make(0, i, 0);    
    }
}
 
int main()
{
    int n, s;
 
    init();
    while (cin >> n >> s) {
	if (s <= LIMIT) {
	    cout << cnt[n][s] << endl;
	} else {
	    cout << 0 << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3104
N, M = map(int, input().split())
a = [[] for _ in range(N)]
flag = 0
for i in range(M):
  s, c = map(int, input().split())
  a[s-1].append(c)
ans = [0]*N
 
for i in range(len(a)): 
  if i == 0 and a[i]:
    if len(a) == 1:
      pass
    elif len(set(a[i]))> 1 or 0 in a[i]:
      flag = 1
      break
    else:
      ans[i] = a[i][0] 
  if len(set(a[i]))>1:
    flag = 1
    break
  elif a[i]:
    ans[i] = a[i][0]
if flag == 0:
  if ans[0] == 0:
    if len(a) == 1:
      ans[0] = 0
    else:
      ans[0] = 1
  ans = ''.join((str(n) for n in ans))
  print(int(ans))
else:
  print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a+b == c+d)
    cout << "Balanced" << endl;
  if (a+b < c+d)
    cout << "Right" << endl;
  if (a+b > c+d)
    cout << "Left" << endl;
    
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define DEC(x) fixed<<setprecision(x)
#define FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);
const long long INF=2e18;

template<typename T,typename T1>void amax(T &a,T1 b){if(b>a)a=b;}
template<typename T,typename T1>void amin(T &a,T1 b){if(b<a)a=b;}

ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

// #define _NCR_
ll cnt[1000001];
int TLE_TERROR()
{
    ll n,ma=-2e18,f=0;
    cin>>n;
    ll int a[n];
    for(ll int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
        ma=max(ma,a[i]);
    }
    ll z=a[0];
    for(ll int i=1;i<n;i++)
    {
        z=__gcd(z,a[i]);
    }
    if(z!=1)
    {
        cout<<"not coprime";
        return 0;
    }
    for(ll int i=2;i<=ma;i++)
    {
        z=0;
        for(ll j=i;j<=ma;j+=i)
        {
            if(cnt[j]>0)
                z++;
        }
        if(z>1)
        {
            f=1;
            break;
        }
    }
    if(f==1)
        cout<<"setwise coprime";
    else
        cout<<"pairwise coprime";
    return 0;   
}

int main()
{
    FAST
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll int TESTS=1;
    // cin>>TESTS;
    #ifdef _NCR_
        initialvalues();
    #endif
    while(TESTS--)
        TLE_TERROR();
    return 0;
}

Measured memory_bytes: 19120
n, d = input().split()
n, d = int(n), int(d)

x = []

for i in range(n):
    x.append([int(j) for j in input().split()])

def are(a, b):
    sm = 0
    for i in range(len(a)):
        sm += (b[i] - a[i]) ** 2
    return sm ** 0.5 == int(sm ** 0.5)

c = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        c += are(x[i], x[j])

print(c)

Measured memory_bytes: 3188
S = input()
S = S[::-1]
L = len(S)

d = ["dreamer", "dream", "eraser", "erase"]
for i in range(4):
    d[i] = d[i][::-1]

count = 0
end = False
yes = False

while 1:
    judge = 0
    for i in range(4):
        if S[count:(len(d[i])+count)] == d[i]:
            count += len(d[i])
            if count == L:
                end = True
                yes = True
        else:
            judge += 1
    if end or judge == 4:
        break

if yes:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  ll n;
  std::cin >> n;
  string s[100010];
  ll m=0,a=0,r=0,c=0,h=0;
  for(ll i=0; i<n; i++){
    std::cin >> s[i];
    if(s[i][0]=='M') m++;
    else if(s[i][0]=='A') a++; 
    else if(s[i][0]=='R') r++; 
    else if(s[i][0]=='C') c++; 
    else if(s[i][0]=='H') h++; 
  }
  unsigned long long ans=0;
  ans+=m*a*r;
  ans+=m*a*c;
  ans+=m*a*h;
  ans+=m*r*c;
  ans+=m*r*h;
  ans+=m*c*h;
  ans+=a*r*c;
  ans+=a*r*h;
  ans+=a*c*h;
  ans+=r*c*h;
  std::cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 6144
def main(x: str):
    weekdays = {
        'SAT': 1,
        'SUN': 7,
        'MON': 6,
        'TUE': 5,
        'WED': 4,
        'THU': 3,
        'FRI': 2,
    }
    print(weekdays[x])


if __name__ == '__main__':
    # a = [input() for i in range(n)]
    # points = [s.split(' ') for s in a]

    main(input())


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

using namespace std;

#define N 300000

int n,x,y,ans,l,r,mid,tot,rt,f[N],a[N],g[N],head[N],d[N];
struct edge{int v,nxt;}e[N];

void add(int x,int y){e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;}

bool dp(int u,int fa){
    f[u]=0;
    for (int i=head[u],v;i;i=e[i].nxt)
        if ((v=e[i].v)!=fa) if (!dp(v,u)) return 0;
    //printf("+++++++%d+++++++\n",u);
    //for (int i=head[u],v;i;i=e[i].nxt)
        //if ((v=e[i].v)!=fa) printf("%d\n",f[v]);
    int xb=0;
    for (int i=head[u],v;i;i=e[i].nxt)
        if ((v=e[i].v)!=fa) a[++xb]=f[v]+1;
    if ((xb&1)==0) a[++xb]=0;
    sort(a+1,a+xb+1);//for (int i=1;i<=xb;i++) cout<<a[i]<<endl;
    memset(g,-1,sizeof(int)*(xb+2));
    int j,k; j=1;
    for (int i=xb;i>=1;i--){
        g[i]=g[i+1];//if (j>=i) g[i]=i-1;
        for (;j<i && a[j]+a[i]<=mid;j++) g[i]=j;
        j--;
    }
    j=0,k=0;
    for (int i=xb;i>xb/2+1;i--) if (g[i]<xb-i+1){k=i; break;}//cout<<"orz"<<k<<endl;
    if (k==0){
        j=1; for (int i=xb;i>xb/2+1;i--) if (g[i]<xb-i+2) j=xb-i+2;
        f[u]=a[j];
    }
    else{
        j=0; for (int i=xb;i>j+1;i--) if (k!=i){j++; if (a[i]+a[j]>mid) return 0;}
        f[u]=a[k];
    }
    if (u==rt && f[u]>mid) return 0;
    return 1;
}

int main(){//freopen("in","r",stdin);
    scanf("%d",&n);
    for (int i=1;i<n;i++){scanf("%d%d",&x,&y); add(x,y); add(y,x); d[x]++; d[y]++;}
    for (int i=1;i<=n;i++) if (d[i]&1) ans++;
    for (int i=1;i<=n;i++) if (d[i]==1){rt=i; break;}// cout<<rt<<endl;
    ans/=2; printf("%d ",ans);
    l=1,r=n;
    while (l<=r){
        mid=(l+r)>>1; memset(f,0,sizeof f);
        if (dp(rt,0)){ans=mid; r=mid-1;} else l=mid+1;
    }//*/mid=2; if (dp(rt,0)) puts("orz");
    printf("%d\n",ans);

    return 0;
}


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

int main() {
  int n;
  cin>>n;
  int a=n%10;
  int b=n/100;
  if(a==b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main(){
    string s;
    cin>>s;
    int q=0,l=s.length();
    while(q<l)
    {
    if(s[q]=='C')break;
    q++;
}
    while(q<l)
    {
    if(s[q]=='F')
    {
    	cout<<"Yes"<<endl;
    	return 0;
	}
	q++;
}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
const int INF = 1000100100;

int main(){
    ll a[10],flag=0;
    
    rep(i,9){
        cin>>a[i];
    }
    if(a[0]-a[3]!=a[1]-a[4]) flag=1;
    if(a[0]-a[3]!=a[2]-a[5]) flag=1;
    if(a[6]-a[3]!=a[7]-a[4]) flag=1;
    if(a[6]-a[3]!=a[8]-a[5]) flag=1;
    if(a[0]-a[1]!=a[3]-a[4]) flag=1;
    if(a[0]-a[2]!=a[3]-a[5]) flag=1;
    if(a[6]-a[7]!=a[3]-a[4]) flag=1;
    if(a[6]-a[8]!=a[3]-a[5]) flag=1;

    if(flag==0){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
const ll mod = 1000000007;
int n;
vvi g;

int go(int v) {
	vi d;
	d.assign(n, -1);
	int ans = 1;
	d[v] = 1;
	queue<int> q;
	q.push(v);
	int md;
	while (q.size()) {
		int V = q.front();
		q.pop();
		md = d[V];
		for (auto i : g[V]) {
			if(d[i] != -1) continue;
			d[i] = d[V]+1;
			q.push(i);
		}
//		cout << V
	}
	for(int i = 0; i < n; i++)
		for(auto j : g[i])
			if(abs(d[i]-d[j])!=1)
				return -1;
//	cout << v << " "
	return md;
}

int main() {
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> n;
	g.resize(n);
	char c;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> c;
			if (c == '1')
				g[i].pb(j);
		}
	}
	int ans = -1;
	for (int i = 0; i < n; i++)
		ans = max(ans, go(i));
	cout << ans;
}


Measured memory_bytes: 640
N = int(input())-1

dic={}
ans=[]
#N=1
dic['a']=1
ans.append('a')

alp = ['a','b','c','d','e','f','g','h','i','j','k']


for i in range(N):
    ans_temp = ans
    dic_temp = dic
    #init for N
    ans = []
    dic={}
    dic_count={}
    #left a
    for j in ans_temp:
        new_j = 'a'+ j
        ans.append(new_j)
        dic[new_j]=dic_temp[j]
        dic_count[new_j]=1
    # right append
    for l in ans_temp:
        num_alp = dic_temp[l]
        for m in range(num_alp+1):
            new_l = l+alp[m]

            if dic_count.get(new_l) is None:
                ans.append(new_l)
                dic_count[new_j]=1
                if m==num_alp:
                    dic[new_l]=dic_temp[l]+1
                else:
                    dic[new_l]=dic_temp[l]

        
    
        
        

for i in ans:
    print(i)

Measured memory_bytes: 21844
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min,max};

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

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

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

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

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

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

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

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

fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin 
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let n : usize = read();
    if n == 1 {
        println!("Hello World");
    } else {
        let a : usize = read();
        let b : usize = read();
        println!("{}", a + b);
    }
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A >= 13)
    cout << B << endl;
  else if (A >= 6)
    cout << B / 2 << endl;
  else
    cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#coding:utf-8
#1_10_A
def fibo(n, numbers):
    if n == 0 or n == 1:
        numbers[n] = 1
        return numbers[n]
    elif numbers[n]:
        return numbers[n]
    else:
        numbers[n] = fibo(n - 1, numbers) + fibo(n - 2, numbers)
        return numbers[n]

n = int(input())
fibonacci_numbers = [0 for i in range(n + 1)]
print(fibo(n, fibonacci_numbers))

Measured memory_bytes: 7728
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#ifdef LOCAL
template <class T> ostream &operator<<(ostream &str, const vector<T> &vec) {
  str << '[';
  for (auto it = vec.begin(); it != vec.end(); it++) {
    if (it != vec.begin())
      str << ", ";
    str << *it;
  }
  str << ']';
  return str;
}
#define var(x) "[" << #x << ": " << x << "] "
#define dbg cerr << "  line " << __LINE__ << ": "
#else
#define var(x) 0
struct dbg_cls {
  template <class T> dbg_cls &operator<<(const T &oth) { return *this; }
} dbg;
#endif
using ll = long long;
using ld = long double;
int main(int argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  auto solve = [&]() {
    ll a;
    string b;
    cin >> a >> b;
    b.erase(1, 1);

    ll realb = stoll(b);

    cout << (a * realb) / 100ll << '\n';
  };
  int t;
  t = 1;
  while (t--)
    solve();
  return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///


void _case()
{
    ll n,i,ans=0;
    cin>>n;
    ll a[n],b[n+1];
    forn(i,n-1) cin>>b[i];
    a[n-1]=b[n-2];
    for(i=n-2;i>0;i--) a[i]=min(b[i],b[i-1]);
    a[0]=b[0];
    forn(i,n) ans+=a[i];
    cout<<ans el;

}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 
int main(){
	int n, q;
	cin>>n>>q;
	queue<pair<int,string> > que;
	string s; int m;
	rep(i, n){
		cin>>s>>m;
		que.push(pair<int,string>(m, s));
	}
	int t = 0;
	pair<int,string> p;
	while(!que.empty()){
		p = que.front();
		que.pop();
		if(p.fi - q > 0) {
			que.push(pair<int,string>(p.fi - q, p.se));
			t += q;
		}
		else {
			t += p.fi;
			cout<<p.se<<" "<<t<<endl;
		}
	}
}

Measured memory_bytes: 4404
fn factor(mut n: u128) -> Vec<(u128, u128)> {
    let mut ret = vec![];
    for i in 2.. {
        if i * i > n {
            break;
        }
        let mut cnt = 0;
        while n % i == 0 {
            cnt += 1;
            n /= i;
        }
        if cnt != 0 {
            ret.push((i, cnt));
        }
    }
    if n != 1 {
        ret.push((n, 1));
    }
    ret
}

fn main() {
    proconio::input! {
        n: u128,
        p: u128,
    }
    let factors = factor(p);
    let gcd_candidates = factors
        .iter()
        .filter(|(_factor, num)| *num >= n)
        .collect::<Vec<_>>();
    let ans = gcd_candidates.iter().fold(1u128, |sum, (factor, num)| {
        sum * factor.pow((num / n) as u32)
    });
    println!("{}", ans);
}


Measured memory_bytes: 2164
n = int(input())
data_list = input().split()
odd_list = [data_list[i] for i in range(0, n, 2)]
even_list = [data_list[i] for i in range(1, n, 2)]

def make_dict(list):
  appeared = dict()
  for i in list:
    if not i in appeared:
      appeared[i] = 1
    else:
      appeared[i] += 1
  return appeared

odd_dict = make_dict(odd_list)
even_dict = make_dict(even_list)
odd_max = max(odd_dict.items(), key=lambda x: x[1])
even_max = max(even_dict.items(), key=lambda x: x[1])

if odd_max[0] != even_max[0]:
  print(n - (odd_max[1] + even_max[1]))
else:
  del odd_dict[odd_max[0]]
  del even_dict[even_max[0]]
  if len(odd_dict) == 0 and len(even_dict) == 0:
    print(n//2)
  elif len(odd_dict) == 0:
    even_second_max = max(even_dict.items(), key=lambda x: x[1])
    print(n//2 - even_second_max[1])
  elif len(even_dict) == 0:
    odd_second_max = max(odd_dict.items(), key=lambda x: x[1])
    print(n//2 - odd_second_max[1])
  else:
    odd_second_max = max(odd_dict.items(), key=lambda x: x[1])
    even_second_max = max(even_dict.items(), key=lambda x: x[1])
    print(n - max((odd_max[1] + even_second_max[1]), (odd_second_max[1] + even_max[1])))


Measured memory_bytes: 19436
takahashi, nakahashi, hikuhashi, k = gets.chomp.split(' ').map{|n| n.to_i}

if takahashi < 1 || nakahashi < 1 || hikuhashi < 1 || k < 0
  exit
end

if 10 < takahashi.to_s.length.to_i || 10 < nakahashi.to_s.length.to_i || 10 < hikuhashi.to_s.length.to_i || 19 < k.to_s.length.to_i
  exit
end

# if takahashi == nakahashi && nakahashi == hikuhashi && takahashi == hikuhashi
#   puts 0
#   exit
# end

# k.times {
#   tempH = nakahashi + hikuhashi
#   tempM = takahashi + hikuhashi
#   tempL = takahashi + nakahashi

#   takahashi = tempH
#   nakahashi = tempM
#   hikuhashi = tempL
# }

result = takahashi - nakahashi
if 19 < result.abs.to_s.length.to_i
  puts 'Unfair'
else
  if k % 2 == 0
    puts result
  else
    puts -1 * result
  end
end


Measured memory_bytes: 1788
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		int num1 = sc.nextInt();
		int num2 = sc.nextInt();
		int num3 = sc.nextInt();
		int num4 = sc.nextInt();
		int num5 = sc.nextInt();
		int num6 = sc.nextInt();
		int num7 = sc.nextInt();
		int num8 = sc.nextInt();
		int num9 = sc.nextInt();
		int num10 = sc.nextInt();

		checkNum(num1);
		checkNum(num2);
		checkNum(num3);
		checkNum(num4);
		checkNum(num5);
		checkNum(num6);
		checkNum(num7);
		checkNum(num8);
		checkNum(num9);
		checkNum(num10);

		List<Integer> list = new ArrayList<Integer>();

		list.add(num1);
		list.add(num2);
		list.add(num3);
		list.add(num4);
		list.add(num5);
		list.add(num6);
		list.add(num7);
		list.add(num8);
		list.add(num9);
		list.add(num10);

		Collections.sort(list);
		Collections.reverse(list);

		for(int cnt = 0; cnt < 3; cnt++){

			System.out.println(list.get(cnt));
		}


	}

	public static void checkNum(int x){

		if(x < 0 || 10000 < x){

			throw new IllegalArgumentException("out of range");

		}
	}

}

Measured memory_bytes: 25928
#include<iostream>
#include<set>
#include<utility>
using namespace std;
typedef pair<int, int> P;
typedef set<P> S;

int main() {
	int n, m, a;
	while (cin >> n >> m >> a, n, m, a) {
		int amida[105];
		for (int i = 0;i < n;i++)amida[i] = i + 1;

		S yoko[1200];
		for (int i = 0;i < m;i++) {
			int h, p, q;
			cin >> h >> p >> q;
			yoko[h].insert(make_pair(p, q));
		}

		for (int i = 1199;i > -1;i--) {
			
			for (auto itr = yoko[i].begin();itr != yoko[i].end();itr++) {
				P d = *itr;
				swap(amida[d.first - 1], amida[d.second - 1]);
			}
		}
		for (int i = 0;i < n;i++) {
			if (amida[i] == a)cout << i + 1 << endl;
		}
	}
	return 0;
}

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

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

    ll n,m;
    cin >> n;
    vector<ll> d(n);
    for (ll i = 0;i < n;i++){
        cin >> d[i];
    }
    cin >> m;
    vector<ll> t(m);
    for (ll i = 0;i < m;i++){
        cin >> t[i];
    }
    sort(d.begin(), d.end());
    sort(t.begin(), t.end());
    bool ans = true;
    if (n < m){
        ans = false;
    }
    else{
        ll c = 0;
        for (ll i = 0; i < n; i++){
            if (d[i] == t[c]){
                c++;
            }
        }
        if (c < m){
            ans = false;
        }
    }

    if (ans){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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

using namespace std;

int main() {
  //input
  int n;
  cin >> n;
  vector<int> a(n); // 大きさが可変な配列
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }

  //solve
  int ans = n;
  for (int i=0; i<n; i++){
    for (int j=0; j<i; j++){
      if (a[i]-a[j]<0){
        ans--;
        break; // jのfor文から抜ける
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 2e5+5;
int N, a[MAX];
ll ans;

int main(int argc, char** argv) {
	scanf("%d", &N);
	rep(i, 0, N)
		scanf("%d", a+i);
	sort(a, a+N, greater<int>());
	if(N == 2) printf("%d\n", a[0]);
	else {
		int j = 1, p = 1;
		ans = a[0]+a[1];
		rep(i, 3, N) {
			ans += a[j];
			if(++p == 2) p = 0, j++;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
long long a[10009],b[10009],n,dp[10009];
long long int lets_use_dp(long long h)
{
    if(h==0||h<0)
        return 0;
         if(dp[h]!=-1)
            return dp[h];
        long long int MIN=INT_MAX;
    for(int i=0;i<n;i++)
    {
        MIN=min(MIN,lets_use_dp(h-a[i])+b[i]);

    }
    dp[h]=MIN;
    return dp[h];
}
int main()
{ memset(dp,-1,sizeof(dp));
  long long h;
  cin>>h>>n;
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];
  cout<< lets_use_dp(h)<<endl;;
 // long long a[n+1];
  /*long long sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
  //long long x=h/a;
    //if(h%a==0)
      //  cout<<x<<endl;
   // else
    if(sum>=h)
   cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;*/

   // cout<<de_counter-1<<endl;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 500100;

int N, D;
ll arr[MAXN];

ll pamt[MAXN];
ll pbest[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    
    cin >> N >> D;
    pamt[0] = D;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i];
        pamt[i+1] = min (pamt[i], abs (pamt[i] - arr[i]));
    }

    pbest[N] = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        if (arr[i] <= 2 * pbest[i+1] + 1)
        {
            pbest[i] = pbest[i+1] + arr[i];
        }
        else
            pbest[i] = pbest[i+1];

        if (pbest[i] >= 1e12)
            pbest[i] = 1e12;
    }
/*
    for (int i = 0; i <= N; i++)
    {
        cout << pamt[i] << " " << pbest[i] << "\n";
    }*/

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++)
    {
        int x;
        cin >> x;
        if (pbest[x] >= pamt[x-1])
            cout << "NO\n";
        else
            cout << "YES\n";
    }
}

Measured memory_bytes: 13696
package main

import (
	"bufio"
	"fmt"
	"os"
	"unicode/utf8"
)

const (
	L = 'L'
	R = 'R'
)

var SIntListInitialValue int
var SIntListIsInitialized bool
var SIntListRecFunc func(int) int = nil

type SIntList []int

func lib_NewSIntList(length int, initialValue int) SIntList {
	if SIntListIsInitialized {
		panic("SIntList is already used")
	}
	ret := make([]int, length, length)
	for i := 0; i < length; i++ {
		ret[i] = initialValue
	}
	SIntListInitialValue = initialValue
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var S string
	scanner.Scan()
	S = scanner.Text()
	solve(S)
}
func (si SIntList) Rec(f func(index int) int) {
	SIntListRecFunc = f
}
func (si SIntList) Update(index int) int {
	if SIntListRecFunc == nil {
		panic("SIntListRecFunc is nil")
	}
	if si[int(index)] != SIntListInitialValue {
		return si[int(index)]
	}
	ret := SIntListRecFunc(index)
	si[int(index)] = ret
	return ret
}
func solve(S string) {
	s := []rune(S)
	N := utf8.RuneCountInString(S)
	lastPos := lib_NewSIntList(N, -1)
	count := make([]int, N, N)
	lastPos.Rec(func(i int) int {
		switch s[i] {
		case R:
			if s[i+1] == L {
				return i
			}
			rightLastPos := lastPos.Update(i + 1)
			switch s[rightLastPos] {
			case L:
				return rightLastPos - 1
			case R:
				return rightLastPos + 1
			}
		case L:
			if s[i-1] == R {
				return i
			}
			leftLastPos := lastPos.Update(i - 1)
			switch s[leftLastPos] {
			case L:
				return leftLastPos - 1
			case R:
				return leftLastPos + 1
			}
		}
		panic("unexpected s: " + string(s[i]))
	})
	for i := 0; i < len(lastPos); i++ {
		count[lastPos.Update(i)]++
	}
	for i := 0; i < len(count)-1; i++ {
		fmt.Print(count[i], " ")
	}
	fmt.Println(count[len(count)-1])
}


Measured memory_bytes: 54656
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 14 21:22:01 2020

@author: Kei
"""

X,N =  map(int,input().split())

p = []*N

if (N != 0):
    p = list(map(int,input().split()))

goal_p = X
goal_m = X
sw_p = 0
sw_m = 0

if (N ==0):
    print(X)
else:
    while(1):
        sw_p = 0
        sw_m = 0
        
        for i in range(0,N):
            if(goal_p == p[i]):
                sw_p =1
        
        for i in range(0,N):
            if(goal_m == p[i]):
                sw_m =1
        
        if(sw_m == 0):
            print(goal_m)
            break
        
        if(sw_p == 0):
            print(goal_p)
            break
        
        goal_p += 1
        goal_m -=1


Measured memory_bytes: 9232
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define re register
#define int long long
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=200000+10;

int n,d,a;
int x[N],h[N];
pair<int,int> m[N];

int c[N];
inline void add(int x,int y) { for (;x<=n+1;x+=x&-x) c[x]+=y; }
inline int sum(int x) { int s=0; for (;x;x-=x&-x) s+=c[x]; return s; }

signed main() {
    n=read(),d=read(),a=read(); int ans=0;
    for (re int i=1;i<=n;++i) m[i].first=read(),m[i].second=read();
    sort(m+1,m+n+1);
    for (re int i=1;i<=n;++i) x[i]=m[i].first,h[i]=m[i].second;
    for (re int i=1;i<=n;++i) {
        if (h[i]-sum(i)<=0) continue;
        int r=upper_bound(x+1,x+n+1,x[i]+d+d)-x-1;
        int c=(int)(ceil(1.0*(h[i]-sum(i))/a)+0.5);
        add(i,c*a),add(r+1,-c*a),ans+=c;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 8064
import Data.Int (Int64)

main = do
  n <- readLn :: IO Int64
  a <- readLn
  b <- readLn
  c <- readLn
  d <- readLn
  e <- readLn
  let m = minimum [a,b,c,d,e]
  print $ 4 + (n + m - 1) `quot` m


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

using namespace std;

const int MAX_N = 100000;

int main() {
    int n;
    int d[MAX_N];

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

    sort(d, d + n);

    cout << d[n / 2] - d[n / 2 - 1] << endl;
}


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

int main(){

    int N,i;
    string color;

    cin >> N;

    for(i=0;i<=N;i++){
        cin >> color;
        if(color == "Y"){
            cout << "Four";
            return 0;
        }
    }
    cout << "Three";
    return 0;
}

Measured memory_bytes: 256
K = int(input())
S = 0

def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A1 = [0,0]
A2 = [0,0,0]
for i in range(1, K+1):
    S = S + i

if K > 1:
    for j in range(1, K):
        A1[0] =  j
        for k in range(j+1,K+1):
            A1[1] = k
            S += 6 * gcd(A1[1],A1[0])

if K > 2:
    for i1 in range(1, K-1):
        A2[0] = i1
        for k1 in range(i1+1, K):
            A2[1] = k1
            for j1 in range(k1+1,K+1):
                A2[2] = j1
                G3 = gcd(A2[2],A2[1])
                if G3 >= A2[0]:
                    S += 6 * gcd(G3,A2[0])
                else:
                    S += 6 * gcd(A2[0],G3)
print(S)

Measured memory_bytes: 9240
#include <bits/stdc++.h>
#include <string>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define SZ(x) ((int)x.size())

using namespace std;
typedef long long ll;

int main() {
  ll N,A,B;
  cin >> N >> A >> B;
  string s;
  cin >> s;

  ll numA = 0;
  ll numB = 0;

  REP(i,N){
    if(s[i] == 'c'){
      cout << "No" << endl;
    }else if(s[i] == 'a'){
      if(numA + numB < A+B){
        cout << "Yes" << endl;
        numA++;
      }else{
        cout << "No" << endl;
      }
    }else{
      if(numA + numB < A + B && numB < B){
        cout << "Yes" << endl;
        numB++;
      }else{
        cout << "No" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 896
import math
X = int(input())
ruto = math.ceil(math.sqrt(2*X))+1
kari = ruto**2+ruto
ans=1
for i in range(ruto-1, 0, -1):
    if i**2+i < 2*X:
        ans = i+1
        break
    kari = i**2+i
print(ans)


Measured memory_bytes: 9016
#include<bits/stdc++.h>
using namespace std;
int main(){
  int e,y;
  cin>>e>>y;
  if(e==0){
    if(y<=1911) cout<<"M"<<y-1867<<endl;
    else if(y<=1925) cout<<"T"<<y-1911<<endl;
    else if(y<=1988) cout<<"S"<<y-1925<<endl;
    else cout<<"H"<<y-1988<<endl;
  }else if(e==1){
    cout<<1867+y<<endl;
  }else if(e==2){
    cout<<1911+y<<endl;
  }else if(e==3){
    cout<<1925+y<<endl;
  }else{
    cout<<1988+y<<endl;
  }
  return 0;
}



Measured memory_bytes: 3120
import math

a, b, x = map(int, input().split())

trapezoid = a * b * a / 2

def trapezoid_v(theta):
  t = math.tan(theta)
  an = a * t
  return b * a * a - a * an * a / 2

def triangle_v(theta):
  t = math.tan(math.pi/2 - theta)
  an = b * t
  return an * b * a / 2

def bin_s(l, u):
  theta = (l + u) / 2

  t = math.tan(theta)
  an = a * t
  if an < b:
    volume_func = trapezoid_v
  else:
    volume_func = triangle_v

  v = volume_func(theta)

  if abs(v-x) < 10**(-6):
    return theta
  elif v > x:
    return bin_s((l+u)/2, u)
  elif v < x:
    return bin_s(l, (l+u)/2)
  else:
    return theta
print(math.degrees(bin_s(0, math.pi/2)))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n;
    cin >> n;
    
    LL m = 0;
    bool ok = false;
    while(m*(m+1)/2 <= n && !ok){
        m++;
        if(m*(m+1)/2 == n){
            ok = true;
        }
    }

    if(!ok){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    cout << m+1 << endl;

    vector<vector<LL>> triangle(m,vector<LL>(m));
    LL state = 1;
    cout << m;
    for(int i = 0; i < m; i++){
        for(int j = 0; j <= i; j++){
            triangle[i][j] = state;
            if(i == j){
                cout << " " << state;
            }
            state++;
        }
    }
    cout << endl;

    for(int i = 0; i < m; i++){
        cout << m;
        for(int j = 0; j <= i ; j++){
            cout << " " << triangle[i][j];
        }
        for(int j = i+1; j < m; j++){
            cout << " " << triangle[j][i];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2944
n, k = gets.split.map(&:to_i)
ws = n.times.map{ gets.to_i }

def check(ws, p, k, n)
  # 最大積載量pのk台のトラックにwsを詰めるか.
  # @return 詰めた荷物の数
  #
  i = 0 # 荷物のindex
  k.times do # k台のトラックに順に積んでいく
    s = 0
    while i != n && s + ws[i] <= p
      s += ws[i]
      i += 1
    end
  end
  return i
end

# PのMax: トラック数の最大値*1つの重さの最大値
left, right = 0, 100000 * 10000
#while left < right
while (right - left) > 1 # <- TODO: なんで??
  mid = (left + right) / 2
  num_w = check(ws, mid, k, n)
  if num_w >= n # nを超えた値が返ってくることはない
    right = mid
  else
    left = mid
  end
end
p right


Measured memory_bytes: 7784
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
const int MaxN=300010;
int N,p[MaxN],q[MaxN];
bool vis[MaxN];
bool calc(){
	int cnt[2]={0},mx[2]={-1,-1},mn[2]={0,0};
	for(int i=0;i<N;i++){
		if(q[i]%2!=i%2)return 0;
		int j=q[i]/2;
		while(vis[mn[i&1]*2+i%2])mn[i&1]++;
		if(j!=mn[i&1]){
			if(mx[i+1&1]>=cnt[i+1&1])return 0;
			if(j<mx[i&1])return 0;
		}
		vis[j*2+i%2]=1;
		if(j>mx[i&1])mx[i&1]=j;
		cnt[i&1]++;
	}
	return 1;
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",p+i),q[--p[i]]=i;
	puts(calc()?"Yes":"No");
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	ll n,i;
	cin>>n;
	ll a[n+2],dp[n+2];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++)
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	cout<<dp[n-1]<<nl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define f(x) ((a*x/b)-a*(x/b))
ll INF=1000000000000000001;
ll mod=1000000007;
 
ll i,j,k;

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

    vector<int> ans(n,0);

    for(i=0;i<k;i++){
        int d;
        cin>>d;
        for(j=0;j<d;j++){
            int a;
            cin>>a;a--;
            ans[a]++;
        }
    }

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

    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 3600