akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
struct A {
	ll a/*??????*/, b/*??????*/, c/*???????????????(vector)*/;
};
struct P {
	ll a/*???*/, i/*???*/, j/*??????*/, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
vector<A>a[2][100100];
ll b[400100], inf = 999999999999999999;
int main() {
	ll h, w, k;
	cin >> w >> h >> k;
	for (ll i = 0; i < k*2; i+=2) {
		ll x, y;
		cin >> x >> y;
		a[0][x].push_back(A{ y,i,(ll)a[1][y].size() });
		a[1][y].push_back(A{ x,i + 1,(ll)a[0][x].size() - 1 });
	}
	a[0][1].push_back(A{ 1,k*2,(ll)a[1][1].size() });
	a[0][w].push_back(A{ h,k*2 + 1,(ll)a[1][h].size() });
	a[1][h].push_back(A{ w,k*2 + 2,(ll)a[0][w].size() - 1 });
	fill(b, b + k * 2 + 100, inf);
	priority_queue<P, vector<P>, greater<P>>p;
	b[k*2] = 0;
	p.push(P{ 0,1,(ll)a[0][1].size() - 1,0 });
	while (!p.empty()) {
		P t = p.top(); p.pop();
		int c, d;
		if (t.a == 0) {
			c = 0;
			d = 1;
		}
		else {
			c = 1;
			d = 0;
		}
		for (ll i = 0; i < a[c][t.i].size(); i++) {
			ll res = abs(a[c][t.i][t.j].a - a[c][t.i][i].a);
			if (res + t.cost < b[a[c][t.i][i].b]) {
				b[a[c][t.i][i].b] = res + t.cost;
			}
			if (a[c][t.i][i].b!=k*2&&b[a[d][a[c][t.i][i].a][a[c][t.i][i].c].b] > t.cost + res + 1) {
				b[a[d][a[c][t.i][i].a][a[c][t.i][i].c].b] = t.cost + res + 1;
				p.push(P{ d, a[c][t.i][i].a, a[c][t.i][i].c, b[a[d][a[c][t.i][i].a][a[c][t.i][i].c].b] });
			}
		}
	}
	ll ans = min(b[k*2 + 1], b[k*2 + 2]);
	if (ans >= inf) cout << -1 << endl;
	else cout << ans << endl;
}

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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;  // 初期状態
  for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  // 1-index にしておく
  
