akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

struct Perm : vector<int> {
    using vector<int>::vector;
    Perm() {}
    Perm(initializer_list<int> list) : vector<int>(list) {}

};

Perm& operator*=(Perm& a, const Perm& b) {
    assert(a.size() == b.size());
    int n = a.size();
    Perm _a(a);
    for (int i = 0; i < n; i++) {
        a[i] = _a[b[i]];
    }
    return a;
}
Perm operator*(const Perm& a, const Perm& b) {
    assert(a.size() == b.size());
    int n = a.size();
    Perm c(n);
    for (int i = 0; i < n; i++) {
        c[i] = a[b[i]];
    }
    return c;
}
Perm pinv(const Perm& a) {
    int n = a.size();
    Perm c(n);
    for (int i = 0; i < n; i++) {
        c[a[i]] = i;
    }
    return c;
}
Perm& operator/=(Perm& a, const Perm& b) {
    return a *= pinv(b);
}
Perm operator/(const Perm& a, const Perm& b) {
    return a * pinv(b);
}
Perm ppow(Perm a, int64_t e) {
    if (e < 0) {
        a = pinv(a);
        e *= -1;
    }
    int n = a.size();
    Perm c(n);
    iota(c.begin(), c.end(), 0);
    for (; e; e>>=1) {
        if (e&1) c *= a;
        a *= a;
    }
    return c;
}
int cycles_cnt(Perm a) {
    int cnt = 0, n = a.size();
    for (int i = 0; i < n; i++) {
        if (~a[i]) {
            cnt++;
            for (int j = i; ~a[j];) {
                int nxt = a[j];
                a[j] = -1;
                j = nxt;
            }
        }
    }
    return cnt;
}

void solve() {
    int n, k;
    cin >> n >> k;
    Perm p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
        q[i]--;
    }
    Perm ip = pinv(p);
    Perm iq = pinv(q);
    int exp = (k-1) / 6;
    int rem = (k-1) % 6;
    Perm base = q*ip*iq*p;
    Perm lhs = ppow(base, exp);
    Perm rhs = pinv(lhs);
    Perm mid;
    if      (rem == 0) mid = p;
    else if (rem == 1) mid = q;
    else if (rem == 2) mid = q*ip;
    else if (rem == 3) mid = q*ip*iq;
    else if (rem == 4) mid = q*ip*iq*p*iq;
    else if (rem == 5) mid = q*ip*iq*p*p*iq;
    Perm res = lhs * mid * rhs;
    for (int i = 0; i < n; i++) {
        cout << res[i]+1 << ' ';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 5104
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a >= 1 && a <= 9)
		{
			if(b >= 1 && b <= 9)
			{
				int answer = a * b;
				System.out.println(answer);
			}

			else
				System.out.println("-1");
		}

		else
			System.out.println("-1");

	}
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    ll ans = INF;
    REP(i, S.length()) {
        ll m = 0;
        REP(j, T.length()) {
            if (j + i >= S.length()) {
                m = INF;
                break;
            }
            if (T[j] == S[i + j])
                continue;
            m++;
        }
        ans = std::min(ans, m);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int n;
    cin >> n;
    vector<Int> x(n);
    map<Int, Int> m;
    REP(n,i){
        cin >> x.at(i);
    }
    vector<Int> wa(n+1);
    wa.at(0) = 0;
    REP(n,i){
        wa.at(i+1) = wa.at(i) + x.at(i);
        m[wa.at(i+1)]++;
    }
    Int ans = 0;
    for (auto z : m){
        Int p = z.second;
        if (z.first == 0) p++;
        ans += p *( p - 1) / 2;
    }
    cout << ans << endl;
}




Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//Micro Futures scalping to get my tendies
int main(){
	int n; cin>>n;
	string s; cin>>s;
	int j = 0; int cc = 0;
	for(int i = s.size()-1; i >= 0; i--){
		if(i <= j) break;
		if(s[i] == 'R'){
			//cout<<"me\n";
			while(s[j] != 'W' && (j < n-1)) j++;
			if(i <= j) break;
			if(s[j] == 'W') {
				s[j] = 'R';
				s[i] = 'W';
				cc++;
				//cout<<j<<" ";
			}
		}
	//	else break;
	}
	//cout<<s<<"\n";
	int ind = -1;
	for(int i = s.size()-1; i >= 0; i--){
		if(s[i] == 'R') {
			ind = i;
			break;
		}
	}
	if(ind != -1){
		for(int i = 0; i < s.size(); i++){
			if((s[i] == 'W') && (i < ind)) cc++;
		}
	}
	cout<<cc<<"\n";
}

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

