akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int N,M,C;
    cin >> N >> M >> C;
    vector<int>vec;
    for(int i=0; i<M; i++){
        int a;
        cin >> a;
        vec.push_back(a);
    }
    vector<int> vec2;
    int count =0;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            int num;
            cin >> num;
            vec2.push_back(num);
        }
        int total = 0;
        for(int i=0; i<vec.size(); i++){
            total += vec[i]*vec2[i];
        }
        vec2.clear();
        if(total + C > 0){
            count++;
        }
    }
    cout << count <<endl;

}

Measured memory_bytes: 3580
#include<iostream>
using namespace std;
void eratos(bool cp_list[],int max){
  for(int i=2;i<=max;i++){
    cp_list[i]=true;
  }
  cp_list[0]=cp_list[1]=false;
  for(int i=2;i<=max;i++){
    if(cp_list[i]){
      for(int j=i+i;j<=max;j+=i){
        cp_list[j]=false;
      }
    }
  }
}
int main(){
  int q,l,r;
  bool p_num[100001]={};
  int ans_cnt[100001]={};
  cin >> q;
  eratos(p_num,100000);
  for(int i=2;i<=100000;i++){
    ans_cnt[i]=ans_cnt[i-1];
    if(i%2==0) continue;
    if(p_num[i]&&p_num[(i+1)/2]) ans_cnt[i]++;
  }
  while(q!=0){
    q--;
    cin >> l >> r;
    cout << (ans_cnt[r]-ans_cnt[l-1])<<endl;
  }
}


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

int heap_size = 0;

void maxHeap(int*,int);
void heapIncrease(int*,int,int);
void maxHeapInsert(int*,int);
int heapExtractMax(int*);

int main() {
  char com[10];
  int heap[2000000];
  int arg;
  while (1) {
    scanf("%s", com);
    if (com[0] == 'i') {
      scanf("%d", &arg);
      maxHeapInsert(heap, arg);
    } else if (com[1] == 'x') {
      printf("%d\n", heapExtractMax(heap));
    } else {
      break;
    }
  }
  return 0;
}
  
  void maxHeap(int* array, int i) {
    int a,b,max;
    int work;
    a=i*2;
    b=i*2+1;
    if (a<=heap_size&&array[a]>array[i]){
      max=a;
    }
    else{
      max=i;
    }
    if(b<= heap_size&&array[b]>array[max]){
      max=b;
    }
    if(max!=i){
      work=array[i];
      array[i]=array[max];
      array[max]=work;
      maxHeap(array,max);
    }
  }
  void heapIncreaseKey(int* array, int i, int key) {
    int work;
    array[i]=key;
    while(i>1&&array[i/2]<array[i]){
      work=array[i];
      array[i]=array[i/2];
      array[i/2]=work;
      i=i/2;
    }
  }
  void maxHeapInsert(int* array, int key) {
    heap_size++;
    array[heap_size]=-1;
    heapIncreaseKey(array,heap_size,key);
  }
  int heapExtractMax(int* array) {
    long max;
    max=array[1];
    array[1]=array[heap_size];
    heap_size--;
    maxHeap(array,1);
    return max;
  }

Measured memory_bytes: 5864
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        k: u64,
        ab: [(u64,u64);n]
    }
    let mut m: BTreeMap<u64,u64> = BTreeMap::new();
    for (a,b) in ab {
        *m.entry(a).or_insert(0) += b;
    }
    let mut x = 0;
    for (&a,&b) in &m {
        x += b;
        if x >= k {
            println!("{}", a);
            return;
        }
    }
}


Measured memory_bytes: 8444
def main():
    *a, = map(int, input().split())
    st = set(a)
    print('Yes' if len(st) == 2 else 'No')


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  // abs, sin, cos, tan
#include <ctime> // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, m; cin >> n >> m;
  vll path(n);
  rep(i, n)
  {
    path[i] = i;
  }
  vvll loot(n);
  vll a(m), b(m);
  rep(i, m)
  {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    loot[a[i]].pb(b[i]);
    loot[b[i]].pb(a[i]);
  }
  ll ans = 0;
  do
  {
    ll flag = 1;
    for(ll i = 0;i < n - 1;i++)
    {
      for(ll j = 0;j < loot[path[i]].size();j++)
      {
        if(path[i + 1] == loot[path[i]][j])
        {
          flag++;
          break;
        }
      }
    }
    if(flag == n&&path[0] == 0) ans++;
  } while (next_permutation(all(path)));
  fin(ans);
  return;
}

