akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        k: usize,
    }
    // annotate for rust-analyzer
    let k: usize = k;

    let mut v = vec![0; k];
    v[0] = 7 % k;
    for i in 1..k {
        v[i] = (v[i - 1] * 10 + 7) % k;
    }
    let mut ans = -1i32;
    for i in 0..k {
        if v[i] == 0 {
            ans = i as i32 + 1;
            break;
        }
    }

    println!("{}", ans);
}


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

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    ll ans = 0;
    ans += A * (N / (A+B));
    ll rem = N - (A+B) * (N / (A+B));
    if(rem>=A) ans += A;
    else ans += rem;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) throws Exception {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			long[] card = new long[n+2];
			for(int i=1; i<=n+1; i++) {
				card[i] = 0;
			}
			for(int i=0; i<m; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				card[a]++;
				card[b+1]--;
			}
			long count = 0;
			int ans = 0;
			for(int i=1; i<=n; i++) {
				count += card[i];
				if(count == m) {
					ans ++;
				}
			}
			System.out.println(ans);
		}
	}

}

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

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main() {
  fast();
  string s, t;
  cin >> s >> t;
  // simulate
  int x = 0;
  while (x < s.length()) {
    s = s.substr(1) + s[0];
    if (s == t) {
      cout << "Yes";
      return 0;
    }
    ++x;
  }
  cout << "No";
  return 0;
}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll MAXSIZE = 3234566667;
vector<ll> ans;
vector<ll> vec = {-1,0,1};
void emb(ll k){
  if(k <= MAXSIZE){
    //cout << k << endl;
    ans.push_back(k);
    ll tmp = k % 10;
    rep(i,3){
      ll num = tmp + vec[i];
      if(0 <= num && num <= 9){
        emb(k*10+num);
      }
    }
  }
}
int main(){
  ll n;
  cin >> n;
  rep(i,9){
    emb(i+1);
  }
  sort(all(ans));
  cout << ans[n-1];
}

Measured memory_bytes: 1400
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (n, m) = (xs[0], xs[1]);
  let hs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let mut es: Vec<Vec<usize>> = vec![vec![]; n];
  for _ in 0..m {
    let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
    let (a, b) = (xs[0] - 1, xs[1] - 1);
    es[a].push(b);
    es[b].push(a);
  }
  let mut count: usize = 0;
  for i in 0..n {
    let h = hs[i];
    let mut b = true;
    for j in &es[i] {
      if h <= hs[*j] {
        b = false;
      }
    }
    if b {
      count += 1;
    }
  }
  println!("{}", count);
}

Measured memory_bytes: 8552
#include<stdio.h>
#include<math.h>

int main()
{

  int n,a[10000],i,judge,j,sosu=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%d",&a[i]);
    judge = 1;
    
    if(a[i] % 2 == 0) judge = 0;
     
    else {  
      for(j=3;j <=sqrt(a[i]);j+=2)
	{
	  if(a[i] % j == 0){
	    judge = 0;
	    break;
	  }
	}
    }
      if(judge == 1 || a[i]==2)
	{
	  sosu++;
	}
    
  }
  printf("%d",sosu);
  printf("\n");
  return 0;
}
  
 

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  int odd = 0 ;
  int even = 0 ;
  
  rep(i,n){
    int c ;
    cin >> c ;
    if(c%2 == 1)  odd++;
    else          even++;
  }
    
  if(odd%2 == 1 && even >0 )  cout << "NO" ;
  else                        cout << "YES"  ;  


}


Measured memory_bytes: 256
def alds13a
    m = gets.chomp.split(/\s/)#.map{|x| x.to_i}

    n = []
    for i in 0..(m.length-1)
        if m[i] =~ /[0123456789]/
            n.push(m[i])
        else
            b,a = n.pop.to_i, n.pop.to_i
            c = 0
            case m[i]
            when '+'
                c = a + b
            when '-'
                c = a - b
            when '*'
                c = a * b
            end
            n.push(c)
        end
    end

    puts n.pop
end

alds13a


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 53;

int n;
LL a[MAXN];
LL nd[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	cin >> n;
	lpi ( i, 1, n ) cin >> a[i];
}

