akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
double pi=3.1415926,n;
int main()
{
	cin>>n;
	cout<<n*2*pi<<endl;
	return 0;}

Measured memory_bytes: 3788
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    set<int> s;
    for(int i=0; i<n; ++i){
        int a, b;
        cin >> a >> b;
        a += b;

        while(s.find(a) != s.end()){
            s.erase(a);
            ++ a;
        }
        s.insert(a);
    }

    for(int x : s)
        cout << x << " 0" << endl;

    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    int N = S.size();
    vector<int> Snum(N);
    long long SnumSum = 0;
    long long ans = 1;
    for (int i = 0; i<N; i++)
    {
        if (S[i] == 'a')
            Snum[i] = 0;
        else if (S[i] == 'b')
            Snum[i] = 1;
        else
            Snum[i] = 2;
        SnumSum += Snum[i];
        if (i>0 && Snum[i] == Snum[i-1])
            ans = 0;
    }

    bool allSameFlg = true;
    {
        for (int i = 0; i < N - 1; i++) if(Snum[i] != Snum[i+1])
                allSameFlg = false;
    }
    if (allSameFlg)
    {
        cout << "1\n";
        return 0;
    }

    if (N == 2)
    {
        cout << "2\n";
        return 0;
    }
    if (N == 3)
    {
        if (Snum[0] != Snum[2] && Snum[1] != Snum[2] && Snum[0] != Snum[1])
        {
            cout << "3\n";
            return 0;
        }
    }

    vector<long long> dist_now(5, 0);
    vector<long long> dist_prev;
    dist_now[3] = 1;
    dist_now[1] = 2;
    for (int i = 2; i <= N; i++)
    {
        dist_prev = dist_now;
        dist_now[0] = dist_prev[1] + dist_prev[2];
        dist_now[1] = 2 * dist_prev[3] + dist_prev[4];
        dist_now[2] = dist_prev[0] + dist_prev[2];
        dist_now[3] = dist_prev[4];
        dist_now[4] = dist_prev[0] + dist_prev[1];

        for (int i = 0; i < 5; i++)
            dist_now[i] = dist_now[i] % (998244353 * 2);
    }

    long long power2n1 = 1;
    long long power3n1 = 1;
    for (int i = 0; i<(N-1); i++)
    {
        power2n1 *= 2;
        power3n1 *= 3;
        power2n1 = power2n1 % 998244353;
        power3n1 = power3n1 % 998244353;
    }
    long long subtract = power2n1;
    if (N % 3 == 0) // 面倒
    {
        if (SnumSum % 3 == 0)
        {
            subtract = dist_now[3] + dist_now[4];
        }
        else
        {
            subtract = (dist_now[0] + dist_now[1] + dist_now[2]) / 2;
        }
    }

    ans += power3n1 - subtract;
    while (ans<0) ans += 998244353;
    cout << ans % 998244353 << "\n";
    return 0;
}


Measured memory_bytes: 1412
#include<stdio.h>
int main(void)
{
	int w, h, c, i, max=-1;
	int temp;

	scanf("%d %d %d", &w, &h, &c);
	if (w > h) {
		for (i = 1; i <= h; i++) {
			if (h % i == 0) {
				if (w % i == 0) {
					temp = i;
				}
				if (max < temp) {
					max = temp;
				}
			}
		}
		printf("%d\n", (w / max)*(h / max)*c);
	}
	else if (w < h) {
		for (i = 1; i <= w; i++) {
			if (h % i == 0) {
				if (w % i == 0) {
					temp = i;
				}
				if (max < temp) {
					max = temp;
				}
			}
		}
		printf("%d\n", (w / max)*(h / max)*c);
	}
	else if (w == h) {
		printf("%d\n", c);
	}
	return 0;
}