//前処理
int main()
{
  int ti = clock();
  srand((unsigned)time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); //0埋め４桁
  Main();
  //printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); // 実行時間計測
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <list>

using namespace std;

int main(){
	int n, q;
	int cnt = 0;
	cin >> n;
	list<int> A;
	list<int>::iterator it;
	for(int i; i < n; i++){
		int x;
		cin >> x;
		A.push_front(x);
	}
	cin >> q;
	int B[q];
	for(int i = 0; i < q; i++){
		cin >> B[i];
		for(it = A.begin(); it != A.end();it++){
			if(B[i] == *it){
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
#include <algorithm>
// #include <atcoder/all>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define rall(hoge) (hoge).rbegin(), (hoge).rend()
#define en '\n'
using Edge = pair<ll, ll>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
template <class T> bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x,y)*y ;}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin >> n >> m;
    priority_queue<ll> q;
    rep(i,n) {
        ll a;
        cin >> a;
        q.push(a);
    }

    ll res = 0;
    rep(i,m) {
        ll tmp = q.top();
        q.pop();
        q.push(tmp/2);
    }

    while (!q.empty()) {
        res += q.top();
        q.pop();
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4276
#include<stdio.h>

int main()
{
	int A,B,K,i,counter;
	counter = 0;
	scanf("%d %d %d",&A,&B,&K);
	for(i=100;i>=1;i--){
		if(A % i == 0 && B % i == 0)
		counter++;
		if(counter == K){
			printf("%d",i);
			break;
		};
	};
}

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

int main() {
	int ans,i,j,k,f,e,u[60000],v;
	string c,a,b,z1,z2,z3;
	stack<string> s[2];
	while(cin >> c) {
		if (c[0]=='0') break;
		for (i=0;i<60000;i++) u[i]=0; v=f=0; ans=-1;
		z1=z2=z3=""; z1.append(c.size(),'r'); z2.append(c.size(),'g'); z3.append(c.size(),'b');
		s[f].push(c);
		while(!s[f].empty()) {
			ans++;
			while(!s[f].empty()) {
				c=s[f].top(); s[f].pop();
				if (c==z1 || c==z2 || c==z3) { v=1; break;} 
				for (i=0; i<c.size()-1; i++) {
				  a=c[i]; b=c[i+1];
			      if (c[i]==c[i+1]) continue;
			      if ((a=="r" && b=="g") || (a=="g" && b=="r")) c[i]=c[i+1]='b';
			      if ((a=="b" && b=="r") || (a=="r" && b=="b")) c[i]=c[i+1]='g';	 	
			      if ((a=="b" && b=="g") || (a=="g" && b=="b")) c[i]=c[i+1]='r';
			      for (j=0,k=1,e=0;j<c.size();j++,k*=3) if (c[j]=='g') e+=k; else if (c[j]=='b') e+=2*k;
			      if (u[e]==0) { u[e]=1; s[1-f].push(c);}
			      c[i]=a[0]; c[i+1]=b[0];
				  }
				}
				if (v==1) {
					 while(!s[f].empty()) s[f].pop();
					 while(!s[1-f].empty()) s[1-f].pop();
					 break;
				 } 
				f=1-f;
		 }
		 if (v==1) cout << ans << endl; else cout << "NA" << endl;
	 }
	return 0;
}

Measured memory_bytes: 1628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  string s;
  cin>>s;
  vector<int>a(4);
  rep(i,4) a[i]=s[i]-'0';
  for(int tmp=0;tmp<(1<<3);tmp++){
    bitset<4>t(tmp);
    int sum=a[0];
    string str;
    str+=(char)(a[0]+'0');
    rep(i,3){
      if(t.test(i)){
        str+='+';
        sum+=a[i+1];
      }
      else{
        str+='-';
        sum-=a[i+1];
      }
      str+=s[i+1];
    }
    if(sum==7){
      str+="=7";
      cout<<str<<endl;
      return 0;
    }
  }
  
}
        

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	string s, t = "";
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] == 'B' && i < n - 1 && s[i + 1] == 'C') {
			t = t + 'D';
			i++;
		} else {
			t = t + s[i];
		}
	}
	int m  = t.size();
	ll cnt = 0, ans = 0;
	for (int i = 0; i < m; i++) {
		if (t[i] == 'A') {
			cnt++;
		} else if (t[i] == 'D') {
			ans += cnt;
		} else {
			cnt = 0;
		}
	}
	dump(ans);
	return 0;
}

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

#define int long long

using namespace std;

