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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>

typedef long long ll;

int main() {
  int N, M, max_L = 0, min_R = 1000000;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    max_L = max(max_L, L);
    min_R = min(min_R, R);
  }
  cout << max(min_R - max_L + 1, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<long, long>> AB(N);
	for (pair<long, long>& i : AB) cin >> i.first >> i.second;
	sort(AB.begin(), AB.end(), [](pair<long, long>& a, pair<long, long>& b)->bool {
		return a.second < b.second;
	});
	for (int i = 1; i < N; ++i) AB[i].first += AB[i - 1].first;
	int i;
	for (i = 0; i < N; ++i) {
		if (AB[i].first > AB[i].second) break;
	}
	if (i == N) cout << "Yes";
	else cout << "No";
}

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

typedef long long ll;
using namespace std;

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

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}
int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int a,b;cin>>a>>b;
  print(max(a-b,0));
  return 0;
}


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

public static partial class Program
{
    public static void Main()
    {
        var nk = CRL().SpTLongs();
        var n = nk[0];
        var k = nk[1];
        var array = new List<KeyValuePair<int, int>>();
        for (int i = 0; i < n; i++)
        {
            var ab = CRL().SpTInts();
            var a = ab[0];
            var b = ab[1];
            array.Add(new KeyValuePair<int, int>(a, b));
        }

        array = array.OrderBy(x => x.Key).ToList();
        for (int i = 0; i < n; i++)
        {
            k -= array[i].Value;
            if (k <= 0)
            {
                CWL(array[i].Key);
                return;
            }
        }
    }
}

