akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 200010;

struct Node {
  int l, r;
  ll v, lazy;
  Node *ls, *rs;

  ll get() const { return v + lazy; }

  void upd() {
    v = max(ls->get(), rs->get());
  }

  void pd() {
    if (lazy) {
      v += lazy;
      ls->lazy += lazy;
      rs->lazy += lazy;
      lazy = 0;
    }
  }

  void ch(int l, int r, ll v) {
    if (this->l == l && this->r == r) {
      lazy += v;
      return;
    }
    pd();
    if (r <= ls->r)
      ls->ch(l, r, v);
    else if (l >= rs->l)
      rs->ch(l, r, v);
    else {
      ls->ch(l, ls->r, v);
      rs->ch(rs->l, r, v);
    }
    upd();
  }

  void*operator new(size_t) {
    static Node pool[N * 2];
    static Node* ptop = pool;
    return ptop++;
  }
};

int n;
vector<pair<int, int>> apply[N];

Node* build(int l, int r) {
  Node* p = new Node;
  p-> l = l;
  p->r =r ;
  if (l == r)
    return p;
  int mid = (l + r) >> 1;
  p->ls = build(l, mid);
  p->rs = build(mid + 1, r);
  return p;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int l, r, a;
    scanf("%d%d%d", &l, &r, &a);
    apply[r].emplace_back(l, a);
  }
  Node* seg = build(1, n);
  for (int i = 1; i <= n; ++i) {
    seg->ch(i, i, seg->get());
    for (const auto& pr : apply[i])
      seg->ch(pr.first, i, pr.second);
  }
  printf("%lld\n", max(seg->get(), 0LL));

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 26752
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const int MAX = 510000;
const int MOD = 1000000007;

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

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

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

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

ll nHr(int n,int k){
  return nCr(n+k-1,k);
}

int main() {
  init();
  
  int n;
  cin>>n;
  
  int m=n/3;
  
  ll ans=0;
  for(int i=1;i<=m;i++){
    ans=(ans+nHr(i,n-3*i))%MOD;
  }
  cout<<ans<<endl;

}

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

using namespace std;
const int MAXN = 3e5 + 5;
int cnt1[MAXN], cnt2[MAXN];
map<pair<int, int>, int> mp;
int main()
{
    int H, W, M;
    scanf("%d %d %d", &H, &W, &M);
    int h, w;
    vector<pair<int, int> > node;
    for (int i = 1; i <= M; i++)
    {
        scanf("%d %d", &h, &w);
        node.push_back({h, w});
        cnt1[h]++;
        cnt2[w]++;
        mp[{h, w}]++;
    }
    int mx1 = 0, mx2 = 0;
    for (int i = 1; i <= H; i++)
        mx1 = max(mx1, cnt1[i]);
    for (int i = 1; i <= W; i++)
        mx2 = max(mx2, cnt2[i]);
    
    int vc1 = 0, vc2 = 0;
    for (int i = 1; i <= H; i++)
        if (cnt1[i] == mx1)
            vc1++;
    for (int i = 1; i <= W; i++)
        if (mx2 == cnt2[i])
            vc2++;
    int numnode = 0;
    for (auto vv : node)
    {
        if (cnt1[vv.first] == mx1 && cnt2[vv.second] == mx2)
        {
            numnode++;
        }
    }
    if (numnode == (long long)vc1 * vc2)
        printf("%d\n", mx1 + mx2 - 1);
    else
        printf("%d\n", mx1 + mx2);
    // int T;
    // cin >> T;
}

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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;

const int mod = 1e9 + 7;

template< typename Data, typename T >
struct ReRooting {

  struct Node {
    int to, rev;
    Data data;
  };

  using F1 = function< T(T, T) >;
  using F2 = function< T(T, int, int, Data) >; // ret, src, to, data

  vector< vector< Node > > g;
  vector< vector< T > > ldp, rdp;
  vector< int > lptr, rptr;
  const F1 f1;
  const F2 f2;
  const T ident;

  ReRooting(int n, const F1 &f1, const F2 &f2, const T &ident) :
      g(n), ldp(n), rdp(n), lptr(n), rptr(n), f1(f1), f2(f2), ident(ident) {}

  void add_edge(int u, int v, const Data &d) {
    g[u].emplace_back((Node) {v, (int) g[v].size(), d});
    g[v].emplace_back((Node) {u, (int) g[u].size() - 1, d});
  }

  T dfs(int idx, int par) {

    while(lptr[idx] != par && lptr[idx] < g[idx].size()) {
      auto &e = g[idx][lptr[idx]];
      ldp[idx][lptr[idx] + 1] = f1(ldp[idx][lptr[idx]], f2(dfs(e.to, e.rev), idx, e.to, e.data));
      ++lptr[idx];
    }
    while(rptr[idx] != par && rptr[idx] >= 0) {
      auto &e = g[idx][rptr[idx]];
      rdp[idx][rptr[idx]] = f1(rdp[idx][rptr[idx] + 1], f2(dfs(e.to, e.rev), idx, e.to, e.data));
      --rptr[idx];
    }
    if(par < 0) return rdp[idx][0];
    return f1(ldp[idx][par], rdp[idx][par + 1]);
  }

