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

void chmin(int& a, int b){
    a = min(a, b);
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int pop_count(int bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int64_t msb(int64_t v){
  v = v | (v >>  1);
  v = v | (v >>  2);
  v = v | (v >>  4);
  v = v | (v >>  8);
  v = v | (v >> 16);
  v = v | (v >> 32);
  return v ^ (v >> 1);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    const int INF = 1e9;
    vector<vector<int>> dp(1<<N, vector<int>(N, INF));
    for(int i=0; i<N; i++) dp[1<<i][i] = 0;
    
    for(int b=0; b<(1<<N); b++) for(int last=0; last<N; last++){
        if(dp[b][last] == INF) continue;
        int cnt = pop_count(b);
        int v1 = ((cnt-last+1)%2 ? B[last] : A[last]);
        int cost = cnt;
        for(int nxt=0; nxt<N; nxt++){
            if(nth_bit(b, nxt)){
                cost--;
                continue;
            }
            int v2 = ((cnt-nxt)%2 ? B[nxt] : A[nxt]);
            if(v1 > v2) continue;
            int b2 = b + (1<<nxt);
            chmin(dp[b2][nxt], dp[b][last] + cost);
        }
    }
    int ans = INF;
    for(int k=0; k<N; k++) chmin(ans, dp[(1<<N)-1][k]);
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26880
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut sum = n;
    let mut result = 0;
    while sum > 0 {
        sum /= k;
        result += 1;
    }

    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
	int n, ans = 0;
	scanf("%d", &n);
	for(int i = 1;i <= n;i++){
		int a;
		scanf("%d", &a);
		if(i % 2 == 1 && a % 2 == 1) ans++;
	}
	printf("%d\n", ans);
	return 0;
}
//ios_base::sync_with_stdio(false);


Measured memory_bytes: 3760
#include <iostream>

using namespace std;
typedef long long ll;
int w[105];
int v[105];
ll dp[105][100005];

int main() {
    int n, W;
    cin >> n >> W;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> v[i];
    }
    for (int j = 0; j <= W; ++j) {
        dp[0][j] = 0;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < w[i]; ++j) dp[i][j] = dp[i - 1][j];
        for (int j = w[i]; j <= W; ++j) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
    }
    cout << dp[n][W] << endl;
}


Measured memory_bytes: 80128
from collections import defaultdict
from heapq import heappop, heappush

N = int(input())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = map(int, input().split())

graph = defaultdict(set)
for v, w, c in edges:
    graph[v].add((w, c))
    graph[w].add((v, c))

dp = [-1] * (N + 1)
pq = []

# Initialization
dp[K] = 0
heappush(pq, (0, K))

while pq:
    cost, u = heappop(pq)
    
    for w, c in graph[u]:
        if dp[w] > -1:
            continue

        dp[w] = dp[u] + c
        heappush(pq, (dp[w], w))

for _ in range(Q):
    x, y = map(int, input().split())
    print(dp[x] + dp[y])


