akhauriyash/Code-Regression huggingface dataset:
import kotlin.math.max

fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val (n, k) = intList()
    val s = readLine() ?: return
    val memo = mutableListOf<Int>()
    val k2 = k * 2
    var c = 0
    var i = 0
    var flag = s.first().toString().toInt()
    s.forEach {
        when (it) {
            '0' -> {
                if (flag == 1) {
                    memo.add(c)
                    c = 0
                    i++
                    flag = 0
                }
                c++
            }
            '1' -> {
                if (flag == 0) {
                    memo.add(c)
                    c = 0
                    i++
                    flag = 1
                }
                c++
            }
        }
    }
    memo.add(c)

    val f1 = s.first() == '1'
    var m = 0
    var p = -1
    0.until(memo.size).forEach { index ->
        val k3 = k2 + if (f1) {
            if (index % 2 == 0) {
                1
            } else {
                0
            }
        } else {
            if (index % 2 == 0) {
                0
            } else {
                1
            }
        }
        if (p == -1) {
            p = 0
            repeat(k3) { j ->
                p += memo.getOrElse(j) { 0 }
            }
        } else {
            if (k2 == k3) {
                p -= memo.getOrElse(index - 1) { 0 }
            } else {
                p =
                    p - memo.getOrElse(index - 1) { 0 } + memo.getOrElse(index + k3 - 2) { 0 } + memo.getOrElse(index + k3 - 1) { 0 }
            }
        }
        m = max(m, p)
    }
    println(m.toString())
}


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int main(){
	int n;cin>>n;
	ll sum=0;
	rep(i,n){
		int v;cin>>v;
		sum+=v-i-1;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b)
{
    if (b == 0)
        return 1;
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
        return res * a;
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int ans[10001],t;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    for (int i=1;i<10001;++i)
        for (int j=1;i*i+j*j+i*j<10001;++j)
        {
            t=i*i+j*j+i*j;
            for (int k=1;t+k*k+i*k+j*k<10001;++k)
                ++ans[t+k*k+i*k+j*k];
        }
    int n;
    cin>>n;
    for (int i=1;i<=n;++i)
        cout<<ans[i]<<"\n";
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include <algorithm> 
using namespace std;
int main()
{
	int n,i,j,k,count=0;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n-2;i++)
	{
		for(j=i+1;j<n-1;j++)
		{
			for(k=j+1;k<n;k++)
			{
				if(a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k])
				{
					if((a[i]+a[j])>a[k])
					{
						if((a[i]+a[k])>a[j])
						{
							if((a[j]+a[k])>a[i])
							{
								count++;
							}
						}
					}
				}
			}
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main()
{
int x = 0;
char a[5];

    
	scanf("%s", a);

	for(int i = 0; i < 4; i++)
	{
		if (a[i] == '+')
		{
			x++;
		}
		else if (a[i] == '-')
		{
			x--;
		}
	}
	printf("%d", x);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=int64_t;

int group(int x) {
  int ret_val;
  switch (x) {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
      ret_val=0;
      break;
    case 4:
    case 6:
    case 9:
    case 11:
      ret_val=1;
      break;
    case 2:
      ret_val=2;
      break;
    default:
      break;
  }
  return ret_val;
}

int main() {
  int x,y; cin >>x >>y;
  cout <<(group(x)==group(y) ? "Yes":"No") <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int k;
	while(scanf("%d", &k)==1)
	{
		vll a(1);
		vi l(1);

		a.reserve(k+1);
		l.reserve(k+1);
		for(int i=1;i<=9;i++)
		{
			a.push_back(i);
			l.push_back(i);
		}
		for(int s=1;a.size()<=k;s++)
		{
			for(int t=l[s]-1;t<=l[s]+1;t++)
			{
				if(t<0 || t>9) continue;
				a.push_back(a[s]*10+t);
				l.push_back(t);
			}
		}
//for(ll ma:a) printf(" %lld", ma); printf("\n");
		printf("%lld\n", a[k]);
	}
	return 0;
}


Measured memory_bytes: 2176
#include<stdio.h> 
int main()
 {
	int a,i,j; 
	for(i=1;i<=9;i++)
	{ 
		for(j=1;j<=9;j++)
		{ 
			printf("%dx%d=%d",i,j,i*j);
			printf("\n");
		}
	} 
return 0; 
} 

Measured memory_bytes: 524
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
//i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
//vector <i64> dp;


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


    //cin >> T;
    T = 1;

    for (i64 tt = 0; tt < T; ++tt) {

        string s, t;
        cin >> s;
        cin >> t;

        i64 res = t.size();

        for (i64 i = 0; i <= s.size() - t.size(); ++i) {
            i64 x = 0;
            for (i64 j = 0; j < t.size(); ++j) {
                if (s[j+i] != t[j]) {
                    x += 1;
                }
            }
            res = min(res, x);
        }


        cout << res << endl;

    }
    return 0;
}

Measured memory_bytes: 3200
N=int(input())
d_i=[]
d=input()
d=d.split(" ")
for i in d:
 d_i.append(int(i))

count=0
for i in range(0,N):
 for j in range(i+1,N):
  count+=d_i[i]*d_i[j]

print(count)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin>>A>>B;
    if(A==B)
        cout<<"Draw";
    else if(A==1)
        cout<<"Alice";
    else if(B==1)
        cout<<"Bob";
    else if(A>B)
        cout<<"Alice";
    else
        cout<<"Bob";
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
  ll n, x;
  cin >> n >> x;
  int ans = 0;
  vector<ll> a(n);
  ll y = x;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    y -= a[i];
  }
  if (y == 0) {
    cout << n << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    if (x >= a[i]) {
      ans++;
    }
    x -= a[i];
  }
  if (x > 0)
    ans--;
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N, K;
int A[500];
inline bool keisan(int k) {
	int a[500];
	int ouchaku = 0;
	rep(j, N) {
		a[j] = A[j] % k;
		ouchaku += min(a[j], k - a[j]);
		if (ouchaku > K + K) return false;
	}
	sort(a, a + N);
	int x = 0, y = N - 1;
	int tmp = a[0] + a[N - 1] - k;
	int kazu = a[0] + k - a[N - 1];
	while (x + 1 < y) {
		if (tmp <= 0) {
			tmp += a[++x];
			kazu += a[x];
		}
		else {
			tmp += a[--y] - k;
			kazu += k - a[y];
		}
	}
	if (kazu / 2 <= K) {
		printf("%d", k);
		return true;
	}
	return false;
}

const int cm = 1 << 12;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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

	fread_unlocked(cn, 1, cm, stdin);

	N = getint();
	K = getint();
	int goukei = 0;
	rep(i, N) {
		A[i] = getint();
		goukei += A[i];
	}

	int yakusuu[15000];
	int M = 0;
	int sq = sqrt(goukei);
	rep1(i, sq) {
		if (goukei % i == 0) {
			yakusuu[M++] = i;
			if (i * i != goukei) {
				if (keisan(goukei / i)) return 0;
			}
		}
	}

	for (int i = M - 1; i >= 0; i--) {
		if (keisan(yakusuu[i])) return 0;
	}

	Would you please return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b >= c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

char a[2048][2048];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, d; cin >> n >> m >> d;
	if (d & 1) {
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
			if ((i + j) & 1) a[i][j] = 'R';
			else a[i][j] = 'G';
		}
	} else {
		int x = d;
		for (int i = 0; i < d / 2; i++) {
			for (int j = 0; j < d + d; j++) {
				if (j < i) a[i][j] = 'B';
				else if (j < i + x) a[i][j] = 'R';
				else if (j < i + d) a[i][j] = 'Y';
				else if (j < i + d + x) a[i][j] = 'G';
				else a[i][j] = 'B';
			}
			x -= 2;
		}
		for (int i = d / 2; i < d; i++) {
			for (int j = 0; j < d + d; j++) {
				if (j < d - i) a[i][j] = 'B';
				else if (j < d - i + x) a[i][j] = 'G';
				else if (j < d - i + d) a[i][j] = 'Y';
				else if (j < d - i + d + x) a[i][j] = 'R';
				else a[i][j] = 'B';
			}
			x += 2;
		}
		for (int i = d; i < d + d; i++) for (int j = 0; j < d + d; j++) {
			a[i][j] = a[i - d][j];
			if (a[i][j] == 'R') a[i][j] = 'G';
			else if (a[i][j] == 'G') a[i][j] = 'R';
			else if (a[i][j] == 'B') a[i][j] = 'Y';
			else a[i][j] = 'B';
		}
		for (int i = 0; i < d + d; i++) for (int j = d + d; j < m; j++) a[i][j] = a[i][j - d - d];
		for (int i = d + d; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = a[i - d - d][j];
	}
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
cout << a[i][j];
if (j == m - 1) cout << endl;
}
//	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) for (int u = 0; u < n; u++) for (int v = 0; v < m; v++) if (abs(i - u) + abs(j - v) == d) {
//		if (a[i][j] == a[u][v]) cerr << i << " " << j << " " << u << " " << v << endl;
//		assert(a[i][j] != a[u][v]);
//	}
	return 0;
}



