akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


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

  ll ans = 0;
  rep(i, n) ans += ll(i+1)*ll(n-i);



  // VV G.assign(n, V());
  rep(i, n-1) {
    ll a, b; cin >> a >> b;
    --a; --b;
    // G[a].push_back(b);
    // G[b].push_back(a);
    if (a > b) swap(a, b);
    ans -= (a+1)*(n-b);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    static Scanner sc;

    final static int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        while (true) {
            int h = sn();
            int w = sn();
            if ((w | h) == 0) {
                break;
            }
            solve2(w, h);
        }
    }

    public static void solve(int w, int h) {
        int rr = rr(w, h);
        int min = INF;
        int minh = h, minw = w;
        for (int i = 1; i <= 150; i++) {
            for (int j = i + 1; j <= 150; j++) {
                int rr2 = rr(i, j);
                if ((h == i && w == j) || rr > rr2) {
                    continue;
                }
                if (min > rr2 || (min == rr2)) {
                    if (min == rr2) {
                        System.out.println(i + " " + j);
                        return;
                    }
                    min = rr2;
                    minh = i;
                    minw = j;
                }
            }
        }
        System.out.println(minh + " " + minw);
    }


    public static void solve2(int w, int h) {
        int rr = rr(w, h);
        for (int h1 = h + 1; h1 <= 150; h1++) {
            for (int w1 = h1 + 1; w1 <= 150; w1++) {
                if (rr(h1, w1) == rr) {
                    System.out.println(h1 + " " + w1);
                    return;
                }
            }
        }

        for (int rr2 = rr + 1, l = 150 * 150; rr2 <= l; rr2++) {
            for (int h1 = 1; h1 < rr2; h1++) {
                double h2 = Math.sqrt(h1);
                double w2 = Math.sqrt(Math.floor(rr2) - h1);
                if (isInt(h2) && isInt(w2) && (h2 != w2)) {
                    System.out.println((int)h2 + " " + (int)w2);
                    return;
                }
            }
        }

    }
    public static boolean isInt(double n) {
        return n == Math.floor(n);
    }

    public static int rr(int w, int h) {
        return w * w + h * h;
    }

    public static int sn() {
        return sc.nextInt();
    }
}

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