  vector< T > solve() {
    for(int i = 0; i < g.size(); i++) {
      ldp[i].assign(g[i].size() + 1, ident);
      rdp[i].assign(g[i].size() + 1, ident);
      lptr[i] = 0;
      rptr[i] = (int) g[i].size() - 1;
    }
    vector< T > ret;
    for(int i = 0; i < g.size(); i++) {
      ret.push_back(dfs(i, -1));
    }
    return ret;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  using pi = pair< int64, bool >;
  pi e(1LL, false);
  auto f1 = [&](pi a, pi b) {
    if(!a.second && !b.second) return e;
    if(!a.second) return pi(b.first, b.second);
    if(!b.second) return pi(a.first, a.second);
    return pi((a.first * b.first) % M, true);
  };
  auto f2 = [&](pi a, int64 b, int c, int64 d) {
    // ここを黒く塗る
    return pi((a.first + 1) % M, true);
  };
  ReRooting< int64, pi > tap(N, f1, f2, e);

  for(int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    tap.add_edge(x, y, 1);
  }
  auto ret = tap.solve();
  for(auto &p :ret) cout << p.first << endl;
}


Measured memory_bytes: 45168
n = gets.to_i
words = []
n.times do
  words << gets.to_s
end
if words.size != words.uniq.size
  puts "No"
else
  result = true
  words.size.times do |i|
    next if i == 0
    result = false if words[i-1][-2] != words[i][0]
  end
  puts result ? "Yes" : "No"
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,A[110];
	cin>>N;
	string ans="APPROVED";
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(A[i]%2==0){
			if(A[i]%3!=0&&A[i]%5!=0)
			ans="DENIED";
		}
	}
	cout<<ans;  
	return 0;
 } 

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

using namespace std;

using int64 = long long;

struct Block {
  int64 weight;
  int64 strength;
  int64 value;
};

constexpr int S_MAX = 20000;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

int64 Max(const vector<int64>& xs) {
  int64 value = INT64_MIN;
  for (int64 x : xs) value = max(x, value);
  return value;
}

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

  int n;
  cin >> n;
  vector<Block> blocks;
  for (int i = 0; i < n; i++) {
    int64 w, s, v;
    cin >> w >> s >> v;
    blocks.push_back(Block({w, s, v}));
  }
  sort(blocks.begin(), blocks.end(), [](const auto& b1, const auto& b2) {
    return (b1.weight + b1.strength) < (b2.weight + b2.strength);
  });

  vector<vector<int64>> dp = Make2DVector<int64>(n + 1, S_MAX + 1, -1);
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= S_MAX; j++) {
      if (dp[i][j] < 0) continue;
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      // cout << "i: " << i << " strength: " << blocks[i].strength << endl;
      if (j <= blocks[i].strength && j + blocks[i].weight <= S_MAX) {
        dp[i + 1][j + blocks[i].weight] =
            max(dp[i + 1][j + blocks[i].weight], dp[i][j] + blocks[i].value);
      }
    }
  }
  cout << Max(dp[n]) << endl;
}


Measured memory_bytes: 160640
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
const size_t SIZE = 1010;
int dp[SIZE], dp_buf[SIZE];
int A[SIZE], B[SIZE];

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

bool solve() {
    int N, M;
    cin >> N >> M;
    if(N + M == 0) return false;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    
    auto to_push = [&](int i) { return ((M - A[i]) + B[i]) % M; };

    dp[0] = to_push(0);
    for(int i = 1; i <= N; i++) dp[i] = dp[0] + i * M;
    for(int i = 1; i < N; i++) {
        fill(dp_buf, dp_buf + SIZE, inf);
        for(int j = 0; j <= N; j++) {
            int pushed = to_push(i - 1) + j * M;
            for(int diff = -1; diff <= 1; diff++) {
                int want = (j + diff) * M + to_push(i);
                if(want < 0) continue;
                chmin(dp_buf[j + diff], dp[j] + max(want - pushed, 0));
            }
        }
        copy(dp_buf, dp_buf + SIZE, dp);
    }

    int ans = inf;
    for(int i = 0; i <= N; i++) chmin(ans, dp[i]);
    cout << ans << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    int a[100000];
    for(int i = 0; i < N; ++i) cin >> a[i];
    map<int, int> m;
    for(int i = 0; i < N; ++i){
        if(m.count(a[i])){
            m.erase(a[i]);
        }else{
            m[a[i]] = 1;
        }
    }
    cout << m.size() << endl;
    return 0;
}

Measured memory_bytes: 5248
N = int(input())
A = [0] + list(map(int, input().split()))

ans = [0] * (N+1)
for i in range(N, 0, -1):
    if sum(ans[i+i:N+1:i])%2 != A[i]: ans[i] = 1