Measured memory_bytes: 7460
string = input()
pos = int(input())

while pos > 1 and (len(string) > 0 and string[0] == '1'):
  pos -= 1
  string = string[1:]
  
if len(string) == 0:
  print('1')
elif pos == 1:
  print(string[0])
elif string[0] == '1' and len(string) > 1:
  print(string[1])
else:
  print(string[0])

Measured memory_bytes: 3064
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, log2
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,M = map(int, input().split())
    A = []
    list(map(lambda x: heappush(A, -1*int(x)), input().split()))
    for _ in range(M):
        a = -1*heappop(A)
        heappush(A, a//2 * -1)
    ans = 0
    for _ in range(N):
        ans += -1 * heappop(A)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 17516
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(N);
  for(int i = 0; i < N; i++)cin >> data.at(i);
  long count = 1;
  long ans = -1;
  for(int i = 0; i < N; i++){
    if(data.at(i) == count)count++;
  }
  if(count == 1)cout << -1 << endl;
  else cout << N - count + 1 << endl;
  return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long M = long.Parse(str[1]);
		long ans = (N-1)/M+1;
		Console.WriteLine(ans);
	}
}


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


def main():
    s = input()
    t = s[::-1]
    n = len(s) // 2
    count = 0

    for i in range(n):
        if s[i] != t[i]:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9116
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		long all = scan.nextLong();
		long left = 0;
		long right = 0;
		for (int i = 0; i < all; i++) {
			long a = scan.nextLong();
			String p = scan.next();
			long num = scan.nextLong();
			if (p.equals("(")) {
				left += num;
			} else {
				right += num;
			}

			if (left == right) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		}
		scan.close();

	}
}

