akhauriyash/Code-Regression huggingface dataset:
class Card():
    def __init__(self, suit: chr, number: int):
        self.suit = suit
        self.number = number

def partition(a: list, left: int, right: int) :
    std = a[right].number
    j = left - 1
    for i, v in enumerate(a[left:right]):
        idx = i + left
        if a[idx].number <= std:
            j += 1
            a[j], a[idx] = a[idx], a[j]

    j += 1
    a[j], a[right] = a[right], a[j]
    return j

def quick_sort(a: list, left: int, right: int):
    if left < right:
        sep = partition(a, left, right)
        quick_sort(a, left, sep-1)
        quick_sort(a, sep+1, right)

def merge(a: list, left: int, mid: int, right: int):
    n1 = mid - left
    n2 = right - mid

    L = []
    R = []
    for i in range(n1):
        L.append(a[left+i])
    for i in range(n2):
        R.append(a[mid+i])

    inf = 1 << 32
    L.append(Card("Z", inf))
    R.append(Card("Z", inf))

    i = 0
    j = 0
    for k in range(left, right, 1):
        if L[i].number <= R[j].number:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1

def merge_sort(a: list, left: int, right: int):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

def is_stable(m, q):
    for i, j in zip(m, q):
        if i.number != j.number or i.suit != j.suit:
            return False
    return True

n = int(input())

cards = []
for i in range(n):
    card_info = input().split(" ")
    cards.append(Card(card_info[0], int(card_info[1])))

merge_sorted = cards.copy()
quick_sorted = cards.copy()

merge_sort(merge_sorted, 0, len(merge_sorted))
quick_sort(quick_sorted, 0, len(quick_sorted) - 1)
stable = is_stable(merge_sorted, quick_sorted)

if stable:
    print("Stable")
else:
    print("Not stable")

for c in quick_sorted:
    print("{} {}".format(c.suit, c.number))

# print("##############")
# for c in merge_sorted:
#     print("{} {}".format(c.suit, c.number))


