akhauriyash/Code-Regression huggingface dataset:
import sys

input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))


# from kiriさん
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1:
                return 0
            t <<= 1
    return 1


def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g):
                return g
            elif isPrimeMR(n // g):
                return n // g
            return findFactorRho(g)


def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k:
            ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1:
        ret[n] = 1
    if rhoFlg:
        ret = {x: ret[x] for x in sorted(ret)}
    return ret


scflag = 0
g = A[0]
nums = set()
for i in range(n):
    g = gcd(g, A[i])
    temp = primeFactor(A[i])
    for a in temp.keys():
        # print(a)
        if a == 1:
            continue
        if a in nums:
            scflag = 1
        else:
            nums.add(a)
if g != 1:
    print("not coprime")
elif scflag:
    print("setwise coprime")
else:
    print("pairwise coprime")



Measured memory_bytes: 184464
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;

int main() {
	int n;
	cin >> n;
	VI p;
	REP(i, n) {
		int t;
		cin >> t;
		p.push_back(t);
	}
	int ans = 0;
	REP(i, n) {
		if (p[i] == i + 1) {
			swap(p[i], p[i + 1]);
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int n, u, v;
vector<vector<int>> edge(1e5);
vector<bool> visited(1e5, false);
vector<int> d(1e5, 0);
vector<int> d2(1e5, 0);

void dfs(int u){
    if (visited[u]) return;
    visited[u] = true;
    for (int i = 0; i < edge[u].size(); i++){
        if (visited[edge[u][i]]) continue;
        d2[edge[u][i]] = d2[u] + 1;
        dfs(edge[u][i]);
        d[u] = max(d[u], d[edge[u][i]] + 1);
    }
}

vector<bool> visited2(1e5, false);
vector<int> d3(1e5, 0);
void dfs2(int u){
    if (visited2[u]) return;
    visited2[u] = true;
    for (int i = 0; i < edge[u].size(); i++){
        if (visited2[edge[u][i]]) continue;
        d3[edge[u][i]] = d3[u] + 1;
        dfs2(edge[u][i]);
    }
}

int main(){
    cin >> n;
    cin >> u >> v;
    u--; v--;
    int a, b;
    for (int i = 0; i < n - 1; i++){
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(v);
    dfs2(u);
    int ans = 0;
    for (int i = 0; i < n; i++){
        if (d3[i] >= d2[i]) continue;
        if ((d2[i] - d3[i]) % 2 == 0) continue;
        ans = max(ans, d2[i] + d[i] - 1);
    }
    int tmp = 1e8;
    for (int i = 0; i < n; i++){
        if (d3[i] == d2[i]) tmp = min(tmp, d2[i]);
    }
    if (tmp == 1e8) tmp = 0;
    int tmp2 = 0;
    for (int i = 0; i < n; i++){
        if (d[i] && d3[i] < d2[i] && (d2[i] - d3[i]) % 2 == 0) tmp2 = max(tmp2, d2[i]);
    }
    cout << max({ans, tmp, tmp2}) << endl;
}

Measured memory_bytes: 10752
A, B = map(int, input().split())
S = list(input())

res = "Yes"

for i in range(A):
    if S[i] not in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
        res = "No"
if S[A] != "-":
    res = "No"
for i in range(A+1, A+B+1):
    if S[i] not in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
        res = "No"
print(res)


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

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount

#define N 100010
int n, L, a[N];

int main () {
	cin >> n >> L;
	for (int i = 0; i < n; i ++) cin >> a[i];
	for (int i = 0; i < n-1; i ++) if (a[i] + a[i+1] >= L) {
		puts ("Possible");
		for (int j = 0; j < i; j ++) cout << j+1 << endl;
		for (int j = n-2; j >= i+1; j --) cout << j+1 << endl;
		cout << i+1 << endl;
		return 0;
	}
	puts ("Impossible");
	return 0;
}

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

int main () {
  int f;
  string a,b;
  cin>>f;
  cin>>a>>b;
  for (int i=0;i<=f-1;i++)
    
  {cout<<a[i]<<b[i];
  
  }
  




	}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t long long
// std::sort(&a[0], &a[4], [](auto& x, auto& y){return x[0] < y[0];});
//accumulate(&arr2[n], &arr2[m-1], 0);
using namespace std;

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

  int n;
  std::cin >> n;
  int p[n] = {};
  for (size_t i = 0; i < n; i++) {
    std::cin >> p[i];
  }

  int cnt = 0;
  for (size_t i = 0; i < n - 2; i++) {
    if((p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i+2] < p[i+1] && p[i+1] < p[i]))
      cnt++;
  }

  std::cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = fs.readArray(n);
    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k < n; k++) {
          if ((arr[i] != arr[j] && arr[j] != arr[k] && arr[k] != arr[i]) && isValidTriangle(arr[i], arr[j], arr[k])) {
//            System.out.println(arr[i] + " " + arr[j] + " " + arr[k]);
            count++;
          }
        }
      }
    }
    System.out.println(count);
  }

  private static boolean isValidTriangle(int a, int b, int c) {
    return !(
        (a + b <= c) ||
        (a + c <= b) ||
        (b + c <= a)
    );
  }

  static class FastScanner {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");

    String next() {
      while (!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    int[] readArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    long nextLong() {
      return Long.parseLong(next());
    }
  }
}


Measured memory_bytes: 33752
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a[] = new int[5];
        for(int i=0;i<5;i++)a[i]=sc.nextInt();
        int k = sc.nextInt();
        for(int i=0;i<4;i++)for(int j=i+1;j<5;j++){
            if(a[j]-a[i]>k){
                System.out.println(":(");
                return;
            }
        }
        System.out.println("Yay!");



    }
}


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