Measured memory_bytes: 46560
N=int(input())
A=list(map(int,input().split()))
ans=0
mins=10**10
ct=0
for i in A:
 ans+=abs(i)
 mins=min(mins,abs(i))
 if i<0:
  ct+=1
if ct%2==1:
 ans-=2*mins
print(ans)

Measured memory_bytes: 84740
import heapq
N,M=map(int, input().split())
H = [[] for _ in range(M)]

for _ in range(N):
  A,B = map(int, input().split())
  if A <= M:
    H[A-1].append(-B)
Q=[]
r=0
for d in range(M):
  for v in H[d]:
    heapq.heappush(Q, v)
  if Q:
    r -= heapq.heappop(Q)
print(r)

Measured memory_bytes: 17604
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n;
  cin >> n;
  vector<int> v(n);
  cin >> v;
  int all_xor = 0;
  for (int x : v) {
    all_xor ^= x;
  }
  for (int x : v) {
    cout << (x ^ all_xor) << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;

const int INF = 1LL << 40;
const int MOD = 1e9 + 7;
const int N = 3001;
int a[N], n;
int dp[N][N][2];

//f takes left, right, cur player and returns min x - y

int f(int l, int r, int p) {
    if(l == r)  
        return a[l];
    int &ans = dp[l][r][p];
    if(ans != -1) return ans;
    ans = max(a[l] - f(l + 1, r, 1 - p), a[r] - f(l, r - 1, 1 - p));
    return ans;
}

signed main() {
    
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
        
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            dp[i][j][0] = dp[i][j][1] = -1;
    
    cout << f(1, n, 0) << endl;
    
    return 0;
}

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


int main() {
    int n;  cin >> n;
    int ans = 0;

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

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

    ans += p.back() / 2;
    for (int i=0; i<n-1; i++) ans += p[i];

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

Measured memory_bytes: 256
import math

ang = int(input())
rad = ang/360*(2*math.pi)

k = 1
x = 1.0
y = 0.0
current = 0
while round(x,3) != 0.0 or round(y,3) != 0.0:

    current += rad
    x += math.cos(current)
    y += math.sin(current)

    k+=1

print(k)

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

using namespace std;

int main(){
  int e;

  while(1)
    {
      cin >> e;
      if(e == 0)break;
      int mini = INT_MAX;
      for(int z=0;z*z*z <= e;z++)
	{
	  for(int y=0;y*y<= e-(z*z*z);y++)
	    {
	      int x = e - y*y - z*z*z;
	      mini = min(mini,x+y+z);
	    }
	}
      cout << mini << endl;
    }
  return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>

int main(void) {
    int i, a, b, c, d, n;

    while(scanf("%d", &n) != EOF) {
        i = 0;
        for(a = 0; a <= 9; a++) {
            for(b = 0; b <= 9; b++) {                                                                                                                                    
                for(c = 0; c <= 9; c++) {
                    for(d = 0; d <= 9; d++) {
                        if(a + b + c + d == n) i++;
                    }   
                }   
            }   
        }   
        printf("%d\n", i); 
    }   

    return 0;
}

Measured memory_bytes: 596
import sys
import bisect


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    t = 0
    for i in range(n):
        for j in range(i + 1, n - 1):
            p = bisect.bisect_left(l, l[i] + l[j])
            t += p - (j + 1)
    print(t)


if __name__ == '__main__':
    solve()


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


int main()
{
    ll M;
    cin >> M;

    ll res = 0;
    stack<ll> st;

    auto way1 = [&](ll c) {
        if (c == 0)return;
        ll n = (c - 1) / 9;
        res += 10 * n;
        ll left = c - 9 * n;
        rep(i, left)st.push(1);
    };
    auto way3 = [&](ll c) {
        if (c == 0)return;
        ll n = (c - 1) / 3;
        res += 4 * n;
        ll left = c - 3 * n;
        rep(i, left)st.push(3);
    };

    rep(i, M) {
        ll d, c, n, left;
        cin >> d >> c;

        switch (d) {
        case 1:
            way1(c);
            break;
        case 2:
            n = c / 5;
            res += 5 * n;
            way1(n);
            left = c - 5 * n;
            rep(i, left)st.push(2);
            break;
        case 3:
            way3(c);
            break;
        case 4:
            n = c / 3;
            res += 3 * n;
            way3(n);
            left = c - 3 * n;
            rep(i, left)st.push(4);
            break;
        case 5:
            n = c / 2;
            res += 2 * n;
            way1(n);
            left = c - 2 * n;
            rep(i, left)st.push(5);
            break;
        case 6:
            n = c / 2;
            res += 2 * n;
            way3(n);
            left = c - 2 * n;
            rep(i, left)st.push(6);
            break;
        case 7:
            n = c / 4;
            res += 6 * n;
            way1(n);
            left = c - 4 * n;
            rep(i, left)st.push(7);
            break;
        case 8:
            n = c / 8;
            res += 14 * n;
            way1(n);
            left = c - 8 * n;
            rep(i, left)st.push(8);
            break;
        case 9:
            n = c - 1;
            res += 2 * n;
            st.push(9);
            break;
        case 0:
            n = c - 1;
            res += n;
            st.push(0);
            break;
        }
    }
    while (st.size() >= 2) {
        ll r = st.top(); st.pop();
        ll l = st.top(); st.pop();
        ll now = l + r;
        res++;
        if (now >= 10)st.push(now / 10);
        st.push(now % 10);
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 7168
#include <stdio.h> 

int main(void) 
{ 

 int intInput;
 int intAnswer;

 scanf("%d",&intInput);

 if (1 <= intInput && intInput <= 100)
 {
 intAnswer = intInput*intInput*intInput;
 
  printf("%d\n",intAnswer); 
 }
  return 0; 

} 


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

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

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    double men = x / a;
    double ans;
    if(men<=a*b/2){
        ans = 90 - atan(2*men/(b*b)) * 180 / M_PI;
    }else{
        double tmp = 2 * men / a;
        ans = 90 - atan(a / (2 * b - tmp)) * 180 / M_PI;
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	int N;
	long long W, weight[110], value[110];
	cin >> N >> W;
	for(long long i = 0; i < N; i++)cin >> weight[i] >> value[i];
	long long dp[110][100100] = {0};
	
	for(long long i = 0; i < N; i++){
		for(long long sum_w = 0; sum_w <= W; sum_w++){
			if(sum_w - weight[i] >= 0){
				dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
			}
			dp[i + 1][sum_w]= max(dp[i + 1][sum_w], dp[i][sum_w]);
		}
	}
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
int main(){
	int P = 43; 
	cout << P * (P+1) + 1 << " " << P+1 << endl; 
	for(int i = 1; i <= P+1; i++){
		cout << i << " "; 
	}
	cout << endl; 
	for(int i = 1; i <= P; i++){
		cout << 1 << " ";
		for(int j = 2; j <= P+1; j++){
			cout << i * P + j << " "; 
		}
		cout << endl; 
	}
	for(int i = 0; i < P; i++){
		for(int j = 0; j < P; j++){
			cout << i+2 << " "; 
			for(int k = 0; k < P; k++){
				cout << P+2 + k*P + ((j + i * k) % P) << " "; 
			}
		cout << endl; 
		}
	}
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  ll n; cin >> n;
  
  if(n < 1200) cout << "ABC" << endl;
  else if(n < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}

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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((a + b + c) - max(a, max(b, c)) == max(a, max(b, c)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>
 
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
 
using namespace std;

mt19937 rr(random_device{}());

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

int main() {    
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);    
    cout.tie(0);

    string s;
    cin >> s;
    int n = sz(s);
    vector<int> cnt(26);
    ll ans = (ll)n * (n + 1) / 2 + 1;
    for (int i = 0; i < n; ++i)
        ++cnt[s[i] - 'a'];
    for (int i = 0; i < 26; ++i)
        ans -= (ll)cnt[i] * (cnt[i] + 1) / 2;
    cout << ans << endl;


 
    return 0;
}

Measured memory_bytes: 720
#include <stdio.h>

int main(void) {
  int a, b, x, ans = 1e9;
  scanf("%d%d%d", &a, &b, &x);
  ans = (x + 999) / 1000 * a;
  if(ans > (x + 499) / 500 * b) ans = (x + 499) / 500 * b;
  if(ans > x / 1000 * a + (x % 1000 + 499) / 500 * b) ans = x / 1000 * a + (x % 1000 + 499) / 500 * b;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2768
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

int ans;
int N, K;

int main(void) {
    scanf("%d %d", &N, &K);

    REP(i, 0, N) {
    	int h;
    	scanf("%d", &h);
    	if (h >= K) ans++;
    }
    
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 384
/*      西江月·证明
	即得易见平凡，仿照上例显然。
   留作习题答案略， 读者自证不难。

	反之亦然同理，推论自然成立。
	略去过程QED，由上可知证毕。*/
# pragma GCC optimize (1)
# pragma GCC optimize (2)
# pragma GCC optimize (3)
# pragma GCC optimize ("Ofast")
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#define kkk register
#define ll long long
#define inf 2147098934832ll
using namespace std;
ll read(){ll ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=-1;a=getchar();}while(a>='0'&&a<='9')ans=(ans<<3)+(ans<<1)+a-'0',a=getchar();return ans*f;}
//一条long long的黄金分割线-----------------------------------------------------------------------------------------------------------------------------------
ll n,a[1000005],cnt;
ll mod(ll x){
    return x%26==0?26:x%26;
}
int main(){
	n=read();
	while(n){
		a[++cnt]=mod(n);
		n=(n-mod(n))/26;
	}
	for(int i=cnt;i>=1;i--)cout<<char(a[i]+'a'-1);cout<<endl;
	return 0; 
} 

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

int main()
{
	int n, s, t = 0;
	int a[2][100];

	cin >> n;

	for(int i = 0; i < 2; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];

	for (int i = 0; i < n; i++) {
		s = 0;
		for (int j = 0; j < i + 1; j++)
			s += a[0][j];
		for (int j = i; j < n; j++)
			s += a[1][j];
		if (t < s)
			t = s;
	}

	cout << t << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int n, k, x, y;
	
	cin >> n >> k >> x >> y;

	if (n > k) {

	cout << (k * x) + (n-k)*y << endl;
	}
	else {
		cout << n * x << endl;
	}

	return 0;
}



Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#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 <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
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[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string a,b;cin>>a>>b;
    int dp[3003][3003];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=a.length();i++){
        for(int j=1;j<=b.length();j++){
            if(b[j-1]==a[i-1]){
                dp[i][j]=dp[i-1][j-1]+1;
                
            }
else
    dp[i][j]=std::max(dp[i-1][j],dp[i][j-1]);
 
        }
    }
    int cnt=dp[a.length()][b.length()];
    string ans="";
    int x=a.length(),y=b.length();
    while(x&&y){
        if(dp[x][y]==dp[x-1][y])x--;
        else if(dp[x][y]==dp[x][y-1])y--;
        else{
            ans=a[x-1]+ans;
            x--;y--;
            
        }
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {
    private static final int INF = 100000;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] coins = new int[m];
        for(int i = 0; i < m; i++) {
            coins[i] = sc.nextInt();
        }

        int[][] dp = new int[m][n + 1];
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n + 1; j++) {
                dp[i][j] = INF;
            }
        }
        dp[0][0] = 0;

        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n + 1; j++) {
                if(i > 0) dp[i][j] = dp[i - 1][j];
                if(j >= coins[i]) dp[i][j] = Math.min(dp[i][j], dp[i][j - coins[i]] + 1);
            }
        }

        System.out.println(dp[m - 1][n]);

        sc.close();
    }
}


Measured memory_bytes: 31224
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    if(a+b+1!=s.length()){
        cout <<"No";
        return 0;
    }
    if(s[a]!='-'){
        cout << "No";
        return 0;
    }
    for(int i=0;i<a;i++){
        if(s[i]=='-'){
            cout << "No";
            return 0;
        }
    }
    for(int i=a+1;i<a+b+1;i++){
        if(s[i]=='-'){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        if(input.endsWith("s")){
            System.out.println(input + "es");
        }else{
            System.out.println(input+"s");
        }

    }

}


Measured memory_bytes: 38504
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n;
string str;

int main(){
	cin >> n >> str;
	ll cntR = 0;
	ll cntB = 0;
	for(ll i = 0; i < n; i++){
		if(str[i] == 'R'){cntR++;}
		else{cntB++;}
	}
	if(cntR > cntB){cout << "Yes" <<endl;}
	else{cout << "No" << endl;}
	return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
cnt = [0] * 3
N = int(input())
A = list(map(int,input().split()))

ans = 1
for i in range(N):
    ans *= cnt.count(A[i])
    ans %= mod
    if ans == 0:
        break
    cnt[cnt.index(A[i])] += 1

print(ans)

Measured memory_bytes: 20708
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val a = io.StdIn.readLine().split(" ").map(_.toInt)
    val count = selectionSort(a, n)
    println(a.mkString(" "))
    println(count)
  }

  def selectionSort(a: Array[Int], n: Int): Int = {
    (0 until n).count { i =>
      val minIdx = (i until n).foldLeft(i) { case (z, j) =>
        if (a(j) < a(z)) j
        else z
      }
      if (i != minIdx) {
        val v = a(i)
        a(i) = a(minIdx)
        a(minIdx) = v
        true
      } else {
        false
      }
    }
  }
}

Measured memory_bytes: 44100
#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 < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

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

	ll tmp = 0;
	ll x = N;
	while(x>0){
		tmp += (x%10);
		x /= 10;
	}
	cout << (N%tmp==0?"Yes":"No") << endl;
    return 0;
}

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

typedef long long ll;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a!=2 && b!=2){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }

  return 0;
}



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