Measured memory_bytes: 28684
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int A;
  int B;
  int M;
  
  cin >> A >> B >> M;
  
  vector<int> a(A);
  vector<int> b(B);
  
  for(int i = 0;i < A;++i){
    cin >> a[i];
  }
  
  for(int i = 0;i < B;++i){
    cin >> b[i];
  }
  
  vector<int> x(M);
  vector<int> y(M);
  vector<int> c(M);
  
  for(int i = 0;i < M;++i){
    cin >> x[i] >> y[i] >> c[i];
  }
  
  vector<int> z(M);
  
  for(int i = 0;i < M;++i){
    int X = x[i] - 1;
    int Y = y[i] - 1;
    int num = a[X] + b[Y] - c[i];
    z[i] = num;
  }
      
      
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(z.begin(),z.end());
  
  int kin = a[0] + b[0];
  
  cout << min(kin,z[0]) << endl;
}
        
        

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	string s;
	cin >>s;
	
	ll ans=700;
	
	rep(i,3)
	if(s[i]=='o') ans+=100;
	
	cout<<ans<<endl;
	
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=5e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int a[N];LL pre[N];
int main()
{
	int n=gi(),i,m=n*3;LL ans=-1LL<<60,sum=0;
	priority_queue<int>q,qq;
	for (i=1;i<=m;i++) {
		a[i]=gi();
		q.push(-a[i]);pre[i]=pre[i-1]+a[i];
		if (i>n) pre[i]+=q.top(),q.pop();
	}
	for (i=m;i>n;i--) {
		sum-=a[i];
		qq.push(a[i]);
		if (m-i+1>=n) {
			if (i<=m-n) sum+=qq.top(),qq.pop();
			ans=max(ans,sum+pre[i-1]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6520
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!
    val dp = Array(s.length + 1) { IntArray(t.length+1) }
    for (x in 1 .. s.length) {
        for (y in 1 .. t.length) {
            if (s[x-1] == t[y-1]) {
                dp[x][y] = dp[x-1][y-1] + 1
            } else {
                dp[x][y] = Math.max(dp[x][y-1], dp[x-1][y])
            }
        }
    }
    var x=s.length
    var y = t.length
    var ans = ""
    while(x!= 0 && y != 0) {
        when {
            dp[x][y] == dp[x-1][y] -> x--
            dp[x][y] == dp[x][y-1] -> y--
            dp[x][y] == dp[x-1][y-1] + 1 -> {
                ans = s[x-1] + ans
                x--
                y--
            }
        }
    }
    println(ans)
}

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

# 整数の入力
n = int(input())
# スペース区切りの整数の入力
h = list(map(int, input().split()))

baseHeight = h[0]
canViewCnt = 1

for i in range(1,n):
    canView = True
    for j in range(i):
        if h[i] < h[j]:
            canView = False
            break
    if canView == True:
        canViewCnt += 1

# 出力
print(str(canViewCnt))


Measured memory_bytes: 3060
#include <iostream>
#include <list>
#include <stack>
#include <set>
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

ll n, t, x, y;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	ll nt, nx, ny;
	nt = nx = ny = 0;
	bool f = 0;
	for (int i = 0; i < n; i++) {
		cin >> t >> x >> y;
		ll T = t - nt, X = abs(x - nx), Y = abs(y - ny);
		if (T < X + Y) {
			f = 1;
			break;
		}
		T -= X;
		if (T % 2 != Y % 2) {
			f = 1;
			break;
		}
		nt = t, nx = x, ny = y;
	}
	cout << (f ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
	s := nextString()
	if len(s)%2 == 1 {
		fmt.Println("No")
		return
	}
	for i := 0; i < len(s); i++ {
		if i%2 == 0 {
			if s[i] != 'h' {
				fmt.Println("No")
				return
			}
		} else {
			if s[i] != 'i' {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
class ilds1_5_c{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    Vec v0 = new Vec(0,0);
    Vec vn = new Vec(100,0);
    v0.printVector();
    koch(v0,vn,n);
    vn.printVector();
  }
  public static void koch(Vec begin, Vec end, int n){
    if(n != 0){
      Vec v1, v2, v3;
      double th = Math.PI*60/180;
      v1 = new Vec((2*begin.x + end.x)/3, (2*begin.y + end.y)/3);
      v3 = new Vec((begin.x + 2*end.x)/3, (begin.y + 2*end.y)/3);
      v2 = new Vec((v3.x-v1.x)*Math.Cos(th) - (v3.y-v1.y)*Math.Sin(th) + v1.x,
        (v3.x-v1.x)*Math.Sin(th) + (v3.y-v1.y)*Math.Cos(th) + v1.y);

      koch(begin,v1,n-1);
      v1.printVector();
      koch(v1,v2,n-1);
      v2.printVector();
      koch(v2,v3,n-1);
      v3.printVector();
      koch(v3,end,n-1);
    }
  }
  public static void printVector(Vec v){
    Console.WriteLine("{0} {1}",v.x, v.y);
  }
}
class Vec{
  public double x{ set; get; }
  public double y{ set; get; }
  public Vec(double tx, double ty){
    x = tx;
    y = ty;
  }
  public void printVector(){
    String sx = string.Format("{0:F8}",x);
    String sy = string.Format("{0:F8}",y);
    Console.WriteLine("{0} {1}",sx,sy);
  }
}



Measured memory_bytes: 17864
#include <cstdio>
int main(){
	int a, b;
	while(1){
		scanf("%d%d", &a, &b);
		if(a==0&&b==0) return 0;
		printf("%d %d\n", a<b?a:b, a>b?a:b);
	}
	return 0;
}


Measured memory_bytes: 2564
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

H,W = LI()
a  = [list(map(str,input())) for _ in range(H)]

d = defaultdict(int)
for i in range(H):
    for j in range(W):
        d[a[i][j]] += 1

if H%2 == 0 and W%2 == 0:
    for k in d.keys():
        if d[k]%4 != 0:
            print('No')
            exit()
    print('Yes')
elif H%2 == 0 and W%2 != 0:
    count = 0
    for k in d.keys():
        if d[k]%4 != 0:
            if d[k]%2 != 0:
                print('No')
                exit()
            else:
                count += 1
    if count%2 == (H//2)%2 and H//2 >= count:
        print('Yes')
    else:
        print('No')
elif W%2 == 0 and H%2 != 0:
    count = 0
    for k in d.keys():
        if d[k]%4 != 0:
            if d[k]%2 != 0:
                print('No')
                exit()
            else:
                count += 1
    if count%2 == (W//2)%2 and W//2 >= count:
        print('Yes')
    else:
        print('No')
else:
    odd_flag = False
    count = 0
    for k in d.keys():
        if d[k]%4 != 0:
            if d[k]%2 != 0:
                if not odd_flag:
                    odd_flag = True
                    if (d[k]-1)%4 != 0:
                        count += 1
                else:
                    print('No')
                    exit()
            else:
                count += 1
    if count%2 == ((H-1)//2+(W-1)//2)%2 and (H-1)//2+(W-1)//2 >= count:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 39664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int a; cin >> a;
    string s; cin >> s;
    if(a >= 3200){
        cout << s << endl;
    }
    else{
        cout << "red" << endl;

    }

    return 0;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}

int main() {
  ll N;
  cin>>N;
  vector<ll> v(N);
  rep(i,N) cin>>v[i];
  sort(v.begin(),v.end());
  ll ans = 0;
  ll k = pow(2LL,N-1,mod);
  rep(i,N){
    ans = (ans + k*(i+2)%mod*v[N-1-i])%mod;
  }
  ans = (ans  * pow(2LL,N-1,mod))%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 4768
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
int func(int n);

int main() {
	int n;
	cin >> n;
	int a, b;
	int minv = n;
	for (int i = 1; i < n; i++) {
		a = i;
		b = n - a;
		a=func(a);
		b=func(b);
		if (min(minv, (a + b)) == (a + b)) {
			minv = a + b;
		}
	}
	cout << minv << endl;
	return 0;
}
int func(int n) {
	int sum = 0;
	if (n < 10) {
		return n;
	}else{
		while (true) {
			sum += n % 10;
			if (n < 10) break;
			n /= 10;
		}
		return sum;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int h,w,k;
  cin>>h>>w>>k;
  char c[310][310];
  rep(i,h){
    cin>>c[i];
  }

  int s[310][310]={};
  int kk=0;
  rep(i,h){
    int t=0;
    rep(j,w){
      if(c[i][j]=='#'){
        kk++;
        t=kk;
      }
      s[i][j]=t;
    }
  }

  rep(i,h){
    rrep(j,w-1){
      if(s[i][j]==0){
        s[i][j]=s[i][j+1];
      }
    }
  }

  rep(j,w){
    rep(i,h){
      if(i&&s[i][j]==0){
        s[i][j]=s[i-1][j];
      }
    }
  }

  rep(j,w){
    rrep(i,h-1){
      if(s[i][j]==0){
        s[i][j]=s[i+1][j];
      }
    }
  }

  rep(i,h){
    rep(j,w){
      cout<<s[i][j]<<' ';
    }
    cout<<endl;
  }


}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	int m;
	cin >> m;
	if(n==m) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

int a[100010];
int n, m, v, p;

void solve() {
	int ans = p;
	for (int i = 0; i < n - p; i++) {
		int cnt = v - i - 1;
		if (a[i] == a[n - p]) {
			ans++;
			continue;
		}
		if (cnt < p) {
			if (a[i] + m >= a[n - p]) ans++;
		} else {
			vector <int> v;
			for (int j = i + 1; j <= n - p; j++) {
				v.push_back(a[j]);
			}
			if (m <= 10000) {
				for (int _ = 0; _ < m; _++) {
					int tot = 0;
					for (int j = 0; j < cnt - p + 1; j++) {
						if (v[j] < a[i] + m) v[j]++;
						else tot++;
					}
					if (tot > 0) goto END;
					sort(v.begin(), v.end());
				}
				ans++;
				END:;
			}
		}
	}
	printf("%d\n", ans);
	exit(0);
}

int main () {
	scanf("%d%d%d%d", &n, &m, &v, &p);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	if (n <= 10) solve();
	int e = n - p;
	while (e > 0 && a[e] == a[e - 1]) e--;
	int ans = n - e;
	int pos = -1;
	for (int i = 0; i < e; i++) {
		int cnt = v - i - 1;
		if (cnt == p) pos = i;
		if (cnt < p && a[i] + m >= a[e]) ans++;
	}
	long long sum = 0;
	int tot = 0, tmp = 1;
	if (~pos) {
		for (int i = pos + 1; i <= n - p; i++) {
			sum += a[i], tot++;
		}
	}
	for (int i = e - 1; i >= 0; i--) {
		int cnt = v - i - 1;
		if (cnt >= p) {
			if (a[i] + m < a[n - p]) {
				sum += a[i], tot++, tmp++;
				continue;
			}
			if (1ll * (a[i] + m) * tot - sum >= 1ll * m * tmp) ans++;
			sum += a[i], tot++, tmp++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n,a,b;
    int ca=0,cb=0;
    string str;

    cin >> n >> a >> b;
    cin >> str;

    for(int i=0;i<str.size();i++){
        if(str[i]=='a'&&ca+cb<a+b){
            cout << "Yes" << endl;
            ca++;
        }else if(str[i]=='b'&&ca+cb<a+b&&cb<b){
            cout << "Yes" << endl;
            cb++;
        }else{
            cout <<"No"<<endl;
        }
    }
}   


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

vector <vector <long long> > DP;
vector <vector <int> > G;
vector <int> Stopnie;
long long Modulo = 1000000007;
int main(){
    ios_base::sync_with_stdio(0);
    int N;
    cin >> N;
    if (N == 1){
        cout << 2 << "\n";
        return 0;
    }
    DP.resize(N, vector <long long>(2)); // dla kazdego wierzcholka sposoby jesli jest bialy / czarny
    G.resize(N);
    Stopnie.resize(N);
    for (int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        Stopnie[a]++;
        Stopnie[b]++;
    }
    queue <int> Q;
    vector <bool> ODW;
    ODW.resize(N);
    for (int i = 0; i < N; i++){
        if (Stopnie[i] == 1){
            Q.push(i);
            ODW[i] = true;
        }
    }
    
    int Root;
    while (!Q.empty()){
       
        int W = Q.front(); 
        ODW[W] = true;
        // cerr << "Rozpatruje " << W+1 << "\n";
        Root = W;
        Q.pop();
        DP[W][0] = 1;
        DP[W][1] = 1;
        for (auto sas : G[W]){
            if (ODW[sas] == 1){ // czyli jest dzieckiemc
                // cerr << "dziecko " << sas+1 << "\n";
                DP[W][0] = DP[W][0]*(DP[sas][1] + DP[sas][0]); // jesli jest bialy, to dzieci sa dowolne
                DP[W][1] = DP[W][1]*DP[sas][0]; // jesli czarny, to wszystkie dzieci biale
                if (DP[W][0] > Modulo){
                    DP[W][0] %= Modulo;
                }
                if (DP[W][1] > Modulo){
                    DP[W][1] %= Modulo;
                }
            }

        }
        // cerr << W+1 << "====\n";
        // cerr << DP[W][0] << " " << DP[W][1] << "\n";
        // cerr << "=====\n";
        for (auto sas : G[W]){
            Stopnie[sas]--;
            if (Stopnie[sas] == 1){
                Q.push(sas);
                
            }
        }
    }
    cout << (DP[Root][0] + DP[Root][1])%Modulo;
}

Measured memory_bytes: 12544
#include<stdio.h>
int main()
{
	int n,a[21],b[21],c[20],i,m=0;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
	for(i=0;i<n-1;i++)
		scanf("%d",&c[i]);
	for(i=0;i<n;i++){
		m+=b[a[i]-1];
		if((i>0)&&(a[i]==a[i-1]+1))
			m+=c[a[i-1]-1];
	}
	//m+=b[a[n-1]-1];
	printf("%d\n",m);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stdio.h>
#include<cmath>

using namespace std;

int main(void)
{
	int num[3];

	int i, lot;
	lot = 0;

	for (i = 0; i < 3; i++)
	{
		cin >> num[i];
	}
	for (i = 1; i < 3; i++)
	{
		if (num[0] == num[i])
		{
			break;
		}
}
	if (i == 1)
	{
		cout << num[2];
	}
	else if (i == 2)
	{
		cout << num[1];
	}
	else
	{
		cout << num[0];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Usize1},
};

struct UnionFind {
    size: usize,
    pos: Vec<isize>,
}

impl UnionFind {
    /// UnionFindを作る関数
    fn new(n: usize) -> Self {
        let size = n;
        let pos = vec![-1; n + 1];
        UnionFind { size, pos }
    }

    /// rootを探す関数
    fn find(&mut self, x: usize) -> usize {
        if self.pos[x] < 0 {
            x
        } else {
            let v = self.pos[x] as usize;
            self.pos[x] = self.find(v) as isize;
            self.pos[x] as usize
        }
    }

    fn unite(&mut self, x: usize, y: usize) -> Result<(), ()> {
        let mut x = self.find(x);
        let mut y = self.find(y);

        // x, y共にrootが設定済みで尚且つ
        // rootが同じ時
        if x == y {
            return Err(());
        }
        if self.pos[x] > self.pos[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.pos[x] += self.pos[y];
        self.pos[y] = x as isize;

        Ok(())
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn size(&mut self, x: usize) -> usize {
        let x = self.find(x);
        -self.pos[x] as usize
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        par: [(Usize1, Usize1); m]
    }
    let mut uf = UnionFind::new(n);
    for &(x, y) in &par {
        uf.unite(x, y).ok();
    }
    let mut ans = 1;
    for i in 0..n {
        ans = std::cmp::max(ans, uf.size(i));
    }
    println!("{}", ans);
}


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

using namespace std;

int main()
{
	int h1, h2, k1, k2, a, b, c, d;
	cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
	int hp = h1 * a + h1 / 10 * c + h2 * b + h2 / 20 * d, kp = k1 * a + k1 / 10 * c + k2 * b + k2 / 20 * d;
	if (hp > kp)
		cout << "hiroshi" << endl;
	else if (hp < kp)
		cout << "kenjiro" << endl;
	else
		cout << "even" << endl;

	return 0;
}



Measured memory_bytes: 3088
import numpy as np
(n,d)=(int(x)for x in input().split())

X = []
tmp = []
for i in range (n):    
    tmp = list ( int(x) for x in input().split() )
    X.append ( tmp )

flag = 0

for i in range (n):
    for j in range (n):  
        if (j<=i) :
            continue
        
        a = X[i][0:d]  
        b = X[j][0:d]

        tmp = 0
        for k in range (d):
            tmp = tmp + ( a [k] - b [k] ) ** 2
            
        r = np.sqrt (tmp)

        if r%1 == 0.0 :
            flag = flag + 1
            
        a.clear()
        b.clear()

print (flag)        
        


Measured memory_bytes: 12448
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=1000+5;

int main(){
    GO();

    int T;
    T=1;
   // cin>>T;
    while(T--){

        int x;
        cin>>x;
        if(x>=30) cout<<"Yes\n";
        else
            cout<<"No\n";


    }
}


















































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

int main()
{
    int arr[3005];
    int n;
    cin>>n;
    int sum=0;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    cout<<sum-n;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-5;
const ll MOD=1e9+7;
int main(){
    string s;cin>>s;
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0';
    if(a*10+a>=b*10+c){
        cout<<a*100+a*10+a<<endl;
    }else{
        cout<<(a+1)*100+(a+1)*10+a+1<<endl;
    }
}   


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    s = C
    for j in range(M):
        s += A[j] * B[j]
    
    if s > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
import collections
import string

s = input()
s_count = collections.Counter(s)
s_list = list(s_count.keys())
ans = []

for alphabet in list(string.ascii_lowercase):
  if not alphabet in s_list:
    ans.append(alphabet)
if ans != []:
  print(ans[0])
else:
  print("None")

Measured memory_bytes: 9972
#include "bits/stdc++.h"
using namespace std;

// コンテスト中のみ
#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	cout << (10000 - n) % 1000 << endl;
	return 0;
}

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

int main() {
  int K;
  cin >> K;
  int64_t ans = 0;
  for (int i = 1; i < K + 1; i++){
    for (int j = 1; j < K + 1; j++){
      for (int k = 1; k < K + 1; k++){
        ans += gcd<int, int>(gcd<int, int>(i, j), k);
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;

static string ln = "\n";
static string sp = " ";

bool isPrimeNumber(int n) {
  if (n == 2) return true;
  if (n < 2 || n % 2 == 0) return false;

  int i = 3;
  while (i <= sqrt(n))
    if (n % i == 0) return false;
    else i += 2;
  return true;
}

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

  int x;
  cin >> x;

  while (true) {
    if (isPrimeNumber(x)) {
      cout << x << ln;
      return 0;
    }
    x++;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t,k;
	while(cin>>t>>k)
	{
		double d[t];
		cin>>d[0];
		d[0]=(1+d[0])/2;
		//cout<<d[0]<<"\n";
		double ans=d[0];
		for(int i=1;i<t;i++)
		{
			cin>>d[i];
			d[i]=(1+d[i])/2;
			d[i]+=d[i-1];
			//cout<<d[i]<<" ";
			if(i+1-k==0) 
			{
				ans=max(ans,d[i]);
			}
			else if(i+1-k>0) ans=max(ans,d[i]-d[i-k]);
		}
		//for(int i=0;i<t;i++) cout<<d[i]<<" ";
		//cout<<"\n";
		printf("%.10lf\n",ans);
	}
	
}

Measured memory_bytes: 1792
/* 
 * Project: AtCoder Beginners Contest 113 B - Palace
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/09
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int n;
int t;
int a;
int h[1000];

void solve() {
    
    vector<int> diff;
    for (int i=0;i<n;i++) {
        diff.push_back(abs(t*1000 - h[i] * 6 - a*1000));
    }

    int min_idx = min_element(diff.begin(), diff.end()) - diff.begin();

    printf("%d\n", min_idx+1);

}

int main() {

    scanf("%d", &n);
    scanf("%d", &t);
    scanf("%d", &a);
    for (int i=0;i<n;i++) {
        scanf("%d", &h[i]);
    }

    solve();

}

Measured memory_bytes: 888
def main():
    x,y = map(int, input().split())
    a="No"
    if y%2 == 1:
        a="No"
    #elif x == 1:
     #   if y==4 or y==2:
           # a="Yes"
    else:
        for i in range(1,x+1):
            j = x-i
            if 2*i+4*j==y or 4*i+2*j==y:
                a="Yes"
    print(a)
main()

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
int adj[1001][1001];
int x[1001];
bool dp[1001][1001];
typedef pair<int, int> pii;
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        x[i] = 1;
        for(int j=1;j<=n-1;j++){
            scanf("%d", &adj[i][j]);
        }
        dp[i][adj[i][1]] = 1;
    } 
    stack<pii> p;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(dp[i][j] && dp[j][i]){
                p.push(pii(i, j));
            }
        }
    }
    int ans = 0, cnt = 0;
    while(1){
        if(p.empty()) break;
        ans++;

        vector<pii> add;
        while(!p.empty()){
            int a = p.top().first, b = p.top().second;
            p.pop();

            x[a]++;
            x[b]++;

            if(x[a] != n){
                int c = adj[a][x[a]];
                dp[a][c] = 1;
                if(dp[a][c] && dp[c][a]){
                    add.push_back(pii(a, c));
                }
            }
            else cnt++;

            if(x[b] != n){
                int c = adj[b][x[b]];
                dp[b][c] = 1;
                if(dp[b][c] && dp[c][b]){
                    add.push_back(pii(b, c));
                }
            }
            else cnt++;
        }
        for(int i=0;i<add.size();i++){
            p.push(add[i]);
        }
    }
    if(cnt != n) ans = -1;
    printf("%d\n", ans);
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

int slen, tlen;
string s, t;

vector <ll> ada[26];

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

    cin >> s >> t;
    slen = s.length();
    tlen = t.length();

    s = "*" + s;
    t = "*" + t;

    for (int i=1;i<=slen;i++){
        int dig = (s[i] - 'a');
        ada[dig].pb((ll)i);
        // cout << dig << el;
    }

    ll ans = 0;
    ll cur = 0;
    bool bisa = 1;
    for (int i=1;i<=tlen;i++){
        int dig = (t[i] - 'a');
        // cout << dig << " " << i << el;
        if (ada[dig].empty()){
            bisa = 0;
            break;
        }
        if (ada[dig][ada[dig].size() - 1] > cur){
            auto pos = upper_bound(ada[dig].begin(), ada[dig].end(), cur);
            ans += *pos - cur;
            cur = *pos;
        } else{
            ans += slen - cur + ada[dig][0];
            cur = ada[dig][0];
        }
    }

    if (!bisa){
        cout << -1 << el;
        return 0;
    } 
    cout << ans << el;

    return 0;
}

Measured memory_bytes: 1768
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input_int()
    MOD = 10**9 + 7
    dp = [0] * 2010
    dp[0] = 1
    dp[1] = 0
    dp[2] = 0
    for i in range(3, S + 1):
        dp[i] = (dp[i - 3] + dp[i - 1]) % MOD
    print(dp[S])
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 63388
n,k = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
ans = 1
div = []
for i in range(1,int(S**0.5)+2):
    if S%i == 0:
        if S//i != i:
            div.append(S//i)
            div.append(i)
        else:
            div.append(i)
div.sort()
L = []
for i in range(len(div)):
    cur = div[i]
    mod = []
    for j in range(n):
        if A[j]%cur != 0:
            mod.append(A[j]%cur)
    if len(mod) == 0:
        ans = max(ans, cur)
    else:
        mod.sort()
        mod_dash = []
        for j in range(len(mod)):
            mod_dash.append(cur-mod[j])
        mod2 = [mod[0]]
        mod3 = [mod_dash[0]]
        for j in range(1,len(mod)):
            t = mod2[j-1]+mod[j]
            mod2.append(t)
            u = mod3[j-1]+mod_dash[j]
            mod3.append(u)
        c = 10**10
        for j in range(1,len(mod2)):
            c = min(c, max(mod2[len(mod2)-j-1],mod3[len(mod3)-1]-mod3[len(mod3)-j-1]))
        if c <= k:
            ans = max(ans, cur)
print(ans)


Measured memory_bytes: 3188
import itertools

nmq = list(map(int, input().split()))
n = nmq[0]
m = nmq[1]
q = nmq[2]
i = [list(map(int, input().split())) for i in range(q)]
a = list(range(1, m + 1))
a_all = list(itertools.combinations_with_replacement(a, n))
ans = 0
for x in a_all:
  val = 0
  for y in i:
    if x[y[1] - 1] - x[y[0] - 1] == y[2]:
      val = val + y[3]
  if val > ans:
    ans = val
print(ans)

Measured memory_bytes: 84272
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

vector<int> demical(ll n, int k, int l = -1) {
	vector<int> rtn;
	if (l < 0) {
		while (n > 0) {
			rtn.push_back(n % k);
			n /= k;
		}
		
	} else {
		rtn.resize(l);
		REP(i, l) {
			rtn[i] = n % k;
			n /= k;
		}
	}
	return rtn;
}

int main() {
	IOS;
	ll n, k;
	cin >> n >> k;
	auto d = demical(n, k);
	put(d.size());
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(Math.min(a, b) + " " + Math.max(0, a + b - n));
	}
}


Measured memory_bytes: 21844
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef vector<pii>vip;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        ll n; cin >> n;
        ll ans = 0;
        for (int i = 1; i <= n; i++) {
            ll k = n/i;
            ans += k * (k+1) / 2 * i;
        }
        cout<<ans<<endl;

return 0;
}




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

using namespace std;

int main() {

    int n;
    cin >> n;

    vector<long long> v(n);

    for (auto &x: v)
        cin >> x;

    long long val = 1000;
    long long cur = 0;
    
    for (int i = 0; i < n - 1; i++) {
        if (v[i] < v[i + 1]) {
            cur = val / v[i];
            val %= v[i];
            val += cur * v[i + 1];
        }
    }

    cout << val << "\n";

    return 0;
}


Measured memory_bytes: 3632
// C

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  int N = s.size();
  ll dp[100001][13] = {0};
  if (s[0] == '?'){
    for (int i(0);i<=9;i++){
      dp[1][i] = 1;
    }
  }else{
    dp[1][s[0]-'0'] = 1;
  }
  for (int i(2);i<=N;i++){
    if (s[i-1] == '?'){
      for (int j(0);j<13;j++){
        for (int k(0);k<10;k++){
          int next_amari = (j*10 + k)%13;
          dp[i][next_amari] += dp[i-1][j];
          dp[i][next_amari] %= mod;
        }
      }
    }else{
      for (int j(0);j<13;j++){
        int next_amari = (j*10 + (s[i-1]-'0'))%13;
        dp[i][next_amari] += dp[i-1][j];
        dp[i][next_amari] %= mod;
      }
    }
  }
  cout << dp[N][5] << endl;
  return 0;
}


Measured memory_bytes: 10624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;
vector<int> G[100000];
int leaf[100000];
bool vis[100000];
int idx = 1;
void dfs(int v, bool head, vector<int> &L) {
	vis[v] = 1;
	if (head) {
		L.push_back(idx);
		for (int i = 2; i <= leaf[v]; i++) L.push_back(idx + i);
		L.push_back(idx + 1);
		idx += leaf[v] + 1;
		for (int to : G[v]) {
			if (G[to].size() > 1) dfs(to, 0, L);
		}
		return;
	}
	int k = G[v].size() - leaf[v];
	if (k == 1) {
		for (int i = 1; i < leaf[v]; i++) L.push_back(idx + i);
		L.push_back(idx);
		L.push_back(idx + leaf[v]);
		idx += leaf[v] + 1;
		return;
	}
	for (int i = 1; i <= leaf[v]; i++) L.push_back(idx + i);
	L.push_back(idx);
	idx += leaf[v] + 1;
	for (int to : G[v]) {
		if (G[to].size() > 1 && !vis[to]) dfs(to, 0, L);
	}
}
int main() {
	int n;
	cin >> n;
	if (n == 2) {
		cout << "1 2" << endl;
		return 0;
	}
	for (int i = 0; i + 1 < n; i++) {
		int u, v;
		cin >> u >> v; u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	vector<int> term;
	for (int i = 0; i < n; i++) {
		if (G[i].size() == 1) continue;
		for (int to : G[i]) {
			if (G[to].size() == 1) leaf[i]++;
		}
		int k = G[i].size() - leaf[i];
		if (k == 1) term.push_back(i);
		else if (k >= 3) {
			cout << -1 << endl;
			return 0;
		}
	}
	if (term.empty()) { //うに
		cout << 1;
		for (int i = 3; i < n; i++) cout << " " << i;
		cout << " 2 " << n << endl;
		return 0;
	}
	vector<int> L1, L2;
	idx = 1;
	memset(vis, 0, sizeof(vis));
	dfs(term[0], 1, L1);
	idx = 1;
	memset(vis, 0, sizeof(vis));
	dfs(term[1], 1, L2);
	vector<int> L = min(L1, L2);
	for (int i = 0; i < L.size(); i++) {
		cout << L[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 13944
using System;
using System.Linq;

class Problem {
    class Dice {
        public int Top    { get; private set; }
        public int South  { get; private set; }
        public int East   { get; private set; }
        public int West   { get; private set; }
        public int North  { get; private set; }
        public int Bottom { get; private set; }
        public Dice(int[] nums) {
            Top    = nums[0];
            South  = nums[1];
            East   = nums[2];
            West   = nums[3];
            North  = nums[4];
            Bottom = nums[5];
        }
        public void Roll(string coms) {
            foreach (var com in coms) {
                var tmp = Top;
                switch (com) {
                    case 'E': Top = West;  West  = Bottom; Bottom = East;  East  = tmp; break;
                    case 'N': Top = South; South = Bottom; Bottom = North; North = tmp; break;
                    case 'S': Top = North; North = Bottom; Bottom = South; South = tmp; break;
                    case 'W': Top = East;  East  = Bottom; Bottom = West;  West  = tmp; break;
                }
            }
        }
        public void RollY(string coms) {
            foreach (var com in coms) {
                var tmp = South;
                switch (com) {
                    case 'R': South = West; West = North; North = East; East = tmp; break;
                    case 'L': South = East; East = North; North = West; West = tmp; break;
                }
            }
        }
        public char Position(int num) {
            return num == Top   ? 'T' :
                   num == South ? 'S' :
                   num == East  ? 'E' :
                   num == West  ? 'W' :
                   num == North ? 'N' : 'B';
        }
    }
    
    public static void Main() {
        var d = new Dice(Console.ReadLine().Split().Select(int.Parse).ToArray());
        var n = int.Parse(Console.ReadLine());
        for (var i = 0; i < n; i++) {
            var dat = Console.ReadLine().Split().Select(int.Parse).ToArray();
            switch (d.Position(dat[0])) {
                case 'T': break;
                case 'S': d.Roll("N"); break;
                case 'E': d.Roll("W"); break;
                case 'W': d.Roll("E"); break;
                case 'N': d.Roll("S"); break;
                case 'B': d.Roll("NN"); break;
            }
            switch (d.Position(dat[1])) {
                case 'S': break;
                case 'E': d.RollY("L"); break;
                case 'W': d.RollY("R"); break;
                case 'N': d.RollY("RR"); break;
            }
            Console.WriteLine(d.East);
        }
    }
}


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

using namespace std;

struct WeightUniTree {
    int *par, *rank, *diff_weight;

    WeightUniTree(int n) {
        par = new int[n];
        rank = new int[n];
        diff_weight = new int[n];
        for(int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            diff_weight[i] = 0;
        }
    }

    int root(int x) {
        if(par[x] == x) return x;
        int r = root(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = r;
    }

    int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }

    void merge(int x, int y, int w) {
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
            diff_weight[x] = -w;
        }else {
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            diff_weight[y] = w;
        }
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    WeightUniTree tree(n);

    bool flag = true;
    for(int i = 0; i < m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        if(tree.same(l - 1, r - 1) && tree.diff(l - 1, r - 1) != d) {
            flag = false;
            break;
        }
        tree.merge(l - 1, r - 1, d);
    }
    cout << (flag? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
typedef unsigned long long Int;
int main() {
    Int n, x;
    cin >> n >> x;
    if(x % 1000 != 0){
        cout << "-1 -1 -1";
        return 0;
    }
    x/=1000;
    
    for(Int i = 0; i <= n; i++){
        for(Int j = 0; j+i <= n; j++){
            Int k = n-i-j;
                if(10*i+5*j+k==x){
                    cout << i << " " << j << " " << k;
                    return 0;
                }
            
        }
    }
    cout << "-1 -1 -1";
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<bitset>
using namespace std;
int n,k,a[5010];
bitset<5010> sum;
bool judge(int x)
{
    if(a[x]>=k)
	{
		return 1;
    }
	sum.reset(); 
	sum[0]=1;
    for(int i=1;i<=n;++i) 
	{
		if(i!=x)
		{
			sum|=sum<<a[i];
		}
	}
	for(int i=k-1;i>=k-a[x];--i)
	{
        if(sum[i]) 
		{
			return 1;
		}
	}
	return 0;
}

void solve()
{
    int l=0,r=n+1;
    while(l<r)
	{
        int mid=(l+r)>>1;
        if(judge(mid))
		{
			r=mid;
        }
		else 
		{
			l=mid+1;
		}
	}
    printf("%d",l-1);
}
void read(int &x)
{
	x=0;
	int f=1;
	char s=getchar();
	while(s<'0'||s>'9')
	{
		if(s=='-')
		{
			f=-1;
		}
		s=getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=(x<<3)+(x<<1)+s-'0';
		s=getchar();
	}
	x*=f;
}
int main()
{
    read(n);read(k);
    for(int i=1;i<=n;++i)
	{
		read(a[i]);
    }
	sort(a+1, a+n+1);
    solve();
    return 0;
}

Measured memory_bytes: 256
import sys
n,k,q=map(int,input().split())
if k-q>0:
  for i in range(n):
    print('Yes')
  sys.exit()
a=[0]*n
for i in range(q):
  b=int(input())
  a[b-1]+=1
for j in range(n):
  if k-q+a[j]>0:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 50904
import math
n=int(input())
count=0
for a in range(n):
    for b in range(n):
        for c in range(n):
            gcd_f=math.gcd(a+1,b+1)
            gcd_s=math.gcd(gcd_f,c+1)
            count+=gcd_s
print(count)

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

int main()
{
    int n;
    cin >> n;
    long long mn = 10000000, mx = -10000000, sm = 0;
    for(int i = 0; i < n; ++i) {
        long long a;
        cin >> a;
        sm += a;
        mn = min(mn, a);
        mx = max(mx, a);
    }
    cout << mn << " " << mx << " " << sm << endl;
    return 0;
}


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

typedef long long int ll;
typedef long double ld;

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define rep1(i, n)    for(ll i = 1; i <= (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define bpc(a) __builtin_popcount(a)
#define ff first 
#define ss second  
#define mk0(a) memset(a,0,sizeof(a))
#define mk_1(a) memset(a,-1,sizeof(a))

const ll MAX=1e5+2;
const ll MAX1=1e2+5;
const ll INF=1e15+2;
const ll MOD=1e9+7;

#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi pair<ll,ll>
#define map1 unordered_map

inline ll nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}

inline ll read(){ll ret=0;bool f=0;char ch=nc();while(ch>'9'|| ch<'0') f^=ch=='-',ch=nc();
while(ch<='9'&& ch>='0') ret=ret*10+ch-'0',ch=nc();return f?-ret:ret;}

ll power(ll base,ll ind,ll mod){ll res=1;while(ind){if(ind&1)res=(res*base)%mod;base=(base*base)%mod;ind>>=1;}return res;}

ll inv(ll den,ll mod){return power(den,mod-2,mod);}

vector<ll>g[MAX];
ll dp[MAX][2];//0 = black 1 = white
ll n;

void calc(ll rt,ll p)
{
    dp[rt][1]=dp[rt][0]=1;
    trav(child,g[rt])
    {
        if(child!=p)
        {
            calc(child,rt);
            dp[rt][0]*=dp[child][1];
            dp[rt][0]%=MOD;
            dp[rt][1]*=(dp[child][0]+dp[child][1]);
            dp[rt][1]%=MOD;
        }
    }
    if(sz(g[rt])==1 and p)
        dp[rt][0]=1,dp[rt][1]=1;
}

int main()
{
    faster;
    cin>>n;
    
    rep(i,n-1)
    {
        ll u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    calc(1,0);
    if(n==1)
        cout<<2;
    else    
        cout<<(dp[1][0]+dp[1][1])%MOD<<endl;
}


Measured memory_bytes: 12800
import java.util.Scanner;
public class Main {
private static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
	int n = s.nextInt();
	int[] p = new int[n+1];
	int[][] m = new int[n+1][n+1];

	for(int i = 1;i <= n;i++) {
		p[i-1] = s.nextInt();
		p[i] = s.nextInt();
		m[i][i] = 0;
	}

	for(int k = 2;k <= n;k++) {
		for(int i = 1;i <= n-k+1;i++) {
			int j = k + i - 1;
			m[i][j] = Integer.MAX_VALUE;;
			for(int l = i;l <= j-1;l++) {
			if(m[i][l] + m[l+1][j] + p[i-1] * p[l] * p[j] < m[i][j])
				m[i][j] = m[i][l] + m[l+1][j] + p[i-1] * p[l] * p[j];
			}
		}
	}
	System.out.println(m[1][n]);
}
}




Measured memory_bytes: 26488