akhauriyash/Code-Regression huggingface dataset:
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, a, b, c): (usize, usize, usize, usize) = parse!(it, 4);
    let l: Vec<usize> = (0..n).map(|_| parse!(it)).collect();
    let mut ret = std::usize::MAX / 2;
    let diff = |x: usize, y: usize| if x >= y { x - y } else { y - x };
    for i in 0..4usize.pow(n as u32) {
        let mut p = 0;
        let mut ca = 0;
        let mut cb = 0;
        let mut cc = 0;
        let mut i = i;
        for j in 0..n {
            match i & 3 {
                1 => {
                    if ca != 0 {
                        p += 10
                    };
                    ca += l[j]
                }
                2 => {
                    if cb != 0 {
                        p += 10
                    };
                    cb += l[j]
                }
                3 => {
                    if cc != 0 {
                        p += 10
                    };
                    cc += l[j]
                }
                _ => (),
            }
            i >>= 2;
        }
        if ca == 0 || cb == 0 || cc == 0 {
            continue;
        }
        p += diff(ca, a) + diff(cb, b) + diff(cc, c);
        ret = std::cmp::min(p, ret);
    }
    println!("{}", ret);
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        5 100 90 80
98
40
30
21
80
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
import math


a, b, c = list(map(int, input().split()))
sa, sb, sc = math.sqrt(a), math.sqrt(b), math.sqrt(c)
d = c-a-b

if (c-a-b > 0) and ((c-a-b)**2 > 4*a*b):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#!/usr/bin/ruby
# encoding: utf-8

n = gets.to_i
$a = Array.new
for i in 0..n-1
  $a[i] = gets.to_i
end
  
# 昇順
$a.sort!
sum = 0
sum1= 0
sum2= 0

$a_copy1 = Marshal.load(Marshal.dump($a))
$a_copy2 = Marshal.load(Marshal.dump($a))
$a_copy3 = Marshal.load(Marshal.dump($a))
$a_copy4 = Marshal.load(Marshal.dump($a))
$a_copy5 = Marshal.load(Marshal.dump($a))

if n.odd? then
  b1 = ($a[n/2] - $a[n-1]).abs
  b2 = ($a[n/2] - $a[0]).abs

  sum1 = b1
  $a.delete_at(n/2)
  ap = $a.pop
# puts "ap = #{ap}"
  while $a.size >= 1 do
    as = $a.shift
#   puts "as = #{as}"
    sum1 += (ap - as).abs
    if  $a.size >= 1 then
      ap = $a.pop
#     puts "ap = #{ap}"
      sum1 += (ap - as).abs
    end
  end    

  sum2 = b2
  $a_copy1.delete_at(n/2)
  as = $a_copy1.shift
# puts "as = #{as}"
  while $a_copy1.size >= 1 do
    ap = $a_copy1.pop
#   puts "ap = #{ap}"
    sum2+= (ap - as).abs
    if  $a_copy1.size >= 1 then
      as = $a_copy1.shift
#     puts "as = #{as}"
      sum2 += (ap - as).abs
    end
  end    

  if sum1 >= sum2 then
    puts sum1
  else
    puts sum2
  end
  exit

# nが偶数の時 ===========================
else
  sum1 = 0
  sum2 = 0
  sum3 = 0
  sum4 = 0

  # pattern1 最初が n/2-1
  c1 = ($a_copy2[n/2-1] - $a_copy2[n-1]).abs
  c2 = ($a_copy2[n/2-1] - $a_copy2[0]).abs

  sum1 = c1
  $a_copy2.delete_at(n/2-1)
  ap = $a_copy2.pop
# puts "ap = #{ap}"
  while $a_copy2.size >= 1 do
    as = $a_copy2.shift
#   puts "as = #{as}"
    sum1 += (ap - as).abs
    if $a_copy2.size >= 1 then
      ap = $a_copy2.pop
#     puts "ap = #{ap}"
      sum1 += (ap - as).abs
    end
  end

  sum2 = c2
  $a_copy3.delete_at(n/2-1)
  as = $a_copy3.shift
# puts "as = #{as}"
  while $a_copy3.size >= 1 do
    ap = $a_copy3.pop