signed main(){
  int N;
  cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int ans1=0;
  int ans2=0;
  int k=0;
  for(int i=0;i<N;i++){
    k+=v[i];
    if(i%2){if(k<=0){ans1+=1-k;k+=1-k;}}
    else{if(k>=0){ans1+=1+k;k-=1+k;}}
  }
  k=0;
  for(int i=0;i<N;i++){
    k+=v[i];
    if(i%2==0){if(k<=0){ans2+=1-k;k+=1-k;}}
    else{if(k>=0){ans2+=1+k;k-=1+k;}}
  }
  cout<<min(ans1,ans2)<<endl;
}


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

int main(){
    int n;
    cin >> n;
    multiset<int> s;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        s.insert(x);
    }
    int diam = *s.rbegin();
    bool even = diam%2==0;
    int to = diam/2+1;
    while(diam >= to){
        bool valid = s.size() >= 2;
        for(int i = 0; i < 2; i++){
            if(valid && s.count(diam))      s.erase(s.find(diam));
            else                            valid = false;
        }
        if(!valid){
            cout << "Impossible" << endl;
            return 0;
        }
        diam--;
    }
    if(even){
        if(s.size() == 0 || s.count(to-1) == 0){
            cout << "Impossible" << endl;
            return 0;
        }else{
            s.erase(s.find(to-1));
        }
    }else{
        to++;
    }
    cout << (s.size() == 0 || *s.begin() >= to ? "Possible" : "Impossible") << endl;
    return 0;
}

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