  bool can = true;
  for (int i = 0; i < N; ++i) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) can = false;
    if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
  }
  
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
/**
 * D - RGB Tripletsc
 * https://atcoder.jp/contests/abc162/tasks/abc162_d
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
    // R, G, B のみからなる、長さ N の文字列 S があります。
    int N;
    string S;
    cin >> N >> S;

    // 以下の 2 つの条件をともに満たす組 (i, j, k) (1≤i<j<k≤N) の数を求めてください。
    // Si≠Sj かつ Si≠Sk かつ Sj≠Sk である
    // j−i≠k−j である
    int r = 0, g = 0, b = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            r++;
        } else if (S[i] == 'G') {
            g++;
        } else if (S[i] == 'B') {
            b++;
        }
    }

    // Si≠Sj かつ Si≠Sk かつ Sj≠Sk である
    // RとGとBの組み合わせによって決まる
    long long cnt = r;
    cnt *= g;
    cnt *= b;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int k = 2 * j - i;
            if (k >= N) {
                continue;
            }

            // Si≠Sj かつ Si≠Sk かつ Sj≠Sk である
            if  (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
                cnt -= 1;
            }
        }
    }

    cout << cnt << endl;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    
    if (a < b)
        if (b < c) cout << "Yes" << endl;
        else cout << "No" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3096
import itertools
import numpy as np

N,M,X = map(int,input().split())
CA = [list(map(int,input().split())) for i in range(N)]
CA = np.array(CA)
# print(CA)

C = [CA[i][0] for i in range(N)]
# print(C)
min_ans = 10**7

l = range(N)

for i in range(N):
    c = list(itertools.combinations(l, i+1))
    for j in range(len(c)):
        # print(c[j])
        target_book = np.array([CA[a] for a in c[j]])
        rikai = np.sum(target_book,axis=0)
        # print(rikai[1:])
        # print(target_book)
        # print(rikai)

        if min(rikai[1:]) >= X and min_ans > rikai[0]:
            # print(rikai[1:])
            # print(target_book)
            # print(rikai)
            min_ans = rikai[0]

if min_ans != 10**7:
    print(min_ans)
else:
    print(-1)


Measured memory_bytes: 27708
def yaku(n):
    l=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            l+=[(i,n//i)]
    return l
        

def resolve():
    n=int(input())
    l=yaku(n)
    ans=[i[0]+i[1]-2 for i in l]
    print(min(ans))
resolve()

Measured memory_bytes: 39280
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

int x[MX];
int y[MX];
int a;
signed main() {
  int h,w,d;
  cin >> h >> w >> d;
  vector<int> dd(h*w+1,0);
  rep(i,h) {
    rep(j,w) {
      cin >> a;
      x[a]=i;
      y[a]=j;
    }
  }
  for(int i = d+1; i<=h*w; i++) {
    dd[i]= dd[i-d]+abs(x[i-d]-x[i])+abs(y[i-d]-y[i]);
  }
  int q;
  cin >> q;
  rep(i,q){
    int l,r;
    cin >> l >> r;
    cout << dd[r]-dd[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 5172
#include <iostream>

int main() {
    int64_t n;
    std::cin >> n;

    int64_t ans = 1e12;
    for (int64_t i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ans = std::min(ans, (i - 1) + (n / i - 1));
        }
    }

    std::cout << ans << std::endl;
    return 0;
}


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

using namespace std;

struct Edge {
    int from, to, cap, rev;
    Edge() {}
    Edge(int from, int to, int cap, int rev) : from(from), to(to), cap(cap), rev(rev) {}
};
int V, E;
vector< vector<Edge> > G;
vector<bool> used;
void init() {
    G.clear(); G.resize(V);
    used.clear(); used.resize(V);
}
void addEdge(int from, int to, int cap) {
    G[from].push_back(Edge(from, to, cap, G[to].size()));
    G[to].push_back(Edge(to, from, 0, int(G[from].size()) - 1));
}
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        Edge& e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
int solve(int s, int t) {
    int flow = 0;
    while (true) {
        fill(used.begin(), used.end(), false);
        int f = dfs(s, t, 1e9);
        if (f == 0) return flow;
        flow += f;
    }
}

int main() {
    cin >> V >> E;
    init();
    for (int i = 0; i < E; i++) {
        int u, v, c; cin >> u >> v >> c;
        addEdge(u, v, c);
    }
    cout << solve(0, V - 1) << endl;
    return 0;
}

Measured memory_bytes: 1268
import numpy as np
import copy

N= int(input())
S=input()
SS= copy.copy(S)
S = list(S)
#N, A, B = map(int, input().split())

flag = 1
#print(len(S))
while flag == 1:
    flag = 0
    flag2 = 1
    i = 0
    while flag2 and len(S)>1:
    # for i in range(len(S)-1):
        #print(S)
        if S[i]=="(" and S[i+1] ==")":
            # print(S, i)
            flag = 1
            del S[i] 
            del S[i]
            i -= 1
            # print(S, i)
        i += 1
        i = max(0,i)
        if i+1>=len(S):
            flag2 = 0
a=0
b=0
for i in range(len(S)):
    if S[i]=="(":
        b+=1
    elif S[i]==")":
        a+=1
#print(S)
# initialization of string to ""
A = ""
B = ""

# traverse in the string
for x in range(a):
    
    A += "("   
for x in range(b):    
    B += ")"   

        
#print(str(A)+SS+str(B))
print(A+SS+B)
    



Measured memory_bytes: 14312
//
// LIS and LDS
//
// verified:
//   ARC 091 E - LISDL
//     https://beta.atcoder.jp/contests/arc091/tasks/arc091_c
//

/*
    0 〜 N-1 の順列であって
    LIS (最長増加部分列) の長さが A
    LDS (最長減少部分列) の長さが B
    となるものを 1 つ求める
*/


#include <iostream>
#include <vector>
using namespace std;


// LIS and LDS
// A + B <= N+1, AB >= N are necessarily and sufficient
vector<long long> LISLDS(long long N, long long A, long long B) {
    vector<long long> res;
    for (long long i = B-1; i >= 0; --i) res.push_back(i);
    
    if (A == 1) return res;
    
    long long rem = N - B;
    long long p = rem / (A-1);
    long long r = rem % (A-1);
    
    long long b = r;
    long long c = A-1-r;
    
    for (int i = 0; i < b; ++i) {
        int size = (int)res.size();
        for (int j = 0; j < p+1; ++j) {
            res.push_back(size + p - j);
        }
    }
    for (int i = 0; i < c; ++i) {
        int size = (int)res.size();
        for (int j = 0; j < p; ++j) {
            res.push_back(size + p-1 - j);
        }
    }
    
    return res;
}