int main(){
  string s;
  cin >> s;
  
  int ans = 0;
  for(int i = 0; i < 4; i++){
    if(s[i] == '+') ans++;
    else ans--;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;


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

    string s;cin >> s;
    int n = s.length();
    int k;cin >> k;
    vector<vi> dp(n+1, vi(n+1));
    vector<vi> prev(n+1, vi(n+1));
    for(int change = 0; change <= k; change++){
        for(int len = 1; len <= n; len++){
            for(int start =0; start <= n - len; start++){
                dp[start][len] = max(dp[start+1][len-1], dp[start][len-1]); 
                if(s[start] == s[start + len -1]){
                    dp[start][len] = max(1 + (len != 1) + dp[start+1][max(len-2,0LL)], dp[start][len]);
                }else if(change > 0){
                    dp[start][len] = max(1 + (len != 1) + prev[start+ 1][max(len-2,0LL)], dp[start][len]); 
//                cout << dp[start][len] <<  " ";
                }
            }
//            cout << endl;
        }
        swap(dp, prev);
    }
    cout << prev[0][n];
}





Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>

#define STR_MAX 100
#define MAX_NODE 500001

// ノード型定義
typedef struct _NODE{
    int key;
    struct _NODE *right;
    struct _NODE *left;
} NODE;

// ノード用RAM管理
NODE node_pool[MAX_NODE];
int node_cnt;
NODE *make_node(int key);

// ツリー操作
NODE *insert_tree(NODE *root,int k);
void print_tree(NODE *root);
void print_tree_inorder(NODE *node);
void print_tree_preorder(NODE *node);

/////////////////////////////
// メイン処理
int main(){
    int i;
    int m,k;
    NODE *root;
    char buf[STR_MAX];

    node_cnt = 0;
    root = NULL;

    // 命令数を読み込んでループ
    scanf("%d%*c",&m);
    for( i=0; i<m; i++){
        // 命令を読み込んで処理
        fgets(buf,STR_MAX,stdin);
        if(strncmp(buf,"insert",6)==0){
            // insert
            sscanf(buf,"%*s %d",&k);
            root = insert_tree(root,k);
        }else if(strncmp(buf,"print",5)==0){
            // print
            print_tree(root);
        }else{
            //処理なし
        }
    }

    return 0;
}


/////////////////////////////
// ツリー操作

// 要素追加
// ツリーのルートを返す
NODE *insert_tree(NODE *root,int k){
    NODE *new_root = root;
    NODE *y = NULL; // x の親
    NODE *x = root;
    NODE *z = make_node(k);

    while( x != NULL ){
        y = x; // 親を設定
        if( z->key < x->key ){
            x = x->left; // 左の子へ移動
        }else{
            x = x->right; // 右の子へ移動
        }
    }

    if( y == NULL){ // T が空の場合
        new_root = z;
    }else if( z->key < y->key){
        y->left = z; // z を y の左の子にする
    }else{
        y->right = z; // z を y の右の子にする
    }

    return new_root;
}

// 内容表示
void print_tree(NODE *root){
    print_tree_inorder(root);
    printf("\n");
    print_tree_preorder(root);
    printf("\n");
}
// 中間順巡回
void print_tree_inorder(NODE *node){
    if(node==NULL) return;
    print_tree_inorder(node->left);
    printf(" %d",node->key);
    print_tree_inorder(node->right);
}

// 先行順巡回
void print_tree_preorder(NODE *node){
    if(node==NULL) return;
    printf(" %d",node->key);
    print_tree_preorder(node->left);
    print_tree_preorder(node->right);
}

//////////////////////
//ノード用RAM管理

//新規ノード作成
NODE *make_node(int key){
    NODE *node = &node_pool[node_cnt];
    node_cnt++;
    node->key   = key;
    node->right = NULL;
    node->left  = NULL;
    return node;
}




Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep_r(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define resize(x, n) x.resize(n)
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MAX = 100000;
struct edge {
    ll from, to, weight;
    edge(ll f, ll t, ll w) : from(f), to(t), weight(w) { }
};
vector<vector<edge>> edges;
vector<vector<ll>> graph;
vector<bool> visited;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll n, k;

ll dp[2001][2001];

ll c(ll n, ll r) {
    if (n < r) return 0;
    if (dp[n][r] != -1) return dp[n][r];
    if (n == r || r == 0) return 1;
    if (r == 1) return dp[n][r] = n;
    return dp[n][r] = (c(n-1, r-1) + c(n-1, r)) % mod;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    cin >> k;
    ll blue = k, red = n-k;
    for (ll i = 1; i <= k; i++) {
        ll answer = c(red+1, i) * c(blue-1, i-1) % mod;
        // printf("%lld回の場合 %lld\n", i, answer);
        cout << answer << "\n";
    }
}

Measured memory_bytes: 34988
#include<stdio.h>

int sum(int *p,int n,int i){
  if(i==n){
    return 0;
  }
  else{
    return p[i]+sum(p,n,i+1);
  }
}

void doit(int n){
  int a[n][n];
  int b[n];
  int c[n];
  int atr[n][n];
  int all;
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j]);
      atr[j][i]=a[i][j];
    }
  }
  for(i=0;i<n;i++){
    b[i]=sum(a[i],n,0);
    c[i]=sum(atr[i],n,0);
  }
  all=sum(b,n,0);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%5d",a[i][j]);
    }
    printf("%5d\n",b[i]);
  }
  for(i=0;i<n;i++){
    printf("%5d",c[i]);
  }
  printf("%5d\n",all);
}

int main(){
  int n;
  scanf("%d",&n);
  while(n!=0){
    doit(n);
    scanf("%d",&n);
  }
  return 0;
}

Measured memory_bytes: 612
def judge(s,t):
    j = True
    if len(s) != len(t):
        return False
    for i in range(len(s)):
        if s[i] != '':
            if(s[i] == t[i] or s[i] == '?') :
                continue
            else:
                j  = False
        else:
            j = False
    return j
            
s = input()
t = input()
ans = 'z'*50
ok = False

for i in range(len(s)):
    if judge(s[i:(len(t)+i)],t):
        ok = True
        s1 = s[0:i]
        s1 += t
        s1 += s[len(t)+i:len(s)]
        if ans > s1:
            ans = s1