struct SegTree{

    int sz;
    vector<long long> dat,laz;

    SegTree(){
        sz=1<<18;
        dat.resize(sz<<1);
        laz.resize(sz<<1);
    };

    void upd(int id,int l,int r,int ql,int qr,long long val){
        if(qr<l||r<ql)return;
        if(ql<=l&&r<=qr){
            laz[id]+=val;
            dat[id]+=val;
            return;
        }
        laz[id<<1]+=laz[id];
        dat[id<<1]+=laz[id];
        laz[id<<1|1]+=laz[id];
        dat[id<<1|1]+=laz[id];
        laz[id]=0;
        upd(id<<1,l,l+r>>1,ql,qr,val);
        upd(id<<1|1,(l+r>>1)+1,r,ql,qr,val);
        dat[id]=min(dat[id<<1],dat[id<<1|1]);
    }

    long long qry(int id,int l,int r,int ql,int qr){
        if(qr<l||r<ql)return 1e18;
        if(ql<=l&&r<=qr){
            return dat[id];
        }
        laz[id<<1]+=laz[id];
        dat[id<<1]+=laz[id];
        laz[id<<1|1]+=laz[id];
        dat[id<<1|1]+=laz[id];
        laz[id]=0;
        return min(qry(id<<1,l,l+r>>1,ql,qr),qry(id<<1|1,(l+r>>1)+1,r,ql,qr));
    }

