akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	static String str;
	static List<Character> stack = new ArrayList<Character>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			str = sc.nextLine();
			if(str.equals("."))break;
			boolean flg = true;
			stack = new ArrayList<Character>();
			for(int i=0;i<str.length();i++){
				char c = str.charAt(i);
				if(c == '(' || c == '['){
					stack.add(c);
				}else if(c == ')'){
					if(stack.size()==0){
						flg = false;
					}
					else if(stack.get(stack.size()-1)=='('){
						stack.remove(stack.size()-1);
					}else{
						flg = false;
					}
				}else if(c == ']'){
					if(stack.size()==0){
						flg = false;
					}else if(stack.get(stack.size()-1)=='['){
						stack.remove(stack.size()-1);
					}else{
						flg = false;
					}						
				}
			}
			if(flg&&stack.size()==0){
				System.out.println("yes");
			}else{
				System.out.println("no");
			}
		}
	}
}

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

int n;
vector<string>d;

void dfs(string s,int cnt){
    if(cnt==n)d.push_back(s);
    else{
        cnt++;
        dfs(s+'0',cnt);
        dfs(s+'1',cnt);
        dfs(s+'2',cnt);
        dfs(s+'3',cnt);
    }
}

int main(){
    cin>>n;
    int a,b,c;cin>>a>>b>>c;
    vector<int>l(n);
    for(int i=0;i<n;++i)cin>>l[i];
    dfs("",0);
    sort(d.begin(),d.end());
    int ans=1e9;
    for(int i=0;i<d.size();++i){
        int la=0,lb=0,lc=0,lans=0,ca=0,cb=0,cc=0;
        for(int j=0;j<n;++j){
            if(d[i][j]=='0'){la+=l[j];ca++;}
            else if(d[i][j]=='1'){lb+=l[j];cb++;}
            else if(d[i][j]=='2'){lc+=l[j];cc++;}
        }
        if(ca==0||cb==0||cc==0)continue;
        lans+=10*(ca-1);
        lans+=10*(cb-1);
        lans+=10*(cc-1);
        lans+=abs(a-la)+abs(b-lb)+abs(c-lc);
        if(ans>lans){ans=lans;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3832
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    
    def hhmmss_to_s(t):
        hh = int(t[0:2])
        mm = int(t[3:5])
        ss = int(t[6:8])
        return hh*3600+mm*60+ss

    while True:
        n = I()
        if n==0:
            break
        else:
            cnt = [0]*(24*3600+1)
            for _ in range(n):
                leave, arrive = map(hhmmss_to_s, input().split())
                cnt[leave] += 1
                cnt[arrive] -= 1
            for i in range(24*3600):
                cnt[i+1] += cnt[i]

            print(max(cnt))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9972
#include <iostream>

using namespace std;

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

int main(){
	int n;
	cin >> n;
	int x[n], y[n], h[n], k;
	rep(i,n) cin >> x[i] >> y[i] >> h[i];
	rep(i,n) if(h[i] != 0) k = i;
	rep(cx,101) rep(cy,101) {
		int ch = h[k] + abs(x[k] - cx) + abs(y[k] - cy);
		bool flag = 1;
		rep(i,n) if(h[i] != max(ch - abs(x[i] - cx) - abs(y[i] - cy), 0)) flag = 0;
		if(flag) cout << cx << " " << cy << " " << ch << endl;
	}
	return 0;
}


Measured memory_bytes: 256
K = int(input())
S = list(input())
len_S = int(len(S))
S1 = ' '

if len_S <= K:
  for x in S:
    S1 += x
  print(S1)
else:
  del S[K:]
  for x in S:
    S1 += x
  print(S1 + '...')

Measured memory_bytes: 9176
package main

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

type card struct {
	suit   string
	number int
}

type trump struct {
	cards []card
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())

	c := make([]card, num)
	t := trump{cards: c}
	org := []card{}
	i := 0
	for sc.Scan() {
		input := strings.Split(sc.Text(), " ")
		t.cards[i].suit = input[0]
		t.cards[i].number, _ = strconv.Atoi(input[1])
		n, _ := strconv.Atoi(input[1])
		org = append(org, card{suit: input[0], number: n})
		i++
	}

	t.quickSort(0, len(t.cards)-1)

	if judgeStable(org, t.cards) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
	for _, v := range t.cards {
		fmt.Println(strings.Trim(fmt.Sprint(v), "{}"))
	}
}

func (t *trump) quickSort(p int, r int) {
	if p < r {
		q := t.partiton(p, r)
		t.quickSort(p, q-1)
		t.quickSort(q+1, r)
	}
}

func (t *trump) partiton(p int, r int) int {
	criterion := t.cards[r].number
	i := p - 1
	for j := p; j < r; j++ {
		if t.cards[j].number <= criterion {
			i++
			tmp := t.cards[i]
			t.cards[i] = t.cards[j]
			t.cards[j] = tmp
		}
	}
	tmp := t.cards[r]
	t.cards[r] = t.cards[i+1]
	t.cards[i+1] = tmp

	return i + 1
}

func judgeStable(org []card, sorted []card) bool {
	sortedSuits := map[int]string{}
	for _, v := range sorted {
		if _, ok := sortedSuits[v.number]; ok {
			sortedSuits[v.number] = sortedSuits[v.number] + v.suit
		} else {
			sortedSuits[v.number] = v.suit
		}
	}

	orgSuits := map[int]string{}
	for _, v := range org {
		if _, ok := orgSuits[v.number]; ok {
			orgSuits[v.number] = orgSuits[v.number] + v.suit
		} else {
			orgSuits[v.number] = v.suit
		}
	}

	return reflect.DeepEqual(sortedSuits, orgSuits)
}



Measured memory_bytes: 17952
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  const input = lines[0].split(" ");
  const a = Number(input[0]);
  const b = Number(input[1]);
  const least_a = a / 0.08;
  const least_b = b / 0.1;
  const most_a = least_a + 12.5;
  const most_b = least_b + 10;
  var res;
  if (least_a >= most_b || least_b >= most_a)
    return console.log(-1);
  else {
    res = least_a < least_b ? Math.ceil(least_b) : Math.ceil(least_a);
    if (res >= most_a || res >= most_b) return console.log(-1);
    else console.log(res);
  }
});


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