int32_t main()
{
	int n;
	cin >> n;

	int m = (n*(n+1))/2;
	m -= (((n/3)*(n/3+1))/2)*3;
	m -= (((n/5)*(n/5+1))/2)*5;
	m += (((n/15)*(n/15+1))/2)*15;

	cout << m << endl;
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
bool check_prime(int n)
{
    if(n == 1)
    {
        return false;
    }
    for(int i = 2;i <= sqrt(n);i++)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        if(check_prime(a))
        {
            ans++;
        }
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {

	int[][] graph;
	int[][] weight;
	int maxValue, maxCnt;
	int N;
	boolean[] visited;
	static final int MOD = 10007;
	
	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			N = in.nextInt();
			if(N == 0) return ;
			graph = new int[N][2];
			weight = new int[N][2];
			visited = new boolean[N];
			for(int i=0; i<N; i++){
				for(int j=0; j<2; j++){
					int x = Integer.parseInt(in.next()), fx = Integer.parseInt(in.next());
					graph[i][j] = x;
					weight[i][j] = fx;
				}
			}
			System.out.println(solve());
		}
	}

	int solve(){
		int ret = 1;
		for(int i=0; i<N; i++)if(!visited[i]){
			maxValue = weight[i][1]; maxCnt = 1;
			dfs(i);
			ret = (ret*(maxCnt%MOD))%MOD;
		}
		return ret;
	}

	void dfs(int v){
		for(;;){
			visited[v] = true;
			boolean end = true;
			for(int i=0; i<2; i++){
				if(!visited[graph[v][i]]){
					if(maxValue <= weight[v][i]){
						if(maxValue == weight[v][i]){
							maxCnt++;
						}
						else{
							maxValue = weight[v][i];
							maxCnt = 1;
						}
					}
					v = graph[v][i];
					end = false;
					break;
				}
			}
			if(end) return ;
		}
	}

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

Measured memory_bytes: 13000
# C - Guess The Number
def guess_number(N: int, conditions: list) -> int:
    if N > 1 and any(cond == (1, 0) for cond in conditions):  # 1st digit mustn't be 0 if N > 1
        return -1
    result = [-1] * N
    for digit, num in conditions:
        if result[-digit] >= 0 and result[-digit] != num:
            return -1
        result[-digit] = num
    if result[-1] == -1:  # 1st digit must be 1 if N > 1 (no leading zeros)
        result[-1] = 1 if N > 1 else 0
    return sum(x * (10 ** i) if x != -1 else 0 for i, x in enumerate(result))


def main():
    N, M, *SC = map(int, open(0).read().split())
    conditions = list(zip(*[iter(SC)] * 2))
    ans = guess_number(N, conditions)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]


def dfs(i, a, b, c):
    if i == n:
        if 1 > a or 1 > b or 1 > c:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int inf=2e9;
int n,k,h[100010],f[100010];
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
		f[i]=inf;
	}
	f[1]=0;
	for (int i=1;i<n;i++)
	{
		for (int j=1;j<=k && i+j<=n;j++)
		{
			f[i+j]=min(f[i+j],f[i]+abs(h[i]-h[i+j]));
		}
	}
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = 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")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let x = read::<usize>();
    let mut xx = (0..n).map(|_| read::<usize>()).collect::<Vec<_>>();
    if n == 1 {
        let diff = if x < xx[0] { xx[0] - x } else { x - xx[0] };
        if diff == 0 {
            println!("1000000000")
        } else {
            if x < xx[0] {
                println!("{}", diff)
            } else {
                println!("{}", diff)
            }
        }
        return;
    }

    xx.sort();

    let mut dist = vec![];
    if x < xx[0] {
        dist.push(xx[0] - x)
    }

    for i in 1..n {
        if xx[i - 1] < x && x < xx[i] {
            dist.push(x - xx[i - 1]);
            dist.push(xx[i] - x);
        } else {
            dist.push(xx[i] - xx[i - 1]);
        }
    }

    let mut g = dist[0];
    for i in 1..dist.len() {
        g = gcd(g, dist[i])
    }

    println!("{}", g);

    fn gcd(a: usize, b: usize) -> usize {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }
}


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

int main(){
    long long n, a, b;

    cin >> n >> a >> b;

    if((b-a) % 2 == 0){
        printf("%lld\n", (b-a)/2);
        return 0;
    }

    if(a-1 <= n-b){
        if(b-a == 1){
            printf("%lld\n", b-1);
        }
        else{
            printf("%lld\n", a + (b-a-1)/2);
        }
    }
    else{
        if(b-a == 1){
            printf("%lld\n", n-a);
        }
        else{
            printf("%lld\n", n-b+1 +(b-a-1)/2);
        }
    }
    return 0;
}