print(sum(ans))
f = 0
for i in range(N+1):
    if ans[i] == 0: continue
    if f: print(' ')
    print(i, end ='')
    f = 1
if f:print()


Measured memory_bytes: 8480
import java.util.Scanner;


public class Main {
	public static void main (String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int[] l= new int[n];
		
		String ans="";
		
		int max=0;
		int sum=0;
		
		for(int i=0;i<n;i++){
			l[i]=sc.nextInt();
			sum=sum+l[i];
			if(max<l[i])max=l[i];
		}
		
		if(sum-max>max)ans="Yes";
		else ans="No";
		
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    ll ans = 1;
    ll MAX = 1;
    rep(i, 18) MAX *= 10;
    ll A[N];
    rep(i, N){
        cin >> A[i];
    }
    rep(i, N) if(A[i] == 0) {cout << 0 << endl; return 0;}
    rep(i, N){
        if(ans > INF/A[i]) {cout << -1 << endl; return 0;}
        ans *= A[i];
    }
    if(ans <= MAX) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 4412
def isKaibun(ss):    
    return ss==ss[::-1]

s = input()
ans=True
n=len(s)

if not isKaibun(s):
    ans=False
if not isKaibun(s[:((n-1)//2)]):
    ans=False

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61904
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()

if S[2] == S[3] and S[4] == S[5]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3572
# -*- coding: utf-8 -*-

"""
・幅優先
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()

# 右左上下
directions = [(0,1),(0,-1),(1,0),(-1,0)]
# 四方に一回り大きいグリッドを作る
grid = [['*'] * (W+2) for i in range(H+2)]
for i in range(1,H+1):
    row = list(input())
    for j in range(1, W+1):
        grid[i][j] = row[j-1]

visited = list2d(H+2, W+2, False)

def bfs(start):
    que = deque()
    # スタート位置
    que.append(start)
    # 白マス通過カウント
    w_cnt = 0
    # 黒マス通過カウント
    b_cnt = 0
    while len(que):
        cur = que.popleft()
        # 見終わった場所はもうやらない
        if visited[cur[0]][cur[1]]:
            continue
        # 訪問済にする
        visited[cur[0]][cur[1]] = True
        # 今のマスのカウント追加
        if grid[cur[0]][cur[1]] == '.':
            w_cnt += 1
        elif grid[cur[0]][cur[1]] == '#':
            b_cnt += 1
        # 4方向見る
        for direction in directions:
            # 上下左右に1つずつ動かした座標
            nxt = list(map(lambda x,y: x+y, cur, direction))
            # 壁か今のマスと同じ色はスキップ
            if grid[nxt[0]][nxt[1]] == '*' or grid[cur[0]][cur[1]] == grid[nxt[0]][nxt[1]]:
                continue
            # キューに次のマスを足す
            que.append(nxt)
    # 今回調べた範囲で得られるカウントを返却
    return w_cnt * b_cnt

cnt = 0
for i in range(H+2):
    for j in range(W+2):
        if grid[i][j] == '#' and not visited[i][j]:
            cnt += bfs((i, j))
print(cnt)


Measured memory_bytes: 89176
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        r: usize,
        D: usize,
        x: usize,
    }
    let mut amount_t = x;
    for i in 0..10 {
        let amount_tpp = r * amount_t - D;
        println!("{}", amount_tpp);
        amount_t = amount_tpp;        
    }
}


Measured memory_bytes: 4352
import numpy as np

def main():
    N = np.array([str(i) for i in range(1,int(input())+1)])
    C = np.zeros((10,10), dtype=np.int)
    ans = 0

    # C[i][j](0 <= i,j <= 9)のテーブルを構築する: O(N)
    for n in N:
        C[int(n[0])][int(n[-1])] += 1

    for i in range(1,9+1):
        for j in range(1,9+1):
            ans += C[i][j] * C[j][i]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 35204
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
A=sorted(A,reverse=True)
sum_A=sum(A)
count=0
for i in range(M):
    if A[i]<sum_A/(4*M):
        break
    count+=1
if count==M:
    print("Yes")
else:
    print("No")

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

int main() {
	long long int i,j,x;
	cin>>x;
	if(x>=1800)
	cout<<1;
	else if(x>=1600)
	cout<<2;
	else if(x>=1400)
	cout<<3;
	else if(x>=1200)
	cout<<4;
	else if(x>=1000)
	cout<<5;
	else if(x>=800)
	cout<<6;
	else if(x>=600)
	cout<<7;
	else cout<<8;
}


Measured memory_bytes: 3588
#include <iostream>

int main() {
    int K, A, B;
    std::cin >> K >> A >> B;

    if (A % K == 0 || B % K == 0 || (B / K - A / K) > 0) {
        std::cout << "OK" << std::endl;
    } else {
        std::cout << "NG" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    ll n, k;
    cin >> n >> k;

    ModComb mc(1001);
    if(n < k)   cout << 0 << endl;
    else        cout << mc.nHk(n-k, k) << endl;

    return 0;
}


Measured memory_bytes: 3092
// AOJ 0372: Three Meals
// 2017.11.14 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

typedef struct { long long b; int n, t; } T;
T tbl[3][1440]; int sz[3];
long long a[3][1440];

int bitcount64(long long x)
{
	x = ((x & 0xAAAAAAAAAAAAAALL) >>  1) + (x & 0x55555555555555LL);
	x = ((x & 0xCCCCCCCCCCCCCCLL) >>  2) + (x & 0x33333333333333LL);
	x = ((x & 0xF0F0F0F0F0F0F0LL) >>  4) + (x & 0x0F0F0F0F0F0F0FLL);
	x = ((x & 0x00FF00FF00FF00LL) >>  8) + (x & 0xFF00FF00FF00FFLL);
	x = ((x & 0xFF0000FFFF0000LL) >> 16) + (x & 0x00FFFF0000FFFFLL);
	x = ((x & 0xFFFFFF00000000LL) >> 32) + (x & 0x000000FFFFFFFFLL);
	return (int)x;
}

int cmp(T *a, T *b) { if (b->n - a->n) return b->n - a->n; return a->t - b->t; }

int main()
{
	int n, i, j, k, at, ht, f, ans;
	long long b, b1;
	T *tp;
	
	scanf("%d", &n);

	for (b = 1, i = 0; i < n; i++, b <<= 1) for (j = 0; j < 3; j++) {
		int sh, sm, eh, em, t;
		scanf("%d%d%d%d", &sh, &sm, &eh, &em);
		sh = sh*60+sm, eh = eh*60+em;
		for (t = sh; t <= eh; t++) a[j][t] |= b;
	}
	for (j = 0; j < 3; j++) {
		for (tp = tbl[j], i = 0; i < 1440; i++) if (a[j][i] > 0) {
			tp->b = a[j][i], tp->n = bitcount64(a[j][i]), tp->t = i, tp++;
		}
		sz[j] = tp - tbl[j];
		qsort(tbl[j], sz[j], sizeof(T), cmp);
	}

	ans = 0;
	for (i = 0; i < sz[0]; i++) {
		if (tbl[0][i].n <= ans) goto done;
		at = tbl[0][i].t, b1 = tbl[0][i].b;
		for (j = 0; j < sz[1]; j++) {
			if (tbl[1][j].n <= ans) break;
			if ((ht = tbl[1][j].t) <= at) continue;
			b = tbl[1][j].b & b1;
			if (bitcount64(b) <= ans) continue;
			for (k = 0; k < sz[2]; k++) {
				if (tbl[2][k].n <= ans) break;
				if (tbl[2][k].t <= ht) continue;
				if ((f = bitcount64(tbl[2][k].b & b)) > ans) ans = f;
			}
		}
	}
done:
	printf("%d\n", ans);
	return 0;
}

/*
5
1:00 2:00   3:30 4:30    6:00 7:00
2:30 3:00   4:00 5:00    5:30 6:30
1:30 2:30   4:30 5:00    6:30 7:00
2:30 3:00   5:00 6:00    6:30 7:00
1:00 2:00   3:00 3:30    4:00 5:00
*/

Measured memory_bytes: 1956
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int N, M; cin >> N >> M;
VS A(N), B(M);
rep(i, 0, N) cin >> A[i];
rep(i, 0, M) cin >> B[i];

rep(i, 0, N - M + 1){
    rep(j, 0, N - M + 1){
        if (A[i].substr(j, M) == B[0]){
            bool match = true;
            rep(k, 0, M){
                if (A[i+k].substr(j, M) != B[k]) 
                    match = false;
            }
            if (match){
                cout << "Yes\n";
                return 0;
            }
        }
    }
}
cout << "No\n";

}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
def solve():
    W, a, b = list(map(int, input().split(" ")))

    if a < b:
        if b - (a + W) > 0:
            print(b - (a + W))
        else:
            print(0)
    elif b < a:
        if a - (b + W) > 0:
            print(a - (b + W))
        else:
            print(0)
    else:
        print(0)


solve()

Measured memory_bytes: 3060
//uses crt;
var cost:array[0..100005] of int64;
dp:array[0..100005] of int64;
i,o,p,l,k,m,n,h,indexx,minindex,j:longint;
min:int64;
begin
//clrscr;
read(n,k);
for i:=1 to n do begin
        read(cost[i]);
        end;
dp[0]:=0;
dp[1]:=0;
dp[2]:=abs(cost[2]-cost[1]);
for i:=3 to n do begin
        min:=10000000000000000;
        for j:=i-1 downto i-k do begin
               // writeln('wda');
                if j=0 then break;
                if abs(cost[j]-cost[i])+dp[j]< min then begin
                        min:=abs(cost[j]-cost[i])+dp[j];
                        indexx:=j;
                        end;
                end;
        dp[i]:=min;
        //writeln('dp[',i,']= ',dp[i],' min=',min,' indexx=',indexx);
        end;
writeln(dp[n]);
//readln;
//readln;
end.

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

using namespace std;
using ll = long long;
using ld = long double;

#define int long long
signed main(){
//int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<int> a(n+1);
    a[0]=0;
    for(int i = 0; i < n; i++) {
        int ta;
        cin >> ta;
        a[i+1]=a[i]+ta;
    }
    for(int i = 0; i < n+1; i++) {
        a[i]%=m;
    }
    sort(a.begin(),a.end());
    int cnt=1;
    int ans=0;
    for(int i = 0; i < n; i++) {
        if(a[i+1]==a[i]) cnt++;
        else{
            ans+=cnt*(cnt-1)/2;
            cnt=1;
        }
    }
    if(a[n]==a[n-1]) ans+=cnt*(cnt-1)/2;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3968
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<set>
#include<map>
#include<vector>

using namespace std;

string s;
string t;
int main()
{
	getline(cin, s);
	getline(cin, t);
	int cnt = 0;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] != t[i])
		{
			cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c;
    cin>>n;
    c=0;
    while(n--)
    {
        cin>>a>>b;
        c+=(b-a+1);
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	static void solve() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		if(a>=b) {
			for(int i = 0; i<a;i++) {
				System.out.print(b);
			}
		}
		else {
			for(int i = 0; i<b;i++) {
				System.out.print(a);
		}		
	}
}
	public static void main(String[] args) {
		solve();
	}
}


Measured memory_bytes: 22996
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int r; cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define vi vector<int>

using ll = long long;
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
inline ll inv(ll x, ll div){return pow(x, div - 2, div);}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
 int ans = INF;
 ans = min(ans, abs((a+b)-(c+d))); 
 ans = min(ans, abs((a+c)-(b+d))); 
 ans = min(ans, abs((a+d)-(c+b))); 
 cout << ans << endl;
}



Measured memory_bytes: 3112
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int secret_num = 0;
		for(; scanner.hasNext();)
		{
			String input = scanner.next();
			
			for(int i=0; i<input.length(); i++)
			{
				char c = input.charAt(i);
				int num = 0;
				for(;('0'<=c && c<='9');)
				{
					num = 10*num + Integer.parseInt(input.substring(i, i+1));
					
					if(++i < input.length())
					{
						c=input.charAt(i);
					}
					else{
						break;
					}
					
				}				
				secret_num += num;
			}
		}
		
		System.out.println(secret_num);
	}
}

Measured memory_bytes: 26044
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    string s;
    cin>>s;
    for(ri int i=0;i<(int)s.length();i++) if(s[i]==',') cout<<' '; else cout<<s[i];
    puts("");
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		if(a < b) System.out.println("a < b");
		else if(a > b) System.out.println("a > b");
		else System.out.println("a == b");
	}
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  map<string, int> mp;
  REP(i, N){
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    mp[s[i]]++;
  }
  ll ans = 0;
  for(auto itr = mp.begin(); itr!=mp.end(); ++itr){
      ll add = 0;
      FOR(i, 1, itr->second){
        ans+=i;
      } 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
  string n;
  cin >> n;
  string ch = n.substr(n.size()-1,1);
  if(ch == "2" || ch == "4" ||
  ch == "5" || ch == "7" || ch == "9")
    cout << "hon" << endl;
  else if(ch == "0" || ch == "1" || 
  ch == "6" || ch == "8")
    cout << "pon" << endl;
  else if(ch == "3") cout << "bon" << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
long long a[100010],n,sisi1,sisi2;
int main() {
cin>>n;
for(int i=1;i<=n;i++) {
	cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=n;i>=2;i--) {
	if(a[i]==a[i-1]) {
		sisi1=i;
		break;
	}
}
//for(int i=n;i>=2;i--) {
//	if(a[i]==a[i-1]) {
//		sisi1=a[i];      //kalo yang ini jadi runtime gatau kenapa
//		break;
//	}
//}      
for(int i=sisi1-2;i>=2;i--) {
	if(a[i]==a[i-1]) {
		sisi2=i;
		break;
	}
}
cout<<a[sisi1]*a[sisi2]<<endl;
}

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

int main(){
    string s1,s2,s3;
    int henkan = 'A'-'a';
    cin >> s1 >> s2 >> s3;
    char a=s1.at(0)+henkan;
    char b=s2.at(0)+henkan;
    char c=s3.at(0)+henkan;
    cout << a << b << c << endl;
}

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

int main() {
  int N;
  cin >> N;

  vector<int> a(N);
  for (auto &i : a) cin >> i;

  int nim = 0;
  for (auto &i : a) {
    nim ^= i;
    i = i & -i;
  }

  sort(a.rbegin(), a.rend());
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (nim & a[i]) {
      nim ^= a[i] + a[i] - 1;
      ans++;
    }
  }

  if (nim) ans = -1;

  cout << ans << endl;
}


Measured memory_bytes: 640
import math
N=1000000
prime=[1]*(N+1)
prime[0],prime[1]=0,0
for i in range(2,int(math.sqrt(N))):
    if prime[i]==1:
        j=i
        while i*j<=N:
            prime[i*j]=0
            j+=1

while True:
    n=input()
    if n==0:break
    cnt=0
    for i in range(2,n/2+1):
        if prime[i]==1:
            if prime[n-i]==1:
                cnt+=1
    print cnt

Measured memory_bytes: 30096
order = list(input())
X, Y = map(int, input().split())
 
Xs = []
Ys = []
cnt = 0
now_lis = Xs
x_dir = 1
for s in order:
    if s=='T':
        if not cnt==0:
            now_lis.append(cnt)
        now_lis = Ys if x_dir else Xs
        x_dir = not x_dir
        cnt = 0
    else:
        cnt += 1
if not cnt==0:
    now_lis.append(cnt)

if order[0]=='T':
    x_start = 0
else:
    x_start = Xs[0]
    del Xs[0]

def dp(start, lis, goal):
    nodes = set([start])
    for x in lis:
        nx = set()
        L = list(nodes)
        for l in L:
            nx.add(l+x)
            nx.add(l-x)
        nodes = nx
    return goal in nodes
 
if dp(x_start, Xs, X) and dp(0, Ys, Y):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 46812
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int N;

void dfs(string S, char cmax)
{
    if (S.size() == N)
    {
        cout << S << endl;
    }
    else
    {
        for (int i = 0; i <= cmax - 'a'; ++i)
        {
            char ch = 'a' + i;
            dfs(S + ch, ((ch == cmax)? (cmax + 1) : cmax));
        }
    }
}

int main()
{
    cin >> N;
    string str = "";
    dfs(str, 'a');

    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using D = double;
using LD = long double;
const int mod = 1e9+7;
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; }

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main(){
    int n; ll d,a; cin >> n >> d >> a;
    vector<ll> x(n), h(n);
    rep(i,n) cin >> x[i] >> h[i];
    
    vector<P> pos(n);
    rep(i,n) pos[i] = make_pair(x[i], h[i]);
    sort(ALL(pos));
    rep(i,n) {
        x[i] = pos[i].first;
        h[i] = pos[i].second;
    }

    ll ans = 0;
    BIT<ll> bit(n+5);

    rep(i,n) bit.add(i+1, i+2, h[i]);

    rep(i,n){
        ll hp = bit.sum(i+1, i+2);
        if(hp <= 0) continue;
        ll cnt = (hp + a - 1) / a;
        int reach = upper_bound(ALL(x), x[i] + 2*d) - x.begin();
        bit.add(i+1, reach+1, -cnt*a);
        ans += cnt;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<bitset>
#include<deque>
#define eps 1e-15
#define maxn 100010
#define maxm 200010
#define mod 1000000007
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char s[1000010];
int n;
int f[1000010][2],a[1000010];
int main()
{
    scanf("%s",s+1);n=strlen(s+1);
    for(int i=1;i<=n;i++)  a[i]=s[i]-'0';
    f[n+1][0]=0;f[n+1][1]=inf;
    for(int i=n;i>=1;i--)
    {
        if(a[i]!=9)
        {
            f[i][0]=min(f[i+1][0]+a[i],f[i+1][1]+a[i]+1);
            f[i][1]=min(f[i+1][0]+10-a[i],f[i+1][1]+10-a[i]-1);
        }
        else{
            f[i][0]=f[i+1][0]+a[i];
            f[i][1]=min(f[i+1][0]+1,f[i+1][1]);
        }
    }
    cout<<min(f[1][0],f[1][1]+1)<<endl;
    return 0;
}

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

using namespace std;

long long gcd(long long a,long long b){
	if(a>b) swap(a,b);
	while(a>0){
		b%=a;
		if(b==0) return a;
		a%=b;
	}
	return b;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	long long m;
	cin >> m;
	vector<long long> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	long long g=a[0]/2;
	for(int i=0;i<n;i++){
		long long b=a[i]/2;
		long long gc=gcd(g,a[i]/2);
		g=g/gc*(a[i]/2);
		if(g>m) break;
	}
	if(g>m){
		cout << 0 << "\n";
		return 0;
	}
	bool bo=true;
	for(int i=0;i<n;i++){
		long long b=a[i]/2;
		if(((g/b) &1)==0) bo=false;
	}
	if(!bo) cout << 0 << "\n";
	else cout << max(0LL,(m-g)/(2*g)+1) << "\n";
}

Measured memory_bytes: 1024
#16:57
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b,w = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append([b,w%2])
  peer[b].append([a,w%2])
now = [0]
seen = [-1 for _ in range(n)]
seen[0] = 0
#print(peer)
while now:
  last = now
  now = []
  for x in last:
    for yw in peer[x]:
      y,w = yw
      if seen[y] == -1:
        seen[y] = (seen[x]+w)%2
        now.append(y)
for i in range(n):
  print(seen[i])

Measured memory_bytes: 82080
s=input()
n=len(s)
rui=[0]
juu=[1]
for i in range(n+5):
  juu.append(juu[-1]*10%2019)  
for i in range(n):
  rui.append((rui[-1]+int(s[n-1-i])*juu[i])%2019)
ama=[0]*2019
for i in range(len(rui)):
  ama[rui[i]]+=1
ans=0
def ui(n):
  return max(0,n*(n-1)//2)
for i in range(2019):
  ans+=ui(ama[i])
print(ans)  

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

char inv01(char num) {
	if (num == '1')return '0';
	if (num == '0')return '1';
	return '2';
}



int main() {

	string cubes;
	cin >> cubes;

	vector<char> stack{ '2' };
	int stackcount = 1;

	int ans = 0;

	for (int i = 0; i < cubes.length(); i++) {
		//スタック最終要素と一致の場合、スタックから1個出す＆ansを2増やす
		if (inv01(cubes[i]) == stack[stackcount - 1]) {
			stack.pop_back();
			stackcount--;

			ans += 2;

		}
		//スタック最終要素と一致しない場合、スタックに積む
		else {
			stack.push_back(cubes[i]);
			stackcount++;
		}
	}

	cout << ans << endl;




	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    long long N,Y;
    cin>>N>>Y;
    Y/=1000;
    if(N>Y){
        cout<<"-1 -1 -1"<<endl;
        return 0;
    }
    long long a,b,c;
    a=(N-Y)/4;
    b=((N-Y)*2-8)/9;
    c=-Y/5;
    if(b>a-1&&b>c-1){
        cout<<Y-N+4*b<<" "<<2*N-2*Y-9*b<<" "<<Y+5*b<<endl;
    }else{
        cout<<"-1 -1 -1"<<endl;
    }
}


Measured memory_bytes: 384
import java.util.Scanner;

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

        for (int i=0;i<n;++i)
        {
            int k=sc.nextInt();
            int p=sc.nextInt();

            int a=k%p;
            if (a!=0) {System.out.println(a);}
            else {System.out.println(p);}
        }
    }
}


Measured memory_bytes: 26396
#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <climits>
#include <cmath>
#include <set>
#include <map>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std; 
const long long  mod=998244353;
typedef long long LL;
const int N=3e5+5;
LL fac[N],inv[N];
LL quickPow(LL a,LL b){
	LL ans=1;
	while(b){
		if(b&1){
			ans=(ans*a)%mod;
		}
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
LL C(int n,int m){
	if(n<0||m<0||m>n) return 0;
	if(n==m||m==0) return 1;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void init(){
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=(fac[i-1]*i)%mod;
	}
	inv[N-1]=quickPow(fac[N-1],mod-2);
	for(int i=N-2;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
LL Lucas(int n,int m){
	if(m==0) return 1;
	return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
int main(){
	LL n,a,b,k,j,ans=0;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
	if(k==0){
		printf("1");
		return 0;
	} 
	init();
	for(int i=0;i<=n;i++){
		if((k-a*i)%b==0&&(k-a*i)>=0){
			j=(k-a*i)/b;
			if(j>n) continue;
			ans=(ans+Lucas(n,i)*Lucas(n,j))%mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>

int main(){
  int n;
  for(;;){
    int sum=0,min=1000,max=0;
    scanf("%d",&n);
    if(n==0) break;
    for(int i=0; i<n; i++){
      int m;
      scanf("%d",&m);
      if(m<min) min=m;
      if(m>max) max=m;
      sum+=m;
    }
    printf("%d\n",(sum-min-max)/(n-2));
  }
}

Measured memory_bytes: 1032
def f(s, cost, route, ans):
    route.append(s)
    ans += cost[s]
    del cost[s]
    for k, c in data.items():
        a, b = k
        if s == a:
            if not b in route:
                if not b in cost or c < cost[b]:
                    cost[b] = c
        elif s == b:
            if not a in route:
                if not a in cost or c < cost[a]:
                    cost[a] = c
    if cost:
        s = sorted(cost.items(), key=lambda x: x[1])[0][0]
        return f(s, cost, route, ans)
    else:
        return ans

while True:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    data = {}
    for i in range(m):
        a, b, c = map(int, raw_input().split())
        data[(a, b)] = c
    else:
        print f(0, {0:0}, [], 0)

Measured memory_bytes: 4332
import sys

def f(n):
    if n & 1:
        return n * 3 + 1
    else:
        return n // 2

s = int(sys.stdin.readline().rstrip())

def main():
    a = s
    res = set([a])
    for i in range(2, 10**6+1):
        a = f(a)
        if a in res:
            return i 
        res.add(a)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
a,b,c = map(int,input().split())
i = 0

if a == b == c:
    if a % 2 == 0:
        print(-1)
        exit(0)
    else:
        print(0)
        exit(0)

while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    al = b // 2 + c // 2
    bl = a // 2 + c // 2
    cl = a // 2 + b // 2
    a = al
    b = bl
    c = cl
    i += 1

print(i)

Measured memory_bytes: 9144
a = str(input())
a = list(a)
b = int(''.join(a[0: 2]))
c = int(''.join(a[2: 4]))
if (99 >= b > 12):
    if (c > 12):
        print('NA', end='')
    elif(12 >= c >= 1):
        print('YYMM', end='')
    else:
        print('NA', end='')
elif (12 >= b > 0):
    if (c > 12):
        print('MMYY', end='')
    elif(12 >= c > 0):
        print('AMBIGUOUS', end='')
    elif(c == 0):
        print('MMYY', end='')
    else:
        print('NA', end='')
elif (b == 0):
    if (99 >= c >= 1):
        print('YYMM', end='')
    else:
        print('NA', end='')


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

int main()
{
  int a,b,c,d,e,f,g,h,i,j,k,l,m,n,t,prothom,boro;
  cin>>n>>k;

   cin>>a;

  boro=a;

  for(int i=1;i<n;i++)
{
    cin>>b;
    a=__gcd(a,b);
    boro=max(boro,b);
}
  if(k<=boro && k%a==0)
    {
    cout<<"POSSIBLE"<<endl;
  }
  else
  {
    cout<<"IMPOSSIBLE"<<endl;
  }

}


Measured memory_bytes: 3620
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int n, cnt = 0, tmp, wc;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        tmp = i;
        wc = 0;
        while (tmp)
        {
            tmp /= 10;
            wc++;
        }
        if (wc % 2 == 1)
            cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define repeat(i, n) for(int i = 0; i < n; i++)
#define maxN 100

int
main(int argc, char *argv[])
{
  int n, a[maxN], color[9] = {}, min = 0;
  scanf("%d", &n);
  repeat(i, n){
    scanf("%d", &a[i]);
    if(a[i] / 400 < 8){
      color[a[i] / 400]++;
      if(color[a[i] / 400] == 1) min++;
    }
    else color[8]++;
  }

  printf("%d %d\n", (min > 1 ? min : 1), min + color[8]);

  return 0;
}


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

long long MOD=998244353LL;

long long fac[111111],finv[111111],inv[111111];

long long p2[111111];
int N,K;
 
void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<111111;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
 
long long COM(int n,int k){
	if(n<k)return 0;
	if(n<0 || k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
	cin >> K >> N;
	
	COMinit();
	p2[0]=1;
	for(int i=1;i<111111;i++)p2[i]=(p2[i-1]*2)%MOD;
	
	for(int i=2;i<=2*K;i++){
		long long ans=0LL;
		int p=(i-1)/2-max(0,i-1-K);
		if(i%2==1){
			for(int k=0;k<=p;k++){
				long long add=p2[k];
				add*=COM(N+(K-2*p+k-1)-k,K-2*p+k-1);
				add%=MOD;
				add*=COM(p,k);
				ans+=add;
				ans%=MOD;
			}
		}
		else{
			for(int k=0;k<=p;k++){
				long long add=p2[k];
				add*=COM(p,k);
				add%=MOD;
				add*=COM(N+((K-1)-2*p+k-1)-k,(K-1)-2*p+k-1)+COM(N-1+((K-1)-2*p+k-1)-k,(K-1)-2*p+k-1);
				add%=MOD;
				ans+=add;
				ans%=MOD;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
n,m=map(int, input().split())
res = [0]*n
wa = [0]*n
pena = 0
for i in range(m):
    p,s = map(str, input().split())

    if s == "AC":
        res[int(p)-1]=1
    if s == "WA" and not res[int(p)-1]:
        wa[int(p)-1]+=1
for i in range(n):
    if res[i]:
        pena += wa[i]
print(sum(res), pena)


Measured memory_bytes: 4596
import numpy as np

X,N = map(int,input().split())
P = list(map(int,input().split()))

P = set(P)
All = set( np.arange(0,102) )
Q = np.array(list(All-P))

Q_X = np.absolute( Q-X )
ans = Q[ np.argmin(Q_X ) ]

print(ans)


Measured memory_bytes: 27216
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

ll power(ll x,ll n)
{
    if(n==0){return 1;}
    if(n==1){return x;}
    if(n%2==0){
        return power((x*x)%M,n/2);
    }
    if(n%2==1){
        return (power((x*x)%M,n/2)*x)%M;
    }
}

ll ncr(ll n,ll r)
{
    ll ans,num=1,denum=1;
    for(ll i=1;i<=r;++i)
    {
        denum=(denum*i)%M;
        num=(num*(n-i+1))%M;
    }
    ans=(num*power(denum,M-2))%M;
    return ans;
}

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

	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=power(2,n);
	ans=(ans-ncr(n,a)+M)%M;
	ans=(ans-ncr(n,b)+M)%M;
	ans=(ans-1+M)%M;


	cout<<ans;

	return(0);
}


Measured memory_bytes: 256