akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--n >= 0){
        string s;
        cin >> s;

        sort(s.rbegin(), s.rend());
        int ret = atoi(s.c_str());
        sort(s.begin(), s.end());
        ret -= atoi(s.c_str());
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll memo[60][60][110];
vl V;
ll N, K;

ll dfs(ll l, ll r, ll k){
    if(k == 0) return 0;
    if(l > r || l < 0 || r < 0 || l >= N || r >= N) return 0;
    if(memo[l][r][k] != -LINF) return memo[l][r][k];
    ll ans = 0;
    ans = max(ans, dfs(l+1, r, k-1) + V[l]);
    if(k >= 2) ans = max(ans, dfs(l+1, r, k-2));
    ans = max(ans, dfs(l,r-1,k-1) + V[r]);
    if(k >= 2) ans = max(ans, dfs(l, r-1, k-2));
    
    return memo[l][r][k] = ans;
}

int main(){
    cin >> N >> K;
    V = vl(N, 0); REP(i, N) cin >> V[i];
    REP(i, 60) REP(j, 60) REP(ii, 110) memo[i][j][ii] = -LINF;
    ll ans = dfs(0,N-1,K);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>

using namespace std;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

string s[] = {"light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"};
double t[] = {48,51,54,57,60,64,69,75,81,91};

int main()
{
	double d;
	while(cin>>d){
		int i = lower_bound(t,t+sizeof(t) / 8,d)-t;
		cout << s[i] << endl;
	}
}

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

int main() {
    int N;
    cin >> N;
    int W[N];

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

    int S = 0;
    for(int i = 0; i < N; i++) {
        S += W[i];
    }

    int S_1[N];
    int S_2[N];
    int a[N];

    for(int i = 0; i < N; i++) {
        S_1[i] = 0;
        S_2[i] = 0;
        a[i] = 0;
    }

    for(int T = 1; T <= N; T++) {
        for(int i = 0; i < T; i++) {
            S_1[T-1] += W[i]; 
        }

        S_2[T-1] = S - S_1[T-1];
    }

    for(int T = 0; T <= N-1; T++) {
        a[T] = S_1[T] - S_2[T];
        if(a[T] < 0) {
            a[T] *= -1;
        }
    }

    sort(a, a+N);

    cout << a[0];

    cout << endl;
    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    double ave = 0;
    rep(i,n) ave += a[i];
    ave /= n;
    int idx = 0;
    rep(i,n) if(abs(ave - a[idx]) > abs(ave - a[i])) {
        idx = i;
    }
    cout << idx << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
ll p = 1000000007ll;

int main(void)
{
  int t;
  cin >> t;
  while(t--) {
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    priority_queue<pair<ll, ll>> pq; // negc, tmpn;
    pq.emplace(0, n);
    set<ll> already;
    while(!pq.empty()) {
      ll negc;
      tie(negc, n) = pq.top(); pq.pop();
      if(n == 0) {
        cout << -negc << endl;
        break;
      }
      if(!already.insert(n).second) continue;
      // cout << n << negc << endl;
      ll target, diff;
      switch(n%2) {
      case 0:
        target = n/2;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(a, d*diff), target);
        else pq.emplace(negc-a, target);
        break;
      case 1:
        target = n/2;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(a+d, d*diff), target);
        else pq.emplace(negc-a-d, target);
        target = n/2+1;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(a+d, d*diff), target);
        else pq.emplace(negc-a-d, target);
        break;
      }
      switch(n%3) {
      case 0:
        target = n/3;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(b, d*diff), target);
        else pq.emplace(negc-b, target);
        break;
      case 1:
        target = n/3;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(b+d, d*diff), target);
        else pq.emplace(negc-b-d, target);
        break;
      case 2:
        target = n/3+1;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(b+d, d*diff), target);
        else pq.emplace(negc-b-d, target);
        break;
      }
      switch(n%5) {
      case 0:
        target = n/5;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(c, d*diff), target);
        else pq.emplace(negc-c, target);
        break;
      case 1:
        target = n/5;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(c+d, d*diff), target);
        else pq.emplace(negc-c-d, target);
        break;
      case 2:
        target = n/5;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(c+d+d, d*diff), target);
        else pq.emplace(negc-c-d-d, target);
        break;
      case 3:
        target = n/5+1;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(c+d+d, d*diff), target);
        else pq.emplace(negc-c-d-d, target);
        break;
      case 4:
        target = n/5+1;
        diff = n-target;
        if(p>diff) pq.emplace(negc-min(c+d, d*diff), target);
        else pq.emplace(negc-c-d, target);
        break;
      }
    }
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(),a.end()), a.end());
  if(a.size()==n) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 1024