if ok :
    print(ans.replace('?','a'))
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input);
    let sec: i32 = input.trim().parse().unwrap();
    let s = sec % 60;
    let m = (sec - s) % 3600 / 60;
    let h = sec / 3600;
    println!("{}:{}:{}", h, m, s);
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll c[3][3];
    for (ll i = 0; i < 3;i++){
        for (ll j = 0; j < 3;j++){
            cin >> c[i][j];
        }
    }
    bool flag = true;
        ll a[3], b[3];
        a[0] = 0;
        a[1] = c[1][0] - c[0][0];
        a[2] = c[2][0] - c[0][0];
        b[0] = c[0][0];
        b[1] = c[0][1];
        b[2] = c[0][2];
        for (ll i = 0; i < 3;i++){
            for (ll j = 0; j < 3;j++){
                if (c[i][j] != (a[i] + b[j])) flag = false;
            }
        }
    cout << (flag ? "Yes" : "No") << endl;
}

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

using namespace std;

int n, w, p, o;
int pesos[103];
int objetos[103];
long long dp[100003];
bool marcados[103];

long long hallar_peso()
{
    long long resp = 0;
    for(int i = 1; i <= n; i++)
    {
        if(marcados[i])
            resp += pesos[i];
    }
    return resp;
}

long long hallar_valor()
{
    long long resp = 0;
    for(int i = 1; i <= n; i++)
    {
        if(marcados[i])
            resp += objetos[i];
    }
    return resp;
}

long long mochilita_recursiva(int pos)
{
    if(pos == n + 1)
    {
        if(hallar_peso() <= w)
            return hallar_valor();
        else
            return 0;
    }
    else
    {
        marcados[pos] = true;
        long long lo_pongo = mochilita_recursiva(pos + 1);

        marcados[pos] = false;
        long long lo_quito = mochilita_recursiva(pos + 1);

        return max(lo_pongo, lo_quito);
    }
}

void inicializar()
{
    for(int i = 0; i < 100001; i++)
    {
        dp[i] = -1;
    }
    dp[0] = 0;
}

long long dame_maximo()
{
    long long maximo = LLONG_MIN;
    for(int i = 0; i < 100001; i++)
    {
        maximo = max(maximo, dp[i]);
    }
    return maximo;
}

long long mochilita_dinamica()
{
    inicializar();
    for(int i = 1; i <= n; i++)
    {
        for(int j = w; j >= 0; j--)
        {
            int q = j - pesos[i];
            if(q >= 0 && dp[q] != -1)
                dp[j] = max(dp[j], dp[q] + objetos[i]);
        }
    }
    long long resp = dame_maximo();
    return resp;
}

long long solucion_recursiva()
{
    long long resp = mochilita_recursiva(1);
    return resp;
}

long long solucion_dinamica()
{
    long long resp = mochilita_dinamica();
    return resp;
}

int main()
{
    cin >> n >> w;

    for(int i = 1; i <= n; i++)
    {
        cin >> p >> o;
        pesos[i] = p;
        objetos[i] = o;
    }

    long long resp_dinamica = solucion_dinamica();
    //long long resp_recursiva = solucion_recursiva();

    //cout << "dinamico = " << resp_dinamica << " y recursiva = " << resp_recursiva << endl;
    cout << resp_dinamica << endl;
}


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

