akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//幅優先探索
//全て添字で扱うこと
map<vector<int>, int> bfs(int &n, vector<vector<int>> &next, int &start, int &kk) {
  queue<int> task;
  task.push(start);

  vector<int> seen(n, 0);
  seen[start] = 1;

  vector<vector<int>> checkc(n, vector<int>(0));

  map<vector<int>, int> m;

  while (task.size() > 0) {
    int width = task.size();
    for (int i = 0; i < width; i++) {
      for (int j = 0; j < next[task.front()].size(); j++) {
        if (seen[next[task.front()][j]] == 0) {
          int x = 1;
          if (checkc[task.front()].size() > 0) x = checkc[task.front()].back() + 1;
          if (x > kk) x = 1;
          m[{min(task.front(), next[task.front()][j]), max(task.front(), next[task.front()][j])}] = x;
          checkc[task.front()].push_back(x);
          checkc[next[task.front()][j]].push_back(x);

          task.push(next[task.front()][j]);
          seen[next[task.front()][j]] = 1;
        }
      }
      task.pop();
    }
  }
  return m;
}

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

  vector<vector<int>> e(n - 1, vector<int>(2)), next(n, vector<int>(0));
  for (int i = 0; i < n - 1; i++) {
    cin >> e[i][0] >> e[i][1];
    next[e[i][0] - 1].push_back(e[i][1] - 1);
    next[e[i][1] - 1].push_back(e[i][0] - 1);
  }

  int k = 0, memo;
  for (int i = 0; i < n; i++) {
    if (k < next[i].size()) {
      k = next[i].size();
      memo = i;
    }
  }

  map<vector<int>, int> m = bfs(n, next, memo, k);

  cout << k << endl;
  for (int i = 0; i < n - 1; i++) {
    cout << m[{e[i][0] - 1, e[i][1] - 1}] << endl;
  }
}

Measured memory_bytes: 28160
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, M := nextInt(), nextInt()
	S, T := nextLine(), nextLine()
	Smap, Tmap := map[int]byte{}, map[int]byte{}
	LCM := lcmof2numbers(N, M)
	for i := 0; i < N; i++ {
		Smap[LCM/N*i+1] = S[i]
		// fmt.Println(LCM/N*i+1, string(S[i]))
	}
	for i := 0; i < M; i++ {
		Tmap[LCM/M*i+1] = T[i]
		// fmt.Println(LCM/M*i+1, string(T[i]))
	}
	for i := 0; LCM/M*i+1 <= LCM; i++ {
		k := LCM/M*i + 1
		// fmt.Println(k, string(Smap[k]), string(Tmap[k]))
		Sk, ifExist := Smap[k]
		if ifExist && Tmap[k] != Sk {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(LCM)
}

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

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

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}