int main() {
    long long N, A, B; cin >> N >> A >> B;
    if (A + B > N+1 || A * B < N) cout << -1 << endl;
    else {
        vector<long long> res = LISLDS(N, A, B);
        for (int i = 0; i < res.size(); ++i) {
            cout << res[i] + 1;
            if (i != (int)res.size() - 1) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 6512
#!/usr/bin/python3.6
n = int(input())
a = [int(item) for item in input().split()]

itr = 0
max_a = max(a)
while max_a >= n:
    for i in range(n):
        if a[i] >= n:
            num = a[i] // n
            a[i] %= n
            for j in range(n):
                if i == j:
                    continue
                a[j] += num
            itr += num
    max_a = max(a)
print(itr)


Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> a(N, vector<int>(N));
  rep(i,M){
    int l, r;
    cin >> l >> r;
    a[l-1][r-1]++;
  }
  vector<vector<int>> s(N+1, vector<int>(N+1));
  for(int i=1; i<=N; i++){
    for(int j=1; j<=N; j++)
      s[i][j] = s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i-1][j-1];
  }
  rep(i,Q){
    int p, q;
    cin >> p >> q;
    int ans = s[q][q]-s[p-1][q]-s[q][p-1]+s[p-1][p-1];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main ()
  {
long long a,b,c,d,d1,d2,ans,
  ans2, lcm, prod, d3;
cin >> a >> b >> c >> d;
d1 = (b / c) - ((a-1)/c);
d2 = (b / d) - ((a-1)/d);
prod = c * d;
lcm = prod / __gcd(c,d);
d3 = (b / lcm) - ((a-1) / lcm);
ans2 = b - a + 1;
ans = ans2 - (d1+d2-d3);
cout << ans << endl;
  }

Measured memory_bytes: 256
<?php
$K = fgets(STDIN);  
  // 標準入力（STDIN）から1行読み込み（fgets）をしてinputに代入します
$input = fgets(STDIN);  // $input = "1 2 3 4 5"

// 取得した値を半角スペースで分解します（PHPのsplit的な関数） とりあえずこれで十分扱えます!
$input_array = explode(" ", $input); // $input_array = [ "1" , "2" , "3" , "4" , "5"]

$i = 0;
while(true){
  if($i * $K >= $input_array[0]){
    if($i * $K <= $input_array[1]){
      echo 'OK';
      return;
    }
    echo 'NG';
    return;
  }
  $i++;
}

Measured memory_bytes: 16092
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;
import java.lang.StringBuilder;

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

    Scanner sc = new Scanner(System.in);
    List<Integer> list = new ArrayList<Integer>();

    for( int i = 0; i < 5; i++) {
      int a = sc.nextInt();
      list.add(a);
    }
    int k = sc.nextInt();

    boolean cantConnect = false;
    for(int i = 0; i < list.size(); i++) {
      for(int j = i + 1; j < list.size(); j++){
        if (list.get(j) - list.get(i) > k) cantConnect = true; 
      }
    }

    System.out.println(cantConnect ? ":(" : "Yay!");

  }
}


Measured memory_bytes: 21588
#include <iostream>

using namespace std;

int main()
{
    int c50, c100, c500, X;

    cin >> c500 >> c100 >> c50 >> X;

    int count = 0, sum;
    for (int i500 = 0; i500 <= c500; ++i500)
    {
        sum = i500 * 500;
        if (sum >= X)
        {
            if (sum == X)
            {
                count++;
            }
            break;
        }

        for (int i100 = 0; i100 <= c100; ++i100)
        {
            sum = i500 * 500 + i100 * 100;
            if (sum >= X)
            {
                if (sum == X)
                {
                    count++;
                }
                break;
            }
            for (int i50 = 0; i50 <= c50; ++i50)
            {
                sum = i500 * 500 + i100 * 100 + i50 * 50;
                if (sum >= X)
                {
                    if (sum == X)
                    {
                        count++;
                    }
                    break;
                }
            }
        }
    }

    cout << count;

    return 0;
}

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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

using ll = long long;

ll k, t, x;
vector<pair<int, int> > a;

int main() {
  init();
  cin >> k >> t;
  a.resize(t);
  rep(i,t) {
    cin >> x;
    a[i] = {x, i};
  }

  sort(all(a), greater<pair<int, int> >());

  int pre = -1, ans = 0;
  ll cnt = 0, id = 0;

  while (cnt < k) {
    //cout << "pre, se = " << pre << " " << a[id % t].se << endl;
    if (a[id % t].fi == 0 or pre == a[id % t].se) {
      ++id;
      while (a[id % t].fi == 0) {
        //cout << "while : " << pre << " " << a[id % t].se << endl;
        ++id;
      }
    }
    //cout << pre << " " << a[id % t].se << endl;
    if (a[id % t].se == pre) ans++;
    pre = a[id % t].se;
    a[id % t].fi--;
    id = 0;
    cnt++;
    sort(all(a), greater<pair<int, int> >());
  }

  cout << ans << endl;

  return 0;
}

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

int a[3][3];

int main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
		a[i][1] -= a[i][0]; a[i][2] -= a[i][0]; a[i][0] = 0;
	}
	for (int i = 0; i < 3; i++) {
		if (!(a[0][i] == a[1][i] && a[1][i] == a[2][i])) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll x, y; cin >> x >> y;
    if (!(x % y)) {
        puts("-1");
        return 0;
    }
    cout << x << nl;
    return 0;
}


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

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

const ll INF64 = 1LL << 60;
const int INF = 1 << 29;
const ll MOD = 998244353;

const int CASES = 1;