N, A, B = map(int, input().split())

ans = 0
for i in range(N+1):
    q = i
    jdg = 0
    for k in range(5):
        jdg += q%10
        q //= 10
    if A <= jdg and jdg <=B:
        ans += i
print(ans)

Measured memory_bytes: 40048
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines  

import numpy as np

N = int(inp())
A = np.array(inp().split(), dtype=np.int64)
MOD = 10**9+7

ans = 0
for k in range(60):
  x0 = 0 # k桁目のbitが0になる総数
  x1 = 0 # k桁目のbitが1になる総数
  B = (A>>k) & 1 # k桁目が1になる要素
  
  # k桁目が 0, 1 のどちらかを数えておく
  x1 = np.count_nonzero(B)
  x0 = N - x1
  # x0 * x1 が 0, 1 の組み合わせ数
  cmb = x0 * x1
  
  for _ in range(k): # 10進数に変換
    cmb *= 2
    cmb %= MOD
  ans += cmb
print(ans%MOD)  
  

Measured memory_bytes: 36976
#include <bits/stdc++.h>
using namespace std;
#define endl			"\n"
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <ll,ll>
#define vii				vector <ii>
#define ull				unsigned long long
const double PI = 2 * acos(0.0);
void run() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
}
const int M = 1e5;
int n, k;
vi v;
int dp[M + 9];
int sol(int i) {
	if (i > n)
		return 1e9;
	if (i == n)
		return 0;
	int &ret = dp[i];
	if (~ret)
		return ret;
	ret = 1e9;
	for (int j = 1; j <= k; j++) {
		if (j + i <= n)
			ret = min(ret, sol(i + j) + abs(v[i + j] - v[i]));
	}
	return ret;
}
int main() {
	run();
	cin >> n >> k;
	v.resize(n);
	lp(i,n)
		cin >> v[i];
	v.push_back(v.back());
	clr(dp, -1);
	cout << sol(0);
	return 0;
}



Measured memory_bytes: 5752
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