    void upd(int l,int r,long long d){
        upd(1,1,sz,l,r,d);
    }

    long long qry(int l,int r){
        return qry(1,1,sz,l,r);
    }
};

int n,m;
int a[200005],b[200005];
SegTree upd,qry;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    for(int i=1;i<=m;i++)upd.upd(i,i,m-i);
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        qry.upd(b[i]+1,b[i]+1,min(upd.qry(1,b[i])-(m-b[i]-1)-qry.qry(b[i]+1,b[i]+1),0ll));
        upd.upd(b[i]+1,b[i]+1,min(upd.qry(1,b[i])-upd.qry(b[i]+1,b[i]+1),0ll));
        qry.upd(a[i],b[i],1e9);
        upd.upd(a[i],b[i],1e9);
        qry.upd(1,m,1);
        upd.upd(1,m,1);
        if(qry.qry(1,m)>=1e9)cout<<"-1\n";
        else cout<<qry.qry(1,m)<<'\n';
    }

    return 0;
}

Measured memory_bytes: 21192
{
  const main = (input: string) => {
    const r = reader(input)
    const X = r.n()
    const a: { [n: number]: boolean } = { 0: true }
    for (let i = 0; i < X; i++) {
      if (!a[i]) {
        continue
      }
      a[i + 100] = true
      a[i + 101] = true
      a[i + 102] = true
      a[i + 103] = true
      a[i + 104] = true
      a[i + 105] = true
    }
    console.log(a[X] ? 1 : 0)
  }

  // const values = obj => Object.keys(obj).map(e => obj[e]);

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const line = s
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    return { lines, line, s, n, ss, ns }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  main(getInput())
}


