akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <vector>
#include <map>
#include <cstring>
using namespace std;

typedef long long ll;

ll n, s;

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

Measured memory_bytes: 256
n = int(input())
cnt = [-1] + [1] + [2] * 10000000
for i in range(2, 10000002 // 2):
    for j in range(2 * i, 10000001, i):
        cnt[j] += 1
ans = 0
for i in range(1, n + 1):
    ans += i * cnt[i]
print(ans)

Measured memory_bytes: 229712
a, b, c, d, e, f = map(int, input().split())
kouho = 0
jisho = {}
max_a = 30 // a
max_b = 30 // b
for i in range(max_a + 1):
    for j in range(max_b + 1):
        water = (a * i + b * j) * 100
        if water == 0:
            continue
        lim1 = e * (a * i + b * j)
        lim2 = f - water
        lim = min(lim1, lim2)
        max_c = lim // c
        max_d = lim // d
        for k in range(max_c + 1):
            for m in range(max_d + 1):
                sugar = k * c + m * d
                if sugar > lim:
                    continue
                satoumizu = water + sugar
                if satoumizu > f:
                    continue
                if sugar == 0:
                    continue

                noudo = 100 * sugar / satoumizu
                if noudo > kouho:
                    kouho = noudo
                    jisho[noudo] = (sugar, satoumizu)
if kouho == 0:
    print(100 * a, 0)
    exit()
ans2, ans1 = jisho[kouho]
print(ans1, ans2)


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

int main() {
    ll mod=1000000007;
    ll n,m;
    cin>>n>>m;
    vector<bool> can(n+1,true);
    rep(i,m){
        ll tmp;
        cin>>tmp;
        can[tmp]=false;
    }
    vector<ll> num(n+1,0);
    num[0]=1;
    if(can[1]){
        num[1]=1;
    }
    for(ll i=2;i<n+1;i++){
        if(can[i]) {
            num[i]=num[i-1]+num[i-2];
            num[i]=(num[i]+mod)%mod;
        }else {
            num[i]=0;
        }
    }
    cout<<(num[n]+mod)%mod<<endl;
}


Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


r, d, x = Is()
for i in range(10):
    x = r*x-d
    print(x)


Measured memory_bytes: 63340
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

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

  long long div = sqrt(N);

  for (int i = div; i > 0; --i)
  {
    if (N%i == 0)
    {
      div = i;
      break;
    }
  }
  cout << div + N / div - 2 << endl;
}


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

using namespace std;

using int64 = long long;
const int mod = 998244353;

int main() {
  int N, A[100000];
  cin >> N;

  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N);
  int64 ret = 1;
  for(int i = 0; i < N; i++) (ret *= __gcd(i, A[i])) %= mod;
  cout << ret << endl;
}


Measured memory_bytes: 640
N = int(input())
A = []

for i in range(N):
    A.append(int(input()))

B = A
maxim = max(A)
max_i = A.index(maxim)
B.remove(maxim)
second = max(B)

for i in range(N):
    if (i == max_i):
        print(second)
    else:
        print(maxim)

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

int main() {
  int N, a=0;
  cin >> N;
  vector<int> c(N, 0);
  for(int i=0;i<N;i++){
    cin >> c.at(i);
  }
  
  sort(c.begin(), c.end());
  
  for(int i=0; i<N-1;i++){
    if(c.at(i)==c.at(i+1)){
      a++;
    }
  }
  cout << N-a <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef pair<uint32_t,uint32_t> P;

int bitSearchReverse(uint32_t x){
    if(x==0)return -1;
    return 31-__builtin_clz(x);
}
struct RadixHeap{
    vector<P>v[33];
    uint32_t last,sz;
    RadixHeap(){
        last=sz=0;
    }
    void push(P p){
        assert(last<=p.first);
        sz++;
        v[bitSearchReverse(p.first^last)+1].push_back({p.first,p.second});
    }
    P top(){
        return pop(false);
    }
    P pop(bool f=true){
        assert(sz);
        if(!v[0].size()){
            int i=1;
            while(!v[i].size())++i;
            last=min_element(v[i].begin(),v[i].end())->first;
            for(P p:v[i])v[bitSearchReverse(p.first^last)+1].push_back(p);
            v[i].clear();
        }
        P r=v[0].back();
        if(f){
            sz--;
            v[0].pop_back();
        }
        return r;
    }
    int size(){
        return sz;
    }
    bool empty(){
        return sz==0;
    }
    void clear(){
        last=sz=0;
        for(auto a:v)a.clear();
    }
};
struct Graph{
    Graph(int n):E(n),d(n){}
    vector<vector<P>>E;
    vector<uint32_t>d;
    void add_edge(int a,int b,uint32_t c){
        E[a].emplace_back(b,c);
    }
    void dijkstra(int s){
        RadixHeap H;
        fill(d.begin(),d.end(),INF);
        H.push({d[s]=0,s});
        while(H.size()){
            P e=H.top();H.pop();
            if(e.first>d[e.second])continue;
            for(P& a:E[e.second]){
                uint32_t x=a.first,y=a.second+e.first;
                if(y<d[x])d[x]=y,H.push({y,x});
            }
        }
    }
};

main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    uint32_t V,E,r;
    cin>>V>>E>>r;
    Graph G(V);
    for(int i=0;i<E;++i){
        uint32_t s,t,d;
        cin>>s>>t>>d;
        G.add_edge(s,t,d);
    }
    G.dijkstra(r);
    for(int i=0;i<V;++i)
        if(G.d[i]==INF) cout<<"INF"<<endl;
        else cout<<G.d[i]<<endl;
}