void work ()
{
	// main work

	LL k = 0;
	LL nc = 0;
	bool flag;
	while ( 1 ){
		flag = true;
		lpi ( i, 1, n ) if ( a[i] >= n ) { flag = false; break; }

		if ( flag ) break;

		nc = 0;
		lpi ( i, 1, n ){
			nd[i] = a[i] / n;
			a[i] %= n;
			nc += nd[i];
			k += nd[i];
		}

		lpi ( i, 1, n ) a[i] += nc - nd[i];
	}

	cout << k << endl;
}

Measured memory_bytes: 256
using System;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var C = Console.ReadLine();
            var countR = 0;
            foreach (char c in C)
            {
                if (c == 'R') countR++;
            }
            var subC = C.Substring(0, countR);
            var countR2 = 0;
            foreach (char c2 in subC)
            {
                if (c2 == 'R') countR2++;
            }
            Console.WriteLine(countR - countR2);
        }
    }
}


Measured memory_bytes: 28552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MAX = 100005;
vector<int> to[MAX];
vector<int> ans(MAX, -1);
int main() {
    int n, m; cin >> n >> m;
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--, b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<int> q;
    q.push(0);
    int cnt = 1;
    while (!q.empty()) {
        int cur = q.front(); q.pop();
        for (int v : to[cur]) {
            if (ans[v] != -1 || v==0) continue;
            ans[v] = cur;
            q.push(v);
            cnt++;
        }
    }
    bool ok = true;
    if (cnt != n) ok = false;
    if(ok) {
        cout << "Yes" << endl;
        rep (i, n-1) {
            cout << ans[i+1] + 1<< endl;
        }
    }
    else cout << "No" << endl;
}


Measured memory_bytes: 10340
#include<cstdio>

/* 配列の要素を順番に出力 */
void trace(int A[], int N) {
  int i;
  for ( i = 0; i < N; i++ ) {
    if ( i > 0 ) printf(" ");  /* 隣接する要素の間に１つの空白を出力 */
    printf("%d", A[i]);
  }
  printf("\n");
}

/* 挿入ソート（0オリジン配列） */
void insertionSort(int A[], int N) {
  int i, v, j;
  for ( i = 1; i < N; i++) {
    v = A[i];
    j = i - 1;
    while ( j >= 0 && A[j] > v ) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A, N);
  }
}

int main() {
  int N, i, j;
  int A[100];

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

  trace(A, N);
  insertionSort(A, N);

  return 0;
}


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

int main()
{

	double time5, time10;

	while( cin >> time5 >> time10 ) {

		if( time5 < 35.50 && time10 < 71.00 ) cout << "AAA";
		else if( time5 < 37.50 && time10 < 77.00 ) cout << "AA";
		else if( time5 < 40.00 && time10 < 83.00 ) cout << "A";
		else if( time5 < 43.00 && time10 < 89.00 ) cout << "B";
		else if( time5 < 50.00 && time10 < 105.00 ) cout << "C";
		else if( time5 < 55.00 && time10 < 116.00 ) cout << "D";
		else if( time5 < 70.00 && time10 < 148.00 ) cout << "E";
		else cout << "NA";

		cout << endl;

	}

	return 0;

}

Measured memory_bytes: 1220
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;