Measured memory_bytes: 13644
N = int(input())
S = list(input() for i in range(N))

S.sort()
count = 0
hoge = ""
ans = [""]
ansnum = -1
for c in S:
    if hoge == c:
        count += 1
    else:
        count = 1
        hoge = c
    if count > ansnum:
        ans = [c]
        ansnum = count
    elif count == ansnum:
        ans.append(c)

ans.sort()
for i in ans:
    print(i)



Measured memory_bytes: 20688
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    if(a < b and b < c ){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 3084
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

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

    if(n >= 10){
        System.out.println(r);
    }else{
        System.out.println(r + (100*(10-n)));
    }
    }
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
//const int mod=1e9+7;
                     // I'm in Love with Experience. 
void solve()
{
    int N;cin>>N;
    int A[N]; for(int i=0;i<N;cin>>A[i++]){}
    sort(A,A+N,greater<int>());
    long ans=0,a=0;
    for(int i=1;i<N;++i)
    {
        ans+=A[a];
        if(i&1)a++;
        //cout<<ans<<'\n';
    }
    cout<<ans<<'\n';
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);solve();
    //int T;cin>>T;while(T--){solve();}exit(0);
}/*Solved By:- Ritik Agarwal*/

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

using namespace std;
using ll = long long int;
#define long ll

int main(void) {
    constexpr ll MOD = 1e9 + 7;

    cin.tie(0); ios::sync_with_stdio(false);

    ll A, B, m;
    cin >> A >> B >> m;
    vector<ll> a(A), b(B);
    for(auto &e: a) cin >> e;
    for(auto &e: b) cin >> e;

    ll ma=1e9, mb=1e9;
    for(auto &e: a) ma = min(ma, e);
    for(auto &e: b) mb = min(mb, e);

    ll r = ma + mb;
    for(ll i=0; i<m; i++) {
        ll x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        r = min(r, a[x] + b[y] - c);
    }
    cout << r << endl;
}


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

def solve():
    city = []
    city.append(int(input()))
    city.append(int(input()))
    city.append(int(input()))
    city.append(int(input()))
    city.append(int(input()))
    k = int(input())

    for i in range(0, len(city)):
        for j in range(i+1, len(city)):
            if abs(city[i]-city[j]) > k:
                print(":(")
                exit()
    
    print("Yay!")

if __name__ == "__main__":
    solve()


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

class AtCoder
{
    const int MOD = 1000000007;
    
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();

