akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;

struct node {
    int a, b;

    bool operator<(const node &t) const {
        return a * (t.b + 1) > t.a * (b + 1);
    }
} p[N];

ll pre[N];
int n, cnt = 0, tot = 0;
ll t;
ll dp[50];

ll calc() {
    for (int i = 0; i < 35; i++)dp[i] = (i ? 1e9 : 0);
    for (int i = 1; i <= cnt; i++) {
        for (int j = 30; j >= 0; j--) {
            if (dp[j] == 1e9)continue;
            dp[j + 1] = min(dp[j + 1], (dp[j] + 1) * (p[i].a + 1) + p[i].b);
            if (dp[j + 1] > t)dp[j + 1] = 1e9;
        }
    }
    int ans = -1;
    for (int i = 0; i < 32; i++) {
        if (dp[i] != 1e9) {
            ll x = t - dp[i];
            int l = 1, r = tot, y = -1;
            while (l <= r) {
                int mid = (l + r) >> 1;
                if (pre[mid] <= x) y = mid, l = mid + 1;
                else r = mid - 1;
            }
            if (y != -1) ans = max(ans, i + y);
            else ans = max(ans, i);
        }
    }
    return ans;
}

int main() {
    scanf("%d%lld", &n, &t);
    int a, b;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a, &b);
        if (a == 0)pre[++tot] = b;
        else p[++cnt] = {a, b};
    }
    sort(p + 1, p + cnt + 1);
    sort(pre + 1, pre + tot + 1);
    for (int i = 1; i <= tot; i++)pre[i] += pre[i - 1] + 1;
    printf("%lld\n", calc());
    return 0;
}

Measured memory_bytes: 5292
#include <stdio.h>
#include <algorithm>
#define mod 100000007
using namespace std;
int r, c, a1, a2, b1, b2, f1, f2, dp[1001][1001];
int main() {
	scanf("%d%d%d%d%d%d", &r, &c, &a1, &a2, &b1, &b2);
	if(a1 > b1) swap(a1, b1);
	if(a2 > b2) swap(a2, b2);
	f1 = ((b1 - a1) * 2 == r ? 2 : 1);
	f2 = ((b2 - a2) * 2 == c ? 2 : 1);
	if((b1 - a1) * 2 > r) a1 += r, swap(a1, b1); b1 -= a1, a1 = 0;
	if((b2 - a2) * 2 > c) a2 += c, swap(a2, b2); b2 -= a2, a2 = 0;
	dp[0][0] = 1;
	for(int i = 0; i <= 1000; i++) {
		for(int j = 0; j <= 1000; j++) {
			if(i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			if(j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	}
	printf("%d\n", dp[b1][b2] * f1 * f2 % mod);
	return 0;
}

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

using namespace std;

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

  int a[n + 1];
  for (int i = 0; i < n + 1; ++i) cin >> a[i];

  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int b;
    cin >> b;

    int x = min(a[i], b);
    ans += x;
    b -= x;

    x = min(a[i+1], b);
    ans += x;
    a[i+1] -= x;
  }

  cout << ans << endl;
}


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

using namespace std;

void Main() {
    int H, W;
    cin >> H >> W;
    vector<vector<string> > C(H, vector<string>(W, ""));
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < W; ++j) {
            C[i][j] = s.substr(j, 1);
        }
    }

    for (int i = 0; i < 2 * H; ++i) {
        for (int j = 0; j < W; ++j) {
            cout << C[i / 2][j];
        }
        cout << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3956
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		int a = s.indexOf("A");
		int z = s.lastIndexOf("Z");
		
		System.out.println(z - a + 1);
		
	}
}

Measured memory_bytes: 26952
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)
struct input_returnner { 
	int N; input_returnner(int N_ = 0) :N(N_) {}
	template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
	template<typename T> operator T() const { T res; cin >> res; return res;} 
};
template<typename T> input_returnner in() { return in<T>(); }
input_returnner in() { return input_returnner(); }
input_returnner in(int N) { return std::move(input_returnner(N)); }

/// ---template---
void solve();

signed main(void) {
	SETUP;
	solve();
	return 0;
}

void solve() {
	ull N, X; cin >> N >> X;
	vector<ull> A = in(N);
	vector<ull> mi(N); REP(i, N) mi[i] = A[i];

	ull res = -1;
	REP(width, N) {
		ull cnt = width*X;
		REP(j, N) {
			mi[j] = min(mi[j], A[(j - width + N)%N]);
			cnt += mi[j];
		}
		res = min(res, cnt);
	}
	cout << res << endl;
}

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