Measured memory_bytes: 256
X,Y = map(int, input().split())

total_prize = 0

if X==1:
  total_prize += 300000
if X==2:
  total_prize += 200000
if X==3:
  total_prize += 100000
if Y==1:
  total_prize += 300000
if Y==2:
  total_prize += 200000
if Y==3:
  total_prize += 100000
if X==1 and Y==1:
  total_prize += 400000
print(total_prize)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
//#define ivorysi
#define MAXN 100005
#define eps 1e-7
#define mo 974711
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
int64 A,B;
int Q;
int64 calc(int64 X,int64 MID) {
	int64 s = MID,t = X - MID + 2;
	if(s >= A) ++s;
	if(t <= B) --t;
	return  s * t;
}
int64 get_Max(int64 X,int64 L,int64 R) {
    while(R - L + 1 >= 3) {
    	int64 K = (R - L + 1) / 3;
    	int64 LB = L + K,RB = R - K;
    	if(calc(X,LB) < calc(X,RB)) L = LB;
    	else R = RB;
    }
    int64 ans = 0;
    for(int64 i = L ; i <= R ; ++i) ans = max(ans,calc(X,i));
    return ans;
}
int64 check(int64 MID) {
	int64 res = 0;
	res = max(get_Max(MID,1,A - 1),res);
	res = max(get_Max(MID,MID - A + 2,MID),res);
	res = max(get_Max(MID,1,B - 1),res);
	res = max(get_Max(MID,MID - B + 2,MID),res);
	res = max(get_Max(MID,A,B),res);
	res = max(get_Max(MID,A,MID - B + 2),res);
	res = max(get_Max(MID,B,MID - A + 2),res);
	return res;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    scanf("%d",&Q);
    while(Q--) {
	    scanf("%lld%lld",&A,&B);
	    if(A > B) swap(A,B);
	    int64 P = A * B;
	    int64 L = 0,R = (A + B);
	    while(L < R) {
	        int64 MID = (L + R + 1) >> 1;
	        if(check(MID) < P) L = MID;
	        else R = MID - 1;
	    }
	    printf("%lld\n",L);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v) cout << i << ' ' << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vin2(v, w) for (ll i = 0; i < v.size(); ++i) cin >> v[i] >> w[i];
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }

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

	int N;
	cin >> N;
	vi cnt(4, 0);
	rep(i, N){
		string str;
		cin >> str;
		if(str == "AC")cnt.at(0) += 1;
		if(str == "WA")cnt.at(1) += 1;
		if(str == "TLE")cnt.at(2) += 1;
		if(str == "RE")cnt.at(3) += 1;
	}
	cout << "AC x " << cnt.at(0) << endl;
	cout << "WA x " << cnt.at(1) << endl;
	cout << "TLE x " << cnt.at(2) << endl;
	cout << "RE x " << cnt.at(3) << endl;

}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int n,m;

int a[100100];
int main()
{
    cin>>n;
    int a2=0,a4=0,a3=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0&&a[i]%4!=0) a2++;
        else if(a[i]%4==0) a4++;
        else a3++;
    }
    if(a2==0){
        if(a4>=a3-1) puts("Yes");
        else puts("No");
    }
    else{
        if(a4>=a3) puts("Yes");
        else puts("No");
    }

}


Measured memory_bytes: 640
(let* ((n (read))
       (l (make-array (list 1001) :initial-element 0))
       (ans 0))
  (loop :for i :from 1 :to n
        :for x := (read)
        :do (incf (aref l x)))
  ;;
  (loop :for a :from 1 :to 1000
        :do (loop :for b :from a :to 1000
                  :do (loop :for c :from b :to (min 1000 (1- (+ a b)))
                            :do (cond ((= a b c)
                                       (incf ans (/ (* (aref l a) (- (aref l a) 1) (- (aref l a) 2)) 6)))
                                      ((= a b)
                                       (incf ans (/ (* (aref l a) (- (aref l a) 1) (aref l c)) 2)))
                                      ((= b c)
                                       (incf ans (/ (* (aref l b) (- (aref l b) 1) (aref l a)) 2)))
                                      (t
                                       (incf ans (* (aref l a) (aref l b) (aref l c))))))))
  (format t "~A~%" ans))


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