Measured memory_bytes: 124888
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
long bignum = 1_000_000_007;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto N = lread();
    foreach (h; 1 .. 3501)
    {
        foreach (n; 1 .. 3501)
        {
            auto molecular = N * h * n;
            auto denominator = 4 * h * n - (n + h) * N;
            if (denominator < 1)
                continue;

            if (molecular % denominator == 0)
            {
                writef("%s %s %s", h, n, molecular / denominator);
                writeln();
                return;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>

#include<math.h>

#include<stdio.h>

#include<string.h>

#include<vector>

#include<algorithm>



typedef long long ll;

#define rep0(i, n) for(int i=0; i < (int)(n); i++)

#define rep1(i, n) for(int i=1; i < (int)(n); i++)

#define all(x) (x).rbegin(),(x).rend()

#define fill(x,y) memset(x,y,sizeof(x))

#define debug1(i) cout << i << '\n'

#define debug2(i,j) cout << i << j << '\n'

#define MAX 1<<20



using namespace std;


long long N, M, L, r, s;
long long p[MAX], q[MAX];
double d, e, f, g, h;
vector<long long > vec1, vec2;



int main() {
	cin >> N >> M >> L;
	for (int i =1 ; i<= 100 ;i++) {
		if (N%i == 0 && M%i == 0) {
			vec1.push_back(i);
		}
	}
	sort(all(vec1));
	cout << vec1[L - 1];
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
using namespace std;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;


int main(){
	int N;
	cin>>N;
	int cnt = 0;
	for(int i = 0; i <= N; i++){
		if((int)floor((log10(i)+1)) % 2 != 0)cnt++; 
	}
	cout<<cnt<<endl;
}

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

void knapsack(int W, int wt[], int val[], int n) 
{ 
   int i, w; 
   long long K[n+1][W+1]; 
  
   for (i = 0; i <= n; i++)
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   cout << K[n][W] << endl;
}

int main()
{
  int n, w;
  cin >> n >> w;
  
  int val[n], wt[n];
  for(int i = 0; i < n; i++)
    cin >> wt[i] >> val[i];
  
  knapsack(w, wt, val, n);
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v.at(i);
  int a = 0, b = 0;
  sort(ALL(v), greater<int>());
  rep(i, n){
    if(i % 2 == 0) a += v.at(i);
    else b += v.at(i);
  }
  cout << a-b << endl;
  return 0;
}

Measured memory_bytes: 3552
import numpy as np
from numba import jit

R, C, K = map(int, input().split())
G = np.zeros((R+1, C+1), np.int64)
for i in range(K):
    [r, c, v] = list(map(int, input().split()))
    G[r-1][c-1] = v

@jit
def main(G, R, C):
    dp = np.full((R+1, C+1, 4), -1)
    dp[0][0][0] = 0
    if G[0][0] != None: dp[0][0][1] = G[0][0]
    for r in range(R):
        for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
    return(max(dp[r][c]))

ret = main(G, R, C)
print(ret)            


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

int main(){
    int A=0,B=0,K=0,i=0,count=0;
    cin >> A >> B >> K;
    int a[100]={};
    for(i=1;i<=100;i++){
        if(A%i==0&&B%i==0){count++;a[count-1]=i;}
    }
    cout << a[count-K] << endl;
    return 0;
}

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

int main() {
	long long int n,f=1;
	int ara[100000];
	cin>>n;
	//n=n-1;
	int k=0;
	while(n!=0){
		n=n-1;
		int g=n%26;
		/*if (g==0){
			g=26;
			n=n/26;
		}*/
		ara[k]=g;
		k++;
		n=n/26;
	}
	for (int i=k-1;i>=0;i--){
		printf("%c",ara[i]+'a');
	}
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n, k;
	cin>>n>>k;
	vector<long long int> h(n);
	for(int i=0; i<n; i++) cin>>h[i];
	vector<long long int> dp(n, 0);
	for(int  i=1; i<n; i++){
		dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
		for(int j=1; j<=k; j++){
			if(i-j < 0) break;
			dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
S = list(input())
R, G, B = [0]*N, [0]*N, [0]*N
rg_set = {("R", "G"), ("G", "R")}
rb_set = {("R", "B"), ("B", "R")}
for i in range(N):
    R[i] += R[i-1] + (1 if S[i] == "R" else 0)
    G[i] += G[i-1] + (1 if S[i] == "G" else 0)
    B[i] += B[i-1] + (1 if S[i] == "B" else 0)
ans = 0
for i in range(N-3):
    for k in range(i+3, N):
        if S[i] != S[k]:
            if (i+k)%2 == 0:
                j = (i+k)//2
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i] - (1 if S[j] == "B" else 0)
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i] - (1 if S[j] == "G" else 0)
                else:
                    ans += R[k] - R[i] - (1 if S[j] == "R" else 0)
            else:
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i]
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i]
                else:
                    ans += R[k] - R[i]
print(ans)


Measured memory_bytes: 69128
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int n,i;
	long int pay;
	long int sum = 0;


	scanf("%i",&n);
	for (i = 0; i < n; ++i) {
		scanf("%ld",&pay);
		if (pay <= 1000000) {
			sum += pay;
		}
	}
	printf("%ld\n", sum / n);
	return 0;
}

Measured memory_bytes: 596
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N, M;
    cin >> N >> M;
    V v(N);
    rep(i, N)cin >> v[i];
    ll sum = 0;
    rep(i, N)sum += v[i];
    sort(v.begin(), v.end(), greater<ll>());
    if(v[M - 1] * 4 * M >= sum)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

#define loop(n) for(int ii = 0; ii<n; ii++)

using namespace std;

long long expect[200010];
long long sum[200010];

int main(){
    int k,n,p[200010];

    cin >> n >> k;
    loop(n){
        cin >> p[ii];
    }

    sum[0] = 0;
    loop(n){
        sum[ii + 1] = sum[ii] + p[ii];
    }

    loop(n-k+1){
        expect[ii] = sum[ii+k] - sum[ii];
    }
    

    sort(expect,expect+n-k+1);
    reverse(expect,expect+n-k+1);

    double ans = (expect[0] + k)/2.;
    printf("%10f",ans);

}

Measured memory_bytes: 4096
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 500001;
//
//

ll n,q;
vector<int> tree[4*MAX+5];
// int arr[MAX+5];
string str;
int count(vector<int>& store){
    int cnt = 0;
    for(int i = 0; i < 26; i++)
        cnt += (store[i] > 0);
    return cnt;
}

void build(int node, int begin , int end){
    if(begin==end){
        tree[node][str[begin] - 'a']++;
    }
    else{
        int mid = (begin + end)>>1;
        build(2*node, begin, mid);
        build(2*node+1, mid+1, end);

        for(int i = 0; i < 26; i++)
            tree[node][i] = tree[node*2][i] + tree[2*node+1][i];
    }
}
void update(int node, int start , int end, int idx , char ch){
    if (start==end){
        if(start != idx)
            return ;
        tree[node][str[start]-'a']--;
        tree[node][ch - 'a']++;
        str[start] = ch;
    }
    else{
        int mid=(start+end)>>1;
        if(start<=idx && idx<=mid)
            update(2*node,start,mid,idx, ch);
        else
            update(2*node+1,mid+1,end,idx, ch);


        for(int i = 0; i < 26; i++)
            tree[node][i] = tree[node*2][i] + tree[2*node+1][i];
    }
}
vector<int> query(int node, int tl, int tr, int l, int r) {
    if (l == tl and r == tr) {
        return tree[node];
    }
    int tm=(tl+tr)>>1;
    if(r<=tm)
            return query(2*node,tl,tm,l,r);
    else if(l>tm)
           return  query(2*node+1,tm+1,tr,l,r);
    else
    {
        vector<int> fst = query(node*2, tl, tm, l, tm);
        vector<int> snd = query(node*2+1, tm+1, tr, tm+1, r);
        vector<int> temp(26, 0);
        for(int i = 0; i < 26; i++)
            temp[i] = fst[i] + snd[i];
        return temp;
    }
}
void solve(){
    int n;
    cin>>n>>str;
    int q;
    cin>>q;
    for(int i = 0; i < 4*n+1; i++)
        tree[i].resize(26);
    build(1, 0, n-1);
    while(q--){
        int type;
        cin>>type;
        if(type == 1){
            int idx;
            char ch;
            cin>>idx>>ch;
            --idx;
            update(1, 0, n-1, idx, ch);
        }
        else{
            int fst, snd;
            cin>>fst>>snd;
            --fst, --snd;
            vector<int> temp = query(1, 0, n-1, fst, snd);
            // for(int i : temp)
            //     cout<<i<<" ";
            cout<<count(temp)<<"\n";
            // cout<<query(1, 0, n, fst, snd)<<"\n";
        }
    }
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 269432
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

int n;
int a[MAXN];

void read()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
}

void solve()
{
	int answer = (int)1e9;
	for(int v = -100; v <= 100; v++)
	{
		int curr = 0;
		for(int i = 0; i < n; i++)
			curr += (v - a[i]) * (v - a[i]);
		chkmin(answer, curr);
	}

	cout << answer << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef TEST
#include <mytest.h>
#else
#define open(...) 0
#define print(...) 42
#endif
using namespace std;
namespace io {
  const int SZ = (1 << 22) + 1;
  char buf[SZ], *ptr = NULL, *bnd = NULL;
  #define GC() ((ptr == bnd) ? (ptr = buf, bnd = buf + fread(buf, 1, SZ, stdin), (ptr == bnd) ? EOF : (*(ptr++))) : (*(ptr++)))
  #define STATE(c) { if (c == '-') sgn = -1; else if (c == EOF) return false; }
  inline bool skip(const char& c) { return c < '0' || c > '9'; }
  template <class V>
  inline bool Read(V &v) {
    register char c, sgn = 1;
    while (skip(c = GC())) STATE(c);
    for (v = c - '0'; !skip(c = GC()); v = v * 10 + c - '0');
    return (v *= sgn), true;
  }
  char oBuf[SZ], *oCur = oBuf, *oBnd = oBuf + SZ, oStk[21], top = 0;
  inline void flush() { if (oCur - oBuf) fwrite(oBuf, 1, oCur - oBuf, stdout), oCur = oBuf; }
  inline void pc(char c) { *(oCur++) = c; if (oCur == oBnd) flush(); }
  template <class V>
  inline void Print(V v) {
    if (!v) return pc('0');
    if (v < 0) v = -v, pc('-');
    while (v) oStk[top++] = v % 10, v /= 10;
    while (top) pc(oStk[--top] + '0');
  }
  template <class V>
  inline void Println(const V& v) { Print(v), pc('\n'); }
  struct flusher { ~flusher() { flush(); } } __flusher__;
}
using io::Read;
using io::Println;
const int N = 1005;
int a[N][N];
bool vis[N];
int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  // cin >> n;
  Read(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < n; j++) {
      // cin >> a[i][j];
      Read(a[i][j]);
    }
    a[i][0] = 1;
  }

  int ans = 0, flg = 1, cnt = 0;
  while (flg) {
    flg = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (a[i][0] == n || vis[i]) continue;
      int t = a[i][a[i][0]];
      if (i == a[t][a[t][0]] && !vis[t]) {
        flg = 1;
        vis[i] = vis[t] = 1, cnt++;
        a[t][0]++, a[i][0]++;
      }
    }
    if (flg) ans++;
  }
  if (cnt != n * (n - 1) / 2) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 10112
#include <stdio.h>

int main(){
  int n,i,a[100001];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,a[i]);
    if((i/2)>=1){
      printf("parent key = %d, ",a[i/2]);
    }
    if((2*i)<=n){
      printf("left key = %d, ",a[2*i]);
    }
    if((2*i+1)<=n){
      printf("right key = %d, ",a[2*i+1]);
    }
      printf("\n");
  }

  return 0;
}



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