Measured memory_bytes: 2112
/*;

THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define r(i, s, l) for (int i = s; i < l; i++)
#define mod 1000000007
#define int long long
#define INT_BITS 32
#define ld long double
#define pp pair<int,int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main()
{


    int n;
    cin>>n;
    unordered_map<int,int> mp;
    while (n % 2 == 0)
    {
        mp[2]++;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        //cout<<n<<endl;
        while (n % i == 0)
        {
            mp[i]++;
            n = n/i;
        }
    }
    if (n > 2)
        mp[n]++;

    int ans=0;
    for(auto i=mp.begin();i!=mp.end();i++)
    {

       int x= i->ss;
       int idx=1;
       while(x>=0 && i->ff!=1)
       {
          //cout<<x<<endl;
          x-=idx;
          if(x<0)
          break;
          ans++;
          idx++;
       }

    }
    cout<<ans;

	return 0;
}


Measured memory_bytes: 3688
from collections import deque
H, W = map(int, input().split())
m = [[-1 if c == "." else 0 for c in input() + "#"] for _ in range(H)]
m.append([0] * (W + 1))
todo = deque(((h, w) for h in range(H) for w in range(W) if m[h][w] == 0))
ans = 0
while todo:
    h, w = todo.popleft()
    count = m[h][w] + 1
    for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        nh = h + dh
        nw = w + dw
        if m[nh][nw] == -1:
            m[nh][nw] = count
            todo.append((nh, nw))
            ans = count
print(ans)

Measured memory_bytes: 85852
def read():
    N = int(input().strip())
    P = list(map(int, input().strip().split()))
    return N, P

def solve(N, P):
    min_value = P[0]
    count = 0
    for i in range(N):
        min_value = min(min_value, P[i])
        if P[i] == min_value:
            count += 1
    return count


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 26012
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=105;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.14159265359
#define mod 1000000007
string stones(int a[],int n,int k)
{
	int i,j;
	int dp[k+1]={};
	dp[0]=0;
	for(i=1;i<=k;i++)
	{   int c=0;
		for(j=0;j<n;j++)
		{  
			if(i-a[j]>=0){
			 if( dp[i-a[j]]==0){
			 	dp[i]=1;
			 	c=1;
			 }

			}

		}
		if(c==0)
			dp[i]=0;
	}
	return(dp[k]? "First":"Second");
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
   cin>>a[i];
     cout<<stones(a,n,k);
	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long n,k,s=0;
    cin>>n>>k;
    int a[n];
    for (int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-k;i++)
        s+=a[i];
    cout<<s;
    
}

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

int numofbits5(long bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main(){
	int n,s,ret,sum;
	while(cin >> n >> s && n || s){
		ret = 0;
		for(int i=0;i < (1<<10);i++){
			sum = 0;
			if(numofbits5(i) != n)continue;
			for(int j=0;j<10;j++){
				if( (1<<j) & i )sum += j;
			}
			if(sum == s)ret++;
		}
		cout << ret << endl;
	}
}

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

int main(){
   int h, r;
   cin>>h>>r;
   if( - h - r < 0 ) cout<<"1"<<endl;
   if( - h - r > 0 ) cout<<"-1"<<endl;
   if( h + r == 0 ) cout<<"0"<<endl;

   return 0;
}


Measured memory_bytes: 3048
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n);
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end());
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define reverse(a)      reverse((a).begin(), (a).end());
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d);
#define outl(d)         std::cout<<(d)<<"\n";
#define Yes()           printf("Yes\n");
#define No()            printf("No\n");
#define YES()           printf("YES\n");
#define NO()            printf("NO\n");
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  string s1, s2, s3; cin >> s1 >> s2 >> s3;
  string s = "";
  s += s1[0]; s += s2[0]; s += s3[0];
  transform(s.begin(), s.end(), s.begin(), ::toupper);
  outl(s)
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12)

  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const ll mod=1e9+7;
const ll inf=1e16;
const ll N=1e5+10;

int main()
{
	boost;
	ll n;
	cin>>n;
	ll a[n];
	for(auto &i:a) cin>>i;
	ll ans=0;
	ll i=0,j=0;
	while(i<n and j<n)
	{
		j=0;
		while(i<(n-1) and a[i]>=a[i+1]) i++,j++;
		ans=max(ans,j);
		i++;
	}	
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
if(B%A==0)
	System.out.println(A+B);
else
	System.out.println(B-A);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21204
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
#A = [a for a,b in AB]
#B = [b for a,b in AB]
#C = list(range(N))

def merge(la, lb, key):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if key(la[ia]) < key(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  return ans
    
def mergeSort(x, key):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d], key)
    right = mergeSort(x[d:], key)
    return merge(left,right, key)

AB = mergeSort(AB, key=lambda x:x[1])

ans = "Yes"
t = 0
for a,b in AB:
    t += a
    if t > b:
        ans = "No"

print(ans)

Measured memory_bytes: 104408
import sys
input = sys.stdin.readline

n = int(input())
b = list(map(int, input().split()))

from queue import Queue
q = Queue()
ans = Queue()

import numpy as np
n = np.array(n)


def bfs(b):
    q.put(b)
    ans.put([])

    while q.empty() == False:
        p = q.get()
        a = ans.get()

        if p == []:
            break

        if p[0] != 1:
            continue

        m = len(p)

        for i in range(m-1, -1, -1):
            if p[i] == i+1:
                q.put(p[:i]+p[i+1:])
                ans.put(a+[i+1])
                break


    if p == []:
        a = a[::-1]
        for aa in a:
            print(aa)
    else:
        print(-1)


bfs(b)

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

int main() {
  int X, i, tmp, ans, count;
  cin >> X;
  for (i = 1; i <= X; i ++) {
    if (i == 1) {
      ans = 1;
    }
    if (i > 1) {
      tmp = i;
      count = 1;
      do {
        tmp *= i;
        if (count > 1) {
          ans = max(ans, tmp/i);
        }
        count++ ;
      } while (tmp <= X);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import combinations
import math

L = list(map(int, input().split()))
N = L[0]
D = L[1]

X = []

for i in range(N):
	X.append(list(map(int, input().split())))

count = 0

for x in combinations(X,2):
	tmp = 0
	for j in range(D):
		tmp += (x[0][j]-x[1][j]) ** 2
		dist = math.sqrt(tmp)
	if dist % 1 == 0:
			count += 1
			
print(count)
	

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
   int i,n,four=0;
   scanf("%d",&n);
   char arare[n];

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

   for(i=0;i<n;i++)
      if(arare[i]=='Y'){four=1; break;}


   if(four==1) printf("Four\n");
   else printf("Three\n");

   return 0;
}

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

int main(){
  long long N,M;
  cin >> N >> M;
  
  for(int i=0;i<M;i++){
    long long a;
    cin >> a;
    N -= a;
  }
  
  cout << max(N,(long long)(-1)) << endl;
  return 0;
}


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

bool bingo(int A[3][3], int N, int B[]){
    bool sign[3][3];
    int a1,a2,a3,a4,a5,a6;
    for(int j = 0; j<3; j++){
        for(int k = 0;k<3;k++){
            sign[j][k]=false;
        }
    }
    for(int i = 0; i<N; i++){
        for(int j = 0; j<3; j++){
            for(int k = 0;k<3;k++){
                if(B[i] ==A[j][k]){
                    sign[j][k] =true;
                }
            }
        }
    }
    a1=0;
    for(int i=0;i<3;i++) if(sign[i][0]) a1++;
    if(a1==3) return true;
    a2=0;
    for(int i=0;i<3;i++) if(sign[i][1]) a2++;
    if(a2==3) return true;
    a3=0;
    for(int i=0;i<3;i++) if(sign[i][2]) a3++;
    if(a3==3) return true;
    a4=0;
    for(int i=0;i<3;i++) if(sign[0][i]) a4++;
    if(a4==3) return true;
    a5=0;
    for(int i=0;i<3;i++) if(sign[1][i]) a5++;
    if(a5==3) return true;
    a6=0;
    for(int i=0;i<3;i++) if(sign[2][i]) a6++;
    if(a6==3) return true;
    if(sign[0][0]==true and sign[1][1]==true and sign[2][2]==true) return true;
    if(sign[2][0]==true and sign[1][1]==true and sign[0][2]==true) return true;
    
    return false;
}

int main() {
    int N, A[3][3];
    cin >> A[0][0] >> A[0][1] >> A[0][2];
    cin >> A[1][0] >> A[1][1] >> A[1][2];
    cin >> A[2][0] >> A[2][1] >> A[2][2];
    cin >> N;
    int B[N];
    for(int i = 0;i<N;i++){
        cin >> B[i];
    }
    if( bingo(A, N, B)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
ary = Array.new
while line = $stdin.gets
ary << line.chomp.split
end
N = ary[0][0].to_i
K = ary[0][1].to_i
ary.delete_at(0)
ary.map!{|item| item[0].to_i }
ary.sort!{|a,b| a <=> b}
kai = ary[K-1]-ary[0]
t = N-K+1
t.times{|num|
if ary[num+K-1]-ary[num] < kai then
kai = ary[num+K-1]-ary[num]
end
}
print kai

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

int main(){
  int a,b,c,k,i;
  long long x;
  cin>>a>>b>>c;
  cin>>k;
  x=max(a,max(b,c));
  for(i=0;i<k;i++){
    x*=2;
  }
  cout<<x+a+b+c-max(a,max(b,c));
}
    

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

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


Measured memory_bytes: 256
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    string s,k;
    cin>>s;
    for(int i=0;i<(int)SZ(s);i++)
    {
        cout<<"x";
    }
    cout<<nl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass 1073741824
#define MAXN 200000 + 5
#define LOGN 20
using namespace std;
#define N 505

/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl; 
#define siz(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define int ll
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)

//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl

typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;

signed main()
{
    FAST;
    int k , n;
    cin >> k >> n;
    int ans = LLONG_MAX;
    vector<int> arr(n , 0);
    rep(i , 0 , n)
        cin >> arr[i];
    for (int i = 0 ; i + 1 < n ; i++)
        ans = min(ans , k - (arr[i + 1] - arr[i]));
    ans = min(ans , k - ((k - arr[n - 1] + arr[0])));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
use proconio::input;

fn main() {
    input!(n: usize, a: [i64; n]);
    if a.iter().all(|&x| x <= 0) {
        let i = a.iter().enumerate().max_by_key(|(_, &x)| x).unwrap().0;
        let steps: Vec<_> = (i + 1..n)
            .rev()
            .chain(std::iter::repeat(0).take(i))
            .collect();
        println!("{}", a[i]);
        println!("{}", steps.len());
        for x in steps {
            println!("{}", x + 1);
        }
    } else {
        let (ans, seq) = (0..2)
            .map(|parity| {
                let mut seq = vec![];
                let mut ans = 0;
                for (i, x) in a
                    .iter()
                    .copied()
                    .enumerate()
                    .filter(|&(i, x)| i % 2 == parity && 0 < x)
                {
                    ans += x;
                    seq.push(i);
                }
                (ans, seq)
            })
            .max()
            .unwrap();

        println!("{}", ans);
        let steps: Vec<_> = (*seq.last().unwrap() + 1..n)
            .rev()
            .chain(
                (0..seq.len() - 1)
                    .rev()
                    .map(|i| {
                        let l = seq[i];
                        let r = seq[i + 1];
                        assert!((r - l) % 2 == 0);
                        (l + 2..r)
                            .filter(move |&i| (i - l) % 2 == 0)
                            .rev()
                            .chain(std::iter::once(l + 1))
                    })
                    .flatten(),
            )
            .chain(std::iter::repeat(0).take(*seq.first().unwrap()))
            .collect();
        println!("{}", steps.len());
        for x in steps {
            println!("{}", x + 1);
        }
    }
}


Measured memory_bytes: 2224
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int A[100001];
int N, M;
ll ans, cnt; 
set<ll> B;

inline ll solve() {
    ans = A[0] - 1;
    M = 2;
    FOR(i, 1, N-1) {
        if(A[i] == M) M++;
        else {
            cnt = A[i] / M;
            ans += cnt;
            if(A[i] - cnt * M == 0) ans--;
        }
    }
    return ans;
}

int main() {
    fastio();
    scanf("%d", &N);
    REP(i, N) scanf("%d", A + i);
    cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define y1 klfjvkldfngldf

#pragma comment(linker, "/STACK:400000000")

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <functional>
#include <numeric>
#include <random>
#include <memory.h>
#include <time.h>

using namespace std;

typedef long long LL;

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

	sort(a.begin(), a.end());

	int last = 0;
	LL s = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		s += a[i];
		if (2 * s < a[i + 1])
			last = i + 1;
	}
	cout << n - last << endl;
	return 0;
}

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

int main(){
    int K,S;
    int ans=0;
    cin >> K >> S;
    for(int X=0;X<=K;X++){
        for(int Y=0;Y<=K;Y++){
            int Z=S-X-Y;
            bool flag=(0<=Z)&&(Z<=K);
            if(flag){
                ans+=1;
            }
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct Info{
	long X;
	long H;
	bool operator<(const Info &another)const{
		return (X < another.X);
	};
};
int main(){
	long N,D,A,x,h,pos,s,t,ave,p;
	long long sum=0;
	long plus[200001]={0};
	vector<Info> info;
	cin>>N>>D>>A;
	D*=2;
	for(int i=0;i<N;i++){
		cin>>x>>h;
		if(h%A==0)h=h/A;
		else h=h/A+1;
		info.push_back({x,h});
	}
	sort(info.begin(),info.end());
	p=0;
	for(int i=0;i<N;i++){
		p+=plus[i];
		info[i].H-=p;
		if(info[i].H<=0)continue;
		pos=info[i].X;
		s=i;
		t=N;
		while(s-t>1||t-s>1){
			ave=(s+t)/2;
			if(info[ave].X<=pos+D)s=ave;
			else t=ave;
		}
		sum+=info[i].H;
		plus[i+1]+=info[i].H;
		plus[s+1]-=info[i].H;
	}
	cout<<sum;
	return 0;
}

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

int main(){
  int n,m,w,s,l,p;
  int dp[400],fr[400],ans[400];
  
  cin >> n;
  for(int i=1;i<=393;i++)fr[i] = 0;

  for(int i=0;i<n;i++){
    cin >> s >> l >> p;
    for(int j=s;j<=l;j++)fr[j] = max(fr[j],p);
  }

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

  for(int i=1;i<=393;i++){
    if(fr[i]){
      for(int j=0;j<=393;j++){
	if(dp[j]>=0)dp[i+j] = max(dp[i+j],dp[j]+fr[i]);
      }
    }
  }

  cin >> m;
  for(int i=0;i<m;i++){
    cin >> w;
    if(dp[w]<0){
      cout << -1 << endl;
      return 0;
    }
    ans[i] = dp[w];
  }

  for(int i=0;i<m;i++)cout << ans[i] << endl;
}

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

int main() {
  int n; cin >>n;
  vector<int> p(n);
  int ans = 0;
  for (int i=0; i<n; i++){
    cin >>p.at(i);
    ans += p.at(i);
  }
  sort(p.begin(), p.end());
  ans -= p.at(n-1) / 2;
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

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

int main(){
    int n, X;
    cin >> n >> X;
    vi x(n+1);
    rep(i, n){
        cin >> x[i];
    }
    x[n] = X;
    Sort(x);
    ll ans = x[1] - x[0];
    rep(i, n){
        ans = gcd(x[i+1]-x[i], ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double r =sc.nextDouble();
		double pi=Math.PI;
		double length=2*r*pi;
		double area=r*r*pi;
		System.out.printf("%f %f",area,length);
		sc.close();
	}

}


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

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

    int tmp1, tmp2, tmp3;
    cin >> tmp1;
    cin >> tmp2;
    
    int result = 0;
    for(int i = 2; i < n;i++){

        cin >> tmp3;

        if((tmp1 < tmp2 && tmp2 < tmp3) || (tmp1 > tmp2 && tmp2 > tmp3)){
            result++;
        }

        tmp1 = tmp2;
        tmp2 = tmp3;
    }

    cout << result << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mo(ll x, ll y)
{
	return max(x, y) - min(x, y);
}
ll n, x, y, t, la = 0, lx, ly;
int main()
{
	cin >> n;
	la = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> t >> x >> y;
		if (la + mo(x, lx) + mo(y, ly) > t || (la + mo(x, lx) + mo(y, ly) - t) % 2 != 0)
		{
			//cout << la + mo(x, lx) + mo(y, ly) << endl;
			cout << "No\n";
			return 0;
		}
		swap(lx, x);
		swap(ly, y);
		swap(la, t);
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
from collections import deque
K=int(input())
d=deque()
for i in range(1,10):
  d.append(i)
ans=0
while ans!=K-1:
  ans+=1
  x=d.popleft()
  if x%10!=0:
    d.append(10*x+x%10-1)
  d.append(10*x+x%10)
  if x%10!=9:
    d.append(10*x+x%10+1)
print(d.popleft())

Measured memory_bytes: 18876
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[5]={-1,0,1,0,0};
int dy[5]={0,-1,0,1,0};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll x,y;cin>>x>>y;
    ll ans=INF;
    for(ll i=0;i<2;i++){
        for(ll j=0;j<2;j++){
            ll xx,yy;
            if(i==0){
                xx=x;
            }
            else xx=-1*x;
            if(j==0){
                yy=y;
            }
            else yy=-1*y;
            if(yy>=xx)
            chmin(ans,i+j+yy-xx);
        }
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































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

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (((int) floor(log10(i)) + 1) & 1) { // floor(log10(i) + 1) counts the number of digits
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int solve(int,int);
int A[20],s;
int n,q;
int main(){

  //int n,q;
  int i,j=0;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&s);
    j=0;

    if(solve(j,s)==1)
      printf("yes\n");

    if(solve(j,s)==0)
      printf("no\n");
  }
  return 0;
}

int solve(int i,int m){

  int res;

  if(m==0)return 1;

  else if(i>=n)return 0;
  res=solve(i+1,m)||solve(i+1,m-A[i]);
}

Measured memory_bytes: 2592
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0) 
#define sz(a) (a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
using namespace std;
 
/*
 tips :
 Sqrt opt
 Binary search
 Try to find the easiest solution
 Recursiya
 FUCK YOU pishi kod akuratnee daun yobani
 sdohni v adu nahui blyat' y ub'uy tebya
 esli ti blyad' budesh pisat' kod gryaznim
 to ya tebya v rot viebu
*/
 
