akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define loop(n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n,j=1,b,countb=0;cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        if(j==b){
            j=j+1;
        }
        else{
            countb++;
        }
    }
    if(countb==n)
    cout<<-1;
    else cout<<countb;
	return 0;
}


Measured memory_bytes: 256
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int ans=0;
for(int i=1;i<=n;i++)
{
string s=to_string(i);
if(s.length()%2==1)
{
ans++;
}
}
cout<<ans;
}

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

void printVec(vector<int> A, int N){
  for (int i = 0; i < N; i ++){
    if(i == N - 1){
      cout << A[i] << "\n";
    }else{
      cout << A[i] << " ";
    }
  }
}

void insertionSort(vector<int> A, int N){
  for (int i = 1; i <= N - 1; i ++){
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    printVec(A, N);
  }
}

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

  vector<int> vc;
  int n;
  cin >> n;
  while (n--){
    int x;
    cin >> x;
    vc.push_back(x);
  }
  printVec(vc, vc.size());
  insertionSort(vc, vc.size());
}




Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<63)-1
#define MAX 1000000000
signed main(){
    int N; cin>>N;
    vii A(2,vi(3));
    rep(i,0,2){
        rep(j,0,3) cin>>A[i][j];
    }
    vii dp(2,vi(N*5000+1));
    rep(i,0,2){
        REP(j,0,N*5000){
            vi B(3,j);
            rep(k,0,3){
                if(j>=A[i][k]) B[k]=dp[i][j-A[i][k]]+A[1^i][k];
            }
            dp[i][j]=max({B[0],B[1],B[2],j});
        }
    }
    int ans=N;
    rep(i,0,2){
        ans=dp[i][ans];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 586240
n,t = map(int, input().split())
lst_c = []
lst_t = []
a = 0
b = 0
for i in range(n):
    a,b = map(int, input().split())
    if b <= t:
        lst_c.append(a)
if lst_c == []:
    print("TLE")
else:
    print(min(lst_c))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int s=0, j=i;
		while(j) {
			s++;
			j/=10;
		}
		if(s%2==1) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        W: u64,
        WV: [(u64,u64); N],
    }
    // 重さごとに4分類
    let mut V = vec![vec![0;0]; 4];
    let mut w0 = 0;
    for i in 0..N{
        let (w,v) = WV[i];
        if i==0{
            V[0].push(v);
            w0 = w;
        }else{
            V[(w-w0) as usize].push(v);
        }
    }
    // 重さごとに降順ソート
    for i in 0..4{
        V[i].sort();
        V[i].reverse();
    }
    // 重さごとに累積和
    let mut S = vec![vec![0;1]; 4];
    for i in 0..4{
        let mut tmp = 0;
        for v in V[i].iter(){
            tmp += *v;
            S[i].push(tmp);
        }
    }
    // 全探索
    let mut ans = 0;
    for i0 in 0..S[0].len(){
        for i1 in 0..S[1].len(){
            for i2 in 0..S[2].len(){
                for i3 in 0..S[3].len(){
                    if w0*i0 as u64 +(w0+1)*i1 as u64 +(w0+2)*i2 as u64 +(w0+3)*i3 as u64 <= W{
                        ans = max(ans, S[0][i0]+S[1][i1]+S[2][i2]+S[3][i3]);
                    }
                }
            }
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
// https://atcoder.jp/contests/abc170/tasks/abc170_b
#include <iostream>
//#include <bits/stdc++.h>
//#include "../../macro.h"
using namespace std;

/*
mm	:	tc(linear) sc(memo+stack)
			idea-
					generate all combinations
			
			TLE: without memorization
			WA: with memorization

ba	:	tc(x) sc(array)
			idea- 
					let x=3 (animal) y=8 (legs total)
					crans possible, c = [0,1,2,3]
					turtle possible, t = [3,2,1,0]
					c, t contain possible number of crane & turtle

			iterate over i=0 to x+1 
				check if 2*c[i]+4*t[i] == y, then return true

*/
int memo[101];
void recursion(int x, int y, int animal, int legs, int &ans){
	if(legs==y && animal==x){
		ans = 1;
		return;
	}
	if(legs>y || animal>x){
		return;
	}

	// memorization
	if(memo[legs]==-1){
		memo[legs]=1;
		recursion(x,y, animal+1, legs+2, ans);
		recursion(x,y,animal+1, legs+4, ans);
	}
}

int editorial(int x, int y){
	int c[x+1], t[x+1];
	for(int i=0; i<x+1; i++){
		c[i] = i;
		t[i] = x-i;
	}
	for(int i=0; i<x+1; i++){
		if(2*c[i]+4*t[i]==y)
			return 1;
	}
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	int x, y;	cin>>x>>y;
	int ans =	editorial(x,y);	
	if(ans)	cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string A,B,C;
    cin >>A>>B>>C;
    if(A.at(A.size()-1)==B.at(0) && B.at(B.size()-1)==C.at(0)){
        cout << "YES" << endl;
    }
    else{
        cout <<"NO" <<endl;
    }




}


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

int dots_num(std::string s); 
int value_num(char c); 
void inner_loop(std::stack<std::pair<int, int> > &st); 
void dfs(int n); 


int main(void) {
    int n;

    while (1) {
        std::cin >> n;
        if (n == 0) {
            break;
        }
        dfs(n);
    }
    return 0;
}

int dots_num(std::string s) {
    int num = 0;
    int loop = 0;
    while (s[loop] == '.') {
        ++num; 
        ++loop;
    }
    return num;
}

int value_num(char c) {
    int ret;
    if (c == '+') {
        ret = -1; 
    } else if (c == '*') {
        ret = -2;
    } else {
        ret = (int) c - 48;
    }
    return ret;
}

void inner_loop(std::stack<std::pair<int, int> > &st) {
    int start_dots;
    std::vector<int> enzan(2);
    start_dots = st.top().first;
    std::pair<int, int> p;

    enzan[0] = 0;
    enzan[1] = 1;
    while (1) {
        if (start_dots > st.top().first) {
            break;
        }
        enzan[0] += st.top().second;
        enzan[1] *= st.top().second;
        st.pop();
    }
    if (st.top().second == -1) {
        p = std::make_pair(st.top().first, enzan[0]);
        st.pop();
        st.push(p);
    } else if(st.top().second == -2) {
        p = std::make_pair(st.top().first, enzan[1]);
        st.pop();
        st.push(p);
    }
    return;
}

void dfs(int n) {
    std::string s;
    std::stack<std::pair<int, int> > st;
    st.push(std::make_pair(0, 0));
    int dots;
    int value;

    for (int i = 0; i < n; i++) {
        std::cin >> s;
        dots = dots_num(s);
        value = value_num(s[dots]);


        while (1) {
            if (st.top().first <= dots) {
                break; 
            }
            inner_loop(st); 
        }
        st.push(std::make_pair(dots, value));
    }

    while (1) {
        if (st.top().first == 0) {
            break; 
        }
        inner_loop(st); 
    }

    std::cout << st.top().second << std::endl;
    return;
}

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

int main(){
	string s,out = "yes";
	map<char,bool> mp;
	cin >> s;
	for(auto i:s){
		if(mp[i]) {out = "no"; break;}
		else mp[i]=true;
	}
	cout << out << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	
	while(true){
		int n;
		cin >> n;
		if (n == 0) break;

		int max_p = 0, max_d = 0;
		for (int i = 0; i < n; i++){
			int p, d1, d2;
			cin >> p >> d1 >> d2;

			if (max_d <= d1 + d2){
				max_d = d1 + d2;
				max_p = p;
			}
		}
		cout << max_p << " " << max_d << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
a = str(input())
ans = 0
count = 0
if a[1] == "R" :
  count = count + 1
  if a[0] == "R" and a[2] == "R" :
    count = count + 2
  elif a[0] == "S" and a[2] == "S" :
    count = 1
  else :
    count = count + 1
else :
  if a[0] == "R" and a[2] == "R" :
    count = count + 1
  elif a[0] == "S" and a[2] == "S" :
    count = 0
  else :
    count = count + 1
ans = count
print(ans)

Measured memory_bytes: 9132
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to, cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

lint n, cnt, ans = inf;
lint a[200010];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i + 1];
		a[i + 1] += a[i];
	}
	rep(i, n - 1) {
		lint b = a[i + 1], c = a[n] - a[i + 1];
		ans = min(ans, abs(b - c));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1920
#include <cstdio>
#include <string>
#include <algorithm>

int main() {
  char buf[131072];
  scanf("%s", buf);
  std::string s = buf;

  std::string t0 = s;
  std::string t1 = s;
  for (size_t i = 0; i < s.length(); ++i) {
    t0[i] = ((i % 2 == 0)? '0': '1');
    t1[i] = ((i % 2 == 0)? '1': '0');
  }

  int res0 = 0;
  int res1 = 0;
  for (size_t i = 0; i < s.length(); ++i) {
    if (s[i] != t0[i]) ++res0;
    if (s[i] != t1[i]) ++res1;
  }

  printf("%d\n", std::min(res0, res1));
}


Measured memory_bytes: 640
S=input()
d={}
for i in range(ord('a'),ord('z')+1):
	d[i]=0
for s in S:
	d[ord(s)]+=1

f=True
for i in d:
	if d[i]==0:
		print(chr(i))
		f=False
		break
if f:print('None')

Measured memory_bytes: 3188
#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  ; 
  vector<string> s(n) ;
  vector<int>    t(n) ;
  
  rep(i,n){
    cin >> s.at(i) >> t.at(i) ;
  }
  
  bool cnt = false ; 
  intll ans = 0 ;
  string S  ;
  cin >> S ;
  
  rep(i,n){
    if(cnt)  ans += t.at(i) ;
    if(s.at(i) == S){
      cnt = true ;
    }
  }
  
  cout << ans ;
  

}


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

int main()
{
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for (int x = 0; x <= k; x++)
    {
        for (int y = 0; y <= k; y++)
        {
            int z = s - x - y;
            if (z >= 0 && z <= k)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int n;
    cin>>n;
    int x=0;
    if(n<=1000)
    x=1000;
    else if(n>1000 &&n <=2000)
    x=2000;
    else if(n>2000 && n<=3000)
    x=3000;
    else if(n>3000 && n<=4000)
    x=4000;
    else if(n>4000 && n<=5000)
    x=5000;
    else if(n>5000 && n<=6000)
    x=6000;
    else if(n>6000 && n<=7000)
    x=7000;
    else if(n>7000 && n<=8000)
    x=8000;
    else if(n>8000 && n<=9000)
    x=9000;
    else if(n>9000)
    x=10000;
    cout<<x-n<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double r1,r2;cin >> r1 >> r2;
	cout << fixed << setprecision(20) << r1*r2/(r1+r2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	string s,t;
	
	cin>>s>>t;
	int ans=t.length();
	for(int i=0;i<s.length();i++){
		if(i+t.length()-1>=s.length())break;
		int cnt=0;
		for(int j=0;j<t.length();j++){
			if(t[j]!=s[i+j])cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<queue>
#include<iostream>
#define REP(i, n) for(int i = 0, ed_##i = n; i < ed_##i; i++)
#define FOR(i, n) for(int i = 1, ed_##i = n; i <= ed_##i; i++)
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))  // Leading zeros
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#ifdef QWERTIER
#define err(x) cerr << #x << " : " << x << endl
#else
#define err(x)
#endif

typedef long long LL;
using namespace std;

typedef pair<int,int> pii;
#define MP make_pair

inline int lowbit(int x) {
  return x & (-x);
}

#define N 200010

int n;

int val[N];
void add(int p, int x) {
  while (p <= n) {
    val[p] = max(val[p], x);
    p += lowbit(p);
  }
}

int get(int p) {
  int ret = 0;
  while (p) {
    ret = max(ret, val[p]);
    p -= lowbit(p);
  }
  return ret;
}

int R[N], L[N], a[N], p[N];
int main(){
#ifdef QWERTIER
  freopen("in.txt","r",stdin);
#endif
  scanf("%d", &n);
  set<int> st;
  FOR (i, n) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
  }
  FOR (i, n) {
    L[i] = get(p[i]) + 1;
    add(p[i], p[i]);
  }
  memset(val, 0, sizeof(val));
  reverse(a+1, a+n+1);
  FOR (i, n) {
    R[i] = n - get(n-p[i]+1);
    add(n-p[i]+1, n - p[i] + 1);
  }
  
  LL ans = 0;
  FOR (i, n) {
    ans += (R[i] - p[i] + 1) *(LL) (p[i] - L[i] + 1) * (LL)i;
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    if (N == 2) {
        cout << -1 << '\n';
    } else {
        for (int i = 0; i < N; i++) {
            vector<int> A;
            for (int j = 0; j < N; j++) if (i != j) A.push_back(j+1);
            rotate(begin(A), end(A)-i, end(A));
            for (int a : A) cout << a << ' ';
            cout << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
const int maxn=1000000;
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);
void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
const int nn=1e5+5;
int result[100005];
int gcd(int a,int b){
    while (b) {
    int c = a;
    a = b;
    b = c % b;
  }
  return a;
}
void solve() {
  int a, b;
  cin >> a >> b;
  int g = gcd(a, b);
  int ret = 1;
  for (int i = 2; i * i <= g; ++i) {
    if (g % i == 0) {
      while (g % i == 0) g /= i;
      ++ret;
    }
  }
  if (g > 1) ++ret;
  cout << ret << endl;
    
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //fillprime();
    //int t;cin>>t;while(t--)
    solve();
}

Measured memory_bytes: 3764
#include<cstdio>
#include<set>
using namespace std;
int fa[2][200010],__rank[2][200010];
int findroot(bool op,int x)
{
	return x==fa[op][x] ? x : fa[op][x]=findroot(op,fa[op][x]);
}
void Union(bool op,int U,int V)
{
	if(__rank[op][U]<__rank[op][V])
	  fa[op][U]=V;
	else 
	 {
	 	fa[op][V]=U;
	 	if(__rank[op][U]==__rank[op][V])
	 	  ++__rank[op][U];
	 }
}
int n,m,K;
bool vis[200010];
int anss[200010];
set<int>S[2][200010];
typedef set<int>::iterator ITER;
int path[200010],e;
int main()
{
	int x,y;
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;++i)
	  fa[0][i]=fa[1][i]=i;
	for(int i=1;i<=m;++i)
	  {
	  	scanf("%d%d",&x,&y);
	  	int f1=findroot(0,x),f2=findroot(0,y);
	  	if(f1!=f2)
	  	  Union(0,f1,f2);
	  }
	for(int i=1;i<=K;++i)
	  {
	  	scanf("%d%d",&x,&y);
	  	int f1=findroot(1,x),f2=findroot(1,y);
	  	if(f1!=f2)
	  	  Union(1,f1,f2);
	  }
	for(int i=0;i<=1;++i)
	  for(int j=1;j<=n;++j)
	    S[i][findroot(i,j)].insert(j);
	for(int i=1;i<=n;++i) if(!vis[i])
	  {
	  	e=0;
	  	int rt[2];
	  	bool o=0;
	  	rt[0]=findroot(0,i);
	  	rt[1]=findroot(1,i);
	  	if(S[0][rt[0]].size()>S[1][rt[1]].size())
	  	  o=1;
	  	set<int> tS=S[o][rt[o]];
	  	for(ITER it=tS.begin();it!=tS.end();++it)
	  	  if(S[o^1][rt[o^1]].find(*it)!=S[o^1][rt[o^1]].end())
	  	    {
	  	      S[o][rt[o]].erase(*it);
	  	      S[o^1][rt[o^1]].erase(*it);
	  	      path[++e]=(*it);
	  	      vis[*it]=1;
	  	    }
	  	for(int j=1;j<=e;++j)
	  	  anss[path[j]]=e;
	  }
	for(int i=1;i<n;++i)
	  printf("%d ",anss[i]);
	printf("%d\n",anss[n]);
	return 0;
}

Measured memory_bytes: 45696
import sys
from heapq import *
input = sys.stdin.readline

def main():
  n, m, s, t = map(int, input().split())
  
  inf = pow(10, 15)
  
  tree = [[] for _ in range(n)]
  for i in range(m):
    u, v, a, b = map(int, input().split())
    tree[u-1].append((v-1, a, b))
    tree[v-1].append((u-1, a, b))
  
  ans_yen = [0]*n
  ans_snuke = [0]*n
  
  for start, ans in zip([s-1, t-1], [ans_yen, ans_snuke]):
    already = [False]*n
    not_yet = [(0, start)]
    
    while len(not_yet) > 0:
      c, p = heappop(not_yet)
      if already[p]:
        continue
      ans[p] = c
      already[p] = True
      
      for (value, a, b) in tree[p]:
        if already[value]:
          continue
        if start == s-1:
          cost = a
        else:
          cost = b
        heappush(not_yet, (c+cost, value))
  
  ans = [0]*n
  sub = inf
  for i in range(n-1, -1, -1):
    sub = min(sub, ans_yen[i]+ans_snuke[i])
    ans[i] = sub
  
  sub = inf
  for a in ans:
    print(sub-a)
      
  
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 110128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int main(){
	ll a,b;
	cin>>a>>b;
	if(a*b==15){
		cout<<'*'<<endl;
	}
	else if(a+b==15)
	{
		cout<<'+'<<endl;
	}
	else {
		cout<<'x'<<endl;
	}
	
}

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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
#define x first
#define y second
#define point pair<double,double>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}

//you don't know math, unless you can do math!
int l,n;
vector<int> cuts;
ll dp[1100][1100];

ll solve(int i, int j){
    ll &ret= dp[i][j];
    if(ret != -1)
        return ret;

    int cur= lower_bound(cuts.begin(), cuts.end(), i+1) - cuts.begin();
    if(cur == cuts.size() || cuts[cur] >= j)
        return ret= 0;



    ret= 10000000;
    while(cur < n && cuts[cur] < j){
        ret = min(ret, solve(i, cuts[cur]) + solve(cuts[cur], j) + j - i);
        cur++;
    }

    return ret;
}
int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    ll n,w; cin>>n>>w;
    map<ll, vector<ll>> mp;

    vector<ll> weights;
    ll weight, value;
    loop(i,n){
        cin>>weight>>value;
        mp[weight].push_back(value);
        weights.push_back(weight);
    }

    sort(weights.begin(), weights.end());
    weights.erase(unique(weights.begin(), weights.end()), weights.end());
    while(weights.size() < 4) weights.push_back(0);


    for(auto it= mp.begin(); it!= mp.end(); it++){
        vector<ll> &v = it->second;
        sort(v.begin(), v.end());

        reverse(v.begin(), v.end());
    }

    for(auto it= mp.begin(); it!= mp.end(); it++){
        vector<ll> &v = it->second;
        loop1(i, v.size()-1)
            v[i]+= v[i-1];
    }

    ll ans=0;

    for(ll a= 0; a <= mp[weights[0]].size(); a++){
        for(ll b=0; b <= mp[weights[1]].size(); b++){
            for(ll c=0; c <= mp[weights[2]].size(); c++){
                for(ll d=0; d <= mp[weights[3]].size(); d++){
                    if((a*weights[0])+(b*weights[1])+(c*weights[2])+(d*weights[3]) > w) continue;

                    ll sum=0;
                    if(a!=0) sum += mp[weights[0]][a-1];
                    if(b!=0) sum += mp[weights[1]][b-1];
                    if(c!=0) sum += mp[weights[2]][c-1];
                    if(d!=0) sum += mp[weights[3]][d-1];

                    ans= max(ans, sum);
                }
            }
        }

    }

    cout<<ans;




}


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

int main(){
  char ss[10000];
  scanf("%s",ss);
  int i=0,j,ans[2],N,cnt=0,f=1,p;
  N=strlen(ss);
  vector<vector<int>> axis(2);
  cin>>ans[0]>>ans[1];
  while(ss[i]=='F')i++;
  ans[0]-=i;
  while(i<N){
    if(ss[i]=='F'){
      cnt++;
    }else{
      f=1-f;
      if(cnt>0){
        axis[f].push_back(cnt);
        cnt=0;
      }
    }
    i++;
  }
  if(cnt>0)axis[1-f].push_back(cnt);

  queue<int> que;
  set<int> se;
  auto ch=se.insert(0);
  for(f=0;f<2;f++){
    while(!que.empty())que.pop();
    que.push(0);
    se.insert(0);
    for(i=0;i<axis[f].size();i++){
      N=que.size();
      se.clear();
      for(j=0;j<N;j++){
        p=que.front();que.pop();
        ch=se.insert(p+axis[f][i]);
        if(ch.second)que.push(p+axis[f][i]);
        ch=se.insert(p-axis[f][i]);
        if(ch.second)que.push(p-axis[f][i]);
      }
    }
    ch=se.insert(ans[f]);
    if(ch.second){
      printf("No\n");
      return 0;
    }
    se.clear();
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 512
a, b, k = map(int, input().split())

a_dis = [x for x in range(1,a+1) if a % x == 0]
b_dis = [x for x in range(1,b+1) if b % x == 0]

co_dis = sorted([i for i in a_dis if i in b_dis],reverse=True)

print(co_dis[k-1])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    string s;
    ll k;
    cin>>s>>k;
    set <string> ans;
    for(ll i=0;i<sz(s);i++)
    {
        string p;
        for(ll j=i;j<min(sz(s),i+k);j++)
        {
            p.pb(s[j]);
            ans.insert(p);
        }
    }
    auto it=ans.begin();
    for(ll i=0;i<k-1;i++)
        it++;
    cout<<*it<<nl;
}


Measured memory_bytes: 4688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int fx = 0;
//    char schar[s.size()];
    rep(i,s.size()) fx += s[i] - '0';
    if (stoi(s)%fx == 0)
    {
	    cout << "Yes" << endl;
    }
    else
    {
	    cout << "No" << endl;
    }


}


Measured memory_bytes: 256
menu = []
for i in range(5):
    menu.append(int(input()))

min_reminder = 10
min_menu = 5
for i in range(5):
    reminder = menu[i]%10
    if reminder < min_reminder and reminder != 0:
        min_reminder = reminder
        min_menu = i
 
total = 0
for i in range(5):
    if min_menu == i or menu[i]%10 == 0:
        total += menu[i]
    else:
        total += menu[i]+10-menu[i]%10
        
print(total)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int r,g,b;
	cin >> r>>g>>b;
	if ((r * 100 + g * 10 + b) % 4 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val numberList = (1..n).map { readLine()!!.toInt() }

    var max = 0
    var second = 0
    for(num in numberList) {
        if(num >= max) {
            second = max
            max = num
        } else if(num >= second) {
            second = num
        }
    }

    for(num in numberList) {
        if(num == max) {
            println(second)
        } else {
            println(max)
        }
    }
}


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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

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

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;


map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


int main() {
	int d;
	cin >> d;
	if (d == 25)cout << "Christmas";
	if (d == 24)cout << "Christmas Eve";
	if (d == 23)cout << "Christmas Eve Eve";
	if (d == 22)cout << "Christmas Eve Eve Eve";

	
	return 0;
}













Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, c int
	fmt.Scan(&n, &m, &c)

	bArr := make([]int, m)
	for i := range bArr {
		fmt.Scan(&bArr[i])
	}

	var a, ans int
	for i := 0; i < n; i++ {
		total := c
		for j := 0; j < m; j++ {
			fmt.Scan(&a)
			total += a * bArr[j]
		}
		if total > 0 {
			ans++
		}
	}

	fmt.Println(ans)
}


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

int main(){
    int N;
    cin >> N;
    if(__builtin_popcount(N)==1){
        cout << "No" << endl;
        return 0;
    }
    vector<pair<int,int>> ans;
    ans.emplace_back(1,2);
    ans.emplace_back(2,3);
    ans.emplace_back(N+1,N+2);
    ans.emplace_back(N+2,N+3);
    ans.emplace_back(N+3,1);
    for(int i=4;i<N;i+=2){
        ans.emplace_back(i,i+1);
        ans.emplace_back(1,i);
        ans.emplace_back(N+i,N+i+1);
        ans.emplace_back(1,N+i+1);
    }
    if(N%2==0){
        for(int i=30;i>=1;i--){
            if(N&(1<<i)){
                int M = N^(1<<i)^1;
                ans.emplace_back(N,(1<<i));
                ans.emplace_back(2*N,N+M);
                break;
            }
        }   
    }
    cout << "Yes" << endl;
    for(auto x:ans) cout << x.first << " " << x.second << endl;
}

Measured memory_bytes: 3952
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    int h=0,w=0,c=1,d=0,n,m,k,ans=0,y;
    string s,s2;
    cin >> n;
    VI x(n+1);
    for(int j=1;j<=n;j++){
        m = j;
        if(j%2!=0){
            for(int i=2;i<=m;i++){
                while(m%i==0){
                    x[i]++;
                    m /= i;
                }
            }
            for(int i=2;i<=n;i++){
                c *= x[i]+1;
            }
            if(c==8){
                ans++;
            }
        }
        c=1;
        rep(i,n+1){
            x[i] = 0;
        }
    }
    cout << ans <<endl;
    return 0;
}


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

int main() {
  long long n, k;
  cin>>n>>k;
  long long a[n], f[n];
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) cin>>f[i];

  sort(a, a + n);
  sort(f, f + n);
  reverse(f, f + n);
  long long l = -1, r = a[n-1] * f[0];
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    long long cnt = 0;
    bool ok = true;
    for (int i=0; i<n; i++) {
      long long c = a[i] * f[i];
      if (c > mid) {
        cnt += a[i] - mid / f[i];
      }
      if (cnt > k) {
        ok = false;
        break;
      }
    }
    if (ok) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout<<r<<endl;
}

Measured memory_bytes: 3456
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors

A, B = map(int, input().split())

listA = make_divisors(A)
listB = make_divisors(B)
lst = list(set(listA) & set(listB))

lst.sort()

if len(lst) == 1:
    print(1)
else:
    check = [lst[1]]
    for i in range(1, len(lst)):
        for c in check:
            if lst[i] % c == 0:
                break
        else:
            check.append(lst[i])
    print(len(check)+1)


Measured memory_bytes: 5180
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()

print(int(A * B / gcd(A, B)))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
string S, T="keyence", U;
ll i, j=0, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    cin>>S;
    if(S==T)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    f0(i,S.sz)
    {
        for(j=i+1; j<S.sz; j++)
        {
            U=S.substr(0,i)+S.substr(j);
            if(T==U)
            {
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
//#include<stdio.h>
//#include<stdlib.h>
//int N,M,t[101],i,j,r;
//typedef struct e{int f,t,c;}e;
//e B[101];
//int cmp(const void *a,const void *b){e x=*(e*)a,y=*(e*)b;return x.c-y.c;}
//void in(n){for(;n--;)t[n]=n;}
//int p(n){return t[n]=t[n]==n?n:p(t[n]);}
//void u(a,b){t[p(a)]=p(b);}
//int s(a,b){return p(a)==p(b);}
//
//main()
//{
//	for(;scanf("%d%d",&N,&M),N,M;)
//	{
//		in(N);
//		for(i=r=0;i<M;i++)
//			scanf("%d%d%d",&B[i].f,&B[i].t,&B[i].c);
//		qsort(B,M,sizeof(e),cmp);
//		for(i=0;i<M;i++)
//			if(!s(B[i].f,B[i].t))
//			{
//				u(B[i].f,B[i].t);
//				r+=B[i].c;
//			}
//		printf("%d\n",r);
//	}
//	return 0;
//}
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<cmath>
#define MAX_N 10005
using namespace std;

typedef struct edge
{
	int from,to,cost;
} edge;

bool mcmp(edge x,edge y)
{
	return x.cost<y.cost;
}

int uft[MAX_N];
vector<edge>e;

void init(int n)
{
	int i;
	for (i=0;i<=n;i++)
	uft[i]=i;
}

int parent(int n)
{
	if (uft[n]==n)
		return n;
	else
		return uft[n]=parent(uft[n]);
}

void unit(int p, int q)
{
	uft[parent(p)]=parent(q);
}

int same(int p, int q)
{
	return parent(p)==parent(q);
}

int kruskal(int n,int r)
{
	int res=0;
	sort(e.begin(),e.end(),mcmp);
	init(n);
	for(int i=0;i<r;i++)
	{
		edge tmp=e[i];
		if(!same(tmp.from,tmp.to))
		{
			res+=tmp.cost;
			unit(tmp.from,tmp.to);
		}
	}
	return res;
}

int piles[10001][2];
int m_distance(int f,int t)
{
	return pow((double)piles[f][0]-piles[t][0],2)+pow((double)piles[f][1]-piles[t][1],2);
}

int main()
{
	int N,M;
	for(;scanf("%d%d",&N,&M),N,M;)
	{
		for(int j=0;j<M;j++)
		{
			edge tmp;
			scanf("%d%d%d",&tmp.from,&tmp.to,&tmp.cost);
			e.push_back(tmp);
		}
		printf("%d\n",kruskal(N,M));
		e.clear();
	}
	return 0;
}

Measured memory_bytes: 1060
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)1e5+5

vl adj[2*MAXN];
ll val[2*MAXN]={0};
ll ans[2*MAXN]={0};

void dfs(ll s, ll e){
    ans[s] += val[s];
    for(auto x: adj[s]){
        if(x!=e){
            ans[x]+=ans[s];
            dfs(x, s);
        }
    }
}

void solve(){
    ll n,q;
    cin>>n>>q;
    loop(i,0,n-1){
        ll a, b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    loop(i,0,q){
        ll p, x;
        cin>>p>>x;
        val[p]+=x;
    }
    dfs(1, 0);
    loop(i,1,n+1){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}

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

    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
        
    
}



Measured memory_bytes: 24960
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  long long A,B,C,K;
  cin >> A >> B >> C >> K;

  /*if(abs(A - B) > (long long)pow(10,18)){
    cout << "Unfair" <<endl;
    return 0;
  }*/

  if(K % 2 == 0){
    A = A-B;
  }
  else{
    A = B-A;
  }
  cout << A <<endl;
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int N;
int main(void){
    cin >> N;
    cout << N*N*N << endl;
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    if(a <= 8 && b <= 8)cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N, M; cin >> N  >> M;
    for (int i = 1; i <= M; i++) {
        ll k = N - i + 1;
        if (N%2 == 0&& (k - i) <= N/2) k--; 
        cout << i << ' ' << k << '\n';
    }
}

Measured memory_bytes: 3636
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  ll a, b, v, w;
  ll t;
  cin >> a >> v >> b >> w;
  cin >> t;

  ll dist = abs(a - b);
  if (v * t - w * t >= dist)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//scanで一行づつ読み込む
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)

//sort
// array := []int{5, 1, 4, 2, 3}
// sort.Sort(sort.IntSlice(array))

func main() {
	// a := make([]int, n)
	// A := strings.Split(nextLine(), " ")

	N := nextLine()
	// n, _ := strconv.Atoi(input[0])
	A := nextLine()
	B := nextLine()
	C := nextLine()
	n, _ := strconv.Atoi(N)
	// a, _ := strconv.Atoi(A[0])
	// b, _ := strconv.Atoi(B[0])
	// c, _ := strconv.Atoi(C[0])

	ans := 0
	for i := 0; i < n; i++ {
		curA := A[i]
		curB := B[i]
		curC := C[i]

		if curA == curB && curA == curC {
			continue
		} else if curA == curB || curA == curC || curB == curC {
			ans++
		} else {
			ans += 2
		}

	}

	fmt.Fprintln(wtr, ans)
	_ = wtr.Flush()
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func com(a, b int) int {

	if a > b {
		return 0
	}
	return abs(a - b)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 640