akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc136/tasks/abc136_d
# ポケモンの動く床みたいに強制的にある座標に移動すると考える。
# ただし10**100回動いた後に、左右どちら側のマスにいるのかに気をつけなければいけない

# 例
# RRLRL
#   | |ココらへんに3人,2人集まるけど
# 01211 と答えはなる

# RRLについて考えると
# 1  ここの人は無限偶数回移動すると
#   1ここに移動する
#  1 ここの人は無限偶数回移動すると変わらない
#
# 一般化すると、RRRRRRにおいて、一番左のRのidx(r)に対してr-idxが偶数ならばrに移動、奇数ならばr+1に移動
# 更に一般化すると、今までRがn回続いたときr+1にはn//2回、rにはn-n//2回追加される

# Lについても一番右のidx(l)に対してidx-lが偶数ならばlに移動、奇数ならばl−1に移動。
# 更に一般化するとこれからLがn回続くとき、l-1にはn//2人、lにはn-n//2人追加

# 前から回すって考えると Rについては更に一般化した方法、Lについては偶奇を考慮した方法がよろしいかと


import sys
read = sys.stdin.readline

S = read()[:-1]
ans = [0] * len(S)

pre = 'R'
cnt = 1
r = 0
for i, s in enumerate(S[1:], start=1):
    if pre == 'R' and s == 'L':
        # lの処理の前にRの処理
        r = i - 1
        ans[r + 1] += cnt // 2
        ans[r] += cnt - cnt // 2
        cnt = 0

        # l開始の処理
        l = i
        pre = 'L'
        ans[l] += 1
    elif pre == 'L' and s == 'L':
        if (i - l) & 1:  # 奇数なら
            ans[l - 1] += 1
        else:
            ans[l] += 1
    if pre == 'L' and s == 'R':
        pre = 'R'
    if pre == 'R' and s == 'R':
        cnt += 1

    # print(*ans)

print(*ans)