const ll N = 2e5 + 10;
const ll M = 3e3 + 10;
const ll big = 1e18;
const ll shift = 1000;
const ll block = 500;
const ll has = 200123140004043;

const ll mod = 998244353;

mt19937 srnd(chrono::steady_clock::now().time_since_epoch().count()); 

ll n, k;
ll L[12], R[12];
ll dp[N], p[N];

int main() {
    speed;
	cin >> n >> k;
	for(int i = 1; i <= k; i++)
		cin >> L[i] >> R[i];
	dp[1] = p[1] = 1;
	for(int i = 2; i <= n; i++) {
		dp[i] = 0;
		for(int j = 1; j <= k; j++) {
			ll l = i - R[j], r = i - L[j];
			if(r < 0)
				continue;
			l = max(0ll, l);;
			dp[i] += (p[r] - (l ? p[l - 1] : 0) + mod) % mod;
			dp[i] %= mod;			 		
		}
		p[i] = (p[i - 1] + dp[i]) % mod;
	}
	cout << dp[n];	
}             
                     
 
/*
6 0
1 2 4 6 8 10
1 4  d
*/ 

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

void input(int& rnMaxNum, int& rnBase)
{
  cin >> rnMaxNum >> rnBase;
}

llong calcNumOfCase(int nMaxNum, int nBase)
{
  llong nNumOfCase = 0;
  int nTerm;

  if (nBase % 2 == 0)
  {
//    an = a1 + (n - 1)d
//    nMaxNum = (nBase / 2) + (n - 1)nBase  
     if ( nMaxNum - (nBase / 2) >= 0 )
     {
       nTerm = ( nMaxNum - (nBase / 2) ) / nBase + 1;
       nNumOfCase += (llong)nTerm * nTerm * nTerm;
     }
  }
  nTerm = nMaxNum / nBase;
  nNumOfCase += (llong)nTerm * nTerm * nTerm;

  return nNumOfCase;
}
  