Measured memory_bytes: 7424
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int a = 0;

    for (int i = 0; i < s.size(); i++)
    {
        if (i%2==0 && s[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
        if(i%2==1 && s[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void YES()
{
	OUT("YES");
}
void NO()
{
	OUT("NO");
}
void YESNO(const bool cond)
{
	OUT(cond ? "YES" : "NO");
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}
void YesNo(const bool cond)
{
	OUT(cond ? "Yes" : "No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
ll factorial(ll n)
{
	for (ll i = n - 1; i > 1; --i)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll ncr(const ll n, ll r)
{
	if (r * 2 > n) r = n - r;

	ll dividend = 1, divisor = 1;

	for (ll i = 1; i <= r; ++i) {
		dividend *= n - i + 1;
		divisor *= i;
	}

	return dividend / divisor;
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool isprime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0) return false;
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll digsum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll n;
	vector<string> w;
	set<string> w2;

	REP(i, n)
	{
		instr w_;
		if (i != 0 && w[i-1].back() != w_.front()) return No();
		w.push_back(w_);
		w2.insert(w_);
	}
	
	return YesNo(w.size() == w2.size());
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    ll N, D;
    cin >> N >> D;
    int ans = 0;
    rep(i, N) {
        ll X, Y;
        cin >> X >> Y;
        if (X*X + Y*Y <= D*D) ans += 1;
    }
    cout << ans << endl;
    return 0;
}


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



int main(){
	
	int n;
	cin >> n;
	vector<int> c(n-1), s(n-1), f(n-1);

	for(int i = 0; i < n-1; i++)
	{
		cin >> c[i] >> s[i] >> f[i];
	}

	for(int i = 0; i < n-1; i++)
	{
		int time=0;
		for(int j = i; j < n-1; j++)
		{
			if(time <= s[j]) time = s[j] + c[j];
			else if(time % f[j] == 0) time += c[j];
			else{
				time += f[j] - time %f[j] + c[j];
			}
		}
		cout << time << endl;
		
	}
	
	cout << 0 << endl;
	


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,n,P=0,W=0,G=0,Y=0;
    scanf("%d",&n);
    char arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%s",&arr[i]);
        if(arr[i]=='P')
        {
            P++;
        }
        if(arr[i]=='W')
        {
            W++;
        }
        if(arr[i]=='G')
        {
            G++;
        }
        if(arr[i]=='Y')
        {
            Y++;
        }

    }
    if(P&&W&&G&&Y)
        printf("Four\n");
    else
        printf("Three\n");

}


Measured memory_bytes: 128
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    inf = 10 ** 13
    h, w = list(map(int, input().rstrip('\n').split()))
    wn = 10
    wl = [[inf] * wn for _ in range(wn)]

    for i in range(wn):
        twl = list(map(int, input().rstrip('\n').split()))
        for j in range(wn):
            wl[i][j] = twl[j]

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    cost = 0
    for i in range(h):
        hw = list(map(int, input().rstrip('\n').split()))
        for j in range(w):
            if hw[j] != -1:
                cost += wl[hw[j]][1]
    print(cost)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 41196
n,m = list(map(int,input().split()))
lis = [[] for _ in range(n)]
for i in range(m):
    pc,s = input().split()
    p = int(pc)
    if s=='AC':lis[p-1].append(1)
    else:      lis[p-1].append(0)

a=w=0
for i in range(n):
    tempwa=0
    for j in lis[i]:
        if j==0:tempwa+=1
        elif j==1:
            a+=1
            w += tempwa
            break
print(a,w)

Measured memory_bytes: 14744
N=gets.to_i
S=gets.chomp

next_cache=Array.new(S.length+1){Array.new(10,-1)}



S.each_char.reverse_each.each_with_index do |c,i|
  10.times do |n|
    next_cache[N-1-i][n]=next_cache[N-i][n]
    next_cache[N-1-i][n]=N-1-i if c==n.to_s
  end
end


x=("0".."9").to_a
ans=0
x.product(x,x) do |a,b,c|
  pos=next_cache[0][a.to_i]
  next if pos==-1
  pos=next_cache[pos+1][b.to_i]
  next if pos==-1
  pos=next_cache[pos+1][c.to_i]
  next if pos==-1
  ans+=1
end
p ans




Measured memory_bytes: 8700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
typedef pair<ll,pii> ipii;
#define MOD 1000000007
#define mod(a) ((a)%MOD)
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define dbg(x) cerr<<#x<<" = "<<x<<"\n"
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<"\n"
#define dbg3(x,y,z) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<" , "<<#z<<" = "<<z<<"\n"
#define INF (1LL<<60)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define endl '\n'
ll gcd(ll a,ll b){if(a==0) return b; return gcd(b%a,a);}
ll powm(ll base,ll exp,ll mod=MOD) {base%=mod;ll ans=1;while(exp){if(exp&1LL) ans=(ans*base)%mod;exp>>=1LL,base=(base*base)%mod;}return ans;}
 



vector<ipii> p;
ll dp[10003][20004];

bool comp(ipii a,ipii b){
     return (a.ft+a.sd.ft)<(b.ft+b.sd.ft);
}


int main(){
      sync;
      ll n;
      cin>>n;
      for(int i=0;i<n;i++){
            ll w,s,v;
            cin>>w>>s>>v;
            p.pb({s,{w,v}});
      }

        sort(all(p),comp);
        ll ans=0;
        for(int i=0;i<=20000;i++){
               dp[0][i]=(p[0].sd.ft<=i?p[0].sd.sd:0);
        }
        for(int i=1;i<n;i++){
             for(int j=0;j<=20000;j++){
                  if(j==0){
                       dp[i][j]=0;continue;
                  }
                  dp[i][j]=dp[i-1][j];
                  if(p[i].sd.ft<=j){
                        dp[i][j]=max(dp[i][j],dp[i-1][min(j-p[i].sd.ft,p[i].ft)]+p[i].sd.sd);
                  }
             }
        }

        for(int i=0;i<=20000;i++) ans=max(ans,dp[n-1][i]);
        cout<<ans<<endl; 
}

Measured memory_bytes: 157952
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<25);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,ufr[225816],ufp[225816],s[100100],x[100100];
vector<int> g[100100];
P rng[100100];

void ufinit(void){
	int i;
	for(i=0; i<n*2; ++i){
		ufr[i] = 1;
		ufp[i] = i;
	}
}

int ufind(int x){
	if(x == ufp[x]){
		return x;
	}
	ufp[x] = ufind(ufp[x]);
	return ufp[x];
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x == y){
		return;
	}
	if(ufr[x] < ufr[y]){
		swap(x,y);
	}
	ufr[x] += ufr[y];
	ufp[y] = x;
}

void solve1(int u, int p = -1){
	int i,v;
	for(i=(g[u].l_ength()-1); i>=0; --i){
		v = g[u][i];
		if(v == p){
			continue;
		}
		solve1(v,u);
		rng[u].first = max(rng[u].first,rng[v].first-1);
		rng[u].second = min(rng[u].second,rng[v].second+1);
	}
}

void solve2(int u, int p = -1){
	int i,v;
	ll val;
	val = rng[u].first;
	if(ufind(u+n*(abs(val)%2))!=ufind(s[0]+n*(x[0]%2))){
		++val;
	}
	rng[u].first = val; rng[u].second = val;
	for(i=(g[u].l_ength()-1); i>=0; --i){
		v = g[u][i];
		if(v == p){
			continue;
		}
		rng[v].first = max(rng[v].first,rng[u].first-1);
		rng[v].second = min(rng[v].second,rng[u].second+1);
		solve2(v,u);
	}
}

int main(void){
	int i,u,v,k;
	cin >> n;
	fill(rng,rng+n,P(-INFLL,INFLL));
	ufinit();
	for(i=1; i<n; ++i){
		cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
		unionf(u,v+n);
		unionf(u+n,v);
	}
	cin >> k;
	for(i=0; i<k; ++i){
		cin >> s[i] >> x[i]; --s[i];
		rng[s[i]] = P(x[i],x[i]);
		if(ufind(s[i]+n*(x[i]%2))!=ufind(s[0]+n*(x[0]%2))){
			cout << "No" << endl;
			return 0;
		}
	}
	solve1(0);
	for(i=0; i<n; ++i){
		if(rng[i].first > rng[i].second){
			cout << "No" << endl;
			return 0;
		}
	}
	solve2(0);
	cout << "Yes" << endl;
	for(i=0; i<n; ++i){
		cout << rng[i].first << endl;
	}
	return 0;
}

Measured memory_bytes: 18176
#include <stdio.h>
#include <string.h>
#include <math.h>

#define DIGIT 100000

int main(void){
	char temp[1000];
	int a[100];
	int b[100];
	int c[100];
	int t;
	int n;

	scanf("%d", &n);
	for(int i=0; i<n; i++){
		for(int k=0; k<100; k++){
			a[k] = 0;
			b[k] = 0;
			c[k] = 0;
		}
		int j;
		scanf("%s", temp);

		for(int k=0, j=strlen(temp)-1; j>=0; k++){
			for(int l=0; l<5; l++, j--){
				if(j < 0) break;
				a[k] +=	(temp[j] - '0') * pow(10, l);
			}
		}

		scanf("%s", temp);
		for(int k=0, j=strlen(temp)-1; j>=0; k++){
			for(int l=0; l<5; l++, j--){
				if(j < 0) break;
				b[k] +=	(temp[j] - '0') * pow(10, l);
			}
		}

		for(j=0; j<100; j++){
			t = a[j] + b[j] + c[j];
			c[j] = t % DIGIT;
			c[j+1] += (t / DIGIT);
		}
		
		j=99;
		while(c[j] == 0 && j >= 0) j--;
		if(j == -1){
			printf("0\n");
		}else if(j > 15){
			printf("overflow\n");
		}else{
			printf("%d", c[j]);
			j--;
			for(; j>=0; j--){
				printf("%05d", c[j]);
			}
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<cmath>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=(int)(n);i>0;--i)
#define reps(i,a,b) for(int i=a;i<=(int)(b);i++)
using namespace std;

int main(){
	int N, A, B, C;
    cin >> N >> A >> B >> C;
    int *l = new int[N];
    rep(i,N) cin >> l[i];
    int *mp = new int[(int)pow(4,N)];
    rep(i,pow(4,N)) mp[i]=0;
    int x[3] = {0, 0, 0};
    int cx[3] = {0, 0, 0};
    int mmp = 10000;
    rep(i,pow(4,N)){
        rep(m,N) {
            if(((i/(int)pow(4,m))%4)!=0) {
                if(x[((i/(int)pow(4,m))%4)-1]!=0) mp[i]+=10;
                x[((i/(int)pow(4,m))%4)-1]+=l[m];
            }
        }
        mp[i] += abs(A-x[0])+abs(B-x[1])+abs(C-x[2]);
        if((x[0]!=0)&&(x[1]!=0)&&(x[2]!=0)) {
            mmp = MIN(mmp,mp[i]);
        }
        rep(j,3) x[j]=0;
    }
    cout << mmp << endl;
    //cout << cx[0] << " " << cx[1] << " " << cx[2] << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int alph[30];
    for(int i = 0; i < 30; i++){
        alph[i] = 0;
    }
    int len = s.length();
    for(int i = 0; i < len; i++){
        alph[s[i]-'a']++;
    }
    for(int i = 0; i < 30; i++){
        if(alph[i] >= 2) {cout << "no" << endl; return 0;}
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

int main() {
	const int M = 1'000'000;
	
	IN(int, n);
	vector<int> a(n), c(M + 1);
	cin >> a;
	
	RF(e, a) { c[e]++; }
	inc1(i, M) {
		for(int j = 2 * i; j <= M; j += i) { c[j] += c[i]; }
	}
	
	int ans = 0;
	RF(e, a) { if(c[e] == 1) { ans++; } }
	OUT(ans);
}


Measured memory_bytes: 8008
#include <stdio.h>

int main(void){
	int n;
	int a, b, c, d, cnt = 0;
	
	while (scanf("%d", &n) != EOF){
		cnt = 0;
		for (a = 0; a < 10; a++){
			for (b = 0; b < 10; b++){
				for (c = 0; c < 10; c++){
					for (d = 0; d < 10; d++){
						if (a+b+c+d == n){
							cnt++;
							break;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	
	return 0;
}

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

int main() {
    int N;
    int a[101];

    int alice = 0;
    int bob = 0;

    cin >> N;

    for (int i=0;i<N;++i) cin >> a[i];
    
    std::sort(a, a+N);
    
    int cnt = 0;
    for (int i=N-1; i>=0; --i) {
        if (cnt%2 == 0) {
           alice += a[i]; 
        } else {
            bob += a[i];
        }
        ++cnt;
    }

    cout << alice - bob << endl;

}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int x;
	cin>>x;
	long long int rem=x%11;
	long long int c=0;
	while(rem>=6){
		rem-=6;
		c++;
	}
	if(rem>0){
		c++;
	}
	cout<<(x/11)*2+c;
	return 0;
}

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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

#define tlll tuple<ll,ll,ll>
#define mt make_tuple
vector<ll> graph[55];
pair<ll,ll> A[55][55];
pair<ll,ll> C[55];
ll dp[55][2505];
ll n,m,S;

void solve(){
    
    cin >> n >> m >> S;
    S = min(S,2500ll);
    for(ll i=0;i<n+1;i++){
        for(ll j=0;j<n+1;j++){
            A[i][j] = {-1,-1};
        }
    }

    for(ll i=0;i<m;i++){
        ll x,y;
        cin >> x >> y;
        x--;y--;
        graph[x].pb(y);
        graph[y].pb(x);
        ll a,b;
        cin >> a >> b;
        A[x][y] = {a,b};
        A[y][x] = {a,b};
    }
    for(ll i=0;i<n;i++){
        cin >> C[i].ff >> C[i].ss;
    }

    for(ll i=0;i<55;i++){
        for(ll j=0;j<2505;j++){
            dp[i][j] = oo;
        }
    }
    dp[0][S] = 0;

    priority_queue<tlll,vector<tlll>,greater<tlll> > pq;
    /*
        0 : time
        1 : node
        2 : coins  
    */
    pq.push(mt(0,0,S));
    while (pq.size()){
        tlll curr = pq.top();
        pq.pop();

        ll time_s = get<0>(curr);
        ll s = get<1>(curr);
        ll coins = get<2>(curr);

        if( dp[s][coins] + C[s].ss <  dp[s][min(2500ll,coins + C[s].ff)] ){
            dp[s][min(2500ll,coins + C[s].ff)] =  dp[s][coins] + C[s].ss;
            pq.push(mt(dp[s][coins] + C[s].ss,s,min(2500ll,coins + C[s].ff)));
        }

        for(auto child : graph[s]){
            ll rem_coins = coins - A[s][child].ff;
            if( rem_coins < 0 ) 
                continue;
            ll time_child = time_s + A[s][child].ss;
            if( dp[child][rem_coins] > time_child ){
                dp[child][rem_coins] = time_child;
                pq.push(mt(time_child,child,rem_coins));
            }
        }
    }

    for(ll i=1;i<n;i++){
        ll ans=oo;
        for(ll j=0;j<2501;j++){
            ans = min(ans , dp[i][j]);
        }
        cout << ans << endl; 
    }

}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 7388
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<bool,int>;
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;}
const int inf = 1001001001;

int main() {
    int n,m;
    cin >> n >> m;
    int co = 0;
    int pe = 0;
    vector<P> pro(n,{false,0});
    rep(i,m) {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC") {
            if(!pro[p].first) {
                pro[p].first = true;
                co++;
                pe += pro[p].second;
            }
        } else pro[p].second++;
    }
    cout << co << " " << pe << endl;
}

Measured memory_bytes: 1024
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

if A.count(0) == N:
    print("Yes")
    exit()

d = Counter(A)
if len(d.keys()) > 3:
    print("No")
    exit()
elif len(d.keys()) == 3:
    a, b, c = d.keys()
    if d[a] == d[b] == d[c] and a ^ b ^ c == 0:
        print("Yes")
    else:
        print("No")
    exit()
elif len(d.keys()) == 2:
    a, b = d.keys()
    if a * b != 0:
        print("No")
    else:
        if a != 0:
            d[a], d[b] = d[b], d[a]  # aを0にする
        if d[a] * 3 == N and 3 * d[b] == 2 * N:
            print("Yes")
        else:
            print("No")
    exit()
print("No")



Measured memory_bytes: 20828
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

const int maxN = 1e6;

void solve()
{
    int k;
    cin >> k;

    if(k % 2 == 0)
    {
        cout << "-1\n";
        return;
    }

    vector<ll> ten(maxN + 1, 1);

    for(int i = 1; i <= maxN; i++)
    {
        ten[i] = ten[i - 1] * 10;
        ten[i] %= k;
    }

    ll curr = 0;

    for(int i = 0; i <= maxN; i++)
    {
        if((curr % k + (7 * ten[i]) % k) % k == 0)
        {
            cout << i + 1 << "\n";
            return;
        }

        curr += (7 * ten[i]) % k;
        curr %= k;
    }

    cout << "-1\n";

}

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

    int T = 1;
    //cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}




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

long long ans, a, b, c, k;

int main() {
	cin >> a >> b >> c >> k;
	ans += min(a, k);
	k -= min(a, k);
	k -= min(b, k);
	ans -= min(c, k);
	k -= min(c, k);
	cout << ans << "\n";
}

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

int main(){
  int N;
  cin >> N;
  vector<int> card(N);
  for(int i = 0; i < N; ++i)
    cin >> card.at(i);
  sort(card.begin(),card.end(),greater<int>());
  int result = 0;
  for(int i = 0; i < N; ++i){
    if(i%2==0) result+=card.at(i);
    else result-=card.at(i);
  }
  cout << result << endl;
}


Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main(void){
    
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0)break;
        char s[n][1919];
        for(int i=0;i<n;i++)scanf("%s",s[i]);
        int a[n];
        for(int i=0;i<n;i++)for(int j=0;;j++){if(s[i][j]!='.'){a[i]=j;break;}}
        for(int i=0;i<n;i++){
            if(a[i]!=0)s[i][a[i]-1]='+';
        }
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(a[i]>a[j])break;
                if(a[i]==a[j]){
                    for(int k=i+1;k<j;k++)s[k][a[i]-1]='|';
                    break;
                }
            }
        }
        for(int i=0;i<n;i++)for(int j=0;j<a[i];j++)if(s[i][j]=='.')s[i][j]=' ';
        for(int i=0;i<n;i++)printf("%s\n",s[i]);
    }
    
    return 0;
}



Measured memory_bytes: 4980
IDENTIFICATION DIVISION.
PROGRAM-ID. 098C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 S          PIC X(300000).
*>
WORKING-STORAGE SECTION.
01 N          PIC 9(6) COMP.
01 I          PIC 9(6) COMP.
01 W-CNT      PIC 9(6) COMP.
01 E-CNT      PIC 9(6) COMP.
01 WW         PIC 9(6) COMP.
01 EW         PIC 9(6) COMP.
01 M          PIC 9(6) COMP.
01 MIN        PIC 9(6) COMP.  
01 OUT        PIC Z(5)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.         
  CLOSE STDIO.
*>
  MOVE 0 TO W-CNT E-CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (S(I:1) = 'W')
      ADD 1 TO W-CNT
    ELSE
      ADD 1 TO E-CNT
    END-IF
  END-PERFORM.
*>
  MOVE N TO MIN.
  MOVE 0 TO WW EW.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (S(I:1) = 'E')
      ADD 1 TO EW
    END-IF
*>
    COMPUTE M = WW + (E-CNT - EW)
    IF (MIN > M)
      MOVE M TO MIN
    END-IF   
*>
    IF (S(I:1) = 'W')
      ADD 1 TO WW
    END-IF
  END-PERFORM.
*>
  MOVE MIN TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 1148
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H;
  vector<bool> isGood;
  for (int i=0; i < N; i++) {
    int Hi;
    cin >> Hi;
    H.push_back(Hi);
    isGood.push_back(true);
  }
 
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    if (H[A-1] > H[B-1]) {
      isGood[B-1] = false;
    } else if (H[A-1] == H[B-1]) {
      isGood[A-1] = false;
      isGood[B-1] = false;
    } else {
      isGood[A-1] = false;
    }
  }
 
  int count = 0;
  for(bool good : isGood) {
    if (good) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s, t;
    cin >> s >> t;
    ll sl = len(s), tl = len(t);
    vector<vector<ll>> dp(sl + 1, vector<ll>(tl + 1, 0));
    reps(i, 1, sl + 1) {
        reps(j, 1, tl + 1) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    string ans = "";
    ll sp = sl, tp = tl, cv = dp[sl][tl];
    while(cv > 0) {
        if (s[sp - 1] == t[tp - 1]) {
            ans += s[sp - 1];
            sp--;
            tp--;
            cv--;
        }
        else if (dp[sp - 1][tp] > dp[sp][tp - 1]) {
            sp--;
        }
        else {
            tp--;
        }
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70784
x = gets.to_i
arr = [1000, 961, 900, 841, 784, 729, 676, 625, 576, 529, 512, 484, 441, 400, 361, 343, 324, 289, 256, 243, 225, 216, 196, 169, 144, 128, 125, 121, 100, 81, 64, 49, 36, 32, 27, 25, 16, 9, 8, 4, 1]
puts arr.find{|item| item <= x}

Measured memory_bytes: 1788
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a,b,c,d,x,y,z;
  string s,t;
  //

  // ここから
  IN2(s,t);
  if(s==t) OUT("H");
  else OUT("D");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    int a, b, t, ans = 0, cntr = 2, temp;
    cin >> a >> b >> t;
    temp = a;
    for(int i = 1; i <= 100; i++){
        if(i * a > t)
            break;
        ans += b;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
    int n;
    
    Scanner sc = new Scanner(System.in);
	n = sc.nextInt();

	int x[] = new int[n];
	int y[] = new int[n];
	
	for (int i = 0; i < n; i++) {
		x[i] = sc.nextInt();
		y[i] = sc.nextInt();
	}

	double sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			sum += Math.sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
		}
	}
	
	double ave = sum / (n * (n - 1));
	
	System.out.println( ave * (n - 1));

    return;
  }
}

    
    
    


Measured memory_bytes: 21716
using System;

namespace C_sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var i = 1;
            while (true)
            {
                var line = Console.ReadLine();
                var x = int.Parse(line);
                if (x == 0)
                {
                    break;
                }
                Console.WriteLine($"Case {i}: {x}");
                i++;
            }
        }
    }
}



Measured memory_bytes: 19976
#include <iostream>
#include <vector>
#include <stack>
#include <string>
using namespace std;
long long n, m;
string s;
int main() {
	cin >> n;
    if(n%2!=0){
        cout << 2*n << endl;
    }else{
        cout << n << endl;
    }
	return 0;
}


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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    
    int n, k;
    cin >> n >> k;
    vi sol;
    cout << setprecision(15) << fixed;
    for(int i=1; i<=n; i++){
        int cnt = 0;
        int curr = i;
        while(curr < k){
            curr*=2;
            cnt++;
        }
        int p2 = pow(2, cnt);
        sol.push_back(n * p2);
    }
    int mx = sol[0];
    int res = 1;
    for(int i=1; i<sol.size(); i++){
        res += mx/sol[i];
    }
    ld a = (ld) res/mx;
    cout << a;
}

Measured memory_bytes: 892
package main

import (
	"fmt"
	"sort"
)

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

	vs := make([][]int, n)
	for i := 0; i < n; i++ {
		vs[i] = make([]int, 0)
	}
	var a, b int
	for i := 0; i < n-1; i++ {
		fmt.Scan(&a, &b)
		a, b = a-1, b-1
		vs[a] = append(vs[a], b)
		vs[b] = append(vs[b], a)
	}

	cs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cs[i])
	}
	sort.Ints(cs)
	sum := 0
	for i := 0; i < n-1; i++ {
		sum += cs[i]
	}

	k := 0
	ans := make([]int, n)
	var dfs func(i int)
	dfs = func(i int) {
		if i == n || ans[i] > 0 {
			return
		}
		ans[i] = cs[n-k-1]
		k++
		for _, e := range vs[i] {
			dfs(e)
		}
	}
	dfs(0)

	fmt.Println(sum)
	for i := 0; i < n; i++ {
		if i < n-1 {
			fmt.Printf("%d ", ans[i])
		} else {
			fmt.Println(ans[i])
		}
	}
}