int main() {
  int N; cin >> N;
  vector<string> S;

  for (int i = 0; i < N; i++) {
    string s; cin >> s;

    S.push_back(s);
  }

  sort(S.begin(), S.end());

  map<string, int> m;
  int largest = 0;
  for (int i = 0; i < S.size(); i++) {
    m[S[i]]++;
    largest = max(largest, m[S[i]]);
  }

  for (auto it = m.begin(); it != m.end(); it++) {
    if (it->second == largest) {
      cout << it->first << endl;
    }
  }
}


Measured memory_bytes: 26736
class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}
	end

	def accum!
		(1..size-1).each{|i|
			self[i] += self[i-1]
		}
		self.unshift(0)
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end

	def accum_2d!
		each{|r| r.accum!}
		(1..size-1).each{|i|
			(1..self[0].size-1).each{|j|
				self[i][j] += self[i-1][j]
			}
		}
		unshift([0] * self[0].size)
	end
		
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

require 'prime'
primes = Prime.each(100000).to_a

loop {
	m, a, b = gets.split.map &:to_i
	break if m == 0

	max = 0
	by = nil
	k = primes.bsearch_last_index{|x| x * 2 <= m}
	k.downto(0){|i|
		p1 = primes[i]
		break if p1 * p1 <= max

		p2 = primes.bsearch_last_item(0,i){|p2| p2 * p1 <= m}
		next if !p2
		
		if p2 * b >= a * p1 && p1 * p2 > max
			by = [p2, p1]
			max = p1 * p2
		end
	}
	puts by.join(" ")
}

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

 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;

//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const LL INF=LONG_MAX;
const double EPS=0.00001;
const long double PI = acos(-1.0);


#define index_of(as, x) distance(as.begin(), lower_bound(as.begin(), as.end(), x))
LL lis_fast(const vector<LL>& a) {
  const int n = a.size();
  vector<LL> A(n, INF);
  vector<LL> id(n);
  for (int i = 0; i < n; ++i) {
    id[i] = index_of(A, a[i]);
    A[ id[i] ] = a[i];
  }
  LL m = *max_element(id.begin(), id.end());
  /*vector<LL> b(m+1);
  for (int i = n-1; i >= 0; --i)
    if (id[i] == m) b[m--] = a[i];*/
  return m+1LL;
}

int main(){
    ios::sync_with_stdio(false);
    LL x[2],y[2];
    cin>>x[0]>>y[0]>>x[1]>>y[1];

    if(x[0]>x[1]){
        swap(x[0],x[1]);swap(y[0],y[1]);
    }
    LL c=1;
    if(y[0]>y[1]){
        c=-1;
    }
    int N;
    cin>>N;
    vector<PLL>XY,YX;
    long double qt=5.0L*PI;

    REP(i,N){
        LL X,Y;
        cin>>X>>Y;
        if(X>=x[0]&&X<=x[1]&&Y>=min(y[0],y[1])&&Y<=max(y[0],y[1])){
            XY.PB(MP(X,c*Y));
            //YX.PB(MP(c*Y,c*X));
        }
    }
    long double sum=abs(y[1]-y[0])+abs(x[1]-x[0]);
    if(x[0]==x[1]||y[0]==y[1]){
        cout<<fixed<<setprecision(20)<<sum*100.0L+(long double)SZ(XY)*(qt*2.0L-20.0L)<<endl;
        return 0;
    }
    SORT(XY);
    vector<LL>a;
    long double res1=0;
    if(SZ(XY)){
        REP(i,SZ(XY))a.PB(XY[i].second);
        res1=lis_fast(a);
    }
    //cout<<res1<<" "<<res2<<endl;
    if(res1==(abs(x[1]-x[0])+1)||res1==(abs(y[1]-y[0])+1)){
        cout<<fixed<<setprecision(20)<<sum*100.0L+(res1-1.0L)*(qt-20.0L)+(qt*2.0L-20.0L)<<endl;
    }else{
        cout<<fixed<<setprecision(20)<<sum*100.0L+res1*(qt-20.0L)<<endl;
    }
    return 0;
}