int main(){
    int i, j;
    char c;
    for(i=0; i<3; i++){
        for(j=0; j<3; j++){
            cin >> c;
            if(i == j){
                cout << c;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

typedef long long ll;

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

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

ll asc(const void* a, const void* b) { return *(ll*)a - *(ll*)b; }

ll dsc(const void* a, const void* b) { return *(ll*)b - *(ll*)a; }

int main() {
    ll n;
    scanf("%lld", &n);
    if (n >= 30) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 2140
import sys
input = sys.stdin.readline
N = int(input())
S = []
for _ in range(N):
    s = input().replace("\n", "")
    S.append(s)
S.sort()
f = 0
tres = 0
res = [S[0]]
for i in range(1, N):
    if S[i] == S[i-1]:
        f += 1
    else:
        f = 0
    if f == tres:
        res.append(S[i])
    elif f > tres:
        tres = f
        res = [S[i]]

print("\n".join(map(str, res)))


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

int main() {
    int A , B , C ;
    cin >> A >> B >> C ; // 1 ≤ A,B,C ≤ 13
    if ((A + B + C) >= 22) cout << "bust" << endl ;
    else cout << "win" << endl ;
	return 0;
}

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

void solve(long long N, std::vector<long long> a)
{
    long long cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
            cnt++;
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 3688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(br.readLine());
        final int h = Integer.parseInt(tok.nextToken());
        final int w = Integer.parseInt(tok.nextToken());
        char[][] mat = new char[h][w];
        boolean[] colVisible = new boolean[w];

        // 読み込み
        int cnt = 0;
        boolean flag;
        String row;
        char c;
        for (int i = 0; i < h; i++) {
            flag = false;
            row = br.readLine();
            for (int j = 0; j < w; j++) {
                c = row.charAt(j);
                mat[cnt][j] = c;
                if (c == '#') {
                    flag = true;
                    colVisible[j] = true;
                }
            }
            if (flag) cnt++;
        }
        // 表示
        for (int i = 0; i < cnt; i++) {
            for (int j = 0; j < w; j++) {
                if (!colVisible[j]) continue;
                System.out.print(mat[i][j]);
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 23124
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            N, M = map(int, raw_input().split())
            if N == M == 0:
                break
            record = [[0] * 2000 for i in range(M+1)]
            r = input()        
            for i in range(r):
                t, n, m, s = map(int, raw_input().split())
                if s == 1:
                    record[m][t] += 1
                else:
                    record[m][t] -= 1
            # for row in record:
            #     print row[540:1000]
            for i in range(1, M+1):
                for j in range(540, 1261):
                    record[i][j] += record[i][j-1]
            # for row in record:
            #     print row[540:1000]                    
            q = input()
            for i in range(q):
                ts, te, m = map(int, raw_input().split())
                ans = 0
                for j in range(ts, te):
                    if record[m][j] >= 1:
                        ans += 1
                print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 252736
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int X; cin >> X;
	int y = 8-(X-400)/200;
	cout<<y;
	
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    string s, t;
    cin>> s >> t;
    string s_double = s + s;
    int s_len = s.size();
    vvi s_next(26, vi(s_len, -1));
    long length = 1;

    for(int i = s_len * 2 - 1; i > 0; i--){
        REP(j, 0, 26){
            if(s_double[i] == 'a' + j) s_next[j][(i-1)%(s_len)] = 1;
            else if(s_next[j][i%(s_len)] != -1) s_next[j][(i-1)%(s_len)] = s_next[j][i%(s_len)] + 1;
        }
    }
    int s_pos = 0;
    REP(i, 0, t.size()){
        if(s_next[t[i]- 'a'][s_pos] == -1){
            length = -1;
        }else{
            if(i == 0 && s[i] == t[i]) continue;
            else if(length > 0) length += s_next[t[i] - 'a'][s_pos];
            s_pos += s_next[t[i] - 'a'][s_pos];
            s_pos %= s_len;
        }
    }
    cout << length << endl;
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}

int main()
{
    fastio();
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    int n;
    cin>>n;
    std::vector<pair<ll,ll> > v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i].ff>>v[i].ss;
    }
    sort(all(v));
    int c=0;
    ll rm = v[0].ff+v[0].ss;
    for(int i=1;i<n;i++)
    {
        if(v[i].ff-v[i].ss<rm)
        {
            c++;
            rm = min(rm,v[i].ff+v[i].ss);
        }
        else 
        {
            rm=v[i].ff+v[i].ss;
        }
    }
    cout<<n-c<<endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N];
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
      if (min > a[i]) {
        min = a[i];
      }
      if (max < a[i]) {
        max = a[i];
      }
    }
    int cost = Integer.MAX_VALUE;
    for (int i = min; i <= max; i++) {
      int tmp = 0;
      for (int j = 0; j < N; j++) {
        tmp += getCost(a[j], i);
      }
      if (cost > tmp) {
        cost = tmp;
      }
    }
    System.out.println(cost);
  }

  public static int getCost(int x, int y) {
    return (x - y) * (x - y);
  }
}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)10)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 15