typedef long long ll;
typedef long double ld;

#define deb(x) cerr << #x << ":" << x << "\n"

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    for (int tc = 1; tc <= t; tc++)
    {
        ll i,j;
        cin>>i>>j;
        if(j>=i)cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 256
N_all=int(input())
A=list(map(int,input().split()))
f_inf=-float("inf")
odds_or_even=N_all%2+2
dp=[[f_inf for x in range(N_all+1)] for x in range(odds_or_even)]
dp[0][0]=0

for i in range(N_all):
  dp[0][i+1]=dp[0][i]+A[i]*((i+1)%2)
for j in range(1,odds_or_even):
  for i in range(N_all):
    dp[j][i+1]=max(dp[j][i]+A[i]*((i+j+1)%2),dp[j-1][i])
        
print(dp[odds_or_even-1][N_all])

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void ckmin(T& a, const T& b) { a = min(a, b); }

pair<int, int> solve(int T, const vector<pair<int, int>>& avail) {
    vi dp(T + 1, INT_MAX), upd(T + 1);
    dp[0] = 0;

    for (auto p : avail) {
        fill(all(upd), INT_MAX);
        for (int t = 0; t + p.first <= T; t++) if (dp[t] != INT_MAX) {
            ckmin(upd[t + p.first], dp[t] + p.second);
        }
        for (int t = 0; t + p.second <= T; t++) if (dp[t] != INT_MAX) {
            ckmin(upd[t + p.second], dp[t] + p.first);
        }
        swap(dp, upd);
    }

    int res = INT_MAX;
    for (int t = 0; t <= T; t++)
        res = min(res, dp[t]);
    return make_pair(res == INT_MAX ? -1 : T, res);
}

pair<int, int> go(vvi& adj, vi& tot, int loc) {
    vector<pair<int, int>> ch;
    for (int c : adj[loc]) {
        auto res = go(adj, tot, c);
        if (res.first == -1) return { -1, INT_MAX };
        ch.emplace_back(res);
    }
    return solve(tot[loc], ch);
}

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

    int N;
    cin >> N;

    vvi ch(N);
    for (int i = 1, p; i < N; i++) {
        cin >> p;
        ch[p-1].push_back(i);
    }

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

    if (go(ch, tot, 0).first == -1) cout << "IM";
    cout << "POSSIBLE\n";

    return 0;
}



Measured memory_bytes: 384
input() = map(parse,split(readline()))
(N,M,C) = input()
B = input()
A = Array{Int}(N,M)
for n=1:N
	A[n,:] = input()
end
ans = 0
D = A*B+C
for d in D
  if d > 0
  	ans+=1
  end
end
println(ans)

Measured memory_bytes: 116496
N, P = map(int, input().split())
S = list(map(int,list(input())))
mod = P
Cum = []
S.reverse()

if 10%P!=0: 
    temp = 0
    power = 1
    for i in range(N):
        temp += (S[i]*power)%mod
        temp %= mod
        power *= 10
        power %= mod
        Cum.append(temp)

    from collections import Counter

    counter=Counter(Cum)

    counter[0]+=1

    ans = 0
    for i in counter:
        ans += int(counter[i]*(counter[i]-1)/2)
    print(ans)    

else:
    ans = 0
    S.reverse()
    for i in range(N):
        if S[i]%P==0:
            ans += (i+1)          
    print(ans)


Measured memory_bytes: 13632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int[] pa;

        int find(int x) {
            return x == pa[x] ? pa[x] : (pa[x] = find(pa[x]));
        }

        boolean union(int a, int b) {
            int ra = find(a), rb = find(b);
            if (ra != rb) {
                pa[ra] = rb;
                return true;
            }
            return false;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str = in.next();
            int len = str.length();
            int[] diff = new int[len + 1];
            diff[0] = str.charAt(0) - 'a';
            for (int i = 1; i < len; ++i) {
                diff[i] = (str.charAt(i) - str.charAt(i - 1) + 26) % 26;
            }
            diff[len] = ('a' - str.charAt(len - 1)) % 26;

            pa = new int[len + 1];
            for (int i = 0; i <= len; ++i) pa[i] = i;

            int n = in.nextInt();
            int l, r;
            for (int i = 0; i < n; ++i) {
                l = in.nextInt();
                r = in.nextInt();
                --l;
                union(l, r);
            }
            for (int i = 0, j = len; i < j; ++i, --j) {
                union(i, j);
            }

            Map<Integer, Integer> mp = new HashMap<>();
            for (int i = 0; i <= len; ++i) {
                int rt = find(i);
                if (!mp.containsKey(rt)) {
                    mp.put(rt, diff[i]);
                } else {
                    mp.put(rt, (mp.get(rt) + diff[i]) % 26);
                }
            }

            for (Integer key : mp.keySet()) {
                if (mp.get(key) != 0) {
                    out.println("NO");
                    return;
                }
            }

            out.println("YES");
        }

    }
}



