akhauriyash/Code-Regression huggingface dataset:
import sys
N, L = map(int, input().split())
a = list(map(int, input().split()))

last = -1
for i in range(N-1):
    if a[i] + a[i+1] >= L:
        last = i
        break
if last == -1:
    print('Impossible')
    sys.exit()

print('Possible')
for i in range(last): print(i+1)
for i in range(N-1, last, -1): print(i)

Measured memory_bytes: 14060
def main(n):
    max_i = 1
    max_time = 1
    
    for i in range(1, n+1):
        max_time_tmp = 1
        is_even = True
        i_tmp = i
        while is_even:
            if i_tmp % 2 == 0:
                max_time_tmp += 1
                i_tmp = i_tmp / 2
            else:
                break
        if max_time_tmp > max_time:
            max_time = max_time_tmp
            max_i = i

    print(max_i)


n = int(input())
main(n)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	char c;
	cin >> c;
	cout << char(c + 1);

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m, l;
    cin >> n>>m>>l;
    int a[n][m], b[m][l];
    long long c[n][l];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> a[i][j];
    
    for(int i=0;i<m;i++)
        for(int j=0;j<l;j++) cin >> b[i][j];

    for(int i=0;i<n;i++) for(int j=0;j<l;j++) c[i][j]=0;

    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
            cout << c[i][j];
            if(j!=l-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3196
--https://www.lua.org/pil/11.4.html
local List = {}
function List.new ()
  return {first = 0, last = -1}
end

function List.pushleft (list, value)
  local first = list.first - 1
  list.first = first
  list[first] = value
end

function List.pushright (list, value)
  local last = list.last + 1
  list.last = last
  list[last] = value
end

function List.popleft (list)
  local first = list.first
  if first > list.last then return false end
  local value = list[first]
  list[first] = nil
  list.first = first + 1
  return value
end

function List.popright (list)
  local last = list.last
  if list.first > last then return false end
  local value = list[last]
  list[last] = nil
  list.last = last - 1
  return value
end

----------

local h,w=io.read("n","n","l")
local maze={}
local shounter=0
for i=1,h do
    local s=io.read()
    maze[i]={}
    for j=1,w do
        local sub=s:sub(j,j)
        if sub=="#" then
            shounter=shounter+1
        end
        maze[i][j]=sub
    end
end

local dx={1,0,-1,0}
local dy={0,1,0,-1}

local function bfs(x,y)
    local dist={}
    for i=1,h do
        dist[i]={}
        for j=1,w do
            dist[i][j]=-1
        end
    end
    local que=List.new()
    
    List.pushright(que,{x,y})
    dist[x][y]=1

    while x~=h and y~=w do
        local q=List.popleft(que)
        if not q then break end
        local x,y=q[1],q[2]
        for i=1,4 do
            local nx,ny=x+dx[i],y+dy[i]
            local checker=(nx<1 or nx>h or ny<1 or ny>w)
            if not checker and maze[nx][ny]~="#" and dist[nx][ny]==-1 then
                dist[nx][ny]=dist[x][y]+1
                List.pushright(que,{nx,ny})
            end
        end
    end
    
    return dist[h][w]
end

local mindist=bfs(1,1)
if mindist>-1 then
    print(h*w-(mindist+shounter))
else
    print(mindist)
end

Measured memory_bytes: 2884
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

bool check(char a, char b) {
	return a > b;
}

int kuraiwa(int n) {
	int ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

bool kaibun(int n) {
	int a[5];
	for (int i = 0;i < 5;i++) {
		a[i] = n % 10;
		n /= 10;
	}
	if (a[0] == a[4] && a[1] == a[3]) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = a;i <= b;i++) {
		if (kaibun(i)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for(int i=1;i<=N;i+=2){
            if(helper(i)==8) ans++;
        }
        System.out.println(ans);
    }
    public static int helper(int N){
        int up = (int) Math.floor(Math.sqrt(N));
        int cnt=2;
        for(int i=2;i<=N-1;i++){
            if(N%i==0) cnt++;
        }
        return cnt;
    }
}


Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

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

	for (int i = 0; i < (1 << n); i++) {
		vector<int> v;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j))	v.push_back(j);
		}
		cout << i << ":";
		for (int k = 0; k < v.size(); k++) {
			cout << " " << v[k];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3120
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 21001
#define int long long
using namespace std;

int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
const int MOD=1e9+7;
int n,a[MN],B[MN],x,mmh=0,mm[20][20][2][2];
inline int M(int x){return x<0?x+10:x;}
inline void work(int p,int n,int a,int b){
    if (mm[p][n][a][b]!=-1) {mmh+=mm[p][n][a][b];return;}
    int u=mmh;
    if (p+p-1==n){
        if (a==0&&b==0) mmh+=10*(B[p]==0);else
        if (a==1&&b==1) mmh+=10*(B[p]==9);
        return;
    }
    if (p+p-1>n){
        mmh+=a==b;
        return;
    }
    for (int i=p==1;i<=9;i++)
    for (int j=0;j<=9;j++)
    if (M(i-j-b)==B[p]&&(a==(j<i)||j==i)&&(M(j-i)==B[n+1-p]||M(j-1-i)==B[n+1-p])){
        if (a){
            if (j==i&&B[n+1-p]==0) continue;
            work(p+1,n,M(j-1-i)==B[n+1-p],i-b-j<0);
        }else{
            if (j==i&&B[n+1-p]==9) continue;
            work(p+1,n,M(j-1-i)==B[n+1-p],i-b-j<0);
        }
    }
    mm[p][n][a][b]=mmh-u;
}
signed main(){
    int i,j,k;
    x=n=read();
    if (n%9) return puts("0"),0;
    for (k=1;k<=10&&x;k++) B[k]=x%10,x/=10;k--;
    for (int i=k;i<=18;i++) memset(mm,-1,sizeof(mm)),work(1,i,0,0);
    printf("%lld\n",mmh);
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const int dh[4] = {0, 1, 0, -1};
const int dw[4] = {1, 0, -1, 0};
struct UnionFind {
    vector<int> data; int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) { return false; }
        if (data[x] > data[y]) { swap(x, y); }
        data[x] += data[y]; data[y] = x; sz--; return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int H, W;
    cin >> H >> W;
    UnionFind uf(H*W);
    vector<string> S(H);
    vector<long long> white(H*W, 0);
    for (int i = 0; i < H; i++) cin >> S[i];
    
    auto idx = [=] (int h, int w) { return h * W + w; };
    for (int h = 0; h < H; h++) for (int w = 0; w < W; w++) {
        int u = idx(h, w);
        for (int i = 0; i < 4; i++) {
            int nh = h + dh[i], nw = w + dw[i];
            int v = idx(nh, nw);
            if ((nh < 0 || H <= nh || nw < 0 || W <= nw)) continue;
            if (S[h][w] != S[nh][nw]) uf.unionSet(u, v);
        }
    }
    
    for (int h = 0; h < H; h++) for (int w = 0; w < W; w++) {
        int u = idx(h, w), i = uf.root(u);
        if (S[h][w] == '.') white[i]++;
    }
    
    long long ans = 0;
    for (int h = 0; h < H; h++) for (int w = 0; w < W; w++) {
        int u = idx(h, w), i = uf.root(u);
        if (S[h][w] == '#') ans += white[i];
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2304
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n = int(input())
    C = list(input())
    #print(C)    
    print('{:}'.format(C[:C.count('R')].count('W')))
    #print('R :{:}'.format(C.count('R')))

    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 29640
# coding: utf-8
# Here your code !
N = int(input())

aMax = 0
bMax = 0
for i in range(N) :
    s = input().split()
    a = int(s[0])
    b = int(s[1])
    
    #aが最大のindexを保存しておきたい
    if a > aMax :
        aMax = a
        bMax = b
        
print(aMax + bMax)

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

typedef long long LL;
const LL N = 10010;
LL a[N], b[N], c[N];
LL n;
bool v[N];

inline LL gcd(LL a, LL b)
{
    return (b ? gcd(b, a % b) : a);
}
/*bool ok(int p) {
    if (a[0] % p) {
        return false;
    }
    for (int i = 0; i <= n; ++i) {
        b[i] = a[i];
    }
    for (int i = n; i >= p - 1; --i) {
        (b[i - (p - 1)] += b[i]) %= p;
        b[i] = 0;
    }
    for (int i = 0; i <= n; ++i) {
        if (b[i] % p) {
            return false;
        }
    }
    return true;
}
bool isprime(int n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)return false;
    }
    return true;
}*/
int main()
{
    register LL p = 0, num = 0;
    scanf("%lld", &n);
    for (register LL i = n; i >= 0; --i) {
        scanf("%lld", &a[i]);
        p = gcd(p, abs(a[i])), b[i] = a[i];
    }
    for (register LL i = 2, q; i <= n; ++i) {
        if (v[i] == 1) continue;
        if(b[0]%i!=0)continue;
        for (register LL j = 0; j <= n; ++j)
            a[j] = b[j];
        for (register LL j = n; j >= i - 1; --j)
            a[j - (i - 1)] = (a[j] + a[j - (i - 1)]) % i, a[j] = 0;
        int f=0;
        for (register LL j = 0; j <= n; ++j) {
            if (a[j] % i != 0) //goto nxt;
            {
                f=1;
                break;
            }
        }
        if(!f) c[++num] = i;
        //nxt:;
        q = n / i;
        for (register LL j = i; j <= q; ++j)
            v[i * j] = 1;
    }
    /*for(int i=2;i<=n;i++){
    if(!isprime(i))continue;
    if(b[0]%i!=0)continue;
    for (register LL j = 0; j <= n; ++j)
            a[j] = b[j];
        for (register LL j = n; j >= i - 1; --j)
            a[j - (i - 1)] = (a[j] + a[j - (i - 1)]) % i, a[j] = 0;
        int f=0;
        for (register LL j = 0; j <= n; ++j) {
            if (a[j] % i != 0) //goto nxt;
            {
                f=1;
                break;
            }
        }
        if(!f) c[++num] = i;
    }*/
    /*for(int i=2;i<=n;i++)
    {
        if(isprime(i)&&ok(i))c[++num]=i;
    }*/
    for (register LL i = 2; i*i <= p; ++i) {
        if (p % i == 0) {
            c[++num] = i;
            while (p % i == 0) p = p / i;
        }
    }
    if (p > 1) c[++num] = p;
    sort(c + 1, c + num + 1);
    for (register int i = 1; i <= num; ++i) {
        if (c[i] == c[i - 1]) continue;
        printf("%d\n", c[i]);
    }
    return 0;
}


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

int main (){
  int h,w,n;
  cin>>h>>w>>n;
  swap(h,w);
  vector<pair<int,int>> vs(n);
  for(int i=0;i<n;i++){
    cin>>vs[i].second>>vs[i].first;
    vs[i].first--,vs[i].second--;
  }

  set<pair<int,int>> s;
  for(int i=0;i<n;i++) s.insert(vs[i]);
  for(int i=0;i<n;i++) s.insert({i,w});
  vector<int> okw(h,w);
  okw[0]=0;
  for(int i=1;i<h;i++){
    for(int j=okw[i-1]+1;j<=w;j++){
      if(!s.count({i,j})){
	okw[i]=j;
	break;
      }
    }
  }

  vector<int> obj(h,w);

  for(int i=0;i<n;i++){
    if(okw[vs[i].first]<=vs[i].second){
      obj[vs[i].first]=min(obj[vs[i].first],vs[i].second);
    }
  }

  int res=1e8;
  for(int i=0;i<h;i++){
    int sc=obj[i];
    res=min(res,sc);
  }
  cout<<res<<endl;
  
  
  return 0;
}

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

int N, A, B, C, D, judg = 0;
string S;

int main() {
	cin >> N >> A >> B >> C >> D >> S;
	int i, K;
	
	if (D < C)
		K = C;
	if (D > C)
		K = D;
	for (i = A; i < K-1; i++) {
		if (S[i] == '#'&&S[i + 1] == '#')
			judg = 1;
	}
	if (judg == 0 && D < C) {
		judg = 1;
		for (i = B-1; i < D - 2; i++) {
			if (S[i] == '.'&&S[i + 1] == '.'&&S[i + 2] == '.')
				judg = 0;
		}
		if (judg == 1) {
			if (S[D - 2] == '.'&&S[D] == '.')
				judg = 0;
			if (S[B - 2] == '.'&&S[B] == '.')
				judg = 0;
		}
	}
	
	if (judg == 0)
		cout << "Yes" << endl;
	if (judg == 1)
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;



int main(){
  int n;
  set<int> s;
  cin >> n;
  int ai;
  for(int i=0; i<n; i++){
    cin >> ai;
    s.insert(ai);
  }
  if(s.size()==n){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

int main(){
  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;
  vector<bool> water(30,false);
  for (int i=0;A*i<30;i++){
    for (int j=0;A*i+B*j<30;j++){
      water[A*i+B*j]=true;
    }
  }
  int w=0,s=0;
  double per=-1;
  for (int i=1;i<F/100+1;i++){
    if (water[i]){
      int smax=0;
      for (int j=0;C*j<=i*E;j++){
        for (int k=0;C*j+D*k<=i*E;k++){
          if (100*i+C*j+D*k<=F){
            smax=max(smax,C*j+D*k);
          }
        }
      }
      double c=(double)(100*smax)/(smax+100*i);
      if (c>per&&100*i+smax<=F){
        w=100*i,s=smax;
        per=c;
      }
    }
  }
  cout << w+s << ' ' << s << endl;
}

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

constexpr int MAX = 123456 * 2;
bool prime[MAX+1] = {false};

void eratos() {
    for(int i = 0; i <= MAX; ++i) {
        prime[i] = true;
    }

    for(int i = 2; i*i <= MAX; ++i) {
        if(prime[i]) {
            for(int j = i*i; j <= MAX; j = j+i) {
                prime[j] = false;
            }
        }
    }
    prime[0] = false;
    prime[1] = false;
}

int check(int min) {
    int ans = 0;
    for (int i = min+1; i < min * 2 + 1; ++i) {
        if (prime[i]) ans++;
    }
    return ans;
}

int main() {
    int n;
    eratos();
    while(cin>>n, n) {
        cout<<check(n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3332
x = int(input())
if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
elif 1800 <= x <= 1999:
    print(1)

Measured memory_bytes: 61648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        management solver = new management();
        solver.solve(1, in, out);
        out.close();
    }

    static class management {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] nums = new int[n + 1];
            for (int i = 2; i <= n; i++) {
                int boss = in.nextInt();
                nums[boss]++;
            }

            for (int i = 1; i <= n; i++) {
                out.append(String.valueOf(nums[i]) + "\n");
            }
        }

    }
}



Measured memory_bytes: 60776
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#define _GLIBCXX_DEBUG
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

//dp[i][j]:i個目において、i個を左詰めしたときの幸福度の最大値を表す
long long dp[2002][2002];

int main() {
    int N;cin >> N;
    vector<int> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    vector<P> num(N);
    //first:活発度,second:位置
    for(int i = 0;i<N;i++){
        num.at(i).first = retu.at(i);
        num.at(i).second = i;
    }
    sort(num.begin(),num.end());
    reverse(num.begin(),num.end());
    for(int i = 0;i<2002;i++)for(int j = 0;j<2002;j++)dp[i][j] = 0;

    //活発度が大きい順に右か左かを選択する
    //↑活発度が大きいのが端に移動するのが良いため
    for(int i = 0;i<N;i++){
        //i個目までに左詰めされた要素が何個あるか
        for(int left = 0;left <= i;left++){
            int right = i - left;
            //その要素を左に詰める
            chmax(dp[i+1][left+1],dp[i][left]+(long long)num.at(i).first*(num.at(i).second-left));
            //右に詰める
            chmax(dp[i+1][left],dp[i][left]+(long long)num.at(i).first*((N-right-1)-num.at(i).second));
        }
    }

    long long ans = 0;
    for(int i = 0;i<=N;i++){
        ans = max(ans,dp[N][i]);
    }

    cout << ans << endl;


    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 35008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int(i)=0 ; (i)<(int)(n) ; ++(i))
#define per(i,n) for(int(i)=(int)(n-1) ; (i)>=0 ; --(i))
#define replu(i,l,u) for(int(i)=(int)(l) ; (i)<=(int)(u) ; ++(i))
#define repul(i,u,l) for(int(i)=(int)(u) ; (i)>=(int)(l) ; --(i))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int>  vi ;
typedef pair<int,int> pii ;
typedef vector<pair<int,int> > vpii ;
typedef long long ll ;
const long mod=1e9+7 ;
const ll inf=2e9+10 ;
template <typename T1, typename T2> static void relax(T1 &x, T2 y) { if(x>y) x = y ; }
template <typename T1, typename T2> static void gain(T1 &x, T2 y) { if(x<y) x = y ; }
ll powmod(ll a, ll b) { ll res = 1 ; while(b) { if(b&1) res = (res*a)%mod ;  a = (a*a)%mod ; b >>= 1 ; }  return res ; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a ; }

const int maxn = 2e5 + 5 ;
int n ;
int a[maxn];
ll ps[maxn] ;
int main() {
   ios::sync_with_stdio(false) ;
   cin.tie(NULL) ;
   cin >> n ;
   rep(i,n) cin >> a[i] ;
   ps[0] = a[0] ;
   replu(i,1,n-1) ps[i] = ps[i-1] + a[i] ;
   map<ll, int> ds ;
   rep(i,n) { ds[ps[i]]++ ; }
   ll ans = 0 ;

   for(map<ll, int> :: iterator it = ds.begin() ; it!=ds.end() ; ++it) {
    ll x = it -> se ;
    if(x>=2)
     ans += (x*(x-1))/2 ;
     if(it -> fi == 0) ans += x ;
   }
    cout << ans << "\n" ;
  return 0 ;
}


Measured memory_bytes: 15104
#include <iostream>
#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

string solve(const string& S, int K) {
   string res = S;
   int N = SZ(S);
   for (int i = 0; i < N && K > 0; ++i) {
      if (res[i] == 'a') continue;
      int req_steps = 'z' - res[i] + 1;
      if (req_steps <= K) {
         res[i] = 'a';
         K -= req_steps;
      }
   }

   K %= 26;

   res.back() = (res.back() - 'a' + K) + 'a';

   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   string S;
   cin >> S;

   int K;
   cin >> K;

   string res = solve(S, K);
   cout << res << endl;

   return 0;
}


Measured memory_bytes: 576
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],max=0,max2=0,x,y;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>max)
        {
            max=a[i];
            x=i;
        }
        else if(a[i]>max2 && max2!=max)
        {
            max2=a[i];
        }
    }
    for(int i=0;i<n;i++)
    {
        if(i==x)
        {
            cout<<max2<<"\n";
        }
        else
        {
            cout<<max<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair

int main() {
    int n,k;
    cin>>n>>k;
    if(k==1)
    {
        cout<<0;
        return 0;
    }
    n-=k;
    cout<<n;
    return 0;
}


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

signed main() {
    int sum;
    string n;
    
    cin >> n;
    sum = 0;
    for (int i=0 ;i<n.size() ;i++ ) {
        sum += n[i] - '0';
        
        sum = sum % 9;
    }
    
    if(sum == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return (0);
}

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

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	vector<int>ropes;
	for (int i = 0; i < N; i++) {
		int rope;
		cin >> rope;
		ropes.push_back(rope);
	}
	int last = -1;
	for (int i = 0; i < N - 1; i++) {
		if (ropes[i] + ropes[i + 1] >= L) {
			last = i;
			break;
		}
	}
	if (last == -1) {
		cout << "Impossible" << endl;
	}
	else {
		last += 1;
		cout << "Possible" << endl;
		for (int i = 1; i < last; i++) {
			cout << i << endl;
		}
		for (int i = N - 1; i > last; i--) {
			cout << i << endl;
		}
		cout << last << endl;
	}
	return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

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

  cout << min(N%K, K-N%K) << endl;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
def ok(p):
  result = 0
  for i in range(n):
    result += max(a[i]-p//f[i],0)
  if result <= k:
    return True
  return False

L = 0
U = a[-1]*f[0]
while U-L >= 1:
  M = (U+L)//2
  if ok(M):
    U = M
  else:
    L = M+1
    
print(U)


Measured memory_bytes: 119500
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=1010;


signed main(){
    ll h,w,m;cin>>h>>w>>m;
    set<pll>st;
    map<ll,ll>x,y;
    ll mx=0,my=0;
    rep(i,m){
        ll a,b;cin>>a>>b;
        x[a]++;
        y[b]++;
        mx=max(mx,x[a]);
        my=max(my,y[b]);
        st.insert(mp(a,b));
    }
    vector<ll>cnty(h+1);
    ll cnt=0;
    vector<ll>used(w+1);
    for(auto e:st){
        if(y[e.se]==my&&x[e.fi]==mx)cnty[e.fi]++;
        if(y[e.se]==my){
            if(used[e.se]==0)cnt++;
            used[e.se]=1;
        }
    }
    ll d=1;
    for(auto e:x){
        if(e.se==mx&&cnty[e.fi]<cnt)d=0;
    }
    cout<<mx+my-d<<endl;
}

Measured memory_bytes: 64056
#include <bits/stdc++.h>
#define N 101
#define M 51
using namespace std;
int n,m,l;
double p[N],t[N],d[N];
vector<double> A[N],B[N];

double nCr(int n, int r){
  if(r==0||n==r)return 1;
  double a=1;
  for(int i=0;i<r;i++) a*=(n-i)/(i+1.0);
  return a;
}

double DP(){
  double dp[N][M]={};
  for(int i=0;i<=m;i++)dp[0][i]=A[0][m-i]*B[0][i]*nCr(m,i);
  
  for(int i=1;i<n;i++)
    for(int j=0;j<=m;j++)
      for(int k=0;k<=m;k++)
	if(d[0]+j*t[0]<d[i]+k*t[i]) 
	  dp[i][j]+=dp[i-1][j]*A[i][m-k]*B[i][k]*nCr(m,k);

  double res=0;
  for(int i=0;i<=m;i++)res+=dp[n-1][i];
  return res;
}

int main(){
  cin>>n>>m>>l;
  for(int i=0;i<n;i++)cin>>p[i]>>t[i]>>d[i],p[i]/=100,d[i]=l/d[i];
  for(int i=0;i<n;i++) {
    //A???j?????????????????£????¢????
    //B???j?????????????¢???????
    A[i]=B[i]=vector<double>(m+1,0);
    A[i][0]=B[i][0]=1;
    for(int j=1;j<=m;j++){
      A[i][j]=A[i][j-1]*(1-p[i]);
      B[i][j]=B[i][j-1]*p[i];
    }
  }
  for(int i=0;i<n;i++){
      printf("%.10f\n",DP());
      swap(p[0],p[i+1]);
      swap(t[0],t[i+1]);
      swap(d[0],d[i+1]);    
      swap(A[0],A[i+1]);    
      swap(B[0],B[i+1]);    
  }
  return 0;
}

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

struct Card
{
    char Name;
    int  Value;
};

int Partition(std::vector<Card>& List, int p, int r);
void Quicksort(std::vector<Card>& List, int p, int r);
string IsStable(vector<Card> Org, vector<Card> After);

int Partition(std::vector<Card>& List, int p, int r)
{
    int x = List[r].Value;
    int i = p - 1;
    Card Temp;
    
    for(int j = p; j < r; j++){
        if(List[j].Value <= x){
            i++;
            Temp    = List[i];
            List[i] = List[j];
            List[j] = Temp;
        }
    }
    Temp    = List[i + 1];
    List[i + 1] = List[r];
    List[r] = Temp;
    
    return i + 1;
}

void Quicksort(std::vector<Card>& List, int p, int r)
{
    if(p < r){
       int q = Partition(List, p, r);
       
       Quicksort(List, p, q - 1);
       Quicksort(List, q + 1, r);
    }
}

string IsStable(vector<Card> Org, vector<Card> After)
{
    for(int i = 0; i < Org.size(); i++){
        for(int j = i + 1; j < Org.size(); j++){
            if(Org[i].Value != Org[j].Value)    continue;
            for(int a = 0; a < Org.size(); a++){
                if(Org[j].Name != After[a].Name) continue;
                if(Org[j].Value != After[a].Value)  continue;
                for(int b = a + 1; b < Org.size(); b++){
                    if(Org[i].Name == After[b].Name 
                    && Org[i].Value == After[b].Value){
                        return "Not stable";
                    }
                }
            }
        }
    }
    return "Stable" ;
}

int main(void){
    int Num;
    std::cin >> Num;
    
    std::vector<Card> Org, After;
    Org.clear();
    for(int i = 0; i < Num; i++){
        Card Temp;
        std::cin >> Temp.Name;
        std::cin >> Temp.Value;
        Org.push_back(Temp);
    }
    
    After = Org;
    Quicksort(After, 0, After.size() - 1);
    
    std::cout << IsStable(Org, After) << std::endl;
    
    for(int i = 0; i < After.size(); i++){
        std::cout << After[i].Name << " " << After[i].Value << std::endl;
    }
}

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (a, b) = [int(e) for e in lines[0].split(" ")]

    return (a, b)


def solve(a, b):

    if a <= 9 and b <= 9:
        result = a * b
    else:
        result = -1

    return result

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
H, W = [int(i) for i in input().split()]
list = [list(input()) for i in range(H)]
dxy = [(-1,0), (1, 0), (0, 1), (0, -1)]
flg = True
for i in range(H):
    for j in range(W):
        count = 0
        if list[i][j] == ".":
            continue
        if list[i][j] == "#":
            for l, m in dxy:
                if (i + l < 0) or (i + l > H -1) or (j + m < 0) or (j + m > W -1):
                    continue
                if list[i + l][j + m] == "#":
                    count += 1
        if count == 0:
            flg = False
if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
from itertools import permutations
from math import sqrt

n = int(input())

temp_list = []
for i in range(n):
    temp_list.append([int(s) for s in input().split()])

ans = 0
for count, temp in enumerate(permutations(list(range(n)))):
    for i in range(n - 1):
        a = temp[i + 1]
        b = temp[i]
        ans += sqrt((temp_list[a][0] - temp_list[b][0]) ** 2 + (temp_list[a][1] - temp_list[b][1]) ** 2)

ans /= (count + 1)
print(ans)

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

int main(void){
 int a,b,c,x;
 cin>>a>>b>>c>>x;
 int ans=0;
 for(int i=0;i<a+1;i++)
   for(int j=0;j<b+1;j++)
     for(int k=0;k<c+1;k++)
        if(i*500+100*j+50*k == x) ans++;

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


Measured memory_bytes: 256
lst=[]
lt=[]
for i in range (10):
    n=int(input())
    lst.append(n)
lst.sort()
for i in range(7):
    lst.pop(0)

    
for i in range (10):
    m=int(input())
    lt.append(m)
lt.sort()
for i in range(7):
    lt.pop(0)

    
a=sum(lst)
b=sum(lt)
print(f'{a:.3g} {b:.3g}')




Measured memory_bytes: 5628
h,w = map(int,input().split())

a = []

for i in range(h):
	a.append(list(map(int,input().split())))
ans = []
for i in range(h):
	for j in range(w-1):
		if a[i][j] % 2 == 1:
			a[i][j+1] += 1
			ans.append([i+1,j+1,i+1,j+2])

for k in range(h-1):
	if a[k][w-1] % 2 == 1:
		a[k+1][w-1] += 1
		ans.append([k+1,w,k+2,w])
print(len(ans))
for i in ans:
	print(i[0],i[1],i[2],i[3])

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

const long long md = 1e9 + 7;

int n;
string s1, s2;

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

	int i = 0, status = 0;
	long long ans = 1;

	for(int i = 0; i < n; ++i) {
		if(s1[i] == s2[i]) {
			if(status == 0) ans = ans * 3;
			else if(status == 1) ans = ans * 2;
			status = 1;
		} else {
			if(status == 0) ans = ans * 6;
			else if(status == 1) ans = ans * 2;
			else if(status == 2) ans = ans * 3;
			status = 2;
			i++;
		}
		ans %= md;
	}

	cout << ans << endl;
}

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

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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    int a;
    string s;
    cin >> a >> s;

    cout << (a >= 3200 ? s : "red") << endl;

    return 0;
}


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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }


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

    int ans;
    ans = n/111;
    ans *= 111;
    if(n%111!=0&&n!=111) ans += 111;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 16;
int n,m,w[N][N],f[1<<N][N],cost1[1<<N],cost2[1<<N][N];
inline void input(void)
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++)
    {
        int a,b,v;
        scanf("%d%d%d",&a,&b,&v);
        w[a][b] = w[b][a] = v;
    }
}
inline void init(void)
{
    for (int S=1;S<1<<n;S++)
        for (int i=1;i<=n;i++)
            if ( S >> (i-1) & 1 )
                for (int j=i+1;j<=n;j++)
                    if ( S >> (j-1) & 1 )
                        if ( w[i][j] != 0 )
                            cost1[S] += w[i][j];
    for (int S=1;S<1<<n;S++)
        for (int i=1;i<=n;i++)
            if ( not ( S >> (i-1) & 1 ) )
                for (int j=1;j<=n;j++)
                    if ( S >> (j-1) & 1 )
                        if ( w[i][j] != 0 )
                            cost2[S][i] += w[i][j];
}
inline void dp(void)
{
    memset( f , 0xff , sizeof f );
    f[1][1] = 0;
    for (int S=1;S<1<<n;S++)
        for (int i=1;i<=n;i++)
            if ( ( S >> (i-1) & 1 ) && f[S][i] != -1 )
            {
                for (int j=1;j<=n;j++)
                    if ( not ( S >> (j-1) & 1 ) )
                        if ( w[i][j] )
                            f[S|(1<<j-1)][j] = max( f[S|(1<<j-1)][j] , f[S][i] + w[i][j] );
                int G = (1<<n) - 1 - S;
                for (int T=G;T;T=G&(T-1))
                {
                    int val = cost1[T] + cost2[T][i];
                    f[S|T][i] = max( f[S|T][i] , f[S][i] + val );
                }
            }
}
int main(void)
{
    input();
    init();
    dp();
    printf("%d\n",cost1[(1<<n)-1]-f[(1<<n)-1][n]);
    return 0;
}


Measured memory_bytes: 8704
import sys

def check(bits, M, k, s, p):
    for x in range(M):
        dec = 0
        for K in range(k[x]):
            if bits >> (s[x][K] - 1) & 1:
                dec += 1
            else:
                pass

        if dec % 2 == p[x]:
            pass
        else:
            return 0

    return 1


def main():
    N, M = map(int, input().split())

    k = [0] * M
    s = [0] * M
    for i in range(M):
        k[i], *s[i] = map(int, input().split())

    p = list(map(int, input().split()))


    ans = 0
    for bits in range(2 ** N):
        ans += check(bits, M, k, s, p)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

template<typename T> T gcd(T a, T b) {
	if (a < b) return gcd(b, a);
	T r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

std::vector<std::pair<LL, LL>> prime_factor;
template<typename T> void prime_factorization(T num) {
	T L = static_cast<T>(ceil(sqrt(num)));
	for (T x = 2; x <= L; x++) {
		bool flg = false;
		while (num % x == 0) {
			if (flg) prime_factor.back().second++;
			else prime_factor.emplace_back(make_pair(x, 1));
			flg = true;
			num /= x;
		}
		if (num == 1) break;
	}
	if (num > 1) prime_factor.emplace_back(make_pair(num, 1));
}

signed main() {
	LL a, b;
	cin >> a >> b;
	
	LL c = gcd(a, b);
	prime_factorization(c);
	LL ans = prime_factor.size() + 1;
	col(ans);
	return 0;
}

Measured memory_bytes: 3732
let n = stdin.ReadLine() |> int

let a =
  [for _ in 1 .. n -> stdin.ReadLine() |> (fun x -> (int x) - 1) ]
  |> List.toArray

let ans =
  [|
    let mutable tmp = 0
    yield tmp
    for i in 1 .. n do
      tmp <- a.[tmp]
      yield tmp
  |]
  |> Array.tryFindIndex (fun i -> i = 1)
  |> (fun x ->
        match x with
        | Some i -> i
        | None -> -1 )

ans |> stdout.WriteLine

Measured memory_bytes: 20956
def main():
    N=int(input())
    digit=len(str(N))
    s=0
    for i in range(1,digit):
        if i %2==1:
            s=s+9*(10**(i-1))
    if digit%2==1:
        s=s+N-10**(digit-1)+1
    print(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(){
    int x,y,len;
    char digit[100];

    while(scanf("%d %d",&x,&y) != EOF){
        sprintf(digit, "%d", x+y);
        len = strlen(digit);
        printf("%d\n",len);
    }

    return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 100010
ll cnt[2][N],n;
int main(){
    cin>>n;
    lol(i,N)cnt[0][i]=cnt[1][i]=0;
    lol(i,n){
	int a;cin>>a;
	if(i&1)cnt[0][a]++;
	else cnt[1][a]++;
    }
    ll maxi=0,pnt=-1;
    lol(i,N)if(maxi<cnt[0][i])maxi=cnt[0][i],pnt=i;
    ll maxo=0,pno=-1;
    lol(i,N)if(maxo<cnt[1][i])maxo=cnt[1][i],pno=i;
    ll ans=maxi+maxo;
    if(pnt==pno){
	ll m=0,t=0;
	lol(i,N)if(i!=pnt)m=max(m,cnt[0][i]);
	lol(i,N)if(i!=pno)t=max(t,cnt[1][i]);
	ans=max(m+maxo,t+maxi);
    }
    cout<<n-ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
def main():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n-1):
        if a[i] + a[i+1] > x:
            num_to_eat = min(a[i+1], a[i] + a[i+1] - x)
            ans += num_to_eat
            a[i+1] -= num_to_eat
            if a[i] + a[i+1] > x:
                num_to_eat = min(a[i], a[i] + a[i+1] - x)
                ans += num_to_eat
                a[i] -= num_to_eat

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14844
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

int n;

void run() {
	scanf("%d", &n);
	int sum = 0;
	for (int x = n; x != 0; x /= 10) sum += x % 10;
	printf("%d\n", sum == 1 ? 10 : sum);
}

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


Measured memory_bytes: 256
def c_4adjacent():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]

    count = defaultdict(int)
    for a in A:
        count[a % 4] += 1
    num_4, num_2, num_other = count[0], count[2], count[1] + count[3]

    if num_2 == 0:
        # 14141 のように並べられるか (余った4はまとめて端に置く)
        ans = 'Yes' if num_other <= num_4 + 1 else 'No'
    else:
        # 2...24141 のように並べられるか (余った4はまとめて端に置く)
        ans = 'Yes' if num_other <= num_4 else 'No'
    return ans

print(c_4adjacent())

Measured memory_bytes: 14636
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int x,n;
  cin>>x>>n;
  int p[n];
  bool b[102];
  for(int i=0;i<102;i++){
      b[i]=true;
  }
  for(int i=0;i<n;i++){
      cin>>p[i];
      b[p[i]]=false;
  }
  int a=10000;
  int ans;
  for(int i=0;i<102;i++){
    if(b[i]){
        if(a>abs(x-i)){
            a=abs(x-i);
            ans=i;
        }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3596
// vim: shiftwidth=2 expandtab foldmethod=marker

// include {{{
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <utility>
#include <cstdlib>
#include <random>
#include <chrono>
// }}}

// debug(...) {{{
#ifdef LOCAL_DEBUG
#include "./debug.h"
#else
#define debug(...)
#define debugn(...)
#define debug_reset()
#endif

#include <cstdio>

template<class T>
std::string bin(int bits, const T& x) {
  char buf[bits + 1];
  buf[bits] = '\0';
  for(int i = 0; i < bits; i++) {
    if((x >> i) & 1) {
      buf[bits - i - 1] = '1';
    } else {
      buf[bits - i - 1] = '0';
    }
  }
  return std::string(buf);
}
std::string bin(int x) {
  if(x < 0) return bin(32, x);
  for(int i = 4; i < 31; i++) {
    int y = 1 << i;
    if(x < y) return bin(i, x);
  }
  return bin(32, x);
}
// }}}

// misc {{{
using namespace std;
template<class T, class U>

using umap = unordered_map<T, U>;
template<class T>
using uset = unordered_set<T>;

typedef long long ll;

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

template<class T>
void sort(T& arr) {
  std::sort(arr.begin(), arr.end());
}
template<class T, class By>
void sort_by(T& arr, By by) {
  std::sort(arr.begin(), arr.end(), [by](auto l, auto r){return  by(l) < by(r); });
}

template<class T>
void reverse(T& arr) {
  std::reverse(arr.begin(), arr.end());
}

class Random {
  public:
  std::uniform_int_distribution<> uniform_int;
  std::mt19937 rnd;
  std::bernoulli_distribution bern_dist;
  int uniform(int l, int r) {
    return uniform_int(rnd, std::uniform_int_distribution<>::param_type(l, r));
  }
  int next(int N) {
    return uniform(0, N - 1);
  }
  int bern(double p) {
    return bern_dist(rnd, std::bernoulli_distribution::param_type(p));
  }
};

template <class A>
ostream& out_vec(const vector<A>& x, const string& sep) {
  rep(i, x.size()) {
    cout << x[i];
    if(i < x.size() - 1)
      cout << sep;
  }
  return cout;
}
// }}}

// main {{{
void solve();
int main() {
  cout << setprecision(20);
  solve();
}
// }}}

void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<int> x(N);
  rep(i, N) {
    x[A[i] - 1] = i + 1;
  }

  out_vec(x, " ") << endl;
}


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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

using Num=double;
using Vec=vector<Num>;
using Mat=vector<Vec>;
const Num Inf=numeric_limits<Num>::infinity();
const Num NoSolution=numeric_limits<Num>::quiet_NaN();

/*
min c*x
s.t. A*x<=b
     x>=0
*/

Num simplex(const Mat &A,const Vec &b,const Vec &c){
    const int m=A.size(),n=A[0].size();

    Mat D(m+1,Vec(n+m+1));
    Vec id(m+n);
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++)D[i][j]=A[i][j];
        D[i][n+i]=1;
        D[i][n+m]=-b[i];
    }
    for(int i=0;i<n;i++)D[m][i]=c[i];

    for(int i=0;i<m;i++)id[i]=n+i;
    for(int i=0;i<n;i++)id[m+i]=i;

    while(true){
        int r=n;
        for(int i=n-1;i>=0;i--)if(D[m][id[m+i]]<0)r=i;
        if(r==n)return D[m][n+m];
        int s=m;
        for(int i=0;i<m;i++)if(D[i][id[m+r]]>0){
            if(s==m||-D[s][n+m]/D[s][id[m+r]]>-D[i][n+m]/D[i][id[m+r]])s=i;
        }
        if(s==m)return Inf;//NoBound
        Num k=D[s][id[m+r]];
        for(int i=0;i<=n+m;i++)D[s][i]/=k;
        for(int i=0;i<=m;i++){
            if(i==s)continue;
            k=D[i][id[m+r]];
            for(int j=0;j<=n+m;j++)D[i][j]-=k*D[s][j];
        }
        swap(id[s],id[m+r]);
    }
}

int N,M;
int U[1111],V[1111],C[1111];

int D[111][1111];

signed main(){
    cin>>N>>M;
    rep(i,M)cin>>U[i]>>V[i]>>C[i];
    Mat A;Vec b,c(M);

    rep(i,M){
        D[U[i]][i]++;
        D[V[i]][i]--;
    }

    for(int i=1;i+1<N;i++){
        Vec v(M);
        for(int j=0;j<M;j++)v[j]=D[i][j];
        A.pb(v);b.pb(0);
        rep(j,M)v[j]*=-1;
        A.pb(v);b.pb(0);
    }
    rep(i,M)c[i]=-D[0][i];
    rep(i,M){
        Vec v(M);
        v[i]=1;
        A.pb(v);b.pb(C[i]);
    }

    Num t=simplex(A,b,c);
    int ans=round(-t);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 33756