int main(void){
	ll x,y,t=0;
	bool is_x=true,first=true,x_can=false,y_can=false;
	string s;
	vector<ll> X,Y;
	set<ll> S;
	queue<ll> Q;
	cin>>s;
	scanf("%lld%lld",&x,&y);
	rep(i,s.size()){
		if(s[i]=='F')t++;
		if(s[i]=='T'){
			if(first){
				x-=t;
				is_x=false;
				first=false;
			}else if(is_x){
				X.push_back(t);
				is_x=false;
			}else{
				Y.push_back(t);
				is_x=true;
			}
			t=0;
		}
	}
	if(first){
		x-=t;
		is_x=false;
		first=false;
	}else if(is_x){
		X.push_back(t);
		is_x=false;
	}else{
		Y.push_back(t);
		is_x=true;
	}
	//x方向が可能かどうか
	int a[16010]={},b[16010]={};
	a[s.size()]++;//0番目は0にいるということにする
	rep(i,X.size()){
		reg(j,0,2*s.size()+1){
			if(a[j]!=0){
				if(j+X[i]<=2*s.size()+1)b[j+X[i]]++;
				if(j-X[i]>=0)b[j-X[i]]++;
			}
		}
		reg(j,0,2*s.size()+1){
			a[j]=b[j];
			b[j]=0;
		}
	}
	if(a[s.size()+x]!=0)x_can=true;

	//y方向が可能かどうか
	reg(j,0,2*s.size()+1){
		a[j]=0;
		b[j]=0;
	}
	a[s.size()]++;//0番目は0にいるということにする
	rep(i,Y.size()){
		reg(j,0,2*s.size()+1){
			if(a[j]!=0){
				if(j+Y[i]<=2*s.size()+1)b[j+Y[i]]++;
				if(j-Y[i]>=0)b[j-Y[i]]++;
			}
		}
		reg(j,0,2*s.size()+1){
			a[j]=b[j];
			b[j]=0;
		}
	}
	if(a[s.size()+y]!=0)y_can=true;

	if(x_can && y_can){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 512
///
// File:  1600.cpp
// Author: ymiyamoto
//
// Created on Fri Nov 10 22:43:01 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  while (true) {
    uint32_t m, n_min, n_max;
    cin >> m >> n_min >> n_max;
    if (m == 0) break;

    vector<uint32_t> points;
    for (uint32_t i = 0; i < m; i++) {
      uint32_t P;
      cin >> P;
      points.push_back(P);
    }

    uint32_t max_gap = 0;
    uint32_t n = 0;
    for (uint32_t i = n_min; i <= n_max; i++) {
      uint32_t pass_point = points[i - 1];
      uint32_t fail_point = points[i];
      uint32_t gap = pass_point - fail_point;
      if (max_gap <= gap) {
        max_gap = gap;
        n = i;
      }
    }

    cout << n << endl;
  }

  return 0;
}

Measured memory_bytes: 3092
S = input()

n = S.count('N')
s = S.count('S')
w = S.count('W')
e = S.count('E')

if n * s > 0 and w * e > 0:
    print('Yes')
elif n * s > 0 and w == 0 and e == 0:
    print('Yes')
elif w * e > 0 and n == 0 and s == 0:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
int r[2];
vector<int> V[2][MC];
int p[MC][2];
int X[MC];

int dfs(int t , int q){
	int z = 0;
	for(auto u : V[t][q]){
		int y = dfs(t,u);
		if(z){
			p[y][t] = z;
			p[z][t] = y;
			z = 0;
		} else {
			z = y;
		}
	}
	return z ? z : q;
}

int main(){
	scanf("%d" , &N);
	repp(t,0,2){
		repp(i,1,N+1){
			int A;
			scanf("%d" , &A);
			if(A<0) r[t] = i;
			else V[t][A].PB(i);
		}
	}
	repp(i,1,N+1){
		if((V[0][i].size() - V[1][i].size()) % 2){
			printf("IMPOSSIBLE\n");
			return 0;
		}
	}
	printf("POSSIBLE\n");
	dfs(0,r[0]);
	dfs(1,r[1]);
	repp(i,1,N+1){
		if(V[0][i].size()%2){
			printf("0%c" , i==N ? '\n' : ' ');
			continue;
		}
		if(X[i]==0){
			repp(k,0,2){
				int q = i;
				int t = k;
				X[i] = 1;
				while(p[q][t] > 0 && X[p[q][t]] == 0){
					X[p[q][t]] = -X[q];
					q = p[q][t];
					t = 1-t;
				}
			}
		}
		printf("%d%c" , X[i] , i==N ? '\n' : ' ');
	}
	return 0;
}


Measured memory_bytes: 11520
import numpy as np

n,k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

dp = np.array([0] * n)

for i in range(1,n):
    s = max(i-k,0)
    dp[i] = min(dp[s : i] + abs(h[i] - h[s:i]))

print(dp[n-1])

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

#define N 200123
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, m, sum = 0, a[1000], cnt = 0;
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++){
    	cin >> a[i];
    	sum += a[i];
    }

    for(int i = 0 ; i < n ; i++){
    	if(a[i]*4*m >= sum) cnt++;
    }
    if(cnt >= m) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pdd;

