akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  string s; cin >> s;
  s.pop_back();
  s.pop_back();

  int ans = 0;
  while(!s.empty()) {
    int i = LEN(s) / 2;
    if (s.substr(0, i) == s.substr(i, i)) {
      ans = LEN(s);
      break;
    }
    s.pop_back();
    s.pop_back();
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
constexpr int dy[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b;
  cin >> n >> a >> b;
  if (a % 2 == b % 2) {
    cout << (b - a) / 2 << endl;
  }
  else {
    ll ans = min(a - 1 + 1 + (b - a - 1) / 2, (n - b) + 1 + (b - a - 1) / 2);
    cout << ans << endl;
  }
}


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

long long n;
vector<int> ans;

int main() {

  int mx=100,mn=1;
  scanf("%lld",&n);
  while(n) {
    if(!(n&1)) {
      n--;
      ans.push_back(mx--);
    }
    n--;
    n/=2;
    ans.push_back(mn++);
  }
  for(int i=1;i<=100;i++) ans.push_back(i);
  printf("%d\n",ans.size());
  for(int i=0;i<ans.size();i++) {
    printf("%d ",ans[i]);
  }

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val S = readString()
  println(if (S == "ABC") "ARC" else "ABC")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 34532
import math
from bisect import bisect_left

def C(a,b):
    return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

n = int(input())
a = sorted(list(map(int, input().split())))

A = a.pop(-1)
if A//2 in a:
    print(A, A//2)
elif A % 2 != 0 and A//2 + 1 in a:
    print(A, A//2 + 1)
else:
    x = A//2
    temp = bisect_left(a, x)
    if temp == 0:
        print(A, a[0])
    elif temp == len(a):
        print(A, a[-1])
    else:
        print(A, a[sorted([temp, temp - 1], key = lambda y: abs(x - a[y]))[0]])

Measured memory_bytes: 14432
from collections import defaultdict
from sys import stdin
input = stdin.readline


def prime_fatorization(n):
  # O(sqrt(n))
  # a = []
  a = defaultdict(int)
  while not(n % 2):
    # a.append(2)
    a[2] += 1
    n //= 2
  f = 3
  while f * f <= n:
    if not(n % f):
      # a.append(f)
      a[f] += 1
      n //= f
    else:
      f += 2
  if n != 1:
    # a.append(n)
    a[n] += 1
  return a


def main():
  A, B = list(map(int, input().split()))

  aprime = prime_fatorization(A)
  bprime = prime_fatorization(B)

  aset = set()
  bset = set()

  for ap in aprime.keys():
    aset.add(ap)

  for bp in bprime.keys():
    bset.add(bp)

  print(1+len(aset & bset))


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 66028
#include<stdio.h>
int main(void){
	int n[200];
	int N;
	//入力部
	scanf("%d",&N);
	for(int i = 0;i<N;i++){
		scanf("%d",&n[i]);
	}
	int check=0;
	int sum=0;
	//探索部
	while(1){
		for(int i=0;i<N;i++){
			if(n[i]%2 == 1){
				check=1;
			}
			n[i]/=2;
		}
		if(check==1)break;
		sum++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> s(1<<n),used;
	multiset<int> ret;
	rep(i,1<<n){
		cin>>s[i];
		ret.insert(s[i]);
	}
	sort(begin(s),end(s)); 
	auto itr=ret.end();
	itr--;
	used.push_back(*itr);
	ret.erase(itr);
	//cout<<used<<endl;
	rep(i,n){
		vector<int> nused(used);
		for(auto v:used){
			if(ret.empty()) break;
			auto itr=ret.lower_bound(v);
			if(itr==ret.begin()){
				cout<<"No"<<endl;
				return 0;
			}
			itr--;
			nused.push_back(*itr);
			ret.erase(itr);
		}/*
		for(auto itr:ret){
			cout<<itr<<' ';
		}
		cout<<endl;*/
		//cout<<used<<endl;
		swap(used,nused);
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 15220
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using  P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, n){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double sum = 0;
    rep(i, n-1){
        sum = (v[i] + v[i+1]) / 2;
        v[i+1] = sum;
    }
    printf("%.7f\n", sum);
    return 0;
}


Measured memory_bytes: 760
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();
		int k = scan.nextInt();
		Arrays.sort(a);
		for(int i = 0; i < k; i++) {
			a[2] = 2 * a[2];
		}
		System.out.println(a[0] + a[1] + a[2]);
	}
}

Measured memory_bytes: 19284
#!/usr/bin python3
# -*- coding: utf-8 -*-

def subtask(sseq, pt):
    n = len(sseq)
#    for i in range(n):
    dp = [[0]*3 for _ in range(n+1)]
    for i in range(n):
        e = sseq[i]
        w = (e+2)%3
        l = (e+1)%3

        dp[i+1][w] = max(dp[i][e]+pt[w] ,dp[i][l]+pt[w])
        dp[i+1][l] = max(dp[i][e] ,dp[i][w])
        dp[i+1][e] = max(dp[i][w] ,dp[i][l])

    return max(dp[n])

def main():
    N, K = map(int, input().split())
    pt = list(map(int, input().split()))
    Sr = [[] for _ in range(K)]
    S = input()
    S = S.translate(str.maketrans('rsp','012'))

    for i, a in enumerate(S):
        Sr[i%K].append(int(a))

    ret=0
    for sq in Sr:
        ret += subtask(sq, pt)

    print(ret)
#    print(Sr)


if __name__ == '__main__':
    main()

Measured memory_bytes: 17136
#!/usr/bin/env python3
import sys
from fractions import gcd
from functools import reduce
input = lambda: sys.stdin.readline().strip()
MOD = 1000000007
def lcm(a, b):
    return a // gcd(a, b) * b
n = int(input())
A = [int(x) for x in input().split()]
x = reduce(lcm, A)
print(sum(x // ai for ai in A) % MOD)


Measured memory_bytes: 6140
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int N;

void Solve(const int len, const string &str, const char maxChar)
{
    if (len == N)
    {
        printf("%s\n", str.c_str());
    }
    else
    {
        for (char ch = 'a'; ch <= maxChar; ++ch)
        {
            Solve(len + 1, str + ch,
                ch == maxChar ? (char)(maxChar + 1) : maxChar);
        }
    }
}

int main()
{
    // N<=10なので，高々10種類の文字を使う→標準形はa~jのみ
    cin >> N;
    Solve(0, "", 'a');
}


Measured memory_bytes: 1536
N = int(input())
A = list(map(int, input().split()))


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


fromLeft = [0]
fromRight = [0]
for i, a in enumerate(A):
    if i == 0:
        fromLeft.append(a)
        continue
    fromLeft.append(gcd(a, fromLeft[-1]))

for i, a in enumerate(A[::-1]):
    if i == 0:
        fromRight.append(a)
        continue
    fromRight.append(gcd(a, fromRight[-1]))
fromRight = fromRight[::-1]

fromLeft[0] = fromRight[1]
fromRight[-1] = fromLeft[-2]

ans = 1
for i in range(N):
    gl = fromLeft[i]
    gr = fromRight[i + 1]
    ans = max(ans, gcd(gl, gr))

print(ans)


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

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    string result;
    for(int i = 0; A > 0 && B > 0; i++){
        if(C - B*i <= 0){
            result = "Yes";
            break;
        }
        if(A - D*i <= 0){
            result = "No";
            break;
        }
    }
    cout << result;
}

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

int main(){
  int t,n;

  for(int i = 0 ; i < 4 ; i++){
    cin >> t >> n;

    switch(t){
    case 1:
      cout << n*6000 << endl;
      break;
    case 2:
      cout << n*4000 << endl;
      break;
    case 3:
      cout << n*3000 << endl;
      break;
    default:
      cout << n*2000 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main() {
  int n, max = 0, sum = 0;
  int p[15];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i];
    sum += p[i];
    if(p[i] >= max) max = p[i];
  }
  sum -= max/2;
  cout << sum;
  return 0;
}
  

Measured memory_bytes: 256
import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    def update(self, i, x):
        """ 値の更新：添字i, 値x """
        self.add(i, x - self.get(i))

N, Q = MAP()
A = [a-1 for a in LIST()]

prev = [-1] * N
events = []
bit = BIT(N)
for t, a in enumerate(A):
    s = prev[a]
    if s != -1:
        events.append((t, 0, s))
    prev[a] = t

for i in range(Q):
    l, r = MAP()
    l -= 1; r -= 1
    events.append((r, 1, l, i))

events.sort(key=itemgetter(0))
ans = [0] * Q
for event in events:
    # 色の区間が来たら、点を追加
    if event[1] == 0:
        t, _, s = event
        bit.add(s, 1)
    # クエリが来たら、点の数を数える
    else:
        r, _, l, i = event
        total = r - l + 1
        # 区間全体 - この時の領域内の点の数
        ans[i] = total - bit.get(l, N)

for a in ans:
    print(a)


Measured memory_bytes: 254376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n, m;
    cin >> n >> m;
    if(n==1 && m==0){
        cout << 0 << endl;
        return 0;
    }
    int a1 = -1;
    int a2 = -1;
    int a3 = -1;

    for(int i = 0; i < m; i++){
        ll s, c;
        cin >> s >> c;
        if(s==1){
            if(a1==-1){
                a1 = c;
            }else if(a1!=-1 && a1==c){
                ;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }else if(s==2){
            if(a2==-1){
                a2 = c;
            }else if(a2!=-1 && a2==c){
                ;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }else if(s==3){
            if(a3==-1){
                a3 = c;
            }else if(a3!=-1 && a3==c){
                ;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }

    }
    int ans = 0;
    //dbg(a1);dbg(a2);dbg(a3);
    if(n==1){
        ans += a1;
        cout << ans << endl;
        return 0;
    }
    else if(n==2){
        if(a1==0){
            cout << -1 << endl;
            return 0;
        }
        if(a1==-1){a1=1;}
        if(a2==-1){a2=0;}
        ans += a1*10;
        ans += a2;
        cout << ans << endl;
        return 0;
    }
    else if(n==3){
        if(a1==0){
            cout << -1 << endl;
            return 0;
        }
        if(a1==-1){a1=1;}
        if(a2==-1){a2=0;}
        if(a3==-1){a3=0;}
        ans += a1*100;
        ans += a2*10;
        ans += a3;
        cout << ans << endl;
        return 0;
    }

    return 0;

}


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

int64_t kazoeru(string St){
	int keta = St.size();
	int cnt = 0;
	for(int i = 0;i < keta - 1;i++)
	{
		if(St.at(i) == St.at(i+1))
		{
			cnt++;
			St.at(i+1) = 'A';
		}
	}
	return cnt;
}

int main() {
	string S;
	int64_t K;
	cin >> S >> K;
	int ss = S.size();
	int64_t kai = 0;
	if(ss == 1)
	{
		kai = K / 2;
	}
	else
	{
		int k1 = kazoeru(S);
		int k2 = kazoeru(S + S);
		int k3 = kazoeru(S + S + S);
		int sa1 = k2 - k1;
		int sa2 = k3 - k2;
		if(K == 1)
		{
			kai = k1;
		}
		else if(K == 2)
		{
			kai = k2;
		}
		else if(K == 3)
		{
			kai = k3;
		}
		else
		{
			kai = k1 + (sa1 * (K / 2)) + (sa2 * ((K - 1)/2));
		}
	}
    cout << kai << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>  

using namespace std;

long long gcd(long long a, long long b) {
    if (b > a) swap(a, b);
    long long r = a % b;
    if ( r == 0 ) return b;
    return gcd(b, r);
}

long long lcm(long long a, long long b) {
    long long x = a * b;
    long long g = gcd(a, b);
    return x/g;
}

long long count(int a, int m) {
    long long n = ( a * 1 ) % m;
    long long cnt = 1;
    while(1) {
        if (n == 1) break;
        cnt++;
        n = ( a * n ) % m;
    }
    return cnt;
}

int main() {
    long long a, b, c;
    long long l, m, n;

    while(cin>>a>>l>>b>>m>>c>>n, a||b||c||l||m||n) {
        long long nx = count(a, l);
        long long ny = count(b, m);
        long long nz = count(c, n);
        long long ans = 0;
        long long tmp = lcm(nx, ny);
        ans = lcm(tmp , nz);
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <map>

using namespace std;

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

    map<int,int> mp;
    for(int i=1; i<=N; i++) {
        int tmp = i;
        for(int j=2; j<=N; j++) {
            while(tmp%j == 0) {
                tmp /= j;
                mp[j]++;
            }
        }
    }

    int cnt74 = 0;
    int cnt24 = 0;
    int cnt14 = 0;
    int cnt04 = 0;
    int cnt02 = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        int val = itr->second;
        if(val >= 74) cnt74++;
        if(val >= 24) cnt24++;
        if(val >= 14) cnt14++;
        if(val >= 04) cnt04++;
        if(val >= 02) cnt02++;
    }

    int ans = 0;
    ans += cnt74;
    ans += cnt24 * (cnt02 - 1);
    ans += cnt14 * (cnt04 - 1);
    ans += cnt04 * (cnt04 - 1) / 2 * (cnt02 - 2);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n = in();
  cout << n*n*n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
int pre[maxn];
ll num[maxn];
int Find(int x){
	if(pre[x] == x) return x;
	int ppx = Find(pre[x]);
	num[x] += num[pre[x]];
	pre[x] = ppx;
	return pre[x];
}

void join(int x,int y, ll w)
{
	int fx = Find(x);
	int fy = Find(y);
	if(fx != fy)
	{
		num[fy] = w+num[x]-num[y];
		pre[fy] = fx;
	}
}

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)&&m+n)
    {
    	for(int i = 1; i <= n; i++)
    	{
    		pre[i] = i;
    		num[i] = 0;
    	}
    	char s[10];
    	int a,b;
    	ll w;
    	while(m--)
    	{
    		scanf("%s%d%d",s,&a,&b);
    		if(s[0] == '?'){
    			int fx = Find(a);
    			int fy = Find(b);
    			if(fx!=fy) puts("UNKNOWN");
    			else
    			printf("%lld\n",num[b]-num[a]);
    		}
    		else
    		{
    			scanf("%lld",&w);
    			join(a,b,w);
    		}
    	}
    }
	return 0;
}


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

int main(){
  ios_base::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;

  if(a <= 8 && b <= 8){
    printf("Yay!\n");
  } else {
    printf(":(\n");
  }

  return 0;
}



Measured memory_bytes: 256
def solve():
    loop = int(input())
    profit = 1 - 10 ** 9

    current_min = int(input())
    for _ in range(loop-1):
        now = int(input())
        if now - current_min > profit:
            profit = now - current_min

        if current_min > now:
            current_min = now
    print(profit)


if __name__ == '__main__':
    solve()



Measured memory_bytes: 5612
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.nextLine().toCharArray();
		int len = arr.length;
		System.out.print(arr[0]);
		System.out.print(len-2);
		System.out.print(arr[len-1]);
      	System.out.println();
	}
}


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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int a = x, b = y, c = z;
    x = c;
    y = a;
    z = b;
    cout << x << " " << y << " " << z<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(int (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(int (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

int main()
{
    ll n,m,a,b,ans = 0;
    cin >> n >> m;
    vector<pair<ll, ll>> c(n);
    rep0(i, n){
        cin >> a >> b;
        c[i] = make_pair(a, b);
    }
    sort(all(c));
    rep0(i, n){
        if (c[i].second >= m) {
            ans += c[i].first * m;
            break;
        }else{
            ans += c[i].first * c[i].second;
            m -= c[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;

namespace AtCoder.ABC
{
    class QuestionA
    {
        public static void Main(string[] args)
        {
            var hw = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            var h = hw[0];
            var w = hw[1];

            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

            var ans = new List<int>();

            for(int i = 0; i < n; i++) {
                var nakami = i + 1;
                for (int j = 0; j < a[i]; j++) {
                    ans.Add(nakami);
				}
			}

            var list = new List<string>();

            for(int i = 0; i < h; i++) {
                var s = ans.GetRange(i * w, w);
                if(i % 2 == 1) {
                    s.Reverse();
				}

                for(int j = 0; j < s.Count; j++) {
                    Console.Write($"{s[j]}");
                    if(j == s.Count - 1) {
                        Console.WriteLine();
					} else {
                        Console.Write(" ");
					}
				}
			}
        }
    }
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  int N, A, B; cin >> N >> A >> B;
  cout << min(A * N, B) << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define M 100005
#define ll long long
const int mod=1e9+7;
int n;char str[M];
int cnt[30];
int main(){
	scanf("%d",&n);
	scanf("%s",str);
	ll a=1;
	for(int i=0;i<n;i++)
		cnt[str[i]-'a']++;
	for(int i=0;i<26;i++)
		if(cnt[i])a=a*(cnt[i]+1)%mod;
	printf("%lld\n",a-1);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {
	uint H, W;
	cin >> H >> W;

	vector<vector<bool>> HW(H, vector<bool>(W));
	
	for(uint i=0; i<H; i++) {
		string l;
		cin >> l;
		for(uint j=0; j<W; j++) HW[i][j] = (l[j] == '.');
	}

	ull mod = pow(10, 9) + 7;
	vector<vector<ull>> cmb(H, vector<ull>(W));

	for(uint i=0; i<H; i++) {
		for(uint j=0; j<W; j++) {
			if(HW[i][j]) {
				if(i > 0 && j > 0) {
					cmb[i][j] = (cmb[i][j-1] + cmb[i-1][j]) % mod;
				} else if(i > 0) {
					cmb[i][j] = cmb[i-1][j];
				} else if(j > 0) {
					cmb[i][j] = cmb[i][j-1];
				} else {
					cmb[i][j] = 1;
				}
			}
		}
	}

	cout << cmb[H-1][W-1] << endl;
	return 0;

}


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

using namespace std;

long double t, x;

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

    cin >> t >> x;

    long double ans = t / x;

    cout << fixed << setprecision(10) << ans;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
import math
n=int(input())

m=int(np.sqrt(n))+1

def f(i,j):
    return max(math.log10(i)+1,math.log10(j)+1)

ans=10**6
for i in range(m):
    a=i+1
    if n%a==0:
        b=int(n/a)
        ans=min(ans,int(f(a,b)))
print(ans)


Measured memory_bytes: 12424
def main():
    S = input()
    T = input()
    s_to_t_dct = dict()
    t_to_s_dct = dict()

    answer = "Yes"

    for s,t in zip(S,T):
        if s in s_to_t_dct and s_to_t_dct[s] != t:
            answer = "No"
            break
        if t in t_to_s_dct and t_to_s_dct[t] != s:
            answer = "No"
            break
        s_to_t_dct[s] = t
        t_to_s_dct[t] = s
    print(answer)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3632
n = int(input())
s = int(n ** 0.5)
i = 0
while True:
    if n%(s + i) == 0:
        k = 1
        break
    if n%(s - i) == 0:
        k = -1
        break
    i += 1
s = s + i * k 
print((s + n // s) - 2)

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

#define for_(i,a,b) for(int i=a;i<b;++i)

struct Edge {
	int v, t;
	Edge(int v_, int t_) : v(v_), t(t_) {}
	bool operator > (const Edge& e) const { return t > e.t; }
};

int n, m, l, lim, J[22], e[22];
vector< vector< Edge > > edges;

int cost[333][333], dp[1 << 20][20];

void djk(int s) {
	priority_queue< Edge, vector< Edge >, greater< Edge > > q;
	q.push(Edge(s, 0));
	cost[s][s] = 0;
	
	while (!q.empty()) {
		Edge e = q.top(); q.pop();
		
		if (cost[s][e.v] < e.t) continue;
		
		for_(i,0,(int)edges[e.v].size()) {
			Edge ei = edges[e.v][i];
			
			if (cost[s][ei.v] > e.t + ei.t) {
				cost[s][ei.v] = e.t + ei.t;
				q.push(Edge(ei.v, e.t + ei.t));
			}
		}
	}
}

void solve() {
	for_(i,0,n+1) for_(j,0,n+1) cost[i][j] = 1e9;
	
	for_(i,0,l+1) djk(J[i]);
	
	for_(i,0,(1 << (l+1))) for_(j,0,l+1) dp[i][j] = 1e9;
	dp[0][0] = 0;
	
	for_(S,0,(1 << (l+1))) for_(u,0,l+1) {
		if (dp[S][u] < 1e9) {
			for_(v,0,l+1) {
				if (!(S >> v & 1)) {
					dp[S | 1 << v][v] = min(dp[S | 1 << v][v], dp[S][u] + cost[J[u]][J[v]] + e[v]);
				}
			}
		}
	}
	
	int ans = 0;
	for_(S,0,(1 << (l+1))) {
		if (dp[S][0] <= lim) ans = max(ans, __builtin_popcount(S));
	}
	cout << ans-1 << endl;
}

int main() {
	while (cin >> n >> m >> l >> J[0] >> lim, n) {
		edges.assign(n+1, vector< Edge >());
		
		for_(i,0,m) {
			int a, b, c;
			cin >> a >> b >> c;
			edges[a].push_back(Edge(b, c));
			edges[b].push_back(Edge(a, c));
		}
		
		e[0] = 0;
		for_(i,1,l+1) cin >> J[i] >> e[i];
		
		solve();
	}
	
	return 0;
}

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

using namespace std;

#define ll long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define rep(i, a, b) for(i = a; i < b; i++)
#define repp(i, a, b) for(i = a; i > b; i--)

int a, b, c;

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin>>a>>b>>c;
    if(a == 5&& b == 5 && c == 7 || a == 5 && b == 7 && c == 5 || a == 7 && b == 5 && c == 5)
        cout<<"YES\n";
    else
        cout<<"NO\n";

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    char b[3][3];
    int i,j;

    while(1){
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                if(scanf("%c",&b[i][j])==EOF){
                    return 0;
                }
            }
        }
        getchar();
        if(b[0][0]==b[0][1]&&b[0][1]==b[0][2]&&b[0][2]==b[0][0]){
            if(!(b[0][0]=='s')){
                printf("%c\n",b[0][0]);
                continue;
            }
        }
        if(b[1][0]==b[1][1]&&b[1][1]==b[1][2]&&b[1][2]==b[1][0]){
            if(!(b[1][0]=='s')){
                printf("%c\n",b[1][0]);
                continue;
            }
        }
        if(b[2][0]==b[2][1]&&b[2][1]==b[2][2]&&b[2][2]==b[2][0]){
            if(!(b[2][0]=='s')){
                printf("%c\n",b[2][0]);
                continue;
            }
        }
        if(b[0][0]==b[1][0]&&b[1][0]==b[2][0]&&b[2][0]==b[0][0]){
            if(!(b[0][0]=='s')){
                printf("%c\n",b[0][0]);
                continue;
            }
        }
        if(b[0][1]==b[1][1]&&b[1][1]==b[2][1]&&b[2][1]==b[0][1]){
            if(!(b[0][1]=='s')){
                printf("%c\n",b[0][1]);
                continue;
            }
        }
        if(b[0][2]==b[1][2]&&b[1][2]==b[2][2]&&b[2][2]==b[0][2]){
            if(!(b[0][2]=='s')){
                printf("%c\n",b[0][2]);
                continue;
            }
        }
        if(b[0][0]==b[1][1]&&b[1][1]==b[2][2]&&b[2][2]==b[0][0]){
            if(!(b[0][0]=='s')){
                printf("%c\n",b[0][0]);
                continue;
            }
        }
        if(b[2][0]==b[1][1]&&b[1][1]==b[0][2]&&b[0][2]==b[2][0]){
            if(!(b[2][0]=='s')){
                printf("%c\n",b[2][0]);
                continue;
            }
        }
        printf("d\n");
    } 
    return 0;
}

Measured memory_bytes: 556
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

unsigned calc_gcd(unsigned a, unsigned b)
{
  if (a < b)
    swap(a,b);
  
  unsigned r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

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

  vector<unsigned> A;
  A.reserve(N);

  for (unsigned n=0; n<N; ++n) {
    unsigned a;
    cin >> a;
    A.push_back(a);
  }

  vector<unsigned> gcd_up, gcd_down;
  gcd_up.reserve(N); gcd_down.reserve(N);
  gcd_up.push_back(A[0]);
  for (unsigned n=1; n<N-1; ++n)
    gcd_up.push_back(calc_gcd(gcd_up.back(),A[n]));
  gcd_down.push_back(A[N-1]);
  for (unsigned n=1; n<N-1; ++n)
    gcd_down.push_back(calc_gcd(gcd_down.back(),A[N-n-1]));

  unsigned ans = max(gcd_up.back(), gcd_down.back());
  for (unsigned n=0; n<N-2; ++n)
    ans = max(ans, calc_gcd(gcd_up[n],gcd_down[N-n-3]));
  
  cout << ans << endl;
  
  return 0;
}

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

using std::cout;
using std::cin;
using std::endl;

/*  テンプレここから */
typedef long long ll;

#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int a, b;
    cin >> a >> b;
    cout << std::max(0, a-b*2) << endl;
}

Measured memory_bytes: 256
N = int(input())
a = map(int, input().split())
dict = {}
for x in a:
    if x in dict:
        dict[x] += 1
    else:
        dict[x] = 1

ans = 0
for k, v in dict.items():
    if k < v:
        ans += v - k
    elif v < k:
        ans += v

print(ans)


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

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]) {

	bool all_visited = true;

	for (int i = 0; i<N; ++i) {
		if (visited[i] == false) all_visited = false;
	}

	if (all_visited) {
		return 1;
	}


	int ret = 0;

	for (int i = 0; i<N; ++i) {
		if (graph[v][i] == false) continue;
		if (visited[i]) continue;

		visited[i] = true;
		ret += dfs(i, N, visited);
		visited[i] = false;

	}

	return ret;

}

int main(void) {
	int N, M;
	cin >> N >> M;

	for (int i = 0; i<M; ++i) {
		int A, B;
		cin >> A >> B;
		graph[A - 1][B - 1] = graph[B - 1][A - 1] = true;

	}

	bool visited[nmax];
	for (int i = 0; i<N; ++i) {
		visited[i] = false;

	}

	visited[0] = true;
	cout << dfs(0, N, visited) << endl;
	return 0;

}

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


int main() {
	int n;cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int cnt=0,ans=0;
        for(int i=0;i<n;i++){
            if(a[i]%2==0){
                cnt++;
            }
        }
        for(int i=0;i<n;i++){
            if(a[i]%2==0&&(a[i]%3==0||a[i]%5==0)){
                ans++;
            }
            
        }
      if(cnt==ans)    cout<<"APPROVED"<<endl;
      else     cout<<"DENIED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    string s;
    vector<string> S;
    vector<char> player{'A', 'B', 'C'};

    for(int i = 0; i < 3; i++){
        cin >> s;
        S.push_back(s);
    }

    int next = 0;

    for(int i = 0;; i++){
        if(S[next].size() == 0){
            cout << player[next] << endl;
            break;
        }

        if(S[next][0] == 'a'){
            S[next].erase(0, 1);
            next = 0;
        }else if(S[next][0] == 'b'){
            S[next].erase(0, 1);
            next = 1;
        }else if(S[next][0] == 'c'){
            S[next].erase(0, 1);
            next = 2;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int ans = k;
	for (int i = 0; i < n - 1; i++) {
		ans = ans*(k - 1);
	}
	cout <<  ans << endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    else:
        for i in range(h):
            for j in range(w):
                if (i+j)%2 == 0:
                    print("#",end="")
                else:
                    print(".",end="")
            print()
        print()


Measured memory_bytes: 7000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#define rep(i,n) for (int i = 0; i < n; ++i)
const int INF = 1001001001;

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    int a, b;
    rep (i,m) {
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    q.push(0);
    vector<bool> seen(n, false);
    seen[0] = true;
    vector<int> ans(n);

    int cur;
    while (!q.empty()) {
        cur = q.front();
        q.pop();
        for (int next: to[cur]) {
            if (seen[next]) continue;
            else {
                ans[next] = cur;
                seen[next] = true;
                q.push(next);
            }
        }
    }
    
    cout << "Yes" << endl;
    rep(i,n-1) cout << ans[i+1]+1 << endl;
    return 0;
}

Measured memory_bytes: 10048
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int n = in.nextInt();
			System.out.println(sumOfFourInt(n));
		}
	}

	static int sumOfFourInt(int n) {
		int a, b, c, d;
		int num = 0;
		L1: for (a = 0; a <= 9; a++) {
			if (a > n)
				break L1;
			L2: for (b = 0; b <= 9; b++) {
				if (a + b > n)
					break L2;
				L3: for (c = 0; c <= 9; c++) {
					if (a + b + c > n)
						break L3;
					L4: for (d = 0; d <= 9; d++) {
						if (a + b + c + d > n)
							break L4;
						if (a + b + c + d == n)
							num++;
					}
				}
			}
		}
		return num;
	}
}

Measured memory_bytes: 26692
fun main(args: Array<String>) {
    var (A, B, C, D) = listOfLong()
    val E = lcm(C , D)
    A = A - 1
    val a0 = A / C
    val b0 = A / D
    val c0 = A / E
    val a1 = B / C
    val b1 = B / D
    val c1 = B / E
    val ans = (B - (a1 + b1 - c1)) - (A - (a0 + b0 - c0))
    println("${ans}")
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }
fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a * b / gcd(a, b)


Measured memory_bytes: 36084
import java.util.Scanner;

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

        int N = sc.nextInt();
        int A = sc.nextInt();

        System.out.println(solve(N, A));

        sc.close();
    }

    static int solve(int N, int A) {
        return N * N - A;
    }
}

Measured memory_bytes: 21844
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    let mut sum = 0;
    for i in 0..n {
        seq[i] = read::<usize>();
        sum += seq[i];
    }
    seq.sort();
    sum -= seq[n - 1] / 2;
    println!("{}", sum);
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] buttons = new long[n];
		long[] mul = new long[n];
		for(int i=0;i<n;i++){
			buttons[i] = in.nextLong();
			mul[i] = in.nextLong();
		}
		long resevoir = 0;
		for(int i=mul.length-1;i>=0;i--){
			long add = (buttons[i]+resevoir)%mul[i]==0?(buttons[i]+resevoir)%mul[i]:mul[i] - (buttons[i]+resevoir)%mul[i];
			resevoir += add;
		}
		System.out.println(resevoir);
	}
	
    
}


Measured memory_bytes: 67612
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,ans;
    cin >> a ;
    cin >> b;
    cin >> c;
    if ( a == b and b == c){
        ans = 1 ;
    } else if ( a != b and  b != c and  c != a) {
        ans = 3;
    }else{
        ans = 2;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    
    int n;
    cin >> n;
    cout << (ll)(n - 1) * n / 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

int a[3], b[3];
int road[5];

signed main(void) {
	// init
	rep(i, 4) {
		road[i] = 0;
	}

	rep(i, 3) {
		cin >> a[i] >> b[i];
	}

	string ans = "YES";

	rep(i, 3) {
		road[a[i]]++;
		road[b[i]]++;

		if (road[a[i]] > 2 || road[b[i]] > 2) {
			ans = "NO";
			break;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,k,m,n;
  cin>>a>>b;
  k=(a+b)/2;
  m=abs(max(a,b)-k);
  n=abs(k-min(a,b));
  if(m==n)
  {
    cout<<k<<endl;
  }
  else
  {
    cout<<"IMPOSSIBLE"<<endl;
  }
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let s = Array.init n (fun _ -> Scanf.scanf " %s" (fun s -> s)) in

    let mini arr s2 =
        let d2 = Array.make 26 0 in
        String.iter (fun c -> let q = int_of_char c - 97 in d2.(q) <- d2.(q) + 1) s2;
        Array.init 26 (fun i -> min arr.(i) d2.(i))
    in

    let rec loop i acc =
        if i = n then acc else loop (i + 1) (mini acc s.(i))
    in
    let c = loop 0 (Array.make 26 50) in
    let rec loop i acc =
        if i = 26 then acc else loop (i + 1) (acc ^ String.make c.(i) (char_of_int (97 + i)))
    in
    loop 0 "" |> print_endline
)

Measured memory_bytes: 3700
#include <cstdio>

inline int Min(const int a,const int b){return a<b?a:b;}
inline int Max(const int a,const int b){return a>b?a:b;}

int n,m,Sum[3005],r[3005],f[3005][3005];
char s[3005];
const int p=1000000007;

int main()
{
    scanf("%d%d%s",&n,&m,s+1);
    for(int i=1;i<=n+1;++i)Sum[i]=Sum[i-1]+(s[i]&1),r[i]=i;
    for(int i=1,L,R;i<=m;++i)scanf("%d%d",&L,&R),r[L]=Max(r[L],R);
    for(int i=1;i<=n;++i)r[i]=Max(r[i],r[i-1]);
    for(int i=f[1][Sum[r[1]]]=1;i<=n;++i)
        for(int j=0;j<=n;++j)
            if(f[i][j])
            {
                int L=r[i]+1,R=r[i+1];
                int c1=j,c0=r[i]-i+1-j,Nc=Sum[R]-Sum[L-1];
                if(c0)(f[i+1][j+Nc]+=f[i][j])%=p;
                if(c1)(f[i+1][j+Nc-1]+=f[i][j])%=p;
            }
    printf("%d\n",f[n+1][0]);
    return 0;
}

Measured memory_bytes: 33792
#include<stdio.h>
#include<math.h>

#define N 15
#define K 15

int n, k, a[N], aTmp[N];

int main(){
    scanf("%d %d",&n ,&k);
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    
    int seenBuilding[K], noBitSearch=pow(2,n-1);
    long cost=0, costMin=pow(10,15);                 //
    for (int i = 0; i < noBitSearch; i++){
        int cntSeen=1;
        seenBuilding[0]=0;
        cost = 0;                 //リセットし忘れ
        for (int j = 1; j < n; j++){
            int isSeen = (i>>(j-1))&1;
            if (cntSeen<k){
                seenBuilding[cntSeen] = j*isSeen;
                cntSeen += isSeen;
            }
            else{
                cntSeen += isSeen;
            }
        }        
        if (cntSeen!=k){
            continue;
        }
        //
        for (int j = 0; j < n; j++){
            aTmp[j] = a[j];
        }
        for (int i1 = 1; i1 < k; i1++){
            for (int j1 = 0; j1 < seenBuilding[i1]; j1++){
                long diff = aTmp[j1] - aTmp[seenBuilding[i1]];
                if (diff>=0){
                    aTmp[seenBuilding[i1]] += diff+1;
                    cost += diff+1;
                    ///////
 //                   if (i=5){
 //                       for (int s = 0; s < k; s++){printf("%d ",seenBuilding[s]);} printf("\n");
 //                       for (int s = 0; s < n; s++){printf("%d ",aTmp[s]);} printf("\n");
 //                       printf("cost %d ",cost); printf("\n");                       
 //                   }
                    //////
                }
            }
        }
        costMin = ( (cost<costMin) ? cost : costMin );
    }
    

    printf("%ld\n", costMin); //  改行忘れ二度目
    return 0;
}

Measured memory_bytes: 2580
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 3003
#include <bits/stdc++.h>
using namespace std;

double dp[maxn][maxn], A[maxn];
bool visited[maxn][maxn];
int n, req;

double rec(int pos, int taken){
    if(visited[pos][taken]) return dp[pos][taken];
    if(pos == n+1){
        if(taken >= req) return 1.0;
        return 0.0;
    }
    double res = (A[pos] * rec(pos+1, taken + 1)) + ((1.0 - A[pos]) * rec(pos+1, taken));
    visited[pos][taken] = true;
    return dp[pos][taken] = res;
}

int main() {
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> A[i];
    }
    req = (n+1) / 2 ;
    printf("%.15lf\n", rec(0, 0));
    return 0;
}


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

using namespace std;

int main() {
int a; cin >> a;
string s; cin >> s;
if(a < 3200)
cout << "red\n";
else
  cout << s << "\n";
  //double arx = sy*((sx == 1) ? ar_n : ar_m); 
 return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int n, x, max;
    int a, b, c;
    int ans;
 
    while (1) {
        scanf("%d%d", &n, &x);
        if (n == 0 && x == 0) break;
 
        ans = 0;
        max = x; if (max > n) max = n;
        for (a = 1; a <= max; a++) {
            for (b = a + 1; b <= max; b++) {
                c = x - a - b;
                if (c > b && c <= n) ans++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2112
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[MAXN];
int bit[2*MAXN+1],s[MAXN];
int sum(int i)
{
    int s=0;
    while(i>0)
    {
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}
void add(int i,int x)
{
    while(i<=2*MAXN)
    {
        bit[i]+=x;
        i+=i&-i;
    }
}
ll check(int x)
{
    memset(bit,0,sizeof(bit));
    memset(s,0,sizeof(s));
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=x) s[i]=s[i-1]+1;
        else s[i]=s[i-1];
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        add(2*s[i-1]-(i-1)+n,1);
        ans+=sum(2*s[i]-i+n-1);
    }
    return ans;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    ll cnt=1LL*n*(n+1)/2;
    int l=0,r=INF;
    while(r-l>1)
    {
        int mid=(l+r)/2;
        if(check(mid)>=cnt/2+1) r=mid; else l=mid;
    }
    printf("%d\n",r);
    return 0;
}



Measured memory_bytes: 1792