Measured memory_bytes: 9452
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
int bobo[1000000];
int next_go[1000000];
int xoring[1000000];
int main(){
	int m, k;
	cin >> m >> k;
	if (k == 0) {
		REP(i, (1 << m)) {
			cout << i << " " << i << " ";
		}
		cout << endl;
		return 0;
	}
	if (k >= (1 << m)) {
		cout << -1 << endl;
		return 0;
	}
	vector<int> geko;
	geko.push_back(0);
	geko.push_back(k);
	geko.push_back(0);
	for (int i = 1; i < (1 << m); ++i) {
		if (i != k) {
			geko.push_back(i);
		}
	}
	geko.push_back(k);
	for (int i = (1 << m)-1; i >= 1; --i) {
		if (i != k) {
			geko.push_back(i);
		}
	}
	REP(i, geko.size()) {
		xoring[i + 1] = xoring[i];
		xoring[i + 1] ^= geko[i];
	}
	for (int i = geko.size() - 1; i >= 0;--i) {
		if (next_go[geko[i]] == 0) {
			next_go[geko[i]] = i + 1;
		}
		else {
			int bobo = xoring[next_go[geko[i]]] ^ xoring[i];
			if (bobo != k) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	REP(i, geko.size()) {
		cout << geko[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 11124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
		int N = Integer.parseInt(tokenizer.nextToken());
		int R = Integer.parseInt(tokenizer.nextToken());
		int L = Integer.parseInt(tokenizer.nextToken());
		int[] po = new int[N];
		int[] c = new int[N];
		int now = 0;
		int index = 0;

		for (int i = 0; i < R; i++) {
			tokenizer = new StringTokenizer(reader.readLine());
			int d = Integer.parseInt(tokenizer.nextToken()) - 1;
			int t = Integer.parseInt(tokenizer.nextToken());
			int x = Integer.parseInt(tokenizer.nextToken());
			c[index] += t - now;
			po[d] += x;
			now = t;
			if (x > 0) {
				if (d == index)
					continue;
				if (po[index] < po[d])
					index = d;
				else if (po[index] == po[d] && index > d)
					index = d;
			} else {
				if (d != index)
					continue;
				int maxp = Integer.MIN_VALUE;
				for (int j = 0; j < N; j++) {
					if (maxp < po[j]) {
						maxp = po[j];
						index = j;
					}
				}
			}

			
		}
		c[index] += L - now;
		int ans = 0;
		int max = 0;
		for (int i = 0; i < N; i++) {
			if (c[i] > max) {
				max = c[i];
				ans = i;
			}
		}
		System.out.println(ans + 1);

	}
}

Measured memory_bytes: 91132
N, W = map(int, input().split())
v, w = [0], [0]
for _ in range(N):
    a, b = map(int, input().split())
    v.append(a)
    w.append(b)
    
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, W+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i])
print(dp[N][W])


Measured memory_bytes: 25492
#include<stdio.h>
int main(){
  int h,w,i,j,k,num=0;
  int a[501][501];
  static int ans[251000][4];
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf("%d",&(a[i][j]));
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(a[i][j]%2==1&&(i!=h-1||j!=w-1)){
        if(j!=(w-1)){
          a[i][j+1]++;
          ans[num][0]=i+1;
          ans[num][1]=j+1;
          ans[num][2]=i+1;
          ans[num][3]=j+2;
        }
        else{
          a[i+1][j]++;
          ans[num][0]=i+1;
          ans[num][1]=j+1;
          ans[num][2]=i+2;
          ans[num][3]=j+1;
        }
        num++;
      }
    }
  }
  printf("%d\n",num);
  for(k=0;k<num;k++){
    printf("%d %d %d %d\n",ans[k][0],ans[k][1],ans[k][2],ans[k][3]);
  }
  return 0;
}

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

int main(){
  int n, x;

  while(cin>>n){
    for(int i = 0; i < n; ++i){
      if(i==0){
	x=2;
      }else x += (1 + i);
    }
    cout << x << endl;
    
  }
    
  return 0;
}



Measured memory_bytes: 3064
/* ex3_3 "Digits"
   dada__        */
#include<stdio.h>
int main(void){
    int integerN, k, digits;
    digits = 0;
    scanf("%d", &integerN); scanf("%d", &k); //N, Kの入力

    while(integerN){ //nが0になった時点でループ終了
        integerN /= k;  //nにkで割った商を代入
        digits++; //桁数のカウント
    }

    printf("%d\n", digits); //桁数の出力
    return 0;
}

Measured memory_bytes: 128
using System.Linq;
using System.Collections.Generic;
using System;