void solve(){
  int n;
  cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  ll x=0;
  rep(i,n)x=gcd(x,a[i]);
  cout<<x;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
ll fonk(ll n){
	return n*n*n*n*n;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	map<int, int> cnt;
	vector<int> vec(n);
	for(int i = 0; i < n; i++){
		cin>>vec[i];
		cnt[i - vec[i]]++;
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		ans += cnt[i+vec[i]];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 21056
N = int(input())

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort(reverse=True)
#print(DeadlineCost)

t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

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

int main() {
	string S;
	cin >> S;
	int count=0;
	for (int i=0; i<S.size()/2; i++){
	    if (S.at(i)!=S.at(S.size()-i-1)) count++;
	}
	cout << count << endl;
}


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

const int _mx = 2e6;
int a[_mx+5];

int main() {
    // freopen("in.txt", "r", stdin);

    int n, q, x, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    for (cin >> q; q--; ) {
        cin >> x;
        int pos = lower_bound(a, a+n, x) - a;
        if (a[pos] == x) ans++;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3140
import numpy as np

N = int(input())

a = list(map(int, input().split()))

a.sort()

a_max = a[N - 1]

ave = a_max / 2


dif = 1000000000
difidx = -1
difidx2 = -1
p = 1
s = 1


for i in range(N):
    an = abs(a[i] - ave)
    if dif > an:
        dif = an
        difidx = i
    elif dif == an:
        difidx2 = i

ans = a[difidx2] if difidx2 > 0 else a[difidx]
ans2 = str(a_max)
if N > 3:
    print(str(a_max) + " " + str(ans))
else:
    if a[0] > a[1]:
        print(str(a[0]) + " " + str(a[1]))
    else:
        print(str(a[1]) + " " + str(a[0]))


Measured memory_bytes: 23132
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		long ans = 1;
		final long mod = 1000000007;
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		Arrays.sort(a);
		if (n%2 != 0 && a[0] != 0) {
			System.out.println(0);
			return;
		} else {
			for (int i =a.length-1; i > 0; i-=2) {
				if (a[i] != a[i-1]) {
					System.out.println(0);
					return;
				}
			}
		}
		for (int i = 0; i < n/2; i++) {
			ans = 2*ans%mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 48004
program main
	implicit none
	integer::ans=0,i,n
    integer,dimension(3005)::a
    read(*,*) n
    read(*,*) (a(i),i=1,n)
    do i=1,n
    	ans=ans+a(i)-1
    end do
    write(*,'(i0)') ans
    stop
end program main


Measured memory_bytes: 2952
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std; 
#define pb push_back 
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define sc(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0&&c>0)
	{
		c-=b;
		if(c>0)
		{
			a-=d;
		}
		else break;
	}
	//cout<<a<<" "<<c<<endl;
	if(a<=0)
	{
		puts("No");
	}
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define loop(i,a,n) for(int i=a;i<n;++i)
#define arrin(arr,n) for(int i=0; i < n; ++i) cin>>arr[i];
#define arrout(arr,n) for(int i=0; i < n; ++i) cout<<arr[i]<<" ";cout<<nl;
#define nl "\n"
#define _USE_MATH_DEFINES
// M_E : e  M_PI :pi  M_SQRT2:sqrt(2)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
struct compare 
{
  bool operator()(const int& l, const int& r) 
  {
      return l > r; //min: > ; max: <
  }
};
  
using namespace std;
priority_queue<int,vector<int>, compare > pq;

int main()
{
  fastio();
  int n, p;
  cin >>n >>p;
  ull e=0,o=0;
  ull x;
  for (int i=0; i<n; i++)
  {
  	cin >>x;
  	if (x%2)
  		o++;
  }
  e=n-o;
  ull ans=pow (2,e);
  if (p==0)
  {
  	ull tmp=1;
  	for (int i=2; i<=o; i+=2)
  	{
  		ull t=1;
  		int ti=i;
  		if (i>o/2)
  			ti=o-i;
  		for (int j=0; j<ti; j++)
  		{
  			t*=(o-j);
  			t/=(j+1);
  		}
  		tmp+=t;
  	}
  	cout <<ans*tmp<<nl;
  }
  else {
	ull tmp=0;
  	for (int i=1; i<=o; i+=2)
  	{
  		ull t=1;
  		int ti=i;
  		if (i>o/2)
  			ti=o-i;
  		for (int j=0; j<ti; j++)
  		{
  			t*=(o-j);
  			t/=(j+1);
  		}
  		tmp+=t;
  	}
  	cout <<ans*tmp<<nl;
  
  }
}


Measured memory_bytes: 256
H, W, N = map(int, input().split())
sy, sx = map(int, input().split())
S = input()
T = input()
S = S[::-1]
T = T[::-1]

safe_y = [1, H]
safe_x = [1, W]
flg = 1
for i in range(N):
    if T[i] == 'L':
        if safe_x[1] != W:
            safe_x[1] += 1
    elif T[i] == 'R':
        if safe_x[0] != 1:
            safe_x[0] -= 1
    elif T[i] == 'U':
        if safe_y[1] != H:
            safe_y[1] += 1
    elif T[i] == 'D':
        if safe_y[0] != 1:
            safe_y[0] -= 1
    if S[i] == 'L':
        safe_x[0] += 1
    elif S[i] == 'R':
        safe_x[1] -= 1
    elif S[i] == 'U':
        safe_y[0] += 1
    elif S[i] == 'D':
        safe_y[1] -= 1
    if safe_y[1] - safe_y[0] < 0 or safe_x[1] - safe_x[0] < 0:
        flg = 0
        break

if flg:
    if safe_y[0] <= sy <= safe_y[1] and safe_x[0] <= sx <= safe_x[1]:
        pass
    else:
        flg = 0

print('YES' if flg else 'NO')


Measured memory_bytes: 47024
program three_variables_game
  implicit none
  integer :: n, r(4) = 0, x(100001) = 0, i, j, p(2) = 0
  character(1) :: c(4) = (/ "A", "B", "X", "C" /)
  character(2) :: s
  read(*,*) n, r(1), r(2), r(4)
  if (sum(r) == 0) then
    write(*,'(a)') "No"
    stop
  end if
  do i = 1, n
    read(*,*) s
    x(i) = hash(s)
  end do
  if (sum(r) == 1) then
    j = maxloc(r,1)
    call simulate(.false.)
    r = 0
    r(j) = 1
    call simulate(.true.)
    stop
  end if
  call get_index(x(1),p)
  if (r(p(1)) == 0 .and. r(p(2)) == 0) then
    write(*,'(a)') "No"
    stop
  else
    write(*,'(a)') "Yes"
  end if
  do i = 1, n
    call get_index(x(i),p)
    if (sum(r) == 2 .and. r(p(1))*r(p(2)) == 1 .and. i < n .and. x(i) /= x(i+1)) then
      j = 1
      if (p(2) == and(x(i),x(i+1))) j = 2
      r(p(j)) = r(p(j))+1
      r(p(3-j)) = r(p(3-j))-1
      write(*,'(a)') c(p(j))
    else if (r(p(1)) > r(p(2))) then
      r(p(1)) = r(p(1))-1
      r(p(2)) = r(p(2))+1
      write(*,'(a)') c(p(2))
    else
      r(p(1)) = r(p(1))+1
      r(p(2)) = r(p(2))-1
      write(*,'(a)') c(p(1))
    end if
  end do
contains
  integer function hash(s)
    character(2), intent(in) :: s
    select case (s)
      case ("AB")
        hash = 3
      case ("AC")
        hash = 5
      case ("BC")
        hash = 6
    end select
  end
  subroutine get_index(x,p)
    integer, intent(in) :: x
    integer, intent(out) :: p(2)
    integer :: i, k
    i = 0
    do k = 0, 2
      if (.not.btest(x,k)) cycle
      i = i+1
      p(i) = lshift(1,k)
    end do
  end
  subroutine simulate(out)
    logical, intent(in) :: out
    if (out) write(*,'(a)') "Yes"
    do i = 1, n
      call get_index(x(i),p)
      if (r(p(1)) /= 0) then
        r(p(1)) = r(p(1))-1
        r(p(2)) = r(p(2))+1
        if (out) write(*,'(a)') c(p(2))
      else if (r(p(2)) /= 0) then
        r(p(1)) = r(p(1))+1
        r(p(2)) = r(p(2))-1
        if (out) write(*,'(a)') c(p(1))
      else
        write(*,'(a)') "No"
        stop
      end if
    end do
  end
end program three_variables_game

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

int main() {
  int n;
  cin >> n;
  unordered_map<int, int> mp;

  for (int i = 2; i <= n; ++i) {
    int t = i;
    int j = 2;
    while (t != 1) {
      if (t % j == 0)
        t /= j, mp[j]++;
      else
        j++;
    }
  }

  ll ans = 1;
  for (auto m : mp) ans = ans * (m.second + 1) % MOD;

  cout << ans << endl;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let (x, y) = i::u2();
    let mut ans = 1;
    let mut x = x;
    while x * 2 <= y {
        ans += 1;
        x *= 2;
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f;
LL n, m, s, t, h, w, dp[100][5];
int main() {
	cin >> n;
	LL log2_n = log2(n);
	if ((1 << log2_n) <= n) {
		LL num = (n >> log2_n) - (((LL)1 << log2_n) >> log2_n);
		dp[log2_n][(num >= 2 ? 2 : num)] += 1;
	}
	if (1) {
		LL num = (n >> log2_n);
		dp[log2_n][(num >= 2 ? 2 : num)] += 1;
	}
	for (int i = log2_n-1; i >= 0;i--) {
		rep(j, 3) {
			if (j != 2) {
				LL now = ((n >> (i + 1)) - j) << (i + 1);
				if (now + (1 << (i + 1)) <= n) {
					LL num = (n >> i) - ((now + ((LL)1 << (i + 1))) >> i);
					dp[i][(num >= 2 ? 2 : num)] += dp[i + 1][j];
				}
				if (now +  (1 << i) <= n) {
					LL num = (n >> i) - ((now + ((LL)1 << i)) >> i);
					dp[i][(num >= 2 ? 2 : num)] += dp[i + 1][j];
				}
				if (now <= n) {
					LL num = (n >> i) - (now >> i);
					dp[i][(num >= 2 ? 2 : num)] += dp[i + 1][j];
				}
			}
			else {
				dp[i][j] += dp[i + 1][j] * 3;
			}
		}
		rep(j, 3)dp[i][j] %= MOD;
	}
	cout << (dp[0][0] + dp[0][1] + dp[0][2])%MOD << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

#define K	1344	/* https://oeis.org/A066150 */
#define MD	1000000007
#define V2	500000004

long long power(int a, int k) {
	long long b = a, p = 1;

	while (k) {
		if (k & 1)
			p = p * b % MD;
		b = b * b % MD;
		k >>= 1;
	}
	return p;
}

int main() {
	static int mm[K], xx[K];
	int n, a, m, l, r, k, i, j, ans;

	scanf("%d%d", &n, &a);
	l = 0, r = K - 1;
	for (m = 1; m <= n / m; m++)
		if (n % m == 0) {
			mm[l] = m, xx[l] = power(a, (m + 1) / 2), l++;
			if (m != n / m)
				mm[r] = n / m, xx[r] = power(a, (n / m + 1) / 2), r--;
		}
	while (++r < K)
		mm[l] = mm[r], xx[l] = xx[r], l++;
	k = l;
	ans = 0;
	for (j = 0; j < k; j++) {
		for (i = 0; i < j; i++)
			if (mm[j] % mm[i] == 0)
				xx[j] = (xx[j] - xx[i] + MD) % MD;
		ans = (ans + (long long) xx[j] * (mm[j] % 2 == 0 ? mm[j] / 2 : mm[j])) % MD;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

signed main(){

  int A, B, C, K;
  long long  ans = 0, maximum;

  cin>>A>>B>>C>>K;

  maximum = max(A, max(B,C));

  ans = maximum;
  
  for(int i = 0; i < K; i++){
    ans *= 2;
  }

  ans += A + B + C;

  ans -= maximum;

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


Measured memory_bytes: 256
N = int(input())
result = []
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    result.append(input())
    if result[i] == "AC":
        AC += 1
    elif result[i] == "WA":
        WA += 1
    elif result[i] == "TLE":
        TLE += 1
    elif result[i] == "RE":
        RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))


Measured memory_bytes: 16320
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define fe(vec,lambda) std::for_each(vec.begin(), vec.end(), lambda );
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){vector<pair<T,T>> out(input.size()-1);rep(i,input.size()-1){out[i].first =input[i  ];out[i].second=input[i+1];}return(out);}
vector<char> String_to_vector_char(const string& input){vector<char> out(input.size());rep(i,input.size()){out[i]=input[i];}return out;}


ll a,b,h;
void input(){
    cin>>a>>b>>h;
}
void src(){
    cout<< (a+b)*h/2;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

int main()
{
	int m,n; string s;

	while(cin >> m >> n, m||n)
	{
		int prevplayer = m-1;
		int currplayer = 0;
		int nextplayer[1024];

		for(int i=0; i<m; i++)
		{
			nextplayer[i] = (i+1)%m;
		}

		bool flag = true;
		for(int i=1; i<=n; i++)
		{
			cin >> s;

			if(flag)
			{
				stringstream ans;

				if(i%3==0 && i%5==0)	ans << "FizzBuzz";
				else if(i%3==0)			ans << "Fizz";
				else if(i%5==0)			ans << "Buzz";
				else					ans << i;

				
				if(s == ans.str())
				{
					prevplayer = currplayer;
					currplayer = nextplayer[currplayer];
				}
				else
				{
					nextplayer[prevplayer] = nextplayer[currplayer];
					nextplayer[currplayer] = -1;
					currplayer = nextplayer[prevplayer];		
				}

				if(currplayer==nextplayer[currplayer])
				{
					flag=false;
				}
			}
		}

		flag=false;
		for(int i=0; i<m; i++)
		{
			if(nextplayer[i]!=-1)
			{
				cout << (flag?" ":"");
				cout << i+1;
				flag = true;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 944
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
    }
    int cnt=0;
    double m4=(double)sum/4.0/(double)m;
    for(int i=0;i<n;i++){
        if(a[i]>=m4){
            cnt++;
        }
    }
    if(cnt>=m){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

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

struct Card {
  int value;
  char suit;
};

int N;
Card A[100100];
Card stable[100100];

void merge(int left, int mid, int right) {
  int n1 = mid-left;
  int n2 = right-mid;

  Card L[N], R[N];
  for (int i = 0; i < n1; i++) {
    L[i] = stable[left+i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = stable[mid+i];
  }
  L[n1].value = INF;
  R[n2].value = INF;
  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    if (L[i].value <= R[j].value) {
      stable[k] = L[i];
      i++;
    } else {
      stable[k] = R[j];
      j++;
    }
  }
}

void mergeSort(int left, int right) {
  if (left + 1 < right) {
    int mid = (left+right)/2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int partition(int p, int r) {
  int x = A[r].value;
  int i = p-1;
  for (int j = p; j < r; j++) {
    if (A[j].value <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }  
  swap(A[i+1], A[r]);
  return i+1;
}

void quickSort(int p, int r) {
  if (p < r) {
    int q = partition(p, r);
    quickSort(p, q-1);
    quickSort(q+1, r);
  }
}

bool isStable() {
  for (int i = 0; i < N; i++) {
    if (A[i].suit != stable[i].suit) {
      return false;
    }
  }
  return true;
}

void Print(Card arr[]) {
  for (int i = 0; i < N; i++) {
    cout << arr[i].suit << " " << arr[i].value << endl;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i].suit >> A[i].value;
    stable[i].suit = A[i].suit;
    stable[i].value = A[i].value;
  }
  quickSort(0, N-1); 
  mergeSort(0, N);
  cout << (isStable() ? "Stable" : "Not stable") << endl;  
  Print(A);
}




Measured memory_bytes: 5456
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , a[maxN];
void solve(){
	cin>>n ;
	ll ans=0;
	for(ll i=1;i<=n ;i++){
		cin>>a[i];
		if(i&1 && a[i]&1)ans++;
	}
	cout<<ans<<endl;

}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    int sumA=0, sumB=0;
    
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    
    for(int i=0; i<N; i++){
        if(i%2==0) sumA += a[i];
        else sumB += a[i];
    }
    cout << sumA-sumB << endl;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();
    let s: Vec<&str> = s.split('/').collect();
    println!("2018/{}/{}", s[1], s[2]);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
n,m=io.read("*n","*n")
f=io.read("*a")
c,d={},{}
for a,b in f:gmatch("(%d+) (%d+)") do
	a=tonumber(a);b=tonumber(b)
	if a==1 then c[#c+1]=b end
	if b==n then d[a]=true end
end
for _,i in ipairs(c)do
	if d[i] then
		print("POSSIBLE")
		os.exit()
	end
end
print("IMPOSSIBLE")

Measured memory_bytes: 14536
from collections import defaultdict
from math import gcd
N,*L = map(int, open(0).read().split())
dic = defaultdict(int)
ans = 0
MOD = 10**9+7
S = set()
for a,b in zip(*[iter(L)]*2):
  if a==0 and b==0:
    ans += 1
    continue
  g = gcd(a,b)
  if b>0:
    dic[(a//g,b//g)] += 1
    S.add((a//g,b//g))
  elif b<0:
    dic[(-a//g,-b//g)] += 1
    S.add((-a//g,-b//g))
  else:
    dic[(1,0)] += 1
    S.add((1,0))
m = 1
for a,b in S:
  if a<=0:
    if dic[(b,-a)]==0:
      m *= pow(2,dic[(a,b)],MOD)
      m %= MOD
      continue
  else:
    if dic[(-b,a)]==0:
      m *= pow(2,dic[(a,b)],MOD)
      m %= MOD
      continue
    c = pow(2,dic[(a,b)],MOD)+pow(2,dic[(-b,a)],MOD)-1
    m *= c
    m %= MOD
ans = (m-1+ans)%MOD
print(ans)

Measured memory_bytes: 214476
#include <iostream>
#include <string>
#include <vector>
#define N_MAX 1000
#define M 1000000007
using namespace std;
typedef long long ll;
 
ll func(int);
 
int N,s,t;
string n[N_MAX];
vector<int> edge[N_MAX];
 
int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>n[i];
  for(int i=0;i<N-1;i++) cin>>s>>t,edge[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
  return 0;
}
 
ll func(int x){
  ll res=0,res2=1;
  if(!edge[x].size()){
    if(n[x]=="E") return 1;
    if(n[x]=="E?") return 2;
    return 0;
  }
  if(n[x]=="E"){
    for(int i=0;i<edge[x].size();i++) res2*=func(edge[x][i]);
    return res2%M;
  }
  if(n[x]=="E?"){
    for(int i=0;i<edge[x].size();i++) res2*=func(edge[x][i]);
    return (res2+1)%M;
  }
  if(n[x]=="A"){
    for(int i=0;i<edge[x].size();i++) res+=func(edge[x][i]);
    /*for(int i=0;i<edge[x].size();i++)
      if(n[edge[x][i]]=="E?") return (res+1)%M;*/
    return res%M;
  }
  if(n[x]=="A?"){
    for(int i=0;i<edge[x].size();i++) res+=func(edge[x][i]);
    return (res+1)%M;
  }
  if(n[x]=="R?"){
    for(int i=0;i<edge[x].size();i++){
      if(n[edge[x][i]]=="E?") res2*=func(edge[x][i]);
      else res2*=(1+func(edge[x][i]));
    }
    return res2%M;
  }
  if(n[x]=="R"){
    for(int i=0;i<edge[x].size();i++){
      if(n[edge[x][i]]=="E?") res2*=func(edge[x][i]);
      else res2*=(1+func(edge[x][i]));
    }
    for(int i=0;i<edge[x].size();i++)
      if(n[edge[x][i]]=="E?") return res2%M;
    return (res2-1)%M;
  }
}

Measured memory_bytes: 1356
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_a = Integer.parseInt(sc.next());
    int number_b = Integer.parseInt(sc.next());
    System.out.println((number_a * 3 + number_b) / 2);
  }
}


Measured memory_bytes: 21844
from numpy import array, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = array(A, dtype=object).reshape(N, N)

ans = eye(N, dtype=object)
while K:
    K, b = divmod(K, 2)
    if b:
        ans = ans.dot(A) % mod
    A = A.dot(A) % mod

print(ans.sum() % mod)

Measured memory_bytes: 14512
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define repi(m, itr) for (auto itr = m.begin();itr != m.end();++itr)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
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; }

// Union-Find Tree
class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

// 
int N, M;
int ans = 0;

int main(){
    cin >> N >> M;
    UnionFind uf = {N};
    rep(i, 0, M){
        int x, y, z;
        cin >> x >> y >> z;
        if(!uf.issame(x,y)){
            uf.merge(x, y);
        }
    }

    rep(i, 0, N){
        if(uf.root(i)==i) ++ans;
    }

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




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

using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    string a, b, c;
    cin >> a >> b >> c;
    int diff = 'A' - 'a';
    string res = "";
    res += (a[0] + diff); 
    res += (b[0] + diff); 
    res += (c[0] + diff); 
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		int[] c = new int[n];
		for(int i = 0;i<n;i++){
			v[i] = sc.nextInt();
		}
		for(int i = 0;i<n;i++){
			c[i] = sc.nextInt();
		}
		sc.close();
		int ans = 0;
		for(int i = 0;i<n;i++){
			if(v[i]>c[i])ans+=(v[i]-c[i]);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int minRight = int.MaxValue;
            int maxLeft = int.MinValue;
            var array = ReadIntArray();
            int N = array[0];
            int M = array[1];
            int L;
            int R;
            for (int i = 0; i < M; i++)
            {
                var lr = ReadIntArray();
                L = lr[0];
                R = lr[1];
                
                maxLeft = Math.Max(L, maxLeft);
                minRight = Math.Min(R, minRight);
                //Console.WriteLine($"maxLeft = {maxLeft}");
                //Console.WriteLine($"minRight = {minRight}");
            }
            if (minRight < maxLeft)
                Console.WriteLine(0);
            else
                Console.WriteLine(minRight - maxLeft + 1);
        }

//ここからテンプレート
        //1行に1入力
        private static string ReadString() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(ReadString()); }
        private static long ReadLong() { return long.Parse(ReadString()); }
        private static double ReadDouble() { return double.Parse(ReadString()); }
        //1行に複数入力(配列で取得)
        private static string[] ReadStringArray() { return ReadString().Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); }
        private static int[] ReadIntArray() { return ReadStringArray().Select(int.Parse).ToArray(); }
        private static long[] ReadLongArray() { return ReadStringArray().Select(long.Parse).ToArray(); }
        private static double[] ReadDoubleArray() { return ReadStringArray().Select(double.Parse).ToArray(); }
    }
}


Measured memory_bytes: 17472
#import <Foundation/Foundation.h>
int main() {
	int n;
	scanf("%d",&n);
	int prev = 0;
	int current = 0;
	int ans = 0;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		if(prev==a){
			current++;
		}else{
			ans += current/2;
			current = 1;
		}
		prev = a;
	}
	ans += current/2;
	printf("%d\n",ans);
}

Measured memory_bytes: 6228
n = int(input())
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))

b = []
for i in range(n):
    d = t - h[i]*0.006
    dd = abs(a-d)
    b.append(dd)

print(b.index(min(b))+1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stdio.h>
typedef long long ll;

using namespace std;

int prime[100001];
int like[100001];
bool isprime[100001];

int sieve(int n)
{
	int p=0;
	for(int i=0;i<=n;i++)
	{
		isprime[i]=true;
	}
	isprime[0]=false;
	isprime[1]=false;

	for(int i=2;i<=n;i++)
	{
		if(isprime[i])
		{
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i)
			{
				isprime[j]=false;
			}
		}
	}
	return p;
}

int main()
{
	int q;
	int r[100000];
	int l[100000];
	int p;
	int cnt;
	
	scanf("%d",&q);
	for(int i=0;i<q;i++)
	{
		scanf("%d %d",&l[i],&r[i]);
	}

	p=sieve(100000);
	like[0]=0;
	for(int i=1;i<100001;i++)
	{
		like[i]=like[i-1];
		if(isprime[i]==true && isprime[(i+1)/2]==true)
		{
			like[i]++;
		}
	}

	for(int i=0;i<q;i++)
	{
		cnt = like[r[i]]-like[l[i]-2];
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int a[10][10],m,n,flag;
char kk[10];
void dfs(int x,int y){
	if(x==m-1&&y==n-1){
		for(int i=0;i<m;++i)for(int j=0;j<n;++j)if(a[i][j])return;
		flag = 1;    
        return;
    }
	if(flag==1)return;
    if(a[x+1][y]){
        a[x+1][y]=0;
        dfs(x+1,y);
        a[x+1][y]=1;
    }
    if(a[x][y+1]){
        a[x][y+1]=0;
        dfs(x,y+1);
        a[x][y+1]=1;
    }
    if(!a[x][y+1]&&!a[x+1][y])return;
}
int main(){
    scanf("%d%d",&m,&n);
    for(int i=1;i<=m;++i){
        cin>>kk;
        for(int j=0;j<n;++j)if(kk[j]=='#')a[i-1][j]=1;
    }
    if(a[0][0]){
        a[0][0]=0;
        dfs(0,0);
    }
    if(flag)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <time.h>

using namespace std;

void solve(){
	time_t start, end;

	string A;
	/*for (int i = 0; i < n; i++)*/ cin >> A;
	string B;
	cin >> B;
	int n = A.size(), m = B.size();
	vector<vector<int>> DP(n + 1, vector<int>(m + 1, 0));
	start = clock();
	
	//for (int i = 0; i < n; i++) DP[i][0] = 0;
	//for (int j = 0; j < m; j++) DP[0][j] = 0;

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (A[i - 1] == B[j - 1]) DP[i][j] = DP[i - 1][j - 1] + 1;
			else DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
		}
	}

	end = clock();

	cout << DP[n][m] << endl;

}

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		solve();
	}
}

Measured memory_bytes: 6796
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N;cin>>N;
  int ans=0;int res=1;
  while(true){
    res*=3;ans++;
    if(res>=N){
      cout<<ans<<endl;
      return 0;
    }
  }
}



Measured memory_bytes: 3092
#!/usr/bin/env python3
#abc151_d
import sys
from collections import deque
mv = ((1,0),(-1,0),(0,1),(0,-1))
h,w = map(int,input().split())
board = [["#"]*(w+2) for _ in range(h+2)]
for i in range(h):
    s = input()
    for j in range(w):
        board[i+1][j+1] = str(s[j])
cur_max = 0 # 初期点を変更しながら全探索した時のmax
#print(board[0][0] == ".")
#for i in range(h+2):
    #print(board[i])
for i in range(h+2):
    for j in range(w+2):
        #print(i,j,board[i][j])
        tmp =  board[i][j]
        if tmp == ".":
            #print("yes",i,j)
            visit = deque()
            start_pos = (i,j)
            visit.append(start_pos)
            cnt = [[-1]*(w+2) for _ in range(h+2)] # -1埋め
            cnt[i][j] = 0 #スタート地点は0
            while visit:
                point = visit.popleft()
                #print(point[0], point[1])
                for k in mv:
                    pos = (point[0]+k[0],point[1]+k[1])
                    #print(pos)
                    if str(board[pos[0]][pos[1]]) == ".":
                        if cnt[pos[0]][pos[1]] == -1: #unvisited
                            #print(i,j,"yes")
                            cnt[pos[0]][pos[1]] = cnt[point[0]][point[1]] + 1
                            visit.append((pos[0],pos[1]))
                            if cnt[pos[0]][pos[1]] > cur_max:
                                cur_max = cnt[pos[0]][pos[1]]
print(cur_max)                    


Measured memory_bytes: 3316
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))
FT = sum(T)*2+1
import numpy as np
limit = []
cumt = 0
for n in range(2+N):
    if n==0:
        lis = [(0.5)*i for i in range(FT)]
    elif n==1:
        lis = [(0.5)*i for i in range(FT)][::-1]
    else:
        t = T[n-2]
        v = V[n-2]
        lis = [v+cumt//2-0.5*i for i in range(cumt)] + [v for _ in range(t*2)] + [v+i*0.5 for i in range(FT-cumt-t*2)]
        cumt += t*2
    limit.append(lis)
limit = np.min(np.array(limit), axis=0)
ans = 0
for i in range(FT-1):
    ans += (limit[i+1]+limit[i])*0.25
print(ans)

Measured memory_bytes: 173720
#define LENGTH 4

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
  // 入力                                                                                                              
  char S[LENGTH+1];
  cin >> S;

  //文字の重複回数                                                                                           
  int dup_count = 0;

  int i, j;

  //文字の重複をカウント                                                                                     
  for(i=0; i<LENGTH-1; i++){
    for(j=i+1; j<LENGTH; j++){
      if(S[i]==S[j])
        dup_count++;
    }
  }

  if(dup_count == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256