akhauriyash/Code-Regression huggingface dataset:
// AtCoder Regular Contest 067
// E - Grouping

#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX_N 1000
#define MOD ((ll)1e9 + 7)
using namespace std;
typedef long long int ll;


ll extgcd(ll a, ll b, ll& x, ll& y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1; y = 0;
  }
  return d;
}

ll inv(ll a, ll m) {
  ll x, y;
  extgcd(a, m, x, y);
  return (m + x) % m;
}


int N, A, B, C, D;
ll fac[MAX_N + 1];
ll inv_fac[MAX_N + 1];
ll dp[MAX_N + 1][MAX_N + 1];
ll ans;

int main() {

  int max_k;
  ll tmp, inv_fac_i_pow_k;

  scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);

  fac[0] = 1;
  inv_fac[0] = inv(fac[0], MOD);
  for (int i = 1; i <= N; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= MOD;
    inv_fac[i] = inv(fac[i], MOD);
  }

  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      inv_fac_i_pow_k = 1;
      dp[i][j] = 0;
      max_k = (A <= i && i <= B) ? min(D, j / i) : 0;
      for (int k = 0; k <= max_k; k++) {
        if (k == 0 || C <= k) {
          tmp = dp[i - 1][j - i * k];
          tmp *= fac[N - j + i * k]; tmp %= MOD;
          tmp *= inv_fac[N - j]; tmp %= MOD;
          tmp *= inv_fac_i_pow_k; tmp %= MOD;
          tmp *= inv_fac[k]; tmp %= MOD;
          dp[i][j] += tmp; dp[i][j] %= MOD;
        }
        inv_fac_i_pow_k *= inv_fac[i];
        inv_fac_i_pow_k %= MOD;
      }
    }
  }

  ans = (dp[B][N] - dp[A - 1][N] + MOD) % MOD;
  printf("%lld\n", ans);

  return 0;

}




Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 1e5;

int main()
{
  int k, x;
  cin >> k >> x;
  for(int i = max(-N, x - k + 1); i <= min(N, x + k - 1) ; i++)
    cout << i << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
	string s;
	cin >> s;
	if(s[0]=='S'){
		cout << "Cloudy" << endl; 
	}else if(s[0]=='C'){
		cout << "Rainy" << endl;
	}else{
		cout << "Sunny" << endl;
	}
}