Measured memory_bytes: 4352
while 1:
    x=input().split()
    a=int(x[0])
    op=x[1]
    b=int(x[2])
    if op=='?':
        break
    if op=='+':
        print("%d"%(a+b))
    elif op=='-':
        print("%d"%(a-b))
    elif op=='/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))


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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif
#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int n, m, k, x;
string s;



integer main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    int q;
    map<int, int> M;
    int sum = 0;
    for (int i = 0; i < n; i++){
        cin >> ar[i];
        M[ar[i]]++;
        sum += ar[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++){
        int a, b;
        cin >> a >> b;
        if (!M.count(a)){
            cout << sum << endl;
            continue;
        }
        int cnt = M[a];
        sum -= cnt * a;
        sum += cnt * b;
        M[b] += cnt;
        M.erase(a);
        cout << sum << endl;
    }

}


Measured memory_bytes: 8248
#include <iostream>
#include <string>
#include <cstring>
#define MAX 100
using namespace std;

int X,Y;
bool flg[MAX][MAX];
string map[MAX];
int main() {
	while (cin >> Y >> X, X||Y) {
		for (int i=0; i<Y; i++)
			cin >> map[i];

		memset(flg, 0, sizeof(flg));
		int x=0,y=0;
		bool f=true;
		while (f) {
			if (flg[y][x]) { cout << "LOOP\n"; break; }
			flg[y][x] = true;
			switch (map[y][x]) {
				case '>':
					x++; break;
				case 'v':
					y++; break;
				case '<':
					x--; break;
				case '^':
					y--; break;
				case '.':
					cout << x << ' ' << y << endl;
					f = false;
					break;
			}
		}
	}
	return 0;
}

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