int main()
{
  int nMaxNum, nBase;
  
  input(nMaxNum, nBase);
  cout << calcNumOfCase(nMaxNum, nBase) << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <random>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define absi(x, y)    ((x) > (y) ? ((x) - (y)) : ((y) - (x)))

typedef long long ll;
ll map[101][101] = {0};

void g(u64 x, u64 y);

void f(u64 x, u64 y, u64 h) {
	if(h == 0) {
		g(x, y);
		return;
	}

	rep(i, 101) {
		rep(j, 101) {
			if(map[i][j] == 0) continue;
			u64 h0 = h + absi(x, i) + absi(y, j);
			if(map[i][j] != h0) {
				map[i][j] = 0;
			}
		}
	}
}


void g(u64 x, u64 y) {
	rep(i, 101) {
		rep(j, 101) {
			if(map[i][j] == 0) continue;
			u64 h0 = absi(x, i) + absi(y, j);
			if(map[i][j] > h0) {
				map[i][j] = 0;
			}
		}
	}
}

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;

	ll x[n], y[n], h[n];
	rep(i, n) cin >> x[i] >> y[i] >> h[i];
	rep(i, n) {
		if(h[i] != 0) {
			swap(x[0], x[i]);
			swap(y[0], y[i]);
			swap(h[0], h[i]);
			break;
		}
	}

	rep(i, 101) {
		rep(j, 101) {
			map[i][j] = h[0] + absi(x[0], i) + absi(y[0], j);
		}
	}

	repd(i, 1, n) {
		f(x[i], y[i], h[i]);
	}

	ll x0 = 0;
	ll y0 = 0;
	ll h0 = 0;
	rep(i, 101) {
		rep(j, 101) {
			if(map[i][j] > h0) {
				x0 = i;
				y0 = j;
				h0 = map[i][j];
			}
		}
	}

	cout << x0 << " " << y0 << " " << h0 << endl;
	return 0;
}