int main() {
   int n, l;
   cin >> n >> l;
   vector<string> s(n);
   for (int i=0; i<n; i++) cin >> s.at(i);
   
   sort(s.begin(), s.end());
   
   for (int i=0 ; i<n; i++) cout << s.at(i);
   cout << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n;
long long arr[100005];
long long temp[100005];
void copy_arr(){
	for(int i=1; i<=n; i++) temp[i] = arr[i];
	return;
}
long long solve(bool pos){
	long long ret = 0;
		for(int i=2; i<=n; i++){
			temp[i]+=temp[i-1];
			if((i%2)^(!pos)){ //양수 
				if(temp[i]>0) continue;
				else{
					ret+=1-temp[i];
					temp[i] = 1;
				}
			}
			else{ //음수  
				if(temp[i]<0) continue;
				else{
					ret+=temp[i]+1;
					temp[i] = -1;
				}
			}
		}
	return ret;
}
int main(){
	cin>>n;
	for(int i=1; i<=n; i++) cin>>arr[i];
	copy_arr();
	if(arr[1]>0){
		long long ret1 = solve(1);
		copy_arr();
		long long ret2 = arr[1]+1;
		temp[1] = -1;
		ret2+=solve(0);
		cout<<min(ret1,ret2);
	}
	else if(arr[1]==0){
		long long ret1 = 1;
		temp[1] = 1;
		ret1+=solve(1);
		copy_arr();
		long long ret2 = 1;
		temp[1] = -1;
		ret2+=solve(0);
		cout<<min(ret1,ret2);
	}
	else{
		long long ret1 = solve(0);
		copy_arr();
		long long ret2 = (1-arr[1]);
		temp[1] = 1;
		ret2+=solve(1);
		cout<<min(ret1,ret2);
	}
}

Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())


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

    ll  s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe";
    else cout<<"safe";
}

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


typedef long long ll;


int main() {
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;

	vector<ll> p(A), q(B), r(C);
	for (int i = 0; i < A; ++i) cin >> p[i];
	for (int i = 0; i < B; ++i) cin >> q[i];
	for (int i = 0; i < C; ++i) cin >> r[i];

	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.rbegin(), r.rend());

	p.resize(X);
	q.resize(Y);

	// guard
	p.push_back(0);
	q.push_back(0);
	r.push_back(0);

	int x = 0, y = 0, z = 0, w = 0;
	ll ans = 0;
	while (X + Y) {
		ll red = p[x]; if (!X) red = 0;
		ll green = q[y]; if (!Y) green = 0;
		ll cless = r[z];
		
		ll mx = max(red, green); mx = max(mx, cless);
		if (mx == red) {
			ans += red; ++x; --X;
		} else if (mx == green) {
			ans += green; ++y; --Y;
		} else {
			ll a = p[x + X - 1]; if (!X) a = 1e10;
			ll b = q[y + Y - 1]; if (!Y) b = 1e10;

			ans += cless; ++z;
			
			if (a < b) --X;
			else --Y;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6056
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct s{
	char s[20];
	int p;
	int id;
}a[105];
bool cmp(s x,s y)
{
	if(strcmp(x.s,y.s)<0||(strcmp(x.s,y.s)==0&&x.p>y.p))return 1;
	else return 0;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a[i].s);
		scanf("%d",&a[i].p);
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		cout<<a[i].id<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop
import itertools

N = int(input())
A = np.array(input().split(), np.int64)

MOD = 10**9 + 7

ans = 0
for i in range(64):
    B = (A >> i) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y

    for _ in range(i):
        x *= 2
        x %= MOD

    ans += x
ans %= MOD
print(ans)


Measured memory_bytes: 62756
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        s: usize,
    }

    let mut dp = vec![0; s+10];
    dp[0]=1;

    for i in 0..s {
        for j in i+3..=s {
            dp[j] = (dp[j] + dp[i]) % MOD;
        }
    }
    println!("{}", dp[s]);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2156
#include<iostream>
#include<algorithm>
#define MAX_E 10000
#define MAX_N 100
using namespace std;
void init_union_find(int);
bool same(int ,int);
void unite(int,int);
struct edge{
  int u,v,cost;
  bool operator < (const edge& e) const{
    if(cost != e.cost) return cost < e.cost;
    else if(u != e.u) return u < e.u;
    else return v < e.v;
  }
};

ostream& operator << (ostream& os,const edge& e){
  os <<e.cost<<e.u<<e.v;
}

int E,n;
edge G[MAX_E];

int A[100][100];

int kruskal(){ 
  sort(G,G + E);
  init_union_find(n);
  int res =0;
  for(int i = 0; i < E; i++){
    edge e = G[i];
    if(!same(e.u,e.v)){
       res += e.cost;
       unite(e.u,e.v);
    }
  }

  return res;
}


int main(){
  cin >> n;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> A[i][j];
      if(A[i][j]==-1){
	continue;
      }
      G[E]=(edge){i,j,A[i][j]};
      E++;
    }
  }
  cout <<kruskal()<<endl;
}