//-std=c++11
//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long
#define FI ios_base::sync_with_stdio(0); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = 998244353;
const int INF = 1e9 + 9;
const int MX = 2e5 + 5;

#define int long long

int n, k;
pair<int, int> inp[10];
int dp[MX];
int pre[MX];

#undef int 
int main()
{
	#define int long long
	cin >> n >> k;
	for(int i=0;i<k;i++) {
		cin >> inp[i].first >> inp[i].second;
	}

	dp[1] = 1;
	pre[1] = 1;

	for(int i=2;i<=n;i++) {
		dp[i] = 0;
		for(int j=0;j<k;j++) {
			int l = i - inp[j].second;
			int r = i - inp[j].first;
			if(r < 1) {
				continue;
			}

			l = max(1LL, l);
			dp[i] = (dp[i] + pre[r] - pre[l-1])%MOD;
			dp[i] = (dp[i] + MOD)%MOD;
		}
		pre[i] = (pre[i-1] + dp[i])%MOD;
	}

	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )
#define SORT(x) sort(x.begin(), x.end())

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K; cin >> N >> K;
    ll sum = 0, ans = 0;
    vector<pair<ll, ll>> v(N);
    rep (i, N) {
        cin >> v[i].fi >> v[i].sc;
    }

    sort(ALL(v));

    rep (i, N) {
        sum += v[i].sc;
        if (sum >= K) {
            ans = v[i].fi;
            break;
        }
    }
    COUT(ans);
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, K: int):
    if K == 1:
        return 0

    return N - K


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(N, K)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5372
#include <stdio.h>