Measured memory_bytes: 384
N = gets.to_i
ls = gets.split(' ').map(&:to_i).sort.reverse!
count = 0
(0..(N - 3)).each do |a|
  ((a + 1)..(N - 2)).each do |b|
    limit = ls[a] - ls[b]
    i = ls.bsearch_index { |c| c <= limit } || N
    count += i - 1 - b if i > b + 1
  end
end
p count

Measured memory_bytes: 1912
from collections import deque
from bisect import bisect_left, bisect_right

n,m,k = map(int, input().split())

al = list(map(int, input().split()))
bl = list(map(int, input().split()))

al_sums = [0]*(n+1)
bl_sums = [0]*(m)

curr_sum = 0
for i,a in enumerate(al):
    curr_sum += a
    al_sums[i+1] = curr_sum

curr_sum = 0
for i,b in enumerate(bl):
    curr_sum += b
    bl_sums[i] = curr_sum

# print(al_sums)
# print(bl_sums)


ans = 0
for i in range(n+1):
    a_sum = al_sums[i]
    if a_sum > k: continue
    cnt = bisect_right(bl_sums, k-a_sum)
    curr_ans = i+cnt
    # print(i,curr_ans, k-a_sum)
    ans = max(ans,curr_ans)

print(ans)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<string> s(N);
    REP(i, N) cin >> s[i];
    REP(i, N) sort(s[i].begin(), s[i].end());
    sort(s.begin(), s.end());

    //cout << s << endl;

    ll res = 0;
    for(int i=0;i<N;i++){
    	int j = i;
    	while(j<N && s[i]==s[j]) j++;
    	ll tmp = j - i;
    	res += tmp*(tmp-1)/2;
    	i = j-1;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5760
from math import cos, sin, pi, sqrt
B = ["BC", "CD", "DB"]
XY0, d0, l0, XY1, d1, l1 = open(0).read().split()
d0, l0, d1, l1 = map(int, [d0, l0, d1, l1])

def calc(XY, d, l):
    angle = B.index(XY) * 60 + d
    x = l * cos(pi*angle/180)
    y = l * sin(pi*angle/180)
    x = x + y/sqrt(3)
    y = y * 2/sqrt(3)
    x = x%2; y = y%2
    A = [["AC", "BD"], ["DB", "CA"]][int(x)][int(y)]
    return A[x%1>y%1]
print("YES"*(calc(XY0, d0, l0)==calc(XY1, d1, l1))or"NO")

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

int main(){
  int N;
  cin >> N;
  vector< pair<int,int> > A(N);
  int a;
  for(int i = 0; i < N; ++i){
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end());
  vector<int> ans(N);
  for(int i = 0; i < N; ++i){
    if(i < N/2) ans[A[i].second] = A[N/2].first;
    else ans[A[i].second] = A[N/2-1].first;
  }
  for(int i = 0; i < N; ++i){
    cout << ans[i] << endl;
  }
  return 0;
}


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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  double r1, r2; cin >> r1 >> r2;
  
  cout << setprecision(20) << r1 * r2 / (r1 + r2) << '\n';
  
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;

    vector<int> L(N, 0);  // 左から貪欲に働いたときの仕事日
    vector<int> R(N, 0);  // 右から貪欲に働いた仕事日

    int cnt = 1;
    REP(i, N){
        if(S[i] == 'o'){
            L[i] = cnt;
            i += C;
            ++cnt;
        }
    }

    cnt = K;
    for(int i = N-1; i >= 0; --i){
        if(S[i] == 'o'){
            R[i] = cnt;
            i -= C;
            --cnt;
        }
    }

    REP(i, N){
        if(L[i] != 0 and L[i] == R[i]) cout << i+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5212
import sys

def solve():
    input = sys.stdin.readline
    X = int(input())
    A = int(input())
    B = int(input())
    moneyLeft = X
    moneyLeft -= A
    while moneyLeft - B >= 0:
        moneyLeft -= B

    print(moneyLeft)

    return 0

if __name__ == "__main__":
    solve()

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

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;

		static void Main(string[] args)
		{
			var str = R;
			var n = RI;
			for (int i = 0; i < str.Length; i += n)
			{
				Console.Write(str[i]);
			}
			Out("");
		}
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int a, b, t;
  cin >> a >> b >> t;
  int time = 0;
  int ans = 0;
  while(time + a <= t){
    time += a;
    ans += b;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int A[4];

void MAIN() {
    REP (i, 4) scanf("%d", A+i);
    sort(A, A+4);

    bool yes = (A[0] == 1 && A[1] == 4 && A[2] == 7 && A[3] == 9);
    puts(yes?"YES":"NO");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

import sys

input = sys.stdin.readline

def main():
    l, r = map(int, input().split())
    m = 2000000000

    if (r - l) > 2019:
        r = l + 2019

    for i in range(l, r):
        for j in range(i+1, r+1):
            m = min(m, (i*j) % 2019)
    print(m)

main()


Measured memory_bytes: 38896
def printList(array):
    print(' '.join(map(str, array)))

def bubbleSort(A, N):
    needToContinue = True
    swapCount = 0
    while needToContinue:
        needToContinue = False
        for index in range(N - 1, 0, -1):
            if A[index] < A[index - 1]:
                A[index], A[index - 1] = A[index - 1], A[index]
                swapCount += 1
                needToContinue = True
    printList(A)
    print(str(swapCount))


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    bubbleSort(A, N)


Measured memory_bytes: 5600
use proconio::input;
fn main() {
    input! {
        n: usize,
        k: usize,
        ab: [(usize,usize); n]
    }
    let mut ab: Vec<(usize, usize)> = ab;
    ab.sort_by(|a, b| (a.0).cmp(&b.0));
    let mut count = 0;
    for i in 0..n {
        count += ab[i].1;
        if k <= count {
            println!("{}", ab[i].0);
            return;
        }
    }
}


Measured memory_bytes: 5456
#include <stdio.h>

int main(){
    int quero, faco, tempo, tot = 0, quant = 0;
    scanf("%d%d%d", &quero, &faco, &tempo);
    for(;;){
            tot = tot + tempo;
            quant = quant + faco;
            if(quant >= quero)
                break;
        
    }
        printf("%d", tot);

    return 0;
}

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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    if(n == 1)  cout << abs(a[0] - w) << endl;
    else    cout << max(abs(a[n-1]-w), abs(a[n-1]-a[n-2])) << endl;
}

Measured memory_bytes: 256