        var n = int.Parse(inputs[0]);
        var m = int.Parse(inputs[1]);
        var edges = 
            Enumerable.Range(0, n)
            .Select(x => new List<int>())
            .ToArray();
        foreach(int i in Enumerable.Range(0, m))
        {
            inputs = Console.ReadLine().Split();
            var u = int.Parse(inputs[0]) - 1;
            var v = int.Parse(inputs[1]) - 1;
            edges[u].Add(v);
        }
        inputs = Console.ReadLine().Split();
        var s = int.Parse(inputs[0]) - 1;
        var t = int.Parse(inputs[1]) - 1;
        var dp = 
            Enumerable.Range(0, 3)
            .Select(x => new bool[n])
            .ToArray(); 
        dp[0][s] = true;
        var que = new Queue<int>();
        que.Enqueue(s);
        int cnt = 0;
        while(que.Any() && !dp[0][t])
        {
            int nmod = (++cnt) % 3;
            int queCount = que.Count;
            foreach(int i in Enumerable.Range(0, queCount))
            {
                int current = que.Dequeue();
                foreach(var next in edges[current].Where(x => !dp[nmod][x]))
                {
                    dp[nmod][next] = true;
                    //System.Console.WriteLine($"{next} {nmod}");
                    que.Enqueue(next);
                }
            }
        }
        if(dp[0][t])
            System.Console.WriteLine(cnt / 3);
        else
        {
            System.Console.WriteLine(-1);
        }
        // System.Console.WriteLine(string.Join(" ", dp[0]));
        // System.Console.WriteLine(string.Join(" ", edges[0]));
        //     System.Console.WriteLine(t);
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 31372
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; ++i)  cin >> a[i];
    vector<vector<int>> graph(N);
    for(int i = 0; i < N - 1; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].emplace_back(v);
        graph[v].emplace_back(u);
    }

    vector<int> dp(N, INF);
    vector<int> ans(N);
    auto dfs = [&](auto&& self, int cur = 0, int par = -1) -> void {
        int prev_pos = lower_bound(dp.begin(), dp.end(), a[cur]) - dp.begin();
        int prev_val = dp[prev_pos];
        dp[prev_pos] = a[cur];
        ans[cur] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
        for(int nxt : graph[cur]){
            if(nxt == par)  continue;
            self(self, nxt, cur);
        }
        dp[prev_pos] = prev_val;
    };
    dfs(dfs);
    for(int i = 0; i < N; ++i)  cout << ans[i] << '\n';
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ship(n, vector<int>(0));
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    ship.at(a).push_back(b);
    ship.at(b).push_back(a);
  }
  
  bool ok = false;
  queue<int> dfs;
  dfs.push(0);
  for(int i = 0; i < 2; i++){
    queue<int> check;
    while(dfs.size() > 0){
      check.push(dfs.front());
      dfs.pop();
    }
    
    while(check.size() > 0){
      int now = check.front();
      check.pop();
      for(auto next : ship.at(now)) dfs.push(next);
    }
  }
  
  while(dfs.size() > 0){
    if(dfs.front() == n-1) ok = true;
    dfs.pop();
  }
  
  if(ok) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 15272
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;
using ii = pair<int,int>;
using ll = long long;

constexpr int MAXN = 5 + 1000;
int a[MAXN];

vector<ll> v[10], vv[10];

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  vector<ll> all;
  for (int i = 0; i <= 9; ++i) {
    v[i].push_back(i);
    all.push_back(i);
  }
  ll pot = 10;
  for (int it = 0; it < 9; ++it) {
    for (int i = 0; i <= 9; ++i) {
      vv[i].clear();
      for (int k = max(0, i-1); k <= min(9, i+1); k++) {
        for (auto x : v[k]) {
          vv[i].push_back(1LL*i*pot+x);
          if (i != 0)  all.push_back(1LL*i*pot+x);
        }
      }
      if (i == 1) {
        
      }
    }
    for (int i = 0; i <= 9; ++i) {
      v[i].swap(vv[i]);
    }
    pot *= 10LL;
  }
  int k; cin >> k;
  cout << all[k] << '\n';
  return 0;
}


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

int main() {
  const unsigned long long mod = 1000000007;
  unsigned N;
  std::cin >> N;
  std::vector<unsigned long long> x(N);
  for (unsigned i = 0; i < N; ++i) {
    std::cin >> x[i];
  }
  unsigned cnt = 0u;
  unsigned cnt2 = 0u;
  unsigned long long ans = 1ull;
  for (unsigned i = 0; i < N; ++i) {
    if (x[i] < 2 * cnt + 1) {
      ans *= (i + 1 - cnt2);
      ans %= mod;
      ++cnt2;
    } else {
      ++cnt;
    }
  }
  for (unsigned i = 0; i < N - cnt2; ++i) {
    ans *= (i + 1);
    ans %= mod;
  }
  std::cout << ans;
  return 0;
}

Measured memory_bytes: 1024