int abs(int a);
int gcd(int a, int b);

int N, X;
int a[100009];

int main(void)
{
	int i, ans;
	scanf("%d%d", &N, &X);
	for (i = 0; i < N; ++i) scanf("%d", a + i);
	for (i = 0; i < N; ++i) a[i] = abs(X - a[i]);
	ans = a[0];
	for (i = 0; i < N; ++i) ans = gcd(ans, a[i]);
	printf("%d\n", ans);
	return 0;
}

int abs(int x)
{
	if (x < 0) return -x;
	return x;
}

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main(){
    int n,m;
    cin >> n >> m;
    ve<int> p(n);
    UnionFind uf(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x,y);
    }
    int ans = 0;
    rep(i,n){
        if(uf.same((int)i,p[i]))ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;

int main(){
    ll x,y;
    while(~scanf("%lld %lld",&x, &y)){
    	ll n = 0;
		for(ll i = 1; i <= 1e8; i++){
			ll c = i * x;
			if(c % y != 0){
				n = c;
				break;
			}
		}
		if(n == 0)
			printf("-1\n");
		else
			printf("%lld\n", n);
	}
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int A=0,B=0;
	int max=0;
	int P=0,M=0,K=0;
	cin>>A>>B;
	P=A+B;
	M=A-B;
	K=A*B;
	max=P;
	if(max<M) max=M;
	if(max<K) max=K;
	cout<<max<<endl;
	return 0;

	}

Measured memory_bytes: 256
list = str(input()).split()
if int(list[0]) == int(list[1]):
   if int(list[1]) == int(list[2]):
      print(1)
   else :
      print(2)
elif int(list[0]) == int(list[2]):
   print(2)
elif int(list[1]) == int(list[2]):
   print(2)
else:
   print(3)

Measured memory_bytes: 3064
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < (int) s.length(); ++i) {
		if (s[i] != t[i]) {
			++cnt;
		}
	}
	cout << cnt << '\n';
	
	return 0;
}