Measured memory_bytes: 79412
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
int INF=pow(10,9);

int main(){
    int N,M;cin>>N>>M;
    mat dp(1010,vec((1<<12),INF));
    dp[0][0]=0;
    for(int i=1;i<=M;i++){
        int a,b;cin>>a>>b;
        int d=0;
        for(int j=1;j<=b;j++){
            int c;cin>>c;
            c--;
            d+=(1<<c);
        }
        for(int k=0;k<(1<<N);k++){
            dp[i][k]=dp[i-1][k];
        }
        for(int l=0;l<(1<<N);l++){
            dp[i][l | d]=min(dp[i][l | d],dp[i-1][l]+a);
        }
    }
    if(dp[M][(1<<N)-1]!=INF)cout<<dp[M][(1<<N)-1]<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
int l,sum=0;
const int maxn=1e5+10;
char t[maxn];
int main()
{
	while(scanf("%s",t)!=EOF)
	{
	   l=strlen(t);
	   for(int i=1;i<l-1;i++)
		  if(t[i-1]!=t[i+1]) sum++;
	   if(sum==0)
	   {
		printf("Second\n");
		continue;
	    }
	   if(t[0]!=t[l-1])
	   {
		  printf("%s\n",l%2?"First":"Second");
       }
       else
	   {
		  printf("%s\n",l%2?"Second":"First");
	   }
	}
	
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int w,a,b;
	scanf("%d%d%d",&w,&a,&b);
	if(a + w < b)	printf("%d\n", b - (a + w));
	else if(b + w < a)	printf("%d\n", a - (b + w));
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int x;
    cin >> x;
    int ans = 0;
    if (400 <= x && x <= 599) {
        ans = 8;
    } else if (600 <= x && x <= 799) {
        ans = 7;
    } else if (800 <= x && x <= 999) {
        ans = 6;
    } else if (1000 <= x && x <= 1199) {
        ans = 5;
    } else if (1200 <= x && x <= 1399) {
        ans = 4;
    } else if (1400 <= x && x <= 1599) {
        ans = 3;
    } else if (1600 <= x && x <= 1799) {
        ans = 2;
    } else if (1800 <= x && x <= 1999) {
        ans = 1;
    }
    cout << ans << endl;
}


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

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  unsigned v;
  modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; }
  m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; }
  m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; }
  m& operator/=(m r) { return *this *= power(r, M - 2); }
  friend m operator+(m l, m r) { return l += r; }
  friend m operator-(m l, m r) { return l -= r; }
  friend m operator*(m l, m r) { return l *= r; }
  friend m operator/(m l, m r) { return l /= r; }
  friend bool operator==(m l, m r) { return l.v == r.v; }
  friend string to_string(m a) { return to_string(a.v); }
};

constexpr long long mod = 1e9 + 7;
using mint = modular<mod>;

mint binom(int n, int k) {
  if (k < 0 or k > n) return 0;
  if (k == 0) {
    return 1;
  }
  return binom(n - 1, k - 1) * n / k;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  mint res = power(mint(2), n) - 1 - binom(n, a) - binom(n, b);
  cout << res.v << '\n';
}


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

int main(){
    string s;
    cin >> s;
    //string型で定義したxの文字列の長さはx.size()で参照できる
    int length = s.length();
    cout << s[0] << length - 2 << s[length - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		int tp = a <= b ? a : b;
		int bp = c <= d ? c : d;

		System.out.println(tp + bp);
	}
}

Measured memory_bytes: 35696
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.size();
  int a, z;
  for(int i = 0;i < n;i++){
    if(s[i] == 'A'){
      a = i;
      break;
    }
  }
  for(int i = n - 1;i >= 0;i--){
    if(s[i] == 'Z'){
      z = i;
      break;
    }
  }
  cout << (z - a + 1) << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main(): 
	nums = []
	while True:
		x = input().split(" ")
		if x == ["0","0"]:
			break
		x.sort(key = int)
		nums.append(x)
	for i in nums:
			print(" ".join(i))
if __name__ == '__main__':
  main()

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