int solve(vector<int> D, int depth = 0){
	int res = INF, b = -1, num;
	// cout<<"depth "<<depth<<endl;
	
	// for(int i = 0; i < D.size(); i++) cout<<" "<<D[i];cout<<endl;
	for(int i = 0; i < D.size(); i++){
		if(D[i]){
			b = i;
			num = D[i];
			break;
		}
	}
	// cout<<b<<endl;
	if(b == -1) return 0;
	
	for(int i = b; i < D.size(); i++){
		D[i] = (D[i] - num + MOD)%MOD;
		// cout<<"depth"<<depth<<" i = "<<i<<" "<<D[i]<<endl;
		res = min(solve(D,depth+1)+1,res);
		
		// cout<<i<<" "<<res<<" "<<b<<endl;
	}
	
	return res;
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A;
	vector<int> D;
	string B, C;
	
	while(true){
		cin>>A;
		
		if(!A) break;
		
		D.clear();
		
		cin>>B>>C;
		
		for(int i = 0; i < A; i++){
			D.push_back((B[i] - C[i] + MOD)%MOD);
			// cout<<i<<" "<<D[i]<<endl;
		}
		
		cout<<solve(D)<<endl;
	}
	
	
	return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

int n,m;
int l[200000],r[200000],d[200000];
vector<edge> g[100000];
ll dist[100000];
bool used[100000];

bool dfs(int V) {
	dist[V]=0;
	queue<int> Q;
	Q.push(V);
	used[V]=false;
	while(!Q.empty()) {
		int v=Q.front();Q.pop();
		for(auto e:g[v]) {
			if(dist[e.to]!=-LINF) {
				if(dist[e.to]==dist[v]+e.cost) continue;
				else {
					return false;
				}
			}
			else {
				dist[e.to]=dist[v]+e.cost;
				used[e.to]=false;
				Q.push(e.to);
			}
		}
	}
	return true;
}

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

	cin>>n>>m;
	REP(i,m) {
		cin>>l[i]>>r[i]>>d[i];
		l[i]--,r[i]--;
		g[l[i]].pb(edge(r[i],d[i]));
		g[r[i]].pb(edge(l[i],-d[i]));
		used[l[i]]=used[r[i]]=true;
	}
	REP(i,n) dist[i]=-LINF;
	REP(i,n) {
		if(used[i]) {
			if(dfs(i)==false) {
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;

	return 0;
}


Measured memory_bytes: 12160
#include<iostream>

using namespace std;

#define N 100

//grobal
int data[N],num1,num2;

//flag
bool flag=false;

//function solve
bool solve(int i,int m){

  //if i >num1 or m<0 then false
  if(i>num1 ||m<0) return false;

  //if m=0 then  true
  if(m==0){
    flag=true;
    return true;
  }
  //execute
  solve(i+1,m);
  solve(i+1,m-data[i]);  

}


int main(){

  int i,m;

  //load number
  cin >>num1;

  //load data
  for(i=0;i<num1;i++){
    cin >>data[i];
  }
  //load number
  cin >>num2;
  //load  data and execute
  for(i=0;i<num2;i++){
    cin >>m;
    //initial flag
    flag=false;
    //execute solve
    solve(0,m);

    //print yes or no
    if(flag==true){
      cout <<"yes"<<endl;
    }  
    else cout <<"no"<<endl;
  }

  return 0;
}

Measured memory_bytes: 856
import java.util.*;
import java.io.*;
class Main
{
    public static void main(String args[])
    {
        Scanner sc= new Scanner(System.in);
        int  a=sc.nextInt();
        int b = sc.nextInt();
        if(a*b%2==1)
        System.out.println("Odd");
        else
        System.out.println("Even");
    }
}

Measured memory_bytes: 21972
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

namespace std {
    template <>
    class hash<std::pair<int, int>> {
    public:
        size_t operator()(const std::pair<int, int>& x) const{
            return hash<int>()(x.first) ^ hash<int>()(x.second);
        }
    };
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],b[100010],d[100010]={};
    ll cnt[100010]={};
    ll ans[100010]={};
    ll c=0;
    cin>>n;
    bool V[200010];
    map<pll,ll> mp;
    vector<pll> G[200010];
    rep(i,n-1){
        cin>>a[i]>>b[i];
        G[a[i]].pb(pll(b[i],i));
        G[b[i]].pb(pll(a[i],i));
        cnt[a[i]]++;
        cnt[b[i]]++;
        c=max(c,cnt[a[i]]);
        c=max(c,cnt[b[i]]);
    }
    cout<<c<<endl;
    queue<pll> que;
    que.push(pll(1,0));
    while(!que.empty()){
        pll u=que.front();
        que.pop();
        ll now=1;
        V[u.fi]=1;
        for(auto i:G[u.fi]){
            // cout<<i<<" "<<u<<endl;
            if(V[i.fi]==1) continue;
            if(now==d[u.fi]) now++;
            ans[i.sc]=now;
            d[i.fi]=now;
            now++;
            que.push(i);
        }
    }
    /*
    for(auto i:mp){
        cout<<i.fi.fi<<"#"<<i.fi.sc<<"#"<<i.sc<<endl;
    }
    */
    rep(i,n-1){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 14464
#include <algorithm>
#include <iostream>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

using Int = long long;
using Event = tuple<Int, Int, Int>;

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

    vector<Event> E;
    for (int i = 0; i < N; i++) {
        Int s, t, x;
        cin >> s >> t >> x;

        E.push_back({s - x, -1, x});
        E.push_back({t - x, 0, x});
    }
    for (int i = 0; i < Q; i++) {
        Int d;
        cin >> d;

        E.push_back({d, 1, i});
    }
    sort(E.begin(), E.end());

    vector<Int> res(Q);
    multiset<Int> S;
    for (auto e : E) {
        Int x, t, v;
        tie(x, t, v) = e;

        switch (t) {
        case -1:
            S.insert(v);
            break;
        case 0:
            S.erase(S.lower_bound(v));
            break;
        case 1:
            res[v] = (S.empty() ? -1 : *(S.begin()));
            break;

        default:
            break;
        }
    }

    for (auto r : res) {
        cout << r << '\n';
    }
}


Measured memory_bytes: 26724
#include<bits/stdc++.h>
using namespace std;
int main()
{
 	int i,j,k,n;
  cin>>n;
  long long int a,b;
  map<long long int,long long int> mp;
  for(i=0;i<n;i++)
  {
    cin>>a>>b;
    mp[a]=b;
  }
  map<long long int,long long int>:: iterator it;
  map<long long int,long long int>:: iterator it1,x,y;
  it1=mp.begin();
  it1++;
  for(it=mp.begin();it!=mp.end() && it1!=mp.end();)
      {
    
                // cout<<"begin"<<it->first<<" "<<it1->first<<"\n";

        if((it->first +it->second) > (it1->first - it1->second))
        {
          	if((it->first + it->second) > (it1->first + it1->second))
            {
                // cout<<it->first<<" ";
                x=it;
                y=it1;
                x++;
                y++;
                
              mp.erase(it);
              it=x;
              it1=y;
            }
          else
          {
            // cout<<it1->first<<" ";
            x=it1;
            x++;
            mp.erase(it1);
            // cout<<it1->first<<"hi";
            it1=x;
          }
        }
        else
        {
            it++;
            it1++;
        }
        // cout<<it->first<<" "<<it1->first<<"\n";
      }
    //   for(it=mp.begin();it!=mp.end();it++)
    //   {
    //       cout<<it->first<<" ";
    //   }
  cout<<mp.size();
}

Measured memory_bytes: 6528
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    def uniq(arr):
        ret = [arr[0]]
        for a in arr[1:]:
            if ret[-1] == a:
                continue
            ret.append(a)
        return ret

    def compress(arr):
        if len(arr) <= 2:
            return arr
        ret = [arr[0]]        
        for a0, a1, a2 in zip(arr, arr[1:], arr[2:]):
            if a0 < a1 < a2 or a0 > a1 > a2:
                continue
            ret.append(a1)
        ret.append(arr[-1])
        return ret

    B = uniq(A)
    C = compress(B)
    if len(C) == 1:
        return 1000
    ans, m, s = 1000, 1000, 0
    for c0, c1 in zip(C, C[1:]):
        if c0 < c1:
            t = m // c0
            s += t
            m -= t * c0
        else:
            m += c0 * s
            s = 0
        ans = max(ans, m)
    else:
        m += c1 * s
        ans = max(ans, m)
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 8996
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;    
    }
    return sum;
}
/// 最大公約数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
string S;
cin >> S;
int Z = INT_MAX;
for(int i = 0;i<S.size()-1;i++){
    string s = S;
    int x = stoi(s.substr(i,3));
    Z = min(Z,abs(753-x));
}
cout << Z << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int X, Y;

ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1)a = a*x%mod;
		x = x*x%mod;
		y /= 2;
	}
	return a;
}