Measured memory_bytes: 48700
from math import sqrt
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())

    table = [1] * (N + 1)

    for n in range(2,N):
        for i in range(2*n, N+1, n):
            table[i] += 1
    
    ans = 0
    for i in range(1, N+1):
        ans += i * (table[i] + 1)
    
    print(ans - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 146124
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

vector<lli> segtree[2000001];
lli val[500001],b[500001];
map<lli,lli> m;

void make_segTree(lli index,lli start,lli end)
{
	if(start==end)
	{
		segtree[index].pb(b[start]);
		return;
	}
	lli mid=(start+end)>>1;
	make_segTree(index<<1,start,mid);
	make_segTree(index<<1|1,mid+1,end);
	
	merge(segtree[index<<1].begin(),segtree[index<<1].end(),segtree[index<<1|1].begin(),segtree[index<<1|1].end(),back_inserter(segtree[index]));
}

lli query(lli index,lli start,lli end,lli l,lli r,lli x)
{
	if(l==start && r==end)
	{
		lli last_index=upper_bound(segtree[index].begin(),segtree[index].end(),x)-segtree[index].begin();
		return segtree[index].size()-last_index;	
	}	
	lli mid=(start+end)>>1;
	if(r<=mid)
		return query(index<<1,start,mid,l,r,x);
	else if(l>=mid+1)
		return query(index<<1|1,mid+1,end,l,r,x);
	else
		return query(index<<1,start,mid,l,mid,x) + query(index<<1|1,mid+1,end,mid+1,r,x);
}

int main()
{
	lli n,q,l,r,i;

	scanf("%lld %lld",&n,&q);

	for(i=0;i<n;i++)
		scanf("%lld",&val[i]);

	for(i=n-1;i>=0;i--)
	{
		if(m.find(val[i])==m.end())
			b[i]=mod;
		else
			b[i]=m[val[i]];
		m[val[i]]=i;
	}

	make_segTree(1,0,n-1);

	while(q--)
	{
		scanf("%lld %lld",&l,&r);
		printf("%lld\n",query(1,0,n-1,l-1,r-1,r-1));
	}
	return 0;
}


Measured memory_bytes: 192020
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll h, w;
        cin >> h >> w;

        char s[h][w];
        ll yoko_dp[h][w];
        ll tate_dp[h][w];
        rep(i, h) rep(j, w) {
                cin >> s[i][j];
                yoko_dp[i][j] = 0;
                tate_dp[i][j] = 0;
            }

        rep(i, h) rep(j, w) {
                if (s[i][j] == '#') continue;
                if (j == 0) yoko_dp[i][j] = 1;
                else yoko_dp[i][j] = yoko_dp[i][j - 1] + 1;
            }
        rep(i, w) rep(j, h) {
                if (s[j][i] == '#') continue;
                if (j == 0) tate_dp[j][i] = 1;
                else tate_dp[j][i] = tate_dp[j - 1][i] + 1;
            }

        ll yoko_max[h][w];
        repr(i, h) repr(j, w) {
                if (s[i][j] == '#') yoko_max[i][j] = 0;
                else {
                    if (j == w - 1 || yoko_dp[i][j + 1] == 0) yoko_max[i][j] = yoko_dp[i][j];
                    else yoko_max[i][j] = yoko_max[i][j + 1];
                }
            }
        ll tate_max[h][w];
        repr(i, w) repr(j, h) {
                if (s[j][i] == '#') tate_max[j][i] = 0;
                else {
                    if (j == h - 1 || tate_dp[j + 1][i] == 0) tate_max[j][i] = tate_dp[j][i];
                    else tate_max[j][i] = tate_max[j + 1][i];
                }
            }

        ll ans = 0;
        rep(i, h) rep(j, w) {
                if (s[i][j] == '#') continue;
                ans = max(ans, tate_max[i][j] + yoko_max[i][j] - 1);
            }
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

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

  int ans = n;
  for(int i = 0; i <= n; i++){
    int c = 0, t = i;
    while(t > 0){ 
      c += t % 6; 
      t /= 6;
    }

    t = n - i;
    while(t > 0){
      c += t % 9; 
      t /= 9;
    }

    ans = min(ans, c);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

vector<ll> G[100001];
vector<ll> bw(100001,-1);

int main(){	
	long long N;
	scanf("%lld",&N);
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		ll a,b;
		scanf("%lld",&a);
		--a;
		scanf("%lld",&b);
		--b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	queue<P> que;
	que.push(P(0, 0));
	que.push(P(N-1, 1));
	while(!que.empty()) {
		ll f = que.front().first, s = que.front().second;
		if (bw[f] == -1) bw[f] = s;
		for (auto x : G[f]) {
			// cout << f << " " << s << " " << x << endl;
			if (bw[x] == -1) que.push(P(x, s));
		}
		que.pop();
	}
	ll bc = 0;
	rep(i, N) {
		// cout << bw[i];
		if (bw[i] == 0) bc++;
	}
	// cout << endl;
	if (bc > N/2) cout << "Fennec" << endl; else cout << "Snuke" << endl;
	return 0;
}



Measured memory_bytes: 7552
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;

const int maxn = 300005;
int a[maxn], pre[maxn], n, last;

void GG() {
	puts("No");
	exit(0);
}

void solve(int l, int r) {
	if (l == r) return;
	if ((r - l) & 1) GG();
	for (int i = l + 1; i <= r - 1; i += 2)
		if (a[i] != i) GG();
	int mx = 0, mn = 0;
	for (int i = l; i <= r; i += 2)
		if (a[i] < i) {
			if (a[i] < mx) GG();
			mx = a[i];
		}
		else {
			if (a[i] < mn) GG();
			mn = a[i];
		}
}

int main() {
	scanf("%d", &n);
	rep (i, 1, n) {
		scanf("%d", &a[i]);
		pre[i] = max(pre[i-1], a[i]);
		if (i == pre[i]) {
			solve(last + 1, i);
			last = i;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;

int main()
{	
	double d, t, s;
	while(cin >> d >> t >> s){
		if(d/t < s || (d/t - s) < 1e-6)
			cout << "Yes\n";

		else
		{
			cout << "No\n";
		}
		
	}
	
	return 0;
}


Measured memory_bytes: 3648
x, y = gets.split.map(&:to_i)
ary = [4, 6, 9, 11]
ary2 = [1, 3, 5, 7, 8, 10, 12]

if ary.include?(x) && ary.include?(y) || ary2.include?(x) && ary2.include?(y)
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14216
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <utility>
#include <algorithm>
using std::cin;
using std::cout;
using std::endl;

int main(void)
{
    int N;
    int m1;
    long long min_two = 1000000000;
    long long max_two = 0;
    long long two_count = 0;
    int temp = 0;
    bool has_even = false;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        bool is_even = false;
        scanf("%d", &m1);
        temp = 0;
        while (1)
        {

            if (m1 % 2 == 0)
            {
                temp++;
                m1 /= 2;
                is_even = true;
                two_count++;
            }
            else
                break;
        }
        if (is_even&&min_two > temp)
        {
            min_two = temp;
            has_even = true;
        }
        if(is_even&&max_two<temp)
        {
            max_two = temp;
            has_even = true;
        }
    }

    if (has_even)
        cout << two_count<< endl;
    else
        cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c - '0';}


// TODO: write
int main() { 
  ll n,k;cin>>n>>k;
  vector<ll> a(n);rep(i,n)cin>>a[i];
  sort(all(a));
  ll ans = 0;
  rep(i,n-k)ans += a[i];
  print(ans);
  return 0;
}

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

int main(){
	long long n,p,q,a,b;
	cin >> n;
	for(long long i = 1;i <= 3500;i++){
		for(long long j = 1;j <= i;j++){
			a = i,b = j;
			p = 4 * a * b - n * a - n * b;
			q = n * a * b;
			if(p > 0 && q % p == 0){
				cout << i << ' ' << j << ' ' << q / p;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int nm = 1e5;
int n, a[nm], b[nm];
long long s = 0, c;
int main() {
	cin >> n;
	c = (long long) n * (n + 1) / 2;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}
	if (s % c) {
		cout << "NO" << endl;
		return 0;
	}
	for (int i = 0; i < n; i++)
		b[i] = a[(i + 1) % n] - a[i] - s / c;
	for (int i = 0; i < n; i++)
		if (b[i] > 0 || b[i] % n) {
			cout << "NO" << endl;
			return 0;
		}
	cout << "YES" << endl;
}

Measured memory_bytes: 1024
n = int(input())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


li = make_divisors(n)

ans = float("inf")

for i in li:
    x = n // i
    ans = min(ans, max(len(str(i)), len(str(x))))

print(ans)

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

int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n;
cin>>n;
vector <int> W(n),B,A,S,D;
for(auto &e:W)cin>>e;
int t=1;
while(t<n){
    for(int i=0;i<n;i++){
        if(i<t){B.emplace_back(W[i]);}
        else{A.emplace_back(W[i]);}
    }
    int s=accumulate(B.begin(),B.end(),0);
    int s1=accumulate(A.begin(),A.end(),0);
    S.emplace_back(abs(s-s1));
    B.clear();
    A.clear();
    t++;
}
cout<<*min_element(S.begin(),S.end()) <<"\n";
}

Measured memory_bytes: 3612
n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
on = [0] * n
#print(s)
ans = 0
for i in range(2**n):
    for j in range(n):
        on[j] = i%2
        i = i >> 1
        #print(i)
    #print(on)
    c = 0
    for j in range(m):
        wa = sum([on[x] for x in range(n) if (x+1) in s[j][1:]])
        if wa%2 == p[j]:
            c += 1

    if c == m:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
int main()
{
	char s[100005];
	int l,flag;
	scanf ("%s",&s);
	l = strlen(s);
	flag = 0;
	for (int i = l-1;i >= 0 ;i--)
	 {
	 	if (s[i] != s[i-1])
	 	 flag++;
	 }
    printf ("%d\n",flag-1);
	
return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int count = 0;
		int temp = N;
		int ans = 0;
		
		while(temp > 0) {
			temp /= 10;
			count++;
		}
		
		for(int i = 1; i <= count; i++) {
			if(i == count) {
				if(i%2 == 1) {
					ans += (N-Math.pow(10, i-1)+1);
				}
			}
			else {
				if(i == 1) {
					ans += 9;
				}
				else if(i%2 == 1) {
					ans += (Math.pow(10, i)-Math.pow(10, i-1));
				}
			}
		}
		
		System.out.println(ans);

	}

}

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

vector<int> TL, TR, p;
vector<long> v;

void in(long k) {
	if (k == -1)
		return;
	else {
		in(TL[k]);
		cout << " " << v[k];
		in(TR[k]);
		return;
	}
}

void pre(long k) {
	if (k == -1)
		return;
	else {
		cout << " " << v[k];
		pre(TL[k]);
		pre(TR[k]);
		return;
	}
}

int main()
{
	string s;
	long n = 0, t = 0;

	cin >> n;

	TL.assign(n, -1);
	TR.assign(n, -1);
	p.assign(n, -1);
	v.assign(n, -2000000001);

	for (long i = 0; i < n; i++) {
		cin >> s;

		if (s == "insert") {
			cin >> v[t];

			long y = -1, x = 0;

			while (x != -1) {
				y = x;
				if (v[t] < v[x])
					x = TL[x];
				else
					x = TR[x];
			}

			if (i > 0 && y != -1) {
				if (v[t] < v[y])
					TL[y] = t;
				else
					TR[y] = t;
				p[t] = y;
			}
			t++;
		}
		else if (s == "print") {
			in(0);
			cout << endl;
			pre(0);
			cout << endl;
		}
		else if (s == "find") {
			long w = 0, x = 0;
			cin >> w;
			
			while (x != -1) {
				if (w == v[x])
					break;
				else if (w < v[x])
					x = TL[x];
				else
					x = TR[x];
			}

			if(x != -1)
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
		else if (s == "delete") {
			long w = 0, x = 0;
			cin >> w;

			while (x != -1) {
				if (w == v[x])
					break;
				else if (w < v[x])
					x = TL[x];
				else
					x = TR[x];
			}

			if (TL[x] == -1 && TR[x] == -1) {
				if (TL[p[x]] == x)
					TL[p[x]] = -1;
				else
					TR[p[x]] = -1;
			}
			else if (TL[x] != -1 && TR[x] != -1) {
				int q = TR[x];

				while (TL[q] != -1)
					q = TL[q];

				v[x] = v[q];

				if (TL[q] == -1 && TR[q] == -1) {
					if (TL[p[q]] == q)
						TL[p[q]] = -1;
					else
						TR[p[q]] = -1;
				}
				else {
					if (TL[q] != -1) {
						p[TL[q]] = p[q];
						if (TL[p[q]] == q)
							TL[p[q]] = TL[q];
						else
							TR[p[q]] = TL[q];
					}
					else if (TR[q] != -1) {
						p[TR[q]] = p[q];
						if (TL[p[q]] == q)
							TL[p[q]] = TR[q];
						else
							TR[p[q]] = TR[q];
					}
				}
			}
			else {
				if (TL[x] != -1) {
					p[TL[x]] = p[x];
					if(TL[p[x]] == x)
						TL[p[x]] = TL[x];
					else
						TR[p[x]] = TL[x];
				}
				else if (TR[x] != -1) {
					p[TR[x]] = p[x];
					if(TL[p[x]] == x)
						TL[p[x]] = TR[x];
					else
						TR[p[x]] = TR[x];
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 12472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C;
    cin >> A >> B >> C;
    cout << C << " " << A << " " << B << "\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int N,M,X;
  int r=0,l=0;
  cin >> N >> M >> X;

  for( int i=0;i<M;i++ )
    {
      int a;
      cin >> a;
      if(a<X)
	l++;
      else
	r++;
    }
  cout << min(l,r) << endl;
}


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i] >> B[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    ll ans = 0;
    if ( N % 2 == 1 ) {
        ans = B[N/2] - A[N/2] + 1;
    } else {
        ll a = A[N/2-1] + A[N/2];
        ll b = B[N/2-1] + B[N/2];
        ans = b - a + 1;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
inline int Ask(string S){
	cout << '?' << ' ' << S << '\n';
	fflush(stdout);
	int x; cin >> x;
	return x;
}
inline void Report(string S){
	cout << "! " << S << '\n';
	fflush(stdout);
	exit(0);
}
struct Data{
	string st;
	Data (string strr = ""){ st = strr; }
	inline bool operator < (Data w) const{ return st.length() > w.st.length(); }
};
string s,s1,s2,t;
priority_queue<Data>H; int suml;
int main(){
	int i,j,k; char c;
	for (c = '0'; c <= '9'; ++c){
		for (s.resize(128),i = 0; i < 128; ++i) s[i] = c;
		for (s.resize(128 - Ask(s)),i = 0; i < s.size(); ++i) s[i] = c;
		if (s.size()) H.push(Data(s)),suml += s.size();
	}
	for (c = 'a'; c <= 'z'; ++c){
		for (s.resize(128),i = 0; i < 128; ++i) s[i] = c;
		for (s.resize(128 - Ask(s)),i = 0; i < s.size(); ++i) s[i] = c;
		if (s.size()) H.push(Data(s)),suml += s.size();
	}
	for (c = 'A'; c <= 'Z'; ++c){
		for (s.resize(128),i = 0; i < 128; ++i) s[i] = c;
		for (s.resize(128 - Ask(s)),i = 0; i < s.size(); ++i) s[i] = c;
		if (s.size()) H.push(Data(s)),suml += s.size();
	}
	while (H.size() > 1){
		s1 = H.top().st,H.pop(),s2 = H.top().st,H.pop();
		s.resize(0);
		for (i = j = 0; i < s1.size(); ++i){
			t.resize(0);
			for (k = i; k < s1.size(); ++k) t.push_back(s1[k]);
			while (j < s2.size() && Ask(s+s2[j]+t) == suml-1-s.size()-t.size()) s.push_back(s2[j]),++j;
			s.push_back(s1[i]);
		}
		while (j < s2.size()) s.push_back(s2[j]),++j;
		H.push(Data(s));
	}
	if (!suml) Report("");
	Report(H.top().st);
	return 0;
}

Measured memory_bytes: 3800
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,i,j;
	cin>>n;
	ll a[n+1];
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	ll ans=a[n/2]-a[n/2-1];
	cout<<ans;
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
#define fore(i,ii,iii)for(int i=ii;i<iii;i++)
#define rfor(i,ii,iii)for(int i=iii-1;i>=ii;i--)
#define all(s) s.begin(),s.end()
#define sz(a) ((int)a.size())
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
#define fst first
#define snd second

const ll N=1e5+15;
int n,x,y;
vector<int>g[N],ch[N];
ll MOD;
ll s[N],d[N],r[N];

struct STree { // [cerrado-abierto)
	vector<ll> st;int n;
	STree(int n): st(4*n+5,1), n(n) {}
	void upd(int k, int s, int e, int p, ll v){
		if(s+1==e){st[k]=v;return;}
		int m=(s+e)/2;
		if(p<m)upd(2*k,s,m,p,v);
		else upd(2*k+1,m,e,p,v);
		st[k]=(st[2*k]*st[2*k+1])%MOD;
	}
	ll query(int k, int s, int e, int a, int b){
		if(s>=b||e<=a)return 1;
		if(s>=a&&e<=b)return st[k];
		int m=(s+e)/2;
		return (query(2*k,s,m,a,b)*query(2*k+1,m,e,a,b))%MOD;
	}
	void upd(int p, ll v){upd(1,0,n,p,v);}
	ll query(int a, int b){return query(1,0,n,a,b);}
}; // usage: STree st(n);st.upd(i,v);st.query(s,e);

void dfs1(int v,int pa) {
  s[v]=1;
  for(int i:g[v])if(i!=pa){
    ch[v].pb(i);
    dfs1(i,v);
    s[v]=(s[v]*(s[i]+1))%MOD;
  }
}

void dfs2(int v,int pa) {
  //cout<<"view "<<v<<" "<<pa<<" "<<d[v]<<endl;
  STree st(ch[v].size());
  fore(i,0,ch[v].size())st.upd(i,s[ch[v][i]]+1);
  fore(i,0,ch[v].size()) {
    ll a=st.query(0,i);
    ll b=st.query(i+1,ch[v].size());
    d[ch[v][i]]=((((d[v]+1)*a)%MOD)*b)%MOD;
    //cout<<v<<" : "<<ch[v][i]<<" "<<a<<" "<<b<<" "<<d[ch[v][i]]<<endl;
    dfs2(ch[v][i],v);
  }
  if(v) {
    //cout<<"r["<<v<<"]="<<d[v]<<" "<<st.query(0,ch[v].size())<<endl;
    r[v]=((d[v]+1)*st.query(0,ch[v].size()))%MOD;
  }
  else r[v]=s[v];
}

int main() {
  scanf("%d %lld",&n, &MOD);
  fore(i,0,n-1) {
    scanf("%d %d", &x, &y);x--,y--;
    g[x].pb(y);
    g[y].pb(x);
  }
  dfs1(0,-1);
  d[0]=0;
  dfs2(0,-1);
  //cout<<"s: ";fore(i,0,n)cout<<s[i]<<" ";cout<<endl;
  //cout<<"d: ";fore(i,0,n)cout<<d[i]<<" ";cout<<endl;
  //cout<<"r: ";fore(i,0,n)cout<<r[i]<<" ";cout<<endl;
  fore(i,0,n)printf("%lld\n",r[i]);
}

Measured memory_bytes: 36992
#include <stdio.h>

int main(){
	int a ,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a > b ){
		if(a < c){
		printf("C\n");
		}
		else {
		printf("A\n");
		}
		}

	else{
		if(b < c){
		printf("C\n");
		}
		else{
		printf("B\n");
		}
	}		
return 0;
}


Measured memory_bytes: 2064
//In the name of 'Allah'
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a , sum ;
    double b ;
    cin >> a >> b;
    sum = b*100+0.1;
    cout << (a*sum )/100 <<endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector <int> H(n);
	for (int i = 0; i < n; i++)  cin >> H[i];

	if (n == 1) { 
		cout << "Yes" << endl; 
		return 0;
	}

	int d = H[0];
	bool flag = true;
	for (int i = 1; i < n; i++) {
		if (d > H[i]) {
			if (d - H[i] >= 2) {
				flag = false;
				break;
			}
		}
		d = max(d, H[i]);
	}
	if (flag) cout << "Yes" << endl;
	else  cout << "No" << endl;
}

Measured memory_bytes: 768
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n)cin >> a[i];
	int now = a[0];
	int ans = 1;
	rep(i, n) {
		if (i == 0)continue;
		if (now <= a[i]) {
			ans++;
			now = a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// 深さ優先探索
package main

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

func genid(a, b int) int {
	if b < a {
		a, b = b, a
	}
	return a*100000 + b
}

func main() {
	N := readInt()

	ab := make([][2]int, N-1)
	edges := make([][]int, N)
	for i := 0; i < N-1; i++ {
		a := readInt() - 1
		b := readInt() - 1
		ab[i][0], ab[i][1] = a, b
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}

	colors := make(map[int]int)
	q := make([][]int, 0)
	q = append(q, []int{0, -1, -1})
	for len(q) != 0 {
		currentNode, usedColor, parentNode := q[0][0], q[0][1], q[0][2]
		q = q[1:]
		color := 1
		for _, childNode := range edges[currentNode] {
			if childNode == parentNode {
				continue
			}
			if color == usedColor {
				color++
			}
			colors[genid(currentNode, childNode)] = color
			q = append(q, []int{childNode, color, currentNode})
			color++
		}
	}

	K := -1
	for i := 0; i < N; i++ {
		t := len(edges[i])
		if t > K {
			K = t
		}
	}
	fmt.Println(K)

	for i := 0; i < N-1; i++ {
		fmt.Println(colors[genid(ab[i][0], ab[i][1])])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

int N;
string S;

int main(){
	cin >> N >> S;

	for(int i = 0; i < S.size(); i++){
		int c = S[i] - 'A';
		c = (c+N)%26;
		S[i] = c + 'A';
	}
	cout << S << endl;

	return 0;
}


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

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int n = Integer.parseInt(chr[0]);
			int m = Integer.parseInt(chr[1]);
			 System.out.println(n==m? "Yes" : "No");
		}
	}
}

Measured memory_bytes: 25360
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

char buf[2000];
string ope;
int pos, size;

void print(){
  //cout << "\"";
  for(int i=0;i<=size;i++){
    if(pos == i) cout << "^";
    if(i >= size) break;
    cout << buf[i];
  }
  //cout << "\"";
  cout << endl;
}

void forwardWord(){
  for(;pos<size;pos++){
    if(buf[pos] != ' '){
      for(;pos<size;pos++) if(buf[pos] == ' ') break;
      return;
    }
  }
}

void backwardWord(){
  if(pos == 0) return;
  for(pos=pos-1;pos>0;pos--){
    if(buf[pos] != ' '){
      for(;pos>0;pos--) if(buf[pos-1] == ' ') break;
      return;
    }
  }
}

void insert(string str){
  if(pos == size){
    for(int i=0;i<str.size();i++) buf[pos+i] = str[i];
  }else{
    for(int i=size-1;i>=0;i--){
      buf[i+str.size()] = buf[i];
      if(i == pos) break;
    }
    for(int j=0;j<str.size();j++) buf[pos+j] = str[j];
  }
  pos += str.size();
  size += str.size();
}

void deleteChar(){
  if(pos == size) return;
  for(int i=pos+1;i<size;i++) buf[i-1] = buf[i];
  size--;
}

void deleteWord(){
  bool f = false;
  int i;
  for(i=pos;i<size;i++){
    if(buf[i] != ' '){
      f = true;
      break;
    }
  }
  if(!f) return;  
  for(;i<size;i++){
    if(buf[i] == ' ') break;
  }

  int j = pos;
  for(int k=i;k<size;k++){
    buf[j++] = buf[k];
  }
  size -= i - pos;
}

main(){
  int tc, n;
  cin >> tc;
  getchar();
  while(tc--){
    pos = size = 0;
    getline(cin, ope);
    insert(ope);
    pos = 0;
    cin >> n;
    getchar();
    for(int i=0;i<n;i++){
      getline(cin, ope);
      if(ope == "forward char" && pos + 1 < size) pos++;
      else if(ope == "forward word") forwardWord();
      else if(ope == "backward char" && pos) pos--;
      else if(ope == "backward word") backwardWord();
      else if(ope.substr(0, 6) == "insert"){
        insert(ope.substr(8, (int)ope.size()-9));
      }else if(ope == "delete char") deleteChar();
      else if(ope == "delete word") deleteWord();
      //print();
    }
    print();
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1");
            WillReturn.Add("2");
            WillReturn.Add("4");
            WillReturn.Add("8");
            WillReturn.Add("9");
            WillReturn.Add("15");
            //Yay!
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("15");
            WillReturn.Add("18");
            WillReturn.Add("26");
            WillReturn.Add("35");
            WillReturn.Add("36");
            WillReturn.Add("18");
            //:(
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int a = int.Parse(InputList[0]);
        int b = int.Parse(InputList[1]);
        int c = int.Parse(InputList[2]);
        int d = int.Parse(InputList[3]);
        int e = int.Parse(InputList[4]);
        int k = int.Parse(InputList[5]);

        int diff = e - a;
        if (diff <= k) Console.WriteLine("Yay!");
        else Console.WriteLine(":(");
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 200005;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;
ll bit[MAXN + 1];
void update (int pos, int val)
{
	while (pos <= MAXN)
	{
		bit[pos] += val % MOD;
		bit[pos] %= MOD;
		pos += (pos & -pos);
	}
}
int query(int pos)
{
	ll ans = 0;
	while (pos > 0)
	{
		ans += bit[pos] % MOD;
		ans %= MOD;
		pos -= (pos & -pos);
	}
	return ans;
}
void getac(int T) {
	int n, k;
	cin >> n >> k;
	vector < pii > q;
	for (int i = 0; i < k; i++) {
		int l, r;
		cin >> l >> r;
		q.pb({l, r});
	}
	ll dp[n + 1];
	for (int i = 0; i <= n; i++) {
		dp[i] = 0;
	}
	dp[0] = 0;
	dp[1] = 1;
	update(1, 1);
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			int l = q[j].first;
			int r = q[j].second;
			l = max(i - l, 0);
			r = max(i - r - 1, 0);
			//cout << j << ' ' << l << ' ' << r << '\n';
			dp[i] += query(l);
			dp[i] -= query(r);
			dp[i] += MOD;
			dp[i] %= MOD;

		}
		update(i, dp[i]);
		//cout << '\n';
	}
	cout << dp[n] << '\n';

}
int  main()
{

	fastio;
	int t = 1;
	if (takeTestCases) { cin >> t; }
	int t_t = 1;
	while (t--) {
		if (printCaseNo)
		case (t_t);
		getac(t_t);
		t_t++;
	}
	cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
	return 0;
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

bitset<55560> prime;

int main(){

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    for(int i = 2; i <= 55555; ++i){
        if(prime[i]) continue;
        for(int j = i + i; j <= 55555; j += i)
            prime[j] = 1;
    }

    for(int i = 55555; i > 0 && n > 1; --i){
        if(prime[i] || (i - 1) % 10 != 0) continue;
        n--;
        cout << i << " ";
    }

    cout << 2;

    return 0;
}


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

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

	int ans = 0;
	vector<int> p(n);
	if(l + 1 - 1 > 0) {
		for(int i = 1; i < n; i++) ans += l + (i + 1) - 1;
	}
	else if(l + n - 1 < 0) {
		for(int i = 0; i < n - 1; i++) ans += l + (i + 1) - 1;
	}
	else {
		for(int i = 0; i < n; i++) ans += l + (i + 1) - 1;
	}

	cout << ans << endl;

	return 0;
}

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

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      foreach (int i in Enumerable.Range(1, 9))
      {
        foreach (int j in Enumerable.Range(1, 9))
        {
          Console.WriteLine(i + "x" + j + "=" + i * j);
        }
      }
    }
  }
}

Measured memory_bytes: 9264
package main

import "fmt"

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+2)
	a[0] = 0
	for i := 1; i < n+1; i++ {
		fmt.Scan(&a[i])
	}
	a[n+1] = 0

	sum := 0
	for i := 0; i < n+1; i++ {
		sum += abs(a[i+1] - a[i])
	}

	for i := 1; i < n+1; i++ {
		ans := sum - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1])
		fmt.Println(ans)
	}
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;

int n;

vector<pair<double,double>> v;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    v.resize(n);
    for (int i=0; i<n; i++) {
	cin>>v[i].first>>v[i].second;
    }

    sort(v.begin(),v.end(),[&](pair<double,double> p, pair<double,double> q) {
	    return atan2(p.second,p.first) < atan2(q.second,q.first);
	});


    double res = 0;
    for (int i=0; i<n; i++) {
	double dx = 0;
	double dy = 0;
	for (int j=i; j<2*n && j-i<n; j++) {
	    dx += v[j%n].first;
	    dy += v[j%n].second;
	    double cur = sqrt(dx*dx + dy*dy);
	    res = max(res, cur);
	}
    }

    cout<<fixed<<setprecision(12)<<res<<endl;    
    return 0;
}


Measured memory_bytes: 4180
# Aizu Problem 0278: Admission Fee

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


N = int(input())
for k in range(N):
    x, y, b, p = [int(_) for _ in input().split()]
    print(min(x * b + y * p, (x * max(b, 5) + y * max(p, 2)) * 8 // 10))

Measured memory_bytes: 8240
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const long long INF = 1LL << 60;

int main() {
  int N, M; cin>>N>>M;
  vector<vector<ll>> students(N, vector<ll>(2));
  vector<vector<ll>> check(M, vector<ll>(2));
  for(int i=0; i<N; i++){
    ll a, b; cin>>a>>b;
    students[i][0]=a;
    students[i][1]=b;
  }
  for(int i=0; i<M; i++){
    ll a, b; cin>>a>>b;
    check[i][0]=a;
    check[i][1]=b;
  }
  for(int i=0; i<N; i++){
    ll min=INF;
    int ans=0;
    for(int j=0; j<M; j++){
      ll man=abs(students[i][0]-check[j][0])+abs(students[i][1]-check[j][1]);
      // cout<<Man<<endl;
      if(man<min){
        ans=j+1;
        min=man;
      }
    }
    cout<<ans<<endl;
  } //i;
}


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

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void*)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

#ifndef CODE_
#include "f:/kyopro/code.c"
#define CODE_
#endif

static inline f64 const coordinate_area(i64 const n,f64 const *x,f64 const *y){
    f64 ret=0LL;
    for(i64 i=1LL;i<n;++i) ret+=x[i-1LL]*y[i]-x[i]*y[i-1LL];
    ret+=x[n-1LL]*y[0LL]-x[0LL]*y[n-1LL];
    return fabs(ret)/2.0;
}

i32 main(void){
    i64 n;
    scanf("%lli",&n);
    f64 *x=(f64 *)calloc(n,sizeof(f64));
    f64 *y=(f64 *)calloc(n,sizeof(f64));
    for(i64 i=0LL;i<n;++i) scanf("%lf%lf",&x[i],&y[i]);
    printf("%.1f\n",coordinate_area(n,x,y));
    return 0;
}



Measured memory_bytes: 2108
#include <stdio.h>

int main(void) {
	int n,sum,j,i,s,max,min;
	max = -1;
	min = 1001;
	sum = 0;

	while(1){
		scanf("%d\n",&n);
		if(n == 0)
			break;
		for(i=0;i<n;i++){
			scanf("%d\n",&s);
			if(max < s) max = s;
			if(min > s) min = s;
			sum += s;
		}	
		printf("%d\n",(sum-max-min)/(n-2));
		max = -1;
		min = 1001;
		sum = 0;
		
	}
	
	return 0;
}



Measured memory_bytes: 2036
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int x[5];

int main() {
    rep(i,5) {
        cin >> x[i];
        if (x[i] == 0) {
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3592
new Promise(function(resolve, reject) {
    let cin = "";
    process.stdin.on("data", chunk => { cin += chunk; });
    process.stdin.on("end", () => { resolve([cin, process.stdout]); });
}).then(function([cin, cout]) {
    const [[N, W], ...d] = cin.split("\n").map(elt => elt.split(" ").map(e => parseInt(e)));
    const opt = new Array(W + 1).fill(0);
    for (const [v, w] of d.slice(0, N)) {
        for (let i = W; i >= w; --i) {
            opt[i] = Math.max(opt[i], opt[i - w] + v);
        }
    }
    cout.write(`${opt[W]}\n`);
});



Measured memory_bytes: 16548
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	ll N;

	ll pow(int a, int b) {
		if (b == 0) return 1;
		if (b % 2) return a*pow(a, b - 1);
		ll tmp = pow(a, b / 2);
		return tmp*tmp;
	}

	void ans() {
		cin >> N;
		int keta = 0;
		int top;
		ll copy = N;
		while (copy) {
			keta++;
			top = copy % 10;
			copy /= 10;
		}
		int res;
		ll n = (top + 1)*pow(10, keta - 1) - 1;
		if (n == N) res = top + 9 * (keta - 1);
		else res = top - 1 + 9 * (keta - 1);
		cout << res << "\n";
	}

};



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   int a,p;
   cin >> a >> p;
   cout << (a*3+p)/2 << endl;
 }

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
    double a[1010];
    int n;
    double m=0;
    double ans=0;
    int i;
    while(scanf("%d",&n),n!=0){
        m=0;
        ans=0;
        for(i=0;i<n;i++){
            scanf("%lf",&a[i]);
            m+=a[i];
        }
        m/=(double)n;
        for(i=0;i<n;i++){
            ans+=pow(a[i]-m,2.0);
        }
        ans/=(double)n;
        printf("%lf\n",sqrt(ans));
    }
    return 0;
}


Measured memory_bytes: 2036
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
#include<stack>
#include<queue>
using namespace std;

typedef long long ll;

int gcd(int x, int y) {
	return y ? gcd(y, x % y) : x;
}

int main(){
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	return 0;
}


Measured memory_bytes: 3088
#ABC119
S =  input()
split = S.split("/")
if int(split[0]) >= 2020:
    print("TBD")
elif int(split[0]) < 2019:
    print("Heisei")
else:
    if int(split[1]) < 5:
        print("Heisei")
    else:
        print("TBD")
    

Measured memory_bytes: 2940
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 3000+1;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}

ll dp[Max+2][Max+2][4];
ll ara[Max+2][Max+2];

ll n,m;

ll call(ll i,ll j,ll cnt)
{
   // if(i==1 && j==2 || (i==2 && j==1))

  // cout<<i<<" "<<j<<" "<<cnt<<" "<<val<<endl;
    if(i>n || j>m )
        return 0;

        ll &ret=dp[i][j][cnt];


        if(~ret)return ret;

        ret=0;

        if(cnt==3)
        {
            ret=max(call(i+1,j,0),call(i,j+1,cnt));
        }
        else
        {
            if(ara[i][j])
            {
ret=max3(ara[i][j]+call(i,j+1,cnt+1),call(i,j+1,cnt),ara[i][j]+call(i+1,j,0));
            }
            else{

            ret=max(call(i+1,j,0),call(i,j+1,cnt));
            }
        }

        return ret;

}
int main()
{

    fastread();

    ll i,j,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

    bool flag=false;

    string str;

    cin>>n>>m>>k;

    while(k--)
    {
        cin>>a>>b>>c;

        ara[a][b]=c;
    }
    memset(dp,-1,sizeof(dp));

    cout<<call(1,1,0)<<endl;






}



Measured memory_bytes: 356324
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;

long long MOD = 1e9 + 7;

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

    int k, x;
    cin >> k >> x;

    int b = std::max(x - k + 1, -1000000);
    int e = std::min(x + k - 1, 1000000);
    for (int i = b; i < e; i++)
    {
        cout << i << " ";
    }
    cout << e << endl;

    return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    set<char> st;

    rep(i, n) {
        char c;
        cin >> c;
        st.insert(c);
    }

    if (st.size() == 4) cout << "Four" << endl;
    else cout << "Three" << endl;


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef unsigned long long ull;
int b=67280421310721,n,a,c;//21387612863821
ull ans;
map<ull,ull>m;
vector<int>v[100009];
ull dfs(int x){
  ull res=1;
  r(i,v[x].size()) res+=dfs(v[x][i]);
  res*=b;
  ans+=m[res]++;
  return res;
}
signed main(){
  cin>>n;
  r(i,n-1){
    cin>>a>>c;
    v[a].push_back(c);
  }
  dfs(1);
  cout<<ans<<endl;
}


Measured memory_bytes: 21132
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  char c;
  cin >> c;
  cout << ++c << endl;
}


Measured memory_bytes: 3572