using namespace std;

int main(void){

    int n, count = 0, tmp = 0;
    vector<int> h;

    cin >> n;

    for(int i = 0;i < n;i++){
        int x;
        cin >> x;
        h.push_back(x);
    }

    for(int i = 0;i < n - 1;i++){
        if(h[i] >= h[i+1] && n-i >= count){
            for(int j = i;;j++){
                if(h[j] >= h[j+1] && j + 1 != n){
                    tmp++;
                }else{
                    if(count < tmp) count = tmp;
                    tmp = 0;
                    break;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}


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

int main(){
  int n;
  int list[5000];

  while(cin>>n){
    if(n==0){
      break;
    }

    int temp=0;
    int max;

    for(int i=0; i<n; i++){
      cin >> list[i];

      temp += list[i];
      if(i==0){
        max = list[i];
      }
      if(max<temp){
        max=temp;
      }
      if( temp<0 ){
        temp=0;
      }
    }

    cout << max << endl;
  }

  return 0;
}

Measured memory_bytes: 1176
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


class UnionFind():
    def __init__(self, n):
        self.par = [-1 for _ in range(n)]
        self.sizeDict = { i: 1 for i in range(n)}

    def unite(self, v1, v2):
        '''
        connect v2 to v1.

        parent: v1
        child: v2
        '''
        r1 = self.root(v1)
        r2 = self.root(v2)
        if r1 == r2:
            return
        self.par[r2] = r1
        self.sizeDict[r1] += self.sizeDict[r2]

    def root(self, v):
        if self.par[v] == -1:
            return v
        self.par[v] = self.root(self.par[v])
        return self.par[v]

    def sameRoot(self, v1, v2):
        return self.root(v1) == self.root(v2)

    def size(self, v):
        return self.sizeDict[self.root(v)]

def main():
    N, M = LI()
    edges = []
    for _ in range(M):
        a, b = LI_()
        edges.append((a, b))

    ans = [N*(N-1)//2]
    uf = UnionFind(N)
    for e in edges[::-1][:-1]:
        a, b = e[0], e[1]
        unconnected = uf.size(a) * uf.size(b)
        if uf.sameRoot(a, b):
            unconnected = 0
        ans.append(ans[-1] - unconnected)
        uf.unite(a, b)
    for a in ans[::-1]:
        print(a)
main()



Measured memory_bytes: 43876
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int s = INT_MAX;
    int l = INT_MIN;
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        s = min(s, tmp);
        l = max(l, tmp);
    }
    cout << l - s << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# 要はPPとDPが出てきたらダメ
# DDとPDはおk
# D?, P?
# ?D ,    ?P(これはどうあがいてもだめ)

# 基本的にはDを入れれば良さそうですね

T = read()[:-1]
print(T.replace('?', 'D'))


Measured memory_bytes: 9772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                if( A[i] == A[j] ) continue;
                if( A[i] == A[k] ) continue;
                if( A[j] == A[k] ) continue;
                if( A[i] >= A[j] + A[k]) continue;
                if( A[j] >= A[k] + A[i]) continue;
                if( A[k] >= A[i] + A[j]) continue;
                ans++;
            }
        }
    }
    ans = ans / 6;
    printf("%lld\n", ans);

}