Measured memory_bytes: 3872
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(N),B(N);
  int a=0,b=0;
  for(int &i:A){
    cin>>i;
    a+=i;
  }
  for(int &i:B){
    cin>>i;
    b+=i;
  }
  int cnt1=0,cnt2=0;
  for(int i=0;i<N;i++){
    if(A[i]<B[i])
      cnt2+=(B[i]-A[i]+1)/2;
    else if(A[i]>B[i])
      cnt1+=A[i]-B[i];
  }
  if(cnt1>b-a || cnt2>b-a)
    puts("No");
  else
    puts("Yes");
}

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

int main(){
    int x, y;
    rep(i, 3000){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        else{
            cout<<min(x, y)<<" "<<max(x, y)<<endl;
        }
    }
}


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

const int MAX = 1e5+1;
int dp[MAX];
int indegree[MAX];
bool visited[MAX];
vector<int> edges[MAX];

void dfs(int node){
	if(!visited[node]){
		visited[node] = true;
		for(int i: edges[node]){
			dp[i]=max(dp[i], dp[node]+1);
			--indegree[i];
			if(indegree[i]==0)
				dfs(i);
		}
	}
}

int main(){
	int n, m; cin>>n>>m;
	int u,v;
	for(int i=0; i<m; ++i){
		cin>>u>>v;
		edges[u].push_back(v);
		++indegree[v];
	}

	for(int i=1; i<=n; ++i){
		if(!visited[i] && indegree[i]==0){
			dfs(i);
		}
	}
	int ans = 0;
	for(int i=1; i<=n; ++i){
		ans = max(ans, dp[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------

int main(void){
    // Your code here!
    int n; cin >> n;
    vi p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    rep(i,n) {
        if (i + 1 == p[i] && i + 2 == p[i+1]) {
            ans++;
            i++;
        }else if (i + 1 == p[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int x[150][150][2],n,m,l,a,b,c,d,i,j,k,o,minx,INF=1<<25,dp[150][150];
int DP(int p,int v){memset(dp,127,sizeof(dp));dp[0][v]=0;for(i=0;i<p;i++){for(j=0;j<n;j++){for(k=0;k<n;k++){if(x[j][k][0]<INF){
for(o=0;o<=v;o++){if(dp[j][o]<INF){dp[k][o]=min(dp[k][o],dp[j][o]+x[j][k][1]);if(o>=x[j][k][0]){dp[k][o-x[j][k][0]]=min(dp[k][o-x[j][k][0]],dp[j][o]);
}}}}}}}minx=INF;for(i=0;i<=v;i++){minx=min(minx,dp[p-1][i]);}return minx;}
main(){while(1){memset(x,127,sizeof(x));cin>>n>>m>>l;if(!n){break;}for(i=0;i<m;i++){cin>>a>>b>>c>>d;a--;b--;x[a][b][0]=c;x[a][b][1]=d;
x[b][a][0]=c;x[b][a][1]=d;}cout<<DP(n,l)<<endl;}}

Measured memory_bytes: 1432