#   puts "ap = #{ap}"
    sum2 += (ap - as).abs
    if $a_copy3.size >= 1 then
      as = $a_copy3.shift
#     puts "as = #{as}"
      sum2 += (ap - as).abs
    end
  end
  

  # pattern2 最初が n/2
  d1 = ($a_copy4[n/2] - $a_copy4[n-1]).abs
  d2 = ($a_copy4[n/2] - $a_copy4[0]).abs

  sum3 = d1
  $a_copy4.delete_at(n/2)
  ap = $a_copy4.pop
# puts "ap = #{ap}"
  while $a_copy4.size >= 1 do
    as = $a_copy4.shift
#   puts "as = #{as}"
    sum3 += (ap - as).abs
    if $a_copy4.size >= 1 then
      ap = $a_copy4.pop
#     puts "ap = #{ap}"
      sum3 += (ap - as).abs
    end
  end

  sum2 = d2
  $a_copy5.delete_at(n/2)
  as = $a_copy5.shift
# puts "as = #{as}"
  while $a_copy5.size >= 1 do
    ap = $a_copy5.pop
#   puts "ap = #{ap}"
    sum2 += (ap - as).abs
    if $a_copy5.size >= 1 then
      as = $a_copy5.shift
#     puts "as = #{as}"
      sum2 += (ap - as).abs
    end
  end
end

ans = Array.new(4)
ans[0] = sum1
ans[1] = sum2
ans[2] = sum3
ans[3] = sum4

puts ans.max


Measured memory_bytes: 9832
# coding: utf-8

C = []
for i in range(3):
    _c = list(map(int, input().split()))
    C.append(_c)

#print(C)

a = [0, 0, 0]
b = [0, 0, 0]

ans_flag = 'No'
a1_flag = False
a2_flag = False
a3_flag = False

def check_b(_b):
    b_count = 0
    for i_b in _b:
        if i_b >= 0 and i_b <= 100:
            b_count += 1
    
    if b_count >= 3:
        return True
    else:
        return False

def check_succes(a_val,b, c):
    b_count2 = 0
    i = 0
    for i_b in b:
        if i_b == c[i] - a_val:
            b_count2 += 1
        i += 1
    if b_count2 >= 3:
        return True
    else:
        return False

main_count = 0

for a_1 in range(101):
    a[0] = a_1
    for x in range(len(b)):
        b[x] = C[0][x] - a[0]
    #main_count += 1
    #if main_count == 1:
        #print("b = {0}".format(b))

    if check_b(b):
        a1_flag = True
        for a_2 in range(101):
            a[1] = a_2
            if check_succes(a[1], b, C[1]):
                a2_flag = True
                for a_3 in range(101):
                    a[2]= a_3
                    if check_succes(a[2], b, C[2]):
                        a3_flag = True
                        ans_flag = 'Yes'



print(ans_flag)


#print('--debug--')
#print(a1_flag)
#print(a2_flag)
#print(a3_flag)