Measured memory_bytes: 256
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	ビットマスクを用いた解法
	"""
	s = input()
	ans = 0
	for b in range(1 << len(s) - 1):
		x = ""
		for index, num in enumerate(s):
			x += num
			if index != len(s) - 1 and b >> index & 1: x += "+"
		ans += eval(x)
	print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 14424
import java.util.*;
public class Main{
      	public static void main(String[] a)throws java.io.IOException{
    		Scanner scan=new Scanner(System.in);
    		while(true){
    			int n= scan.nextInt();
    			if(n==0)break;
    			int [] s = new int[n];
    			int [] c = new int[n];
    			int max=0;
    			for(int i=0;i<n;i++){
    				s[i]=scan.nextInt();
    				max=Math.max(s[i], max);
    			}
    			int count=0;
    			while(!Arrays.equals(s, c)){
    				int [] f = new int[max+1];
    				max=0;
    				for(int i=0;i<n;i++){
    					f[s[i]]++;
    					c[i]=s[i];
    				}
    				for(int i=0;i<n;i++){
    					s[i]=f[s[i]];
    					max=Math.max(s[i], max);
    				}
    				count++;
    			}
    			StringBuilder ans = new StringBuilder();
    			for(int i=0;i<n;i++){
    				ans.append(c[i]);
    				if(i!=n-1)ans.append(" ");
    			}
    			System.out.println(count-1);
    			System.out.println(ans.toString());
    		}
    	}
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m; cin >> n >> m;
  string s; cin >> s;
  vvi g(n);
  REP(i, m) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<bool> ok(n, true);
  set<int> st;
  REP(i, n) {
    st.insert(i);
  }
  bool upd = true;
  while(upd) {
    upd = false;
    set<int> nxtst;
    set<int> diff;
    for(auto &i: st) {
      if(!ok[i]) continue;
      bool a = false, b = false;
      REP(j, SZ(g[i])) {
        int to = g[i][j];
        if(ok[to]) {
          a |= s[to] == 'A';
          b |= s[to] == 'B';
        }
      }
      if(!a || !b) {
        diff.insert(i);
        ok[i] = false;
        upd = true;
      }
    }
    for(auto &e: diff) {
      REP(j, SZ(g[e])) {
        int to = g[e][j];
        if(ok[to]) nxtst.insert(to);
      }
    }
    st = nxtst;
  }

  bool ans = false;
  REP(i, n) {
    ans |= ok[i];
  }
  cout << (ans ? "Yes" : "No") << endl;
}
























Measured memory_bytes: 27472
using System;
class Ho{
  static void Main(){
    var b = Console.ReadLine().Split();
    var W = double.Parse(b[0]);
    var H = double.Parse(b[1]);
    var x = double.Parse(b[2]);
    var y = double.Parse(b[3]);
    double kotae = W*H/2;
   
    
    
    if(2*x == W&&2*y == H){
      Console.WriteLine(kotae+" "+"1");
    }
    else{
        Console.WriteLine(kotae+" "+"0");
    }
    
     
      
  }
}

Measured memory_bytes: 11220
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

bool same[100005];
int main() {
	int n;
	cin >> n;
	int a;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		if (a == i)same[i] = true;
	}
	for (int i = 1; i <= n; i++) {
		if (i!=n&&same[i] && same[i + 1]) {
			same[i] = false;
			same[i + 1] = false;
			ans++;
		}
		else if (same[i]) {
			same[i] = false;
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
long long int dp[100030] = {};
int main() {
	int n;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		dp[i] = i;
	}
	for (int i = 6; i <= n; i = i * 6) {
		for (int j = 0; j <= n; j++) {
			if(j-i < 0){
				continue;
			}
			dp[j] = min(dp[j], dp[j - i] + 1);
		}
	}
	for (int i = 9; i <= n; i = i * 9) {
		for (int j = 0; j <= n; j++) {
			if (j - i < 0) {
				continue;
			}
			dp[j] = min(dp[j], dp[j - i] + 1);
		}
	}
	cout << dp[n];
}

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

struct node{  
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};


typedef struct node Node;
//typedef struct tree Tree;

void insert(Node**,int);
void preorder(Node*);
void inorder(Node*);
Node* find(int,Node*);

Node *NIL;

  
int main(){

  int n,i,num;
  char order[7];
  Node *root;
  //Tree tree;
  Node *finder;

  root=NIL;

  //root=(Node*)malloc(sizeof(Node));

  //NIL->right=NULL;
  //printf("wa-i30\n");Node* find(int num,Node** u){

  //NIL->left=NULL;
  //NIL->parent=NULL;
  //NIL->key=-1;

  //printf("wa-i20\n");
  
  // tree.root=NIL;
 
  scanf("%d",&n);

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

    scanf("%s %d",order,&num);
    
    //printf("%s\n",order);

    // root->key=3;

    if(strcmp(order,"insert")==0){
      
      //printf("wa-i\n");
      //printf("%d\n",root->key);
      insert(&root,num);
      //printf("Main : address of root;%p\n",root);
      //printf("%d\n",root->key);

    }
    
    else if(strcmp(order,"print")==0){
      //printf("%d\n",root->key);

      // printf("wa-i50\n");
      
      inorder(root);
      
      printf("\n");
	     
      preorder(root);

      printf("\n");

    }
    else if(strcmp(order,"find")==0){

      finder=find(num,root);
      // printf("wa-i30\n");
      
      if(finder!=NIL) printf("yes\n");
      else printf("no\n");
      
      
    }
  }

  return 0;
}

void insert(Node** root,int num){

  Node *x,*y,*z;

  y=NIL;
  x=*root;

  //printf("address of root;%p\n",root);

  z=(Node*)malloc(sizeof(Node));

  z->left=NIL;
  z->right=NIL;
  z->key=num;

  //printf("%d\n",z->key);  

  while(x!=NIL){
    y=x;
    if( z->key < x->key )x=x->left;
    else x=x->right;
    //printf("wa-i200\n");
  }
    
  z->parent=y;
  
  if(y==NIL){
    *root=z;
    //printf("wa-i100\n");
  }
  else if( z->key < y->key ) y->left=z;
  else y->right=z;

  //printf("%d\n",(*root)->key);
  //printf("%d\n",z->key);
  // printf("address of root;%p\n",root);
  
}

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

void inorder(Node *u){

  if(u==NIL) return;
  
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}

Node* find(int num,Node* u){

  while(u!=NIL&&num!=u->key){

    if(num< u->key ) u= u->left;
    else u=u->right;
  }
  // printf("wa-i20\n");
  return u;

}

	       












  

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

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

  int d=0, g=0;

  for(int i=0; i<N; i++){
    if(S[i] == 'a' && d+g < A+B){
      cout << "Yes" << endl;
      d++;
    }else if (S[i] == 'b' && d+g < A+B && g < B){
      cout << "Yes" << endl;
      g++;
    }
    else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <queue>
#include <vector>

int main() {
  int N;
  std::cin>>N;
  std::vector<std::deque<int>> dq(N);
  std::deque<int> cur;
  for (int i=0;i<N;++i) {
    for (int j=0;j<N-1;++j) {
      int a;
      scanf("%d", &a);
      --a;
      dq[i].push_back(a);
      cur.push_back(i);
    }
  }
  int res=N*(N-1)/2;
  int ans=0;
  while (res>0) {
    ++ans;
    bool upd=false;
    std::vector<bool> used(N, false);
    std::deque<int> next;
    while (!cur.empty()) {
      int i=cur.front(); cur.pop_front();
      if (dq[i].empty()||used[i]) continue;
      if (dq[dq[i].front()].empty()||used[dq[i].front()]) continue;
      if (dq[dq[i].front()].front()==i) {
	int s=i;
	int t=dq[i].front();
	used[s]=true;
	used[t]=true;
	dq[s].pop_front();
	dq[t].pop_front();
	upd=true;
	--res;
	next.push_back(s);
	next.push_back(t);
      }
    }
    cur=next;
    if (res>0&&!upd) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  std::cout<<ans<<std::endl;
  return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int d = 0;
  bool f = false;
  rep(i,n){
    int t;
    cin >> t;
    if(i+1==t){
      if(f){

        f = false;
      }else{
        f = true;
        d++;
      }
    }else{
      f = false;
    }
  }
  cout << d << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1e18+9999999;
ll pow(ll x,ll y){
  ll res=1;
  for(int i=0;i<y;i++) res*=x;
  return res;
}
int main(){
  ll n;
  cin>>n;
  if(n%2==1){
    cout<<0<<endl;
    return 0;
  }
  ll ans=0;
  for(int i=1;pow(5,i)<inf;i++){
    ll k=pow(5,i)*2;
    ans+=n/k;
  }
  cout<<ans<<endl;
}


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

int main()
{
  int n, k;
  cin >> n >> k;
  
  vector<int> v;
  
  for (int i=0; i<n; ++i){
    int x;
    cin >> x;
    v.push_back(x);
  }

  std::sort(v.begin(), v.end());
  int sum = 0;
  for (int i=0; i<k; ++i){
    sum += v[i];
  }

  cout << sum << endl;   
  return 0;
}


Measured memory_bytes: 3168
inp1 = list(map(int, input().split()))
n = inp1[0]
m = inp1[1]

inp2 = list(map(int, input().split()))
sum2 = sum(inp2)
ans =  n - sum2
if (n - sum2) >= 0:
  print(n - sum2)
else:
  print("-1")

Measured memory_bytes: 9876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll MOD2=1e9+9;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

map<string,ll> m;
ll n,ans;
string s;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);	
	cin>>n;
	REP(i,n){
		cin>>s;
		sort(s.begin(),s.end());
		ans+=m[s];
		m[s]++;
	}
	cout<<ans<<"\n";
	return 0;
}




Measured memory_bytes: 11264
#[derive(Debug)]
struct BIT<T> {
    table: Vec<T>,
}
impl<T: std::default::Default + Clone + Copy + std::ops::AddAssign> BIT<T> {
    fn new(n: usize) -> BIT<T> {
        BIT {
            table: vec![T::default(); n + 1],
        }
    }
    // 1..i番目の要素までの和を求める
    fn sum(&self, mut i: usize) -> T {
        let mut sum: T = T::default();
        while i != 0 {
            sum += self.table[i];
            i &= i - 1;
        }
        sum
    }

    fn add(&mut self, mut i: usize, x: T) {
        if i == 0 {
            panic!("0 is given to BIT");
        }
        while (i as usize) < self.table.len() {
            self.table[i as usize] += x;
            i += i - (i & (i - 1));
        }
    }
}

fn main() {
    let (n, q): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut bit = BIT::<usize>::new(n);
    for _ in 0..q {
        let c: usize = read();
        if c == 0 {
            let (i, x): (usize, usize) = (read::<usize>(), read::<usize>());
            bit.add(i, x);
        } else if c == 1 {
            let (l, r): (usize, usize) = (read::<usize>(), read::<usize>());
            println!("{}", bit.sum(r) - bit.sum(l - 1));
        } else {
            unreachable!();
        }
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

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

// =========



Measured memory_bytes: 5048
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
ll n,a,b;
cin>>n>>a>>b;

if(b<a)
{
	ol("0");
	return 0;
}

if(n==1)
{
	if(a==b)
	{
		ol("1");
	}
	else
	ol("0");
	return 0;
}

ol((n-1)*b+a-(n-1)*a-b+1);

return 0;
}



Measured memory_bytes: 256
S = input().strip()
Q = int(input())
ind = 1
x = []
y = []
for i in range(Q):
    q = list(input().split())
    if len(q)==1:
        ind = ind*(-1)
    else:
        if q[1]=="1":
            if ind>0:
                x.append(q[2])
            else:
                y.append(q[2])
        else:
            if ind>0:
                y.append(q[2])
            else:
                x.append(q[2])
if ind>0:
    x = x[::-1]
    S = "".join(x)+S+"".join(y)
else:
    S = S[::-1]
    y = y[::-1]
    S = "".join(y)+S+"".join(x)
print(S)

Measured memory_bytes: 96536
#include <bits/stdc++.h>
using namespace std;
int n = 8;
int a = 0, b = 0, c = 0;
vector<int> t(n);

int dfs(int i, int suma, int sumb, int sumc, int cost)
{
    if(i == t.size())
    {
        int da = abs(suma - a);
        int db = abs(sumb - b);
        int dc = abs(sumc - c);
        if(suma >= 1 && sumb >= 1 && sumc >= 1)
            return cost + da + db + dc;
        else return 1000000;
    }
    int d1 = dfs(i+1, suma, sumb, sumc, cost);
    int d2 = 0, d3 = 0, d4 = 0;
    if(suma > 0) d2 = dfs(i+1, suma + t[i], sumb, sumc, cost + 10);
    else d2 = dfs(i+1, suma + t[i], sumb, sumc, cost);
    if(sumb > 0) d3 = dfs(i+1, suma, sumb + t[i], sumc, cost + 10);
    else d3 = dfs(i+1, suma, sumb + t[i], sumc, cost);
    if(sumc > 0) d4 = dfs(i+1, suma, sumb, sumc + t[i], cost + 10);
    else d4 = dfs(i+1, suma, sumb, sumc + t[i], cost);
    
    return min(min(d1, d2), min(d3, d4));
}

int main()
{
    cin >> n >> a >> b >> c;

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

    cout << dfs(0, 0, 0, 0, 0) << endl;
}



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

using namespace std;

const int INF=1e9;

int main (){
	int n;
	cin >> n;
	vector<int> steps={1,2};
	vector<int> h(n);
	vector<int> dp(n,INF);
	dp[0]=0;
	for(int i=0; i<n; ++i) cin >> h[i];
	for(int i=0; i<n; ++i){
		for(int j=0; j<(int)steps.size() && i+steps[j]<n; ++j) {
			dp[i+steps[j]]=min(dp[i+steps[j]],dp[i]+abs(h[i]-h[i+steps[j]]));
		}
	}
	cout << dp[n-1];
				
	return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int GCD(int a, int b) {if(b==0)return a; return GCD(b, a%b);}
int main() {
    int A, B; cin >> A >> B;
    for (int i = 1; i < 4; i++) {
        if(A * B * i % 2 == 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    int a,b; cin>>a>>b;

    if(a+b>=10)cout<<"error"<<endl;
    else cout<<a+b<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using p = pair<int, int>;

int main()
{
    int n;
    vector<int> a(200000),temp(200000);

    cin >> n;

    rep(i, n-1) {
        cin >> a.at(i);
        //cout << a.at(i);
        temp.at(a.at(i) - 1) += 1;
    }

    rep(i, n)
        cout << temp.at(i) << endl;

    return 0;
}

Measured memory_bytes: 4644
def main():
    N, A, B = map(int, input().split())

    if A == 0:
        print(0)
        return

    z = N % (A + B)

    if A >= z:
        print(N // (A + B) * A + z)
    else:
        print(N // (A + B) * A + A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;


int a[100]={};

int  solve(int n,int d,int x,vector<string> v){
	int ans;
	int sousa;
	for(int i=x;i<n;i++){
		if(v[i].size()==d){
			sousa = a[i];
			break;
		}
	}
	if(sousa==10){
		ans = 0;
	}else{
		ans = 1;
	}
	for(int i=x+1;i<n;i++){
		if(v[i].size()<d+1){
			break;
		}
		if(v[i].size()==d+1){
			if(sousa==10){
				if(a[i]<=9){
					ans +=a[i];
				}else{		
					ans +=solve(n,d+1,i,v);
				}
			}else if(sousa==20){
				if(a[i]<=9){
					ans *=a[i];
				}else{
					ans *=solve(n,d+1,i,v);
				}
			}
		}
	}
	return ans;
}

int main(){
	int n;
	while(cin >> n && n>0){
		vector<string> v(n);
		for(int i=0;i<n;i++){
			cin >> v[i];
		}
		if(n==1){
			cout << v[0] << endl;
		}else{
			int x =1;
			for(int i=0;i<n;i++){
				if(v[i][v[i].size()-1]=='+'){
					a[i] = 10;
				}else if(v[i][v[i].size()-1]=='*'){
					a[i] = 20;
				}else{
					a[i] = v[i][v[i].size()-1]-'0';
				}
			}
			int ans = solve(n,1,0,v);
			cout << ans <<endl;
		}
	}
	return 0;
}

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

int main(void) {
	int N;
	cin >> N;
	int result = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 2 == 0) {
			continue;
		}
		int cnt = 0;
		for (int j = 1; j <= i; j++) {
			if (i % j == 0) {
				cnt++;
			}
		}
		if (cnt == 8) {
			result++;
		}

	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
void solve()
{
    string s,t;cin>>s>>t;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==t[0])
        {
            bool flag=0;
            for(int k=0;k<t.size();k++)
            {
                if(s[(k+i)%s.size()]!=t[k])
                    {flag=1;break;}
                //cout<<k<<" ";
            }
            //cout<<endl;
            if(!flag)
            {cout<<"Yes"<<endl;return;}
        }
    }cout<<"No";
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
<?php

$count = intval(trim(fgets(STDIN)));
$target = array_map("intval", explode(" ", trim(fgets(STDIN))));
$tmp = 0;

echo implode(" ", $target)."\n";
for ($i = 1; $i < count($target); $i++) {
    $j = $i-1;
    $tmp = $target[$i];
    while($j >= 0 && $target[$j] > $tmp) {
        $target[$j+1] = $target[$j];
        $j--;
    }
    $target[$j+1] = $tmp;
    echo implode(" ", $target)."\n";
}

?>


Measured memory_bytes: 9320
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  
  if(a == b){
    if(b == c){
      printf("Yes");
    }else{
      printf("No");
    }}else{
      printf("No");
  }
    return 0;
}
  

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <string.h>
using namespace std;


int main(){
    int h, w;

    cin >> h >> w;

    char s[h][w];

    int count_b = 0;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> s[i][j];
            if(s[i][j] == '#'){
                count_b++;
                
            }
        }
    }

    int sum = 0;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){

            if(i - 1 >= 0 and s[i - 1][j] == '#' and s[i][j] == '#'){
                sum++;
                continue;
            }
            if(i + 1 < h and s[i + 1][j] == '#' and s[i][j] == '#'){
                sum++;
                continue;
            }
            if(j - 1 >= 0 and s[i][j - 1] == '#' and s[i][j] == '#'){
                sum++;
                continue;
            }
            if(j + 1 < w and s[i][j + 1] == '#' and s[i][j] == '#'){
                sum++;
                continue;
            }
        }
    }

    //printf("count_b %d\n", count_b);

    //printf("sum %d\n", sum);


    if(sum == count_b){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;

    







}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int r,c,i,j;
    cin >> r >> c;
    int A[r+1][c+1];
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            cin >> A[i][j];
        }
        A[i][c]=0;
    }
    for(j=0;j<c+1;j++) A[r][j]=0;
    for(i=0;i<r;i++){
        for(j=0;j<c;j++) A[i][c] += A[i][j];
    }
    for(j=0;j<c+1;j++){
        for(i=0;i<r;i++) A[r][j] += A[i][j];
    }
    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            if(j) cout << " ";
            cout << A[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;
const int INF=1000000;
const int MOD=998244353;


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a);
    vector<int> q(b);
    vector<int> r(c);
    r.reserve(c+x+y);

    rep(i,a) cin >> p[i] ;
    rep(i,b) cin >> q[i] ;
    rep(i,c) cin >> r[i] ;
    sort(all(p), greater<int>());
    sort(all(q), greater<int>());
    r.insert(r.end(),p.begin(),p.begin()+x);
    r.insert(r.end(),q.begin(),q.begin()+y);
    sort(all(r), greater<int>());
    ll sum=0;
    cout << accumulate(r.begin(),r.begin()+x+y,sum) << "\n" ;
}   

Measured memory_bytes: 2168
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define MN 40002
#define MM 5000001
#define ll long long
#define ld long double
#define inf 0x7fffffff
#define clz 1000000007
#define ers(arr,val) memset(arr,val,sizeof(arr));
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,b,a) for(int i=(b);i>=(a);i--)
#define repe(i,u) for(int i=h[u];i;i=e[i].nx)
using namespace std;
int n,sum=0,N,p=0;
int ans[3001][3001];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=5000;i++){
		sum+=i;
		if(sum==n) {N=i;break;}
		if(sum>n) break;
	}
	if(N){
		rep(i,1,N)rep(j,i,N) ans[i][j]=++p;
		p=0;
		rep(j,1,N)rep(i,j,N) ans[i+1][j]=++p;
		puts("Yes");
		printf("%d\n",N+1);
		rep(i,1,N+1){
			printf("%d ",N); rep(j,1,N) printf("%d ",ans[i][j]);puts("");
		}
	}
	else puts("No");
	return 0;
}


Measured memory_bytes: 6528
from operator import itemgetter as I
while True:
    n= int(input())
    if n==0: break
    d=dict()
    for _ in range(n):
        p,d1,d2= map(int, input().split())
        d[p]= d1+d2
    print(*sorted(d.items(), key=I(1))[-1])

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

int main()

{
	int a,b,k;
	cin>>k>>a>>b;
	for(int i=0;i<1000;i++)
	{
		if(k*i>a&&k*i<b||k*i==a||k*i==b)
		{
			cout<<"OK";
			return 0; 
		}
	}
    cout<<"NG";
    return 0;
}

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

int main() {
  ll N,max=0;
  cin >> N;
  string S;
  map<string, ll> vote; 
  rep(i,N){
    cin >> S;
    vote[S]++;
    if(vote[S]>max) max=vote[S];
  }
  int n=vote.size();
  rep(i,n){
    //cout << vote[i] << endl;
  }
  for (auto p : vote) {
  auto k = p.first;
  auto v = p.second;
  if(v==max) cout << k << endl;
}
  return 0;
}


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

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

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    priority_queue<int> que;
    rep(i,n) que.push(a[i]);

    rep(_,m) {
        int x = que.top();
        que.pop();
        que.push(x/2);
    }
    
    ll ans = 0;
    rep(i,n) {
        ans += que.top();
        que.pop();
    }

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

Measured memory_bytes: 1276
/*input
1000000000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x; cin >> x;
    cout << 1000 * (x/500) + 5 * ((x % 500)/5);

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstddef>

struct strongly_connected_component {
	using size_type = std::size_t;
private : 
	std::vector<std::vector<size_type>> g, revg;
	std::vector<size_type> order, index;
	std::vector<bool> seen;

	void dfs (size_type v) {
		seen[v] = true;
		for (const size_type &u : g[v]) {
			if (not seen[u]) dfs(u);
		}
		order.push_back(v);
	}

	void dfs2 (size_type v, const size_type idx) {
		index[v] = idx;
		for (const size_type &u : revg[v]) {
			if (index[u] == g.size()) dfs2(u, idx);
		}
	}

public : 
	strongly_connected_component (size_type n)
	noexcept : g(n), revg(n), index(n, n), seen(n, false) { order.reserve(n); }

	void add_edge (size_type u, size_type v) noexcept {
		g[u].push_back(v);
		revg[v].push_back(u);
	}

	size_type solve () noexcept {
		size_type idx = 0;
		for (size_type v = 0; v < g.size(); v++) if (not seen[v]) dfs(v);
		for (size_type i = order.size(); i > 0; i--) {
			if (index[order[i - 1]] == g.size()) dfs2(order[i - 1], idx++);
		}
		return idx;
	}

	std::vector<std::vector<size_type>> build () noexcept {
		std::vector<int> count(solve());
		std::vector<std::vector<size_type>> tpls(count.size());
		for (size_type i = 0; i < g.size(); i++) count[index[i]]++;
		for (size_type i = 0; i < count.size(); i++) tpls[i].reserve(count[i]);
		for (size_type i = 0; i < g.size(); i++) tpls[index[i]].push_back(i);
		return tpls;
	}

	const size_type &operator[] (size_type v) const noexcept {
		return index[v];
	}

};


#include <iostream>

using usize = std::size_t;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	usize n, m;
	std::cin >> n >> m;
	strongly_connected_component scc(n);
	for (usize i = 0; i < m; i++) {
		usize a, b;
		std::cin >> a >> b;
		scc.add_edge(a, b);
	}
	
	auto ans = scc.build();
	std::cout << ans.size() << '\n';
	for (const auto &v : ans) {
		std::cout << v.size();
		for (const auto &e : v) std::cout << ' ' << e;
		std::cout << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 85016
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

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

    int z = count(S.cbegin(), S.cend(), '0');
    int o = count(S.cbegin(), S.cend(), '1');
    if(z > o) cout << o*2 << endl;
    else cout << z*2 << endl;

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
  int i,l,r,d,count=0;
  scanf("%d %d %d",&l,&r,&d);
  for(i=l;i<=r;i++)
  {
    if(i % d == 0)
    {
      count++;
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 1724
x = list(map(str, input().split()))
num = []
for v in x:
    try:
        num.append(int(v))
    except:
        if v == '+':
            num.append(num.pop(-2) + num.pop(-1))
        elif v == '*':
            num.append(num.pop(-2) * num.pop(-1))
        elif v == '-':
            num.append(num.pop(-2) - num.pop(-1))
print(num[0])


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

int main() {
  string s;
  cin >> s;
  int count = 0;
  int S = s.size();
  for(int i=0; i<S; i++){
    if(i>=1){
      if(s[i] == '0' && s[i] == s[i-1]){
        count++;
        s[i] = '1';
      }
      if(s[i] == '1' && s[i] == s[i-1]){
        count++;
        s[i] = '0';
      }
    }
  }
  
  cout << min(count,S-count) << endl;
  
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
typedef long long ll;
ll n, t, ans=1;

ll gcd(ll p, ll q) {
	if(q==0) return p;
	gcd(q, p%q);
}

int main() {
	cin >> n;
	while(n--) {
		cin >> t;
		ans *= t / gcd(ans, t);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int ans=1<<30;
char s[100001];
int main(){
    cin>>s;
    for(int i=1;i<strlen(s);i++)
        if(s[i]!=s[i-1])
            ans=min(ans,max(i,int(strlen(s))-i));
    printf("%lld\n",min(ans,int(strlen(s))));
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum;
  cin >> N;
  for(int i = 0;i < N;i++){
    int l, r;
    cin >> l >> r;
    sum += (r - l + 1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

N = int(input())
S = input()
res = []

res.append(S[1:].count('E'))
for i in range(1, len(S)):
    if S[i] == 'E':
        tmp = res[-1]-1
        if S[i-1] == 'W':
            tmp += 1
        
    elif S[i] == 'W':
        tmp = res[-1]
        if S[i-1] == 'W':
            tmp += 1
    res.append(tmp)
    

print(min(res))

Measured memory_bytes: 15564
#include <algorithm> 
#include <iostream> 
using namespace std; 
 
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a>=b&&a>=c){
cout<<b+c<<endl;
return 0;
}
if(b>=a&&b>=c){
cout<<a+c<<endl;
return 0;
}
if(c>=b&&c>=a){
cout<<b+a<<endl;
}
}

Measured memory_bytes: 256
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=Number(r[0]),n=r[1].split(" ").map(function(e){return Number(e)}),o={},u=0;u<t;u++)o[n[u]]||(o[n[u]]=0),o[n[u]]+=1;var i=0;for(var f in o){var l=o[f]-f;l<0&&(l=o[f]),i+=l}console.log(i)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 39700
package main
import (
    "fmt"
    "os"
    "bufio"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}


func main(){
    sc.Split(bufio.ScanWords)
    
    n := nextInt()
    m := nextInt()
    
    // cango := make(map[int][]int)
    cango := make([][]int, n+1)
    
    for i := 0; i < m; i++ {
        a := nextInt()
        b := nextInt()
        
        cango[a] = append(cango[a], b)
        cango[b] = append(cango[b], a)
    }
    
    var q Queue
    q.Add(1)
    
    togo := make(map[int]int)
    
    for len(q) > 0 {
        now := q.Remove()
        for i := 0; i < len(cango[now]); i++ {
            if _, ok := togo[cango[now][i]]; !ok {
                togo[cango[now][i]] = now
                q.Add(cango[now][i])
            }
        }
    }
    
    var ans []int
    for i := 2; i <= n; i++ {
        if v, ok := togo[i]; ok {
            ans = append(ans, v)
        } else {
            fmt.Println("No")
            return
        }
    }
    
    fmt.Println("Yes")
    for i := 0; i < len(ans); i++ {
        fmt.Println(ans[i])
    }
}
 
type Queue []int
 
func (q *Queue) Add (n int) {
    *q = append(*q, n)
}
 
func (q *Queue) Remove () int {
    temp := *q
    *q = temp[1:]
    return temp[0]
}

Measured memory_bytes: 23220
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        Queue<Process> processes = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            String name = in.next();
            int time = in.nextInt();
            processes.add(new Process(name, time));
        }
        schedule(processes, q);
    }

    private static void schedule(Queue<Process> processes, int quantum) {
        int totalTime = 0;
        PriorityQueue<Process> finishedProcesses = new PriorityQueue<>();
        while (!processes.isEmpty()) {
            Process p = processes.remove();
            boolean finished = p.start(quantum);
            if (finished) {
                totalTime += quantum + p.getTime();
                p.setCompletedAt(totalTime);
                finishedProcesses.add(p);
            } else {
                totalTime += quantum;
                processes.add(p);
            }
        }
        while (!finishedProcesses.isEmpty()) {
            System.out.println(finishedProcesses.remove());
        }
    }
}

class Process implements Comparable {
    private String name;
    private int time;
    private int completedAt;

    Process(String name, int time) {
        this.name = name;
        this.time = time;
    }

    String getName() {
        return name;
    }

    int getTime() {
        return time;
    }

    void setTime(int time) {
        this.time = time;
    }

    int getCompletedAt() {
        return completedAt;
    }

    void setCompletedAt(int completedAt) {
        this.completedAt = completedAt;
    }

    /**
     * Starts the process and runs it for the amount of time given.
     * @param quantum the amount of time allotted to run the process.
     * @return True if process is finished, else false.
     */
    boolean start(int quantum) {
        int timeLeft = getTime() - quantum;
        if (timeLeft > 0) {
            setTime(timeLeft);
            return false;
        } else {
            setTime(timeLeft);
            return true;
        }
    }

    @Override
    public int compareTo(Object o) {
        Process p = (Process) o;
        return Integer.compare(getCompletedAt(), p.getCompletedAt());
    }

    @Override
    public String toString() {
        return getName() + " " + getCompletedAt();
    }
}


Measured memory_bytes: 81256
#include<bits/stdc++.h>
using namespace std;
int main() 
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==1)return cout<<"YES\n",0;
  for(register int i=1;i<=100;i++)
    if(a*i%b==c)return cout<<"YES\n",0;
  return cout<<"NO\n",0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans[100],a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n;
       Cout(50);
      rep(i,50){
          ans[i]=49+n/50;
          if(i<n%50)ans[i]++;
          else ans[i]-=n%50;
      }
      cout << ans[0];
      rrep(i,1,50){
          cout << " " << ans[i];
      }
      cout << endl;
       
return 0;
}


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

using namespace std;

const int N = 2e5 + 5;

long long n ;

int main()
{
    cin>>n;
    if(n%2)
        return cout<<0,0;
    long long ans  = 0;
    ans = 0;
    long long dem = 2;
    while(1)
    {
        dem*=5;
        ans+=n/dem;
        if(n<dem)
            break;
    }
    cout<<ans ;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;

using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<pair<vector<ll>,ll>> G(N);//辺のリストと根からの距離
    map<pair<ll,ll>,ll> E = map<pair<ll,ll>,ll>();
    for(ll i = 0; i < N; i++){
        G[i].first = vector<ll>(0);
        G[i].second = -1;
    }
    for(ll i = 0; i < N - 1; i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        E[make_pair(a,b)] = c;
        E[make_pair(b,a)] = c;
        G[a].first.push_back(b);
        G[b].first.push_back(a);
    }
    ll Q,K;
    cin >> Q >> K;
    vector<pair<ll,ll>> todo(Q);
    for(int i = 0; i < Q; i++){
        ll x,y;
        cin >> x >> y;
        x--;y--;
        todo[i] = make_pair(x,y);
    }

    bool didVisit[N];
    for(int i = 0; i < N; i++){
        didVisit[i] = false;
    }
    queue<ll> q = queue<ll>();
    q.push(K-1);
    G[K - 1].second = 0;
    while(q.size() != 0){
        ll v = q.front();q.pop();
        for(int i = 0;i < G[v].first.size(); i++){
            ll targetId = G[v].first[i];
            if(didVisit[targetId]){
                continue;
            }
            G[targetId].second = G[v].second + E[make_pair(targetId,v)];
            q.push(targetId);
        }
        didVisit[v] = true;
    }
    for(int i = 0; i < Q; i++){
        pair<ll,ll> task = todo[i];
        cout << G[task.first].second + G[task.second].second << endl;
    }


}

Measured memory_bytes: 23284