akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
	int i,j,k,n,x,sum,count;
while(1){
	count=0;
	scanf("%d %d",&n,&x);
	if(n==0 && x==0){break;}
	for(i=1;i<=n-2;i++){
		for(j=i+1;j<=n-1;j++){
			for(k=j+1;k<=n;k++){
				if(!((i==j)||(i==k)||(j==k))){
					sum=i+j+k;
					if(sum==x){count++;}
				}
			}
		}
	}
	printf("%d\n",count);
}
	return 0;
}

Measured memory_bytes: 600
S = input()
N = len(S)
L = ["A", "T", "C", "G"]
ans = 0

for i in range(N):
    for j in range(N-i):
        sub = S[j:j+i+1]
        for k in range(len(sub)):
            if sub[k] not in L:
                break
        else:
            ans = len(sub)

print(ans)

Measured memory_bytes: 3060
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const a = s[0];
  const b = s[1];

  const ans = (a <= 8 && b <= 8) ? 'Yay!' : ':(';

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	if(s.substr(0,3)=="RRR"){
		cout<<3<<endl;
	}else if(s.substr(0,2)=="RR" || s.substr(1,2)=="RR"){
		cout<<2<<endl;
	}else if(s.substr(0,1)=="R" || s.substr(1,1)=="R" || s.substr(2,1)=="R"){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}


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


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,ans;
  cin>>a>>b;
  ans=a;
  int mon=1,day=1;
  if(b<a){
    ans--;
  }
  cout<<ans;

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

# input = stdin.readline

def solve(n,m,original,temp):
  def judge(sy,sx):
    for i in range(m):
      for j in range(m):
        if original[sy+i][sx+j] != temp[i][j]:
          return False
    return True
  

  sy = 0
  while sy + m - 1 < n:
    sx = 0
    while sx + m - 1 < n:
      if judge(sy,sx):
        return True
      sx += 1
    sy += 1

  return False

def main():
  N,M = map(int,input().split())
  a = [input() for _ in range(N)]
  b = [input() for _ in range(M)]
  print("Yes" if solve(N,M,a,b) else "No")
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n,m;cin >> n >> m;
    vector<int> a(m);
    for(int i=0;i<m;i++){
        cin >> a[i];
    }
    sort(ALL(a));
    a.pb(INF);
    int s=0;
    vector<LL> dp(2*n+1,0);
    dp[0]=1;
    for(int i=0;i<n;i++){
        if(a[s]==i){
            s++;
            continue;
        }
        if(i+1<=n) dp[i+1] = (dp[i+1]+dp[i])%mod;
        if(i+2<=n) dp[i+2] = (dp[i+2]+dp[i])%mod;
    }
    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <cstring>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define inf (1<<29)
using namespace std;

int par[10000];

int find(int a) {
  return par[a] < 0 ? a : par[a] = find(par[a]);
}

int union_(int a, int b) {
  a = find(a);
  b = find(b);
  if(a != b) {
    if(par[a] < par[b]) {
      par[a] += par[b];
      par[b] = a;
    } else {
      par[b] += par[a];
      par[a] = b;
    }
  }
  return a - b;
}


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

  memset(par, -1, sizeof(par));
  int com, x, y;
  rep(i,q) {
    cin >> com >> x >> y;
    if(com == 1) {
      cout << (find(x) == find(y) ? 1 : 0) << endl;
    }
    if(com == 0) {
      union_(x, y);
    }
  }
  return 0;
}

Measured memory_bytes: 1212
#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.at(i);
  }
  int64_t ans = 0;
  int kijun = A.at(0);
  for (int i = 1 ; i<N ; i++){
    if (A.at(i) < kijun){
      ans += ( kijun - A.at(i) );
    }
    
    kijun = max(kijun,A.at(i));
  }
      
  cout << ans << endl;
}


Measured memory_bytes: 4052
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
acgt = ["A","C","G","T"]

cnt = 0
ans = 0
for i in range(len(s)):
    if s[i] in acgt:
        cnt += 1
    else:
        cnt = 0
    ans = max(ans,cnt)

print(ans)

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