void solve() {
    int r; cin >> r;
    int ans = r * r;
    cout << ans << endl;
    return ;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    private static final char BLACK = '0';
    private static final char WHITE = '1';


    public void execute(CustomReader in) throws IOException {
        char[] tiles = in.readLine().toCharArray();
        int N = tiles.length;

        char[] ptn1 = new char[N];
        char[] ptn2 = new char[N];

        ptn1[0] = BLACK;
        ptn2[0] = WHITE;
        for (int i = 1; i < N; i++) {
            ptn1[i] = oppositeColor(ptn1[i - 1]);
            ptn2[i] = oppositeColor(ptn2[i - 1]);
        }

        int cnt1 = 0;
        int cnt2 = 0;
        for (int i = 0; i < N; i++) {
            if(tiles[i]!= ptn1[i]){
                cnt1++;
            }
            if(tiles[i] != ptn2[i]){
                cnt2++;
            }
        }

        System.out.println(Math.min(cnt1, cnt2));

    }

    private char oppositeColor(char col) {
        if (col == BLACK) {
            return WHITE;
        } else if (col == WHITE) {
            return BLACK;
        } else {
            throw new IllegalArgumentException();
        }
    }


    static class CustomReader extends BufferedReader {

        //private static final int DEFAULT_BUF_SIZE = 2048;
        private static final int DEFAULT_BUF_SIZE = 4096;
        // private static final int DEFAULT_BUF_SIZE = 8192;
        //private static final int DEFAULT_BUF_SIZE = 16384;
        // private static final int DEFAULT_BUF_SIZE = 1048576;

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in), DEFAULT_BUF_SIZE);
        }


        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public long[] readLineAsLongArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            long[] longArray = new long[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                longArray[i] = Long.parseLong(strArray[i]);
            }
            return longArray;
        }


        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }
    }

}

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

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> s(n + 1, 0);
  rep(i, n) s[i + 1] = s[i] + a[i];

  ll ans = 0;
  rep(i, n - 1) {
    ll sum = s[n] - s[i+1];
    ans += (((a[i] % mod) * (sum % mod)) % mod);
  }

  cout << ans % mod << endl;

  return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  string s; cin >> s;
  ll k; cin >> k;

  for(int i = 0; i < k; i++){
    if(s[i] != '1'){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const ll MOD = 1e9 + 7;

ll n;
map<ll, ll> ms[70];
ll pw3[70];
ll ans = 0;

int main() {
	cin >> n;
	ms[60][n] = 1;
	pw3[0] = 1;
	for (int i = 1; i < 70; ++i)
		pw3[i] = (pw3[i - 1] * 3) % MOD;
	for (int i = 59; i >= 0; --i) {
		ll mx = (1ll << (i + 2)) - 2;
		for (pair<ll, ll> e: ms[i + 1]) {
			ll x = e.first;
			ll c = e.second % MOD;
			if (x >= mx) {
				ans = (ans + c * pw3[i + 1]) % MOD;
				continue;
			}
			ms[i][x] += c;
			if (x >= (1ll << i))
				ms[i][x - (1ll << i)] += c;
			if (x >= (1ll << (i + 1)))
				ms[i][x - (1ll << (i + 1))] += c;
		}
	}
	for (auto e: ms[0])
		ans += e.second;
	ans %= MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL N,K;
	cin >> N >> K;
	vector<LL> A(N);
	LL sum = 0;
	for(int i=0;i<N;++i){
		cin >> A[i];
		sum += A[i];
	}
	if( sum < K ){
		cout << N << endl;
		return;
	}
	sort( A.begin(), A.end() );
	int NG = -1;
	int OK;
	vector<bool> dp(K,false);//[0,K-1]まで保持する
	dp[0] = true;
	bool flag = false;
if( A[N-1] < K ){
	for(int i=0;i<N;++i){
		if( i == N-1) continue;
		for(LL var=K-1;var>=0;--var){
			if( dp[var] == false ) continue;
			LL res = var + A[i];
			if( res >= K ) continue;
			dp[ res ] = true;
			
			if( K-A[N-1] <= res ){
				flag = true;//作れる
				break;
			}
		}
		if( flag ) break;
	}
}else{
	flag = true;
}
	if( flag ){
		OK = N-1;
	}else{
		cout << N << endl;
		return;
	}
	int mid;
	while(OK-NG>1){
		mid = (NG+OK)/2;
		dp.assign(K,false);//[0,K-1]
		dp[0] = true;
		bool flag = false;
		if( A[mid] < K ){
			for(int i=0;i<N;++i){
				if( i == mid ) continue;
				for(LL var = K-1;var>=0;--var){
					if( dp[var] == false ) continue;
					LL res = var + A[i];
					if( res >= K ) continue;
					dp[ res ] = true;
					if( K-A[mid] <= res ){
						flag = true;
						break;
					}
				}
				if( flag ) break;
			}
		}else{
			flag = true;
		}
		if( flag ){
			OK = mid;
		}else{
			NG = mid;
		}
	}
	cout << OK << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scan(&x)
	for i := -1000;  i < 1001; i++ {
		for j := -1000;  j < 1001; j++ {
			if i*i*i*i*i - j*j*j*j*j == x {
				fmt.Println(i, j)
				return
			}
		}
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int x, y;
	cin >> x >> y;
	for(int i = 0; i <= x; i++)
	{
		if(i * 2 + (x - i) * 4 == y)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int list[4][14] = {};
    //????????????????????????????????????????????????
    for(int i = 0; i < n; i++){
        char mak;
        int temp;
        cin >> mak;
        cin >> temp;
        if(mak == 'S') list[0][temp] = 1;
        else if(mak == 'H') list[1][temp] = 1;
        else if(mak == 'C') list[2][temp] = 1;
        else if(mak == 'D') list[3][temp] = 1;
    }

    for(int j = 0; j < 4; j++){
        for(int i = 1; i < 14; i++){
            if(list[j][i] == 0){
                if(j == 0)cout << 'S' << " " << i << endl;
                else if(j == 1)cout << 'H' << " " << i << endl;
                else if(j == 2)cout << 'C' << " " << i << endl;
                else if(j == 3)cout << 'D' << " " << i << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    vector<int> cnt(10, 0);
    ++cnt[A];
    ++cnt[B];
    ++cnt[C];
    rep(i, 0, 10) {
        if (cnt[i] == 2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
char ans[250010][256]={""};
int main(){
	int h,w,in;cin>>h>>w;
	bool mp[550][550];int ansc=-1;
	for (int j=0;j<h;++j)for (int i=0;i<w;++i)cin>>in,mp[j][i]=in%2;
	for (int j=0;j<h;++j){
		for (int i=0; i<w-1; ++i)
			if (mp[j][i]){mp[j][i]=0;mp[j][i+1]=!mp[j][i+1];sprintf(ans[++ansc],"%d %d %d %d\n",j+1,i+1,j+1,i+2);}
		if(j!=h-1&&mp[j][w-1]){mp[j][w-1]=0;mp[j+1][w-1]=!mp[j+1][w-1];sprintf(ans[++ansc],"%d %d %d %d\n",j+1,w,j+2,w);}
	}cout<<ansc+1<<endl;for (int i=0;i<=ansc;++i)cout<<ans[i];
}

Measured memory_bytes: 35072
from collections import deque
que1 = deque([])
que2 = deque([])
s = input()
q = int(input())
rev = 1
for i in range(q):
  t = input()
  
  if t == '1':
    rev *= -1
  else:
    x,y,sr = t.split()
    if (rev == 1 and y == '2') or (rev == -1 and y == '1'):
      que2.append(sr)
    else:
      que1.appendleft(sr)

s = ''.join(que1+deque([s])+que2)     
if rev == -1:
  s = s[::-1]
  
print(s)  
  

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

using namespace std;

int h,w,k;
int f[10][1000];
int sf[11][1001];

int cs(int py,int px,int y,int x){
    return sf[y+1][x+1]-sf[py][x+1]-sf[y+1][px]+sf[py][px];
}

void solve(){
    int i,j;
    string str;
    cin >> h >> w >> k;
    for(i = 0;i < h;i++){
        cin >> str;
        int s = 0;
        for(j = 0;j < w;j++){
            if(str[j] == '1'){
                f[i][j] = 1;
            }
            else{
                f[i][j] = 0;
            }
            s += f[i][j];
            sf[i+1][j+1] = s + sf[i][j+1];
        }
    }
    long long ans = 9999;
    int b,px,py,y;
    for(i = (1<<(h-1));i < (1<<h);i++){
        int c = -1;
        for(b = 1;b < (1<<h);b <<= 1){
            if(i&b) c++;
        }
        px = 0;
        for(j = 0;j < w;j++){
            py = 0;
            for(b = 1,y = 0;b < (1 << h);b <<= 1,y++){
                if(i&b){
                    if(k < cs(py,px,y,j)){
                        if(k < cs(py,j,y,j)){
                            j = w;
                            c = 9999;
                            break;
                        }
                        else{
                            px = j;
                            c++;
                            break;
                        }
                    }
                    py = y+1;
                }
            }
        }
        if(c < ans) ans = c;
    }
    cout << ans << endl;
}

int main(){
    solve();
}


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

int dp[3001][3001], dp2[3001][3001];

int main(){
    string S, T;
    cin >> S >> T;
    int N = S.size(), M = T.size();

    for(int i=0; i<N; i++) for(int j=0; j<M; j++){
        if(S[i] == T[j]){
            dp[i+1][j+1] = dp[i][j] + 1;
            dp2[i+1][j+1] = 0;
        }else if(dp[i+1][j] < dp[i][j+1]){
            dp[i+1][j+1] = dp[i][j+1];
            dp2[i+1][j+1] = 1;
        }else{
            dp[i+1][j+1] = dp[i+1][j];
            dp2[i+1][j+1] = -1;
        }
    }

    string ans = "";
    int i = N, j = M;
    while(i>0 && j>0){
        if(dp2[i][j] > 0){
            i--;
        }else if(dp2[i][j] < 0){
            j--;
        }else{
            ans.push_back(S[i-1]);
            i--; j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    vector<ll> s;
    ll n;
    cin>>n;
    rep(i,n){
        ll a;
        cin>>a;
        s.push_back(a);
    }

    sort(s.begin(),s.end());

    ll smax = s[s.size()-1];
    ll mid1 = (smax)/2;

    ll samin = smax;
    ll p = 0;



    rep(i,n-1) {
        ll k=s[i];

//        if(mid1<s[i]){
//            k = smax-s[i];
//        }


       // cout<<s[i]<<" "<<k<<endl;
        if(samin>=abs(mid1-k)){
            samin = abs(mid1-k);
            p=i;
        }
    }


    cout<<smax<<" "<<s[p]<<endl;





    return 0;
}


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

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    cin>>n;
    if(n>=400 && n<=599)
        cout<<"8";
    if(n>=600 && n<=799)
        cout<<"7";
    if(n>=800 && n<=999)
        cout<<"6";
    if(n>=1000 && n<=1199)
        cout<<"5";
    if(n>=1200 && n<=1399)
        cout<<"4";
    if(n>=1400 && n<=1599)
        cout<<"3";
    if(n>=1600 && n<=1799)
        cout<<"2";
    if(n>=1800 && n<=1999)
        cout<<"1";


}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define Inf 1000000000000000000LL
#define MOD 1000000007LL
#define MX 1000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
namespace IO{
template<typename T>
void __RI(T&x){
	int ch=getchar(),neg=1;
	x=0;
	for(;!(isdigit(ch)||ch=='-'||ch==EOF);ch=getchar());
	if(ch==EOF)return;
	if(ch=='-')neg=-1,ch=getchar();
	for(;isdigit(ch);ch=getchar())x=x*10+ch-48;
	x*=neg;
}
void R(int&x){__RI(x);}
#ifndef int
void R(int64_t&x){__RI(x);}
#endif
template<typename T1,typename T2>
void R(std::pair<T1,T2>&x){
	R(x.first);
	R(x.second);
}
template<typename T>
void R(std::vector<T>&x){
	for(auto&i:x){R(i);}
}
template<typename T>
void R(T&x){
	std::cin>>x;
}
template<typename T,typename...Args>
void R(T &x,Args&...args){
	R(x),R(args...);
}
template<typename T>
void RA(T *arr,int l,int r){
	arr+=l;
	int p=r-l+1;
	while(p--)R(*arr++);
}
char space=' ';
template<typename T>
void __WI(T x){
	if(x==0)putchar('0');
	if(x<0)putchar('-'),x=-x;
	char ch[64];
	int pos=0;
	while(x)ch[pos++]=x%10+48,x/=10;
	while(pos)putchar(ch[--pos]);
}
void W(){}
void W(const int&x){__WI(x);}
#ifndef int
void W(const int64_t&x){__WI(x);}
#endif
void W(const double&x){printf("%lf",static_cast<double>(x));}
void W(const char&x){putchar(x);}
void W(const std::string&x){printf("%s",x.c_str());}
template<typename T1,typename T2>
void W(const std::pair<T1,T2>&x){
	W(x.first);
	W(space);
	W(x.second);
}
template<typename T>
void W(const std::vector<T>&x){
	for (auto it=x.cbegin();it!=x.cend();it++){
		W(*it);
		W(space);
	}
	W('\n');
}
template<typename T>
void W(const T&x){
	std::cout<<x;
}
template<typename T,typename...Args>
void W(const T&x,const Args&...args){
	W(x),W(space),W(args...);
}
template<typename...Args>
void WL(const Args&...args){
	W(args...),W('\n');
}
template<typename T>
void WA(T *arr,int l,int r){
	arr+=l;
	int p=r-l;
	while(p--)W(*arr++),W(space);
	W(*arr);
}
template<typename T>
void WAL(T *arr,int l,int r){
	arr+=l;
	int p=r-l;
	while(p--)W(*arr++),W(space);
	WL(*arr);
}
}; // namespace IO
int n;
char s[100010];
int dp[100010][30];
int p[100010];
signed main(){
	IO::R(s);
	n=strlen(s);
	reverse(s,s+n);
	p[0]=1;
	for(int i=1;i<=n;i++)p[i]=p[i-1]*10%13;
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<13;j++){
			if(s[i-1]=='?')
				for(int k=0;k<=9;k++)
					dp[i][j]=(dp[i][j]+dp[i-1][(j-(k*p[i-1])%13+13)%13])%MOD;
			else dp[i][j]=(dp[i][j]+dp[i-1][(j-((s[i-1]-'0')*p[i-1])%13+13)%13])%MOD;
		}
	IO::WL(dp[n][5]%MOD);
	return 0;
}


Measured memory_bytes: 24576
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int V[51];
    rep(i, n) cin >> V[i];
    int ans = 0;
    rep(i, n + 1) {
        rep(j, n + 1) {
            if(i + j > n || i + j > k) continue;
            int sum = 0;
            priority_queue<int, vector<int>, greater<int>> que;
            rep(t, i) {sum += V[t]; que.push(V[t]);}
            rep(t, j) {sum += V[n - 1 - t]; que.push(V[n - 1 - t]);}
            int remain = k - i - j;
            while(remain && que.size() && que.top() < 0) {
                sum -= que.top();
                que.pop();
                remain--;
            }
            //cout << i << " " << j << " " << sum << endl;
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
  ll D;
  while (cin >> D, D) {
    int n, m;
    cin >> n >> m;

    vector<ll> d(n, 0);
    for (int i = 1; i < n; i++) {
      cin >> d[i];
    }
    d.push_back(D);
    sort(d.begin(), d.end());

    ll ans = 0;
    for (int i = 0; i < m; i++) {
      ll k;
      cin >> k;
      
      int q = upper_bound(d.begin(), d.end(), k) - d.begin();
      int p = q - 1;
      ans += min(k - d[p], d[q] - k);
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4320
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n, m, a;
        cin >> n >> m >> a;
        if (n == 0 && m == 0 && a == 0) {
            return 0;
        }

        // 高さごとの横線のリスト
        vector<vector<pair<int, int>>> v(1000);
        for (int i = 0; i < m; ++i) {
            int h, p, q;
            cin >> h >> p >> q;
            v[h - 1].emplace_back(p, q);
        }
        reverse(begin(v), end(v));

        auto next = [&v](int h, int c) {
            auto it1 = find_if(begin(v[h]), end(v[h]),
                               [c](const auto& p) { return p.first == c; });
            if (it1 != end(v[h])) {
                return it1->second;
            }
            auto it2 = find_if(begin(v[h]), end(v[h]),
                               [c](const auto& p) { return p.second == c; });
            if (it2 != end(v[h])) {
                return it2->first;
            }
            return c;
        };

        int current = a;
        for (int i = 0; i < v.size(); ++i) {
            current = next(i, current);
        }
        cout << current << endl;
    }
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <map>
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main(){
	//入力
	int A, B;
	cin >> A >> B;

	//出力用変数定義
	int ans = 0;

	/*計算*/
	//2回繰り返す
	for(int i = 0; i < 2; i++){
		//もしＡのほうが大きかったら
		if(A > B){
			//Ａ枚獲得する
			ans += A;
			//Ａの大きさが１小さくなる
			--A;
		}
		//Ｂのほうが大きかったら
		else{
			//Ａと同じ処理
			ans += B;
			--B;
		}
	}
	//出力
	cout << ans << endl;
}

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

typedef long long ll;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin>>n;
	
	bool yes = 0;
	
	for(ll a=1;a<=9;a++) {
		ll b = n / a;
		if(a * b != n) continue;
		
		if(a < 10 && b < 10) yes = 1;
		
		if(yes) break;
	}
	
	if(yes) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

}

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

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

    int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
    string str;

    for (int i = 0; i < N; i++) {
        cin >> str;
        if (str.at(0) == 'A') {
            c0++;
        }
        else if (str.at(0) == 'W') {
            c1++;
        }
        else if (str.at(0) == 'T') {
            c2++;
        }
        else if (str.at(0) == 'R') {
            c3++;
        }
    }

    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;  
}

Measured memory_bytes: 3576
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int n;
int a;

int main() {
    while (cin >> n) {
        if (n == 0) break;
        vint num;
        for (int i = 0; i < n; ++i) {
            int sum = 0;
            for (int j = 0; j < 5; ++j) {
                cin >> a; sum += a;
            }
            num.PB(sum);
        }
        sort(ALL(num));
        cout << num[num.size()-1] << " " << num[0] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1220
import sys;sys.setrecursionlimit(10**9)
h,w=map(int,input().split())
b=[[0]*(w+1)]
for i in range(h):
  b.append([0])
  for j in input():
    if j==".":b[-1].append(1)
    else:b[-1].append(2)
  b[-1].append(0)
b.append([0]*(w+1))
d=[[0,1],[0,-1],[1,0],[-1,0]]
a=0
def bfs(i,j):
  global br,wh
  if b[i][j]==0:return
  if b[i][j]==1:wh+=1
  elif b[i][j]==2:br+=1
  v=b[i][j]
  b[i][j]=0
  for k in d:
    if v^3!=b[i+k[0]][j+k[1]]:continue
    bfs(i+k[0],j+k[1])
for i in range(1,h+1):
  for j in range(1,w+1):
    br=wh=0
    bfs(i,j)
    a+=br*wh
print(a)

Measured memory_bytes: 149364
n=int(input())
r=range(1,int((2*10**4)**.5)+1)
l=[0]*-~n
for i in r:
  for j in r:
    for k in r:
      t=(j+k)**2+(k+i)**2+(i+j)**2
      if t<=n*2 and t%2<1:
        l[t//2]+=1
for i in range(n): print(l[i+1])

Measured memory_bytes: 69744
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.List

readInt = fst . fromJust . BS.readInt
readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine
getNString n = map readString <$> replicateM n BS.getLine

compareRestaurant :: ((String, Int), Int) -> ((String, Int), Int) -> Ordering
compareRestaurant r1 r2 = if fst (fst r1) > fst (fst r2)
                            then GT
                            else if fst (fst r1) < fst (fst r2)
                              then LT
                              else if snd (fst r1) > snd (fst r2)
                                then LT
                                else if snd (fst r1) < snd (fst r2)
                                  then GT
                                  else EQ
main = do
  n <- getInt
  sps <- getNString n
  let sps' = map (\x -> (head x, read (last x) :: Int)) sps
  let sqs'' = zip sps' [1..n]
  let sqs''' = sortBy (compareRestaurant)  sqs''
  mapM_ print (map (\x -> snd x) sqs''')


Measured memory_bytes: 1020
/*input
1
1
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int n, mi = 1000000000, ans = 0;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int x; cin >> x;
		if(x <= mi) {
			ans++;
		}
		mi = min(mi, x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    ll a[3]; rep(i,0,3) cin >> a[i];
    sort(a, a+3);
    rep(i,0,3) {
        if(a[i] % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << a[0] * a[1] << endl;
    return 0;
}

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

long int ruijo(int a,int b);

int main(void){
	
  	int N,K;
  
  	scanf("%d %d\n",&N,&K);
  
  	int i=0,j,m=0;
  
  	int a[100];
 
  
  	while(ruijo(K,m)<=N){
  
  	m++;
  
	}
  
  	//printf("%d",m);

	for(i=m;1<=i;i--){
    
      	for(j=1;j<=K;j++){
        
        	if(N-j*ruijo(K,i-1)<0){
            	N=N-(j-1)*ruijo(K,i-1);
              	//printf("%d %d\n",N,j-1);
              	a[i]=j-1;
              	break;
            }
          
      
        }
    
    
    }
  
  	printf("%d\n",m);
  
 /* 	for(i=m;1<=i;i--){
    	
      printf("%d",a[i]);
    
    }*/
  
  
  
	return 0;

} 


long int ruijo(int a,int b){

  if(b==0){return 1;}

  if(b%2==0){return ruijo(a,b/2)*ruijo(a,b/2);}

  else{return a*ruijo(a,b-1);}

}





Measured memory_bytes: 128
let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let es = Array.make n [] in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- b - 1 :: es.(a - 1);
      es.(b - 1) <- a - 1 :: es.(b - 1)
  done;
  let rs = Array.make n (-1) in
  let cs = Array.make n 0 in
  Scanf.scanf "%d\n" @@ fun q ->
    let rec dfs d c v =
      if rs.(v) < d then begin
        rs.(v) <- d;
        if cs.(v) = 0 then
          cs.(v) <- c;
        List.iter (dfs (d - 1) c) es.(v)
      end in
    let vdcs = Array.init q @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun v d c -> v, d, c in
    List.iter (fun (v, d, c) -> dfs d c (v - 1)) (List.rev (Array.to_list vdcs));
    Array.iter (Printf.printf "%d\n") cs



Measured memory_bytes: 19072
S = input()
N = len(S)
ms = [1]
for i in range(N):
  m = ms[-1]*10%2019
  ms.append(m)
Rs = [0]
for i in range(N):
  c = int(S[N-i-1])
  R = (Rs[-1]+c*ms[i])%2019
  Rs.append(R)
NRs = {}
for R in Rs:
  if R not in NRs:
    NRs[R] = 0
  NRs[R] += 1
r = 0
for R in NRs:
  N = NRs[R]
  r += N*(N-1)//2
print(r)


Measured memory_bytes: 23548
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int ans = 0;
    for(size_t i = 0; i < s.size(); i++){
        ans += (s[i] == '0') ^ (i & 1);
    }
    int cand = 0;
    for(size_t i = 0; i < s.size(); i++){
        cand += (s[i] == '0') ^ !(i & 1);
    }
    cout << min(ans, cand) << '\n';
}


Measured memory_bytes: 512
s=input()
a=int(s[0:2])
b=int(s[2:4])
ans=0
if 1<=a<=12 and 1<=b<=12:
    print('AMBIGUOUS')
elif 1<=a<=12:
    print('MMYY')
elif 1<=b<=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  cout << (n%10==n/100 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b, c, d, e;
vector<int> u, v;
string s, t;

int main()
{
    cin >> a >> b;
    int ans = 0;
    if (a > 12)
        ans += b;
    else if (a > 5)
        ans += b / 2;

    cout << ans << endl;
}

Measured memory_bytes: 256