#define  ll  long long
#define  pii pair<int,int>
#define  pll pair<ll , ll>
#define  debug cout << "this far" << endl;
#define  For(i, n) for(int i = 0; i < (n); ++i)
#define  lsb(x) ((x) & (-x))
#define  PI acos(-1)
#define  line cout << endl;
#define  getbit(n, i) (((n) & (1LL << (i))) != 0)
#define  resetbit(n, i) ((n) & (~(1LL << (i))))
#define  setbit(n, i) ((n) | (1LL << (i)))
#define  togglebit(n, i) ((n) ^ (1LL << (i)))
#define  gap " "
using namespace std;
const int N = 1e6;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s ; cin >> s ;
    ll sm = 0;
    for(auto  i : s) sm +=  ( i - '0') ;
    if( sm % 9 ) cout << "No"  ;
    else cout << "Yes"  ;

}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define M 100002
using namespace std;
struct lll{
	int l,to;
}edge[M];
struct ll{
	int x,flg,step;
};
queue<ll>Q;
int h[M],S,T;
bool mem[5][M];
void Add(int i,int st,int to){
	edge[i].l=h[st];
	edge[i].to=to;
	h[st]=i;
}
int bfs(){
	while(!Q.empty()){
		ll t=Q.front();
		Q.pop();
		if(t.x==T&&t.flg==0)return t.step;
		for(int i=h[t.x];i;i=edge[i].l){
			int y=edge[i].to;
			ll now=t;
			now.x=y;
			if(now.flg==0)now.step++;
			now.flg=(now.flg+1)%3;
			if(!mem[now.flg][now.x])Q.push({now}),mem[now.flg][now.x]=1;
		}
	}
	return -1;
}
int main(){
	memset(mem,0,sizeof(mem));
	int n,m,u,v;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d",&u,&v),Add(i,u,v);
	scanf("%d%d",&S,&T);
	Q.push({S,0,0});
	mem[0][S]=1;
	printf("%d\n",bfs());
	return 0;
}

Measured memory_bytes: 2304
x, k ,d = map(int, input().split())

if abs(x) > k*d:
    print(abs(x)-k*d)
else:
    t = abs(x)%d
    s = (abs(x)-t)//d
    if (k-s) % 2 == 1:
        print(abs(t-d))
    else:
        print(t)


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a[3];

int main() {
	inc(i, 3) { cin >> a[i]; }
	
	
	if(a[0] == a[1]) { cout << a[2] << endl; }
	if(a[1] == a[2]) { cout << a[0] << endl; }
	if(a[2] == a[0]) { cout << a[1] << endl; }
		
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll key = 1e9;
int main() {
	ll s;
	cin >> s;
	vector<ll> x(3), y(3);
	x[0] = 0, y[0] = 0;
	if(s >= 1e18) {
		x[1] = 1e9, y[1] = 0;
		x[2] = 0, y[2] = 1e9;
	}else {
		ll a = s / key, b = s%key;
		a++;
		b -= key;
		x[1] = key, y[1] = 1;
		x[2] = -b, y[2] = a;
	}
	for(int i=0;i<3;i++) {
		cout << x[i] << " " << y[i] << ((i==2)?"\n":" ");
	}
}

Measured memory_bytes: 256
lst = input().split()

X = int(lst[0])
K = int(lst[1])
D = int(lst[2])

a = int((D * K - X) / (2 * D))

if a < 0:
   a = 0

if a > K:
   a = K

def f(x):
   return X - D * K + 2 * D * x

lst2 = [abs(f(a))]

if a + 1 <= K:
   lst2.append(abs(f(a+1)))

if 0 < a:
   lst2.append(abs(f(a-1)))

result = min(lst2)

print(result)

Measured memory_bytes: 9124
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) int {
	ans := l[0]
	for _, n := range l {
		if n > ans {
			ans = n
		}
	}
	return ans
}