int main(void) {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    token = lines[0].split()
    a = int(token[0])
    b = int(token[1])

    return (a, b)


def solve(a, b):

    if debug:
        log("a=%s" % a)
        log("b=%s" % b)
        
    tmp_a = a
    tmp_b = b

    result = 0
    for i in range(2):
        if tmp_a > tmp_b:
            result = result + tmp_a
            tmp_a = tmp_a - 1
        else:
            result = result + tmp_b
            tmp_b = tmp_b - 1

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

const long long mod = 1e9+7;

struct point{
    ll x;
    ll y;
    ll h;
};

int main(){
    int n;
    point* points;
    cin >> n;
    points = new point[n];
    for(int i = 0; i < n; i++){
        cin >> points[i].x >> points[i].y >> points[i].h;
    }

    sort(points, points+n, [](point &x, point &y){return x.h > y.h;});

    int cx, cy, ansH;
    for(cx = 0; cx <= 100; cx++){
        for(cy = 0; cy <=100; cy++){
            bool flag = true;
            ansH = points[0].h + abs(points[0].x-cx) + abs(points[0].y-cy);
            for(int i = 0; i < n; i++){
                if(points[i].h){
                    if(ansH != points[i].h + abs(points[i].x-cx) + abs(points[i].y-cy)){
                        flag = false;
                        break;
                    }
                }else{
                    if(ansH > abs(points[i].x-cx) + abs(points[i].y-cy)){
                        flag = false;
                        break;
                    }
                }
            }

            if(flag){
                cout << cx << " " << cy << " " << ansH << endl;
                return 0;
            }
        }
    }
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
 
int main(){
    int N, X;

    cin >> N >> X;
    int mmin = 1e9;
    
    for(int i = 0; i < N; i++){
        int m;
        cin >> m;
        X -= m;
        mmin = min(mmin, m);
    }
    
    int cnt = 0;
    cnt = X / mmin + N;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


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


int main(){
    ll n, p; cin >> n >> p;
    auto mp = prime_factor(p);
    ll ans = 1;
    for(auto p: mp){
        // オーバーフロー対策
        if(p.second >= n) rep(i, p.second/n) ans *= p.first;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std;
int main(){
  int sum_a = 0,sum_b = 0;
  for(int i = 0;i < 4;i++){
    int tmp;
    cin >> tmp;
    sum_a += tmp;
  }
  for(int i = 0;i < 4;i++){
    int tmp;
    cin >> tmp;
    sum_b += tmp;
  }
  if(sum_a >= sum_b)cout << sum_a << endl;
  else cout << sum_b << endl;
  
    
  
  return 0;
}
vector<string> split(string str,string delim){
  vector<string> items;
  size_t dlm_idx;
  if(str.npos == (dlm_idx = str.find_first_of(delim))){
    items.push_back(str.substr(0,dlm_idx));
  }
  while(str.npos != (dlm_idx = str.find_first_of(delim))){
    if(str.npos == str.find_first_not_of(delim)){
      break;
    }
    items.push_back(str.substr(0,dlm_idx));
    dlm_idx++;
    str = str.erase(0,dlm_idx);
    if(str.npos == str.find_first_of(delim) && "" != str){
      items.push_back(str);
      break;
    }
  }
  return items;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    // vector <int> l(m);
    // vector <int> r(m);

    int tmpl, tmpr;
    int ansl = 0, ansr = n;
    for (int tsumugi = 0; tsumugi < m; tsumugi++){
        cin >> tmpl >> tmpr;
        ansl = max(tmpl, ansl);
        ansr = min(tmpr, ansr);
    }
    int ans = ansr - ansl + 1;
    if (ans < 0){
        ans = 0;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll dp[200007][33];
int main(){
  rep(i,200007){
    rep(j,33){
      dp[i][j] = -1;
    }
  }
  ll n;
  cin >> n;
  vl a(n+1);
  ll num = 2;
  rep(i, 5){
    num *= num;
  }
  rep(i,n){
    ll num1 = num;
    cin >> a[i];
    bool z = false;
    for (ll j = 32; j >= 0; j--){
      if(!z&&a[i]<num1){
        dp[i][j] = -1;
      }
      else if(!z&&a[i]>=num1){
        dp[i][j] = 1;
        z = true;
        a[i] -= num1;
      }
      else if(z&&a[i]<num1){
        dp[i][j] = 0;
      }
      else{
        dp[i][j] = 1;
        a[i] -= num1;
      }
      num1 /= 2;
    }
  }
  ll s=0;
  ll num2 = 1;
  rep(i, 33){
    ll count0 = 0;
    ll count1 = 0;
    rep(j, n){
      if(dp[j][i]==1){
        count1++;
      }
    }
    s += num2 *  (count1 % 2);
    num2 *= 2;
  }
  ll num1 = num;
  a[n] = s;
  bool z = false;
  for (ll j = 32; j >= 0; j--){
    if (!z && a[n] < num1){
      dp[n][j] = -1;
    }
    else if (!z && a[n] >= num1)
    {
      dp[n][j] = 1;
      z = true;
      a[n] -= num1;
    }
    else if (z && a[n] < num1)
    {
      dp[n][j] = 0;
    }
    else
    {
      dp[n][j] = 1;
      a[n] -= num1;
    }
    num1 /= 2;
    }
    rep(i,n){
      ll ans = 0;
      ll num3 = 1;
      rep(j, 33){
        if((dp[i][j]==1||dp[n][j]==1)&&(dp[i][j]==1!=dp[n][j]==1)){
          ans += num3;
        }
        num3 *= 2;
      }
      print(ans);
    }
}

Measured memory_bytes: 56316
import math
import numpy as np

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

num_P, num_Q = 0, 0
for i in range(N):
  val = P[0]
  tmp_P = sorted(P)
  idx_P = tmp_P.index(val)
  del P[0]
  if i == N-1:
    num_P += 1
  else:
    num_P += idx_P * math.factorial(N-(i+1))	# 一つ値が決まるごとに使える数値が減ることを考慮していない
    
for i in range(N):
  val = Q[0]
  tmp_Q = sorted(Q)
  idx_Q = tmp_Q.index(val)
  del Q[0]
  if i == N-1:
    num_Q += 1
  else:
    num_Q += idx_Q * math.factorial(N-(i+1))

print(abs(num_P-num_Q))

    
  

Measured memory_bytes: 12500
# coding: utf-8
# Your code here!


def binarysearch(ok,ng,isOK): #二分探索
    while(abs(ok-ng) > 1):
        mid = (ok + ng)//2
        if isOK(mid): ok = mid
        else: ng = mid
    return ok


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

from heapq import *

#n = int(input())
n,k = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]
f = [int(i) for i in readline().split()]

a.sort()
f.sort()
f.sort(reverse=True)


def isOK(c):
    res = 0
    for ai,fi in zip(a,f):
        p = max(0,(ai*fi-c+fi-1)//fi)
        res += p
#    print(res,c)
    return res <= k
   

print(binarysearch(10**12,-1,isOK))

"""
res = 0
for i in range(n):
    while a[i]*f[i] > 12:
        a[i] -= 1
        res += 1
        
print(res)        
"""        
        
        




Measured memory_bytes: 107724
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<cmath>
#include <map>
#include <set>
#include <iostream>

using namespace std;



int main()
{
	int n;
	string s;
	cin >> n;;
	cin >> s;
	int w = 0;
	for (int i = 0; i < s.size(); i++) if (s[i] == 'W') w++;
	int t = w;
	int e = 0;
	for (int j = s.size() - 1; t-- > 0; j--) {
		if(s[j] == 'W') e++;
	}
	cout << w -e  ;

}



Measured memory_bytes: 3484
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

vector<vector<int> > ans;
vector<int> t;

void dfs(int n, int mx) {
    if (n == 0) {
        ans.push_back(t);
        return ;
    }
    for (int i=1; i<=min(n,mx); ++i) {
        t.push_back(i);
        dfs(n-i, i);
        t.pop_back();
    }
}

int main() {
    int n;
    while (cin >> n, n) {
        ans.clear();
        t.clear();
        dfs(n, n);
        sort(ans.begin(), ans.end(), greater<vector<int> >());
        for (int i=0; i<(int)ans.size(); ++i) {
            for (int j=0; j<(int)ans[i].size(); ++j) {
                cout << (j == 0 ? "" : " ") << ans[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  ll ans=0;
  ll count=0;
  ll small=1e9+1;
  for(int i=0;i<n;i++){
    if(a[i]<0){
      count++;
    }
    a[i]=abs(a[i]);
    small=min(small,a[i]);
    ans+=a[i];
  }
  if(count%2==0){
    cout << ans << endl;
  }
  else{
    cout << ans-small*2 << endl;
  }
}

Measured memory_bytes: 1024
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

#define MAXN 2500
int N,M,P;
vector<int> F[MAXN+5];
vector<pair<int,int> > G[MAXN+5];

int Dist[MAXN+5];
bool flag[MAXN+5];
bool vis[MAXN+5];
int cnt[MAXN+5];
int SPFA(int S,int T){
    queue<int> Q;
    memset(Dist,0x3f,sizeof Dist);
    Dist[S]=0;
    Q.push(S),vis[S]=1,cnt[S]=1;
    while(!Q.empty()){
        int u=Q.front();vis[u]=0;Q.pop();
        for(int i=0;i<int(G[u].size());i++){
            int v=G[u][i].first,w=G[u][i].second;
            if(!flag[v])
                continue;
            if(Dist[v]>Dist[u]+w){
                Dist[v]=Dist[u]+w;
                if(!vis[v]){
                    Q.push(v);
                    vis[v]=1;
                    cnt[v]++;
                    if(cnt[v]>N)
                        return -1;
                }
            }
        }
    }
    return max(-Dist[T],0);
}

int main(){
    N=read(),M=read(),P=read();
    for(int i=1;i<=M;i++){
        int u=read(),v=read(),w=read()-P;
        F[v].push_back(u);
        G[u].push_back(make_pair(v,-w));
    }
    queue<int> Q;
    Q.push(N);
    flag[N]=1;
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(int i=0;i<int(F[u].size());i++){
            int v=F[u][i];
            if(flag[v])
                continue;
            flag[v]=1;
            Q.push(v);
        }
    }
    printf("%d",SPFA(1,N));
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N, Q;
  ll B, C;
  cin >> N;
  ll ans = 0;
  // ll A[N];
  ll count[1000010] = {0};
  for (int i = 0; i < N; ++i) {
    ll tmp;
    cin >> tmp;
    ans += tmp;
    ++count[tmp];
  }
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    cin >> B >> C;
    if (count[B] != 0) {
      ans -= B * count[B];
      ans += C * count[B];
      count[C] += count[B];
      count[B] = 0;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 11560
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x)   (x.begin(),x.end()) 
#define sz(v)     ((int)(v.size()))
#define INF 1e9+7
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 


int32_t main(){
  fast; 
    
  int n , k; cin>>n>>k; 
  int ans; 
  if(k==n){
    ans=0; 
  }
  else if(k>n){
    ans=min(n,k-n); 
  }
  else{
    ans=min(n%k , k-(n%k)); 
  }

  cout<<ans<<endl; 

  
  return 0; 

}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

int main(){
    std::map<char, std::string> s;
    std::cin >> s['a'] >> s['b'] >> s['c'];

    char turn, next_turn;
    turn = 'a';

    while(!s[turn].empty()){
        next_turn = s[turn][0];
        s[turn].erase(s[turn].begin());

        turn = next_turn;
    }

    std::cout << (char)(turn - 0x20) << std::endl;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_A&lang=jp
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;

class Node{
protected:
  int id;
  Node* parent;
  vector<Node*> children;
  void becomeParentOf(Node*);
public:
  Node();
  void becomeChildOf(Node*);
  void setId(int);
  bool isRoot();
  bool isLeaf();
  int getDepth();
  int getParentId();
  int getId();
  string getType();
  string getListOfChildren();
};

void Node::setId(int aId){
  id = aId;
}

Node::Node(){
  id = NULL;
  parent = NULL;
  children.clear();
}

void Node::becomeChildOf(Node* aParent){
  parent = aParent;
  parent->becomeParentOf(this);
}

void Node::becomeParentOf(Node* child){
  children.push_back(child);
}

bool Node::isRoot(){
  return parent == NULL;
}

bool Node::isLeaf(){
  return children.empty();
}

int Node::getDepth(){
  if (parent == NULL){
    return 0;
  }
  else{
    return parent->getDepth() + 1;
  }
}

int Node::getId() {
	return id;
}

int Node::getParentId() {
	if (parent == NULL) {
		return -1;
	}
	else{
		return parent->getId();
	}
}

string Node::getType() {
	if (isRoot()) {
		return "root";
	}
	else if (isLeaf()) {
		return "leaf";
	}
	else {
		return "internal node";
	}
}

string toString(int number) {
	stringstream ss;
	ss << number;
	return ss.str();
}

string Node::getListOfChildren() {
	if (children.empty()) {
		return "[]";
	}
	string listStr = "[";
	for (vector<Node*>::iterator it = children.begin(); it != children.end(); it++) {
		listStr += toString((*it)->getId());
		if (it + 1 != children.end()) {
			listStr += ", ";
		}
	}
	listStr += "]";
	return listStr;
}

vector<string> split(const string &str, char delim) {
	istringstream iss(str); string tmp; vector<string> res;
	while (getline(iss, tmp, delim)) res.push_back(tmp);
	return res;
}

int main(){
	string strNumOfNodes;
	getline(cin, strNumOfNodes);
	int numOfNodes = atoi(strNumOfNodes.c_str());
	
	Node* nodes = new Node[numOfNodes];
	for (int i = 0; i < numOfNodes; i++) {
		nodes[i].setId(i);
	}
	
	for (int i = 0; i < numOfNodes; i++) {
		string line;
		getline(cin, line);
		
		vector<string> splitLine = split(line, ' ');
		vector<int> splitLineInt;
		for (vector<string>::iterator it = splitLine.begin(); it != splitLine.end(); it++) {
			splitLineInt.push_back(atoi((*it).c_str()));
		}

		int numOfChildren = splitLineInt.size() - 2;
		int parentId = splitLineInt[0];
		for (int i = 0; i < numOfChildren; i++) {
			int childId = splitLineInt[i + 2];
			nodes[childId].becomeChildOf(&nodes[parentId]);
		}
	}

	for (int i = 0; i < numOfNodes; i++) {
		cout << "node " << i << ": ";
		cout << "parent = " << nodes[i].getParentId() << ", ";
		cout << "depth = " << nodes[i].getDepth() << ", ";
		cout << nodes[i].getType() << ", ";
		cout << nodes[i].getListOfChildren();
		cout << endl;
	}

	delete[] nodes;

//	string end;
//	cin >> end;

	return 0;
}

Measured memory_bytes: 13244
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static System.Math;

namespace _20190420
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole())
            {
                var n = Console.ReadLine().ToInt();
                var str = GetString();
                var k = Console.ReadLine().ToInt();

                var kChr = str[k - 1];
                string tmp = "";
                for (int i = 0; i < n; i++)
                {
                    if (str[i] != kChr)
                    {
                        tmp += "*";
                    }
                    else
                    {
                        tmp += kChr;
                    }
                }
                CWrite(tmp);
            }
        }

        static void CWrite<T>(T str) => Console.WriteLine(str);
        static string GetString() => Console.ReadLine();
        static T[] GetArray<T>()
        {
            var t = typeof(T);
            var str = Console.ReadLine();
            if (t == typeof(string))
            {
                return (T[])(object)str.Split();
            }
            if (t == typeof(int))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            if (t == typeof(long))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            if (t == typeof(double))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            throw new NotSupportedException($"{t} is not supported.");
        }
    }

    class SetConsole : IDisposable
    {
        readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
        public SetConsole()
        {
            sw.AutoFlush = false;
            Console.SetOut(sw);
        }
        public void Dispose()
        {
            Console.Out.Flush();
            sw.AutoFlush = true;
            Console.SetOut(sw);
        }
    }
    static class ExtentionsLibrary
    {
        public static T[] ToNumArray<T>(this string str)
        {
            var t = typeof(T);
            if (t == typeof(int))
            {
                return (T[])(object)str.Split().Select(int.Parse).ToArray();
            }
            if (t == typeof(long))
            {
                return (T[])(object)str.Split().Select(long.Parse).ToArray();
            }
            if (t == typeof(double))
            {
                return (T[])(object)str.Split().Select(double.Parse).ToArray();
            }
            throw new NotSupportedException();
        }
        public static int ToInt(this string str) => int.Parse(str);
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> cnt(2,0);

    for (int i=0; i<n; i++) {
        cnt[s[i]%2]++;
    }

    cout << 2*min(cnt[0], cnt[1]) << endl;
}
    


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

int main() {
    int N, cnt = 0, ans = 0; cin >> N;
    
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        if (x == y) cnt++;
        else cnt = 0;
        ans = max(ans, cnt);
    }
    if (ans >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++) 
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
int a[1005];
int main(int argc, char** argv) {
	int n,m;
	cin>>n>>m;
	int sum=0;
	rep(i,1,n)scanf("%d",&a[i]),sum+=a[i];
	sort(a+1,a+n+1);
	if(a[n-m+1]*(4*m)<sum)
	{
		printf("No");
	}
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    abc149c()
}

fun abc149c() {
    val x = readLine()!!.toLong()

    for (i in x..Long.MAX_VALUE) {
        if (isPrime(i)) return println(i)
    }
}

private fun modPow(n: Long, p: Long, m: Long): Long {
    var x = n
    var y = p
    var result = 1L

    x %= m
    while (y > 0) {
        if (y % 2 == 1L)
            result = (result * x) % m
        y = y shr 1
        x = (x * x) % m
    }

    return result
}

private fun millerTest(n: Long, d: Long): Boolean {
    val a = 2 + (Math.abs(Random().nextLong()) % (n - 2))
    var x = modPow(a, d, n)
    var d1 = d

    if (x == 1L || x == n - 1) return true

    while (d1 != n - 1) {
        x = (x * x) % n
        d1 *= 2
        if (x == 1L) return false
        if (x == n - 1) return true
    }
    return false
}

private fun isPrime(n: Long): Boolean {
    if (n <= 1L || n == 4L) return false
    if (n <= 3L) return true

    var d = n - 1
    while (d % 2 == 0L) d /= 2

    for (i in 0 until 1000) {
        if (!millerTest(n, d)) return false
    }
    return true
}


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

const int N=100010;
int n,m;
struct edge{
	int y,next;
}s[N<<1];
vector<int> out[N];
int first[N],len=0,a[N],b[N],id[N],rk[N],fa[N];
long long sum[N],dp[N];

bool cmp(int x,int y){return a[x]<a[y];}
int findpa(int x){return fa[x]!=x?fa[x]=findpa(fa[x]):x;}
void ins(int x,int y){s[++len]=(edge){y,first[x]};first[x]=len;}

void dfs(int x,int fa){
	sum[x]=b[x];
	for(int i=first[x];i!=0;i=s[i].next) if(s[i].y!=fa) dfs(s[i].y,x),sum[x]+=sum[s[i].y];
}

void get_ans(int x,int fa){
	if(first[x]==0) dp[x]=a[x]+b[x];
	else dp[x]=1e18;
	for(int i=first[x];i!=0;i=s[i].next) if(s[i].y!=fa){
		get_ans(s[i].y,x);
		dp[x]=min(dp[x],sum[x]-sum[s[i].y]+max(dp[s[i].y],1ll*a[x]));
	}
}

int main(){
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=1;i<=n;i++) scanf("%d %d",&a[i],&b[i]),a[i]=max(a[i]-b[i],0),id[i]=i;
	for(int i=1;i<=m;i++) scanf("%d %d",&x,&y),out[x].push_back(y),out[y].push_back(x);
	sort(id+1,id+1+n,cmp);
	for(int i=1;i<=n;i++) rk[id[i]]=i,fa[i]=i;
	for(int i=1;i<=n;i++){
		x=id[i];
		for(int j=0;j<out[x].size();j++){
			y=findpa(out[x][j]);
			if(rk[y]<rk[x]) ins(x,y),fa[y]=x;
		}
	}
	dfs(id[n],0);
	get_ans(id[n],0);
	printf("%lld\n",dp[id[n]]);
}

Measured memory_bytes: 13820
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s;
	cin >> s;

	for (int i = 0; i < 4; i++) {
		cout << s[i];
	}
	cout << " ";
	for (int i = 4; i < (int)s.size(); i++) {
		cout << s[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
private val ACCEPTABLE_HEAD = setOf('M', 'A', 'R', 'C', 'H')

fun main(args: Array<String>) {
    val n = readLine()?.toLong() ?: return

    // 名前の頭文字とその数のmapを作ってしまう
    // MARCH以外の頭文字をもつ名前は除外する
    val sMap: Map<Char, Long> = (0 until n)
        .map { readLine()!![0] }
        .filter { it in ACCEPTABLE_HEAD }
        .groupBy { it }
        .mapValues { it.value.size.toLong() }

    // sMapのsizeは今確実に5未満となっている
    // 5個から3つ選ぶ組み合わせを計算するために3重ループするが、
    // これは十分間に合う速度

    var count = 0L

    for (entry1 in sMap.entries) {
        for (entry2 in sMap.entries) {
            for (entry3 in sMap.entries) {
                // keyの順序を固定することで重複を排除する
                // Kotlin(1.0.0)だとcompareでChar to Numberの変換が行われてClassCastException
                // となるので、それを回避
                if (entry1.key.toInt() < entry2.key.toInt() &&
                    entry1.key.toInt() < entry3.key.toInt() &&
                    entry2.key.toInt() < entry3.key.toInt())
                {
                    count += (entry1.value * entry2.value * entry3.value)
                }
            }
        }
    }

    println(count)
}

Measured memory_bytes: 39584
#include<iostream>
#include<vector>

void stupid(){
    int N;
    std::cin>>N;
    std::vector<unsigned long long>A(N);
    unsigned long long totalXOR=0x0000;
    for(auto& a:A){
        std::cin>>a;
    }
    for(int i=0;i<N;++i){
        totalXOR^=A[i];
    }
    for(int i=0;i<N;++i){
        unsigned long long buf=totalXOR^A[i];
        std::cout<<buf<<" ";
    }
}
int main(){
    stupid();
    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define int	long long
#define sz(x)	((int)(x).size())
#define w(x)	int x; cin>>x; while(x--)
#define db(x)	{ cerr << #x << " = " << x << endl; }
using namespace std;

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

int32_t main(){
	c_p_c();
	int n,k; cin>>n>>k;
	vector<int> a,p;
	unordered_set <int> check;
	a.push_back(0);
	for(int i=1;i<=n;i++){
		int x; cin>>x;
		a.push_back(x);
	}
	p.push_back(1);
	check.insert(1);
	int index=1;
	while(1){
		if(check.count(a[index]) == 1){
			break;
		}
		p.push_back(a[index]);
		check.insert(a[index]);
		index = a[index];
	}
	int s=p.size();
	if(a[index]==1){
		cout<<p[k%s]<<endl;
	}
	else{
		if(k<s){
			cout<<p[k%s]<<endl;
		}else{
			vector<int> b;
			int f=0;
			for(int i=0;i<s;i++){
				if(a[index]==p[i]){
					k=k-i;
					f=1;
				}
				if(f==1)
					b.push_back(p[i]);
			}
			s=b.size();
			cout<<b[k%s]<<endl;

		}
	}

	return 0;
}

// g++ -std=c++17 -Wshadow -Wall -o "sol" "sol.cpp" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG


Measured memory_bytes: 15576
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let a: Vec<u64> = get!(u64;n);

    let mut set = HashSet::with_capacity(100_000);

    for &x in &a {
        if !set.remove(&x) {
            set.insert(x);
        }
    }

    println!("{}", set.len());
}


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

int main()
{
	int a, sum = 0;
	char s[81];
	while (scanf("%*[^0-9]", s) != EOF) {
		if ( scanf("%d", &a) == EOF ) break;
		sum += a;
	}
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
#define inf 1ll<<60
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
#define int llong
#define be(x) x.begin(), x.end()
typedef pair<int, int> P;

signed main(){
	int N, M;
	int use[10] = {0,2,5,5,4,5,6,3,7,6};
	vector<int> A, B;
	char choose[10];

	cin >> N >> M;
	A.resize(M);
	for(int i = 0; i < M; i++){
		cin >> A[i];
		B.pb(use[A[i]]);
	}
	sort(be(A));
	sort(be(B));
	for(int i = 0; i < M; i++)
		choose[use[A[i]]] = (char)('0' + A[i]);

	string dp[10001] = {};
	fn(dp, 10001, "");
	for(int i = 0; i < M; i++){
		string check; check += choose[B[i]];
		dp[B[i]] = max(dp[B[i]], check);
	}

	for(int i = B[0]+1; i <= N; i++){
		for(int j = 0; j < M; j++){
			if(i - B[j] >= 0 && dp[i-B[j]] != ""){
				// cerr << dp[i-B[j]] << " " << choose[B[j]] << endl;
				string check = dp[i-B[j]] + choose[B[j]];
				if(dp[i].length() < check.length())
					dp[i] = check;
				else if(dp[i].length() == check.length())
					dp[i] = max(dp[i], check);
			}
		}
	}

	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 41600
def main():
    n = int(input())
    count = [[0]*26 for _ in range(n)]
    for i in range(n):
        s = input()
        for c in s:
            count[i][ord(c)-97] += 1
    d = dict()
    for lv in count:
        t = tuple(lv)
        if t not in d:
            d[t] = 1
        else:
             d[t] += 1
    # print(d)
    output = 0
    for t in d:
        output += d[t] * (d[t]-1) // 2
    return output



if __name__ == '__main__':
    print(main())

Measured memory_bytes: 64872
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int mod = (int)1e9 + 7;
ll f[300200];
int n, m, a, b;
ll binpow(ll x, ll y) {
	if(y == 0) return 1;
	if(y % 2 == 1) return binpow(x, y-1) * x % mod;
	return binpow(x * x % mod, y/2);
}
ll C(int n, int k) {
	return f[n] * binpow(f[n-k] * f[k] % mod, mod-2) % mod;
}
ll go(int x, int y){
	return C(x+y-2, x-1);
}
int main () {
	cin >> n >> m >> a >> b;
	f[0] = 1;
	for(int i = 1; i <= 300100; i++)
		f[i] = f[i-1] * i % mod;
	ll ans = 0;
	for(int i = 1; i <= n-a; i++) {
		ans = (ans + go(i, b) * go(n-i+1, m - b)) % mod;
	}
	cout << ans << "\n";
 	return 0;
}



Measured memory_bytes: 2560
using System;
using System.Linq;
public class Simple {
    public static void Main() { new Simple().Solve(); }
    int N, A, B;
    long[] v;
    void Solve() {
        //input
        var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        N = inp[0];
        A = inp[1];
        B = inp[2];
        v = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        v = v.OrderByDescending(v => v).ToArray();

        //average
        var ave = v.Take(A).Average();

        //patern
        var patern = 0L;
        var Comb = C(50);
        var top = v.First();
        var bot = v[A - 1];
        var usable = v.Where(v => v == bot).Count();
        if (v[0] == v[A - 1]) {
            for (int i = A; i <= B; i++) {
                if (usable < i) break;
                patern += Comb[usable, i];
            }
        } else {
            var use = v.Select((e, i) => new { e, i }).
                       Where(v => v.e == bot && v.i < A).Count();
            patern = Comb[usable, use];
        }

        //res
        Console.WriteLine(ave);
        Console.WriteLine(patern);
    }

    long[,] C(int N) {
        long[,] ret = new long[N + 1, N + 1];
        for (int i = 0; i <= N; i++)
            for (int j = 0; j <= i; j++)
                ret[i, j] = (j == 0 || j == i) ? 1L : ret[i - 1, j - 1] + ret[i - 1, j];
        return ret;
    }


}

Measured memory_bytes: 13620
#include <stdio.h>
#include <stdlib.h>
#define SHORT 1
#define LONG 0

long hyouka(long n,long m,long book[101],long bookcase){
	long length,count = 0,i,j;
	for(i = 0 ;i < m ;i++){
		length = 0;
		for(j = 0;;j++){
			length = length + book[count];
			if(bookcase < length){
				break;
			}
			count++;
			
		}
	}
	
	if(count < n){
		return SHORT;
	}else{
		return LONG;
		}
}


long nibutan(long n,long m,long book[101]){
	long left = 0,right = 1500000,half,a;
	while(1){
		half = (right + left) / 2;
		//printf("%ld\t",half);
		
		a = hyouka(n,m,book,half);
		
		if(a == SHORT){
			left = half;
		}else if(a == LONG){
			right = half;
		}if(right == left || right == left + 1){
			break;
		}
		//printf("%ld %ld\n",left,right);
	}
	return right;
}


int main(void)
{
	long  n,m,book[101],answer,i;
	
	while(1){
		scanf("%ld %ld",&m,&n);
		
		if(n == 0 && m == 0){
			break;
		}
		
		for(i = 0;i < n;i++){
			scanf("%ld",&book[i]);
		}
		
		answer = nibutan(n,m,book);
		
		printf("%ld\n",answer);
	}
	return 0;
}

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

int main()
{
long long N;
long long A;
long long i;
A=1;
scanf("%d",&N);
for(i=0; i<N; i++)
{
 A=A*(i+1);
 A=A%(1000000007);
}
printf("%d",A);
return 0;
}



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

int n, a[2000010];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    int j = 1;
    long long suma = 0, sumb = 0, ret = 0;
    for(int i = 1; i <= n; i++){
        while(j-1 <= n && suma == sumb){
            suma ^= a[j], sumb += a[j];
            j++;
        }
        suma ^= a[j-1], sumb -= a[j-1];
        suma ^= a[i], sumb -= a[i];
        ret += j - i - 1;
        j--;
    }
    printf("%lld\n", ret);
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=acos(-1.0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll par[800010];
ll len[800010];
ll you[800010];
void init(ll n){
  for(int i=0;i<n;i++){
    par[i]=i;
    len[i]=0;
    you[i]=1;
  }
}
ll root(ll n){
  if(par[n]==n)return n;
  return par[n]=root(par[n]);
}
void unit(ll a,ll b){
  a=root(a);
  b=root(b);
  if(a==b)return;
  if(len[a]<len[b]){
    par[a]=b;
    you[b]+=you[a];
  }
  else{
    par[b]=a;
    you[a]+=you[b];
    if(len[a]==len[b])len[a]++;
  }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k,l;cin>>n>>k>>l;
    init(400000);
    rep(i,0,k){
        int a,b;cin>>a>>b;
        unit(a,b);
    }
    rep(i,0,l){
        int a,b;cin>>a>>b;
        a+=200000;b+=200000;
        unit(a,b);
    }
    map<pii,int> mp;
    rep(i,1,n+1){
        int f=root(i);
        int g=root(i+200000);
        mp[{f,g}]++;
    }
    rep(i,1,n+1){
        int f=root(i);
        int g=root(i+200000);
        cout<<mp[{f,g}]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 24448
import sys


class UnionFind:
    def __init__(self, n):
        self.root = [i for i in range(n)]
        self.rank = [0] * n

    def find(self, x):
        if self.root[x] == x:
            return x
        else:
            y = self.find(self.root[x])
            self.root[x] = y
            return self.root[x]

    def unite(self, x, y):
        if self.is_same(x, y):
            return
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.root[rx] = ry
        else:
            self.root[ry] = rx
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    uft = UnionFind(N)
    for _ in range(M):
        x, y, _ = map(int, input().split())
        uft.unite(x-1, y-1)

    root = set()
    for i in range(N):
        root.add(uft.find(i))

    return len(root)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 16784
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
using namespace std;

int main(){
    
    int n,t;
    cin >> n >> t;
    vector<pair<int,int>> v(n);
    for (int i = 0; i < n; i++)
    {
        int a,b;
        cin >> a >> b;
        v[i] = make_pair(a,b);
    }
    
    int ans = 1e9;
    for (int i = 0; i < n; i++)
    {
        if(v[i].second<=t){
            ans = min(ans,v[i].first);
        }
    }
    
    if(ans==1e9){
        cout << "TLE" << endl;    
    }else{
    cout << ans << endl;
    }
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int carMax = 0;
    int ans;
    for (int i = 0; i < N; i++){
        a.at(i) = i + 1;
    }
    
    int count;
    
    for (int i = 0; i < N; i++){
        while(a.at(i) % 2 == 0){
            a.at(i) /= 2;
            count++;
        }
        carMax = max(carMax, count);
        if (carMax == count) ans = i + 1;
        count = 0;
    }
    
    cout << ans << endl;

    


}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)

	cc := make([]int, m)

	for i := 0; i < m; i++ {
		cc[i] = getNextInt(scanner)
	}

	dp := make([]int, n+1)

	for i := 1; i <= n; i++ {
		for ii := 0; ii < m; ii++ {
			if i-cc[ii] < 0 {
				continue
			}
			if dp[i] == 0 || dp[i-cc[ii]]+1 < dp[i] {
				dp[i] = dp[i-cc[ii]] + 1
			}
		}
	}
	fmt.Fprintln(writer, dp[n])
	writer.Flush()
}



Measured memory_bytes: 1588
n,m,x=map(int,input().split())
l=[]

for i in range(n):
    a=list(map(int,input().split()))
    l.append(a)
ans=99999999
for i in range(2 ** n):
    bag = []
    for j in range(n):  
        if ((i >> j) & 1): 
            bag.append(l[j])  
    skill=[0]*m
    enou=[0]*m
    mone=0
    for sub in bag:
        mone+=sub[0]
        for kk in range(1,m+1):
            skill[kk-1]+=sub[kk]
            if skill[kk-1]>=x:
                enou[kk-1]+=1
    if 0 not in enou:
        if ans>mone:
            ans=mone
if ans==99999999:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9136
/*C - Divide the Problemsr*/
#include <bits/stdc++.h>
using namespace std;

using Long = long long;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int tam;

	cin >> tam;

	vector <int> arr(tam);

	int ans = 0;

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

	if(tam % 2 == 0){
		
		int mitad = tam / 2;
		sort(arr.begin(), arr.end());

		if(arr[mitad - 1] != arr[mitad]){
			ans = arr[mitad] - arr[mitad - 1];
		}
	}

	cout << ans;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e5 + 5;
int32_t main()
{
	IOS;
	int t;
	//cin >> t;
	t=1;
	while(t--)
	{
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int ans = a*c;
        ans = max(ans, a*d);
        ans = max(ans, b*c);
        ans = max(ans, b*d);
        cout<<ans;
	}
	return 0;
} 

Measured memory_bytes: 3644
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    lint h,w;cin>>h>>w;
    if(h==1||w==1)cout<<1<<endl;
    else cout<<(h*w+1)/2<<endl;
}


Measured memory_bytes: 3636