int par[MAX_N] ,rank[MAX_N];

void init_union_find(int n){
for(int i=0;i<n;i++) {
    par[i]=i;
    rank[i]=0;
 }
}

int find(int x){
  if ( par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return;

  if(rank[x] < rank[y]){
    par[x] = y;
  }else {
    par[y] = x;
    if( rank[x] == rank[y]) rank[x]++;
  }
}
bool same(int x,int y){
  return find(x) == find(y);
}
    

Measured memory_bytes: 1312
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

int main() {
  size_t k;
  scanf("%zu", &k);

  char buf[101];
  scanf("%s", buf);
  std::string s = buf;
  size_t n = s.length();

  if (n <= k) {
    printf("%s\n", s.data());
  } else {
    printf("%s...\n", s.substr(0, k).data());
  }
}


Measured memory_bytes: 3280
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll k;cin>>k;
  ll ans=0;
  for(ll i=1;i<=k;i++){
    for(ll j=1;j<=k;j++){
      for(ll l=1;l<=k;l++){
        ans+=__gcd(__gcd(i,j),l);
      }
    }
  }
  cout<<ans<<endl;
}

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

int main(void){

    // cout << "aaaaa" << endl;
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    // cout << "aaa" << endl;
    vector<int> ans(N);
    for (int i=0; i<N; i++){
        // cout << "ans[" << A[i] << "] = " << i + 1 << endl;
        ans[A[i] - 1] = i + 1;
    }
    for(int i=0; i<N; i++){
        cout << ans[i];
        if(i < N - 1){
        cout << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#include<string>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
const ll mod=1e9+7;

bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}


void solve(){

    ll a;
    cin>>a;
    ll ans=0;
    ll coin500= a/500;
    ans += coin500*1000;

    a -= coin500*500;

    ans+= (a/5)*5;
    cout<<ans;

    return;
}

int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
 
    return 0;
}       

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

#define pi 3.141592653589
#define repeat(i,n) for(int i=0;i<n;i++)

int n;
int *x, *y;

void solve(int n)
{
	x = new int[n];
	y = new int[n];

	//2つのn次元ベクトルを形成
	repeat(i, n)
	{
		cin >> x[i];
	}
	repeat(i, n)
	{
		cin >> y[i];
	}

	//p=1(マンハッタン距離)
	double sum = 0;
	repeat(i, n)
	{
		sum += abs(x[i] - y[i]);
	}
	cout << fixed << setprecision(5) << sum << endl;

	//p=2(ユークリッド距離)
	sum = 0;
	repeat(i, n)
	{
		sum += pow(x[i] - y[i], 2);
	}
	cout << fixed << setprecision(5) << sqrt(sum) << endl;

	//p=3
	sum = 0;
	repeat(i, n)
	{
		sum += abs(pow(x[i] - y[i], 3));
	}
	cout << fixed << setprecision(5) << cbrt(sum) << endl;

	//p=∞(チェビシェフ距離)
	sum = 0;
	double max = 0;
	repeat(i, n)
	{
		if (abs(x[i] - y[i]) >= max) max = abs(x[i] - y[i]);
	}
	cout << fixed << setprecision(5) << max << endl;

	return;
}

int main()
{
	while (cin >> n)
	{
		solve(n);
	}
	return 0;
}

Measured memory_bytes: 1332
#include <stdio.h>

int main()
{
	int a,b;

	while(1)
	{
		int kai;
		int i = 1;
		int j = scanf("%d %d" , &a,&b);
		if(j==EOF) break;

		kai = a+b;

		while(kai > 9)
		{
			kai /= 10;
			i++;
		}

		printf("%d\n" , i);
	}
}

Measured memory_bytes: 1028
import math
N = int(input())
def make_prime_list_2(num):
    if num < 2:
        return []
    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def prime_factorization_2(num):
    if num <= 1:
        return {1: 1}
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1

        return dict_counter

dict = prime_factorization_2(N)
lst = list(dict.values())

res = 0
for i in range(1,(N//2)+1):
    for j in range(len(lst)):
        if lst[j] >= i:
            lst[j] = lst[j] - i
            res += 1
    if all(k <= i for k in lst):
        break

print(res)

Measured memory_bytes: 49340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 1e18
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n+2],b[m+2];
    ll u=0,w=0,ans=0,sum=0,inp;
    for(int i=1;i<=n;i++)
    {
    	cin>>inp;
    	sum+=inp;
    	a[i]=sum;
    	if(k>=a[i])
    	{
    		ans=i;
		}
	}
	sum=0;
	for(ll i=1;i<=m;i++)
	{
		cin>>inp;
		sum+=inp;
		b[i]=sum;
		if(k>=b[i])
		{
			ans=max(ans,i);
		}
	}
	u=1,w=m;
	ll temp;
	while(u<=n && w>0)
    {
        if(a[u]+b[w]<=k) 
        {
        	temp=u+w;
        	ans=max(ans,temp);
        	u++;
		}
		else
		{
			w--;
		}
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 6744
// finish date: 2018/12/22

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << B +  min(A + B + 1, C) << endl;


    return 0;
}



Measured memory_bytes: 256
N=int(input())
MOD=10**9+7
R=range(5)
dp=[[[[0,0,0,0,0] for i in R] for j in R] for k in range(N+1)]
dp[0][0][0][0]=1

#0:dammy 1:A 2:G 3:C 4:T
for x in range(N):
    for d in R:
        for c in R:
            for b in R:
                for a in range(1,5):
                    #a:X+1文字目、b:X-1文字目、...
                    if (c==1 and b==2 and a==3):
                        continue
                    if (c==2 and b==1 and a==3):
                        continue
                    if (c==1 and b==3 and a==2):
                        continue
                    if (d==1 and b==2 and a==3):
                        continue
                    if (d==1 and c==2 and a==3):
                        continue
                    dp[x+1][c][b][a]+=dp[x][d][c][b]
                    dp[x+1][c][b][a]%=MOD

ans=0
for c in range(1,5):
    for b in range(1,5):
        for a in range(1,5):
            ans+=dp[N][c][b][a]
            #print(c,b,a,dp[N][c][b][a])
            ans%=MOD

print(ans)

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

int main() {
  double ans;
  int N;
  cin >> N;
  vector<double> vect(N);
  for (int i = 0; i < N; i++){
    cin >> vect.at(i);
  }
  sort(vect.begin(), vect.end());
  ans = vect.at(0);
  for (int i = 0; i < N-1; i++) {
    ans = (ans + vect.at(i+1) )/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define MOD 1000000007
#define INF 1e9
#define sum(a) accumulate(begin(a), end(a), 0, [](int a, int b) {return a+b;})

using namespace std;
using ll = long long;

int gcd(ll A, ll B) {
    if (B == 0) return A;
    return gcd(B, A % B);
}

int main() {
    ll A, B;
    cin >> A >> B;
    ll lcm = A * B / gcd(A,B);
    cout << lcm << endl;
}



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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> Zalgorithm(const string &S) {
	int N = S.size();
	vector<ll> res(N);
	res[0] = N;
	int i = 1, j = 0;
	while(i<N){
		while(i+j<N && S[j]==S[i+j]) ++j;
		res[i] = j;
		if(j==0){++i;continue;}
		int k=1;
		while(i+k<N && k+res[k]<j) res[i+k] = res[k], ++k;
		i += k, j -= k;
	}
	return res;
}

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

	int N=in();
	string S=in<string>();

	ll res = 0;
	for(int i=0,ei=S.size();i<ei;i++){
		string T = S.substr(i);
		auto lcp = Zalgorithm(T);
		for(ll j=0,ej=lcp.size();j<ej;j++){
		res = max(res,min(lcp[j],j));
		}
	}

	out(res);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
long long int fact(int in){
    long long int ret=in;
    for(int i=1;i<in-1;i++){
        ret*=in-i;
        if(ret>=1000000007){
            ret%=1000000007;
        }
    }
    return ret;
}
int main(){
    int n,m;
  cin>>n>>m;
    long long int a;
    if(n==m){
        a=2*fact(n)*fact(m);
    }else if((n==m-1)||(m==n-1)){
        a=fact(n)*fact(m);
    }else{
        a=0;
    }
    if(a>=1000000007){
        a=a%1000000007;
    }
    cout<<a<<endl;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
    char T;
    while (cin >> T && T != '#') {
        vector<int64> r[4];
        vector<char> s[4];
        REP(i, 4) {
            r[i].resize(13); s[i].resize(13);
            REP(j, 13) {
                char a;
                cin >> a >> s[i][j];
                if ('2' <= a && a <= '9') {
                    r[i][j] = a-'0';
                } else {
                    switch (a) {
                        case 'T': r[i][j] = 10; break;
                        case 'J': r[i][j] = 11; break;
                        case 'Q': r[i][j] = 12; break;
                        case 'K': r[i][j] = 13; break;
                        case 'A': r[i][j] = 14; break;
                    }
                }
            }
        }
        int64 lead = 0;
        int32 res[2] = {};
        res[0] = res[1] = 0;
        REP(i, 13) {
            char lc = s[lead][i];
            char nc = s[lead][i]; int64 rank = r[lead][i];
            int64 now = lead;
            REP(j, 4) {
                if (nc == T) {
                    if (s[j][i] == T && rank < r[j][i]) {
                        rank = r[j][i];  now = j;
                    }
                } else {
                    if (s[j][i] == T) {
                        rank = r[j][i]; now = j;
                        nc = s[j][i];
                    } else if (s[j][i] == nc && r[j][i] > rank) {
                        rank = r[j][i]; now = j;
                    }
                }
            }
            res[now%2]++;
            lead = now;
        }
        cout << (res[0] > res[1] ? "NS" : "EW") << " " << max(res[0], res[1]) - 6 << endl;
    }
}




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

const int maxn = int(1e5)+5;

int n, m, suff[maxn], pref[maxn];

bool f(int x)
{
	for(int i = 1;i < m;i++)
	{
		//cout << i << " " << pref[i] << " " << suff[i+1] << "\n";
		if(pref[i] < x && suff[i+1] < x) return false;
	}
	return true;
}

int main(void)
{
	string S;
	cin >> S;
	n = int(S.size());

	pair<int, int> cur = {1, int(S[0]-'0')};

	vector<int> A;
	A.push_back(0);
	for(int i = 1;i < n;i++)
	{
		if(int(S[i]-'0') == cur.second) cur.first++;
		else
		{
			A.push_back(cur.first);
			cur = {1, int(S[i]-'0')};
		}
	}

	A.push_back(cur.first);

	m = int(A.size())-1;
	//cout << m << "\n";
	for(int i = 1;i <= m;i++) pref[i] = A[i]+pref[i-1];
	for(int i = m;i > 0;i--) suff[i] = A[i]+suff[i+1];

	int L = 1, R = n, ans = 0;
	while(L <= R)
	{
		int mid = (L+R)/2;
		//cout << mid << "\n";
		if(f(mid)) L = mid+1, ans = mid;
		else R = mid-1;
	}
	printf("%d\n", ans);
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const int Max_N=15;
const int Max_M=1e3+5;
int c[Max_M][Max_N];
const int INF=1e9;

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M);
	rep(i,M){
		cin >> a[i] >> b[i];
		rep(j,b[i]) cin >> c[i][j];
		rep(j,b[i]) c[i][j]--;
	}
	vector<int> dp(1<<N,INF);
	dp[0]=0;
	rep(bit,1<<N){
		rep(i,M){
			int bit_next=bit;
			rep(j,b[i]) if(!(bit&1<<c[i][j])) bit_next+=1<<c[i][j];
			dp[bit_next]=min(dp[bit_next],dp[bit]+a[i]);
		}
	}
	if(dp[(1<<N)-1]==INF) cout << -1 << endl;
	else cout << dp[(1<<N)-1] << endl;

	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int solve(int n)
{
  const lli mod = 1000000000 + 7;
  lli m = 1;
  for (int i = 0; i < n / 2; ++i) {
    m *= 2;
    m %= mod;
  }
  return m;
}

int main(int argc, char *argv[])
{
  int n;
  while (scanf("%d", &n) == 1) {
    int a[n];
    for (int i = 0; i < n; ++i) {
      scanf("%d", a + i);
    }
    map<int, int> cnt;
    for (int i = 0; i < n; ++i) {
      ++cnt[a[i]];
    }
    bool f = true;
    if (n % 2) {
      int x = 2;
      for (int i = 0; i < n / 2; ++i) {
        f = (cnt[x] == 2);
        x += 2;
      }
      f = (cnt[0] == 1);
    } else {
      int x = 1;
      for (int i = 0; i < n / 2; ++i) {
        f = (cnt[x] == 2);
        x += 2;
      }      
    }
    printf("%d\n", f ? solve(n) : 0);
  }
  
  return 0;
}


Measured memory_bytes: 4480
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);

    rep(i, N){
        cin >> A.at(i);
        if(A.at(i) % 2 == 0 && (A.at(i) % 3 != 0 && A.at(i) % 5 != 0)){
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << endl;
}



Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H, N, A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> N;
	rep(i, 0, N) cin >> A[i];

	int tot = 0;
	rep(i, 0, N) tot += A[i];

	if (H <= tot) cout << "Yes" << endl;
	else cout << "No" << endl;
}







Measured memory_bytes: 640
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0

for l in range(k + 1):
	for r in range(k - l + 1):
		hand = []
		if l + r > n:
			break
        #handに左からl個
		hand = v[: l]
        #右からr個の要素を追加
		hand.extend(v[n - r:])
        #現時点でのhandの和をhand_sum
		hand_sum = sum(hand)  
		hand.sort()
        #hand_sum中の負の要素を詰めていく
		for i in range(min(k - l - r, l + r)):
			if hand[i] < 0:
			  hand_sum -= hand[i]
		ans = max(ans, hand_sum)

print(ans)

Measured memory_bytes: 3064
import sys
from fractions import gcd


def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for i in range(h)]

    ans = []

    for i in range(h):
        if i % 2 == 0:
            for j in range(w - 1):
                if a[i][j] % 2 == 1:
                    ans.append((i+1, j+1, i+1, j+2))
                    a[i][j+1] += 1
            
            if i != h - 1 and a[i][w-1] % 2 == 1:
                ans.append((i+1, w, i+2, w))
                a[i+1][w-1] += 1
        else:
            for j in range(w - 1, 0, -1):
                if a[i][j] % 2 == 1:
                    ans.append((i+1, j+1, i+1, j))
                    a[i][j-1] += 1
            
            if i != h - 1 and a[i][0] % 2 == 1:
                ans.append((i+1, 1, i+2, 1))
                a[i+1][0] += 1
    
    print(len(ans))
    for ansi in ans:
        print(*ansi)


if __name__ == '__main__':
    main()


Measured memory_bytes: 30340
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

struct Point {
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
};

int n, h, w;
Point a[MAXN];
ll dp[MAXN], f[MAXM], rev[MAXM];

ll mu(ll a, ll b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    ll g = mu(a, b/2);
    if (b % 2) return g * g % MODBASE * a % MODBASE;
    return g * g % MODBASE;
}

ll C(int n, int k) {
    if (k < 0 || k > n) return 0;
    return f[n] * rev[n-k] % MODBASE * rev[k] % MODBASE;
}

ll get(int x, int y, int u, int v) {
    int g = u - x + 1, h = v - y + 1;
    return C(g + h - 2, g - 1);
}

ll solve(int u) {
    if (dp[u] != -1) return dp[u];
    ll res = get(1,1,a[u].x,a[u].y);
    FOR(i,1,n)
        if (i != u)
            if (a[i].x <= a[u].x && a[i].y <= a[u].y) {
                res = (res - solve(i) * get(a[i].x,a[i].y,a[u].x,a[u].y) % MODBASE + MODBASE) % MODBASE;
            }
    return dp[u] = res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    f[0] = 1;
    rev[0] = mu(f[0], MODBASE-2);
    FOR(i,1,200000) {
        f[i] = f[i-1] * i % MODBASE;
        rev[i] = mu(f[i], MODBASE-2); 
    }
    cin >> h >> w;
    cin >> n;
    FOR(i,1,n) cin >> a[i].x >> a[i].y;
    n++; a[n].x = h; a[n].y = w;
    FOR(i,1,n) dp[i] = -1;
    cout << solve(n);
    return 0;
}


Measured memory_bytes: 3456
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,K;
  cin>>N>>K;
  ll max=0;
  ll min=0;
  ll ans=0;
  FOR(i,0,K){
    min+=i;
    max+=N-i;
  }
  ans+=max-min+1;
  FOR(i,K,N+1){
    min+=i;
    max+=N-i;
    ans+=max-min+1;
    ans%=mod;
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 3692
using System;
using System.Collections.Generic;
using System.Linq;

class CountOrder
{
    static void Main(string[] args)
    {

        var input =int.Parse( Console.ReadLine());

        var x = Enumerable.Range(1, input).ToArray();
        var p = AllPermutation(x);

        string[] start = Console.ReadLine().Split(' ');
        string[] end = Console.ReadLine().Split(' ');

        var a = 0;
        for(int i = 0;i < p.Count; i++)
        {
            var ok = true;
            for(int j = 0; j < input; j++)
            {
                if (int.Parse(start[j]) != p[i][j]) ok = false;
            }
            if (ok)
            {
                a = i;
                break;
            }
        }

        var b = 0;
        for (int i = 0; i < p.Count; i++)
        {
            var ok = true;
            for (int j = 0; j < input; j++)
            {
                if (int.Parse(end[j]) != p[i][j]) ok = false;
            }
            if (ok)
            {
                b = i;
                break;
            }
        }


        Console.WriteLine("{0}",Math.Abs(a-b));
    }

    static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable
    {
        var a = new List<T>(array).ToArray();
        var res = new List<T[]>();
        res.Add(new List<T>(a).ToArray());
        var n = a.Length;
        var next = true;
        while (next)
        {
            next = false;

            // 1
            int i;
            for (i = n - 2; i >= 0; i--)
            {
                if (a[i].CompareTo(a[i + 1]) < 0) break;
            }
            // 2
            if (i < 0) break;

            // 3
            var j = n;
            do
            {
                j--;
            } while (a[i].CompareTo(a[j]) > 0);

            if (a[i].CompareTo(a[j]) < 0)
            {
                // 4
                var tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                Array.Reverse(a, i + 1, n - i - 1);
                res.Add(new List<T>(a).ToArray());
                next = true;
            }
        }
        return res;
    }

}

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

const ll MOD = 1e9+7;

int main(){
	string s;
	cin >> s;
	
	int c[s.size()] = {0};
	
	rep(i,s.size()){
		if(s[i] == '?') c[i] = -1;
		else c[i] = s[i] - '0';
	}
	
	ll dp[s.size()][13] = {0};
	if(c[0]!=-1) dp[0][c[0]] = 1;
	else{
		rep(i,10) dp[0][i] = 1;
	}
	
	
	for(int i=1;i<s.size();i++){
		rep(j,13){
			if(c[i]!=-1){
				dp[i][(j*10+c[i])%13] += dp[i-1][j];
				dp[i][(j*10+c[i])%13] %= MOD;
			}
			else{
				rep(k,10){
					dp[i][(j*10+k)%13] += dp[i-1][j];
					dp[i][(j*10+k)%13] %= MOD;
				}
			}
		}
	}
	
	cout << dp[s.size()-1][5] << endl;
	return 0;
}

Measured memory_bytes: 11008
#pragma GCC optimize ("-O3","unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<typeinfo>
#include<typeindex>
#include<type_traits>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep1(i,n) for(int(i)=0; i<n; i++)
#define rep(i,n) for(unsigned int(i)=0; i!=n; ++i)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define var(type) valarray<type>
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T,class F>
struct SegTree{
	V(T) seg;
	int size;
	const F f;
	const T ini;

	SegTree(const V(T)& d,F f,T ini):f(f),ini(ini){
		int n=d.size();
		size=1;
		while(size<n)size<<=1;
		seg.resize(size*2-1,ini);
		rep(i,n)seg[i+size-1]=d[i];
		gnr(i,0,size-2)upd(i);
	}

	void upd(int i){
		seg[i]=f(seg[i*2+1],seg[i*2+2]);
	}

	void set(int i,T t){
		i+=size-1;
		seg[i]=t;
		while(i){
			i=(i-1)/2;
			upd(i);
		}
	}

	T get(int a,int b,int i,int l,int r){
		if(r<0)r=size;
		if(b<=l||r<=a)return ini;
		if(a<=l&&r<=b)return seg[i];
		int mid=(l+r)/2;
		return f(get(a,b,i*2+1,l,mid),get(a,b,i*2+2,mid,r));
	}

	T get(int a,int b){
		return get(a,b,0,0,-1);
	}

  T operator[](const int &i)const{
    return seg[i+size-1];
  }
};
template<class T,class F>
SegTree<T,F> segtree(const V(T)& d,F f,T ini){
	return SegTree<T,F>(d,f,ini);
}

template<class T,class F>
struct LazySegTree{
};
template<class T,class F>
LazySegTree<T,F> lsegtree(const V(T)&d,F f,T ini){

}

int n,m,_,x,y,q,key;
string s,sb;
bool ok;

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

	cin>>n>>q; V(int)a(n,INF32);
	auto seg=segtree(a,[](int x,int y){return min(x,y);},INF32);
	rep(i,q){
		cin>>m>>x>>y;
		if(m)pri1(seg.get(x,y+1));
		else seg.set(x,y);
	}
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int a,b;
    cin >> a >> b;
    if(a > 8 || b > 8) pr(":(");
    else pr("Yay!");
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    if(n>=k){
        if(n%k!=0)
        cout<<k*(n/k+1)-n;
        else cout<<0;
    }
    else cout<<min(n,abs(n-k));
    return 0;
}

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

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


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

const int N=1e5+5;
const int mod=1e9+7;
int32_t main() {
    IOS
int n,ans=0;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        int a;
        cin>>a;
        if(a%2==0){
            while(a%2==0)a/=2,ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = list(map(int,input().split()))

C = defaultdict(int)

ans = 0
sumA = 0
for a in A:
    sumA += a
    C[sumA] += 1
    if C[sumA] >=2:
        ans += C[sumA]-1
        
for i in range(1,C[0]+1): ans+= 1
    
print(ans)

Measured memory_bytes: 39296
#include <iostream>

using namespace std;



int main()
{

    int d_map[6][6] = { { -1, 2, 4, 1, 3,-1 },
                        {  3,-1, 0, 5,-1, 2 },
                        {  1, 5,-1,-1, 0, 4 },
                        {  4, 0,-1,-1, 5, 1 },
                        {  2,-1, 5, 0,-1, 3 },
                        { -1, 3, 1, 4, 2,-1} };

    int nums[6];
    for(int i = 0; i < 6; i++)
    {
        cin >> nums[i];
    }

    int N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        int top, front;
        cin >> top >> front;

        int top_index;
        for(top_index = 0; top_index < 6; top_index++)
        {
            if(nums[top_index] == top){ break; }
        }
        int front_index;
        for(front_index = 0; front_index < 6; front_index++)
        {
            if(nums[front_index] == front){ break; }
        }
        cout << nums[d_map[top_index][front_index]] << endl;

    }
    return 0;
}

Measured memory_bytes: 3064
# include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if (a%2 == 0) {
        cout << "Even" << endl;
    }else if (b%2 == 0) {
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }
    return 0;
}

Measured memory_bytes: 256