Measured memory_bytes: 3720
import math

def calc_half(n):
  return int(n // 2)

def calc_surplus(n):
  return int(n % 2)

N = int(input())
str_A = input().split()
A_0 = [int(i) for i in str_A]
A = A_0

while list(map(calc_surplus, A)) == [0] * N:
  A = list(map(calc_half, A))
  
print(int(math.log(int(A_0[0] / A[0]), 2)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;




int main() 
{

 fast();
  
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt","w",stdout);
  // #endif
  
  ll n,a,b;
  cin>>n>>a>>b;
  cout<<min(n*a,b);


  


    




    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
O = input()
E = input()
dif_len = len(O) - len(E)
password = ''

if dif_len == 0:
    for i in range(len(O)):
        password += O[i] + E[i]
elif dif_len > 0:
    for i in range(len(O)):
        if i != len(O) - 1:
            password += O[i] + E[i]
        else:
            password += O[i]

print(password)

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

using namespace std;

int main() {
  string S; cin >> S;
  int ansNum = 1000;
  for(int i = 0; i < (int)S.size() - 2; i++) {
    ansNum = min(ansNum, abs(stoi(S.substr(i, 3)) - 753));
  }
  cout << ansNum << endl;
}


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

int main() {
    int n;
    while (cin >> n, n) {
        vector<pair<pair<int,int>, pair<int,char> > > res;
        for (int i=0; i<n; ++i) {
            char t;
            cin >> t;
            int r, win = 0, lose = 0;
            for (int j=0; j<n-1; ++j) {
                cin >> r;
                if (r == 0) ++ win;
                else if (r == 1) ++ lose;
            }
            res.push_back(make_pair(make_pair(-win, lose), make_pair(i, t)));
        }
        sort(res.begin(), res.end());
        for (int i=0; i<(int)res.size(); ++i) {
            cout << res[i].second.second << endl;
        }
    }
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> ans(n);
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    a--;
    ans.at(a)++;
  }
  
  for (int i = 0; i < n; i++) cout << ans.at(i) << '\n';
}

Measured memory_bytes: 3992
import itertools

n,k = map(int,input().split())
x = []
y = []
xy = []
for i in range(n):
  x0,y0 = map(int,input().split())
  x.append(x0)
  y.append(y0)
  xy.append((x0,y0))
x.sort()
y.sort()
xs = {}
ys = {}
for i in range(n):
  xs[x[i]] = i
  ys[y[i]] = i
m = [[0 for _ in range(n+1)] for _ in range(n+1)]
for x0,y0 in xy:
  m[ys[y0]+1][xs[x0]+1] += 1
for i in range(n):
  for j in range(n):
    m[i+1][j+1] += m[i][j+1]+m[i+1][j]-m[i][j]

ans = float('INF')
for x1,x2 in itertools.combinations(range(n),2):
  for y1,y2 in itertools.combinations(range(n),2):
    if k <= m[y2+1][x2+1]-m[y2+1][x1]-m[y1][x2+1]+m[y1][x1]:
      #print(x1,x2,y1,y2)
      ans = min((x[x2]-x[x1])*(y[y2]-y[y1]),ans)
print(ans)
#print(m)


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

int main() {
  int a,b;
  cin >> a >> b;
  if(((a+b)*10/2)%10==0){
    cout << (a+b)/2 << endl;
  }else{
  	cout << (a+b)/2+1 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

typedef struct sort_num {
  int64_t A;
  int64_t B;
  int64_t C;
} t_sort_num;

int my_sort( const void * a , const void * b ) {
  return (((t_sort_num*)b)->C - ((t_sort_num*)a)->C);
}

int main(void){
  int N;
  t_sort_num X[100000];
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%lu %lu", &X[i].A, &X[i].B);
    X[i].C = X[i].A + X[i].B;
  }
  // sort
  qsort((void*)X, N, sizeof(t_sort_num), my_sort);

  int64_t taka = 0;
  int64_t aoki = 0;
  for(int i = 0; i < N; i++) {
    if(i % 2) {
      aoki += X[i].B;
    } else {
      taka += X[i].A;
    }
  }
  printf("%ld\n", taka - aoki);
  return 0;
}


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

using namespace std;

const int N = 200010;
const int inf = 2e9;

int tab[21][N];
int a[N];
int n;

int query(int l, int r) {
  if (l < 0 || l >= n || r < 0 || r >= n) {
    return -inf;
  }
  int k = __lg(r - l + 1);
  return min(tab[k][l], tab[k][r - (1 << k) + 1]);
}

int find_left(int rr, int v) {
  int lo = -1, hi = rr + 1;
  while (hi - lo > 1) {
    int mi = (lo + hi) >> 1;
    if (query(mi, rr) < v) {
      lo = mi;
    } else {
      hi = mi;
    }
  }
  return lo + 1;
}

int find_right(int ll, int v) {
  int lo = ll - 1, hi = n;
  while (hi - lo > 1) {
    int mi = (lo + hi) >> 1;
    if (query(ll, mi) < v) {
      hi = mi;
    } else {
      lo = mi;
    }
  }
  return hi - 1;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    tab[0][i] = a[i];
  }
  int k = __lg(n);
  for (int t = 0; t < k; t++) {
    int l = 1 << t;
    for (int i = 0; i < n - 2 * l + 1; i++) {
      tab[t + 1][i] = min(tab[t][i], tab[t][i + l]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int l = find_left(i - 1, a[i]);
    int r = find_right(i + 1, a[i]);
    ans += 1ll * a[i] * (i - l + 1) * (r - i + 1);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 16640
A, B, C, D = map(int, input().split())
mod = 998244353

dp = [[0] * (D + 1) for _ in range(C + 1)]

for i in range(A, C + 1):
    for j in range(B, D + 1):
        if (i, j) == (A, B):
            dp[i][j] = 1
        else:
            dp[i][j] = dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1)
            dp[i][j] %= mod
print(dp[C][D])


Measured memory_bytes: 136692
#include <iostream>
using namespace std;
int main(void){
    int k,s;
    cin >> k >> s;
    int count=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int z = s - i - j;
            if(0<=z && z<=k) count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    while(cin >> H >> W,H+W){
        rep(i,H){
            rep(j,W)cout << "#";
            cout << endl;
        }
        cout << endl;
    }
}





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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, f[100][10], p[100][11];

int main() {
	cin >> n;
	inc(i,  n) {
	inc(j, 10) {
		cin >> f[i][j];
	}
	}
	inc(i,  n) {
	inc(j, 11) {
		cin >> p[i][j];
	}
	}
	
	int ans = -1e9;
	
	inc(b, 1 << 10) {
		if(b == 0) { continue; }
		
		int s = 0;
		inc(i, n) {
			int c = 0;
			inc(j, 10) { c += f[i][j] * ((b >> j) & 1); }
			s += p[i][c];
		}
		setmax(ans, s);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,i,j,ans=0;cin>>n;
	string s;cin>>s;
	//harf zenrekkyo
	vector<pair<string,string>>ue(1<<n);
	for(int bi=0;bi<(1<<n);bi++){
		pair<string,string>gen;
		for(j=0;j<n;j++){
			if(bi&(1<<j)){gen.fir.pub(s[j]);}
			else{gen.sec.pub(s[j]);}
		}
		ue[bi]=gen;
	}
	SO(ue);
	REV(s);
	for(int bi=0;bi<(1<<n);bi++){
		pair<string,string>gen;
		for(j=0;j<n;j++){
			if(bi&(1<<j)){gen.fir.pub(s[j]);}
			else{gen.sec.pub(s[j]);}
		}
		ans+=UBI(ue,gen)-LBI(ue,gen);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35840
#include<bits/stdc++.h>
using namespace std;
long long f[105],X;                 
int main(){
    cin>>X;
    f[0]=2;
    for(int i=1;i<=X;i++) 
        f[i]=f[i-1]*2+2;
    cout<<f[X]<<endl;
    return 0;
}

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

#define filein freopen ("in.txt", "r", stdin)
#define fileout freopen ("out.txt", "w", stdout)
#define dbg(x) cerr << #x << ": " << x << endl

using namespace std;
typedef long long ll;

const int maxn = 102;
const ll inf = 10000000000;

ll w[maxn], v[maxn];
ll dp[100005];

int main(){
	ll n, weight;
	scanf ("%lld %lld", &n, &weight);
	ll sum = 0;
	for (ll i = 1; i <= n; i++){
		scanf ("%lld %lld", &w[i], &v[i]);
		sum += v[i];
	}
	for (ll i = 1; i <= sum; i++)
		dp[i] = inf;
	for (ll i = 1; i <= n; i++){
		for (ll j = sum - v[i]; j >= 0; j--){
			dp[j + v[i]] = min (dp[j + v[i]], dp[j] + w[i]);
		}
	}
	ll ans;
	for (int i = 0; i <= sum; i++){
		if (dp[i] <= weight)
			ans = i;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    vector <int> prev(2019,0);
    vector <int> cur(2019,0);
    prev[s[0]-48]+=1;
    ll x=0;
    for(int i=1;i<n;i++){
        cur[s[i]-48]++;
        for(int j=0;j<2019;j++)
        {
            cur[(j*10+s[i]-48)%2019]+=prev[j];
        }
        x+=cur[0];
        prev=cur;
        for(auto &i:cur)
            i=0;
    }
    cout<<x<<endl;

        
    
    return 0;   
}




 
 


Measured memory_bytes: 3752
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int i = 1;
		while (true) {
			int n = sc.nextInt();
			if (n == 0) return;
			System.out.println("Case "+i+": "+n);
			i++;
			
		}
		
	}
}


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

using namespace std;

int main()
{
    long long a, b, c;
    cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0)
        printf("0\n");
    else
        printf("%lld\n", min({a*b, b*c, c*a}));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,a,b,s,t,test;
    scanf("%d",&test);
    t = 0;
    s = 0;
    for(j = 0;j < test;j++){
        scanf("%d %d",&a,&b);
        if(a == b){
            s++;
        }
        else if(a != b){
            s = 0;
        }
        if(s > t){
            t = s;
        }
    }
    if(t > 2){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


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

using namespace std;

const int maxn=2e6+10;

int n,k;
char c[maxn];
int a[maxn],b[maxn],sl;


// 最后一位为 A 后 ....BABABA 循环最多进行 2n  次  
deque<int> q;
int main()
{
//	freopen("a.in","r",stdin);
	scanf("%d%d",&n,&k);
	scanf("%s",c+1);
	for(int i=1;i<=n;++i) {
		a[i]=c[i]-'A';
		if((i)&1) b[n-i+1]=0;
		else b[n-i+1]=1;
		q.push_back(a[i]);
	} 
	int now=0;
	int z=min(2*n,k);
	for(int i=1;i<=z;++i) {
		int u=q.front();//cout<<i<<" "<<now<<":"<<u<<"\n";
		if((u^now)==0) {
			q.pop_front();
			q.push_front(u^1);
		}else {
			q.pop_front(); 
			q.push_back(1^now);
			now^=1;
		}
	}
	if(k<=2*n) {
		while(!q.empty()) {
			int u=q.front();q.pop_front();
			if(u^now) cout<<"B";
			else cout<<"A";
		}	
		return 0;
	}
	int tot=0,sl=2*n;
	while(!q.empty()) {
		int u=q.front()^now;q.pop_front();
		if(u!=b[++tot]) {
			sl=2*n+1;
			break;
		}		
	}
	if((n%2)) {
		if((k-sl)%2) b[1]=1; 
	}
	for(int i=1;i<=n;++i) {
		if(b[i]&1) {
			cout<<"B";
		}else {
			cout<<"A";
		}
	}
	return 0;
} 

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
ll dp[101][10001];
ll maxval(ll ar[],ll i,ll n,ll s){
	if(i==n){
		if(s%10==0)
			return 0;
		else return s;
	}

	if(dp[i][s]!=-1){
		return dp[i][s];
	}

	ll a,b;
	a=maxval(ar,i+1,n,s+ar[i]);
	b=maxval(ar,i+1,n,s);
	return dp[i][s]=max(a,b);
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n];
	memset(dp,-1,sizeof(dp));
	for(i=0;i<n;i++){
		cin>>ar[i];
	}
	
	l=maxval(ar,0,n,0);
	cout<<l;
	return 0;
}


Measured memory_bytes: 8192
#include<iostream>

#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

typedef long long int lli;

int main(){
  int n;
  cin >> n;
  cout << (n >= 1200 ? "ARC" : "ABC") << endl;
  return 0;
}


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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(cout.fixed);
    cout.precision(20);
    int n;
    cin >> n;
    map<ll, int> cnt;
    ll sum = 0;
    cnt[0] = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sum += a;
        cnt[sum]++;
    }
    ll res = 0;
    for (auto &p : cnt) {
        res += (ll)p.second * (p.second - 1) / 2;
    }
    cout << res << "\n";
}


Measured memory_bytes: 12800
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define all(v) v.begin(),v.end()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);
#define curMod 998244353

int main(){
		//do_not_disturb
		int n;
		double ans;
		cin >> n;
		if(n&1){
			ans = double(1./n);
			ans *= double((n+1)/2.);
			cout << precision(10) << ans;
		}
		else{
			cout << precision(10) << double(1./2.);
		}
		
    return 0;
} // What is to be written here?


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

int main() {
  int a, b, c, k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  if(a >= k) cout << k;
  else if(a + b >= k) cout << a;
  else cout << (2*a + b - k);
}

Measured memory_bytes: 3696
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int n,sum=0,k=0;
	cin>>n;
	for(int j=1;j<=n;j++)
	{
		sum=0;
		if(j%2!=0)
		{
			for(int i=1;i<=j;i++)
			{
				if(j%i==0)
				sum++;
				if(sum==8)
				{
					k++;
				}
			}
		
		}
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int a[m],b[m], vis[n+1]={0};
	for (int i = 0; i < m; ++i)
	{
		cin>>a[i]>>b[i];
		vis[a[i]]++;
		vis[b[i]]++;
	}
	for (int i = 0; i < n; ++i)
	{
		if(vis[i]%2==1)
		{
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#define MAX 100

int main()
{
  int M[MAX][MAX];
  int n,u,k,v;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j] = 0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}
  



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mx = (1 << 17) + 5;
const int N = 45;
int n,x,y,z;
long long ans = 1;
int lim,chk;
int dp[N][mx] = {0};
int main(){
    scanf("%d%d%d%d",&n,&x,&y,&z);
    for(int i = 1;i<=n;i++)
        ans = (ans * 10) % mod;
    lim =  1 << (x + y + z);
    chk = (1 << (x + y + z - 1)) + (1 << (y + z - 1)) + (1 << (z - 1));
    dp[0][0] = 1;
    int cnt = 0;
    for(int i = 1;i<=n;i++){
        for(int j = 0;j<lim;j++){
            for(int k = 1;k<=10;k++){
                int res = ((j << k) + (1 << (k-1))) % lim;
                if((res & chk) == chk) continue;
                dp[i][res] = (dp[i][res] + dp[i-1][j]) % mod;
            }
        }
    }
    for(int i = 0;i<lim;i++)
    	ans = (ans + mod - dp[n][i]) % mod;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 22272