akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a,ll b);
ll lcm(ll a,ll b);

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  rep(i,n){
    ll t;
    cin >> t;
    if(i == 0) ans = t;
    else{
      ans = lcm(ans,t);
    }
  }
  cout << ans << endl;
}

ll gcm(ll a,ll b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  gcm(a%b,b);
}

ll lcm(ll a,ll b){
  if(a > b) return a/gcm(a,b)*b;
  else return b/gcm(a,b)*a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();
int main() {
    ll N;
    cin >> N;

    vector<bool> values(N + 1, false);
    values[1] = true;
    for (ll i = 2; i <= N; ++i) {
        ll v = i * i;
        while (v <= N) {
            values[v] = true;
            v *= i;
        }
    }

    for (ll i = N; i >= 0; --i) {
        if (values[i]) {
            PR(i);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll long long
//#define mod 1000000007
#define NCONS 100001

using namespace std;
int N, Q, K;
vector<ll> adj[NCONS];
vector<ll> cost[NCONS];
bool visited[NCONS];
ll dist[NCONS];

void set_dist(int cur, ll len)
{
	visited[cur] = true;
	dist[cur] = len;
	for (int i = 0; i < adj[cur].size(); i++)
	{
		auto next = adj[cur][i];
		auto next_cost = cost[cur][i];
		if (visited[next]) continue;
		set_dist(next, len + next_cost);
	}
}

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N - 1; i++)
	{
		ll a, b, c; cin >> a >> b >> c;
		adj[a].push_back(b);
		adj[b].push_back(a);
		cost[a].push_back(c);
		cost[b].push_back(c);
	}
	cin >> Q >> K;
	set_dist(K, 0);
	for (int i = 0; i < Q; i++)
	{
		int x, y; cin >> x >> y;
		cout << dist[x] + dist[y] << endl;
	}
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum = 0;
  int x;
  for(int i=0; i<N; i++){
    cin >> x;
    if(2*x < 2*(abs(K-x)))
      sum += 2*x;
    else
      sum += 2*(abs(K-x));
  }
  
  cout << sum << endl;
}


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

int main() {
  int n,m;
  cin>>n>>m;
  
  int ans=0;
  
  if(n>1) ans=ans+n*(n-1)/2;
  if(m>1) ans=ans+m*(m-1)/2;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    if N <= 999:
        print('ABC')
    else:
        print('ABD')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10056
n,d = map(int,input().split())
import math
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
    x[i],y[i] = map(int,input().split())
ans = 0
for i in range(n):
    dis = math.sqrt(x[i]**2 + y[i]**2)
    if dis <= d:
        ans += 1
print(ans)

Measured memory_bytes: 24752
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) { return m / gcd(n, m) * n; }

int main(void) {
	int a, b;
	cin >> a >> b;
	cout << a * b << " " << 2 * (a + b) << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n,k; cin >> n >> k;
    int cnt = n;
    int ans = 0;
    while(cnt > 0){
        cnt /= k;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    for(int i=0; i<a.size(); i++)
    {
        if(a[i]=='7')
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;


int val[200];


int analysis(string str){
	if(str == "P")
		return val['P'];
	else if(str == "Q"){
		return val['Q'];
	}
	else if(str == "R"){
		return val['R'];
	}
	else if(str == "0" || str == "1" || str == "2")
		return str[0] - '0';

	// ツ環古環づーツ偲ヲツづィツ渉慊つュ
	if(str[0] == '('){
		int cnt = 1;
		for(int i = 1; i < str.size(); i++){
			if(str[i] == '(')
				cnt++;
			else if(str[i] == ')'){
				cnt--;
				//if(cnt == 0 && str.size()-1 != i){
				//	break;
				//}
				//else if(cnt == 0 && i == str.size()-1){
				//	return analysis(str.substr(1,str.size()-2));
				//}
			}
			if(cnt == 1 && str[i] == '*'){
				int v1 = analysis(str.substr(1,i-1));
				int v2 = analysis(str.substr(i+1,str.size()-2-i));
				if(v1 == 0 || v2 == 0)
					return 0;
				else if(v1 == 1 || v2 == 1)
					return 1;
				else
					return 2;
			}
			else if(cnt == 1 && str[i] == '+'){
				int v1 = analysis(str.substr(1,i-1));
				int v2 = analysis(str.substr(i+1,str.size()-2-i));
				if(v1 == 0 && v2 == 0)
					return 0;
				else if(v1 == 1 && v2 != 2)
					return 1;
				else if(v2 == 1 && v1 != 2)
					return 1;
				else
					return 2;
			}
		}
	}
	else if(str[0] == '-'){
		int v2 = analysis(str.substr(1));
		if(v2 == 0)
			return 2;
		else if(v2 == 1)
			return 1;
		else
			return 0;
	}

}

int main(){
	string str;
	while(cin >> str && str != "."){
		int cnt =0;
		for(int P = 0; P <= 2; P++){
			for(int Q = 0; Q <= 2; Q++){
				for(int R = 0; R <= 2; R++){
					val['P'] = P;
					val['Q'] = Q;
					val['R'] = R;
					if(analysis(str) == 2)
						cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 916
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for (int i=1;i<=n;i++)if (i!=sc.nextInt())count++;
        if (count>2)System.out.println("NO");
        else System.out.println("YES");
    }
}


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

def check_score(N, C, B, A):
    correct = 0
    for A_i in A:
        score = sum([a*b for a, b in zip(A_i, B)]) + C
        if score > 0: correct += 1
    return correct

def main():
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))
    A = []
    for _ in range(N):
        A.append(list(map(int, input().split())))
    print(check_score(N, C, B, A))

if __name__ == "__main__":
    try:
        assert check_score(2, -10, [1, 2, 3], [[3, 2, 1], [1, 2, 2]]) == 1
        assert check_score(5, -4, [-2, 5], [[100, 41], [100, 40], [-3, 0], [-6, -2], [18, -13]]) == 2
        assert check_score(3, 0, [100, -100, 0], [[0, 100, 100], [100, 100, 100], [-100, 100 ,100]]) == 0
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    static void Main()
    {
        var nk = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
        var N = nk[0];
        var K = nk[1];
        var max = 1d;
        var bunshi = 1d;
        for (int i = 1; i <= N; ++i)
        {
            var num = i;
            var count = 0d;
            while (num < K)
            {
                num *= 2;
                count++;
            }
            if (count == 0 && i != 1) bunshi += max;
            else if (i == 1) max = (Math.Pow(2, count));
            else bunshi += (max / Math.Pow(2, count));
        }
        var ans = bunshi / (N * max);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11348
import java.util.Scanner;

class Main {
    public static int factorial(int n) {
        if (n == 0) { 
            return 1;
        } else {
            return n * factorial(n - 1);
        }
    }
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = Integer.parseInt(stdIn.next());
        int[] p = new int[n];
        int[] q = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(stdIn.next());
        }
        for (int i = 0; i < n; i++) {
            q[i] = Integer.parseInt(stdIn.next());
        }

        int a = 0;
        int b = 0;
        for (int i = 0; i < n; i++) {
            int minus = 0;
            for (int j = 0; j < i; j++) {
                if (p[j] < p[i]) minus++;
            }
            a += (p[i] - 1 - minus) * factorial(n - i - 1);
            
        }
        for (int i = 0; i < n; i++) {
            int minus = 0;
            for (int j = 0; j < i; j++) {
                if (q[j] < q[i]) minus++;
            }
            b += (q[i] - 1 - minus) * factorial(n - i - 1);
        }

        int ans = a - b;
        if (ans < 0) ans *= -1;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()

//int const N = 1;
int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if(b==0)
        return 1 % MOD;
    ll x = bigmod(a,b/2);
    x = (x * x) % MOD;
    if(b%2)
        x = (x * a) % MOD;
    return x;
}

int const N = 3e5 + 10;

ll dp[110][N] ;
ll cum[110][N] ;
ll ara[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;

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

    dp[0][0] = 1;
    cum[0][0] = 1;
    for(int i = 1; i <= k; i++)
        cum[0][i] = cum[0][i-1] + dp[0][i];

    for(int i = 1; i <= n; i++)
    {
        for(int K = 0; K <= k; K++)
        {
            dp[i][K] = cum[i-1][K] ;
            if(K > ara[i])
            {
                dp[i][K] = (dp[i][K] + 2*MOD - cum[i-1][K-ara[i]-1] ) % MOD;
            }
            cum[i][K] = (cum[i][K-1] + dp[i][K] ) % MOD ;

            //cout <<i << " " << K << " " << dp[i][K] << endl;
        }

    }

    cout << dp[n][k] << endl;

    return 0;
}




Measured memory_bytes: 471296
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    vector<int> niz(5);
    int k;
    for (int i = 0; i < 5; i++)
        cin >> niz[i];
    cin >> k;
    for (int i = 0; i < 5 - 1; i++)
        for (int j = i + 1; j < 5; j++)
        {
            if (niz[j] - niz[i] > k)
            {
                cout << ":(";
                return 0;
            }
        }
    cout << "Yay!";
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(3, 0);
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[tmp%3]++;
    }

    int ans = 0;
    if(a[0] == n){
        ans = 1;
    }else if(a[1] < a[2]){
        ans = a[0]+a[1]+min(a[2], a[1]+3);
    }else{
        ans = a[0]+a[2]+min(a[1], a[2]+3);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
int n,k,a[max_n];
ll s[max_n];
int bit[max_n],tot;
void update(int i,int x){
    for(;i<=tot;i+=i&-i)bit[i]+=x;
}
int query(int i){
    int res=0;
    for(;i;i-=i&-i)res+=bit[i];
    return res;
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
    for(int i=0;i<=n;i++)s[i]-=1ll*k*i;
    vector<ll> lsh;
    for(int i=0;i<=n;i++)lsh.push_back(s[i]);
    sort(lsh.begin(),lsh.end());lsh.erase(unique(lsh.begin(),lsh.end()),lsh.end());
    for(int i=0;i<=n;i++)s[i]=lower_bound(lsh.begin(),lsh.end(),s[i])-lsh.begin()+1;
    tot=lsh.size();
    ll ans=0;
    for(int i=0;i<=n;i++){
        ans+=query(s[i]);
        update(s[i],1);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 5104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, l, i;
    string ans;
    cin >> n >> l;
    vector <string> s(n);
    for(i = 0; i < n; i++)
        cin >> s[i];
    sort(all(s));
    for(i = 0; i < n; i++)
        ans += s[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 200000

vector<int> G[MAX_N];
bool colored[MAX_N] = {};
int cnt = 0;

void dfs(int v, int pre, bool color) {
    colored[v] = color;
    if (color) cnt++;
    for (auto to : G[v]) {
        if (to == pre) continue;
        dfs(to, v, !color);
    }
}

signed main() {
    int n;
    cin >> n;
    int a, b;
    rep(i, n - 1) {
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    dfs(0, -1, true);
    int ans[n];
    if ((n + 1) / 3 > cnt) {
        int now = 3;
        bool fixed[n] = {}, used[n + 1] = {};
        rep(i, n) {
            if (colored[i]) {
                ans[i] = now;
                fixed[i] = true;
                used[now] = true;
                now += 3;
            }
        }
        now = 1;
        rep(i, n) {
            if (!fixed[i]) {
                if (used[now]) now++;
                ans[i] = now;
                fixed[i] = now;
                used[now] = true;
                now++;
            }
        }
    } else if ((n + 2) / 3 > n - cnt) {
        int now = 3;
        bool fixed[n] = {}, used[n + 1] = {};
        rep(i, n) {
            if (!colored[i]) {
                ans[i] = now;
                fixed[i] = true;
                used[now] = true;
                now += 3;
            }
        }
        now = 1;
        rep(i, n) {
            if (!fixed[i]) {
                if (used[now]) now++;
                ans[i] = now;
                fixed[i] = now;
                used[now] = true;
                now++;
            }
        }
    } else {
        int now[3];
        iota(now, now + 3, 1);
        rep(i, n) {
            if (colored[i]) {
                if (now[0] > n) {
                    ans[i] = now[2];
                    now[2] += 3;
                } else {
                    ans[i] = now[0];
                    now[0] += 3;
                }
            } else {
                if (now[1] > n) {
                    ans[i] = now[2];
                    now[2] += 3;
                } else {
                    ans[i] = now[1];
                    now[1] += 3;
                }
            }
        }
    }
    rep(i,n){
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 17920
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  ll ans = x * min(k, n);
  if(n <= k){
    cout << ans << endl;
  }else{
    ans += y * (n-k);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector< vector<int> > l(n + 1), a(n + 1);
		for (int i = 0; i <= n; i++) {
			int m; cin >> m;
			vector<int> x(m), y(m);
			for (int j = 0; j < m; j++)
				cin >> x[j] >> y[j];
			vector<int> dx(m - 1), dy(m - 1);
			for (int j = 0; j < m - 1; j++) {
				dx[j] = x[j + 1] - x[j];
				dy[j] = y[j + 1] - y[j];
			}
			for (int j = 0; j < m - 1; j++)
				l[i].push_back(abs(dx[j] + dy[j]));
			for (int j = 0; j < m - 2; j++)
				a[i].push_back((dx[j] * dy[j + 1] - dx[j + 1] * dy[j]) / l[i][j] / l[i][j + 1]);
		}
		vector<int> L = l[0], A = a[0];
		vector<int> _L = L, _A = A;
		reverse(_L.begin(), _L.end());
		reverse(_A.begin(), _A.end());
		for (int j = 0; j < _A.size(); j++)
			_A[j] *= -1;
		for (int i = 1; i <= n; i++)
			if ((l[i] == L && a[i] == A) || (l[i] == _L && a[i] == _A))
				cout << i << endl;
		cout << "+++++" << endl;
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int X,N,i,B,count;
  count=1;
  B=0;
  cin>>N>>X;
  int L[N];
  for(i=0;i<N;i++){
  cin>>L[i];
  }
  for(i=0;i<N;i++){
  B=B+L[i];
    if(B<=X){
    count++;
    }
    
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
// 2014/07/15 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int x, y;
		cin >> x >> y;

		if(x==0 && y==0)
			break;

		if(x<y){
			cout << x << ' ' << y << '\n';
		}
		else{
			cout << y << ' ' << x << '\n';
		}
	}

	return 0;
}

Measured memory_bytes: 1160
L, R = map(int, input().split())

mL = L % 2019
mR = R % 2019

if R-L >= 2019:
    print(0)
elif mL >= mR:
    print(0)
else:
    ans = 10**10
    for i in range(mL, mR+1):
        for j in range(mL, mR+1):
            if i < j:
                ans = min(ans, (i*j)%2019)
    print(ans)


Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val h = (1..n).map { sc.nextInt() }.toIntArray()

  val bool = BooleanArray(n) { false }

  val hh = IntArray(n) { h[it] }
  for (i in 0 until n - 1) {
    if (hh[i] > hh[i + 1]) {
      hh[i] = hh[i] - 1
      bool[i] = true
    }
  }
  for (i in n - 2 downTo 0) {
    if (hh[i] > hh[i + 1]) {
      if (bool[i]) continue
      hh[i] = hh[i] - 1
      bool[i] = true
    }
  }

  for (i in 0 until n - 1) {
    if (hh[i] > hh[i + 1]) {
      println("No")
      return
    }
  }

  println("Yes")
}

Measured memory_bytes: 53996
//
//  main.swift
//  readLine
//
//  Created by MAC on 5/4/20.
//  Copyright © 2020 Ahliddin Akhmedov. All rights reserved.
//

import Foundation

//print("Enter how many days you will swim, bike or run this week?")
//
//var numberOfDays = Int(readLine() ?? "-1") ?? -1
//
//print("you entered \(numberOfDays + 10)")
//
//// command + r => builds and run the application
//// command + b => only builds and checks for errors
//
//var a = Int(readLine()!)!
//var b : [Int] = []
//
//
//
//var s : Int = 0
//var c : Int = 0
//
//for i in b {
//    if i == 10{
//        s += 1
//    } else{
//        c += 1
//    }
//}
//print("s - \(s), c- \(c)")

var str = readLine()
if str == "ARC" {
    print("ABC")
} else{
    print("ARC")
}






Measured memory_bytes: 12932
#include<stdio.h>
int main (void){
    int m,n,i,masu[1001],me,koma,ans;
    for(;;){
        scanf("%d%d",&n,&m);
        if(n==0&&m==0)break;
        koma=0,ans=m;
        for(i=0;i<n;i++){
            scanf("%d",&masu[i]);
        }
        for(i=0;i<m;i++){
            scanf("%d",&me);
            if(koma+me>=n&&ans>i){
                ans=i+1;
            }
            else if(koma+me<n){
                koma=koma+me+masu[koma+me];
            }
            if(n-1<=koma&&ans>i){
                ans=i+1;
            }
        }
        printf("%d\n",ans);
    }
return 0;
}

Measured memory_bytes: 604
#include <iostream>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    
    string a[h];
    for (int i = 0;i<h;i++){
        cin>>a[i];
    }
    int pre=0;
    int r,l;
    for (int i=0;i<h;i++){
        r=0;l=-1;
        for (int j=0;j<w;j++){
            if (a[i][j]=='#'){
                r=j;
                if (l==-1){
                    l=j;
                }
            }
        }
        if (i>0 & pre>l){
            cout<<"Impossible";
            exit(0);
        }
        pre=r;
    }
    cout<<"Possible";
    
}


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

using namespace std;
const LL mod=1e9+7;
const int maxn=1e5+5;
LL powMod(LL x, LL n, LL mod) {//快速幂求x^n%mod

    LL res=1;
    while(n) {
        if(n&1)
            res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
LL inv(LL x,LL mod) {//求逆元
    return powMod(x,mod-2,mod);
}
LL fac[maxn];
LL C(LL n, LL m)
{

    //C(n,m) = n!*(m!%mod的逆元)*((n-m)!%mod的逆元)%mod
    LL res=fac[n]*inv(fac[m],mod)%mod*inv(fac[n-m],mod)%mod;
//    printf("%lld\n",res);
    return res;
}

LL a[maxn];
LL ans=0;
int main()
{
    int n, k, i, j;
    cin>>n>>k;
    fac[0]=1;
    for(LL i=1;i<=n+2;i++)//预处理求fac，fac[i]=i!%mod
        fac[i]=fac[i-1]*i%mod;
    for(i=0; i<n; i++)scanf("%lld", &a[i]);
    sort(a, a+n);
    for(i=0; i<=n-k; i++)
    {
        ans=(ans-a[i]*C(n-i-1, k-1)%mod+mod)%mod;
//        printf("%lld\n", ans);
    }
    for(i=k-1; i<n; i++)
    {
        ans=(ans+a[i]*C(i, k-1)%mod+mod)%mod;
//        printf("%lld\n", ans);
    }
    cout<<ans%mod<<endl;
    return 0;
}



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

int main(){
  int N;
  vector<string> S(10010);

  cin >> N; int ans = 0;

  int A = 0, B = 0, BA = 0;
  for(int i=0; i<N; i++){
    cin >> S[i]; int l = S[i].length();
    for(int j=0; j<l-1; j++){
      if(S[i][j] == 'A' && S[i][j+1] == 'B') ans++;
    }

    if(S[i][0] == 'B' && S[i][l-1] == 'A'){
      BA++;
    } else if (S[i][0] == 'B'){
      B++;
    } else if (S[i][l-1] == 'A'){
      A++;
    }
  } 

  if(BA >= 1){
    ans += BA-1;
    if(A>0){ans++; A--;}
    if(B>0){ans++; B--;}
  }
  ans += min(A,B);
  cout << ans << endl;
}

Measured memory_bytes: 768
#include<iostream>                                                     
using namespace std;                                                   
int N;                                                                 
                                                                       
int Linear_Search(int *A,int key) {                                    
  for (int i=0; i<N; i++) {                                            
    if (A[i] == key) {                                                 
      return 1;                                                        
    }                                                                  
  }                                                                    
  return 0;                                                            
}                                                                      
                                                                       
int main() {                                                           
  int T[100000];                                                       
  int q;                                                               
  int a;                                                               
  int ans = 0;                                                         
  cin >> N;                                                            
  for (int i=0; i<N; i++) {                                            
    cin >> T[i];                                                       
  }                                                                    
  cin >> q;                                                            
  for (int i=0; i<q; i++) {                                            
    cin >> a;                                                          
    ans += Linear_Search(T,a);                                         
  }                                                                    
  cout << ans <<endl;                                                  
  return 0;                                                            
}                                           

Measured memory_bytes: 3124
def ord(N,n):#N,nは正の整数、Nで割り切れる回数、許容はN^1000
    if n%N!=0:
        return 0
    else:
        return 1+ord(N,n//N)

def get_sieve_of_eratosthenes_new(n):
    import math
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

primelist=get_sieve_of_eratosthenes_new(1000)

import sys

input=sys.stdin.readline

N=int(input())

factorize=[0 for i in range(0,len(primelist))]

for i in range(1,N+1):
    for j in range(0,len(primelist)):
        factorize[j]+=ord(primelist[j],i)
        i=i//primelist[j]**ord(primelist[j],i)

ans=1
for i in range(0,len(primelist)):
    ans=ans*(factorize[i]+1)
print(ans%(10**9+7))


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

namespace ABC_Training
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var sd = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x=>x).ToArray();
            Console.WriteLine(sd[n / 2] - sd[n / 2 - 1]);
        }
    }
}


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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    button_count = int(input())
    button_rules = {i + 1: int(input()) for i in range(button_count)}

    count = 1
    result = button_rules[count]

    while (result != 2) and (count < button_count):
        result = button_rules[result]
        count += 1

    if count < button_count:
        print(count)
    else:
        print(-1)


Measured memory_bytes: 17892
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<unordered_set>
#include<string.h>
#include<unordered_map>
#include<numeric>
#include<iomanip>
#include<string.h>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;

#define FOR(i,N) for(int i=0;i<N;i++)

ll mod=1e9+7;
double EPS=1e-8;



int main(){
    string s;
    cin>>s;
    if(s.length()<2){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=1;i<s.length();i++){
        if(s[i-1]=='A'&&s[i]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> A={1,3,5,7,8,10,12};
  vector<int> B={4,6,9,11};
  int x, y; cin >> x >> y;
  char X, Y;
  if (x!=2 && y!=2){
    for (int i=0;i<7;i++){
      if (x==A.at(i)) X='A';
      if (y==A.at(i)) Y='A';
    }
    for (int j=0;j<4;j++){
      if (x==B.at(j)) X='B';
      if (y==B.at(j)) Y='B';
    }
    if(X==Y) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int n, m;
const int N = 2e5 + 5;
int link[N], si[N];

int power(int x,int n,int mod){
    //(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){
    return power(x,mod-2,mod);
}



int find(int u) {
    if(link[u] == u)return u;
    return link[u] = find(link[u]);
}

void unite(int u, int v) {
    int a = find(u);
    int b = find(v);
    if(si[a] < si[b])swap(a, b);
    si[a] += si[b];
    si[b] = 0;
    link[b] = a;
}

int32_t main() {

    fast
    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        link[i] = i;
        si[i] = 1;
    }
    int a, b;
    while(m--) {
        cin >> a >> b;
        if(find(a - 1) != find(b - 1))
            unite(a - 1, b - 1);
    }
    int maxi = 0;
    // for(int i = 0; i < n; i++) {
    //     cout << si[i] << " ";
    // }
    // cout << endl;
    for(int i = 0; i < n; i++) {
        maxi = max(maxi, si[find(i)]);
    }
    cout << maxi;


    return 0;
}



Measured memory_bytes: 6768
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int A[2];
  cin >> A[0] >> A[1];
  sort(A, A+2);
  if (A[0] == 1 && A[1] == 2) {
    cout << 3 << endl;
  } else if (A[0] == 1 && A[1] == 3) {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)

int gcd(int n,int m){return m?gcd(m,n%m):n;}
int lcm(int n,int m){return n*m/gcd(n,m);} 

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

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;++i) cin >> A[i];
    int ans = lcm(A[0],A[1]);
    for(int i=2;i<N;++i) ans = lcm(A[i],ans);
    cout << ans << endl;
}


Measured memory_bytes: 3204
from time import time

def main():
    N = int(input())
    S = input()

    r = S.count('R')
    g = S.count('G')
    b = S.count('B')
    answer = r * g * b

    for i in range(N):
        for j in range(i, N):
            k = 2*j - i
            if k >= N: continue
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: answer -= 1
    print(answer)

if __name__ == '__main__':
    start = time()
    main()
    # print(time() - start)


Measured memory_bytes: 9096
#ABC066.py
s=input()
L=len(s)
Ans=0
for k in range(2,L):
    i=L-k
    t=i+1
    A=0
    if t%2==0:
        for l in range(0,int(t/2)):
            if s[l]==s[l+int(t/2)]:
                A=A+1
            else:
                continue
    if A==int(t/2):
        Ans=i+1
        break

print(Ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using std::max;
#define int long long
const int mod=998244353;
int K,n,_2[5010],C[5010][5010];
signed main(){
	scanf("%lld%lld",&K,&n);
	C[0][0]=1;
	for(int i=1;i<=5000;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	_2[0]=1;
	for(int i=1;i<=5000;i++)
		_2[i]=_2[i-1]*2%mod;
	for(int i=2;i<=2*K;i++)
		if(i&1){
			int y=abs(K-i+1),x=(K-y)/2,ans=0;
			for(int j=0;j<=x;j++)
				(ans+=C[x][j]*_2[j]%mod*C[n+y-1][j+y-1]%mod)%=mod;
			printf("%lld\n",ans);
		}
		else{
			int y=abs(K-i+1),x=(K-y)/2,ans=0;
			for(int j=0;j<=x;j++)
				(ans+=C[x][j]*_2[j]%mod*(C[n+y-1][j+y-1]+C[n+y-2][j+y-1])%mod)%=mod;
			printf("%lld\n",ans);
		}
}

Measured memory_bytes: 118428
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <deque>
using namespace std;
typedef long long int ll;

vector<pair<int,int>> g[100100];
int d[100100];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int k; cin >> k;
	for(int i=0;i<k;i++){
		g[i].push_back(make_pair((i+1)%k,1));
	}
	for(int i=0;i<k;i++){
		g[i].push_back(make_pair(i*10%k,0));
	}
	for(int i=0;i<k;i++){
		d[i]=1e9;
	}
	deque<int> q;
	q.push_front(1);
	d[1]=1;
	while(q.size()){
		int p=q.front();
		q.pop_front();
		for(auto t:g[p]){
			if(d[t.first]>d[p]+t.second){
				if(t.second){
					d[t.first]=d[p]+1;
					q.push_back(t.first);
				}
				else{
					d[t.first]=d[p];
					q.push_front(t.first);
				}
			}
		}
	}
	cout << d[0] << endl;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;
    int n = s.size();

    int eb = 0, ew = 0, ob = 0, ow = 0;

    for(int i=0; i<n; i+=2){
        if(s[i] == '1') ow++;
        else ob++;
    }

    for(int i=1; i<n; i+=2){
        if(s[i] == '1') ew++;
        else eb++;
    }

    int ans = min(ob+ew, ow+eb);

    dunk(ans);
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int p = std.nextInt();
        int q = std.nextInt();
        int r = std.nextInt();

        int max = Math.max(Math.max(p, q), r);

        System.out.println(p + q + r - max);
    }
}


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

struct Point {
    int i, j, count;
};

int count_black(int h, int w, string table[]) {
    int count = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (table[i][j] == '#')
                count++;
        }
    }
    return count;
}

int shortest_pass(int h, int w, string table[]) {
    queue<Point> que;
    que.push(Point {0, 0, 1});

    bool used[h][w];
    for (int i = 0; i < h; i++) {
        fill(used[i], used[i] + w, false);
    }
    while (!que.empty()) {
        Point p = que.front();
        que.pop();
        if (p.i < 0 || h <= p.i || p.j < 0 || w <= p.j || table[p.i][p.j] == '#' || used[p.i][p.j])
            continue;

        if (p.i == h - 1 && p.j == w - 1)
            return p.count;

        used[p.i][p.j] = true;
        p.count++;
        que.push(Point {p.i - 1, p.j, p.count});
        que.push(Point {p.i + 1, p.j, p.count});
        que.push(Point {p.i, p.j - 1, p.count});
        que.push(Point {p.i, p.j + 1, p.count});
    }
    return -1;
}

int main() {
    int h, w;
    cin >> h >> w;
    string table[h];
    for (int i = 0; i < h; i++) {
        cin >> table[i];
    }

    int blacks = count_black(h, w, table);
    int sp = shortest_pass(h, w, table);
    cout << ((sp < 0) ? -1 : (h * w - blacks - sp)) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long ans1=0;
    	long ans2=0;
		long X = sc.nextLong();
		loop:for(long i=-1000;i<=1000;i++){
			for(long k=-1000;k<=1000;k++){
				if (X==(i-k)*((i*i*i*i)+(i*i*i)*k+(i*i)*(k*k)+i*(k*k*k)+(k*k*k*k))){
							ans1=i;
							ans2=k;
							System.out.print(ans1);
							System.out.print(" ");
							System.out.print(ans2);
							break loop;
				}
				}
			}
		}
    }

Measured memory_bytes: 35720
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll SUM = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        SUM ^= a[i];
    }
    for (int i = 0; i < n; i++)
    {
        ll ans = SUM ^ a[i];
        cout << ans << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 4752
import numpy as np
N,K = list(map(int, input().split()))

A =[]
for i in range(K):
    input()
    A += list(map(int, input().split()))


res = []
for i in range(1,N+1):
    if not np.any(i in A):
        res.append(i)

print(len(res))
    

Measured memory_bytes: 27212
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int P = 998244353;

struct Simple {
  int n;
  vector<int> fac, ifac, inv;

  void build(int n) {
    this->n = n;
    fac.resize(n + 1);
    ifac.resize(n + 1);
    inv.resize(n + 1);
    fac[0] = 1;
    for (int x = 1; x <= n; ++x)
      fac[x] = fac[x - 1] * (ll)x % P;
    inv[1] = 1;
    for (int x = 2; x <= n; ++x)
      inv[x] = -(P / x) * (ll)inv[P % x] % P + P;
    ifac[0] = 1;
    for (int x = 1; x <= n; ++x)
      ifac[x] = ifac[x - 1] * (ll)inv[x] % P;
  }

  Simple() {
    build(1);
  }

  void check(int k) {
    int nn = n;
    if (k > nn) {
      while (k > nn)
        nn <<= 1;
      build(nn);
    }
  }

  int gfac(int k) {
    check(k);
    return fac[k];
  }

  int gifac(int k) {
    check(k);
    return ifac[k];
  }

  int ginv(int k) {
    check(k);
    return inv[k];
  }

  int binom(int n, int m) {
    if (m < 0 || m > n)
      return 0;
    return gfac(n) * (ll)gifac(m) % P * gifac(n - m) % P;
  }
} simp;

int mpow(int x, int k, int p = P) {
  int ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * (ll)x % p;
    x = x * (ll)x % p;
    k >>= 1;
  }
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> dist(n), cnt(n);
  cin >> dist;
  for (int i = 0; i < n; ++i)
    ++cnt[dist[i]];
#define GG do { puts("0"); return 0; } while (false);
  if (dist[0] != 0 || cnt[0] != 1) GG;
  int ans = 1;
  for (int i = 1; i < n; ++i)
    ans = ans * (ll)mpow(cnt[i - 1], cnt[i]) % P;
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);
  long long a[n];
  int zero=0;
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);
    if(a[i]==0){
      zero++;
    }
  }
  
  if(zero>0){
    printf("0\n");
    return 0;
  }
  
  long long r=1;
  for(int i=0;i<n;i++){
    if(a[i]<=1000000000000000000/r){
      r*=a[i];
    }else{
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n",r);
}
  

Measured memory_bytes: 2452
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int a,b,c,k;
    cin >> a >> b >> c >>k;
    ll ans = min(a,k);
    k-=a;
    if(k>0){
    k-=b;
    if(k>0){
        ans-=min(c,k);
    }
    }
    cout<< ans << endl;
}
    



Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	while(cin>>n,n){
		vp co(30);
		rep(i,30)co[i].second=i+'A';
		rep(i,n){
			char c;
			cin>>c;
			rep(j,30)if(co[j].second==c)co[j].first--;
			sort(all(co));
			int a=-co[0].first,b=-co[1].first;
			if(a>b+n-i-1){
				cout<<(char)co[0].second<<" "<<i+1<<endl;
				loop(j,i+1,n)cin>>c;
				goto end;
			}
		}
		cout<<"TIE"<<endl;
		end:;
	}
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int h[100005];
inline bool check(long long times)
{
	long long tmp=times;
    for(int i=1;i<=n;i++)
    {
        long long blood=h[i]-b*times;
        if(blood>0)
        {
            long long cnt=blood/(a-b)+(blood%(a-b)==0?0:1);
            tmp-=cnt;
            if(tmp<0)
            {
            	return false;
			}
        }
    }
    return true;
}
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	int lb=0,rb=1e9,mid;
	int ans=0;
	while(lb<=rb)
	{
		mid=(lb+rb)/2;
		if(check(mid))
		{
			ans=mid;
			rb=mid-1;
		}
		else
		{
			lb=mid+1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	int n, a[55], mx = -INF, mn = INF, mxi, mni, i;

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

		if(mx < a[i]){
			mx = a[i];
			mxi = i + 1;
		}
		if(mn > a[i]){
			mn = min(mn, a[i]);
			mni = i + 1;
		}
	}

	if(mx >= 0 && mn >= 0){
		cout << n - 1 << endl;
		for(i = 0; i < n - 1; i++){
			cout << i + 1 << ' ' << i + 2 << endl;
		}
	}
	else if(mx <= 0 && mn <= 0){
		cout << n - 1 << endl;
		for(i = n - 1; i > 0; i--){
			cout << i + 1 << ' ' << i << endl;
		}
	}
	else if(mx >= abs(mn)){
		cout << 2 * n - 1 << endl;
		for(i = 0; i < n; i++){
			cout << mxi << ' ' << i + 1 << endl;
		}
		for(i = 0; i < n - 1; i++){
			cout << i + 1 << ' ' << i + 2 << endl;
		}
	}
	else{
		cout << 2 * n - 1 << endl;
		for(i = 0; i < n; i++){
			cout << mni << ' ' << i + 1 << endl;
		}
		for(i = n - 1; i > 0; i--){
			cout << i + 1 << ' ' << i << endl;
		}
	}
}

Measured memory_bytes: 256
def bubble(A,n):
	A = A.copy()
	for i in range(n):
		for j in range(n-1,i,-1):
			if A[j][1]<A[j-1][1]:
				A[j],A[j-1]=A[j-1],A[j]
	return A

def selection(A,n):	
	A=A.copy()
	for i in range(n-1):
		minj = i
		for j in range(i+1,n):
			if A[j][1]<A[minj][1]:
				minj=j
		A[i],A[minj]=A[minj],A[i]
	return A


n =int(input())
A =input().split()

C1,C2=bubble(A,n),selection(A,n)

print(' '.join(C1))
print('Stable')
print(' '.join(C2))
flag = 1
for i in range(n):
	if C1[i]!=C2[i]:
		flag=0
if flag:
	print('Stable')
else:
	print('Not stable')




Measured memory_bytes: 5608
def main()
  n = gets.chomp.to_i
  x = gets.chomp.split(' ').map(&:to_i)
  table = Array.new(n,0)
  ans = Float::INFINITY
  sum = 0
  for i in 0..n-1
    table[i] = sum + x[i]
    sum = sum + x[i]
  end

  for i in 0..(n-2)
    tmp = (table[i] - (table[n-1] - table[i])).abs
    ans = [ans, tmp].min
  end
  puts ans
end

main()

Measured memory_bytes: 22020
n, m  = map(int, input().split())
arr = []
for i in range(n):
    a, b = map(int, input().split())
    arr.append([a, b])
arr.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    ans += arr[idx][0] * min(arr[idx][1], m)
    m -= min(arr[idx][1], m)
    idx += 1
print(ans)


Measured memory_bytes: 20064
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = sc.nextInt();
		if(A <= X && X <= A + B) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;

	int ans_pat_1 = 0; // 010101010...
	int ans_pat_2 = 0; // 101010101...
	
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s[i] == '0') {
				ans_pat_2++;
			} else {
				ans_pat_1++;
			}
		} else {
			if (s[i] == '0') {
				ans_pat_1++;
			} else {
				ans_pat_2++;
			}
		}
	}
	
	cout << min(ans_pat_1, ans_pat_2) << endl;
	
	return 0;
}

Measured memory_bytes: 512
N = int(input())
P = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
print(*P[:N])

Measured memory_bytes: 38256