akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
import random
import time
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    start = time.time()
    d = I()
    c = LI()
    s = LIR(d)
    n = 26
    t = [(i%n)+1 for i in range(d)]
    v = score(t)
    nt = []
    for i in range(d):
        argmax = 0
        m = s[i][0]
        for j in range(1,n):
            sj = s[i][j]
            if m < sj:
                argmax = j
                m = sj
        nt.append(argmax+1)
    nv = score(nt)
    if v < nv:
        t = [i for i in nt]
        v = nv
    nt = []
    for i in range(d):
        argmax = 0
        m = s[i][0]-c[0]
        for j in range(1,n):
            sj = s[i][j]-c[j]
            if m < sj:
                argmax = j
                m = sj
        nt.append(argmax+1)
    nv = score(nt)
    if v < nv:
        t = [i for i in nt]
        v = nv
    i = 0
    T = 1000
    min_T = 20
    while time.time() < 1.5+start:
        nt = [i for i in t]
        r = random.random()
        if r > 0.5:
            if nt[i] < n:
                nt[i] += 1
        else:
            if nt[i] > 1:
                nt[i] -= 1
        nv = score(nt)
        if v <= nv:
            t = [i for i in nt]
            v = nv
        else:
            r = random.random()
            e = math.exp((nv-v)/T)
            if r < e:
                t = [i for i in nt]
                v = nv
        i += 1
        i %= d
        if T > min_T:
            T -= 1
    for i in t:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int N, K, X, Y;