class A {
    static int N;
    static int[] L;
    static void Main() {
        N = int.Parse(Console.ReadLine());
        L = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Array.Sort(L);
        int cnt = 0;
        if (L.Length % 2 == 0) {
            for(int i = 0; i < L.Length; i += 2) {
                cnt += L[i];
            }
        }
        else {
            for(int i = 1; i < L.Length; i += 2) {
                cnt += L[i];
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
const int MOD = 1331;
using namespace std;
const int N = 1e5 + 10;
int n;
int main(){
	// freopen("in.txt", "r", stdin);
	int a, b, c;
	cin >> a >> b >> c;
	int k;
	cin >> k;
	while (b <= a && k) {
		b *= 2;
		k--;
	}
	while (c <= b && k) {
		c *= 2;
		k--;
	}
	if (b > a && c > b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i * 2 < s.size(); i++) {
    if (s[i] != s[s.size() - 1 - i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n,m,k,t;
    while(scanf("%d",&k)!=EOF)
    {
        int x,y,z,f=1;
        x=0;y=0;z=0;
        for (int i=0;i<k;i++)
        {
            scanf("%d%d%d",&t,&n,&m);
            int h,p;
            p=t-z;
            h=abs(n-x)+abs(m-y);
            x=n; y=m; z=t;
            if (!(p%2==h%2&&t>=h)) f=0;
        }
        if (f==1) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = 0;
    for (int i = 0; i < a.size(); i++) {
        cin >> a[i];
        ans += a[i];
    }
    
    int m;
    cin >> m;
    
    for (int i = 0; i < m; i++) {
        int p, x;
        cin >> p >> x;
        
        cout << ans - a[p-1] + x << '\n';
        
    }
    
    
    
    
    
    
    return 0;
}



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

using namespace std;

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

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

    vector<long long> s(n, a[0]);
    for (int i = 1; i < n; i++) {
        s[i] = s[i-1] + a[i];
    }

    vector<int> f(n-2);
    int l = 0, r = 1;
    while (r < n-2) {
        while (l < n-3 && abs(s[r]-2*s[l]) > abs(s[r]-2*s[l+1])) {
            l++;
        }
        f[r] = l;
        r++;
    }

    vector<int> g(n-2);
    l = 1, r = 2;
    while (l < n-2) {
        while (r < n-1 && abs(s[n-1]-2*s[r]+s[l]) > abs(s[n-1]-2*s[r+1]+s[l])) {
            r++;
        }
        g[l] = r;
        l++;
    }

    vector<long long> ans(n-2);
    for (int i = 1; i < n-2; i++){
        ans[i] = max({s[f[i]], s[i]-s[f[i]], s[g[i]]-s[i], s[n-1]-s[g[i]]})
            - min({s[f[i]], s[i]-s[f[i]], s[g[i]]-s[i], s[n-1]-s[g[i]]});
    }

    cout << *min_element(ans.begin()+1, ans.end()) << endl;
}


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

int n, k, d, a, nums[1000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> d;
        for (int k = 0; k < d; k++)
        {
            cin >> a;
            nums[a]++;
        }
    }

    int c = 0;

    for (int i = 1; i <= n; i++)
    {
        if (nums[i] == 0)
        {
            c++;
        }
    }

    cout << c;
}

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

class UnionFind{
	public:
		vector<int> Parent;
		vector<int> Rank;
		UnionFind(int n){
			++n;
			Parent.resize(n, 0);
			Rank.resize(n, 0);
			for(int i=0; i<n; ++i){
				Parent[i] = i;
				Rank[i] = 0;
			}
		}

		int find(int x){
			if(Parent[x] == x) return x;
			return Parent[x] = find(Parent[x]);
		}

		void unite(int x, int y){
			x = find(x);
			y = find(y);
			if(x == y) return;
			if(Rank[x] < Rank[y]) Parent[x] = y;
			else{
				Parent[y] = x;
				if(Rank[x] == Rank[y]) ++Rank[x];
			}
		}

		bool same(int x, int y){
			return find(x) == find(y);
		}
};

int main(){
	int n, q;
	cin >> n >> q;
	UnionFind uf(n);
	for(int i=0; i<q; ++i){
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) uf.unite(x, y);
		else cout << (uf.same(x, y) ? 1 : 0) << endl;
	}
}


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

const ll INF = 1000000009;

void solve(){
  ll ans = 0;
  int k;
  cin >> k;
  for(int a = 1; a <= k; a++)
    for(int b = 1; b <= k; b++) 
      for(int c = 1; c <= k; c++)
        ans += __gcd(__gcd(a,b),c);
  cout << ans << "\n";
}

int main(){
#ifndef LOCAL
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#endif
  // int t;cin >> t;while(t--) solve();
  solve();
}


Measured memory_bytes: 3620
import java.io.*;
import java.util.*;

public class Main {
	String check( String card ) {
		int one = card.indexOf("1");
		int two = card.indexOf("2");
		if ( card.indexOf("4") != -1 )
			return "four card";
		else if ( card.indexOf("3") != -1 ) {
			if ( two != -1 )
				 return "full house";
			else
				return "three card";
		} else if ( two != card.lastIndexOf("2") )
			return "two pair";
		else if ( two != -1 )
			return "one pair";
		else {
			if ( card.charAt(0)=='1' && card.charAt(9)=='1' && card.charAt(10)=='1' && card.charAt(11)=='1' && card.charAt(12)=='1')
				return "straight";
			for ( int i = one+1; i < one+5; i++ )
				if ( card.charAt(one) != card.charAt(i) ) return "null";
			return "straight";
		}
	}
	public static void main ( String[] args ) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("[\n,]");
		Main m = new Main();
		int[] cards;
		while ( sc.hasNext() ) {
			String card = "";
			cards = new int[13];
			for ( int i = 0; i < 5; i++ )
				cards[sc.nextInt()-1]++;
			for ( int i = 0; i < cards.length; i++ )
				card += cards[i];
			String result = m.check(card);
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 11000
MOD = 10 ** 9 + 7
FACT_MAX = 2001
fact = [1] * FACT_MAX
for i in range(1, FACT_MAX):
    fact[i] = fact[i - 1] * i % MOD
def comb(n, r):
    return 0 if n < r else fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD) % MOD

N, K = map(int, input().split())
for i in range(1, K + 1):
    print(comb(N - K + 1, i) * comb(K - 1, i - 1) % MOD)

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

int main(void){
	int N;
	ll K;
	cin >> N >> K;
	int P[N+1];
	rep(i,N) cin >> P[i+1];
	ll C[N+1];
	rep(i,N) cin >> C[i+1];

	ll ans = -1e10;
	for (int i = 1; i <= N; i++) {
		ll tot = 0;
		int period = 0;
		int j = i;
		vector<ll> v;
		while (1) {
			j = P[j];
			tot += C[j];
			v.push_back(C[j]);
			period++;
			if (j == i) break;
		}

		ll cand;
		ll tmp = 0;
		rep(j, v.size()) {
			if (j+1>K) break;
			tmp+=v[j];
			cand = tmp;
			if (tot>0) {
				cand += tot*((K-j-1)/period);
			}
			ans = max(ans, cand);
		}
	}

	cout << ans << endl;

return 0;
}


Measured memory_bytes: 3800
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        System.out.println(a+a*a+a*a*a);
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 32452
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        if((A==B && B==C) || (A!=B) && B!= C && C != A) {
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
        return;
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
char s[N];
ll l,r,len,border,sta[N],suf[N],ans[N];
int n,top,nxt[N];
void query(ll len,int d){
	map<ll,ll> m;
	m[-len]=1;
	for (int i=top;i;i--){
		ll T=sta[i];
		for (map<ll,ll>::iterator i=m.begin();i!=m.end();++i){
			ll len=-i->first,cnt=i->second;
			if (len<=T) continue;
			m[-T]+=cnt*(len/T);
			m[-len%T]+=cnt;
		}
		while (-m.begin()->first>T) m.erase(m.begin());
	}
	for (map<ll,ll>::iterator i=m.begin();i!=m.end();++i) suf[-i->first]+=d*i->second;
}
int main()
{
	scanf("%s%lld%lld",s+1,&l,&r);
	n=len=sta[top=1]=strlen(s+1);
	for (int i=2;i<=n;i++){
		int j=nxt[i-1];
		while (j&&s[j+1]!=s[i]) j=nxt[j];
		nxt[i]=(s[j+1]==s[i]?j+1:0);
	}
	border=nxt[n/2];
	while (len<r){
		while (sta[top]>len-border) top--;
		sta[++top]=len-border;
		sta[++top]=2*(len-border);
		border=len/2-border;
		len=sta[top];
	}
	query(r,1);query(l-1,-1);
	for (int i=n;i;i--) suf[i]+=suf[i+1],ans[s[i]]+=suf[i];
	for (int i='a';i<='z';i++) printf("%lld ",ans[i]);
	puts("");
	return 0;
}

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

int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(a,b)+min(c,d)<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,M;
  cin>>N>>M;
  if(N>=2&&M>=2){
    cout<<(N-2)*(M-2)<<endl;
  }
  else if(N==1&&M!=1){
    cout<<M-2<<endl;
  }
  else if(M==1&&N!=1){
    cout<<N-2<<endl;
  }
  else if(M==1&&N==1){
    cout<<1<<endl;
  }
}
  


Measured memory_bytes: 256