def check_succes(a_val,b, c):
    b_count2 = 0
    i = 0
    for i_b in _b:
        if i_b == c[i] - a_val:
            b_count2 += 1
        i += 1
    if b_count2 >= 3:
        return True
    else:
        return False



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(int argc, char** argv) {
    int n, m, prev;

    cin >> n >> m;
    vector<int> ac(n), wa(n);

    prev = 0;
    rep(i, m) {
        int d;
        string ans;
        cin >> d >> ans;

        if (ac[d - 1])
            continue;
        if (ans == "AC")
            ac[d - 1] = 1;
        else
            wa[d - 1]++;
    }

    ll sumac = 0;
    ll sump = 0;
    rep(i, n) {
        if (ac[i] > 0) {
            sumac += ac[i];
            sump += wa[i];
        }
    }
    cout << sumac << " " << sump << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

const string YES = "YES";
const string NO = "NO";

void solve(std::string S)
{
    map<char, int> m;
    for (int i = 0; i < S.size(); i++)
    {
        m[S[i]]++;
    }

    int minimum = INF;
    int maximum = -1;
    for (char i = 'a'; i <= 'c'; i++)
    {

        minimum = min(minimum, m[i]);
        maximum = max(maximum, m[i]);
    }

    if ((maximum - minimum) <= 1)
    {
        cout << YES << endl;
    }
    else
    {
        cout << NO << endl;
    }
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

#define ll long long
using namespace std;

map<int, int> mp;

int main() {

    int n;
    string ss;
    cin>>ss;

    for(int i=0;i<ss.size();i++){
        if(!(i&1)){
            if(ss[i]=='R'||ss[i]=='U'||ss[i]=='D') ;
            else                 return cout<<"No"<<endl,0;


        }
        else {
            if(ss[i]=='L'||ss[i]=='U'||ss[i]=='D') ;
            else
                return cout<<"No"<<endl,0;

        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
#define mp make_pair
#define pb push_back
# define PI acos(-1)
# define double long double
const int MxN = 200005 ; 
# define FOR(i,a,b) for(int i = a ; i < b ; ++i) 
# define RFOR(i,a,b) for(int i = b ; i > )
 
bool fun(const PII &a, const PII &b) {
	if(a.first == b.first) {
		return a.second > b.second ; 
	}

	return a.first < b.first ; 
}

ll dp[10][10] ; 


void solve() {
	int h ,w ; 
	ll c[10][10] ; 
	cin >> h >> w ; 
	FOR(i,0,10) {
		FOR(j,0,10) {
			cin >> c[i][j] ; 
			dp[i][j] = c[i][j] ; 
		}
	}

	FOR(k,0,10) {
		FOR(i,0,10) {
			FOR(j,0,10) {
				dp[i][j] = min(dp[i][j] ,(ll) dp[i][k] +(ll) dp[k][j]) ; 
			}
		}
	}



	int x ; 
	ll ans = 0 ; 
	FOR(i,0,h) {
		FOR(j,0,w) {
			cin >>x ; 
			if(x != -1)
			ans += (ll)dp[x][1] ; 
		}
	}
	cout << ans ;


	
 

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	int  t =1; 
	//cin >> t ; 
	while(t--)
		solve() ; 
	return 0 ; 
}



Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	io;
	ll a,p;
	cin>>a>>p;
	ll n=a*3+p;
	ll ans=n/2;
	cout<<ans;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int n, m;
vector<vector<int> > g;
vector<int> res;

void bfs(int s = 0) {
    queue<int> q;
    q.push(s);
    res[0] = 0;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        rep (i, g[x].size()) {
            int next = g[x][i];
            if (res[next] != -1) continue;
            res[next] = x + 1;
            q.push(next);
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cin >> n >> m;
    g = vector<vector<int> >(n);
    rep (i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    } 
    res.resize(n, -1);
    bfs();
    cout << "Yes" << endl;
    FOR (i, 1, n) cout << res[i] << endl;
    
    return 0;
}



Measured memory_bytes: 10176
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{
    lli a,b;
    cin>>n>>a>>b;

    if(a==b)
    {
        cout<<1<<endl;
        return 0;
    }

    if(n==1||a>b)
    {
        cout<<0<<endl;
        return 0;
    }

    cout<<(b-a)*(n-2)+1<<endl;

}   aryanc403();
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int getketa(int x){
    int cnt = 0;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    return cnt;
}
int main() {
    int n;
    cin >> n;

    int cnt = 0;
    IFOR(i, 1, n){
        if(getketa(i) % 2 == 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N);
    for(auto &e : H) cin >> e;
    vector<int> A(N, 1);
    for(int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        if(H[a] <= H[b]) A[a] = 0;
        if(H[b] <= H[a]) A[b] = 0;
    }
    int ans = count(A.begin(), A.end(), 1);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4052
import math

def solve(a, b):
	if a>b: a,b = b,a
	if a==b or a+1==b:
		return 2*a-2
	
	mul = a*b
	c = int(math.sqrt(mul))
	if c**2==mul: c-=1
	if c*(c+1)<mul:
		return 2*c-1 #(a-1)+(2c-a)
	else:
		return 2*c-2 #(a-1)+(2c-a-1)

n = int(input())
for _ in range(n):
	a,b = map(int, input().split())
	print(solve(a,b))
	

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

int main(){
	string s;
	cin>>s;
	
	if(s[0]!=s[1] &&s[1]!=s[2] && s[2]!=s[0]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public void main() {
        Scanner sc = new Scanner(new InputStreamReader(System.in));

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        println((a + c) == 2 * b ? "YES" : "NO");
    }

    public void print(Object o) {
        System.out.print(o);
    }

    public void println(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        new Main().main();
    }
}


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

ll maxtime(ll x) {
    return (x+9) / 10 * 10;
}

ll remtime(ll x) {
    return maxtime(x) - x;
}

int main() {
    ios::sync_with_stdio(false);
    ll n = 5;
    //cin >> n;
    ll a[n];
    ll sum;
    ll remmax = -987654321;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += maxtime(a[i]);
        remmax = max(remmax, remtime(a[i]));
    }
    cout << sum - remmax << endl;
    return 0;
}


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

using namespace std;

int main() {
    double a,b,x;
    cin >> a >> b >> x;
    double s = x/a;
    double ans;
    if (s <= (a*b)/2) {
        double a_l = (2*s)/b;
        ans = M_PI/2.0 - atan(a_l/b);
    } else {
        double s_b = a*b - s;
        double b_b = (2*s_b)/a;
        ans = atan(b_b/a);
    }
    cout << fixed << setprecision(20) << ans/M_PI * 180.0 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

l6 = [6**i for i in range(1,7)]
l9 = [9**i for i in range(1,6)]

l = [1]+l6+l9

dp=[10**8 for _ in range(n+1)]

for i in range(1,n+1):
    for j in l:
        if i == j:
            dp[i]= 1
        elif i>j:
            if dp[i-1]!=0:
                dp[i] = min(dp[i],dp[i-j]+1)
            else:
                pass

print(dp[n])        

Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int n;
vi a;

bool odd(int k) {
  bool res = false;
  rep(i, n) if(a[i] == k) res ^= (((n - 1) & i) == i);
  return res;
}

int main() {
  cin >> n;
  bool one = false;
  rep(i, n) {
    char c;
    cin >> c;
    a.push_back(c - '1');
    if(c == '2') one = true;
  }
  if(odd(1))
    cout << 1;
  else if(!one && odd(2))
    cout << 2;
  else
    cout << 0;
  cout << endl;
}

Measured memory_bytes: 6512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];
int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}

ll fac[1000010], finv[1000010], inv[1000010];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 1000010; ++i) {
		fac[i] = fac[i - 1] * i%MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	ll N, M; cin >> N >> M;
	COMinit();
	ll t = M;
	ll ans = 1;
	for (int i = 2; i*i <= M; ++i) {
		ll cnt = 0;
		while (1) {
			if (t%i != 0) break;
			cnt++;
			t /= i;
		}
		ans = ans*COM(N + cnt - 1, cnt)%MOD;
	}
	if (t != 1) ans = ans * COM(N, 1) % MOD;
	cout << ans << endl;
	int nm; cin >> nm;
	return 0;
}

Measured memory_bytes: 23680
package main

import (
	"fmt"
	"bufio"
	"strconv"
	"os"
	"strings"
)

var N int
var count int
const MAX_NUM int = 10e9
var L, R =  make([]int, 500000+2), make([]int, 500000+2)

func merge(A []int, left, mid, right int) {
	n1 := mid -left
	n2 := right - mid
	for i:=0; i<n1; i++ {
		L[i] = A[left+i]
	}
	L[n1] = MAX_NUM
	for i:=0; i<n2; i++ {
		R[i] = A[mid+i]
	}
	R[n2] = MAX_NUM
	i := 0
	j := 0
	for k:=left; k<right; k++ {
		if L[i]<R[j] {
			A[k] = L[i]
			i += 1
		} else {
			A[k] = R[j]
			j += 1
		}
	}
	count += right - left
}


func mergeSort(A []int, left, right int) {
	if left+1<right {
		mid := (right + left) / 2
		mergeSort(A, left, mid)
		mergeSort(A, mid, right)
		merge(A, left, mid, right)
	}
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, _ := strconv.Atoi(scanner.Text())
	return i
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	A := make([]int, N+1)
	for i:=0; i<N; i++ {
		A[i] =nextInt(scanner)
	}
	mergeSort(A, 0, N)
	fmt.Println(strings.TrimRight(fmt.Sprintf("%+v", A[0:N])[1:], "]"))
	fmt.Println(count)
}


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

typedef struct time{
  int a;
  int b;
} time;

int cmp(const void *x, const void *y) {
  return (*(time *)x).b - (*(time *)y).b;
}

int main() {
  int n; long int sum = 0;
  scanf("%d", &n);
  time t[n];
  for (size_t i = 0; i < n; i++) {
    scanf("%d %d", &(t[i].a), &(t[i].b));
  }
  qsort(t, n, sizeof(time), cmp);
  for (size_t i = 0; i < n; i++) {
    sum += t[i].a;
    if (sum > t[i].b) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n, m;
	cin >> n >> m;
	int dp[n+1];
	rep(i,m){
		int a;
		cin >> a;
		dp[a] = INF;
	}
	dp[0] = 1; if(dp[1]==INF)dp[1] = 0;else dp[1] = 1;
	rep(i,n-1) {
      if(dp[i+2]!=INF){
		dp[i+2] = (dp[i+1]!=INF?dp[i+1]:0)+(dp[i]!=INF?dp[i]:0);
		dp[i+2]%=MOD;}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

/*
opt    = {} # opt[t] は t円の最適な払い方。これから求めるよ！
opt[0] = [] # 0円 はコイン0枚で最適に(?)払えます
1.upto(T) do |t|
  opt[t] =                       # t円の最適な払い方は
	 C.select{|c| opt[t-c]}.
		  map{|c| opt[t-c]+[c]}. #   t-c円の最適な払い方 + c円玉
	   min_by{|p| p.size}        #   … のうち一番枚数少ないヤツ
end
p opt[T]
*/

int main()
{
	set<int> pay;

	rep(i, 10) {
		int x = pow(6, i);
		if (x < 100000)
			pay.insert(x);
		x = pow(9, i);
		if (x < 100000)
			pay.insert(x);
	}
	int N;
	cin >> N;
	vector<int> dp(N + 1);
	rep1(t, N) {
		int p = 100000;
		for (int c : pay) {
			if (t - c >= 0) {
				p = min(p, dp[t - c] + 1);
			}
		}
		dp[t] = p;
	}
	int ans = dp[N];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.*;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            while (a[i] % 2 == 0) {
                a[i] /= 2;
                cnt++;
            }
        }

        System.out.println(cnt);
        sc.close();
    }
}

Measured memory_bytes: 35064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

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


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


class SegmentTree():
    def __init__(self, values, default=float("inf")):
        n = len(values)
        self.size = 1
        self.default = default
        while self.size < n:
            self.size *= 2
        # tree[0] = empty
        # child of tree[n] = tree[n*2], tree[n*2+1]
        self.tree = [self.default] * self.size * 2
        for i in range(n):
            self.tree[self.size + i] = values[i]
        for i in range(self.size-1, 0, -1):
            self.tree[i] = min(self.tree[i*2], self.tree[i*2+1])

    def update(self, index, value):
        index += self.size
        self.tree[index] = value
        while index > 1:
            index //= 2
            self.tree[index] = min(
                self.tree[index*2], self.tree[index*2+1])

    def __query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.default
        if a <= l and r <= b:
            return self.tree[k]
        left = self.__query(a, b, k*2, l, (l+r)//2)
        right = self.__query(a, b, k*2+1, (l+r)//2, r)
        return min(left, right)

    # query segmentation value of [a, b)
    def query(self, a, b):
        return self.__query(a, b, 1, 0, self.size)


def main():
    N, M = map(int, input().split())
    op = [None] * M
    for i in range(M):
        L, R, C = map(int, input().split())
        op[i] = (L-1, R-1, C)
    op.sort()
    tree = SegmentTree([float("inf")] * N)
    tree.update(0, 0)
    for l, r, c in op:
        mn = tree.query(l, r)
        current = tree.tree[tree.size + r]
        if mn+c < current:
            tree.update(r, mn+c)
    ans = tree.query(N-1, N)
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 122332
/* is_prime.cpp
    素数判定

    verified: AOJ ALDS1_1_C Prime Numbers
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=ja
*/
#include <bits/stdc++.h>
using namespace std;

/*  is_prime(n)
    入力：整数 n
    出力：nが素数かの真偽値
    計算量：O(√n)
*/
bool is_prime(long long n) {  // is n prime or not
    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int k;
        cin >> k;
        if (is_prime(k)) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int n,m,ans=0;
    cin >>n ;
    vector<string> st_n(n);
    vector<int> ct_n(n,1);
    for (int i=0;i<n;i++){
        cin >> st_n[i];
    }
    cin >>m ;
    vector<string> st_m(m);
    for (int i=0;i<m;i++){
        cin >> st_m[i];
    }
    for (int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(st_n[i]==st_n[j]){
                ct_n[i]++;
            }
        }
        for(int j=0;j<m;j++){
            if(st_n[i]==st_m[j]){
                ct_n[i]--;
            }
        }
        ans = max(ans,ct_n[i]);
    }
    cout << ans <<endl;
}


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

#define MAX 101
int graph[MAX][MAX];

int main(){
	for(int i=0;i<MAX;i++){
		for(int j=0;j<MAX;j++){
			graph[i][j]=0;
		}
	}

	int n,from,k,to;	cin>>n;
	for(int i=0;i<n;i++){
		cin>>from>>k;
		for(int j=0;j<k;j++){
			cin>>to;
			graph[from][to]=1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(j>1)cout<<" ";
			cout<<graph[i][j];
		}
		cout<<endl;
	}

	return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,K,Q;
ll A,B,C,D,X;

ll ans;
bool F=false;
string S,T,U;
int main(){
    cin>>A>>B>>C>>K;
    if(K<A){
        cout<<K<<endl;
    }else if(K<=A+B){
        cout<<A<<endl;
    }else{
        cout<<A-(K-(A+B))<<endl;
    }
}

Measured memory_bytes: 3620
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    ll n=s.length();
    ll ans=0;
    ll pre=0;
    s="0"+s;
    for(ll i=n;i>=0;i--){
        ll num=s[i]-'0';
        if(pre==1){
            num++;
        }
        //cout<<num<<endl;

        if(num<=4){
            ans+=num;
            pre=0;
        }
        else if(num>=6){
            ans+=(10-num);
            pre=1;
        }
        else if(num==5){
            ll tmp=s[i-1]-'0';
            if(tmp<=4){
                ans+=5;
                pre=0;
            }
            else{
                ans+=5;
                pre=1;
            }
        }
        //cout<<ans-preans<<endl;
        
        //cout<<ans<<endl;
    }
    /*cout<<ans<<endl;
    ll num=s[0]-'0';
    if(pre==1)num++;
    if(num<=5){
        ans+=num;
    }
    else if(num<=9){
        ans+=(10-num);
        ans++;
    }*/
    cout<<ans<<endl;
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






//99999999999995
// 31415  9  265358  9 7  9  323846264338327  9  5028841  9  71693  9  9  3755105820  9  74  9  445  9 2307816406286208  9  9  86280348253421170


Measured memory_bytes: 2332
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    private static int solve(int N, int[] A, int[] B) {
        Integer[] buf = new Integer[N];
        long required = 0;
        int minus = 0;
        int plus = 0;

        for(int i = 0; i < N; i++) {
            buf[i] = 0;

            int diff = B[i] - A[i];
            if (diff <= 0) {
                buf[i] = -1 * diff;
                plus += 1;
            } else {
                required += diff;
                minus += 1;
            }
        }

        if (minus == 0) {
            return 0;
        }

        Arrays.sort(buf, Collections.reverseOrder());
        for(int i = 0; i < plus; i++) {
            required -= buf[i];
            if (required <= 0) {
                return (i+1) + minus;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        for(int i = 0; i < N; i++) {
            B[i] = sc.nextInt();
        }

        int ans = solve(N, A, B);
        System.out.println(ans);
    }
}


Measured memory_bytes: 83716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H[] = new int[N];
		boolean possible = true;

		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}

		for (int i = 0; i < N - 1; i++) {
			if (H[i + 1] < H[i]) {
				H[i]--;
				if (H[i + 1] < H[i]) possible = false;
			} else if (1 <= i && 1 <= H[i] - H[i - 1]) {
				H[i]--;
			}
			if (1 <= i && H[i] < H[i - 1]) possible = false;
		}

		if (possible) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 48752
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>


#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _Ty> static _Ty tp_abs(const _Ty& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _Ty> static _Ty tp_min(_Ty a, _Ty b) {
	return a < b ? a : b;
}
template <class _Ty> static _Ty tp_max(_Ty a, _Ty b) {
	return a > b ? a : b;
}

static const int EduDp_INF = 101000000;

static void D_task();

int main()
{
	D_task();
	
	fflush(stdout);
	return 0;
}


class Baggage
{
public:
	LLONG weight = 0;
	LLONG value = 0;
	bool picked = false;
};

class SumOfWV
{
public:
	LLONG value = 0;
	LLONG weight = 0;
};

static void D_task()
{
	static const int D_WMAX = 100001;

	int N, W;
	scanf(" %d %d", &N, &W);

	auto bgg = new Baggage[N];
	for (int i = 0; i < N; i++) {
		scanf(" %lld %lld", &(bgg[i].weight), &(bgg[i].value));
	}

	auto dp = new LLONG[N + 1][D_WMAX];
	memset(dp, 0, sizeof(dp[0][0]) * (N + 1) * D_WMAX);

	for (int i = 0; i < N; i++) {
		for (LLONG sumw = 0; sumw <= W; sumw++) {
			if ((sumw >= bgg[i].weight)) {
				dp[i + 1][sumw] = dp[i][sumw - bgg[i].weight] + bgg[i].value;
			}
			dp[i + 1][sumw] = tp_max<LLONG>(dp[i + 1][sumw], dp[i][sumw]);
		}
	}
	printf("%lld\n", dp[N][W]);

	delete[] bgg;
	delete[] dp;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	int n, m;
	cin >> n >> m;
	ll a[n];
	for(int i=0;i<n;i++)	cin >> a[i];
	int count = 0;
	ll total = accumulate(a, a+n, 0);
	ll thresh = ceil(total / (4*m));
	if((total % (4*m)) == 0)
		for(int i=0;i<n;i++) {
			if(a[i] >= thresh)	count++;
		}
	else
		for(int i=0;i<n;i++) {
			if(a[i] > thresh)	count++;
		}
		
	if(count >= m)	cout << "Yes\n";
	else	cout << "No\n";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi v(n); rep(i, n) cin >> v[i];
	
	ll sum = accumulate(all(v), 0ll);
	if(sum % (n * (n + 1ll) / 2)){
		cout << "NO" << endl;
		return 0;
	}
	
	ll m = sum / (n * (n + 1ll) / 2);
	vector<ll> d(n);
	rep(i, n) d[i] = v[(i + 1) % n] - v[i] - m;
	rep(i, n) if(d[i] > 0 || (-d[i]) % n){
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
	int a,b,x,y;
	scanf("%d %d",&a,&b);
	x=a+b;
	if(x%2==0){
		y=x/2;
		printf("%d\n",y);
	}
	else{
		y=(x/2)+1;
		printf("%d\n",y);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;
ll a[5]={0};

void print(vector<int> n){
  cout << "------" << endl;
  rep(i,3){
    printf("a[%d]=%lld\n", n[i], a[n[i]]);
  }
}

ll calc(vector<int> n){
  ll res=1;
  //print(n);                                                                   
  for(auto i:n){
    res *= a[n.back()];
    n.pop_back();
  }
  return res;
}

ll dfs(vector<int> idx, int depth){
  if (depth==3) return calc(idx);
  ll res=0;
  rep(i,5){
    if(find(idx.begin(), idx.end(),i)==idx.end()){
      vector<int> used(idx.begin(),idx.end());
      used.push_back(i);
      res += dfs(used, depth+1);
      used.pop_back();
    }
  }
  return res;
}

int main()
{
  int N;
  char S[110000][15];
  ll res=0;
  cin >> N;

  rep(i,N) cin >> S[i];

  rep(i,N){
    char c=S[i][0];
    if(c=='M') a[0]++;
    else if(c=='A') a[1]++;
    else if(c=='R') a[2]++;
    else if(c=='C') a[3]++;
    else if(c=='H') a[4]++;
  }

  vector<int> v = {};
  res = dfs(v, 0);

  cout << res/6 << endl;
}



Measured memory_bytes: 1664
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	
	if (k <= a) {
		cout << a - k << " " << b << endl;
	}
	else if (k <= a + b) {
		cout << 0 << " " << a+b-k<< endl;
	}
	else {
		cout << 0 << " " << 0 << endl;
	}
}

Measured memory_bytes: 764
n, d = [int(i) for i in input().split()]

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


count = 0
for i in range(n):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k]) ** 2

        if s ** 0.5 % 1 == 0:
            count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long unsigned int K;
  string S;
  cin >> K >> S;
  if(S.length()<=K){
    cout << S <<endl;
  }
  else{
    cout << S.substr(0,K) << "..." <<endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 200005

ll inv[N], fac[N], finv[N];

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

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

	string s;
	cin >> s;
	int a1 = (s[0] - '0') * 10 + (s[1] - '0');
	int a2 = (s[2] - '0') * 10 + (s[3] - '0');

	int f1 = 0, f2 = 0;
	// cout << a1 << " " << a2 << "\n";
	if(a1 >= 1 && a1 <= 12)
		f1 = 1;
	if(a2 >= 1 && a2 <= 12)
		f2 = 1;
	if(f1 && f2)
		cout << "AMBIGUOUS\n";
	else if(f1)
		cout << "MMYY\n";
	else if(f2)
		cout << "YYMM\n";
	else
		cout << "NA\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
vector<LL>val;
LL a[1010]={};
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        a[i]+=a[i-1];
    }

    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
        val.push_back(a[j]-a[i-1]);

    LL ans=0;
    for(int i=40;i>=0;i--)
    {
        vector<LL>val2;
        int cnt=0;
        LL tmp=1LL<<i;
        for(int j=0;j<val.size();j++)
        {
            if(val[j]&tmp)
            {
                val2.push_back(val[j]);
                cnt++;
            }
        }
        if(cnt>=k)
        {
            val=val2;
            ans+=tmp;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6384
#include<stdio.h>
#include<math.h>

int main()
{
	long int N, M;
	scanf("%ld %ld", &N, &M);
	
	int A[M];
	int r;
	for(r=0; r<M; r++){
		scanf("%d", &A[r]);
		N = N - A[r];
	}
	
	if(N<0) printf("-1");
	else printf("%ld", N);
	
	return 0;
	
}



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


void solve(long long N, long long M, std::vector<long long> A){
    long long sum = accumulate(A.begin(), A.end(), 0);
    cout << (sum <= N ? N - sum : -1) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


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

int main(){
  map<int, int> T;
  int N, sum = 0; cin >>N;
  for(int i = 1; i <= N; i++){
    int a; cin >>a;
    sum += a;
    T[i] = a;
  }
  int M; cin >>M;
  while(M--){
    int a, b; cin >>a >>b;
    cout <<sum - (T[a] - b) <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    char ch, res;
    cin >> ch;
    if (ch == 'A') {
        res = 'T';
    } else if (ch == 'T') {
        res = 'A';
    } else if (ch == 'C') {
        res = 'G';
    } else if (ch == 'G') {
        res = 'C';
    }
    cout << res;
}

Measured memory_bytes: 256
n,ma,mb=map(int,input().split())
A=[]
for i in range(n):
  a,b,c=map(int,input().split())
  A.append([a,b,c])
DP=[[[float("inf")]*(10*n+1) for _ in range(10*n+1)] for _ in range(n+1)]
DP[0][0][0]=0
for i in range(n):
  a,b,c=A[i][0],A[i][1],A[i][2]
  for j in range(10*(i+1)+1):
    for k in range(10*(i+1)+1):
      if j>=a and k>=b:
        DP[i+1][j][k]=min(DP[i][j-a][k-b]+c,DP[i][j][k])
      else:
        DP[i+1][j][k]=DP[i][j][k]
ans=float("inf")
for i in range(10*n+1):
  for j in range(10*n+1):
    if i*mb==j*ma and i*j!=0:
      ans=min(ans,DP[n][i][j])
print(ans if ans!=float("inf") else -1)

Measured memory_bytes: 145628