ll modinv(ll x) {
	return pw(x, mod - 2);
}

int comb(int n, int r) {
	if (r < 0 || n < r)return 0;
	ll a = 1;
	ll b = 1;
	for (ll i = 0; i < r; i++) {
		a *= n - i;
		a %= mod;
		b *= i + 1;
		b %= mod;
	}
	return (a*modinv(b)) % mod;
}

int main() {
	cin >> X >> Y;
	if ((2 * X - Y) % 3) {
		cout << 0 << endl;
		return 0;
	}
	cout << comb((X + Y) / 3, (Y + Y - X) / 3) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
#define IMAX 0x3f3f3f3f
#define LLMAX 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef double db;
inline int read() {
  int x=0,f=1;
  char c=getchar();
  while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
  while(isdigit(c)){x=x*10+c-'0';c=getchar();}
  return x*f;
}
int x,y,z;

signed main() {
  x=read(),y=read(),z=read();
  swap(x,y);swap(x,z);
  printf("%d %d %d",x,y,z);
  return 0;
}

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

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(K <= A) out(K);
    else if(A < K && K <= A+B) out(A);
    else out(A-(K-A-B));
}
int main() {
    INCANT;
    solve();
    return 0;
}




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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int A[2111111];
int B[2111111];
int seica[11111];