Measured memory_bytes: 13416
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

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

    map<string, int> blue;
    map<string, int> red;

    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        if(blue.find(s) == blue.end()){
            blue[s] = 1;
        }
        else{
            blue[s] += 1;
        }
    }

    cin >> m;
    for(int i = 0; i < m; i++){
        string s;
        cin >> s;
        if(red.find(s) == red.end()){
            red[s] = 1;
        }
        else{
            red[s] += 1;
        }
    }

    int max_point = 0;

    map<string, int>::iterator it;

    for(it = blue.begin(); it != blue.end(); it++){
        max_point = max(max_point, it->second - red[it->first]);
    }

    cout << max_point << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <cstdio>

int main(){
    std::list<int> lst;
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        std::string op;
        std::cin >> op;
        if(op == "insert"){
            int val;
            std::scanf("%d", &val);
            lst.push_front(val);
        }
        else if(op == "deleteFirst"){
            lst.pop_front();
        }
        else if(op == "deleteLast"){
            lst.pop_back();
        }
        else if(op == "delete"){
            int val;
            std::scanf("%d", &val);
            for(auto iter = lst.begin(); iter != lst.end(); ++iter){
                if(*iter == val){
                    lst.erase(iter);
                    break;
                }
            }
        }
    }
    int m = lst.size();
    int i = 0;
    for(auto iter = lst.begin(); iter != lst.end(); ++iter, ++i){
        std::cout << *iter;
        if(i == m - 1) std::cout << '\n';
        else std::cout << ' ';
    }
    return 0;
}


Measured memory_bytes: 34464
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>
#include <functional>

using namespace std;
using ll = long long;
using ld = double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll, ll>;
const ll INF = 1e17;
const ld eps = 1e-10;
const ll MOD = 1e9 + 7;

const double pi = acos(-1.0);


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	cout << 180 * (N - 2) << endl;
	return 0;
}






Measured memory_bytes: 256
h,w,k=map(int,input().split())
#a(h,x)
p=[-1]*(w+1)
p[0]=1
p[1]=2
def pat(x):
    if x<0 or x>=w:
        return 1
    else:
        if p[x]!=-1:
            return p[x]
        else:
            return pat(x-2)+pat(x-1)
        
for j in range(1):
    0
mo=10**9 +7

a=[[0 for i in range(w)] for i in range(h+1)]
a[0]=[1]+[0]*(w-1)
for i in range(1,h+1):
    #a[i][0]=a[i-1][0]*pat(-1)*pat(h-1)+a[i-1][1]*pat(0)*pat(h-2)
    #a[i][w-1]=a[i-1][w-2]*pat(w-3)*pat(h-w+1)+a[i-1][w-1]*pat(w-1-1)*pat(h-w)
    for j in range(0,w):
        if j>0: a[i][j]+=a[i-1][j-1]*pat(j-2)*pat(w-j-2)
        a[i][j]+=a[i-1][j]*pat(j-1)*pat(w-1-j-1)
        if j<w-1: a[i][j]+=a[i-1][j+1]*pat(j-1)*pat(w-j-3)
print(a[h][k-1] % mo)
#print(a)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using tpl = tuple<int,int,int>;