func min(l []int) int {
	ans := l[0]
	for _, n := range l {
		if n < ans {
			ans = n
		}
	}
	return ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	r := nextInt()
	s := nextInt()
	p := nextInt()
	tt := next()
	t := []rune(tt)
	var ans int
	flag := make([]bool, n, n)
	for i := 0; i < n; i++ {
		idx := n - 1 - i
		if flag[idx] {
			continue
		}
		if idx >= k {
			if t[idx] == t[idx-k] {
				flag[idx-k] = true
			}
		}
		x := string(t[idx])
		if x == "r" {
			ans += p
		} else if x == "s" {
			ans += r
		} else if x == "p" {
			ans += s
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1408
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    println(if (n % 2 == 0) n else n*2)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33524
num = gets.split.map(&:to_i).sort
diff1 = num[-1] - num[0]
diff2 = num[-1] - num[1]
if diff1.even? && diff2.even?
    puts ((diff1 / 2) + (diff2 / 2))
    
elsif diff1.odd? && diff2.odd?
    puts ((diff1 / 2) + (diff2 / 2) + 1) 
else
    puts ((diff1 / 2) + (diff2 / 2) + 2)
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int r_count = 0, l_count = 0, r = 0, l = 1;
  vector<int> v(n);
  rep(i, n) {
    if (s[i] == 'R') r_count++;
    if (s[i] == 'L') l_count++;
    if (s[i] == 'R' && s[i + 1] == 'L') r = i, l = i + 1;
    if (s[i] == 'L' && s[i + 1] == 'R' || i == n - 1) {
      int count = r_count + l_count;
      v[r] = count / 2, v[l] = count / 2;
      if (count % 2 != 0) {
        if ((max(r_count, l_count) - 1) % 2 == 0) {
          if (r_count > l_count)
            v[r]++;
          else
            v[l]++;
        } else {
          if (r_count > l_count)
            v[l]++;
          else
            v[r]++;
        }
      }
      r_count = 0, l_count = 0;
    }
  }
  for (auto m : v) cout << m << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 3820
(n,_),*z=[t.split()for t in open(0)]
n=int(n)
a=0
for i in range(1000):
  t=str(i)
  a|=n==-~a*len(t)and all(c==t[int(s)-1]for s,c in z)and-~i
print(a-1)

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include <vector>
#include <map> // pair
using namespace std;


int main()
{	
	long long int N, M;
	scanf("%lld %lld", &N, &M);
	
	long long int P[M], Y[M][2];
	
	for(long long int i=0;i<M;i++){
		scanf("%lld %lld", &P[i], &Y[i][0]);
	}
	long long int ken[N+1];
	for(long long int i=0;i<N+1;i++){
		ken[i]=1;
	}
	
	
	for(long long int i=0;i<M;i++)
	{
		Y[i][1]=i;
	}

	vector<pair<long long int, long long int> > pairs(M);
	for (long long int i = 0; i < M; i++) {
	pairs[i] = make_pair(Y[i][0], Y[i][1]);
	}

	sort(pairs.begin(), pairs.end());
	
	for(long int i=0;i<M;i++)
	{
		Y[i][0]=pairs[i].first;
		Y[i][1]=pairs[i].second;
	}

	
	long long int answer[M];	
	
	for(long long int i=0;i<M;i++){
		answer[Y[i][1]]=1000000*P[Y[i][1]]+ken[P[Y[i][1]]];
		ken[P[Y[i][1]]]++;
	}
	for(long long int i=0;i<M;i++){
		printf("%012lld \n",answer[i]);
	}
}


Measured memory_bytes: 7040
using namespace std;
#include <bits/stdc++.h>
#include<math.h>
int main()
{
    int a=0;
    string s;cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+'){
            a++;
        }
        else if(s[i]=='-'){
            a--;
        }
    }
    std::cout << a << std::endl;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
vector<int> to[100010];
int main(void){
    ll n,m;
    cin>>n>>m;
    ll h[100001];
    for(int i=0;i<n;i++) cin>>h[i];
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        bool ok=true;
        for(auto x:to[i]){
            if(h[i]<=h[x]){
                ok=false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9524
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll a, p;
    cin >> a >> p;

    cout << (a * 3 + p) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {

	long long int a, b, k; cin >> a >> b >> k;
	if (a >= k) { cout << a - k << " " << b << endl; }
	else if (a < k && a + b >= k) { cout << "0 " << b - (k - a) << endl; }
	else { cout << "0 0" << endl; }

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m;
int main(){
	cin>>n>>m;
	if (n==1){
		cout<<m<<endl;
		return 0;
	}
	for (long long i=m/n;i>=1;i--)
		if (m%i==0){
			cout<<i<<endl;
			break;
		}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
#import heapq
from collections import deque

H,W = map(int, input().split())
Ch,Cw = map(int, input().split())
Dh,Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

S = []
for _ in range(H):
  S.append(list(input()))
  
dpat = ((-1,0),(1,0),(0,-1),(0,1))
mpat = []
for i in range(-2,3):
  for j in range(-2,3):
    if (i,j) in dpat:
      continue
    if i == j and j == 0:
      continue
    mpat.append((i,j))
                
#print(mpat)

#BFS
visited = [[False] * W for _ in range(H)]
willSearch = [[False] * W for _ in range(H)]
Q = deque()
QN = deque()
Q.append((0,Ch,Cw))
QN.append((0,Ch,Cw))
while Q:
  while Q:
    c,x,y = Q.popleft()
    if visited[x][y]:
      continue
    visited[x][y] = True
    QN.append((c,x,y))
    #print(c,x,y)
    if x == Dh and y == Dw:
      print(c)
      exit(0)
    for dx,dy in dpat:
      nx,ny = x+dx, y+dy
      if 0<=nx<H and 0<=ny<W:
        if S[nx][ny] == "#":
          continue
        if visited[nx][ny] or willSearch[nx][ny]:
          continue
        Q.append((c,nx,ny))
        QN.append((c,nx,ny))
        willSearch[nx][ny] = True
  while QN:
    c,x,y = QN.popleft()
    for dx,dy in mpat:
      nx,ny = x+dx, y+dy
      if 0<=nx<H and 0<=ny<W:
        if S[nx][ny] == "#":
          continue
        if visited[nx][ny] or willSearch[nx][ny]:
          continue
        Q.append((c+1,nx,ny))
        #print("m", c+1, nx,ny)
        #willSearch[nx][ny] = True
      
print(-1)

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

using namespace std;

int main(){

   string t;

   cin >> t;

   for(int i = 0; i < t.length(); i++){
      if(t[i] == '?'){
         cout << "D";
      }
      else{
         cout << t[i];
      }
   }

   cout << endl;

   return 0;
}

Measured memory_bytes: 3724
// 2011/01/31 Tazoe

#include <iostream>
using namespace std;

void print4(int n)
{
	if(n/4!=0)
		print4(n/4);

	cout << n%4;
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==-1)
			break;

		print4(n);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
using Graph = vector<vector<int>>;

long long N;
map<int, map<int, int>> mp; //頂点、色種、0
map<pair<int, int>, int> ecolor; //辺、色番号

void dfs(Graph &G, int v, vector<int> &done, int K){
	if(done[v] == 1) return;

	map<int, int> used;
	//隣の頂点が処理済の場合、隣の頂点の辺の色をusedに追加
	for(auto next_v : G[v]){
		if(done[next_v] == 0){
			continue;
		}
		int a = min(v, next_v);
		int b = max(v, next_v);
		if(ecolor.count({a, b}) != 0){
			used[ecolor[{a, b}]] = 1;
			continue;
		}
		for(auto nn_v : G[next_v]){
			if(nn_v != v){
				used[ecolor[{min(next_v, nn_v), max(next_v, nn_v)}]] = 1;
			}
		}
	}

	//used以外の色を順番に色付け
	map<int, int> color;
	int c = 1;
	for(auto next_v : G[v]){
		int a = min(v, next_v);
		int b = max(v, next_v);
		if(ecolor.count({a, b}) != 0){
			continue;
		}
		int i;
		for(i = c; i <= K; i++){
			if(used.count(i) == 0){
				color[i] = 1;
				used[i] = 1;
				ecolor[{a, b}] = i;
				break;
			}
		}
		c = i + 1;
	}
	mp[v] = color;
	done[v] = 1;

	//次の頂点の処理
	for(auto next_v : G[v]){
		dfs(G, next_v, done, K);
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	Graph G(N);
	vector<pair<int, int>> edge;
	for(int i=0; i<N-1; i++){
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
		edge.push_back(make_pair(a - 1, b - 1));
	}

	int K = 0;
	int v = 0;
	for(int i=0; i<N; i++){
		int w = G[i].size();
		if(w > K){
			K = w;
			v = i;
		}
	}
	printf("%d\n", K);

	//vを起点に辺に色付けしていく
	vector<int> done;
	done.assign(N, 0);
	dfs(G, v, done, K);

	for(int i=0; i<edge.size(); i++){
		int a = edge[i].first;
		int b = edge[i].second;
		int c = ecolor[{a, b}];
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 44464
#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring> 
#include <algorithm>
using namespace std;
#include <queue> 
#define ll long long
int main()
{
	ll a,b,c,d;
	ll x,y;
	cin>>a>>b>>c>>d;
	x=(a*c>=b*d?a*c:b*d);
	y=(b*c>=a*d?b*c:a*d);
//	cout<<x<<endl<<y<<endl;
	cout<<(x>=y?x:y);
}

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

int main(){
    int list[4][3][10]={{{}}};
    int n;
    cin >> n;
    int b,f,r,v;
    
    for (int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        list[b-1][f-1][r-1]+=v;
    }
    
    for (int c=0;c<4;c++){
        for (int d=0;d<3;d++){
            for (int e=0;e<10;e++){
                cout << " " << list[c][d][e];
            }
            cout << endl;
        }
        if (c==3) break;
        cout << "####################"<<endl;
    }
    return 0;
}


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

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

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

ll DT[100010]={0};

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

	int ma=0;
	for (int i = 0; i < n; i++){
		cin>>d;

		if(i==0&&d!=0){
			cout<<0<<endl;
			return 0;
		}

		DT[d]++;
		ma=max(ma,d);
	}

	if(DT[0]!=1){
		cout<<0<<endl;
		return 0;
	}

	ll ans=1,mod=998244353;
	for (ll i = 2; i <= ma ; i++){
		ll pp=1;
		for (int j = 0; j < DT[i]; j++){
			pp=(pp*DT[i-1])%mod;
		}

		ans = (ans*pp)%mod;
	}
	cout<<ans<<endl;



	return 0;
}
	


Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {

  int A,B;
  scanf("%d %d",&A,&B);
  
  if(A == 1){
    A += 13;
  }
  if(B == 1){
    B += 13;
  }

  if(A>B){
    printf("Alice\n");
  } else if(A==B){
    printf("Draw\n");
  } else {
    printf("Bob\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

int main(){
    int k;
    cin>>k;
    char s[105];
    cin>>s;
    
    int slen=strlen(s);
    if(slen<=k){
        cout<<s<<endl;
    }else{
        s[k]='.';
        s[k+1]='.';
        s[k+2]='.';
        s[k+3]='\0';
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
//written by: rishav2416
#include <bits/stdc++.h>
#define ll long  long
#define lli long long int
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define arrinit(arr,n,k) for(ll c1=0;c1<n;c1++) arr[i]=k;
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define revrep(i,a,n) for(ll i=a; i>=n ; i--)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define INF 1e18a



ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}


std::string str="All Good Till Here";

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

int32_t main()
{
    fastio
	ll n,tt,i,j,x;
	//cin>>tt;
  tt=1;
	while(tt--)
	{
    cin>>n;
    ll a[n],b[2*n];
    input(a,n);
    j=-1;
    map<ll,ll> mp;
    for(i=0;i<n;i++)
    {
      mp[i-a[i]]++;
    }
    ll count=0;
    for(i=0;i<n;i++)
    {
      count+=mp[i+a[i]];
    }
    cout<<count<<"\n";
	}
    return 0;
}


Measured memory_bytes: 27772
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

#[derive(Debug)]
struct Value {
    a: i32,
    b: i32,
    c: i32,
}

fn main() {
    input! {
        n: usize,
        h: [(i32, i32, i32); n],
    }
    let mut values: Vec<Value> = Vec::new();
    for (a, b, c) in h {
        values.push(Value{ a: a, b: b, c: c });
    }

    // initialize
    let mut dp: Vec<(i32, i32, i32)> = vec![(0, 0, 0); n];
    let before_a = max(values[n - 1].b, values[n - 1].c);
    let before_b = max(values[n - 1].c, values[n - 1].a);
    let before_c = max(values[n - 1].a, values[n - 1].b);
    dp[n - 1] = (before_a, before_b, before_c);

    for i in (0..n - 1).rev() {
        let choose_a = values[i].a + dp[i + 1].0;
        let choose_b = values[i].b + dp[i + 1].1;
        let choose_c = values[i].c + dp[i + 1].2;
        dp[i] = if i == 0 {
            (choose_a, choose_b, choose_c)
        } else {
            let before_a = max(choose_b, choose_c);
            let before_b = max(choose_c, choose_a);
            let before_c = max(choose_a, choose_b);
            (before_a, before_b, before_c)
        };
    }
    println!("{}", max(max(dp[0].0, dp[0].1), dp[0].2));

} 


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define lli   long long int
#define pb push_back
#define rep(i,s,n) for(lli i=s;i<n;i++)
#define irep(i,n,s) for(lli i=n-1;i>=s;i--)
#define mp make_pair
#define mod 1000000007
using namespace std;

vector<int>graph[200005];


void dfs(int src, bool vis[], int &count)
{
    vis[src] = true;
    count++;
    for (int i = 0; i < graph[src].size(); i++)
    {
        if (!vis[graph[src][i]])
        {

            dfs(graph[src][i], vis, count);
        }
    }

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio;
    cin.tie(NULL);
    int i, j, k, m, n;
    // cin >> t;


    cin >> n >> m;


    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }

    bool vis[n + 1] = {false};
    int ans = 0;

    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            int count = 0;
            dfs(i, vis, count);

            ans = max(ans, count);
        }
    }
    cout << ans ;






}




Measured memory_bytes: 23996
#include <iostream>

using namespace std;

int main() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    double answer = w / 2.0 * h;
    int z = 0;
    if (w == x * 2 && h == y * 2) {
        z = 1;
    }
    cout << answer << " " << z << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	
	int N;
	scanf("%d", &N);
	int d[50];
	int sum = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &d[i]);
	}

	for (int i = 0; i < N-1; i++) {

		for (int j = i+1; j < N; j++) {
			sum += d[i] * d[j];
		}
	}

	printf("%d", sum);
	return 0;

}

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

int main() {
  string S;
  int K;
  cin >> S >> K;
  vector<string> V;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 1; j <= K; j++) {
      if (i + j - 1 < S.size()) V.push_back(S.substr(i, j));
    }
  }
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());
  cout << V.at(K - 1) << endl;
}

Measured memory_bytes: 4320
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        int num = Integer.parseInt(a + b);

        double sqrt = Math.sqrt(num);
        int sqrtInt = (int) sqrt;
        if (sqrt % sqrtInt == 0) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


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

int main()
{
	int a, n;
	std::cin >> n >> a;
	if ((n % 500) <= a) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	 int x;char C,X;
	scanf("%c",&C);
	if (C=='z')
		printf("a\n");
	else
	{
		x = (int) C;
		X = (char) (x+1);
		printf("%c\n",X);
	}
	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define PPC(x) __builtin_popcount(x)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...)
#endif
using namespace std;

const int maxN = 1 << 11;

char in[2][maxN];

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	long long c = 1ll * a * b / __gcd(a,b);
	printf("%lld\n", c);
	
	printf("\n");

	return 0;
}


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

import sys
import math
import itertools
import bisect

INF = int(1e18)

def main():
    n, t = map(int, sys.stdin.readline().split())

    nzshops = []
    zshops = []
    for _ in range(n):
        a, b = map(int, sys.stdin.readline().split())
        (zshops if a == 0 else nzshops).append((a, b))

    nzshops.sort(key=lambda x: x[0] / (x[0] + x[1] + 1), reverse=True)
    zshops.sort()

    dp = [0]
    for i in range(len(nzshops)):
        dp_ = dp + [INF]
        for c in range(1, len(dp_)):
            a, b = nzshops[i]
            x = dp[c - 1] + 1
            dp_[c] = min(dp_[c], x + x * a + b)
        dp = [x for x in dp_ if x <= t]

    rs = list(itertools.accumulate(1 + b for _, b in zshops))
    ans = max(c + bisect.bisect(rs, t - dp[c])
            for c in range(len(dp)) if dp[c] <= t)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 72028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, r; cin >> n >> r;
    if (10 <= n)cout << r << "\n";
    else cout << r + 100 * (10 - n) << "\n";
}

Measured memory_bytes: 256
/*s1190073  Rina Sato,
File name:prog1.c,
2012 4/18(Wed),
This is a program which reads a list of N integers and prints the number of prime numbers in the list.*/

#include <stdio.h>
#include <math.h>
int hantei(int);
int main(void){
  int N,s[10000],i,count=0;
  
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&s[i]);
  }
  /*if s[i] is a prime,it's counted*/
  for(i = 0 ; i < N ; i++){
    if(hantei(s[i]) == 1) count++;
  }
  printf("%d\n",count);
  return 0;
}
/*judge whether the argument is a prime or a composite number*/
int hantei(int s){
  int j;
  for(j =2 ; j <= sqrt(s) ; j++){
    if(s%j == 0) return 0;
  }
  return 1;
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            String pushs = "";
            
            if(h == 0 && w == 0){
                break;
            } else{
                for(int i = 0; i < h; i++){
                    pushs = "";
                    for(int j = 0; j < w; j++){
                        if(i == 0 || i == h-1 ||
                        j==0 || j == w-1){
                            pushs += "#";
                        } else {
                            pushs +=".";
                        }
                    }
                    System.out.println(pushs);
                }
                System.out.println("");
            }
        }
    }
}