int main(){
	
	REP(i,1111111)A[i] = B[i] = INF;
	A[0] = B[0] = 0;
	REP(i,11111){
		seica[i] = i*(i+1)*(i+2)/6;
		if(seica[i] > 1000000)break;
	}
	
	REP(i,1000000){
		for(int j = 1;j < 10000;j++){
			A[i+seica[j]] = min(A[i]+1,A[i+seica[j]]);
			if(i + seica[j] > 1000000)break;
		}
	}
			
	REP(i,1000000){
		for(int j = 1;j < 10000;j++){
			if(seica[j]%2==1)B[i+seica[j]] = min(B[i]+1,B[i+seica[j]]);
			if(i + seica[j] > 1000000)break;
		}
	}	
	
	DBG(SHOW1d(A,100);)
	DBG(SHOW1d(B,100);)
	
	int n;
	while(cin >> n ,n){
		cout << A[n] << ' ' << B[n] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 11756
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

class FactInv:
    def __init__(self, N, MOD=1000000007):
        fact, inv = [1]*(N+1), [None]*(N+1)
        for i in range(1, N+1): fact[i] = fact[i - 1] * i % MOD
        inv[N] = pow(fact[N], MOD - 2, MOD)
        for i in range(N)[::-1]: inv[i] = inv[i + 1] * (i + 1) % MOD
        self.N, self.MOD, self.fact, self.inv = N, MOD, fact, inv

    def perm(self, a, b):
        if a > self.N or b > self.N: raise ValueError("\nPermutaion arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b))
        return self.fact[a] * self.inv[a-b] % self.MOD

    def comb(self, a, b):
        if a > self.N or b > self.N: raise ValueError("\nCombination arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b))
        return self.fact[a] * self.inv[b] * self.inv[a-b] % self.MOD

def main():
    S = I()
    n = math.floor(S / 3.0)
    factinv = FactInv(S)

    ans = 0
    for i in range(1, n+1):
        ans = (ans + factinv.comb(S - 2 * i - 1, i - 1)) % MOD
    print(ans % MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 72976
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

template<class T>bool chmax(T &a, const T &b) {
   if (a < b) {
      a = b;
      return 1;
   }
   return 0;
}
template<class T>bool chmin(T &a, const T &b) {
   if (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll nR, nG, nB;
ll N, A;
ll ans;
const ll kMod = 1000000007;
int main()
{
   cout << fixed << setprecision(10);
   ans = 1;
   cin >> N;
   REP(i, N) {
      cin >> A;
      if (nR == A) {
         if (nG == A) {
            if (nB == A) {
               ans = ans * 3 % kMod;
               nR++;
            } else {
               ans = ans * 2 % kMod;
               nR++;
            }
         } else {
            if (nB == A) {
               ans = ans * 2 % kMod;
               nR++;
            } else {
               nR++;
            }
         }
      } else {
         if (nG == A) {
            if (nB == A) {
               ans = ans * 2 % kMod;
               nG++;
            } else {
               nG++;
            }
         } else {
            if (nB == A) {
               nB++;
            } else {
               cout << 0 << endl;
               return 0;
            }
         }
      }
   }
   cout << ans << endl;
      
   return 0;
}



Measured memory_bytes: 256
x,y = map(int, input().split())

import sys
sys.setrecursionlimit(200000000)
p = 10**9+7

def exp(y,x):
  xbin=str(bin(x))[2:]
  ans=1
  yl=[0]*(len(xbin)+1)
  yl[0]=y
  yl[1]=y**2
  for d,i in enumerate(xbin[::-1],start=0):
    if d > 1:
      yl[d]=yl[d-1]**2%p
    if i == "1":
      ans=(ans*yl[d])%p
  return ans%p

def ff(n,ca):
  if ca == 0:
    return 1
  if ca == 1:
    return n
  return n*ff(n-1,ca-1)%p

if (y+x)%3 != 0:
  print(0)
elif y/x > 2:
  print(0)
elif y/x < 0.5:
  print(0)
else:
  n=(2*x-y)//3
  m=(2*y-x)//3
  fact=1
  for i in range(2,n+1):
    fact=fact*i%p
  ans=ff(n+m,n)*exp(fact,p-2)%p
  print(ans)

Measured memory_bytes: 300148
<?php
$n=trim(fgets(STDIN));
if($n==1){
  echo trim(fgets(STDIN))==1?0:1;
}else{
  $a=explode(' ',trim(fgets(STDIN)));
  $a=array_count_values($a);
  $ans=0;
  foreach($a as $k=>$v){
    $ans+=$k<=$v?$v-$k:$v;
  }
  echo $ans;
}

Measured memory_bytes: 19188
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        int n = Integer.valueOf(scan.next());
        Integer[] ns = new Integer[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        for(int i = 1;i<=ns.length-1;i++) {
        	int cnt=0;
    	    for(int val:ns) {
    	    	if(cnt==n-1) break;
    	    	System.out.print(val+" ");
    	    	cnt++;
    	    }
    	    System.out.println(ns[n-1]);
    	    int key = ns[i];
    	    int j = i - 1;
    	    while(j >= 0 && ns[j] > key) {
    	        ns[j+1] = ns[j];
    	        j--;
    	    }
    	    ns[j+1] = key;
        }
        int cnt=0;
	    for(int val:ns) {
	    	if(cnt==n-1) break;
	    	System.out.print(val+" ");
	    	cnt++;
	    }
	    System.out.println(ns[n-1]);
        scan.close();
    }
}


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

#define EPS (1e-7)
#define INF (1<<25)
#define PI (acos(-1))

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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; }

using ll = long long;

int main() {
  int n; cin >> n;
  vector<string> s(n);
  REP(i,n) cin >> s[i];
  vector<int> cnt(26,INF), tmp(26,0);
  REP(i,n) {
    REP(j,26) tmp[j] = 0;
    REP(j,s[i].size()) tmp[s[i][j]-'a']++;
    REP(j,26) chmin(cnt[j], tmp[j]);
  }
  string ans;
  REP(i,26) REP(j,cnt[i]) ans.push_back(i+'a');
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List
main = do
    n <- readLn
    a <- replicateM n readLn
    let ml = take n (scanl (max) 0 a)
    let mr = drop 1 (scanr (max) 0 a)
    let m = zipWith (max) ml mr
    forM_ m print


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



i64 n, a[101010], d[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < n; i++){
		d[i+1] = a[i]-d[i];
	}
	
	d[0] = d[n];
	for(int i = 0; i < n; i++){
		cout << d[i] << " ";
		d[i+1] = (a[i]-d[i]/2)*2;
	}
	cout << endl;
}

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


Measured memory_bytes: 2944
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1), B(N);
    for (int i = 0; i < N + 1; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (B[i] >= A[i]) {
            if (A[i+1] >= B[i]-A[i]) {
                A[i + 1] -= (B[i] - A[i]);
                ans += B[i];
            } else {
                ans += (A[i] + A[i+1]);
                A[i+1] = 0;
            }
        } else {
            ans += B[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024