ll solve() {
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    for ( int i = 0; i < X; i++ ) cin >> A[i];
    for ( int i = 0; i < Y; i++ ) cin >> B[i];
    for ( int i = 0; i < Z; i++ ) cin >> C[i];
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    int a, b, c;
    // priority queue reverse order
    auto cmp = [&](tpl& x, tpl& y) { 
        int xa, xb, xc, ya, yb, yc;
        tie(xa,xb,xc) = x;
        tie(ya,yb,yc) = y;
        return A[xa]+B[xb]+C[xc] < A[ya]+B[yb]+C[yc];
    };
    priority_queue<tpl, vector<tpl>, decltype(cmp)> q(cmp);
    vector<ll> ans;
    set<tpl> used;
    q.push(tpl(0,0,0));
    used.insert(tpl(0,0,0));
    for ( int i = 0; i < K; i++ ) {
        tie(a,b,c) = q.top();
        q.pop();
        ans.push_back(A[a]+B[b]+C[c]);
        if ( a+1 < X ) {
            auto t = tpl(a+1,b,c);
            if ( used.count(t) == 0 ) {
                q.push(t);
                used.insert(t);
            }
        }
        if ( b+1 < Y ) {
            auto t = tpl(a,b+1,c);
            if ( used.count(t) == 0 ) {
                q.push(t);
                used.insert(t);
            }
        }
        if ( c+1 < Z ) {
            auto t = tpl(a,b,c+1);
            if ( used.count(t) == 0 ) {
                q.push(t);
                used.insert(t);
            }
        }
    }
    for ( int i = 0; i < ans.size(); i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4120
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int N;
  cin >> N;
  long long count = 0;
  N = N - 1;
  for(int i = 1;i <= N;i++){
    for(int j = 1;j <= N;j++){
      if(i * j <= N){
        count++;
      }else{
        break;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3632
from collections import defaultdict

def f(a, b):
    for i in range(9,0,-1):
        if a[i] == b[i]: continue
        elif a[i] > b[i]:
            return True
        else:
            return False
    return False

N, M = map(int, input().split())
se = set()
A = list(map(int, input().split()))
toNum = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [[] for i in range(N+1)]
done = [False for i in range(N+10)]
done[N] = True
dics = [defaultdict(int) for i in range(N+1)]
for i in range(N-1, -1, -1):
    for a in A:
        num = toNum[a]
        if not done[i+num]: continue
        l = len(dp[i+num])+1
        d = dics[i+num].copy()
        d[a] += 1
        if l > len(dp[i]) or (l == len(dp[i]) and f(d, dics[i])):
            dp[i] = dp[i+num] + [a]
            done[i] = True
            dics[i] = d
dp[0].sort(reverse=True)
print(*dp[0], sep='')


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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

signed main(){
    
    ll n;
    cin >> n;
    ll ans = 1;
    vector<int> v = {2};
    for(int i = 3;i <= 1000 ;i++){
        int c = 1;
        for(auto x : v){
            if(i%x == 0) c = 0;
        }
        
        //cerr << i << " : " << c << endl;
        if(c != 0) v.push_back(i);
    }

    int cnt = 0;
    //for(auto x : v) cerr << x << endl;

    int a[1001] = {0};
    for(int i = 2;i <= n;i++){
        for(auto x : v){
            int d = i;
            while(d%x == 0){
                a[x]++;
                d /= x;
            }
            
            if(i == x)break;
        }
    }
    for(auto x : v){
        ans *= a[x]+1;
        ans %= 1000000007LL; 
        //cerr << ans << endl;
    }
    //REP(i,n+1) cerr << i << ":" <<  a[i]  << endl;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

mod = 10**9 + 7

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(n+1)]
        self.invs = [1 for i in range(n+1)]

        for i in range(1, n+1):
            self.facts[i] = self.facts[i-1] * i % mod
        self.invs[n] = pow(self.facts[n], mod-2, mod)
        for i in range(1, n+1):
            self.invs[n-i] = self.invs[n-i+1] * (n-i+1) % mod

    def ncr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

    def nhr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.ncr(n+r-1, n-1)

comb = Combination(N)

if K == 1:
    print(0)
    exit()

ans = 0
for i in range(N-K+1):
    ans += (comb.ncr(N-1-i, K-1) * A[i] - comb.ncr(N-1-i, K-1) * A[N-1-i]) % mod

print(ans%mod)

Measured memory_bytes: 20696
from collections import deque

s = list(input())
q = int(input())
s = deque(s)

flg = "order"
for i in range(q):
    t, *f = map(str, input().split())
    if t == "1":
        if flg == "order":
            flg = "reverse"
        else:
            flg = "order"
    else:
        if f[0] == "1":
            if flg == "order":
                s.appendleft(f[1])
            else:
                s.append(f[1])
        else:
            if flg == "order":
                s.append(f[1])
            else:
                s.appendleft(f[1])

if flg == "order":
    print("".join(s))
else:
    s.reverse()
    print("".join(s))

Measured memory_bytes: 8676
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
a.sort()
for i in range(N):
    if a[i]<=x:
        x -= a[i]
        cnt += 1
    else:
        break
if (x!=0)and(cnt==N):
    cnt -= 1
print(cnt)

Measured memory_bytes: 9124
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

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

int bitCount(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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int sq;
    sq = a * b / 2;
    cout << sq << '\n';

    return 0;
}


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

using namespace std;
using ll = long long;

int n;
ll a[100];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int pos;
	ll ans = 0, d;
	bool p = true;
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	while (p)
	{
		pos = 1;
		if (a[pos] < n) p = false;
		for (int i = 2; i <= n; ++i)
		{
			if (a[i] > a[pos])
			{
				pos = i;
			}
		}
		if (a[pos] >= n) p = true;
		if (p)
		{
			d = a[pos] / n;
			ans += d;
			a[pos] %= n;
			for (int i = 1; i <= n; ++i)
			{
				if (i != pos) a[i] += d;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
from operator import itemgetter
N = int(input())
A = Counter(map(int, input().split()))
ans = 0
left = 0
for k, v in sorted(A.items(), key=itemgetter(1))[::-1]:
    if left == 1:
        if v == 1:
            ans += 1
            left = 0
            continue
        else:
            v -= 1
            ans += 1
            left = 0
    if v > 3:
        v = v%2 + 2

    if v == 1:
        ans += 1
    elif v == 2:
        left += 1
    elif v == 3:
        ans += 1

print(ans)


Measured memory_bytes: 67308
#include<bits/stdc++.h>
#include<set>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
//#define sort(v)	sort(v.begin(),v.end());
//#define rsort(v) sort(v.rbegin(),v.rend());
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vb vector<bool>
#define vc vector<char>
#define vvll vector<vector<long long int> >
#define sll set<long long int>
#define mll map<long long int,long long int>
#define sllit set<long long int>::iterator
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli mpower(lli a,lli b,lli m){lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli gcd(lli a,lli b){if(b==0) return a;if(a==0) return b;if(a>=b) return gcd(b,a%b);else return gcd(a,b%a);}
lli lcm(lli a,lli b){lli p=a*b;return p/gcd(a,b);}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}


/******************************START********************************/
bool found(lli arr[],lli n,lli x)
{
	for(lli i=0;i<n;i++){
		if(arr[i]==x)	return true;
	}
	return false;
}
int main()
{
	//init();
	char ch1,ch2,ch3;
	string s1,s2,s3,str;
    lli i,j,k,a,t,b,c,n,z,m,sum=0,ans=0,temp;
    cin >> n >> k;
    while(n)
    {
    	ans++;
    	n/=k;
	}
	cout << ans << endl;
    
    
    
    
    
    return 0;
}





















/* UJJWAL KESHRI */

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

#define ll long long

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

    int N, M;
    ll K;
    cin >> N >> M >> K;
    // cout << N << M << K << endl;

    ll A[N+1];
    A[0] = 0;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] += A[i-1];
    }

    ll B[M+1];
    B[0] = 0;

    for (int i = 1; i <= M; i++) {
        cin >> B[i];
        B[i] += B[i-1];
    }

    // for (const auto& value: A) {
    //     cout << value << ' ';
    // }

    int cur_max = 0;

    int books_stack_b = M;

    ll diff = -1;
    for (int books_stack_a = 0; books_stack_a <= N; books_stack_a++) {
        if (A[books_stack_a] > K) {
            break;
        }
        diff = K - A[books_stack_a];
        while (diff < B[books_stack_b]) { // guaranteed to terminate at zero
            books_stack_b--;
        }
        // cout << books_stack_b << ' ' << B[books_stack_b] << '\n';
        cur_max = max(cur_max, books_stack_a + books_stack_b);
    }

    cout << cur_max;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main()
{
  finp;
 int a,b;
cin>>a>>b;
if(a+b == 15)cout<<"+";
else if(a*b == 15)cout<<"*";
else cout<<"x";
  
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
string dte;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string arr[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	cin >> dte;
	for(int i = 0; i < 7; i++)
		if(arr[i] == dte) cout << 7 - i << "\n";
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val list = List.fill(n)(sc.nextInt)
    sc.close()

    val result =
      (1 to n).map(i => Math.abs(list.take(i).sum - list.drop(i).sum)).min
    println(result)
  }
}

Measured memory_bytes: 25668
/***************************************************
 * Problem Name : A.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2020-02-03
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    //~ cout << setprecision (10);
    //~ cout << fixed;
    int n, a;
    cin >> n;
    cin >> a;
    int ans = n / a;

    if (n % a != 0) ans++;

    cout << ans << "\n";
    return 0;
}


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


int main(){

  ll N;

  cin>>N;
  

  vector<long long> A;
  A.resize(N);
  rep(i,N)cin>>A[i];
  
  sort( A.begin(), A.end() );
  
  ll t=0;
  ll sum=0;
  rep(i,N){

    if(i!=0){
      if(2*sum<A[i])t=i;
    }
    sum+=A[i];
    
  }
  
  cout<<N-t<<endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std; 
#define vll vector<long long>
#define pb push_back
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[500005];
ll vis[500005],color[500005],I[101][101];

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

bool isPrime(int n)
{
    if (n<=1) return false; 
    if (n<=3) return true; 
    if (n%2==0||n%3==0) return false; 
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false; 
    return true; 
}

ll binpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res*=n;
			po--;
		}
		else
		{
			n*=n;
			po/=2;
		}
	}
	return res;
}

ll swap(ll a, ll b)
{
	a=a+b;
	b=a-b;
	a=a-b;
}

ll fact(ll n) { 
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}


int main()
{
	float a,b;
	cin>>a>>b;
	ll ans=1;
	ans+=ceil((b-a)/(a-1));
	cout<<ans;
}


Measured memory_bytes: 13696
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int treeLength = in.nextInt();
		ArrayList<Integer> values = new ArrayList<>();
		for (int i=0; i<treeLength; i++) {
			int tempInt = in.nextInt();
			values.add(tempInt);
		}
		//reading input complete
		for (int i=0; i<values.size(); i++) {
			System.out.print("node "+(i+1)+": key = "+values.get(i)+", ");
			if (i>0) {
				System.out.print("parent key = "+values.get((i-1)/2)+", ");
			}
			if ((2*i+1)<values.size()) {
				System.out.print("left key = "+values.get(2*i+1)+", ");
			}
			if ((2*i+2)<values.size()) {
				System.out.print("right key = "+values.get(2*i+2)+", ");
			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 27528
#abc_151_f

#return minimum and not related to whether the function is convex or not 
from scipy.optimize import fmin

n = int(input())
l = []
for i in range(n):
    x,y = [int(j) for j in input().split()]
    l.append((x,y))
    
#determine the fuction representing the longest distance ^2 from the center point to designated N points.
def f(s):
    x,y = s
    maxi = 0
    for i,j in l:
        maxi = max(maxi, (i-x)**2 + (j-y)**2)
    return maxi

x,y = fmin(f, [100,100], xtol=10**-9, disp=0)
ans = f((x,y)) ** 0.5
print(ans)

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

S = input().strip()

def rec(S):
    N = len(S)
    for i in range(N//2):
        if S[i] != S[N-i-1]:
            return False
    return True

if rec(S) and rec(S[:(len(S)-1)//2]) and rec(S[(len(S)+3)//2-1:]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
n, k = map(int, input().split())
s = list(input())
s_num = []
point = 1
prev = s[0]
ans = 0
for i in range(n - 1):
    if prev != s[i + 1]:
        prev = s[i + 1]
        s_num.append(point)
        ans += point - 1
        point = 1        
    else:
        point += 1
s_num.append(point)
ans += point - 1
kkk = max(len(s_num) - 2, 0)
ans = ans + min(kkk, k) * 2
if kkk < k:
    ans += k - kkk
ans = min(n - 1, ans)
print(ans)

Measured memory_bytes: 4652
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
"""
全員が自分以外の全員のxorを把握しているので、全員の値を求めよ
nは偶数

桁ごとに独立に考える。
テストケースで検証すると、
その桁において1の数が偶数個の場合は、自分自身の桁の数字を入れる
奇数個の場合は、自分自身の桁の値をbit反転したものを入れる
ことが正解であることが分かる。
これを実装するだけ。
"""
n = int(readline())
lst1 = list(map(int,readline().split()))
limit = 33 #制約10**9は2**32内に収まる。
ans = []
parity = [0]*limit
for i in lst1:
    for j in range(limit):
        parity[j] += i>>j

for i in range(limit):
    parity[i] %= 2

for i in lst1:
    res = 0
    for j in range(limit):
        p = i>>j&1
        if parity[j]== 0 and p== 1:
            res += 1<<j
        elif parity[j] == 1 and p == 0:
            res += 1<<j
    ans.append(res)
print(*ans)

Measured memory_bytes: 98524
#include<bits/stdc++.h>
#define Pii pair<int,int>
#define se second
#define fi first
#define mp make_pair
#define pb push_back
#define maxn 100100
using namespace std;
int n,seg[maxn],res=1;
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int m;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%d",&seg[i]);
	res=seg[1];
	for(int i=2;i<=n;i++) res=gcd(res,seg[i]);
	bool flag=false;
	for(int i=1;i<=n;i++){
		if(m>seg[i]) continue;
		if((seg[i]-m)%res==0){
			flag=true;
			break;
		}
	}
	if(flag){
		cout<<"POSSIBLE"<<endl;
	}else 
		cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    string A, B;
    cin >> A >> B;
    
    int l1 = A.size(), l2 = B.size();
    if(l1 > l2){
        cout << "GREATER" << endl;
        return 0;
    }
    if(l1 < l2){
        cout << "LESS" << endl;
        return 0;
    }

    // 以下, l1 == l2の場合
    for(int i=0;i<l1;i++){
        if(A[i] > B[i]){
            cout << "GREATER" << endl;
            return 0;
        }
        if(A[i] < B[i]){
            cout << "LESS" << endl;
            return 0;
        }
    }

    cout << "EQUAL" << endl;

}

Measured memory_bytes: 256
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;

	int a_idx = 0;
	int b_idx = 0;
	int idx_cnt = 0;

	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		int N = Integer.parseInt(line);
		// int H = Integer.parseInt(line.split("\\s+")[0]);
		// int K = Integer.parseInt(line.split("\\s+")[1]);

		String str_a = scanner.nextLine().replaceAll("\\s+", "");
		String str_b = scanner.nextLine().replaceAll("\\s+", "");

		dfs(1, N, "", new HashSet<>(), str_a, str_b);

		System.out.println(Math.abs(a_idx - b_idx));
		return;
	}

	public void dfs(int idx, int max_n, String temp, Set<Integer> used, String str_a, String str_b) {
        if (temp.length() == max_n) {
			idx_cnt ++;
			if (temp.equals(str_a)) {
				a_idx = idx_cnt;
				// System.out.println("a = " + idx_cnt);
			}
			if (temp.equals(str_b)) {
				b_idx = idx_cnt;
				// System.out.println("b = " + idx_cnt);
			}
            return; // uncomment if subset
        }
        // if (idx == max_n+1) return;

        for (int i=1; i<=max_n; i++) { // idx->combinations, 0->permutations
            if (used.contains(i)) continue; // for permutations
			used.add(i); // for permutations
            dfs(i + 1, max_n, temp + String.valueOf(i), used, str_a, str_b);
			used.remove(i);
        }

        return;
    }

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}

// class Num implements Comparable<Num>{
// 	public int val;
//
// }


Measured memory_bytes: 42924
#include<stdio.h>
int vis[100];
int main()
{
	int m,n;
	scanf("%d%d",&m,&n);
	while(n--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		vis[a]++;
		vis[b]++;
	}
	for(int i=1;i<=m;i++)
	{
		printf("%d\n",vis[i]);
	}
	return 0;
 } 

Measured memory_bytes: 128
from collections import deque, defaultdict

n = int(raw_input())

edges = []
g = [[] for i in xrange(n)]

d = [0 for i in xrange(n)]
for i in xrange(n - 1):
    (a, b) = map(int, raw_input().split())
    a -= 1
    b -= 1
    edges.append((a, b))
    g[a].append(b)
    g[b].append(a)
    d[a] += 1
    d[b] += 1

vs = sorted(map(int, raw_input().split()))
vidx = 0
ns = [-1 for i in xrange(n)]

q = deque()

for i in xrange(n):
    if d[i] == 1:
        q.append(i)

while q:
    cur = q.popleft()
    #print q, cur, d
    ns[cur] = vs[vidx]
    vidx += 1

    for nxt in g[cur]:
        d[nxt] -= 1
        #print nxt, d
        if d[nxt] == 1:
            q.append(nxt)

ans = 0
for (a, b) in edges:
    ans += min(ns[a], ns[b])
print ans

print ' '.join(map(str, ns))


Measured memory_bytes: 6540
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input!{
        n: usize,
        m: usize,
        x: i64,
        ca: [(i64, [i64; m]); n],
    };
    let mut res = None;
    let two: i32 = 2;
    for i in 0..two.pow(n as u32){
        let mut cost: i64 = 0;
        let mut skill = vec![0; m];
        for j in 0..n{
            if (i>>j) & 1 == 1{
                cost += ca[j].0;
                for k in 0..m{
                    skill[k] += ca[j].1[k];
                }
            }
        }
        if skill.into_iter().min().unwrap() < x {
            continue;
        }
        if let Some(x) = res {
            res = Some(std::cmp::min(x,cost));
        } else {
            res = Some(cost);
        }
    }
    println!("{}", res.unwrap_or(-1));
}


Measured memory_bytes: 2192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<lint, lint> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N, K;
	cin >> N >> K;
	vector<int>h(N);
	rep(i, N) {
		cin >> h[i];
	}
	sort(h);
	vector<int>dif(N - K + 1);
	rep(i, N - K + 1) {
		dif[i] = h[i + K - 1] - h[i];
	}
	sort(dif);
	cout << dif[0] << endl;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const ll mod = 1000000007;

int main(){
  ll k, n;
  cin >> k >> n;
  vll a(n);
  for(auto &i : a) cin >> i;
  ll maxdis = 0;
  rep(i, 0, n - 1){
    if(maxdis < a.at(i + 1) - a.at(i)) maxdis = a.at(i + 1) - a.at(i);
  }
  if(maxdis < k - a.at(n - 1) + a.at(0)) maxdis = k - a.at(n - 1) + a.at(0);
  cout << k - maxdis << endl;
}

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

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

  vector<double> A, B;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }

  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  int ans = 0;
  if (N%2!=0) {
    int l = A[N/2];
    int r = B[N/2];
    ans = r - l + 1;
  } else {
    double l = (A[N/2-1]+A[N/2])/2;
    double r = (B[N/2-1]+B[N/2])/2;
    ans = 2*(r - l) + 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6636
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;


static class P
{
    static void Main()
    {
        var s = Console.ReadLine();
        Console.WriteLine(s.Replace("2017", "2018"));
    }
}


Measured memory_bytes: 11092
def getStart(field):
    search_field = field[1:]     # cut the first [H,W,N] for min_path matrix
    for y in range(len(search_field)):
        for x in range(len(search_field[0])):
            if search_field[y][x] == "S":
                return x,y+1


def bfs(field,start_x,start_y,goal_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    gotten_cheese = 1
    distance = 0
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * field[0][1] for i in range(field[0][0])]
    min_path[start_y-1][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < field[0][1] and 1 <= ny < field[0][0]+1 and field[ny][nx] != "X" and min_path[ny-1][nx] == INF:
                min_path[ny-1][nx] = min_path[current[1]-1][current[0]] + 1
                if field[ny][nx] == gotten_cheese: # at the same cheese-power number
                    distance += min_path[ny-1][nx]
                    if field[ny][nx] == goal_N: # goal
                        print(distance)
                        return
                    else: # not goal, but could eat cheese
                        que = []
                        que.append([nx,ny])
                        gotten_cheese += 1
                        min_path = [[INF] * field[0][1] for i in range(field[0][0])]
                        min_path[ny-1][nx] = 0
                        break
                else:
                    que.append([nx,ny])


def main(field):
    sx,sy = getStart(field)
    bfs(field,sx,sy,field[0][2])

# field = [[10,10,9],
# [".","X",".",".",".","X",".","S",".","X"],
# [6,".",".",5,"X",".",".","X",1,"X"],
# [".",".",".","X","X","X","X",".",".","X"],
# ["X",".",".",9,"X",".",".",".","X","."],
# [8,".","X",2,"X",".",".","X",3,"X"],
# [".",".",".","X","X",".","X",4,".","."],
# ["X","X",".",".",".",".",7,"X",".","."],
# ["X",".",".","X",".",".","X","X",".","."],
# ["X",".",".",".","X",".","X","X",".","."],
# [".",".","X",".",".",".",".",".",".","."]]
#
# main(field)

matrix = []
while True:
    row = input().rstrip().split()
    if len(row) == 3:
        re_row = []
        for i in row:
            re_row.append(int(i))
        matrix.append(re_row)
    else:
        re_row = []
        for char in row[0]:
            if char.isdigit():
                re_row.append(int(char))
            else:
                re_row.append(char)
        matrix.append(re_row)
    if len(matrix) == int(matrix[0][0]) + 1:
        main(matrix)
        break

Measured memory_bytes: 43800
import java.util.Scanner;

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

        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                for(int k = 1; k <= n; k++) {
                    result += euclid(j,euclid(k,i));
                }
            }
        }
        System.out.println(result);
    }

    private static int euclid(int m, int n) {
        int tmp;

        if(m < n) {
            tmp = m;
            m = n;
            n = tmp;
        }
        while(n > 0){
            tmp = m % n;
            m = n;
            n = tmp;
        }
        return m;
    }
}


Measured memory_bytes: 27168
#include <iostream>
#define ll long long
#define f(i, n) for (int i=0; i < n; i++)
// sort(bb, bb+n);
 
using namespace std;
int main()
{
    string s;
    cin >> s;
  	if(s=="AAA"||s=="BBB"){
      cout<<"No";
    }
    else{
    cout<<"Yes";
    }
    return 0;
}

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

int main() {
  int n,k,x;
  int ans = 0;
  cin >> n >> k;
  for (int i=0; i<n; i++) {
    cin >> x;
    if(x<k-x) {
      ans += x;
    }
    else {
      ans += k-x;
    }
  }
  cout << ans*2 << endl;
}

Measured memory_bytes: 3600
function Main(input) {
    input = input.split("\n");
    for (i=0; i < input.length-1; i = i + 2) {
        var n = parseInt(input[i])
        var num = []
        tmp = input[1].split(" ")
        for (j=0; j < n; j++) {
            num.push(tmp[j])
        }
        var max = Math.max.apply(null, num)
        var min = Math.min.apply(null, num)
        var sum = 0
        for (k=0; k < num.length; k++) {
            sum += parseInt(num[k])
        }
        console.log(min, max, sum)
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto&& e : v) {
    cin >> e;
  }
  sort(begin(v), end(v));
  cout << v[n / 2] - v[n / 2 - 1] << endl;
}


Measured memory_bytes: 640
(let* ((s (read-line))
       (q (read))
       (head nil)
       (tail nil)
       (rev 0))
  (loop :for i :from 1 :to q
        :for x := (read)
        :if (= x 1)
        :do (progn
              (incf rev))
        :else
        :do (let ((f (read))
                  (c (read-char)))
              (cond ((and (evenp rev) (= f 1))
                     (push c head))
                    ((and (evenp rev) (= f 2))
                     (push c tail))
                    ((and (oddp rev) (= f 1))
                     (push c tail))
                    (t
                     (push c head)))))
  (when (oddp rev)
    (rotatef head tail)
    (setf s (reverse s)))
  (loop :for c :in head :do (format t "~A" c))
  (format t "~A" s)
  (loop :for c :in (reverse tail) :do (format t "~A" c))
  (format t "~%"))


Measured memory_bytes: 80752
import collections
from collections import deque
N=int(input())
D=list(map(int,input().split()))
c=collections.Counter(D)
count0=0
count12=0
zeroflag=0
l=[]
if c[12]>0:
    count12=c[12]
if c[0]>0:
    count0=c[0]+1
#print(l,count0,count12)
#print(n)
allmax=0
q=deque()
l=[]



if (count0==0)and(zeroflag==0):
    q.append([0])
else:
    zeroflag=1

if (count12==1)and(zeroflag==0):
    length=len(q)
    j=0
    while j<length:
        buf1=[]
        l=q.popleft()
        buf1.extend(l)
        l.append(12)
        q.append(l)
        j=j+1
elif count12>1:
    zeroflag=1

if zeroflag==0:
    for i in range(1,12):
        length=len(q)
        j=0
        if c[i]==0: continue
        if c[i]==1:
            while j<length:
                buf1=[]
                buf2=[]
                l=q.popleft()
                buf1.extend(l)
                buf1.append(i)
                buf2.extend(l)
                buf2.append(24-i)
                q.append(buf1)
                q.append(buf2)
                j=j+1
        if c[i]==2:
            while j<length:
                buf1=[]
                buf2=[]
                buf3=[]
                l=q.popleft()
                #buf1.extend(l)
                #buf1.extend([i,i])
                #buf2.extend(l)
                #buf2.extend([24-i,24-i])
                buf3.extend(l)
                buf3.extend([i,24-i])
                #q.append(buf1)
                #q.append(buf2)
                q.append(buf3)
                j=j+1
        if c[i]>2:
            zeroflag=1
            break
        #print(q)

#print(q)

if zeroflag==0:
    for l in q:
        l.sort()
        mi=100
        n=len(l)
        for j in range(n-1):
            mi=min(mi,l[j+1]-l[j],24-l[j+1]+l[j])
        mi=min(mi,l[n-1],24-l[n-1])
    #print(mi)
        allmax=max(allmax,mi)
else:
    allmax=0
print(allmax)


Measured memory_bytes: 71148