int main() {
    ll n,k;cin>>n>>k;
    vector<ll> a(n),f(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>f[i];
    Sort(f);Sort(a);Reverse(f);
    vector<Pdd> af(n);
    rep(i,n)  af[i]=Pdd(a[i]*f[i],f[i]);
    ll l=0,r=2e12;
    int cnt=0;
    while(cnt!=100){
        cnt++;
        ll mid=(l+r)/2;
        ll sum=0;
        rep(i,n){
            if(af[i].first>mid){
                sum+=(af[i].first-mid-1)/af[i].second+1;
            }
        }
        if(sum>k){
            l=mid;
        }
        else if(sum<=k){
            r=mid;
        }
    }
    r=max(0ll,r-500ll);
    while(1){
        ll sum=0;
        rep(i,n){
        if(af[i].first>r){
            sum+=(af[i].first-r-1)/af[i].second+1;
            }
        }
        if(sum<=k){cout<<r<<endl;return 0;}
        r++;   
    }
        
    return 0;
}


Measured memory_bytes: 6528
import math
a, b = map(int,input().split())
min = math.floor(a / 0.08)
max = math.ceil((a+1)/0.08)
ans = 0
for i in range(min, max):
    if math.floor(i * 0.08) == a and math.floor(i*0.1) == b:
        ans = i
        break
if ans == 0:
    print("-1")
else:
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 511111
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
char s[MAXNUM];
int bef[MAXNUM];
int main()
{
    scanf("%s",s);
    int ssize=strlen(s);
    int co=0;
    for(int i=ssize-1;i>=0;i--)
    {
        if(s[i]=='>')co++;
        else co=0;
        bef[i]=co;
    }
    ll sum=bef[0];
    int x=bef[0];
    rep(i,0,ssize)
    {
        if(s[i]=='<')x++;
        else x=0;
        x=max(x,bef[i+1]);
        sum+=x;
    }
    printf("%lld\n",sum);
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ptr=0;
    int ptr2 = k;
    while(ptr2<n){
        if(a[ptr]>=a[ptr2])cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
        ptr++;
        ptr2++;
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}

int main(){

	int n,k;
	cin>>n>>k;
	int x[n+1];
	rep(i,n)cin>>x[i];
	x[n]=k;
	sort(x,x+n+1);

	int ans=x[1]-x[0];
	rep(i,n){
		ans=gcd(ans,x[i+1]-x[i]);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
function main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var c = input[0].split(" ")[2]-0;
    console.log(Math.max(a,Math.max(b,c)) - Math.min(a,Math.min(b,c)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y

//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};
ll int n,m,a[200005];
ll bigmod(ll x,ll y,ll m)
{
    if(y==0)return 1;
    ll n=bigmod(x,y/2,m);
    n=(n*n)%m;
    if(y & 1)n=((n%m)*(x%m))%m;
    return n;
}

int main()
{
    ll var;
    sfl(n);
    sfl(k);
    z=0;
    for(i=k;i>=1;i--)
    {
        a[i]=bigmod(k/i,n,MOD);
        for(j=i+i;j<=k;j+=i)
        {
            a[i]-=a[j];a[i]+=MOD;a[i]%=MOD;
        }
        z+=a[i]*i;z%=MOD;
    }
    cout<<z<<endl;
}


Measured memory_bytes: 4432
fun main(args: Array<String>) {
  val (n, k) = readLine()!!.split(" ").map(String::toInt)
  if (k == 0) {
    println(n.toLong() * n.toLong())
    return
  }
  var ans = 0L
  for (b in (k + 1)..n) {
    ans += (b - k).toLong() * (n / b).toLong()
    ans += Math.max((n % b) - (k - 1), 0)
  }
  println(ans)
}


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

int main(void)
{
    int N, K;
    cin >> N >> K;
    vector<int> p(N);

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

    ll maxval = 0;
    ll sum = 0;
    for(int i = 0; i < K; i++){
        sum += 1 + p[i];
    }
    maxval = sum;

    for(int i = 1; i < N - K + 1; i++){
        sum = sum - p[i-1] + p[i+K-1];
        if(sum > maxval) maxval = sum;
    }

    double E = maxval * 0.5;

    cout << std::fixed << std::setprecision(10) << E << endl;
    return 0;
}


Measured memory_bytes: 4040
N, K = map(int, input().split())
h_list = []
min1 = 10**10
for i in range(N):
    h = int(input())
    h_list.append(h)
h_list = sorted(h_list, reverse = True)
for i in range(N-K+1):
    cnt = h_list[i]-h_list[i+K-1]
    min1 = min(min1, cnt)
print(min1)

Measured memory_bytes: 8280
from collections import Counter
def f(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
if n == 1:
    print(1)
    exit()
d = {}
mod = 10**9+7
d[2] = 1
for i in range(3, n+1):
    x = f(i)
    c = Counter(x)
    for j in c.keys():
        if j not in d:
            d[j] = c[j]
        else:
            d[j] += c[j]
        d[j] = d[j] % mod
ans = 1
for i in d.keys():
    ans *= d[i]+1
print(ans%mod)

Measured memory_bytes: 9364
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(long long i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(long long i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1<<30)-10;

const string YES = "Yes";
const string NO = "No";
void yn(bool ok){
  cout << (ok ? YES : NO) << endl;
}

void solve(std::string S){
  yn(!(S=="AAA" || S=="BBB"));
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


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

int main() {
  int a,b;

  while(true){
  cin>>a>>b;
    if(a==0 &&b==0)break;
    else if(b%2==0){
      for(int j=0;j<a;j++){
	if(j%2==0)for(int i=0;i<b/2;i++){
	    cout <<"#.";
          }
        else for(int i=0;i<b/2;i++){
	    cout <<".#";
          }
	cout <<endl;
      }
      cout<<endl;
    }  
    else if(b%2==1){
      for(int j=0;j<a;j++){
	if(j%2==0){for(int i=0;i<b/2;i++){
	    cout <<"#.";
		}
	  cout<<"#";}
        else{ for(int i=0;i<b/2;i++){
	    cout <<".#";
          }
	  cout<<".";	}
	cout <<endl;
      }
      cout <<endl;
    }  
  }
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int l = pow(m,0.5);
  vector<int> a;
  for(int i = 1;i <= l+10;i++){
    if(m % i == 0){
      a.push_back(m/i);
      a.push_back(i);
    }
  }
  sort(a.begin(),a.end());    
  for(int i = a.size()-1;i >= 0;i--){
    if(m % a[i] == 0 && m / a[i] >= n){
      cout << a[i] << endl;
      break;
    }
  }
}


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

using namespace std;

int main(){
	
	int N,M;
	cin>>N>>M;
	vector<int> L(M);
	for(int i=0;i<M;i++){
		L[i]=0;
	}
	int K;
	int A;
	for(int i=0;i<N;i++){
		cin>>K;
		for(int j=0;j<K;j++){
			cin>>A;
			L[A-1]+=1;
		}
	}
	int ans=0;
	for(int i=0;i<M;i++){
		if(L[i]==N){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
h, w = gets.chomp.split(" ").map(&:to_i)
queue = []
turn = Array.new(h * w, 0)
h.times do |i|
  l = gets.chomp
  j = 0
  while (j = l.index("#", j))
    queue << i * w + j
    turn[i * w + j] = 1
    j += 1
  end
end

cnt = 0
while (q = queue.shift)
  cnt = turn[q]
  i, j = q.divmod(w)
  if i > 0 && turn[(idx = (i - 1) * w + j)].zero?
    queue << idx
    turn[idx] = cnt + 1
  end
  if i < h - 1 && turn[(idx = (i + 1) * w + j)].zero?
    queue << idx
    turn[idx] = cnt + 1
  end
  if j > 0 && turn[(idx = i * w + (j - 1))].zero?
    queue << idx
    turn[idx] = cnt + 1
  end
  if j < w - 1 && turn[(idx = i * w + (j + 1))].zero?
    queue << idx
    turn[idx] = cnt + 1
  end
end

puts cnt - 1

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

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

fn main() {
    let n = read::<usize>();
    let mut p = vec![];
    for i in 0..n {
        p.push(read::<i64>());
    }
    let ans = p.iter().sum::<i64>() - p.iter().max().unwrap() / 2;
    println!("{}", ans);
}

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

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


Measured memory_bytes: 4352
S = input()
ATGC = "ATGC"

cnt_ = 0
for i in range(len(S)):
    cnt = 0
    for j in range(i,len(S)):
        if S[j] in ATGC:
            cnt += 1
        else:
            break
    
    if cnt > cnt_:
        cnt_ = cnt

print(cnt_)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      long long int a,b,c,d ;
      cin >> a >> b >> c >> d;
      
      vector<long long int> calc(4);
      calc.at(0)=a*c;
      calc.at(1)=a*d;
      calc.at(2)=b*c;
      calc.at(3)=b*d;
      
      long long int max=calc.at(0);
      
      for(int i=1;i<4;i++){
        if(max<calc.at(i)){
          max=calc.at(i);
        }
      }
      
      cout << max << endl;
      
    }

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int number;
    long long int sum = 0;
    cin >> number;
    for(int i=1; i<=number; i++) {
        if(i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

int main(){
    ll d;
    cin >> d;
    vector<ll> c(26),num(26);
    rep(i,26){
        cin >> c[i];
    }
    vector<vector<ll>> s(d,vector<ll>(26));
    rep(i,d){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    ll ans=0;
    rep(i,d){
        ll t;
        cin >> t;
        t--;
        ans+=s[i][t];
        num[t]=i+1;
        rep(j,26){
            ans-=c[j]*(i+1-num[j]);
        }
        cout << ans << endl;
    }
    return 0;
} 

Measured memory_bytes: 3720
def same(x, y):
    for g in [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]:
        if x in g and y in g:
            return 'Yes'
    return 'No'


if __name__ == '__main__':
    x, y = map(int, input().split())
    print(same(x, y))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
int a[N];

int main()

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

    int n;
    string tmp, s = "keyence";

    cin >> tmp;

    n = tmp.size();

    for (int i = 1; i <= 7; i++) {

        if (tmp.substr(0, i) + tmp.substr(n-(7-i)) == s) {

            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


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

int main() {
  int A;
  string op;
  int B;
  cin >> A >> op >> B;
  if (op == "+") {
    cout << A + B << endl;
  }
  if (op == "-") {
    cout << A - B << endl;
  }
}



Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
                        if(n==0) break;
			for(int i=0;i<n;i++) {
				int[] score = new int[3];
				for(int j=0;j<3;j++) score[j] = sc.nextInt();
				
				if( score[0] == 100 || score[1] == 100 || score[2] == 100 ||
					score[0] + score[1] >= 180 || score[0] + score[1] + score[2] >= 240) {
					System.out.println("A");
				}
				else if( score[0] + score[1] + score[2] >= 210 || 
						 ( score[0] + score[1] + score[2] >= 150 && (score[0] >= 80 || score[1] >= 80) ) ) {
					System.out.println("B");
				}
				else System.out.println("C");
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
N,C,K=map(int,input().split())
T=[int(input()) for i in range(N)]
S=sorted(T)
B=0
first=-1
board=0
for i in range(N):
	if first==-1:
		first=S[i]
		board+=1
		B+=1
	elif board<C and S[i]-first<=K:
		board+=1
	else:
		first=S[i]
		board=1
		B+=1
print(B)

Measured memory_bytes: 8280
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{
	auto line = readln().split(); 
	if (line.length < args.length) return;
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
//------------------------------
const coin = [10,50,100,500];
void main(){	
	int total;
	//read(total);
	//while(total){
	for(read(total);total;read(total),write(total ? "\n":"")){
		auto have = new int[4];
		readArray(have);
		int howMany = int.max; 
		auto uses = new int[4];
		foreach(i0;iota(have[0]+1)){
			foreach(i1;iota(have[1]+1)){
				foreach(i2;iota(have[2]+1)){
					foreach(i3;iota(have[3]+1)){
						auto tmpuses = [i0,i1,i2,i3];
						auto pay = i0 * coin[0] + i1 * coin[1] + i2 * coin[2] + i3 * coin[3];	
						if (pay < total) continue;
						int tmpHowMany = have.sum + howManyCoins(pay - total) - tmpuses.sum;
						if (tmpHowMany < howMany ){
							howMany = tmpHowMany;
							uses = tmpuses;
						}
					}
				}
			}
		}
		foreach(i,u;uses){if(u >0)writeln(coin[i]," ",u);}
//		read(total);
//		if (total) writeln();
	}
}
int howManyCoins(int pay){
	int res;
	foreach_reverse(c;coin){
		while(pay >= c){ 
			pay -= c;res ++;
		}
	} 
	return res;
}

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

void fst()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define binary(n) cout << bitset<31>(n) << "\n";
#define FOR(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define input_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define print_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cout << a[i] << " ";
#define deb(n) cerr << #n << "=" << n << "\n";
#define int long long
int32_t main()
{

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(all(a), greater<int>());
    ll ans = a[0];
    int i = 1;
    for (int it = 1; it < n - 1; it += 2)
    {

        ans += 2 * a[i];
        if(it==n-2){
            ans-=a[i];
        }
        i++;
    }
    cout << ans;
}


Measured memory_bytes: 4840
#include <stdio.h>
#include <string.h>

int main (){
	int k;
	char str[105];
	
	scanf("%d", &k);
//	getchar();
	scanf("%s", &str);
	
	
	int len = strlen(str);
	if (len <= k) {
		printf("%s\n",str);
	}
	else {
		for (int i = 0; i <k; i++) {
			printf("%c", str [i]);
		}
		puts ("...");
	}
	return 0;
}


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

using namespace std;


int main() {
  int H, W;
  cin >> H >> W;
  string S[100];
  for(int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for(int i = 0; i < W + 2; i++) putchar('#');
  puts("");

  for(int i = 0; i < H; i++) {
    putchar('#');
    cout << S[i];
    puts("#");
  }

  for(int i = 0; i < W + 2; i++) putchar('#');
  puts("");

}




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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 100010;
char str[N];

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  scanf("%s", str);
  int len = strlen(str), cnt0, cnt1;
  cnt0 = cnt1 = 0;
  for (int i = 0; i < len; ++i)
    if (str[i] == '0') ++cnt0;
    else ++cnt1;
  
  cout << 2 * min(cnt0, cnt1);
  return 0;
}


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

void testcase(){
    ll x,k,d;
    cin >> x >> k >> d;
    if(x<0) x*=-1;
    if(k>=x/d){
    k-= x/d;
    x%=d;
    if(k%2==0)
        cout << x;
    else
        cout << d-x;
    }
    else{
        cout << x-k*d;
    }

}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int q=1;
  //  cin >> q;
    while(q--){
    testcase();
    }
    return 0;
}



Measured memory_bytes: 3684
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 2e5 + 2;
 
vector <int> adj[MAXN];
long long dp[MAXN];
 
void dfs(int node, int parent){
	if(parent != -1){
		dp[node] += dp[parent];
	}
	for(int i : adj[node]){
		if(i == parent)continue;
		dfs(i, node);
	}
}
 
int main(){
	#ifdef EVAL
		freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif
	int N, Q;
	cin >> N >> Q;
	for(int i = 1, a, b; i < N; i++){
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(int i = 0; i < Q; i++){
		int node;
		long long value;
		cin >> node >> value;
		dp[node] += value;
	}
	dfs(1, -1);
	for(int i = 1; i <= N; i++){
		cout << dp[i] << " ";
	}
	return 0;
}

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

int main() {
  string o, e;
  cin >> o >> e;
  int size = o.size() + e.size();

  string res = "";
  int i      = 0;
  int O = 0, E = 0;
  while (i < size) {
    if (i % 2 == 0) {
      res += o[O];
      O++;
    } else {
      res += e[E];
      E++;
    }
    i++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int N;
    scanf("%d",&N);
    int a[N],i,ans=0;
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
        ans += ( a[i] - 1 );
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <limits.h>
#define N 2000000



int A[N],heap=0;

main()
{
  
  
  int a;
  char s[30];
  
 
  while(1){
    scanf("%s",s);
    if(strcmp(s,"end")==0){
      break;
    }
    
    if(s[0]=='i') {
      scanf("%d",&a);
      maxHeapInsert(a);
    }
    else {
      printf("%d\n",heapExtractMax());
    }
  }
  
  return 0;
  
}

int parent(int a)
{
  return a/2;
}

int left(int a)
{
  return 2*a;
}

int right(int a)
{
  return 2*a + 1;
}

int maxHeapify(int i)
{
  
  int l = left(i),r = right(i); 
  int largest;
  int tmp;
  
  
  if(l <= heap && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }
  
  if(r <= heap && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int heapExtractMax()
{

  int max;

    if(heap < 1){
    return 0;
    }

  max = A[1];
  A[1] = A[heap];
  heap--;
  maxHeapify(1);
  return max;
}

void heapIncreaseKey(int i, int key)
{
  int tmp;
  
  if(key < A[i]){
    return;
  }
  
  A[i] = key;
  while(i > 1 && A[parent(i)] < A[i]){
    tmp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = tmp;
    i = parent(i);
   
  }
 
}

int maxHeapInsert(int key)
{
  
  heap++;
  A[heap] = INT_MIN;
  heapIncreaseKey(heap,key);
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

long long dp[110][10010];

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

    int n,w;
    cin>>n>>w;
    vector<pair<int,int>> v(n);
    for(int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
    int sumv=0;
    for(int i=0;i<n;i++)sumv+=v[i].first;
    for(int i=1;i<=sumv;i++)dp[0][i]=INF;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=sumv;j++){
            if(j-v[i-1].first>=0)dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1].first]+v[i-1].second);
            else dp[i][j]=dp[i-1][j];
        }
    }
    int ans=0;
    for(int i=0;i<=sumv;i++)if(dp[n][i]<=w)ans=i;
    cout<<ans<<endl;

}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in(), m = in();
    vector<vector<bool>> v(m, vector<bool>(n, false));
    rep(i, m)
    {
        int k = in();
        rep(j, k)
        {
            int s = in();
            --s;
            v[i][s] = true;
        }
    }
    vint p = in(m);

    int ans = 0;
    rep(bit, (1 << n))
    {
        bool ok = true;
        rep(i, m)
        {
            int cnt = 0;
            rep(j, n)
            {
                if ((bit & (1 << j)) && v[i][j])
                {
                    ++cnt;
                }
            }

            if (cnt % 2 != p[i])
                ok = false;
        }
        if (ok)
            ++ans;
    }
    cout << ans << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

long long N;

//             p     , pos
vector<pair<long long, long long> >P;

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		long long p;
		cin >> p;
		P.push_back(make_pair(p, i));
	}
	sort(P.begin(), P.end(), greater<pair<long long, long long> >());
	//for(long long i = 0; i < P.size(); i++){
	//	cout << P[i].first << ", " << P[i].second << endl;
	//}

	long long ans = 0;
	set<long long> bigger_pos;
	for(long long i = 0; i < P.size(); i++){
		long long val = P[i].first;
		long long pos = P[i].second;
		auto rit = bigger_pos.lower_bound(pos);
		auto lit = bigger_pos.lower_bound(pos);

		// left2, left1, cur, right1, righ2
		long long left1 = -1;
		long long left2 = -1;
		long long right1 = N;
		long long right2 = N;

		if(rit != bigger_pos.end()){
			right1 = *rit;
			rit++;
			if((rit) != bigger_pos.end()){
				right2 = *(rit);
			}
		}

		if(lit != bigger_pos.begin()){
			lit--;
			left1 = *(lit);
			if((lit) != bigger_pos.begin()){
				lit--;
				left2 = *(lit);
			}
		}


		long long tmp = 0;
		//左の大きいのを取る
		if(left1 != -1){
			//左はleft2 + 1 から left1, 右はpos から right1 - 1まで
			tmp += val * (left1 - (left2 + 1) + 1) * (right1 - 1 - pos + 1);
		}

		//右の大きいのを取る
		if(right1 != N){
			//左はleft1 + 1 から pos, 右はright1 から right2 - 1まで
			tmp += val * (pos - (left1 + 1) + 1) * (right2 - 1 - right1 + 1);
		}
		ans += tmp;

		//cout << "cur " << P[i].first << endl;
		//cout << " add " << tmp << endl;
		//cout << "l1 " << left1 << " l2 " << left2 << " r1 " << right1 << " r2 " << right2 << endl;

		bigger_pos.insert(pos);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
using namespace std;
int a[3][3];
int main() {
	for(int i=0;i<3;i++)
		for (int j = 0; j < 3; j++)
		{
			cin >> a[i][j];
		}
	int n;
	cin >> n;
	while (n--) {
		int t;
		cin >> t;
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				if (a[i][j] == t)
					a[i][j] = -1;
	}
	for (int i = 0; i < 3; i++)
	{
		int flag = 1;
		for (int j = 0; j < 3; j++)
			if (a[i][j] != -1)
				flag = 0;
		if (flag) {
			cout << "Yes";
			return 0;
		}
	}
	for (int i = 0; i < 3; i++)
	{
		int flag = 1;
		for (int j = 0; j < 3; j++)
			if (a[j][i] != -1)
				flag = 0;
		if (flag) {
			cout << "Yes";
			return 0;
		}
	}
	int flag = 1;
	for (int i = 0; i < 3; i++)
		if (a[i][i] != -1)
			flag = 0;
	if (flag) {
		cout << "Yes"; return 0;
	}
	flag = 1;
	for (int i = 0; i < 3; i++)
		if (a[i][2 - i] != -1)
			flag = 0;
	if (flag) {
		cout << "Yes"; return 0;
	}
	cout << "No";
}

Measured memory_bytes: 256
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200005;
const int MOD =1000000007;

signed main(){
  int x;
  cin>>x;
  if(x==0)cout<<1<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 3628