public static partial class Program
{
    //テンプレここから
    private static int ToInt(this string str) => int.Parse(str);
    private static long ToLong(this string str) => long.Parse(str);
    private static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] SpTInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static long[] SpTLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Sign(this int i) => Math.Sign(i);
    public static bool IsEven(this int i) => i % 2 == 0;
    public static int[] dx = new int[] { 0, -1, 0, 1 };
    public static int[] dy = new int[] { -1, 0, 1, 0 };
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static int ToInt(this char c) => c.ToString().ToInt();
    public static long ToLong(this char c) => c.ToString().ToLong();
    //テンプレここまで
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n; cin >> n;
  vi32 h(n); rep(i, n) cin >> h[i];
  int ans = 0, mx = 0;
  rep(i, n) if (mx <= h[i]) { ans++; mx = h[i]; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
l = len(s)
a = 0
for i in range(l):
  if i&1 == 0:
    a <<= 2
    a += 1
b = ((2**l)-1) ^ a

S = int(s, 2)
A = bin(S^a).count('1')
B = bin(S^b).count('1')
print(min(A, B))

Measured memory_bytes: 3188
using System;

namespace AOJ.Volume1
{
    public class QuaternaryNotation
    {
        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n < 0) { break; }

                if (n == 0) { Console.WriteLine("0"); }
                else
                {
                    string output = "";
                    while (n > 0)
                    {
                        output = (n % 4).ToString() + output;
                        n = n / 4;
                    }

                    Console.WriteLine(output);
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9276
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int maxn = 1e5+5;
char str[15];
int main(void)
{
	scanf("%s", str);
	if ((str[2] == str[3]) && (str[4] == str[5]))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nm = Input.ar;
        var ab = new int[nm[1]][];
        for (var i = 0; i < nm[1]; i++)
            ab[i] = Input.ar;
        ab = ab.OrderBy(c => c[1]).ToArray();
        var ct = 0;
        var last = -1;
        for(var i = 0; i < nm[1]; i++)
        {
            if (last <= ab[i][0])
            {
                ct++;
                last = ab[i][1];
            }
        }
        WriteLine(ct);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 27972
#include <stdio.h>
int main(void)
{
    int n,b,f,r,v,room[4][3][10],i,j,k;
    
    for(i=1;i<=4;i++)
    {
        for(j=1;j<=3;j++)
        {
            for(k=1;k<=10;k++) room[i-1][j-1][k-1]=0;
        }
    }
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d %d %d",&b,&f,&r,&v);
        room[b-1][f-1][r-1]=room[b-1][f-1][r-1]+v;
    }
    
    for(i=1;i<=4;i++)
    {
        for(j=1;j<=3;j++)
        {
            for(k=1;k<=10;k++) printf(" %d",room[i-1][j-1][k-1]);
            printf("\n");
        }
        if(i!=4)
        {
            printf("####################\n");
        }

    }
    
    return 0;
}



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

#define PI 3.14159265358979323846264338327950L
#define ll long long

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a;
    long double b;
    cin >> a >> b;
    ll number = a * b;
    cout << number << "\n";

    return 0;

}
/*
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll answer = 1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll temp;
        cin >> temp;
        if (answer * temp >= pow(10, 18)) {
            answer = -1;
            break;
        } else {
            answer *= temp;
        }
    }
    cout << answer << "\n";

    return 0;

}*/


/*int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        set<int> sets;
        for (int i = 0; i < n; i++) {
            int temp;
            cin >> temp;
            if (temp % 2 == 0) {
                sets.insert(temp);
            }
        }
        ll answer = 0;
        for (auto i = sets.end() - 1; i != sets.begin() - 1; --i) {
            int number = *i;
            while (number % 2 == 0) {
                if (sets.find(number) != sets.end()) {
                    sets.erase(number);
                }f
                answer++;
                number = number / 2;
            }
        }
    }*/


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	map<ll,ll>a;
	for(ll i=2;i<=n;i++){
		ll now=i;
		for(ll j=2;j<=i;j++){
			while(now%j==0){
				now/=j;
				a[j]++;
			}
		}
		a[now]++;
	}
	ll ans=1;
	for(auto itr=a.begin();itr!=a.end();itr++){
		ll num=itr->first;
		ll val=itr->second;
	//	cout <<num<<" "<< val<<endl;
		if(num==1){
			continue;
		}
			ans*=(val+1);
			ans%=inf;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
using System;

namespace Atc_0019
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong N = ulong.Parse(Console.ReadLine());
            string nums = Console.ReadLine();

            var numArray = nums.Split(' ');

            ulong ans = 1;

            for (ulong i = 0; i < N; i++)
            {
                if (numArray[i] == "0")
                {
                    Console.WriteLine("0");
                    return;
                }
            }

            for (ulong i = 0; i < N; i++)
            {
                if (ulong.Parse(numArray[i]) > (1000000000000000000 / ans))
                {
                    Console.WriteLine("-1");
                    return;
                }

                ans = ans * ulong.Parse(numArray[i]);
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 39708
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(il, ir, l, r):
    ni = il + (ir - il) // 2
    print(ni)

    s = input()
    if s == 'Vacant':
        return
    elif (s == l and (ni - il) % 2 == 1) or (s != l and (ni - il) % 2 == 0):  # left
        solve(il, ni, l, s)
    else:
        solve(ni, ir, s, r)


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

    print(0)

    s = input()
    if s == 'Vacant':
        return

    solve(0, N, s, s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int n, m, k;
  vector<int> a, b;
  vector<int> sum_a, sum_b;
  int n_max, m_max;
  cin >> n >> m >> k;

  for (int i = 0; i < n; i++)
  {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  for (int i = 0; i < m; i++)
  {
    int tmp;
    cin >> tmp;
    b.push_back(tmp);
  }

  for (int i = 0; i < n; i++)
  {
    int tmp2;
    if (i == 0)
    {
      sum_a.push_back(a[0]);
      n_max = i + 1;
    }
    else
    {
      tmp2 = sum_a[i - 1] + a[i];
      if (tmp2 <= k)
      {
        sum_a.push_back(tmp2);
        n_max = i + 1;
      }
      else
      {
        break;
      }
    }
  }
  for (int i = 0; i < m; i++)
  {
    int tmp2;
    if (i == 0)
    {
      sum_b.push_back(b[0]);
      m_max = i + 1;
    }
    else
    {
      tmp2 = sum_b[i - 1] + b[i];
      if (tmp2 <= k)
      {
        sum_b.push_back(tmp2);
        m_max = i + 1;
      }
      else
      {
        break;
      }
    }
  }
  // cout << n_max << " " << m_max << endl;
  // for (int i = 0; i < n_max; i++)
  // {
  //   cout << sum_a[i] << " ";
  // }
  // cout << endl;
  // for (int j = 0; j < m_max; j++)
  // {
  //   cout << sum_b[j] << " ";
  // }
  // cout << endl;

  int max = 0;
  int sum = 0;

  // pick 0 books from A
  // pick j books from B
  int max_0;
  for (int j = 0; j < m_max; j++)
  {
    if (sum_b[j] <= k)
    {
      // cout << sum_b[j] << endl;
      if (max < j + 1)
      {
        max = j + 1;
      }
    }
    else
    {
      break;
    }
  }
  max_0 = max;

  // pick i books from A
  // pick 0 books from B
  for (int i = 0; i < n_max; i++)
  {
    if (sum_a[i] <= k)
    {
      // cout << sum_a[i] << endl;
      if (max < i + 1)
      {
        max = i + 1;
      }
    }
    else
    {
      break;
    }
  }

  // pick max_0-1 to 0 books from A
  // increase the number of books from B
  for (int l = max_0 - 1; l >= 0; l--)
  {
    sum = sum_b[l];
    for (int o = max - l - 1; o < n_max; o++)
    {
      sum = sum_b[l] + sum_a[o];
      if (sum <= k)
      {
        if (max < l + 1 + o + 1)
        {
          max = l + 1 + o + 1;
        }
      }
      else
      {
        break;
      }
    }
  }

  // pick i books from A
  // pick j books from B
  // for (int i = 0; i < n_max; i++)
  // {
  //   // sum = sum_a[i];
  //   for (int j = 0; j < m_max; j++)
  //   {
  //     sum = sum_a[i] + sum_b[j];
  //     // cout << sum << endl;
  //     if (sum <= k)
  //     {
  //       if (max < i + 1 + j + 1)
  //       {
  //         max = i + 1 + j + 1;
  //       }
  //     }
  //     else
  //     {
  //       break;
  //     }
  //   }
  // }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 7180
// AOJ 1138: Traveling by Stagecoach
// 2017.11.18 bal4u@uu

#include <stdio.h>
//#include <stdlib.h>
#include <string.h>

#define QMAX 1000000
typedef struct { double t; int node, c; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
//	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
//	return 1;
}

int qmax;
void enq(int n, double t, int c)
{
	int i, min;
	QUE qt;

	i = qsize++;	//if (qsize > qmax) qmax = qsize;
	que[i].t = t, que[i].node = n, que[i].c = c;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 1e10
#define MAX 31
typedef struct { int to[MAX], d[MAX]; } TBL;
TBL tbl[MAX];
int len[MAX];
int t[8];
double node[MAX][256];
char visited[MAX][256];


void dijkstra(int start, int goal, int N)
{
	int i, j, jj, s, e, c, lim;
	double tm;

	qsize = 0;
	memset(visited, 0, sizeof(visited));
	for (lim = 1<<N, i = 0; i < lim; i++) node[goal][i] = INF;
	enq(start, 0, 0);
	while (qsize) {
		s = que[0].node, tm = que[0].t, c = que[0].c, deq();
		if (visited[s][c]) continue;
		visited[s][c] = 1;
		node[s][c] = tm;
		for (i = 0; i < len[s]; i++) {
			e = tbl[s].to[i];
			for (jj = 1, j = 0; j < N; j++, jj <<= 1) {
				if ((c & jj) == jj) continue;
				if (visited[e][c | jj]) continue;
				enq(e, tm+(double)tbl[s].d[i]/t[j], c | jj);
			}
		}
	}
}

char buf[40], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int N, M, P, A, B, i, k, x, y, z, lim;
	double ans;

	while (fgets(bp=buf, 40, stdin) && *bp != '0') {
		N = getint(), bp++, M = getint(), bp++;
		P = getint(), bp++, A = getint()-1, bp++, B = getint()-1;
		memset(len, 0, sizeof(len));
		fgets(bp=buf, 40, stdin);
		for (i = 0; i < N; i++) t[i] = getint(), bp++;
		for (i = 0; i < P; i++) {
			fgets(bp=buf, 40, stdin);
			x = getint()-1, bp++, y = getint()-1, bp++, z = getint();
			k = len[x], tbl[x].to[k] = y, tbl[x].d[k] = z, len[x]++;
			k = len[y], tbl[y].to[k] = x, tbl[y].d[k] = z, len[y]++;
		}
		dijkstra(A, B, N);
		for (ans = INF, lim = 1<<N, i = 0; i < lim; i++) {
			if (node[B][i] < ans) ans = node[B][i];
		}
		if (ans == INF) puts("Impossible");
		else printf("%lf\n", ans);
	}
//	printf("qmax %d\n", qmax);
	return 0;
}

Measured memory_bytes: 8704
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
忘文件操作，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
signed main(){
	int s=read(),w=read();
	if(w>=s)	puts("unsafe");
	else		puts("safe");
	return 0;
}

Measured memory_bytes: 3616
#Some Sums
x = input()
x = x.split(" ")
sum = 0
plo = [int(s) for s in x]
for i in range(1,plo[0] + 1):
    cnt = 0
    num = list(str(i))
    inte = [int(s) for s in num]
    for j in range(len(inte)):
        cnt += inte[j]
    if(cnt >=plo[1] and cnt <= plo[2]):
        sum += i
print(sum)

Measured memory_bytes: 3188
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = A[N-1]

update = True
while update == True:
    update = False
    n = len(A)
    for i in range(1,n):
        A[i] %= A[0]
    C = []
    for a in A:
        if 1 <= a:
            C.append(a)
    C.sort()
    A = C
    if A[0] < ans:
        ans = A[0]
        update = True

print(ans)

Measured memory_bytes: 14252
def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = (0..n1).to_a
  r = (0..n2).to_a
  0.upto(n1-1).each {|i| l[i] = a[left+i]}
  0.upto(n2-1).each {|i| r[i] = a[mid+i]}
  l[n1] = Float::INFINITY
  r[n2] = Float::INFINITY
  i = 0
  j = 0
  count = 0
  left.upto(right - 1).each {|k|
    if l[i] <= r[j]
      a[k] = l[i]
      i += 1
    else
      a[k] = r[j]
      j += 1
      count += n1 - i
    end
  }
  count
end

def merge_sort(a, left, right)
  return 0 unless left + 1 < right
  mid = (left + right) / 2
  count = merge_sort(a, left, mid)
  count += merge_sort(a, mid, right)
  count += merge(a, left, mid, right)
  count
end

n = gets.to_i
s = gets.split.map(&:to_i)

count = merge_sort(s, 0, n)
puts count

Measured memory_bytes: 32480
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 long long a[n];
 for(int i=0;i<n;i++)
 {
     cin>>a[i];
 }
 long long cnt=0;
 long long m=0;
 for(int i=0;i<n;i++)
 {
  m = max(m,a[i]);
  int b= m;
  cnt +=b-a[i];

 }
 cout<<cnt;
    return 0;
}


Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

vector<P> G[800];
int used[800];

P dfs(int n) {
	used[n] = 1;
	int id = n;
	ll ma = 0;
	for (auto to : G[n]) {
		if (G[to.first].size() == 1 || used[to.first]) continue;
		auto p = dfs(to.first);
		if (p.second + to.second > ma) {
			ma = p.second + to.second;
			id = p.first;
		}
	}
	used[n] = 0;
	return P(id, ma);
}

int main()
{
	int n;
	while (cin >> n, n) {
		vector<ll> a(n - 1), b(n - 1), d(n - 1);
		for (int i = 1, p; i < n; i++) {
			cin >> p; p--;
			a[i - 1] = i;
			b[i - 1] = p;
		}
		for (int i = 0; i < n - 1; i++) {
			cin >> d[i];
			G[a[i]].push_back(P(b[i], d[i]));
			G[b[i]].push_back(P(a[i], d[i]));
		}
		ll res = 0;
		for (int i = 0; i < n - 1; i++) {
			res += d[i];
			if ((int)G[a[i]].size() > 1 && (int)G[b[i]].size() > 1) {
				res += d[i] * 2;
			}
		}
		int s = 0;
		while (G[s].size() == 1) s++;
		auto p = dfs(s);
		p = dfs(p.first);
		cout << res - p.second << endl;

		for (int i = 0; i < n; i++) G[i].clear();
	}
	return 0;
}

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

int main() {
  
  int N ;
  cin >> N;
  vector <int> A(N) ;
  
  for(int i = 0 ; i < N ; i++){
    cin >> A.at(i) ;
  }
   int res = 0 ;
  
  while(true){
    bool eo = false ;
    for(int i = 0 ; i < N ; ++i){
      if(A.at(i) % 2 != 0){
        eo =true;
      }
    }
    
    if(eo){
      break;
    }
    
    for(int i = 0; i < N; ++i){
      A.at(i) /= 2;
    }
    
    res++;
  }
  
  cout << res << endl;
  
}

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


int main(){
	int x;
  	cin >> x;
  	int s1;
  	s1= x/500;
  	int ans;
  	int s2;
  	s2 = (x-s1*500)/5;
  	ans = s1*1000 + s2*5;
 	
  	cout << ans << endl;
    

}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000
#define MAX 1000000
#define SQRT 1000

// sieve of Eratosthenes (prime num)
bool p[MAX+1]; //prime number=true
void prime(){
  int n=MAX;
  rep(i,n+1) p[i]=true;
  p[0]=p[1]=false;
  for(int i=2;i<=n;i++){
    if(p[i]){
      for(int j=i*2; j<=n; j+=i){
	p[j]=false;
      }
    }
  }
}


int mat[SQRT][SQRT];
pii tb[MAX+1];

int dp_n[MAX+1]; //num
int dp_l[MAX+1]; //last prime cave

// from n, max m return<num,last>
pii search(int m, int n){
  if(dp_n[n] != -1) return mp(dp_n[n],dp_l[n]);

  pii now=tb[n];
  vector<pii> vp;
  for(int i=-1; i<=1; i++){
    int nx=now.first+i, ny=now.second-1;
    if(nx>=0 && nx<SQRT && ny>=0 && mat[nx][ny]<=m){
      vp.pb(search(m, mat[nx][ny]));
    }
  }

  pii mxp=mp(0,0);
  rep(i,vp.size()){
    mxp =max(mxp, vp[i]);
  }

  if(p[n]){
    mxp.first++;
    if(mxp.second==0) mxp.second=n;
  }
  dp_n[n] = mxp.first;
  dp_l[n] = mxp.second;
  return mxp;
}

int main(){
  prime();

  // set-up tables
  int x=499, y=499;
  int dx[]={1,0,-1,0}, dy[]={0,1,0,-1};
  int i=1, d=0;
  while(i<=MAX){
    int ddx = dx[d%4];
    int ddy = dy[d%4];
    rep(j,(d+2)/2){
      mat[x][y]=i;
      tb[i]=mp(x,y);
      x += ddx;
      y += ddy;
      i++;
    }
    d++;
  }

  int m,n;
  while(cin>>m>>n, m|n){
    fill(dp_n, dp_n+m+1, -1);
    fill(dp_l, dp_l+m+1, -1);
    pii r = search(m,n);
    cout << r.first << " " << r.second <<endl;
  }
  return 0;
}

Measured memory_bytes: 21860
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

int x,y;

int f(int x,int y){ return y-x>=0?y-x:x-y+2; }

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	cin>>x>>y;
	cout<<min(min(f(x,y),f(-x,y)+1),f(x,-y)+1)<<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 rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 998244353;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 200010;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mpow(ll a, ll b, ll m) {
    ll res = 1;
    if (b > 0) {
    res = mpow(a, b/2, MOD);
    if (b % 2 == 0) res = (res * res) % MOD;
    else res = (((res * res) % MOD) * a) % MOD;
    }
    return res;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;

    COMinit();

    ll ans = 0;
    for (ll i = 0; i <= k; i++) {
        ll cur = m;
        cur *= mpow(m-1, n-1-i, MOD);
        cur %= MOD;
        if (cur < 0) cur += MOD;
        cur *= comb(n-1, i);
        cur %= MOD;
        if (cur < 0) cur += MOD;
        ans += cur;
        ans %= MOD;
        if (ans < 0) ans += MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8328
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const ll MOD = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a - b >= c)
        cout << 0 << endl;
    else
        cout << c - (a - b) << endl;
}

Measured memory_bytes: 256
s=STDIN.gets.split
n = s[0].to_i
q = s[1].to_i
parent  = Array.new(n)
0.upto(n-1) {|i|
  parent[i]  = i
}
1.upto(q) {
s=STDIN.gets.split
com = s[0].to_i
x   = s[1].to_i
y   = s[2].to_i
#printf(":%d %d %d\n",com,x,y)
if com == 0 then
  px = parent[x]
  py = parent[y]
  if(px != py) then
    if(px > py) then
      w = px
      px = py
      py = w
    end
    0.upto(n-1) {|i|
      parent[i] = px if parent[i]==py
    }
  end
elsif com == 1 then
  if(parent[x]==parent[y])
    puts 1
  elsif
    puts 0
  end
end
}

Measured memory_bytes: 8868
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int K,T;
  cin >> K >> T;
  vector<int> a(T);
  for (int i = 0; i < T; i++)
    cin >> a[i];
  sort(a.begin(),a.end());
  int end = T-1;
      if (K - a[end] > a[end])
	cout << 0 << endl;
      else
	{
	  cout << a[end]-1 - (K-a[end]) << endl;
	  
	}
}


Measured memory_bytes: 256
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
	int k,m;
	cin >> k;
	int i=0,j=0;
	vector<int>mm(10000001),kk(k,0);
	
	mm.at(i) = 7 % k;
	
	rep(i,10000001) {

		if (mm.at(i) == 0) {
			cout << i+1 << endl;
			return 0;
		}
		kk.at(mm.at(i)) += 1;	
		if (kk.at(mm.at(i)) == 2) {
			cout << -1 << endl;
			return 0;
		}
	
		
		    mm.at(i+1)=((mm.at(i) * 10 + 7) % k);
	}
	
	return 0;
}//アルゴリズムは見て解いたやつ(´･_･`)

Measured memory_bytes: 46228
a = int(input())
b = {}
for i in range(a):
    c = input()
    if c not in b:
        b.setdefault(c, 1)
    else:
        b[c] = b.get(c) + 1
d = int(input())
for i in range(d):
    c = input()
    if c not in b:
        b.setdefault(c, 1)
    else:
        b[c] = b.get(c) - 1
b = sorted(b.values(), reverse=True)
print(max(b[0], 0))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef double db;
const int N = 100005, mod = 1000000007;
int n, A, B, X[N], Y[N], num[N], fa[N];
ll ans;
struct node { int x, y, id; } a[N];
bool cmp(node a, node b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
int dx(int i, int j) { return abs(a[i].x - a[j].x); }
int dy(int i, int j) { return abs(a[i].y - a[j].y); }
int fd(int x) { return fa[x] == x ? x : fa[x] = fd(fa[x]); }
void link(int x, int y) {
	x = fd(x), y = fd(y);
	fa[x] = y;
}
void work(bool f) {
	int d = max(dx(A, B), dy(A, B));
	sort(a + 1, a + n + 1, cmp);
	int l = 1, r = 0;
	Rep(i, 1, n) {
		while (dx(i, l) > d || (dx(i, l) == d && a[i].y - a[l].y > d - f)) l ++;
		r = max(r, l - 1);
		while (dx(i, r + 1) == d && dy(i, r + 1) <= d - f) {
			if (r >= l) link(a[r].id, a[r + 1].id);
			r ++;
		}
		if (l <= r) link(a[i].id, a[l].id);
		num[ a[i].id ] += r - l + 1;
	}
}
int main()
{
	scanf ("%d%d%d", &n, &A, &B);
	Rep(i, 1, n) fa[i] = i;
	Rep(i, 1, n) scanf ("%d%d", &X[i], &Y[i]);
	Rep(i, 1, n) a[i] = (node) { X[i] + Y[i], X[i] - Y[i], i };
	work(0);
	Rep(i, 1, n) a[i] = (node) { X[i] - Y[i], X[i] + Y[i], i };
	work(1);
	/* Rep(i, 1, n) a[i] = (node) { X[i] + Y[i], Y[i] - X[i], i };
	work();
	Rep(i, 1, n) a[i] = (node) { X[i] - Y[i], Y[i] + X[i], i };
	work(); */
	Rep(i, 1, n) if (fd(i) == fd(A)) ans += num[i]; // cout << i<<endl;
	printf("%lld\n", ans);

	return 0;
}

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

int main(void){
    long a,b,c;
    scanf("%ld %ld %ld",&a,&b,&c);
    if(sqrtl(((long long)a*c)*1.0l) + sqrtl(((long long)b*c)*1.0l)<c*1.0l)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=[I() for _ in range(5)]

  for i in range(len(l)):
    if l[i]==min(l):
      return -(-n//l[i])+len(l)-1

print(main())


Measured memory_bytes: 6476
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

#define ll long long

int main() {
    int a, b;
    int ans = 0;
    cin >> a >> b;
    for (int i = 0; i < 1200; ++i) {
        if (a ==  floor(i * 0.08) && b == floor(i * 0.1)) {
            ans = i;
            break;
        }
    }
    if (ans > 0) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int ll;
int main(){
  ll A, V;
  cin >> A >> V;
  ll B,W;
  cin >> B >> W;
  ll T;
  cin >> T;
  ll D=abs(A-B);
  ll D2=(V-W)*T;
  puts(D<=D2?"YES":"NO");
}

Measured memory_bytes: 3588
l = sorted(list(map(int,input().split())))
#N<=Mとして一般性を失わない
N=l[0]
M=l[1]

if N==M==1:
    print(1)
if N==1 and M>=2:
    print(M-2)
if N==2 and M>=2:
    print(0)
if N>=3 and M>=3:
    print((N-2)*(M-2))

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

int main()
{
    long long A, B, K;
    cin >> A >> B >> K;

    if (K <= A)
    {
        cout << A - K << " " << B << endl;
    }
    else if (A < K && K <= A + B)
    {
        cout << 0 << " " << A + B - K << endl;
    }
    else
    {
        cout << 0 << " " << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
from math import gcd
from bisect import bisect
def main():
    n, x, *a = map(int, read().split())
    if n == 1:
        print(abs(a[0] - x))
        sys.exit()
    a.sort()
    a2 = [x - y for x, y in zip(a[1:], a)]
    xpos = bisect(a, x)
    if xpos == 0:
        xd = a[0] - x
        a2.append(xd)
        a2.append(xd)
    elif xpos == n:
        xd = x - a[-1]
        a2.append(xd)
        a2.append(xd)
    else:
        xd1 = x - a[xpos - 1]
        xd2 = a[xpos] - x
        a2.append(xd1)
        a2.append(xd2)
    if len(a2) == 2:
        r = gcd(a[0], a[1])
        print(r)
        sys.exit()

    r = gcd(a2[0], a2[1])
    for i1 in range(2, n + 1):
        r = gcd(r, a2[i1])
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20440
#include<stdio.h>
int main(){
int a;
while(scanf("%d\n",&a)!=EOF){
a=a%39;
if(a==0){
printf("3C39\n");
}
else if(a<10){
printf("3C0%d\n",a);
}
else{
printf("3C%d\n",a);
}
}
return 0;
}


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

using namespace std;

long long X, Y;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%lld %lld", &X, &Y);
if (X % Y == 0) printf ("-1\n");
else printf ("%lld\n", X);

return 0;
}


Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_058_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(11).
    01 a      PIC S9(3).
    01 b      PIC S9(3).
    01 c      PIC S9(3).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO a b c.

    IF b - a = c - b THEN
        DISPLAY "YES"
    ELSE
        DISPLAY "NO"
    END-IF.

    STOP RUN.


Measured memory_bytes: 764
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        if (n == 1) {
            System.out.println(m);
            return;
        }

        long ans = 0;
        for (long i = 1; i * i <= m; i++) {
            if (m < n * i) {
                break;
            }
            if (m % i != 0) {
                continue;
            }
            ans = Math.max(ans, i);

            long p = m / i;
            if (m < n * p) {
                continue;
            }
            ans = Math.max(ans, p);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
	int A, P, ans;
    cin>>A>>P;
    P=P+A*3;
    ans=P/2;
    cout<<ans<<endl;
}

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


int main() {
    int N, K;
    cin >> N >> K;

    vector<int> l(N);
    rep (i,N) {
        cin >> l.at(i);
    }
    sort(l.rbegin(), l.rend());

    int sum = 0;
    for (int i = 0; i < K; ++i) {
        sum += l.at(i);
    }
    cout << sum << endl;
    

}


Measured memory_bytes: 3620
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);

	        int N = sc.nextInt();
	        int K = sc.nextInt();
	        long[] a = new long[N];
	        for (int i=0 ; i<N; i++) {
	            a[i] = Long.parseLong(sc.next());
	        }	        
	        Arrays.sort(a);
	        long ans=0;
	        for(int i=0;i<K;i++) {
	        	ans=ans+a[i];
	        }

	        System.out.println(ans);
	    }
	}

Measured memory_bytes: 38304
fn main() {
    let input: Vec<i32> = read_vec();
    let x = input[0];
    let y = input[1];

    println!("{}", if solve(x, y) { "Yes" } else { "No" });
}

fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn solve(x: i32, y: i32) -> bool {
    // つまりは鶴亀算。
    //
    // 鶴と亀の数をそれぞれa,bとすると、以下の連立方程式が成り立つ。
    //   a + b = x
    //   2a + 4b = y
    // これをa,bについて解くと
    //   a = (4x - y)/2
    //   b = (y - 2x)/2
    // a,bがともに0以上の整数になれば、(x,y)は存在する。
    let a = 4 * x - y;
    let b = y - 2 * x;

    a >= 0 && a % 2 == 0 && b >= 0 && b % 2 == 0
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_solve_1() {
        assert_eq!(true, solve(3, 8));
    }

    #[test]
    fn test_solve_2() {
        assert_eq!(false, solve(2, 100));
    }

    #[test]
    fn test_solve_3() {
        assert_eq!(true, solve(1, 2));
    }
}


Measured memory_bytes: 2168
import java.util.Scanner
import kotlin.math.*
import kotlin.system.exitProcess

fun main() {
    val scn = Scanner(System.`in`)
    val n = scn.nextInt()
    val pre = mutableListOf<Pair<Int, Int>>()
    val q = mutableListOf<Pair<Int, Int>>()
    repeat(n){
        val s = scn.next().map {c -> if (c=='(') 1 else -1}
        var min = Integer.MAX_VALUE
        var sum = 0
        s.forEach {
            sum += it
            min = min(sum, min)
        }
        val p = Pair(min, sum)
        if (sum>=0) pre.add(p)
        else q.add(p)
    }
    pre.sortByDescending { it.first }
    q.sortBy{it.first-it.second}

    var sum = 0
    for ((m, f) in pre){
        if (sum+m<0) no()
        sum += f
    }
    for ((m, f) in q){
        if (sum+m<0) no()
        sum += f
        if (sum<0) no()
    }

    println(if (sum==0) "Yes" else "No")
}

fun no() {
    println("No")
    exitProcess(0)
}

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

int main(){
	int q;
	cin >> q;
	for(int p=0; p < q; p++){
		int c, a, n;
		int ans = 0;

		cin >> c >> a >> n;

		int t = min(c, min(a, n));
		ans += t;
		c -= t; a -= t; n -= t;

		t = min(c/2, a);
		ans += t;
		c -= t*2; a -= t;

		ans += c/3;

		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
  ll n,l,t,x;
  ll x0,w0;
  int w;
  ll count=0;
  ll sw;
  vector<pair<ll,int>> ans;
  vector<pair<ll,int>> ri;
  vector<pair<ll,int>> le;
  vector<pair<ll,int>>all;
  cin>>n>>l>>t;
  vector<ll> nans(n,0);
  for(int i=0;i<n;i++){
    cin>>x>>w;
    if(i==0){
      x0=x;
      w0=w;
    }
    if(w==1) le.emplace_back(pair(x,i));
    else ri.emplace_back(pair(x,i)); 
    all.emplace_back(pair(x,i));
  }
  sort(all.begin(),all.end());
  for(int i=0;i<n;i++){
    if(w0==1){
      if((int)ri.size()<=i)break;
      count+=(2*t/l+(((l+ri[i].first-x0)%l)<(2*t%l)));

    }else{
      if((int)le.size()<=i)break;
      count+=(2*t/l+(((l-le[i].first+x0)%l)<=(2*t%l)));
    }
  }
  if(w0==1){
    sw=count%n;
  }else{
    sw=(n-count%n)%n;
  }

  for(pair<ll,int> x:le){
    ans.emplace_back(pair((x.first+t)%l,x.second));
  }
  for(pair<ll,int> x:ri){
    ans.emplace_back(pair((l-(l-x.first+t)%l)%l,x.second));    
  }


  sort(ans.begin(),ans.end());
  int key1,key2;
  for(int i=0;i<n;i++){
    if(ans[i].second==0)key1=i;  
  }
  for(int i=0;i<n;i++){
    if(all[i].second==0)key2=i;  
  }
  for(int i=0;i<n;i++){
    nans[all[(key2+i+sw)%n].second]=ans[(i+key1)%n].first;
  }
  
  for(int i=0;i<n;i++){
    cout<<nans[i]<<endl;
  }
  
  
}

Measured memory_bytes: 10928
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define m 1000000007 
#define MAXN 100000
using namespace std;
int main(){
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++){
        if(i%3==0 || i%5==0 || (i%3==0 && i%5==0)) continue;
        else{
            sum+=i;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(m);
    vector<int>b(m);
    vector<vector<int> >pass(n+1,vector<int>(0));
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        pass[a[i]].push_back(b[i]);
        pass[b[i]].push_back(a[i]);
    }
    int br=0;
    for(int i=0;i<m;i++){
        //最初に見る点はa[i]
        vector<bool>check(n+1,false);
        check[a[i]]=true;
        queue<int>q;
        for(int j=0;j<pass[a[i]].size();j++){
            if(pass[a[i]][j]!=b[i]){
                q.push(pass[a[i]][j]);
                check[pass[a[i]][j]]=true;
            }
        }
        while(q.size()){//bfs
            int qf=q.front();
            if(qf==b[i]){//到達可能:bridgeではない
                br--;
                break;
            }
            for(int j=0;j<pass[qf].size();j++){
                if(check[pass[qf][j]]==false)q.push(pass[qf][j]);
                check[pass[qf][j]]=true;
            }
            q.pop();
        }
        br++;
    }
    cout<<br<<endl;
    return 0;
}

Measured memory_bytes: 256
from copy import deepcopy
from itertools import combinations
N = int(input())
if N==1:
    print(1)
    exit()
XY = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")
for (x1, y1), (x2, y2) in combinations(XY, 2):
    p, q = (x2-x1), (y2-y1)
    XY_ = deepcopy(XY)

    #XY_.sort()
    XY_.sort(key=lambda v: (v[0]*q - v[1]*p, v[0], v[1]))
    an = 0
    xp, yp = float("inf"), float("inf")
    for x, y in XY_:
        if xp+p==x and yp+q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    # if ans > an:
    #     print(p, q)
    ans = min(ans, an)
    for x, y in XY_:
        if xp-p==x and yp-q==y:
            pass
        else:
            an += 1
        xp, yp = x, y
    #if ans > an:

    ans = min(ans, an)
print(ans)




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

using namespace std;

int n, q;
char c[200010];
pair<char, char> cmd[200010];

bool canL(int idx){
	char now = c[idx];
	for(int i = 0; i < q; i++){
		if(c[idx] == cmd[i].first){
			if(cmd[i].second == 'L'){
				idx--;
				if(idx == -1) break;
			} else {
				idx++;
				if(idx == n) break;
			}

			now = c[idx];
		}
	}

	if(idx == -1) return true;
	return false;
}

bool canR(int idx){
	char now = c[idx];
	for(int i = 0; i < q; i++){
		if(c[idx] == cmd[i].first){
			if(cmd[i].second == 'L'){
				idx--;
				if(idx == -1) break;
			} else {
				idx++;
				if(idx == n) break;
			}

			now = c[idx];
		}
	}

	if(idx == n) return true;
	return false;
}

int main(){
	scanf("%d%d", &n, &q);
	scanf(" %s", c);

	for(int i = 0; i < q; i++){
		scanf(" %c %c", &cmd[i].first, &cmd[i].second);
	}

	//Binary Search that went to left side
	int l, r, mid;

	l = 0, r = n - 1;

	int tp, ans;
	ans = 0; tp = -1;
	while(l <= r){
		mid = (l + r) >> 1;

		if(canL(mid)){
			tp = mid;
			l = mid + 1;
		} else r = mid - 1;
	}

	ans = tp + 1;

	l = 0, r = n - 1;
	tp = n;
	while(l <= r){
		mid = (l + r) >> 1;

		if(canR(mid)){
			tp = mid;
			r = mid - 1;
		} else l = mid + 1;
	}

	ans += n - 1 - tp + 1;

	if(ans > n) ans = n;

	printf("%d\n", n - ans);

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    double sum = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        double x;
        cin >> x;
        string u;
        cin >> u;
        if (u == "JPY") {
            sum += x;
        } else {
            sum += x * 380000;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
N,P = map(int,input().split())
A = list(map(int,input().split()))
odd = 0 
for i in range(N):
  if A[i]%2 != 0:
    odd += 1

if odd == 0:
  if P == 0:
    ans = 2**N
  else:
    ans = 0
else:
  ans = 2**(N-1)
  
print(ans)

Measured memory_bytes: 3060