int main() {
	long K,T;
	cin >> K >> T;
	
	long a,max=0;
	
for(long i=0; i<T; i++){
	cin >> a;
	if(a>max){max=a;}
}

long kazu=2*max - K -1;
if(kazu>0){cout << kazu << endl;}
else{cout << 0 << endl;}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(unsigned long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
const int MAX = 510000;
ll gcd(ll a,ll b){
  if(a%b==0) return b;
  else gcd(b, a%b);
}

P f(int x){
  int last=x%10;
  int first=0;
  while(x){
    first=x;
    x/=10;
  }
  return P(first,last);
}

int main() {
  int n;
  cin >> n;
  map<P,int> freq;
  for(int i=1;i<=n;i++){
    P p=f(i);
    freq[p]++;
  }
  ll ans = 0;
  for(int i=1;i<=n;i++){
    P p=f(i);
    P q(p.second,p.first);
    ans+=freq[q];
  }
  cout << ans<< endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; ++i) cin >> d[i];
  sort(d.begin(),d.end());
  cout << d[d.size()/2]-d[d.size()/2-1] << endl;
  return 0;
}

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

int main(){
  int a[10];
  for(int i=1;i<=6;i++)cin >> a[i];
  int c[10];
  for(int i=1;i<=6;i++){c[i]=0;}
  for(int i=1;i<=6;i++){c[a[i]]++;}
  string ans="YES";
  for(int i=1;i<=6;i++){
    if(c[i]>=3){ans="NO";}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

using ui = uint32_t;

const int maxn = 50100;
ui _q[4000 * maxn];
ui* q[maxn];
int qmem[maxn];
int m;

void qset(int x, int y, bool val = true) {
  assert((m - y) / 32 < qmem[x]);
  q[x][(m - y) / 32] |= (ui(1) << ((m - y) % 32));
  if (!val) {
    q[x][(m - y) / 32] ^= (ui(1) << ((m - y) % 32));
  }
}

bool qget(int x, int y) {
  assert((m - y) / 32 < qmem[x]);
  return q[x][(m - y) / 32] & (ui(1) << ((m - y) % 32));
}

void qor(int x, int y) {
  assert(x > y);
  for (int i = 0; i < qmem[x]; ++i) {
    q[x][i] |= q[y][i];
  }
}

int qfind_first(int x) {
  for (int i = qmem[x] - 1; i >= 0; --i) {
    if (!q[x][i]) {
      continue;
    }
    for (int j = 31; j >= 0; --j) {
      int c = m - (i * 32 + j);
      if (c <= x) {
        continue;
      }
      if (qget(x, c)) {
        return c;
      }
    }
  }
  return maxn;
}

signed main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif
  string s;
  int qs;
  cin >> s >> qs;
  int n = (int) s.size();
  m = n / 2;
  int OFF = 0;
  for (int i = m; i >= 0; --i) {
    int mem = (m - i + 1 + 31) / 32;
    q[i] = _q + OFF;
    qmem[i] = mem;
    OFF += mem;
  }

  for (int i = 0; i < qs; ++i) {
    int l, r;
    cin >> l >> r;
    --l;
    int nl, nr;
    if (r <= m) {
      nl = l;
      nr = r;
    } else if (l >= n - m) {
      nl = n - r;
      nr = n - l;
    } else {
      nl = l;
      nr = n - r;
      if (nl >= nr) {
        swap(nl, nr);
      }
    }
    if (nl != nr) {
      assert(nr > nl);
      qset(nl, nr);
      //cerr << nl << ' ' << nr << '\n';
    }
  }
  vector<int> val(m);
  for (int i = 0; i < m; ++i) {
    val[i] = (s[i] - s[n - 1 - i] + 26) % 26;
  }
  int add = 0;
  vector<int> delta(m + 1);
  //for (int i = 0; i < m; ++i) {
    //cerr << val[i] << '\n';
  //}
  for (int i = 0; i < m; ++i) {
    //cerr << i << ' ' << val[i] << '\n';
    add = (add - delta[i] + 26) % 26;
    val[i] = (val[i] - add + 26) % 26;
    int to = qfind_first(i);
    if (val[i] != 0 && to == maxn) {
      cout << "NO\n";
      return 0;
    }
    if (val[i] != 0) {
      //cerr << "add " << i << ' ' << to << ' ' << val[i] << '\n';
      delta[to] = (delta[to] + val[i]) % 26;
      add = (val[i] + add) % 26;
    }
    if (to != maxn) {
      qor(to, i);
      //q[to] |= q[i];
    }
  }
  cout << "YES\n";
}


Measured memory_bytes: 154496
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    LL A,B;cin >>A >> B;
    auto calc = [&](LL A,LL B){
    bitset<50> A_bits(A);
    bitset<50> B_bits(B);
    bitset<50> ans(0);
    LL ins = 1;
    for(int a = 0;a<50;a++){
        ins *= 2;
        LL w = (B+1)/ins*ins/2 + ((B+1) >= ins/2 ? max(0LL,(B+1)%ins-ins/2) : 0);
        LL q = A/ins*ins/2 + (A >= ins/2 ? max(0LL,A%ins-ins/2) : 0);
    //    cout<<w<<" "<<q<<endl;
        if((w-q) % 2 == 0)ans[a] = 0;
        else ans[a] = 1;
        ins *= 1;
    }
    return ans.to_ullong();
    };
    cout<<calc(A,B)<<endl;
    for(int a = 1;a < 10;a++){
        for(int b = a+1;b < 11;b++){
            int w = a;
            for(int c = a+1;c <= b;c++){
                w ^= c;
            }
            if(calc(a,b) != w){
           //     cout<<a<<" "<<b<<" "<<w<<" "<<calc(a,b)<<endl;
            }
        }
    }
}



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

const int MOD = 998244353;

class ModInt
{
public:
    int64_t x;
    ModInt(int64_t x = 0) : x((x % MOD + MOD) % MOD) {}
    ModInt operator-() const { return ModInt(-x); }
    ModInt &operator+=(const ModInt a)
    {
        if ((x += a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    ModInt &operator-=(const ModInt a)
    {
        if ((x += MOD - a.x) >= MOD)
            x -= MOD;
        return *this;
    }
    ModInt &operator*=(const ModInt a)
    {
        (x *= a.x) %= MOD;
        return *this;
    }
    ModInt operator+(const ModInt a) const { return ModInt(*this) += a; }
    ModInt operator-(const ModInt a) const { return ModInt(*this) -= a; }
    ModInt operator*(const ModInt a) const { return ModInt(*this) *= a; }
    ModInt pow(int64_t n) const
    {
        if (n == 0)
            return 1;
        ModInt t = pow(n >> 1);
        t *= t;
        if (n & 1)
            t *= *this;
        return t;
    }
    ModInt inv() const { return pow(MOD - 2); }
    ModInt &operator/=(const ModInt a) { return *this *= a.inv(); }
    ModInt operator/(const ModInt a) const { return ModInt(*this) /= a; }
};
istream &operator>>(istream &is, const ModInt &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x; }

void solve(int N, int K, vector<int> L, vector<int> R)
{
    vector<ModInt> add(N), sub(N);
    add.at(0) = 1;
    sub.at(0) = 1;
    ModInt acc = 0;
    vector<ModInt> dp(N);
    for (int i = 0; i < N; i++)
    {
        acc += add.at(i);
        dp.at(i) = acc;
        for (int j = 0; j < K; j++)
        {
            if (i + L.at(j) < N)
            {
                add.at(i + L.at(j)) += dp.at(i);
            }
            if (i + R.at(j) < N)
            {
                sub.at(i + R.at(j)) += dp.at(i);
            }
        }
        acc -= sub.at(i);
    }
    cout << dp.at(N - 1) << endl;
}

int main()
{
    int N;
    cin >> N;
    int K;
    cin >> K;
    vector<int> L(K);
    vector<int> R(K);
    for (int i = 0; i < K; i++)
    {
        cin >> L.at(i);
        cin >> R.at(i);
    }
    solve(N, K, move(L), move(R));
    return 0;
}


Measured memory_bytes: 8008
#include<bits/stdc++.h>
using namespace std;
main(){
  int a[10005],n,aice;
  while(1){
    cin>>n;
    if(n==0)break;
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
      cin>>aice;
      a[aice]++;
    }
    for(int i=0;i<10;i++){
      if(a[i]==0){
	cout<<'-'<<endl;
      }
      else{
	for(int j=0;j<a[i];j++){
	  cout<<'*';
	}
	cout<<endl;
      }
    }
  }
}

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

public class Remainder
{
    static public void Main ()
    {
        var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        long N = NM[0];
        long M = NM[1];
        long ans = 0L;
        
        if(M-2*N >= 0){
            ans = N+(M-2*N)/4;
        }else{
          ans = M/2;
        }
        
        
        
        Console.WriteLine(ans);

    }

}


Measured memory_bytes: 11348
import java.util.Scanner;

public  class Main{
	public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	String n = stdIn.next();
	int ans = 0;
	for(int i=0;i<n.length();i++){
		ans+= n.charAt(i)-'0';
	}
if(ans%9==0){
System.out.println("Yes");
}
else {
System.out.println("No");
}

}
}

Measured memory_bytes: 40340
function Main(input: string) {
  const lines: string[] = input.split('\n');
  const params1 = lines[0].split(' ');
  const params2 = lines[1].split(' ');

  const n = parseInt(params1[0]);
  const x = params2.map(x => parseInt(x));

  const y = sort(x);

  const l = Math.floor(n / 2);
  const y1 = y[l - 1];
  const y2 = y[l];

  x.forEach(a => {
    const b = (a <= y1) ? y2 : y1;
    console.log(b);
  });
}

function sort(a: number[]): number[] {
  let b = [...a];
  b.sort((x, y) => x - y);
  return b
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 42908
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;


void main()
{
    auto N = readln.chomp.to!int;
    auto HS = readln.split.to!(int[]);

    int[] cs = [HS[0]-1, HS[0]];
    foreach (h; HS[1..$]) {
        if (cs.length == 1) {
            auto c = cs[0];
            if (h > c) {
                cs = [h-1, h];
            } else if (c == h) {
                cs = [h];
            } else {
                writeln("No");
                return;
            }
        } else {
            if (h >= cs[1]) {
                cs = [h-1, h];
            } else if (h == cs[0]) {
                cs = [h];
            } else {
                writeln("No");
                return;
            }
        }
    }
    writeln("Yes");
}

Measured memory_bytes: 4496
#include <stdio.h>
#include <string.h>

int main(void){

  char a[11], b[11], c[11];
  scanf("%s %s %s", a, b, c);
  int a_length = strlen(a);
  int b_length = strlen(b);
  if (a[a_length-1] == b[0] && b[b_length-1] == c[0]) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}

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

int main(){
  int s,i=1;
  cin >> s;
  if(s==1 || s==2 || s==4){
    cout << 4 << endl; return 0;
  }
  while(s!=4){
    if(s%2==0){
      s/=2;
    }else{
      s=s*3+1;
    }
    i++;
  }
  cout << i+3 << endl;
}

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

int counter(int x){
    if(x==0) return 0;
    return counter(x>>1) +(x&1);
}

int main(){
    int n;cin>>n;
    int a[n];
    int x[n][n],y[n][n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }

    int ans=0;
    for(int bits=1;bits<(1<<n);bits++){
        bool ok=true;
        for(int i=0;i<n;i++){
            if(!((bits>>i)&1)) continue;
            for(int j=0;j<a[i];j++){
                if(((bits>>(x[i][j]-1))&1) ^ y[i][j]) ok=false;
            }
        }
        if(ok) ans=max(ans,counter(bits));
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,n,i,j,k;
bool b[40001]={1};
main(){
  for(cin>>n;i++<n;){
    cin>>a;
    for(k=40001;k+1;--k)b[k]?b[k+a]=1:0;
  }
  for(cin>>n;j++<n;cout<<(b[i]?"yes\n":"no\n"))cin>>i;
}

Measured memory_bytes: 3080
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long X = sc.nextLong();
		long[] five = new long[121];
		long A = 0;
		for( int i=1; i<=120; i++ ){
			A++;
			five[i] = A*A*A*A*A;
		}
		loop:for( int i=0; i<=120; i++ ){
			for( int k=0; k<=120; k++ ){
				if( five[i]-five[k]==X ){
					System.out.println(i+" "+k);
					break loop;
				}
				if( five[i]+five[k]==X ){
					System.out.println(i+" "+(-k));
					break loop;
				}			
			}
		}
	}
}


Measured memory_bytes: 38808
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    print(n//3)
    return

#B
def B():
    _ = II()
    s = S()
    print(["Three", "Four"][len(set(s)) - 4])
    return

#C
def C():
    return

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

    def root(self,x):
        if x == self.par[x]:
            return x
        r = self.root(self.par[x])
        self.differ_weight[x] += self.differ_weight[self.par[x]]
        self.par[x] = r
        return r

    def weight(self, x):
        self.root(x)
        return self.differ_weight[x]

    def unit(self, x, y, w):
        w += self.weight(x)
        w -= self.weight(y)
        x = self.root(x)
        y = self.root(y)
        if x == y: return False
        if self.rank[x] < self.rank[y]: x, y, w = y, x, -w
        if self.rank[x] == self.rank[y]: self.rank[x] += 1
        self.par[y] = x
        self.differ_weight[y] = w
        return True

    def differ(self, x, y):
        return self.weight(y) - self.weight(x)
#D
def D():
    h, w, d = LI()
    u = Value_UnionFind(h * w)
    field = defaultdict(list)
    for i in range(h):
        a = LI_()
        for j in range(w):
            field[a[j]] = [j, i]
    for i in range(h * w):
        if i + d < h * w:
            x1, y1 = field[i]
            x2, y2 = field[i + d]
            u.unit(i, i + d, abs(x1 - x2) + abs(y1 - y2))

    for _ in range(II()):
        l, r = LI_()
        print(u.differ(l, r))
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 89852
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
ab = [LIST() for _ in range(N-1)]
c = sorted(LIST())
print(sum(c)-c[-1])

cnt = [0]*N
graph = [[] for _ in range(N)]

for a, b in ab:
	graph[a-1].append(b-1)
	graph[b-1].append(a-1)
	cnt[a-1] += 1
	cnt[b-1] += 1

ans = [0]*N

q = deque([0])
while q:
	p = q.popleft()
	ans[p] = c.pop()
	for i in graph[p]:
		if ans[i] == 0:
			q.append(i)

print(*ans)

Measured memory_bytes: 13892
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)

const LL N=2505;
LL t,n,m,ans;
LL pr[N];
bitset<N> prime;
map<LL,LL> ma;

void getprime(){
	LL i,j,k,l;
//	cout<<pow(1e10,1.0/3.0)<<endl;
	for(i=2;i<N;i++){
		if(!prime[i]){
			pr[++pr[0]]=i;
			for(j=i+i;j<N;j+=i)prime[j]=1;
		}
	}
//	cout<<pr[0]<<endl;
	for(i=1;i<=pr[0];i++){
		pr[i]=pr[i]*pr[i]*pr[i];
	}
}
 
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0;
	getprime();
	cin>>n;
	repu(i,1,n){
		cin>>k;
		for(j=1;j<=pr[0]&&pr[j]<=k;j++){
			while(k%pr[j]==0)k/=pr[j];
		}
		ma[k]++;
	}
	for(auto &p:ma){
		if(p.first==1ll)ans+=min(1ll,p.second);
		else {
			k=1ll*p.first*p.first;
			for(i=1;i<=pr[0]&&pr[i]<=k;i++)while(k%pr[i]==0)k/=pr[i];
			ans+=max(p.second,ma[k]);
			p.second=ma[k]=0ll;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 18688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static long N;
    static long A;
    static long B;
    static void INPUT()
    {
        N = NextLong();
        A = NextLong();
        B = NextLong();
    }

    static void OUT()
    {
        var a = (N / (A + B)) * A;
        var b = Math.Min(N % (A + B), A);
        Console.WriteLine(a + b);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 11220
#include<iostream>
#include<algorithm>

using namespace std;

int main(){

    int n;
    cin>>n;
    long long sum=0ll;
    for(int a=1;a<=n;++a){
        for(int b=1;b<=n;++b){
            for(int c=1;c<=n;++c){
                sum+=(__gcd(a,__gcd(b, c)));
            }
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3636
n=int(input())
a=list(map(int,input().split()))

a.sort()
amax=max(a)
dp=[True]*(amax+1)

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aa=set()
for ai in a:
    if dp[ai]:
        aa.add(ai)
        for aj in range(ai*2,amax+1,ai):
            dp[aj]=False

aa=aa-dset    
print(len(aa))


Measured memory_bytes: 59776
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,ans=0;
	cin>>a>>b;
	if(a==b)
	{
		cout<<"1";
	}
	else
	{
		while(b>1)
		{
			ans++;
			b-=a-1;
		}
		cout<<ans;
	}
    return 0;
}

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

int main(void) {

    int A,B,C,D;

    int score = 0;

    // A +1
    // B +0
    // C -1
    scanf("%d %d %d %d",&A,&B,&C,&D);

    while(D != 0 && A != 0){
        A--;
        D--;
        score++;
    }

    if(D == 0){
        printf("%d\n",score);
        return 0;
    }

    while(D != 0 && B != 0){
        B--;
        D--;
    }

    if(D == 0){
        printf("%d\n",score);
        return 0;
    }

    while(D != 0 && C != 0){
        C--;
        D--;
        score--;
    }

    if(D == 0){
        printf("%d\n",score);
        return 0;
    }


    return 0;
}

Measured memory_bytes: 2152
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

ll n;
bool used[100001]={};
ll dist[100001][2]={};
vector<ll> ver[100001];
int gote=0;
ll snuke_n=0;

void dfs(ll v){
  for(auto&& vn : ver[v]){
    if(!used[vn]){
      dist[vn][gote]=dist[v][gote]+1;
      used[vn]=true;
      if(gote==1){
        if(dist[vn][1]>=dist[vn][0])continue;
        snuke_n++;
      }
      dfs(vn);
    }
  }
}

int main(){
  cin>>n;
  for(ll i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    ver[a].push_back(b);
    ver[b].push_back(a);
  }
  used[1]=true;
  dfs(1);
  for(ll i=1;i<=n;i++){
    used[i]=false;
  }
  gote=1;
  used[n]=true;
  dfs(n);
  cout<<((snuke_n*2>=n-2)?"Snuke":"Fennec")<<endl;
  return 0;
}


Measured memory_bytes: 10624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define INFLL (1LL << 60)
#define INF (1 << 30)
using namespace std;
typedef long long ll;

template<class T> inline void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }

class UnionFind
{
	vector<int> pr, rank;
public:
	UnionFind(int n) {
		pr.resize(n);
		rank.resize(n, 0);	//rank	子どもの深さ
		for (int i = 0; i < n; ++i) pr[i] = i;	//頂点iの親を格納する
	}
	int root(int x) {
		if (x == pr[x]) return x;
		else return pr[x] = root(pr[x]);	//経路圧縮
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) {
			pr[x] = y;	//子どもを深く持つ方を親にする
		}
		else {
			pr[y] = x;
			if (rank[x] == rank[y]) ++rank[x];
		}
		return true;
	}
};

struct Edge { int from, to, cost; };

ll kruskal(vector<Edge>& edges, int vnum) {
	sort(edges.begin(), edges.end(), [](Edge a, Edge b) {
		return a.cost < b.cost;
		});
	ll sum = 0;
	UnionFind uf = UnionFind(vnum);
	for (Edge e : edges) {
		if (uf.unite(e.from, e.to)) {
			sum += e.cost;
		}
	}
	return sum;
}
int main()
{
	int N; cin >> N;
	vector<int> X(N), Y(N);
	rep(i, N) {
		cin >> X[i] >> Y[i];
	}
	vector<pair<int, int>> ps(N);	//点(x,y)の管理
	vector<pair<int, int>> xs(N);	//xと点id
	vector<pair<int, int>> ys(N);	//yと点id
	rep(i, N) {
		ps[i] = make_pair(X[i], Y[i]);
		xs[i] = make_pair(X[i], i);
		ys[i] = make_pair(Y[i], i);
	}
	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());

	vector<Edge> edges((N - 1) * 2);
	rep(i, N - 1) {
		edges[i].from = xs[i].second;
		edges[i].to = xs[i + 1].second;
		edges[i].cost = xs[i + 1].first - xs[i].first;

		edges[i + N - 1].from = ys[i].second;
		edges[i + N - 1].to = ys[i + 1].second;
		edges[i + N - 1].cost = ys[i + 1].first - ys[i].first;
	}
	cout << kruskal(edges, N) << endl;
	return 0;
}


Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int count = 0;
    for(int i = 100; i > 0; i--){
        if(a%i == 0 && b%i == 0) count++;
        if(count == k) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// https://www.hamayanhamayan.com/entry/2017/12/18/181730

const ll maxn=1<<16;
ll dp1[maxn];           // sの時、全ての線分を平行にできるか
set<pll> dp2[maxn];     // sの時、全ての線分が平行な状態の時の傾きの集合
ll dp3[maxn];           // sの時、平行な線分の組数の最大

// dp1[s]は以下の様に求める
// sから2点を取り除いた集合をnmaskとする
// dp1[nmask]==1 かつ 取り除いた2点の傾きが、dp2[nmask]に含まれるならば、dp1[s]=1となり、dp2[s]にはその傾きが含まれる
// よって、dp1を更新するためには、以下の初期化を行う
// dp1は全ての2点の組合せに対して、1にしておく(...011=3, ...101=5 など)
// dp2も同様に全ての2点の組合せに対して、傾きを求めておく

ll bitcount(ll x){
  if(x==0) return 0;
  return bitcount(x>>1)+(x&1);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll m; cin>>m;
  vpll p(m);
  rep(i,m){
    ll x,y; cin>>x>>y;
    p[i]={x,y};
  }
  
  dp1[0]=1;
  rep(i,m) irep(j,i+1,m){
    ll s=(1<<i)|(1<<j);
    ll x=p[i].first-p[j].first, y=p[i].second-p[j].second;
    dp1[s]=1;
    dp2[s].insert({x,y});
  }
  
  irep(s,1,1<<m){
    if(bitcount(s)%2!=0) continue;
    rep(i,m) if(s>>i&1) irep(j,i+1,m) if(s>>j&1){
      ll nmask=s^(1<<i)^(1<<j);
      if(!dp1[nmask]) continue;
      
      ll x=p[i].first-p[j].first, y=p[i].second-p[j].second;
      for(auto e: dp2[nmask]){
        if(e.first*y==e.second*x){
          dp1[s]=1;
          dp2[s].insert(e);
        }
      }
    }
  }
  
  rep(s,1<<m) if(dp1[s]){
    ll cnt=bitcount(s)/2;
    dp3[s]=cnt*(cnt-1)/2;
  }
  
  rep(s,1<<m){
    for(ll sub=s; sub>=0; sub--){
      sub&=s;
      chmax(dp3[s],dp3[s-sub]+dp3[sub]);
    }
  }
  
  // rep(s,1<<m) cout<<dp1[s]<<endl;
  // rep(s,1<<m) cout<<dp3[s]<<endl;
  
  cout<<dp3[(1<<m)-1]<<endl;
  
}



Measured memory_bytes: 6984
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N;
double dp[3099][3099],p[3099],head[3099],tail[3099];

double f(ll n, ll m){
	if (n==0){
		if (m==0)return 1;
		else return 0;
	}
	if (m==0){
		return tail[n];
	}
	if (m==n){
		return head[n];
	}
	if(dp[n][m]>-1)return dp[n][m];
	dp[n][m]=p[n]*f(n-1,m-1)+(1-p[n])*f(n-1,m);
	return dp[n][m];
}

int main(){
	cin >> N;
	memset(dp,-1,sizeof dp);
	for(int i=1; i<=N; i++){
		cin >> p[i];
	}
	head[1]=p[1];
	tail[1]=1-p[1];
	for(int i=2; i<=N; i++){
		head[i]=p[i]*head[i-1];
		tail[i]=(1-p[i])*tail[i-1];
	}
	double jwb=0;
	for(int i=(N+1)/2; i<=N; i++){
		 jwb+=f(N,i);
	}
	cout << fixed << setprecision(10) << jwb << endl;
	
}

Measured memory_bytes: 75520
class Program
{
    static void Main(string[] args)
    {
        string[] temp = System.Console.ReadLine().Split(' ');
        int A = int.Parse(temp[0]);
        int B = int.Parse(temp[1]);
        int C = int.Parse(temp[2]);
        if (B / A > C) { System.Console.WriteLine(C); }
        else { System.Console.WriteLine(B/A); }
    }
}


Measured memory_bytes: 11092
#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 a, b;
  cin >> a >> b;
  if (a == b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
int main(){
	int end=0;
	int x,y;
	while(end==0){
		scanf("%d",&x);
		scanf("%d",&y);
		if(x==0&&y==0){
			end=1;
		}else{
			if(x<=y){
				printf("%d %d\n",x,y);
			}else{
				printf("%d %d\n",y,x);
			}
		}
	}
}


Measured memory_bytes: 2100
#include <iostream>
using namespace std;
int main(void){
    char s[26],c=0;
    cin>>s;
    for(int i=0;s[i]!='\0';i++){
        for(int j=i+1;s[j]!='\0';j++){
            if(s[i]==s[j]){
                c++;
            }
        }
    }
    if(c==0){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Char
import Data.Int
import Data.Bifunctor
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

readInt :: BS.ByteString -> Int
readInt s = case BS.readInt s of
              Just (x, _) -> x

main = do
  n <- readInt <$> BS.getLine
  xs :: U.Vector Int64 <- U.unfoldrN n (fmap (bimap fromIntegral (BS.dropWhile isSpace)) . BS.readInt) <$> BS.getLine
  let negatives = U.filter (<= 0) xs
      abss = U.map abs xs
  if even (U.length negatives)
    then print $ U.sum abss
    else print $ U.sum abss - 2 * U.minimum abss


Measured memory_bytes: 5756
Q, H, S, D = map(int, input().split())
N = int(input())

rate = {"Q": 4 * Q, "H": 2 * H, "S": S, "D": 1 / 2 * D}
price = 0
score_sorted = sorted(rate.items(), key=lambda x: x[1])
for x in score_sorted:
    if x[0] == "D" and N >= 2:
        div, mod = divmod(N, 2)
        N = mod
        price = D * div
    elif x[0] == "S":
        price += N * S
        break
    elif x[0] == "H":
        price += N * H * 2
        break
    elif x[0] == "Q":
        price += N * Q * 4
        break
    if N == 0:
        break
print(price)


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC066A___ringring
{
    class Program
    {
        static void Main(string[] args)
        {
            int buyingRingNum = 2;

            string[] input = Console.ReadLine().Split(' ');

            List<int> ringPrice = new List<int>();
            List<int> buyingRingPrice = new List<int>();

            foreach (string v in input)
            {
                ringPrice.Add(int.Parse(v));
            }

            for (int index = 0; index < buyingRingNum; index++)
            {
                int min = ringPrice.Min();
                buyingRingPrice.Add(min);
                ringPrice.Remove(min);
            }

            Console.WriteLine(buyingRingPrice.Sum());

        }
    }
}


Measured memory_bytes: 13268