int main() {
    cin >> N >> K >> X >> Y;

    if (N <= K) {
        cout << N * X << endl;
    } else {
        cout << K * X + (N - K) * Y << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
typedef long long LL;
const int MaxN = 1e5;
using namespace std;
int main(){
	int n;
	while(~scanf("%d",&n)){
		printf("ABC");
		printf("%d\n",n);
		}
	return 0;
	}

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

using namespace std;
#define sf scanf
#define pf printf
#define mem(a,b) memset(a,b,sizeof(a));
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define bug1 puts("bug1");
#define bug2 puts("bug2");
#define bug3 puts("bug3");
#define N 100
#define M 200
#define ULL unsigned long long
#define LL long long
const int INF=1e9;
const LL inf=0x3f3f3f3f;

const int maxn=2e5+10;
//2017年7月15日 21:09:44
LL a[maxn];
LL sum[maxn];
int main(){
    int n;
    sf("%d",&n);
    rep(i,1,n){
        sf("%lld",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    LL ans=100000*inf;
    rep(i,1,n-1){
        ans=min(ans,abs(sum[i]-(sum[n]-sum[i])));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
   
   long int n;
   cin>>n;

   for(long int i = 0; i < n; i++){
   	long int x;
   	cin>>x;

   	if(x % 2 == 0){
   		if(x % 3 == 0 || x % 5 == 0)
   			continue;
   		return cout<<"DENIED",0;
   	}
   }

   cout<<"APPROVED";
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n, l; cin >> n >> l;
    int a[n]; for (int i = 1; i <=n; i++) a[i-1] = i;
    int flavor[n], sum = 0;
    for (int i = 0; i < n; i++) 
    {
        flavor[i] = l + i;
        sum += flavor[i];
    }
    int mini = abs(sum-(sum-flavor[0])), temp= 0;
    for (int i = 1; i < n; i++)
    {
        if (mini > abs(sum-(sum-flavor[i])))
        {
            mini = abs(sum-(sum-flavor[i]));
            temp = i;
        }
    }
    cout << sum - flavor[temp] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	int k =0, n = s.size(),m = t.size();
	vector<int> v;
	for(int i = 0; i<n; i++)
	{
		// cout<<i<<endl;
		if(s[i]==t[k] || s[i]=='?')
			k++;
		else
		{
			if(k)
				i-=1;
			k = 0;
		}
		if(k==m)
		{
			v.push_back(i-m+1);
			k = 0;
			i -= m;
			i++;
		}
	}
	if(v.size()==0)
		cout<<"UNRESTORABLE"<<endl;
	else
	{
		set<string> st;
		for(auto l: v)
		{
			string t2="";
			for(int i = 0; i<n; i++)
			{
				if(i==l)
				{
					i += m-1;
					t2 +=t;
				}
				else if(s[i]=='?')
					t2.push_back('a');
				else
					t2.push_back(s[i]);
			}
			st.insert(t2);
		}
		cout<<*st.begin()<<endl;
	}
	return 0;
}


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

ll const INF = 1e+18;
ll dp[60][2][2][10];
ll k;

bool check(ll m){
	string s = to_string(m);
	int n = s.size();
	rep(i,n)rep(smaller,2)rep(zero,2)rep(x,10) dp[i][smaller][zero][x] = 0;
	rep(x,s[0]-'0'+1){
		if(x == 0) {
			dp[0][1][0][x] = 1;
		}else if(x == s[0] - '0'){
			dp[0][0][1][x] = 1;
		}else{
			dp[0][1][1][x] = 1;
		}
	}
	REP(i,n-1){
		rep(smaller,2){
			rep(zero,2){
				rep(x,10){
					rep(nx,10){
						int d = s[i] - '0';
						int nsmaller = smaller;
						if(smaller == 0){
							if(nx > d) continue;
							if(nx < d) nsmaller = 1;
						}
						int nzero = 1;
						if(zero == 0){
							if(nx == 0) nzero = 0;
							dp[i][nsmaller][nzero][nx] += dp[i-1][smaller][zero][x];
						}else{
							if(abs(nx-x) > 1) continue;
							dp[i][nsmaller][nzero][nx] += dp[i-1][smaller][zero][x];
						}
					}
				}
			}
		}
	}
	ll count = -1;
	rep(smaller,2)rep(zero,2)rep(x,10) count += dp[n-1][smaller][zero][x];
	
	if(count >= k){
		return true;
	}else{
		return false;
	}
}

int main(){
	cin >> k;
	ll r = INF;
	ll l = 0;
	while(r-l>1){
		ll m = (r+l)/2;
		if(check(m)){
			r = m;
		}else{
			l = m;
		}
	}
	cout << r << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	long long e,best;
	while(true){
	cin>>e;
	if(e==0)
		break;
	best=e;
	for(int i=0;i*i*i<=e;i++){
		for(int j=0;j*j<=e;j++){
			if(i*i*i+j*j<=e&&i+j+e-i*i*i-j*j<best)
				best=i+j+e-i*i*i-j*j;
		}
	}
	cout<<best<<endl;
	}
    return 0;
}

Measured memory_bytes: 1156
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#define min(x, y) (x < y ? x : y)
#define ll long long int 
#define Lff long double

int main()
{

 int N , K ;
 scanf("%d %d",&N,&K);
 
 printf("%d",N%K != 0);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int L[1000000];
    int idx1 = 500000;
    int idx2 = 499999;

    char line[15];
    fgets(line, 15, stdin);
    int q = atoi(line);

    int d, i;
    while (q--) {
        fgets(line, 15, stdin);
        if (line[0] == '0') L[--idx1] = atoi(line + 2);
        else if (line[0] == '1') {
            d = atoi(line + 2);
            if (d >= 0) {
                for (i = 0; i < d; i++) L[++idx2] = L[idx1++];
            }
            else {
                for (i = d; i < 0; i++) L[--idx1] = L[idx2--];
            }
        }
        else idx1++;
    }

    for (i = 500000; i <= idx2; i++) printf("%d\n", L[i]);
    for (i = idx1; i < 500000; i++) printf("%d\n", L[i]);

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
int main() {
    string str;
    cin >> str;

    ll count = 0;
    for (const auto& c : str) {
        count += (c == '1') ? 1 : 0;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3580
# -*- coding: utf-8 -*-
# init
n, y = map(int, input().split())
a, b, c = -1, -1, -1

try:
  for i in list(reversed(range(n + 1))):
    for j in list(reversed(range(n - i + 1))):
      k = n - (i + j) if i + j < n else 0
      if (((i * 10000) + (j * 5000) + (k * 1000)) == y):
        a, b, c = i, j, k
        exit
finally:
  print(a, b, c)


Measured memory_bytes: 3060
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

typedef long long int tint;

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

	tint n, m; cin >> n >> m;
	
	if (n == 1 && m == 1) {cout << 1 << endl; return 0;}
	if (n == 1) {cout << m - 2 << endl; return 0;}
	if (m == 1) {cout << n - 2 << endl; return 0;}
	cout << (m - 2) * (n - 2) << endl;
	
}


Measured memory_bytes: 256
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

struct SegmentTree{
    int ide = 0;

    inline void updatef(int &x, int y){
        x += y;
    }

    inline int queryf(int x, int y){
        return x + y;
    }

    int n;
    vector<int> node;

    SegmentTree(int sz){
        n = 1;
        while(n < sz) n <<= 1;
        node.resize(2 * n - 1, ide);
        // for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        // for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void update(int k, int x){
        k += n - 1;
        updatef(node[k], x);
        while(k){
            k = (k - 1) / 2;
            node[k] = queryf(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    int get(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = n;
        if(r <= a || b <= l) return ide;
        if(a <= l && r <= b) return node[k];
        int xl = get(a, b, 2 * k + 1, l, (l + r) / 2);
        int xr = get(a, b, 2 * k + 2, (l + r) / 2, r);
        return queryf(xl, xr);
    }
};

int main(){
    // CFS;
    int n, k;
    cin >> n >> k;
    vl a(n);
    rep(i, n){
        cin >> a[i];
        a[i] -= k;
    }
    vl rui(n + 1);
    rui[0] = 0;
    map<ll, int> mp;
    mp[0] = 0;
    rep(i, n){
        rui[i + 1] = rui[i] + a[i];
        mp[rui[i + 1]] = 0;
    }
    int now = 0;
    for(auto &p:mp) p.second = now++;
    SegmentTree seg(now);
    ll ans = 0;
    rep(i, n + 1){
        ans += seg.get(0, mp[rui[i]]+1);
        seg.update(mp[rui[i]], 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11820
def main():
    from sys import stdin
    input=stdin.readline
    
    n, q = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]
    px = [list(map(int, input().split())) for _ in [0]*q]
    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]
    root = 0  # 根
    d = [-1]*n  # 根からの距離
    d[root] = 0
    q = [root]
    cnt = 0
    while q:  # BFS
        cnt += 1
        qq = []
        while q:
            i = q.pop()
            for j in g[i]:
                if d[j] == -1:
                    d[j] = cnt
                    qq.append(j)
        q = qq
    d2 = list(sorted(enumerate(d), key=lambda x: x[1]))

    ans = [0]*n
    for p, x in px:
        ans[p-1] += x
    for i, j in d2:
        for k in g[i]:
            if d[k] == j+1:
                ans[k] += ans[i]
    print(*ans)


main()


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

int main() {
	int a = -1, b;
	for (int i = 0;; i++) {
		char c = getchar_unlocked();
		if (c == '\n')break;
		if (c == 'A'&&a == -1)a = i;
		if (c == 'Z')b = i;
	}
	cout << b - a + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair<int,int>
#define mp make_pair
using namespace std;
int main()
{
string s,t;
cin>>s>>t;
int ans = 0;
for(int i=0;i<3;i++)
{
    if(s[i]==t[i])
        ans++;
    
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.00001;

int main() {
    vector<pair<int,int>> r;
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 0; i < m;i++) {
        int a,b;
        scanf("%d %d",&a,&b);
        r.push_back(make_pair(a,b));
    }
    sort(r.begin(),r.end());
    int c = 1;
    int s = r[0].second;
    for(auto i = r.begin();i != r.end();i++){
        if(i->first >= s) {
            c++;
            s = i->second;
        }
        else s = min(s,i->second);
    }
    cout << c << endl;
}

Measured memory_bytes: 1400
X = int(input())

def check(mid):
    if (mid)*(mid-1)//2 >=X:
        return False
    else:
        return True

left = 0
right = 10**18
while (right-left) > 1:
    mid = (right+left)//2
    if check(mid):
        left = mid
    else:
        right = mid
if check(left):
    print(left)
else:
    print(right)

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

int main()
{
    int t;

    cin >> t;

    int hour, min, sec;

    hour = t / 3600;
    min = t % 3600 / 60;
    sec = t % 60;

    cout << hour << ':' << min << ':' << sec << endl;

    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  vector<vector<int>> dp(110,vector<int>(110,INF));
  int h,w;cin>>h>>w;
  vector<string> a(h);rep(i,h)cin>>a[i];
  dp[0][0] = a[0][0] == '#';
  rep(i,h){
    rep(j,w){
      if(i>0)chmin(dp[i][j],dp[i-1][j]+(a[i][j]=='#'&&a[i-1][j]=='.'));
      if(j>0)chmin(dp[i][j],dp[i][j-1]+(a[i][j]=='#'&&a[i][j-1]=='.'));
    }
  }
  
  cout<<dp[h-1][w-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

#define INF (1 << 30)
#define MAXN (1 << 20)

int a[MAXN];
int n, k;

int get(int x, int t) {
	return (x - 1) / t;
}

bool cuts(int t) {
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		ret += get(a[i], t);
	}
	return ret <= k;
}

int main() {
	cout << fixed << setprecision(12);	
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (cuts(1)) {
		cout << 1 << endl;
		return 0;
	}
	int l = 1;
	int r = INF;
	while (r - l > 1) {
		int m = (r + l) / 2;
		if (cuts(m)) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << r << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 4316
n = int(input())
*h, = map(int, input().split())
mx = max(h)
a = [[0]*mx for _ in [0]*n]
for i in range(n):
    for j in range(h[i]):
        a[i][j] = 1
ans = 0
for j in range(mx):
    f = 0
    for i in range(n):
        if not f and a[i][j]:
            f = 1
            ans += 1
        elif f and not a[i][j]:
            f = 0
print(ans)

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

string s;

bool is_mm(char c1, char c2) {
  bool b2 = c2 == '0' || c2 == '1' || c2 == '2';
  bool b3 = '1' <= c2 && c2 <= '9';
  return (c1 == '0' && b3) || (c1 == '1' && b2);
}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> s;

  bool is_yymm = is_mm(s[2],s[3]);
  bool is_mmyy = is_mm(s[0],s[1]);

  if (is_yymm && is_mmyy)
    cout << "AMBIGUOUS\n";
  else if (is_yymm)
    cout << "YYMM\n";
  else if (is_mmyy)
    cout << "MMYY\n";
  else
    cout << "NA\n";

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
ans = 0
n.times do |i|
    c = (a[i] < b[i] ? a[i] : b[i])
    ans += c
    a[i] -= c
    b[i] -= c
    c = (a[i+1] < b[i] ? a[i+1] : b[i])
    ans += c
    a[i+1] -= c
end
puts ans

Measured memory_bytes: 15380
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

const int N = 62;
const int L = 220;

int xb[N];
int len = 0;

bool bit(int m, int i) {
	return (m >> i) & 1LL;
}

void clear() {
	fill_n(xb, N, 0);
	len = 0;
}

int check(int num) {
	for (int i = 0; i < N; ++i) {
		if (bit(num, i)) {
			num ^= xb[i];
		}
	}
	return num;
}

void add(int num) {
	num = check(num);
	if (!num) {
		return;
	}
	int ind = __builtin_ctzll(num);
	assert(0 <= ind && ind < N && bit(num, ind) && !xb[ind]);
	xb[ind] = num;
	for (int i = 0; i < N; ++i) {
		if (i != ind && bit(xb[i], ind)) {
			xb[i] ^= xb[ind];
		}
	}
}

int n;
int a[L];
string s;

void solve() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	cin >> s;
	clear();
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == '0') {
			add(a[i]);
		} else if (check(a[i])) {
			cout << "1\n";
			return;
		}
	}
	cout << "0\n";
}

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);
	int tn;
	cin >> tn;
	while (tn--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

template<class T> struct Compression : public vector<T> {
  Compression(const vector<T>&a) :vector<T>(a) {
    sort(all(*this));
    this->erase(unique(all(*this)), this->end());
  }
  int index(T num) {
    return lower_bound(all(*this), num) - this->begin();
  }
};
template<class T, class O = int> struct CumulativeSum {
  Compression<T> x, y;
  vector<vector<O>> s;
  CumulativeSum(const vector<T>& xa, const vector<T>& ya) :x(xa), y(ya) {
    s.resize(y.size() + 1);
    for (auto& i : s) i.resize(x.size() + 1);
    rep(i, xa.size()) {
      int xs = x.index(xa[i]);
      int ys = y.index(ya[i]);
      s[ys + 1][xs + 1]++;
    }
    rep(i, y.size())rep(j, x.size()) {
      s[i + 1][j + 1] += s[i][j + 1] + s[i + 1][j] - s[i][j];
    }
  }
  O sum(T lx, T ly, T rx, T ry) {
    lx = x.index(lx);
    rx = x.index(rx + 1);
    ly = y.index(ly);
    ry = y.index(ry + 1);
    return s[ry][rx] - s[ly][rx] - s[ry][lx] + s[ly][lx];
  }
};



void Calc() {

  var(int, a, b, c);
  if (a == b) {
    cout << (c) << endl;
  }
  else if (a == c) {
    cout << (b) << endl;
  }
  else {
    cout << (a) << endl;


  }


}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll>A(N);
    ll nm=0;
    ll pm=0;
    ll pinx;
    ll ninx;
    rep(i,N){
        cin>>A[i];
        if(A[i]>pm){
            pm=A[i];
            pinx=i;
        }
        if(A[i]<nm){
            nm=A[i];
            ninx=i;
        }

    }
    vector<Pi>ans;
    if(pm>-nm){
        
        rep(i,N){
            if(A[i]<0){
                A[i]+=pm;
                ans.pb(mp(pinx,i));
            }
        }
        //A[0]+=pm;
        if(pinx!=0)
            ans.pb(mp(pinx,0));
        rep(i,N-1){
            ans.pb(mp(i,i+1));
        }
    }else{
        rep(i,N){
            if(A[i]>0){
                A[i]+=nm;
                ans.pb(mp(ninx,i));
            }
        }
        if(ninx!=N-1)
            ans.pb(mp(ninx,N-1));
        rep(i,N-1){
            ans.pb(mp(N-i-1,N-i-2));
        }
    }
    ll M=ans.size();
    cout<<M<<endl;
    rep(i,M){
        cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
    }



    return 0;
    

}

Measured memory_bytes: 3648
#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>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (auto &e: s) cin >> e;

    int ans = 0;
    for (int d = 0; d < n; ++d) {
        bool f = true;
        for (int i = 1; i < n; ++i) {
            for (int j = 0; j < i; ++j) {
                if (s[i][(j+d)%n] != s[j][(i+d)%n]) f = false;
            }
        }
        if (f) ans += n;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int main () {
  int n;
  cin >> n;
  vi p(n);
  rep(i,n) cin >> p[i];
  
  int ans = 0;
  int mi = p[0];
  rep(i,n) {
    if (p[i] <= mi) ans++;
    if (mi > p[i]) mi = p[i]; 
  }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> sum(200, 1);
    for (int i = 0; i < S.size(); i++) sum[S[i]]++;
    int ans = 1;
    for (char i = 'a'; i <= 'z'; i++) {
        ans *= sum[i];
        ans %= MOD;
    }
    cout << (ans + MOD - 1) % MOD << endl;    
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if(A+B > C+D){
    cout << "Left";
  }else{
    if(A+B < C+D){
      cout << "Right";
    }else{
      cout << "Balanced";
    }
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true) {
			int h = scan.nextInt();
			int w = scan.nextInt();
			if(h == 0 && w == 0) {
				break;
			}

			for(int i = 0; i < h; i++) {
				for(int j = 0; j < w; j++) {
					System.out.printf("#");
				}
				System.out.println("");
			}
			System.out.println("");
		}

		scan.close();
	}
}


Measured memory_bytes: 57140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

	int H, N; cin >> H >> N;
	vector<int> A(N);
	rep(i, N) cin >> A[i];

	if (accumulate(all(A), 0ll) >= H) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 640
n,m,k=map(int,input().split())
#n*mからk個選ぶ
#x方向
mod=10**9+7
kaidan=[1]*(n*m+1)
gyaku=[1]*(n*m+1)
for i in range(1,n*m+1):
    kaidan[i]=i*kaidan[i-1]%mod
    gyaku[i]=pow(kaidan[i],mod-2,mod)
def comb(n,r):
    if n-r>0 and n>0 and r>0:
        return (kaidan[n]*gyaku[n-r]*gyaku[r])%mod
    elif n==0 or r==0 or n==r:
        return 1
    else:
        0
ans=0
for d in range(1,n):
    ans+=d*(n-d)*m*m*comb(n*m-2,k-2)
for d in range(1,m):
    ans+=d*(m-d)*n*n*comb(n*m-2,k-2)
print(ans%mod)

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

int main()
{
  int h,w;  
  for( ; ; ){
    cin >> h >> w;
    if(h==0 || w==0) break;    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cout << "#";
      }
      cout << endl;  
    } 
    cout << endl;   
  }  
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cctype>
#include <bits/stdc++.h>

using namespace std; // consider removing this line in serious projects

int main() {
	string str;
	getline(cin,str);
	for	(int i =0; i < str.size();i++){
		if(str[i]>= 'a' && str[i] <= 'z'){
			str[i]=toupper(str[i]);
		} else if(str[i] >= 'A' && str[i] <= 'Z'){
			str[i]=tolower(str[i]);
		}
	}

	cout << str << endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int inf=(1<<20);


int main(void){
    int n,u,q,c;
int m[100][100];
int d[100];
int w[100];

    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            m[i][j]=inf;
        }
        d[i]=inf;
        cin>>q>>c;
        for(int j=0;j<c;j++){
            int k,l;
            cin>>k>>l;
            m[q][k]=l;
        }
    }
    
    d[0]=0;
    while(1){
        u=-1;
        int min=inf+1;
        for(int i=0;i<n;i++){
            if(min>d[i]&&d[i]!=-1){
                min=d[i];
                u=i;
            }
        }
        if(u==-1)break;
        w[u]=d[u];
        for(int i=0;i<n;i++){
            if(d[i]!=-1&&d[i]>m[u][i]+d[u]){
                d[i]=m[u][i]+d[u];
            }
        }

        d[u]=-1;
    }
  for(int i=0;i<n;i++){
      cout<<i<<" "<<w[i]<<endl;
  }
    return 0;
}



Measured memory_bytes: 3124
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());
	let n: usize = iter.read();
	let k: u64 = iter.read();

	let tree = {
		let mut tree: Vec<Vec<usize>> = vec![vec![]; n];
		for _ in 1..n {
			let a: usize = iter.read();
			let b: usize = iter.read();
			let a: usize = a - 1;
			let b: usize = b - 1;
			tree[a].push(b);
			tree[b].push(a);
		}
		tree
	};

	let mut x_list: Vec<Option<u64>> = vec![None; n];
	x_list[0] = Some(k);
	run(&mut x_list, &tree, 0, k, k);

	let mut r = 1;
	for x in x_list {
		if let Some(x) = x {
			r = (r * x) % 1000000007;
		}
	}
	println!("{}", r);

	fn run(x_list: &mut Vec<Option<u64>>, tree: &Vec<Vec<usize>>, node: usize, prev: u64, k: u64) {
		let mut prev = if k - 1 > prev { k - 1 } else { prev };
		for &t in tree[node].iter() {
			let f = match x_list[t] {
				Some(_) => false,
				None => true,
			};
			if f {
				prev = if 0 == prev { 0 } else { prev - 1 };
				x_list[t] = Some(prev);
				run(x_list, tree, t, prev, k);
			}
		}
	}
}


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

int main()
{
    long long int n;
    cin >> n;
    long long int k = n;
    long long int ans = 0;
    for (int i = 2; i <= 1000010; i++)
    {
        int curr = 0;
        while (n % i == 0)
        {
            curr++;
            n /= i;
        }
        for (int j = 1; j < 10000; j++)
        {
            if (curr < j)
                break;
            ans++;
            curr -= j;
        }
    }
    if (n > 1)
        ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
Count = 0
Array = []
for i in range(int(input())):
    Dice_1, Dice_2 = map(int, input().split())
    if Dice_1 == Dice_2:
        Array.append(1)
    else:
        Array.append(0)

ans = []
j_1 = 0
for j in range(len(Array)):
    if j_1 == 1 and Array[j] == 1:
        Count = Count + 1
    else:
        Count = 0
    j_1 = Array[j]
    ans.append(Count)
if max(ans) >= 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62488
S = [int(i) for i in input()]
s0 = [x for i,x in enumerate(S) if i % 2 == 0]
s1 = [x for i,x in enumerate(S) if i % 2 == 1]
# 0_1, 0_0, 1_1, 1_0
num01 = sum(s0)
num11 = sum(s1)
print(min(num01+len(s1)-num11, num11+len(s0)-num01))

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

int main() {
  int N,i,j,max,tmp,sum=0;
  
  cin >> N;
  
  int a[N];
  
  for(i=0;i<N;i++) cin >> a[i];
  
  for(i=0;i<N;i++) {
    //max = a[i];
    for(j=i+1;j<N;j++) {
      if(a[i] < a[j]) {
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  
  if(N%2 == 0) {
    for(i=0;i<N-1;i+=2) {
      sum += (a[i]-a[i+1]);
    }
  } else {
    for(i=0;i<N-2;i+=2) {
      sum += (a[i]-a[i+1]);
    }
    sum += a[N-1];
  }
  
  cout << sum << endl;;
  
  return 0;
}

Measured memory_bytes: 3556
def main():
    N = int(input())

    ans = (N + 1) // 2
    ans /= N
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 2940
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    rgb = [None for _ in range(n)]
    rgb_acc = [None for _ in range(n)]
    rgb_st = {"R","G","B"}
    rgb_lst = ["R","G","B"]
    for i, char in enumerate(s):
        if char == "R":
            rgb[i] = [1,0,0]
        elif char == "G":
            rgb[i] = [0,1,0]
        else:
            rgb[i] = [0,0,1]
    
    rgb_acc[0] = rgb[0]
    for i in range(1, n):
        rgb_acc[i] = rgb_acc[i-1][:]
        rgb_acc[i][rgb[i].index(1)] += 1
    
    ans = 0
    for i in range(n-2):
        for j in range(i+1,n-1):
           if s[i]!=s[j]:
                ex = rgb_st - {s[i], s[j]}
                ex = ex.pop()
                index = rgb_lst.index(ex)
                cnt = rgb_acc[n-1][index]-rgb_acc[j][index]
                if j+1 <= 2*j-i < n:
                    if s[2*j-i] == ex:
                        cnt -= 1
                ans += cnt

    print(ans)
main()

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

void assign_if(int& a0, const int& a1) {
    if (a1 < a0) a0 = a1;
}

struct Chemicals {
    Chemicals& operator+=(const Chemicals& o) {
        a += o.a; b += o.b; c += o.c;
        return *this;
    }
    bool operator<(const Chemicals& o) const {
        return a != o.a ? a < o.a : b != o.b ? b < o.b : c < o.c;
    }
    int a, b, c;
};

Chemicals p[40];
Chemicals q[2][1 << 20];

int n, ma, mb;
int k[2], l;

void enumerate(int i, int i1, Chemicals o) {
    if (i < i1) {
        enumerate(i + 1, i1, o);
        o += p[i];
        enumerate(i + 1, i1, o);
    } else {
        int t = min(o.a / ma, o.b / mb);
        q[l][k[l]++] = { o.a - t * ma, o.b - t * mb, o.c };
    }
}

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

    for (int i = 0; i < n; i++) {
        cin >> p[i].a >> p[i].b >> p[i].c;
    }

    int m[3] = { 0, n / 2, n };
    for (int i = 0; i < 2; i++) {
        k[l = i] = 0;
        enumerate(m[i], m[i + 1], { 0, 0, 0 });
    }

    auto end = q[1] + k[1];
    sort(q[1], end);
    end = unique(q[1] + 1, end, [&](const Chemicals& o0, const Chemicals& o1) {
        return o0.a == o1.a && o0.b == o1.b;
    });

    int r = 4001;
    for (int i = 0; i < k[0]; i++) {
        auto o = q[0][i];
        int t = max((o.a + ma - 1) / ma, (o.b + mb - 1) / mb);
        o = { t * ma - o.a, t * mb - o.b, 0 };
        auto it = lower_bound(q[1] + (i == 0), end, o);
        if (it == end) continue;
        if (it->a != o.a || it->b != o.b) continue;
        assign_if(r, q[0][i].c + it->c);
    }

    cout << (r < 4001 ? r : -1) << endl;

    return 0;
}

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

int main(){

	int H, W, x;
  	cin >> H >> W;
  	vector<vector<char>> vec(H + 1 , vector<char>(W + 1));
  	
  	for(int i = 0; i < H; i++){
    	for (int j = 0; j < W; j++){
        	cin >> vec.at(i).at(j);
          
          
        }
    }
  
 	for(int i = 0; i < W + 2; i++){
    	cout << '#';
    }
 	 cout << endl;
  	
  	for(int i = 0; i < H ; i++){
      cout<< '#';
      for(int j = 0; j < W; j++){
    	cout << vec.at(i).at(j);
      }
      cout << '#' << endl;
    }
  	
 	for(int i = 0; i < W + 2 ; i++){
    	cout << '#';
    }
 	 cout << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,dis[200001],l,r,d;
bool Error,f[200001];
struct edge {
	int to,cost;
	edge(int a=0,int b=0) {
		to=a;
		cost=b;
	}
};
vector<edge> path[200001];
void spfa(int x) {
	for(int i=0; i<path[x].size(); i++) {
		edge e=path[x][i];
		if(f[e.to])
			if(e.cost+dis[x]!=dis[e.to]) {
				Error=true;
				return;
			} else continue;
		f[e.to]=true;
		dis[e.to]=dis[x]+e.cost;
		spfa(e.to);
		if(Error) return;
	}
}
int main() {
	cin>>n>>m;
	for(int i=0; i<m; i++) {
		scanf("%d%d%d",&l,&r,&d);
		path[l].push_back(edge(r,d));
		path[r].push_back(edge(l,-d));
	}
	for(int i=0; i<n; i++) {
		if(!f[i]) {
			spfa(i);
			if(Error) break;
		}
	}
	if(!Error) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 13440
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

class Point{
public:
  int t,n,m,g;
  bool f;
  Point(int t = 0,int n = 0,int m = 0,int g = 0):t(t),n(n),m(m),g(g){}
  bool operator < (const Point &p)const {
    return t < p.t;
  }
};

int main(){
  int i,j,k,n,m,r,q,c;
  Point p[1000];
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    cin >> r;
    c = 0;
    int x1,x2,x3,x4;
    for(i=0;i<r;i++){
      cin >> x1 >> x2 >> x3 >> x4;
      if(x4 == 1){
	p[c].t = x1;
	p[c].n = x2;
	p[c].m = x3;
	p[c].f = false;
	c++;
      }
      else{
	for(j=c-1;j>=0;j--){
	  if(x2 == p[j].n && x3 == p[j].m && !p[j].f){
	    p[j].f = true;
	    p[j].g = x1;
	    break;
	  }
	}
      }
    }

    sort(p,p+c);

    cin >> q;
    int y1,y2,y3,ans,totyu;
    for(i=0;i<q;i++){
      cin >> y1 >> y2 >> y3;
      ans = 0;
      totyu = y1;
      for(j=0;j<c;j++){
	if(p[j].m == y3 && p[j].g > totyu && p[j].g <= y2){
	  if(p[j].t > totyu) ans += p[j].g - p[j].t;
	  else ans += p[j].g - totyu;
	  totyu = p[j].g;
	}
	else if(p[j].m == y3 && y2 > totyu && p[j].g > y2 && y2 > p[j].t){
	  if(p[j].t > totyu) ans += y2 - p[j].t;
	  else ans += y2 - totyu;
	  totyu = y2;
	}
      }
      cout << ans << endl;
    }


  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    int n;
    cin >> n;
    rep(i,10){
        rep(j,10){
            if(i*j==n){
                cout << "Yes" <<endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;
using u64 = std::uint_fast64_t;

void solve(void){

  llint n, k;
  std::cin >> n >> k;
  std::vector<llint> p(n), c(n);
  for(int i=0; i<n; i++){
    std::cin >> p[i];
    p[i]--;
  }
  for(int i=0; i<n; i++){
    std::cin >> c[i];
  }

  std::vector<std::vector<llint> > loops;

  std::vector<bool> checked(n, false);
  for(int i=0; i<n; i++){
    if(checked[i]) continue;

    std::vector<llint> loop;
    llint now = i;
    while(true){
      now = p[now];
      if(checked[now]) break;
      checked[now] = true;
      loop.push_back(now);
      //std::cout << now << " ";
    }
    loops.push_back(loop);
    //std::cout << std::endl;
  }

  std::vector<llint> score(n);
  std::vector<llint> best_score(n, -10000000000LL);
  for(int i=0; i<loops.size(); i++){
    const auto& loop = loops[i];
    llint loop_score = 0;
    for(const auto& elem: loop){
      //std::cout << elem << ":" << c[elem] << " ";
      loop_score += c[elem];
    }
    //std::cout << std::endl;
    //std::cout << loop_score << std::endl;

    for(int j=0; j<loop.size(); j++){
      const auto& elem = loop[j];
      if(loop_score >=0){
	//llint loop_cnt = std::max(0, (k/loop.size()) - 1);
	llint loop_cnt = (k/loop.size()) - 1;
	
	score[elem] += loop_cnt * loop_score;
	best_score[elem] = std::max(best_score[elem], score[elem]);
	llint nokori = k - loop_cnt*loop.size();
	for(int l=0; l<nokori; l++){
	  llint idx = loop[(j+l+1)%loop.size()];
	  score[elem] += c[idx];
	  best_score[elem] = std::max(best_score[elem], score[elem]);
	}
      }else{
	for(int l=0; l<std::min((llint) loop.size(), k); l++){
	  llint idx = loop[(j+l+1)%loop.size()];
	  score[elem] += c[idx];
	  best_score[elem] = std::max(best_score[elem], score[elem]);
	}
      }
    }

  }
  std::sort(best_score.begin(), best_score.end());
  std::cout << best_score[best_score.size()-1] << std::endl;
  return;
}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 3828
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = [0] * N
for i in range(N): res[0] += a[i] * (pow(-1, i % 2))
for i in range(N - 1):
  a[i] -= res[i] // 2
  res[(i + 1) % N] = a[i % N] * 2
print(*res)

Measured memory_bytes: 60644