akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define N 40010
#define int long long
#define INF 0x3f3f3f3f
#define mod 1000000007
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
inline int read()
{
	register char cc = getchar();register int cn(0), flus(1);
	while(cc > '9' || cc < '0') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus; 
}
signed main()
{
	int n = read(), m = read();
	if(n == m) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main() {
    ll x;
    cin >> x;
    ll p = 100;
    for (ll i = 0; ; ++i) {
        if (p >= x) {
            cout << i << endl;
            break;
        }
        p *= 1.01;
    }
}


Measured memory_bytes: 3648
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll mod=1e9+7;
int main()
{
IOS
ll n;
cin>>n;
map<string,ll> mp;
for(ll i=0;i<n;i++)
{
    string s;
    cin>>s;
    mp[s]++;
}
cout<<"AC x "<<mp["AC"];nl
cout<<"WA x "<<mp["WA"];nl
cout<<"TLE x "<<mp["TLE"];nl
cout<<"RE x "<<mp["RE"];nl
return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll A, B;
  scanf("%lld %lld", &A, &B);

  ll val;

  ll start_even = (A % 2 == 0) ? A : A + 1;
  ll end_odd = (B % 2 == 1) ? B : B - 1;

  ll pair_count = (end_odd - start_even + 1) / 2;

  ll v = (pair_count % 2 == 1) ? 1 : 0;

  if (A % 2 == 1) {
    v ^= A;
  }
  if (B % 2 == 0) {
    v ^= B;
  }
  cout << v << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-03-22 21:55:41 +0900
# LastModified: 2020-03-22 22:18:26 +0900
#


import os
import sys
from collections import Counter as ct

def main():
    N = int(input())
    A = list(map(int,input().split()))
#    print(A)
    c = ct(A)
#    print(c)
    d = {}
    total = 0
    for key in c:
        d[key] = c[key]*(c[key]-1)//2
        total += d[key]
#    print(d)
#    print(total)
    for a in A:
        print(total-c[a]+1)

        

if __name__ == "__main__":
    main()


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

int a[100002];
int suff[100002];
int main() {
	int i;
	int n;
	cin>>n;
	for(i=1;i<=n;i++) cin>>a[i];
	suff[n] = a[n];
	for(i=n-1;i>=1;i--)
		suff[i] = min(suff[i+1], a[i]);

	bool ok = true;
	for(i=1;i<=n;i++)
		if(a[i] - suff[i] >=2) ok = false;
	if(ok) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 1024
# 組み合わせの総数 p=10**9+7 で割ったあまりを求める Satoooh Blog 2020/02/27 4分 
"""n<10**7 , p は素数"""
def cmb(n, r, p):

    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p



# 初期入力
import sys
input = sys.stdin.readline
N,K = (int(x) for x in input().split())

NN = 10 ** 4  # NN は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
p =10**9 +7
for i in range(2, NN + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#青の場合の数
c_blue =[0]*(K+1)
b_blue =K
c_red =[0]*(K+1)
b_red = N -K
for i in range(1,K+1):
    gap_blue = i -1             #青の隙間＝赤を必ず置くべき場所
    c_blue[i] =cmb(b_blue -1 ,gap_blue ,p)
    b_red_free = b_red - gap_blue           #隙間に赤を置く⇒自由における赤が減る 
    #if b_red_free <0:
     #   continue
    c_red[i]  = cmb(gap_blue +2 +b_red_free -1 ,b_red_free ,p) 
    print(c_blue[i] *c_red[i] %p )

Measured memory_bytes: 4712
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define PI 3.141592654
//#define rz(x) resize(x)
//#define rz(x,y) resize(x,y)



void mymain(){
   int n,k;
   cin >> n >> k;
   vi arr(n);
   for(int i=0;i<n;i++){
    cin >> arr[i];
   }
   double ans=0,till=0;
   for(int i=0;i<k;i++){
        ans += (arr[i]+1)/(2.0);
   }
   till = ans;
   for(int i=k;i<n;i++){
        till -= (arr[i-k]+1)/(2.0);
        till += (arr[i]+1)/(2.0);
        ans = max(ans,till);
   }

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

}

signed main(){
//IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
//cin>>t;
for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}
/*

*/


Measured memory_bytes: 1792
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String li[]=line.split("",0);
        boolean b[]=new boolean[26];
        String s="qwertyuiopasdfghjklzxcvbnm";
        String ss[]=s.split("",0);
        for(int i=0;i<li.length;i++){
            for(int j=0;j<26;j++){
                if(ss[j].equals(li[i])){
                    b[j]=!b[j];
                    break;
                }
            }
        }
        boolean f=true;
        for(int i=0;i<26;i++){
            if(b[i]){
                f=false;
                break;
            }
        }
        if(f)System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int D;
    cin>>D;
    vector<int> c(26);
    rep(i,26){
        int tmp=0;
        cin>>tmp;
        c[i]=tmp;
    }
    vector<vector<int>> s(D,vector<int>(26));
    vector<int> last(26,0);//最後にiのテストをやってからの経過日数とする
    rep(i,D){
        rep(j,26){
            int stmp=0;
            cin>>stmp;
            s[i][j]=stmp;
        }
    }

    vector<int> ans(D);
    rep(i,D){
        int tmp;
        cin>>tmp;
        ans[i]=tmp;
    }
    
    int M;
    cin>>M;
    vector<int> d,q;
    rep(i,M){
        int tmpd,tmpq;
        cin>>tmpd>>tmpq;
        d.push_back(tmpd);
        q.push_back(tmpq);
    }
    //i日目の満足度を計算する
    int manzokudo=0;//sは0indexにつき
    rep(i,D){
        //i日目にやるやつはans[i]
        manzokudo+=s[i][ans[i]-1];//sは0indexにつき

        rep(j,26){
            //テストans[i]-1以外はやってないので満足度下がる
            if(j!=ans[i]-1)
            manzokudo+=c[j]*(last[j]+1)*-1;//やってないとしたので1ひいとく
        }
        //i日目にans[i]-1番のテストをやることに決めたとみせかけて
        //iがdのどれか(d[k]としよう)と一致していた場合はans[i]-1番の代わりにq[k]番のテストをやることになるので
        //ans[i]-1番以外のlastを1増やす,ans[i]-1番は0に戻るとみせかけて
        //その場合に限りq[k]-1番以外のlastを1増やす,q[k]-1番は0に戻る

        rep(j,26){
            if(j!=ans[i]-1){
                last[j]++;
            }else{
                last[j]=0;
            }
        }
    //    cout << manzokudo << endl;
    }

    //i番目の日程変更を行った時のviを計算する
    rep(i,M){
        manzokudo=0;//満足度を初期化
        ans[d[i]-1]=q[i];
        //d[i]日目のテストをq[i]にすり替えて再計算
        rep(m,26){
            last[m]=0;//lastも初期化
        }
        rep(l,D){
        //l日目にやるやつはans[l]
        manzokudo+=s[l][ans[l]-1];//sは0indexにつき
        
        rep(j,26){
            //テストans[l]-1以外はやってないので満足度下がる
            if(j!=ans[l]-1)
            manzokudo+=c[j]*(last[j]+1)*-1;//やってないとしたので1たしとく
        }
        //i日目にans[i]-1番のテストをやることに決めたとみせかけて
        //iがdのどれか(d[k]としよう)と一致していた場合はans[i]-1番の代わりにq[k]番のテストをやることになるので
        //ans[i]-1番以外のlastを1増やす,ans[i]-1番は0に戻るとみせかけて
        //その場合に限りq[k]-1番以外のlastを1増やす,q[k]-1番は0に戻る

        rep(j,26){
            if(j!=ans[l]-1){
                last[j]++;
            }else{
                last[j]=0;
            }
        }
        
    }

cout << manzokudo << endl;
    }

    return 0;
}

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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

void solve()
{
	int a, b;
	cin >> a >> b;
	cout << a * b;
}

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

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

	return 0;
}


Measured memory_bytes: 3612
#include <set>
#include <cstdio>

#define MAXN 100000

int main(){
    int n;
    int q;
    int nodes[MAXN];
    std::set<long long int> nset;
    std::scanf("%d", &n);
    std::scanf("%d", &q);
    for(int i = 0; i < q; ++i){
        int op;
        std::scanf("%d", &op);
        if(op == 0){
            int id;
            int val;
            std::scanf("%d", &id);
            std::scanf("%d", &val);
            long long int key = nodes[id];
            key = (key << 32) | id;
            auto it = nset.find(key);
            if(it != nset.end()) nset.erase(it);
            nodes[id] = val;
            key = val;
            key = (key << 32) | id;
            nset.insert(key);
        } else {
            int from;
            int to;
            std::scanf("%d", &from);
            std::scanf("%d", &to);
            bool isFind = false;
            for(auto &x : nset){
                int id = 0xFFFFFFFF & x;
                if(id >= from && id <= to){
                    int val = x >> 32;
                    std::printf("%d\n", val);
                    isFind = true;
                    break;
                }
            }
            if(isFind != true){
                std::printf("2147483647\n");
            }
        }
    }
    return 0;
}



Measured memory_bytes: 5200
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B = imn()

diff = B-A
if diff % 2 == 0:
    print(diff//2)
else:
    to_edge = min(A-1,N-B)
    print(to_edge+1+(diff)//2)

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

int main(){
  int A,B;
  cin>>A>>B;
  if(A!=1 &&B!=1){
    cout<<1<<endl;
  }
  else if(A!=2 &&B!=2){
    cout<<2<<endl;
  }
  else if(A!=3 &&B!=3){
    cout<<3<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String curr = "A";
      
      while(sc.hasNext()) {
         String[] input = sc.nextLine().split(",");
         String p1 = input[0];
         String p2 = input[1];
         
         if(p1.equals(curr)) {
            curr = new String(p2);
         } else if (p2.equals(curr)) {
            curr = new String(p1);
         }
         
      }
      
      System.out.println(curr);
   }
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

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

    int K = 6;

    int A, B;
    cin >> A >> B;

    cout << K - A - B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  double x=h*30+m*0.5,y=6*m;
  double kakudo=min(360-abs(x-y),abs(x-y));
  double pi=3.1415926535897932384626433832795028841971;
  double unit=(pi*kakudo)/180.0;
  double c=cos(unit);
  cout<<fixed<<setprecision(10)<<sqrt((a*a)+(b*b)-2.0*(a*b*c))<<endl;
  return 0;
}

Measured memory_bytes: 4168
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    // dp[heads][tails] but tails is n - heads so => dp[heads]
    vector<double> dp(n+1);
    // dp[i] - probability that there are i heads so far

    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin)
    {
        double p_heads;
        cin >> p_heads;
        for(int i = coin + 1; i>= 0; --i)
        {
            dp[i] = (i== 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1-p_heads);
        }

    }
    double ans = 0;
    for(int heads = 0; heads <=n ; ++heads)
    {
        int tails = n - heads;
        if(heads > tails)
        {
            ans+=dp[heads];
        }
    }
    cout << fixed << setprecision(10) << ans;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, x, m;
  cin >> n >> x >> m;
  
  vector<ll> store(0);
  set<ll> check;

  ll sum = 0;
  ll ans = 0;
  while (check.find(x) == check.end()){
    store.emplace_back(x);
    check.insert(x);
    sum = sum + x;

    x = x*x % m;
  }

  if (n <= store.size()){
    for (ll i = 0; i < n; i++){
      ans += store[i];
    }
  }
  else {
    ll id = 0;
    for (ll i = 0; i < store.size(); i++){
      if (store[i] == x){
        id = i;
        break;
      }
    }


    ans = sum;


    for (ll i = 0; i < id; i++){
      sum -= store[i];
    }

    ll l = store.size() - id;

    ans += sum * ((n - id) / l - 1);


    for (ll i = 0; i < (n - id) % l; i++){
      ans += store[id + i];
    }
  }

  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 5992
#include <stdio.h>

int main(void){
  
  int AB;
  int BC;
  int CA;
  
  scanf("%d",&AB);
  scanf("%d",&BC);
  scanf("%d",&CA);
  
  int K = AB * BC / 2;
  
  printf("%d",K);
  
  return 0;
}
    


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <stdio.h>
#include <iterator>

#include <string.h>
using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORD(i,a,b) for(int i=(a);i>(b);i--)
#define scn(a)  scanf("%d",&a)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vecout(vec) for(int i=0;i<vec.size();i++){cout<<vec[i]<<" ";} 
typedef long long ll;


const ll mod =1e9 +7;

int main(){
fastio
int n;
cin>>n;
char color[n];
int r=0,w=0;
FOR(i,0,n){
cin>>color[i];
if(color[i]=='W') w++;
else r++;
}
int ans=0;
FOR(i,0,r){
if(color[i]=='W') ans++;
}

cout<<ans<<'\n';


    return 0;
}

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

signed main(void)
{
	string s, t;
	cin >> s >> t;
	if (t.substr(0, s.size()) == s && t.size() == s.size() + 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vs=vector<string>;
using vvi =vector<vector<int>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    char c=s[0];
    int ans=0;
    rep(i,n){
        if(s[i]!=c){
            ans++;
            c=s[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

using namespace std;

int main(int argc, char *argv[]) {
    ll result = 0;
    ll A, B;
    cin >> A >> B;
    
    if((A + B) % 2 != 0){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    result = (A + B) / 2;

    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
min_cnt = 1000000
for A in range(1, N):
    cnt = 0
    B = N - A
    for i in str(A):
        cnt += int(i)
    for i in str(B):
        cnt += int(i)
    if min_cnt > cnt:
        min_cnt = cnt
print(min_cnt)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl a(n+1);
    exrep(i, 1, n) {
        cin >> a[i];
    }

    vl v(n+1);  // v[i] : 箱i(iは1-index)にボールを入れるなら1
    for(ll i = n; i >= 1; i--) {
        ll cnt = 0;
        for(ll j = 2*i; j <= n; j += i) {
            if(v[j]) {
                cnt++;
            }
        }
        if(cnt%2 != a[i]) {
            v[i] = 1;
        }
    }

    ll M = 0;
    vl b;
    exrep(i, 1, n) {
        if(v[i]) {
            M++;
            b.pb(i);
        }
    }

    out(M);
    for(auto p : b) {
        out(p);
    }
    
    re0;
}

Measured memory_bytes: 4980
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  int mas[w+1];
  memset(mas,0,sizeof(mas));
  for(int i=0,sum=0,a;i<h;i++,sum=0){
    for(int j=0;j<w;j++){
      cin >> a;
      cout << (j!=0?" ":"") << a;
      sum += a;
      mas[j]+=a;
    }
    cout << " " << sum << endl;
    mas[w] += sum;
  }
  for(int i=0;i<=w;i++){
    cout << (i!=0?" ":"") << mas[i];
  }
  cout << endl;
}



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

int main(){
long long n,i,t;
 cin>>n;
 vector<long long> v;
 long long sum=0;
 for(i=0;i<n;i++){
    cin>>t;
    v.push_back(t);
 }
 for(i=0;i<n-1;i++){
    if(v[i]>v[i+1]){
        sum=sum+(v[i]-v[i+1]);
        v[i+1]=v[i];
    }
 }
 cout<<sum;
   


    return 0;
}


Measured memory_bytes: 5284
#include<bits/stdc++.h>
#define slowanddetermined ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x); cout<<#x<<"="<<x<<endl;
#define debug2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long
using namespace std;


int32_t main()
{

    int n,x,y;
    cin>>n>>x>>y;
    map<int,int>mp;
    vector<int>adj[2003];
    for(int i=0;i<n-1;i++){
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    adj[x-1].push_back(y-1);
    adj[y-1].push_back(x-1);
    for(int k=0;k<n;k++){

        queue<int>q;
        vector<int>dist(n);
        vector<bool>visited(n);
        q.push(k);
        visited[k]=true;
        dist[k]=0;
        while(!q.empty()){
            int to=q.front();
            q.pop();
            for(int j=0;j<adj[to].size();j++){
                if(visited[adj[to][j]]==false){
                    dist[adj[to][j]]=dist[to]+1;
                    q.push(adj[to][j]);
                    visited[adj[to][j]]=true;
                }
            }
        }
        for(int j=0;j<n;j++){
            if(k!=j){
                mp[dist[j]]++;
            }
        }
        //debug(k);
        for(int i=0;i<n;i++){
           // cout<<dist[i]<<" ";
        }
       // cout<<endl;


    }
    for(int i=1;i<n;i++){
        cout<<(mp[i])/2<<endl;
    }

    return 0;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rrep(i,n) for (ll i = (n)-1; i >=0; --i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define dame { puts("-1"); return 0;}
#define show(x) cerr<<#x<<" = "<<x<<endl;

using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;

typedef vector<ll> vl;
typedef vector<pl> vp;
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 (a>b) { a=b; return 1; } return 0; }


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);


int main() {
  ll h1,m1,h2,m2,k;
  cin >> h1>>m1>>h2>>m2>>k;

  ll sa = -(h1*60+m1) + h2*60+m2;

  ll ans = sa - k;

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


Measured memory_bytes: 6200
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <tuple>
#include<cmath>
#include<queue>
#include <climits>

using lli = long long int;
using namespace std;
int inf = 1000000007;

int N, Q;
string s;
char t, d;

bool solve(vector<tuple<char, char>> q, int x) {
	char now = s[x];
	for (int i = 0; i < Q; i++) {
		tie(t, d) = q[i];
		if (t == now) {
			if (d == 'R')x++;
			else x--;
		}
		if (x == -1 || x == N) return false;
		now = s[x];
	}
	return true;
}

int main() {
	cin >> N >> Q;
	cin >> s;
	vector<tuple<char, char>> quary(Q);
	for (int i = 0; i < Q; i++) {
		cin >> t >> d;
		quary[i] = make_tuple(t, d);
	}
	//左端と右端探す
	int ok = -1;
	int ng = N;
	while (ng - ok != 1) {
		int x = (ng + ok) / 2;
		if (solve(quary, x))ok = x;
		else ng = x;
	}
	int left = ok;
	ok = N - 1;
	ng = -1;
	while (ok - ng != 1) {
		int x = (ng + ok) / 2;
		if (solve(quary, x))ok = x;
		else ng = x;
	}
	cout << max(0, left - ok + 1) << endl;
}


Measured memory_bytes: 1296
def main():
	n, *a = map(int, open(0).read().split())
	idc = [0] * (n + 1)
	R = list(range(n + 2))
	L = R[:]
	ans = 0
	for i in range(n):
		idc[a[i]] = i + 1
	for x in range(n, 0, -1):
		i = idc[x]
		M = R[i]
		m = L[i]
		ans += x * (M - i + 1) * (i - m + 1)
		# とくに変更済みのとき連結
		R[m - 1] = M
		L[M + 1] = m
	print(ans)

if __name__=="__main__":
	main()


Measured memory_bytes: 28316
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926
 
 
int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b <= 8)
        cout << "Yay!";
    else    
        cout << ":(";

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <math.h>
#include <string>
using namespace std;
 
const double PI = acos(-1);
const int M=1e9+7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define oo 1e9

int n,k;
vi a;
vector <int> dP;

void solve(){
	cin>>n>>k;
	a.resize(n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&a[i]);
	}
	dP.resize(n);
	for (int i = 1; i < n; ++i)
	{
		dP[i]=oo;
		for (int j = 1; j <= min(i,k); ++j)
		{
			dP[i]=min(dP[i], dP[i-j] + abs(a[i-j]-a[i]));
		}
	}
	printf("%d\n", dP[n-1]);
}

int main()
{

	int t;
	t=1;
	while(t--){
		solve();
	}

	return 0;
}




Measured memory_bytes: 4104
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,cnt=0;
  char s[101];
  scanf("%d",&n);
  scanf("%s",s);
  if(n%2!=0){
    cnt=-1;
  }
  else{
    for(i=0; i<n/2; i++){
      if(s[i]==s[n/2+i]){
        cnt++;
      }
    }
  }
  if(cnt==n/2){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
// Problem : C - gacha
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		set<string> st;
		for(int i=0;i<n;++i)
		{
			string s;
			cin>>s;
			st.insert(s);
		}
		cout<<st.size();
		    	
    }
    return 0;
}


Measured memory_bytes: 19200
#include<cstdio>
using namespace std;
typedef long long LL;

LL x,y;

int main()
{
	scanf("%lld%lld",&x,&y);
	LL num=y/x,ans=0;
	while (num) ans++,num/=2;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main() {
  int coin, point = 0;
  std::cin >> coin;
  while (true) {
    if (coin >= 500) {
      coin -= 500;
      point += 1000;
    }
    else {
      break;
    }
  }
  while (true) { 
    if (coin >= 5) {
    coin -= 5;
    point += 5;
    }
    else {
      break;
    }
  }
  std::cout << point;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    char s[105]={};
    long long int k;
    scanf("%s\n%lld",s,&k);
    int len=strlen(s);
    REP(i,len)
    {
        if(s[i]=='1')
        {
            k--;
            if(k==0)
            {
                printf("1\n");
                return 0;
            }
        }
        else
        {
            printf("%c\n",s[i]);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,h;
int a[100005],b[100005],ans,maxv=0x8fffffff,pos;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	cin>>n>>h;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]>maxv)
		{
			maxv=a[i];
		}
	}
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(b[i]>maxv)
		{
			pos++;
		}
	}
	for(int i=1;i<=pos;i++)
	{
		if(h>b[i])
		{
			h-=b[i];
			ans++;
		}
		else
		{
			ans++;
			cout<<ans;
			return 0;
		}
	}
	ans+=int(ceil(h*1.0/maxv));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
typedef long long ll;

ll min(ll a,ll b){return a<b?a:b;}
int main(void){
    ll n,x,ans=0,count=1,countp=1;
    scanf("%lld%lld",&n,&x);
    for (int i=0; i<n; i++){
        count=count*2+3;
        countp=countp*2+1;
    }
    for (int i=n; i>0; i--){
        if (x>count){
            ans+=countp;
            x-=count;
            if (x>0){
                ans++;
                x--;
            } else {
                break;
            }
        }
        if (x>0){
            x--;
        } else {
            break;
        }
        count=(count-3)/2;
        countp=(countp-1)/2;
    }
    printf("%lld\n",ans+(x<3?x:3));
	return 0 ;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 10000000
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;

double cost[1024][1024];
int d[1024];
bool used[1024];
int prev[1024];
int V;

void dijkstra(int s){
	fill(d,d+V,INF);
	fill(used,used+V,false);
	fill(prev,prev+V,-1);
	d[s] = 0;
	while(true){
		int v = -1;
		rep(i,V)if(!used[i] && (v == -1 || d[i] < d[v]))v = i;
		if(v == -1)break;
		used[v] = true;
		rep(i,V){
			if(d[i] > d[v] + cost[v][i]){
				d[i] = d[v] + cost[v][i];
				prev[i] = v;
			}
		}
	}
	return ;
}

vector<int> get_path(int t){
	vector<int> path;
	for(; t != -1; t = prev[t])path.push_back(t);
	reverse(path.begin(),path.end());
	return path;
}

int main(){
	int n;
	while(scanf("%d",&n),n){
		rep(i,1024)rep(j,1024)cost[i][j] = INF;
		int num[12800]={0},x[12800]={0},y[12800]={0};
		int ma = 0;
		rep(i,n){
			scanf("%d%d%d",&num[i],&x[i],&y[i]);
			num[i]--;
		}
		rep(i,n){
			reps(j,i+1,n){
				double dis = sqrt(((x[i]-x[j])*(x[i]-x[j]))+((y[i]-y[j])*(y[i]-y[j])));
				cost[num[i]][num[j]] = (dis > 50) ? INF : dis;
				cost[num[j]][num[i]] = (dis > 50) ? INF : dis;
			}
		}
		V = n;
		int m;
		scanf("%d",&m);
		rep(i,m){
			vector<int> ans;
			int from,to;
			scanf("%d%d",&from,&to);
			from--;to--;
			dijkstra(from);
			ans = get_path(to);
			int len = ans.size();
			if(d[to] == INF)puts("NA");
			else{
				rep(j,len-1)printf("%d ",ans[j]+1);
				printf("%d\n",ans[len-1]+1);
			}			
		}
	}
	return 0;
}

Measured memory_bytes: 9572
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  for(int i=1; i<=5; i++){
    int a; cin >>a;
    if(!a){cout <<i; return 0;}
  }
return 0;}

Measured memory_bytes: 3640
#define DEBUG 0

/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 5/19/2019, 9:06:56 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll N, K;
ll P[100010];
ll cnt[50];

int main()
{
  cin >> N >> K;
  for (auto i = K; i <= N; i++)
  {
    P[i] = 0;
  }
  for (auto i = 1; i < K; i++)
  {
    ll t = i;
    while (t < K)
    {
      P[i]++;
      t *= 2;
    }
  }
  fill(cnt, cnt + 50, 0);
  for (auto i = 1; i <= N; i++)
  {
    cnt[P[i]]++;
  }
  double ans = 0;
  for (auto i = 0; i < 50; i++)
  {
    ll t = 1;
    for (auto j = 0; j < i; j++)
    {
      t *= 2;
    }
    ans += cnt[i] / (double)t;
  }
  ans /= N;
  cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <stack>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <numeric>
#include <random>
#include <memory>
#include <chrono>
#include <iterator>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define sz(x) int((x).size())


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int S = 2e5 + 7;
const int inf = INT_MAX / 3;
const ll INF = LLONG_MAX / 3;
const int MOD = 1e9 + 7;



signed main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(9);
	ios::sync_with_stdio(false);
	cin.tie();
	cout.tie();

	ll n;
	cin >> n;

	vector < pair <ll, ll> > a(n);
	for (auto& x : a) {
		cin >> x.first >> x.second;
	}
	sort(a.begin(), a.end(), [](pii a, pii b) {return a.second < b.second; });

	ll t = 0;
	for (auto x : a) {
		t += x.first;
		if (t > x.second) {
			return cout << "No", 0;
		}
	}
	cout << "Yes";
	
	return 0;
}

Measured memory_bytes: 3456
/**
*    created: 04.05.2020 07:59:31
**/

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


int main() {
    ll x;
    cin >> x;
    ll a=0, b=0LL;
    rep(i,200){
        for (int j = -200; j < 200;j++){
            if(pow(i,5)-pow(j,5)==x){
                a = i;
                b = j;
            }
        }
    }
cout << a<<" "<<b << endl;
}


Measured memory_bytes: 4068
#include <stdio.h>
#include <math.h>
int main(){
	int H,W,i,j;
	while(1){
	scanf("%d %d",&H,&W);
		if(H ==0 && W==0){
			break;
		}
		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
			{
				if((i == 0 || i==H-1) || (j ==0 || j == W-1) ){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
			printf("\n");
	}
	return 0;
}

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y, z;
	cin >> x >> y >> z;
	
	int width = x - z;
	
	int answer = width / (y + z);
	cout << answer << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    string s;
    cin >> s;

    s.insert(4, 1, ' ');

    cout << s << 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++)

int main() {
    int n;
    scanf("%d", &n);
    vector<long> a(n+1);
    rep(i, n+1) {
        cin >> a[i];
    }
    vector<long> b(n);
    rep(i, n) {
        cin >> b[i];
    }
    long cnt = 0;
    rep(i, n) {
        if (a[i] + a[i+1] < b[i]) {
            cnt += a[i] + a[i+1];
            a[i] = 0;
            a[i+1] = 0;
        } else {
            cnt += b[i];
            if (a[i] > b[i]) {
                a[i] -= b[i];
            } else {
                a[i+1] -= b[i] - a[i];
                a[i] = 0;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4912
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author c0117321c5
 */
public class Main{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        int number=sc.nextInt();
        String mo=sc.next();
        if(number<3200){
            System.out.println("red");
        }else{
            System.out.println(mo);
        }
    }
    
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define all(x) (x).begin(), (x).end()
#define pb push_back

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> c[2];
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        c[i%2][x]++;
    }
    vpii m[2];
    for (int i=0; i<2; i++) {
        for (pii p : c[i]) {
            m[i].pb(pii(p.second, p.first));
        }
        m[i].pb(pii(0, -1));
        sort(all(m[i]));
        reverse(all(m[i]));
    }
    int ans = n;
    if (m[0][0].second != m[1][0].second) {
        ans = min(ans, n - m[0][0].first - m[1][0].first);
    }
    ans = min(ans, n - m[0][1].first - m[1][0].first);
    ans = min(ans, n - m[0][0].first - m[1][1].first);
    cout << ans << '\n';
}


Measured memory_bytes: 6140
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
  long long int a,b,c,d,e,f,g[110],h[110];
  cin >>a >>b>>c>>d;
  
  {
  if( d-b>0){
    for(int i=0;i<d-b;i++){
      cout << "U" ;
     
    }
  }
  else if(d-b<0){
    for(int i=0;i<b-d;i++){
      cout <<"D";
      
    }
  }
  }
        
   {
  if( c-a>0){
    for(int i=0;i<c-a;i++){
      cout << "R" ;
      
    }
  }
  else if(c-a<0){
    for(int i=0;i<a-c;i++){
      cout <<"L";
      
    }
  }
  }
  {
  if( d-b<0){
    for(int i=0;i<b-d;i++){
      cout << "U" ;
      
    }
  }
  else if(d-b>0){
    for(int i=0;i<d-b;i++){
      cout <<"D";
      
    }
  }
  }
  {
  if( c-a>0){
    for(int i=0;i<c-a+1;i++){
      cout << "L" ;
     
    }
  }
  else if(c-a<0){
    for(int i=0;i<a-c+1;i++){
      cout <<"R";
      
    }
  }
  }
  {
  if( d-b>0){
    for(int i=0;i<d-b+1;i++){
      cout << "U" ;
      
    }
  }
  else if(d-b<0){
    for(int i=0;i<b-d+1;i++){
      cout <<"D";
     
    }
  }
  }
  {
  if( c-a>0){
    for(int i=0;i<c-a+1;i++){
      cout << "R" ;
     
    }
  }
  else if(c-a<0){
    for(int i=0;i<a-c+1;i++){
      cout <<"L";
      
    }
  }
  }
     {
  if( d-b>0){
    for(int i=0;i<1;i++){
      cout << "D" ;
      
    }
  }
  else if(d-b<0){
    for(int i=0;i<1;i++){
      cout <<"U";
     
    }
  }
  }
  {
  if( c-a>0){
    for(int i=0;i<1;i++){
      cout << "R" ;
     
    }
  }
  else if(c-a<0){
    for(int i=0;i<1;i++){
      cout <<"L";
      
    }
  }
  }
  {
   if( d-b>0){
    for(int i=0;i<d-b+1;i++){
      cout << "D" ;
      
    }
  }
  else if(d-b<0){
    for(int i=0;i<b-d+1;i++){
      cout <<"U";
     
    }
  }
  }
  {
  if( c-a>0){
    for(int i=0;i<c-a+1;i++){
      cout << "L" ;
     
    }
  }
  else if(c-a<0){
    for(int i=0;i<a-c+1;i++){
      cout <<"R";
      
    }
  }
  }
    {
  if( d-b>0){
    for(int i=0;i<1;i++){
      cout << "U" ;
      
    }
  }
  else if(d-b<0){
    for(int i=0;i<1;i++){
      cout <<"D";
     
    }
  }
  }

cout << endl;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vec<pint> a(N);
  REP(i, N) {
    int p;
    cin >> p;
    a[i].fst = p;
    a[i].snd = i;
  }
  sort(ALL(a));
  int ans = 0;
  REP(i, N) {
    if (i % 2 == 0 && a[i].snd % 2 == 1) ans++;
  }
  print(ans);
}

Measured memory_bytes: 1792
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
L = []
for k, v in C.items():
  if v >= 2:
    L.append(k)
  if v >= 4:
    L.append(k)
if len(L) < 2:
  print(0)
else:
  L.sort()
  ans = L[-1] * L[-2]
  print(ans)

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

int main() {
    int64_t H, W, K, x1, y1, x2, y2;
    cin >> H >> W >> K >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;

    vector<string> c(H);
    for (string& C : c) {
        cin >> C;
    }

    vector<vector<int64_t>> cost(H, vector<int64_t>(W, LLONG_MAX));
    struct Element {
        int64_t x, y, cost;
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;
    pq.push({ x1, y1, cost[x1][y1] = 0 });

    int64_t dx[] = { 0, 1, 0, -1 };
    int64_t dy[] = { 1, 0, -1, 0 };

    while (!pq.empty()) {
        Element t = pq.top();
        pq.pop();
        if (t.cost > cost[t.x][t.y]) {
            continue;
        }

        for (int64_t i = 0; i < 4; i++) {
            int64_t nx = t.x, ny = t.y;
            int64_t new_cost = t.cost + 1;
            for (int64_t j = 0; j < K; j++) {
                nx += dx[i];
                ny += dy[i];
                if (nx < 0 || H <= nx || ny < 0 || W <= ny || c[nx][ny] == '@' || new_cost > cost[nx][ny]) {
                    break;
                }
                if (new_cost < cost[nx][ny]) {
                    pq.push({ nx, ny, cost[nx][ny] = new_cost });
                }
            }
        }
    }

    int64_t ans = cost[x2][y2];
    cout << (ans == LLONG_MAX ? -1 : ans) << endl;
}

Measured memory_bytes: 20008