using namespace std;

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

#define X first
#define Y second

const int MAXN = 110;

int n, p;
int a[MAXN];
ll C[MAXN][MAXN];

int main()
{
	
	scanf("%d%d", &n, &p);
	for (int i = 1; i <= n; ++ i)
	{
		int x;
		scanf("%d", &x);
		a[x%2] ++;
	}
	for (int i = 0; i <= n; ++ i)
		C[i][0] = 1;
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= i; ++ j)
			C[i][j] = C[i-1][j-1]+C[i-1][j];
	ll ans = 0;
	for (int i = 0; i <= a[0]; ++ i)
		for (int j = 0; j <= a[1]; ++ j)
			if (j%2 == p) ans += C[a[0]][i]*C[a[1]][j];
	cout << ans << endl;
	
	return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using ll = long long;
using namespace std;

#define MX 100001

int N, C;
bool arr[30][MX] = {};
int ans[MX] = {};

int main()
{
    cin >> N >> C;
    for (int i = 0; i < N; i++) {
        int s, t, c;
        cin >> s >> t >> c;
        for (int j = s; j <= t; j++) {
            arr[c - 1][j - 1] = true;
        }
    }
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < MX; j++) {
            if (arr[i][j]) {
                ans[j]++;
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < MX; i++) {
        if (mx < ans[i]) {
            mx = ans[i];
        }
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 3584
a=list(map(int,input().split()))
cnt=0
ans=0
for i in range(3):
    if a[i]%2!=0:
        cnt+=1
if cnt==1:
    for i in range(3):
        if a[i] % 2 == 0:
            a[i] += 1
    ans+=1
elif cnt==2:
    for i in range(3):
        if a[i] % 2 != 0:
            a[i] += 1
    ans+=1
a.sort()
ans+=(a[2]-a[0])//2+(a[2]-a[1])//2
print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

string letters = "abcdefghijklmnopqrstuvwxyz";
int main() {
	map<char, int> m;
	string s;
	cin >> s;
	for(char x: s) m[x] = 1;
	
	for(char l: letters){
		if(m.count(l) == 0){
			cout << l;
			exit(0);
		}
	}
	cout << "None";
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 700;
const int MAX_W = 333;
const int MAX_H = 333;
int N;
int W, H;
int x, y;
int S, T;
int d[MAX_W][MAX_H];

inline bool check(int hx, int hy){ return 0 <= hx && hx <= W && 0 <= hy && hy <= H; }

int solve(int x, int y)
{
  int ret = 0;
  if(!check(x + S, y + T)) return 0;
  rrep(i, x, x + S) rrep(j, y, y + T) ret += d[i][j];
  return ret;
}

int main()
{
  while(cin >> N, N){
    cin >> W >> H;
    rep(i, W+2) rep(j, H+2) d[i][j] = 0;
    rep(i, N){
      cin >> x >> y;
      d[x-1][y-1] = 1;
    }
    cin >> S >> T;
    int res = 0;
    rep(i, W) rep(j, H) maxup(res, solve(i, j));
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;


	
int main()
{ 
	int n;
	cin>>n;
	int arr [200000];
	for(int i=0;i<200000;i++)arr[i]=0;
	for(int i=0;i<n-1;i++){
		int a;
		cin>>a;
		arr[a-1]++;
	}
	for(int i=0;i<n;i++)cout<<arr[i]<<endl;
	return 0;
}
	
	



Measured memory_bytes: 4416
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/PCK/Prelim/0336?year=2016

#include <bits/stdc++.h>

using namespace std;

int main() {
    int h, r;
    cin >> h >> r;

    if (h + r > 0) {
        cout << 1 << endl;
    } else if (h + r < 0) {
        cout << -1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

/*
 * 円の上端のy座標はh+r。これの政府を調べる。
 * 
 */


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

vector<ll> GetDivisors(ll n) {
  vector<ll> divisors;
  for (ll d = 1; d * d <= n; ++d) {
    if (n % d == 0) {
      divisors.push_back(d);
      if (n / d != d) divisors.push_back(n / d);
    }
  }
  return divisors;
}

int main() {
  ll N;
  cin >> N;
  
  int count = GetDivisors(N - 1).size() - 1;  // exclude 1

  for (auto K : GetDivisors(N)) {
    if (K == 1) continue;
    ll tmp = N;
    while (tmp % K == 0) {
      tmp /= K;
    }
    if (tmp % K == 1) ++count;
  }
  
  cout << count << endl;
  return 0;
}


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

int main()
{
    long a, b, k;
    cin >> a;
    cin >> b;
    cin >> k;

    if(a + b <= k){
        cout << 0 << ' ' << 0 << endl;
    }else if(k-a >= 0){
        cout << 0 << ' ' << b+a-k << endl;
    }else if(k <= a){
        cout << a-k << ' ' << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int m = saori.saori_hayami();
		HashSet<Integer> a = new HashSet<>();
		for(int i = 0;i < m;i++){
			a.add( saori.saori_hayami() - 1);
		}
		int[] dp = new int[n];
		for(int i = 0;i < n;i++){
			if(a.contains(i)){
				continue;
			}
			if(i == 0){
				dp[i] = 1;
			} else if(i == 1){
				dp[i] = dp[0] + 1;
			} else {
				dp[i] = (dp[i-1]+dp[i-2])%1000000007;
			}
		}
		System.out.println(dp[n-1]);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 42696
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &e: v) cin >> e;
    sort(v.begin(), v.end());

    double d = 1.0;
    double ans = 0;
    for (int i = n-1; i > 0; --i) {
        d *= 2.0;
        ans += v[i]/d;
    }
    ans += v[0]/d;

    cout << fixed << setprecision(20) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mx INT_MAX
#define mn INT_MIN
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define itr set<int> :: iterator
const int N = 1e5+10;

ll dp[101][100001];
ll wt[100001];
ll val[100001];
int n;

ll solve(int nW, int ind){
    
    if(ind == n)
        return nW==0 ? 0:mx;

    if(dp[ind][nW]!=-1)
        return dp[ind][nW];

    ll ans = solve(nW, ind+1);

    if(val[ind] <= nW){
        ans = min(ans, wt[ind]+solve(nW-val[ind], ind+1));
    }

    return dp[ind][nW] = ans;
}

int s(int vmaxx, int W){

    for(int i=vmaxx; i>=0; i--){
        if(solve(i, 0) <= W)
            return i;
    }

    return 0;
}

int main(){
    // ******* START HERE ******
    
    int W;
    cin>>n>>W;

    int vmaxx =0;
    for(int i=0; i<n; i++){
      int v, w;
      cin>>w>>v;
      val[i] = v;
      wt[i] = w;
      vmaxx +=val[i];
    }
    
    memset(dp, -1, sizeof(dp));
    cout<<s(vmaxx, W)<<endl;
    // ***** END HERE ***** 
    return 0;
}

Measured memory_bytes: 82520
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int x;
  cin >> x;
  if (x == 0) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


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

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

  vector<int> H(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &H.at(i));
  }

  for (int i = N - 1; i > 0; i--) {
    if (H.at(i) < H.at(i - 1)) {
      H.at(i - 1)--;
    }

    if (H.at(i) < H.at(i - 1)) {
      printf("No");
      return 0;
    }
  }
  
  printf("Yes");
  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main()
{
    FASTIO;
    int Count=0;
    string pattern,txt;
    cin>>pattern;
    while(1)
    {
        getline(cin,txt);
        if(txt=="END_OF_TEXT")
            break;
        transform(txt.begin(), txt.end(), txt.begin(), ::tolower);
        int len=txt.length();

        for(int i=0; i<len; i++)
        {
            if(ispunct(txt[i]))// space is not punctuation
            {
                txt.erase(i--,1);
            }
            len=txt.length();
        }

        stringstream ss(txt);
        string word;//to hold string
        while(ss >> word)
        {
            if(word==pattern)
                Count+=1;
        }

        txt.clear();
    }

    cout<<Count<<endl;
    return 0;
}



Measured memory_bytes: 3164
let words str =
  let len = String.length str in
  let buf = Buffer.create 4 in
  let rec aux i l =
    if i >= len then
      List.rev (int_of_string (Buffer.contents buf) :: l)
    else 
      match str.[i] with
      | ' ' ->
        let s = int_of_string (Buffer.contents buf) in
        Buffer.clear buf;
        aux (i+1) (s::l)
      | c   ->
        Buffer.add_char buf c;
        aux (i+1) l
  in
  aux 0 []

let () =
  let n,m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n,m) in
  let aux lim =
    let rec loop i l =
      if i >= lim then List.rev l
      else
        let am = read_line () in
        loop (i+1) (words am :: l)
    in
    loop 0 [] in
  let a = aux n in
  let b = List.concat (aux m) in
  List.iter
    (fun am ->
       let c = List.map2 (fun x y -> x*y) am b in
       print_int (List.fold_left (fun acc n -> acc + n) 0 c);
       print_newline ())
    a

Measured memory_bytes: 3272
def main():
    a, b = (int(i) for i in input().split())
    if a <= 0 and 0 <= b:
        print("Zero")
    elif a > 0:
        print("Positive")
    elif b < 0:
        if (b - a) % 2 == 0:
            print("Negative")
        else:
            print("Positive")
if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
//#pragma GCC optimize (2)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii =  pair<int,int>;
const int  dir[2][2] = {{-1,0},{0,1}};
const int mod = 1000000007;
const int INF = 0x3f3f3f;
#define all(v) v.begin(),v.end()
ll quick_pow(ll base, ll n) {
    ll ans = 1;
    while (n ) {
        if (n & 1 )ans *= base;
        base *= base;
        n >>= 1;
    }
    return ans;
}
void solution();
int main() {
    int T = 1;
//    cin>>T;
    while (T--) {
        solution();
    }
    return 0;
}
void solution(){
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<int(ceil((double ) a/b))*c<<endl;
}

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

int N, M, a, b;
bool cek1[200010], cek2[200010];
int main () {
    cin >> N >> M;
    for (int i =1; i<=M; i++){
        cin >> a >> b;
        if (a==1){
            cek1[b] = true;
        }
        else if (b == N) {
            cek2[a]=true;
        }
    }
    // cari diantara pulau 2..N-1
    // mana pulau yg terhubung ke 1 dan juga ke N
    // yaitu yg (cek1[i] && cek2[i])
    bool valid = false;
    for (int i =1; i<=M; i++){
        if ((cek1[i]==true)&&(cek2[i]==true)){
            valid=true;
        }
    }
   if (valid == true) {
       cout<< "POSSIBLE" << endl;
   }     
   else {
       cout<< "IMPOSSIBLE" << endl;
   }
}


Measured memory_bytes: 3820
/**                                                     **\
 *    created by:   Divianshu Bansal                     *
 *    e-mail id:    god_coder@icloud.com                 *
*                                                        */

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>


using namespace std;
using namespace __gnu_pbds;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>new_data_set;
#define MOD 1000000007
#define int long long
#define BIG 998244353
#define pf push_front
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589


int power(int x, int y) {
    int r = 1, z = x;
    while (y) {
        if (y & 1)r *= z;
        z *= z; y = y >> 1;
    }
    return r;
}
int powerm(int x, int y, int p) {
    int r = 1;
    while (y) {
        if (y & 1)r = (r * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return r % p;
}
int modinv(int x, int m) {
    return powerm(x, m - 2, m);
}
int logarithm(int a, int b) {
    int x = 0;
    while (a > 1) {
        x++;
        a /= b;
    }
    return x;
}
int max3(int a, int b, int c) {
    return max(a, max(b, c));
}
int min3(int a, int b, int c) {
    return min(a, min(b, c));
}
int32_t main() {
    fast;
    int n;
    cin >> n;
    string ans = "";
    --n;
    while (n >= 0) {
        int x = n % 26;
        char a = 'a' + x;
        ans += a;
        n /= 26;
        --n;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}

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

int main(){
  int data[101]={},n,num=0;
	while(cin >> n) data[n]++;
	for(int i=1;i<=100;i++)if(data[i]>num)num=data[i];
	for(int i=1;i<=100;i++)if(data[i]==num)cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
struct data
{
    int pos;
    int num;
}a[maxn];
int ans[maxn];
bool cmp(data a,data b)
{
    return a.num<b.num;
}
int main()
{
    ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].num;
        a[i].pos=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        if(i<=n/2)
            ans[a[i].pos]=a[n/2+1].num;
        else
            ans[a[i].pos]=a[n/2].num;
    }
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 4608
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long X = sc.nextLong();
		long money = 100;
		int ans = 0;
		while(money<X) {
			money += money/100;
			ans++;
		}
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 27048
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner scan = new Scanner(System.in);
    int X = scan.nextInt();
     if(X==7 || X==5 || X==3){
      System.out.println("YES") ;
     }
    else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main(){
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
  if (x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H){
  cout<<"Yes"<<endl;
  } else {
  cout<<"No"<<endl;
  
  } return 0;
  }

Measured memory_bytes: 3060
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        int count = 0;
        int ans = 0;
         for(int i = 0; i <= N ; i++){
            if(i % 2 != 0){
              for(int j = 1; j <= i; j++){
                if(i % j == 0){
                  count++;
                }
              }
             if(count == 8){
               ans++;
             } 
            }
            count = 0;
          }
          
          System.out.println(ans);
        
     
	}
}

Measured memory_bytes: 35632
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< "0" <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

map<ll,ll> zip;
ll unzip[200010];
ll compress(vector<ll> ve) {
    SORT(ve);
    ve.erase(unique(ALL(ve)),ve.end());
    rep(i,ve.size()){
        zip[ve[i]] = i;
        unzip[i] = ve[i];
    }
    return ve.size();
}

struct BIT{
    int M;
    vector<ll> bit;
    BIT(int n): M(n), bit(M+1,0) {}

    void add(int a, ll w=1) { // aを +w  aは 1-indexed
        for(int x=a; x<=M; x+= x& -x){
            bit[x] += w;
        }
    }

    ll sum(int a) { // [1,a] 1-indexed
        ll ret=0;
        for(int x=a; x>0; x-= x& -x){
            ret+= bit[x];
        }
        return ret;
    } // 左上のものをすべて足す
};

//--MAIN-----------------------------------
void Main() {
    ll N,K; cin>>N>>K;
    vector<ll> A(N),B(N);
    rep(i,N) cin>>A[i];
    rep(i,N) B[i]=A[i]-K;
    reps(i,1,N) B[i]+=B[i-1];
    compress(B);
    BIT bi(N+1);
    ll ans=0;

    rep(i,N){
        ans+=bi.sum(zip[B[i]]+1);
        bi.add(zip[B[i]]+1);
        if(B[i]>=0) ++ans;
    }

    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 19072
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
      	Double SUM = 0.;
      	int N = s.nextInt();
      	for (int i = 0; i < N; i++){
        	Double M = s.nextDouble();
      		if (s.next().equals("JPY")) SUM += M;
            else SUM += M * 380000.0;
        }
        System.out.println(SUM);
	}
}


Measured memory_bytes: 25044
R, G, B = list(map(int, input().split()))
K = int(input())

def f(R,G,B):
  if R<G and G<B:
    return 1
  elif R<G and G>=B:
    return 2
  else:
    return 3

c = 0
fl = 0

while c <= K:
  c +=1
  if f(R,G,B)==1:
    fl = 1
    c = K+1
  elif f(R,G,B)==2:
    B = B*2
  else:
    G = G*2
    
if fl == 0:
  print("No")  
else:
  print("Yes")

Measured memory_bytes: 9204
#include<stack>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#define INF 0x7fffffff//1<<31-1
#define IP 3.141592654
#define LINF 9223372036854775807//1<<63-1
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define per(i,a,b) for(long long i=b-1;i>=a;i--)
using namespace std;
typedef long long LL;
const int maxn=2e5+10;
const int maxm=1e8+10;
int P[maxn];
int Q[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    memset(P,0,sizeof(P));
    rep(i,0,n)
    {
        int k;scanf("%d",&k);
        P[k]++;
        P[k+1]++;
        P[k-1]++;
    }
    int a=0,b=0;
    rep(i,-1,1e5+1)
    {
        if(P[i]>a){
            a=P[i];b=i;
        }
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 1024
n, x = map(int, input().split())
L = list(map(int,input().split()))
D = [0]*(n+1)
ans = 1
for i in range(n):
  D[i+1] = D[i] + L[i]
  if D[i+1] <= x:
    ans += 1
   
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 1010101010;

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

    string s;
    cin >> s;
    LL k;
    cin >> k;
    LL l = INF;
    REP(i, s.size()){
        if(s[i] != '1'){
            l=i;
            break;
        }
    }
    if(k <= l) cout << 1 << endl;
    else cout << s[l] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

n = int(sys.stdin.readline().rstrip())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, sys.stdin.readline().split())
    graph[u-1].append((v - 1, w))
    graph[v-1].append((u - 1, w))

def coloring_tree(g, size):
    par = [None] * size
    stack = [(0, 0)]
    color = [None] * size
    color[0] = 0
    while stack:
        u, d = stack.pop()
        color[u] = d & 1
        for v, w in g[u]:
            if par[u] == v:
                continue
            par[v] = u
            stack.append((v, d + w))
    return color

def main():
    return coloring_tree(graph, n)
    
if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 40352
#include<stdio.h>
int main()
{
 	int n;
  	scanf("%d",&n);
  	long long int sum=0;
  	int x,pos=0;
  	for(int i=0;i<n;i++)
    {
      scanf("%d",&x);
      if(pos>x)
      {
        sum=sum+(pos-x);
      }
      //printf("%d \t %d \n",x,pos);
      if(pos<=x)
      {
        pos=x;
      }
        
    }
  	printf("%lld \n",sum);
}

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

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

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

using namespace std;

int main() {

	string s;
	cin >> s;
	string t="AA";
	t[0] = s[0];
	t[1] = s[1];
	string u = "BB";
	u[0] = s[2];
	u[1] = s[3];

	int i = stoi(t);
	int j = stoi(u);

	if((i>12 || i==0) && j<=12 && j>0){
		cout << "YYMM" << endl;
	}
	else if (i <= 12 && i>0 && (j > 12 || j==0)) {
		cout << "MMYY" << endl;
	}
	else if (i <= 12 && j <= 12 && i>0 && j>0) {
		cout << "AMBIGUOUS" << endl;
	}
	else {
		cout << "NA" << endl;
	}

}

Measured memory_bytes: 256
array = []
while True:
    n = input()
    if n == "0 0":
        break
    array.append(n.split())
for i in range(len(array)):
    for i2 in range(int(array[i][0])):
        for i3 in range(int(array[i][1])):
            if i3 == int(array[i][1])-1:
                print("#")
            else:
                if i2 != 0 and i2 !=  int(array[i][0])-1:
                    if i3 != 0:
                        print(".",end="")
                    else:
                        print("#",end="")
                else:
                    print("#",end="")
    print("")

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
int main(void){
  
  int n,m,x,i,j;
  cin >> n >> m >> x;
  vector <vector<int> > a(n, vector<int>(m));
  vector <int> ans(12,0);
  int c[12];
  int money = 0,d=0;
  bool isOK = true;
  int count = 0;

  for(i=0;i<n;i++){
	cin >> c[i];
    for(j=0;j<m;j++){
     cin >> a[i][j];   
    }
    money += c[i];
  }
  
  int loop = (1 << n);

  int k;
  
  for(i=0;i<loop;i++){

    for(j=0;j<n;j++){
     if(i >> j & 1){ 
       for(k=0;k<m;k++){
      	ans[k] += a[j][k];
       }
      d += c[j];
     }
    }
    for(j=0;j<m;j++){
     if(ans[j] < x){
       isOK = false; 
     }
    }
    if(! isOK) count++;
    
    if(isOK == true & money > d){
     money = d;
    }
    isOK = true;
    d = 0;
    
    for(j=0;j<m;j++){
     ans[j] = 0; 
    }
  }
  
  if (count == loop){
    cout << -1;
    return 0;
  }
  cout <<  money;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;


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

	cin >> a >> b >> c >> d;

	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b == c + d) {
		cout << "Balanced" << endl;
	}
	else {
		cout << "Right" << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

template <class T> int getbit(T s, int i) { return (s >> i) & 1; }
template <class T> T onbit(T s, int i) { return s | (T(1) << i); }
template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template <class T> ll cntbit(T s) { return __builtin_popcntll(s); }

#define all(a) (a).begin(), (a).end()
#define ms(a, x) memset(a, x, sizeof(a))
#define forv(v, it) for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); it++)
#define print(x) cout << "L" << __LINE__ << " -- " << #x << " = " << x << endl
#define clear(x) v.clear(); vector<T>(v).swap(v)

#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define eps 1e-12

#define div ___div
#define next ___next
#define prev ___prev
#define left ___left
#define right ___right
#define y0 ___y0
#define y1 ___y1


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

  string abcd;
  cin >> abcd;

  for(int i = 0; i < 8; i++) {
    string binary = bitset<3>(i).to_string();

    int answer = int(abcd[0] - '0');

    string temp = "";
    temp.push_back(abcd[0]);
    for(int j = 0; j < 3; j++) {
      if(binary[j] == '1') {
        answer += int(abcd[j+1] - '0');
        temp.push_back('+');
      } else {
        answer -= int(abcd[j+1] - '0');
        temp.push_back('-');
      }
      temp.push_back(abcd[j+1]);
    }

    if(answer == 7) {
      temp = temp + "=7";
      cout << temp << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,c,k,x;
  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);

  for(int i=0;i<k;i++){
    if(a<b&&b<c){
      printf("Yes");
      return 0;
    }
    else if(a>=b){
      b = b*2;
      
    }
    else if(b>=c){
      c = c*2;
      
    }
  }
  if(a<b&&b<c) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int posi = 0;
    int minNum = 0;
    vector<int> elist(s.size(), 0);
    vector<int> wlist(s.size(), 0);
    if (s[0] == 'E')
        elist[0] = 1;
    if (s[0] == 'W')
        wlist[0] = 1;
    REP(i, 1, s.size())
    {
        if (s[i] == 'E')
        {
            elist[i] = elist[i - 1] + 1;
            wlist[i] = wlist[i - 1];
        }
        if (s[i] == 'W')
        {
            elist[i] = elist[i - 1];
            wlist[i] = wlist[i - 1] + 1;
        }
    }
    int num = INT_MAX;
    num = min(num, (elist.back()));
    REP(i, 1, elist.size())
    {
        num = min(num, (elist.back() - elist[i] + wlist[i]));
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;
//#define _USE_MATH_DEFINES

int main(void) {
	string a;
	cin >> a;
	sort(a.begin(), a.end());
	if (a == "abc") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 100000
using namespace std;
typedef long long ll;

int main(){
	int x;
	cin >> x;
	if (x < 1200) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ARC" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    t = int(ipt())

    for _ in [0]*t:
        n,a,b,c,d = map(int,ipt().split())
        dp = defaultdict(lambda:-1)
        dp[0] = 0
        dp[1] = d

        def calc(n):
            mi = d*n
            for i,x in {(2,a),(3,b),(5,c)}:
                if dp[n//i] == -1:
                    dp[n//i] = calc(n//i)
                if mi > d*(n-n//i*i)+x+dp[n//i]:
                    mi = d*(n-n//i*i)+x+dp[n//i]
                if not n%i == 0:
                    if dp[n//i+1] == -1:
                        dp[n//i+1] = calc(n//i+1)
                    if mi > d*((n//i+1)*i-n)+x+dp[n//i+1]:
                        mi = d*((n//i+1)*i-n)+x+dp[n//i+1]
            return mi

        print(calc(n))

    return



if __name__ == '__main__':
    main()


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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<a<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define DEBUG(a) 
#define DEBUG_ARRAY(a,n) 
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

int N;
pll D[100000];
ll d[100000];
int childnumD[100000];
vector<ll> ans[100000];
ll dfs(ll index,ll depth){
  ll ret = 0;
  DEBUG(index);
  for(auto&& i : ans[index])
  {
    DEBUG(i);
    ret+=depth+1;
    ret+=dfs(i,depth+1);
  }
  return ret;
}
int main(){
  cin>>N;
  REP(N){
    ll tmp;
    cin>>tmp;
    D[i]=pll(tmp,i+1);
  }
  sort(D,D+N,greater<pll>());
  REP(N){
    d[i]=D[i].first;
    DEBUG(d[i]);
  }
  for (int i = 0; i < N-1; i++) {
    ll tmp=d[i]-(N-2)+2*childnumD[i];
    DEBUG(tmp);
      auto itr=lower_bound(d,d+N,tmp,greater<ll>());
      DEBUG(*itr);
      if(itr==d+N||*itr!=tmp){
        cout<<-1<<endl;
        return 0;
      }
      ans[itr-d].push_back(i);
      childnumD[itr-d]++;
      childnumD[itr-d]+=childnumD[i];
  }
  if(dfs(N-1,0)!=d[N-1]){
    DEBUG(dfs(N-1,0));
    cout<<-1<<endl;
    return 0;
  }
  For(j,N){
    DEBUG(j);
  for(auto&& i : ans[j])
  {
    DEBUG(i);
    cout<<D[j].second<<" "<<D[i].second<<endl;
  }
  }
  
  return 0;
}



Measured memory_bytes: 11904
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = lr()
answer = 1
cur = P[0] #現在の最小値
for i in range(1, N):
    x = P[i]
    if cur >= P[i]:
        answer += 1
        cur = P[i]

print(answer)


Measured memory_bytes: 25716
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	int x, n;
	cin >> x >> n;
	vi a(n);
	unordered_map<int, int> m;
	rep(i, 0, n) {
		cin >> a[i];
		m[a[i]]++;
	}
	int ans = 10000, num = 0;
	rep(i, 0, 500) {
		if (m[i]) {
			continue;
		}
		// trace(i)
		int dist = abs(x - i);
		if (dist < ans) {
			ans = dist;
			num = i;
		}
	}
	cout << num;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    double a,sum;
    sum=0;
    std::deque<double> deq;
    while (cin>>a) {
        deq.emplace_back(0);
        deq.emplace_back(a);
        for (int i=2;i<11;i++) {
            if (i%2==0) {
                deq.emplace_back(deq[i-1]*2);
            } else {
                deq.emplace_back(deq[i-1]/3);
            }
        }
        for (int j=0;j<deq.size();j++) {
            sum=sum+deq[j];
        }
        printf("%.8f",sum);
        cout<<endl;
        sum=0.0;
        deq.clear();
    }
}


Measured memory_bytes: 3216
#include <iostream>
using namespace std;
int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int i,j,k;
  int cnt = 0;
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
        if(x==(500*i+100*j+50*k)) cnt++;
      }
    }
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    val N: Int = readLine()!!.toInt()
    val A: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    var flug = true
    for (a in A) {
        if (a % 2 == 0) {
            //
            if (a % 3 != 0 && a % 5 != 0) {
                // 入国条件を満たさない
                flug = false
            }
        }
    }

    if (flug) {
        print("APPROVED")
    } else {
        print("DENIED")
    }
}

Measured memory_bytes: 37936
#include <stdio.h>

void bubbleSort(int *,int);
void trace(int *,int);

int cnt=0;

int main(){
  int N=0,i,j;
  int A[100];

  scanf("%d",&N);
  for(i=0; i < N; i++){
    scanf("%d",&A[i]);
  }
  
  bubbleSort(A,N);

  return 0;
}

void trace(int *A,int N){
    int i;
    
    for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i != N-1)printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);
}

void bubbleSort(int *A,int N){
  int i,j=0;
  int tmp;
  //printf("hoge");
  for(i=0;i<N;i++){
    //printf("hoge2");
    j=N-2;
    while(j>=i){
      //printf("hoge");
      if(A[j]>A[j+1]) {
	tmp=A[j+1];
	A[j+1]=A[j];
	A[j]=tmp;
	cnt++;
      }
      j--;
    }
  }
  trace(A,N);
}



Measured memory_bytes: 2108
from collections import deque

def main():
    n = int(input())
    a = list(int(x) for x in input().split())
    b = list(int(x) for x in input().split())
    
    que = deque(a)
    ans = 0
    
    for i in b:
        q1 = que.popleft()
        if i >= q1:
            ans += q1
            q2 = que.popleft()
            if i-q1 >= q2:
                ans += q2
                que.appendleft(0)
            else: #i-q1 < q2
                ans += i-q1
                que.appendleft(q2-(i-q1))
        else: #i < q1
            ans += i
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 19000