Measured memory_bytes: 50080
#include"bits/stdc++.h"
using namespace std;
 
int main(){
  int n, i, j, point;
 
  char name[100];
  cin >> n;
 
  pair<pair<string, int>, int> p[110];
  for(i=0; i<n; i++) {
    cin >> name >> point;
    p[i] = make_pair(make_pair(name, -point), i);
  }
 
  sort(p, p+n);
  for(i=0; i<n; i++) cout << p[i].second+1 << endl;
  return 0;
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

ll dp[101][101010];
ll w[101], v[101];

int main() {
    int N, W;
    cin >> N >> W;
    rep(i, N) {
        cin >> w[i] >> v[i];
    }

    rep(i, N) {
        rep(j, 101010) dp[i][j] = LLINF;
    }

    dp[0][0] = 0;
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= 100000; ++j) {
            if (j - v[i-1] >= 0) {
                dp[i][j] = min(dp[i-1][j], dp[i-1][j - v[i-1]] + w[i-1]);
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    ll ans = 0;
    for (int j = 100000; j >= 0; --j) {
        if (dp[N][j] <= W) {
            cout << j << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 83232
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nhw = br.readLine().split(" ");
        int n = Integer.parseInt(nhw[0]);
        int h = Integer.parseInt(nhw[1]);
        int w = Integer.parseInt(nhw[2]);
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            String[] ab = br.readLine().split(" ");
            int a = Integer.parseInt(ab[0]);
            int b = Integer.parseInt(ab[1]);
            if (a >= h && b >= w) count++;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 21460
#include<stdio.h>

int main()
{
	int p,s,q, i,j, k=0,cnt;
	int arrp[101] = { 0 }, arr[101] = {0},arrs[31] = { 0 }, arrq[101] = { 0 };

	while (1) 
	{
		scanf("%d,%d", &p, &s);
		if (p == 0 && s == 0)
		{
			break;
		}
		++k;
		arrp[p] = s;
		arr[p] = s;
	}

	for (i = 1; i < k; i++)
	{
		for (j = i + 1; j < k+1; j++)
		{
			if (arrp[i] < arrp[j])
			{
				cnt = arrp[i];
				arrp[i] = arrp[j];
				arrp[j] = cnt;
			}
		}
	}

	cnt = 0;
	for (i = 1; i < k + 1; i++)
	{
		if (arrp[i] == arrp[i - 1])
		{
			++cnt;
		}
		else
		{
			arrs[arrp[i]] = i-cnt;
		}
	}

	k = 0;
	while (scanf("%d", &q) != EOF)
	{
		arrq[k] = arrs[arr[q]];
		++k;
	}
	
	for (i = 0; i < k; i++)
	{
		printf("%d\n",arrq[i]);
	}

	return 0;
}


Measured memory_bytes: 604
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
 
z = list(range(K+1))
ans = []
 
for i in z:
  s_z = S - i
  if s_z < 0:
    pass
  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.append(2*K + 1 - s_z)
  else:
    ans.append(s_z + 1)
 
print(sum(ans))


Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
from collections import Counter
def main():
    N = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)
    Q = int(input())
    T = sum(A)
    for i in range(Q):
        b, c = map(int, input().split())
        if b in D.keys():
            T += (c-b) * D[b]
            D[c] += D[b]
            D[b] = 0
        print(T)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21168
from math import sqrt
M = 10**6
p = [1 for i in range(M+1)]
p[0] = 0
p[1] = 0
for x in range(2, int(sqrt(M))+1):
    if p[x]:
        for y in range(x*x, M+1, x):
            p[y] = 0

a = [0 for i in range(M+1)]
for i in range(M):
    if i%2 != 0 and p[i] and p[(i+1)//2]:
        a[i] = 1

ans = [0 for i in range(M)]
for i in range(1, M):
    ans[i] = ans[i-1] + a[i]

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(ans[r] - ans[l-1])

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

int n, a, b, c;
vector<int> l;

int dfs(int cur, int ma, int mb, int mc)
{
    if (cur == n)
        return (min({ma, mb, mc}) > 0)
                   ? abs(a - ma) + abs(b - mb) + abs(c - mc) - 30
                   : 1e9;
    int ret0 = dfs(cur + 1, ma, mb, mc);
    int ret1 = dfs(cur + 1, ma + l[cur], mb, mc) + 10;
    int ret2 = dfs(cur + 1, ma, mb + l[cur], mc) + 10;
    int ret3 = dfs(cur + 1, ma, mb, mc + l[cur]) + 10;
    return min({ret0, ret1, ret2, ret3});
}

int main()
{
    cin >> n >> a >> b >> c;
    l.resize(n);
    for (int i = 0; i < n; i++)
        cin >> l[i];
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, 1, 0, -1};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;
	int a[n];
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	map<int, int> mp;
	int now = 0;
	int st = 0, len = 0, z = 0;
	vector<int> p(500005);
	rep(i, 500005) {
		now = a[now];
		p[i] = now;
		if (mp.count(now) > 0 and len == 0) {
			z = mp[now], st = now, len = i + 1 - mp[now];
		} else
			mp[now] = i + 1;
	}
	if (k < 300005)
		cout << p[k - 1] + 1 << endl;
	else {
		int pt = (k - z + 1) % len;
		if (pt == 0) pt = len;
		cout << p[pt + z - 2] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 15308
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int n;
void dfs(string s, int mx) {
    if (sz(s) == n) {
        cout << s << endl;
        return;
    }
    for (char c = 'a'; c <= mx+1; ++c) {
        s += c;
        dfs(s, c == mx+1 ? mx+1 : mx);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    dfs("", 'a'-1);
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

ll dp[21][1010];
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(k);
    rep(i,k)cin>>a[i];
    mod_build();
    dp[0][0]=1;
    rep(i,k){
        rep(j,n+1){
            rep(l,j+1){
                dp[i+1][j]+=dp[i][l]*comb(n-l,j-l)%mod*comb(n-j+l,a[i]-j+l)%mod;
                dp[i+1][j]%=mod;
            }
        }
    }
    cout<<dp[k][n]<<endl;
    return 0;
}

Measured memory_bytes: 2816
(defun solve (n ans tmax)
  (cond
    ((< n 1)
     (if (> ans 1000) 'tle ans))
    (t
     (let ((cost (read)) (time (read)))
	 (if (and
	      (<= time tmax)
	      (< cost ans))
	     (solve (- n 1) cost tmax)
	     (solve (- n 1) ans tmax))))))
(print (solve (read) 1000000000 (read)))

Measured memory_bytes: 11492
n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

copy_a = sorted(a, reverse=True)

A_Max = copy_a[0]
A_Second = copy_a[1]

for x in range(n):
    if a[x] == A_Max:
        print(A_Second)
    else:
        print(A_Max)


Measured memory_bytes: 18908
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] numbers = br.readLine().split(" ");

            double average = (Double.parseDouble(numbers[0]) + Double.parseDouble(numbers[1])) / 2;
            int roundUpAverage = (int) Math.ceil(average);

            System.out.println(roundUpAverage);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21204
n=int(input())
a=list(map(int,input().split()))
cnt=0
judge=0

for i in range(n):
    minj=i
    for j in range(i,n):
        if a[j]<a[minj]:
            minj=j
    if a[i]>a[minj]:
        a[i],a[minj]=a[minj],a[i]
        cnt+=1
   
for i in range(n):
    if i==0:
        print(a[i],end="")
    else:
        print("{: }".format(a[i]),end="")
print()
print(cnt)


Measured memory_bytes: 5620
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 ll a[n+1];
 vector<ll>b;
 rep(i,0,n){
  sc(a[i]);
  push(b,a[i]);
 }
 sort(b);
 rep(i,0,n){
  if(a[i]<=b[n/2-1])pr(b[n/2]);
  else pr(b[n/2-1]);
 }
return 0;}

Measured memory_bytes: 6536
import sys
sys.setrecursionlimit(10**6)

def toord(st):
	ans = ""
	if st//1000 != 0:
		if st // 1000 != 1:
			ans += str(st//1000)
		ans+="m"
		st = st % 1000
	if st // 100 != 0:
		if st // 100 != 1:
			ans += str(st//100)
		ans += "c"
		st = st % 100
	if st // 10 != 0:
		if st // 10 != 1:
			ans += str(st//10)
		ans += "x"
		st = st % 10
	if st != 0:
		if st!=1:
			ans += str(st)
		ans += "i"
	return ans
			

def main():
	a,b = input().split()
	a, b = "+" + a, "+"+b
	a, b = a.replace("m","*m+"), b.replace("m", "*m+")
	a, b = a.replace("c","*c+"), b.replace("c", "*c+")
	a, b = a.replace("x","*x+"), b.replace("x", "*x+")
	a, b = a.replace("i","*i+"), b.replace("i", "*i")
	ans, tans = 0, 0
	for j in a+b:
		# print(j,end="")
		if j == "+":
			tans = 1
		elif j == "*":
			ans = ans
		elif j == "m":
			tans *= 1000
			ans += tans
		elif j == "c":
			tans *= 100
			ans += tans
		elif j == "x":
			tans *= 10
			ans += tans
		elif j == "i":
			ans += tans			
		else:
			tans = int(j)
	print(toord(ans))
	return

n = int(input())
for i in range(n):
	main()


Measured memory_bytes: 5632