akhauriyash/Code-Regression huggingface dataset:
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n >= m then [] else List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = List.sort Int.compare @@ scan_list ~sep:' ' Int.of_string

module IntSet = Set.Int

let () =
  let hcount = Hashtbl.create n in
  ListL.iter ls ~f:(fun v -> Hashtbl.modify_def 0 v succ hcount);
  let m = List.last ls in
  let arr = Array.make (succ m) true in
  ListL.iter (List.of_enum @@ Hashtbl.keys hcount) ~f:(fun v ->
      let rec aux i =
        if i*v > m then ()
        else (arr.(i*v) <- false; aux @@ succ i)
      in
      aux 2);
  ListL.map (Hashtbl.to_list hcount) ~f:(fun (v,n) ->
      if n >= 2 then 0
      else if arr.(v) then 1 else 0
    ) |> List.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 49228
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, c; cin >> n >> k >> c;
    int INF = 1001001001;
    string s; cin >> s;
    vector<P> l(n + 1), r(n + 1);
    l[0] = {-INF, 0}; // left-est, max
    rep (i, n) {
        if (s[i] == 'o' && l[i].first + c + 1 <= i) l[i + 1] = {i, l[i].second + 1};
        else l[i + 1] = l[i];
    }
    r.back() = {INF, 0};
    reprev (i, n) {
        if (s[i] == 'o' && r[i + 1].first - c - 1 >= i) r[i] = {i, r[i + 1].second + 1};
        else r[i] = r[i + 1];
    }
    rep (i, n + 1) eprintf("(%d,%d) ", l[i].first, l[i].second); eprintf("\n");
    rep (i, n + 1) eprintf("(%d,%d) ", r[i].first, r[i].second); eprintf("\n");
    rep (i, n) {
        if (l[i].second + r[i + 1].second < k) cout << i  + 1 << "\n";
    }
    return 0;
}

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

using namespace std;

class union_find{
public:
	vector<int> arr;
	union_find(int n){
		arr.resize(n);
		fill(arr.begin(),arr.end(),-1);
	}
	int find(int x){
		return arr[x]<0?x:arr[x]=find(arr[x]);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		if(arr[x]>arr[y]) swap(x,y);
		arr[x]+=arr[y];
		arr[y]=x;
	}
	bool connected(int x,int y){
		return find(x) == find(y);
	}
	int size(int x){
		return -arr[find(x)];
	}
};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<pair<pair<int,int>,int>> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i].first.first >> a[i].first.second;
		a[i].second=i;
	}
	sort(a.begin(),a.end());
	
	union_find uf(n);
	multiset<pair<int,int>> st;
	for(int i=0;i<n;i++){
		int y=a[i].first.second;
		int cur=a[i].second;
		
		auto itr=st.lower_bound(make_pair(y,0));
		if(itr==st.begin()){
			st.insert(make_pair(y,cur));
		}else{//merge
			while(itr!=st.begin()){
				itr--;
				auto p=*itr;
				int num=p.second;
				uf.unite(num,cur);
				if(itr!=st.begin()){
					st.erase(itr);
					itr=st.lower_bound(make_pair(y,0));
				}
			}
		}
	}
	
	vector<int> res(n);
	for(int i=0;i<n;i++){
		res[a[i].second]=uf.size(a[i].second);
	}
	
	for(int i=0;i<n;i++) cout << res[i] << "\n";
	return 0;
}

Measured memory_bytes: 10972
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        char[] cl = sc.next().toCharArray();
        for(char c : cl){
            if(c == 'a'){
                if(a+b > 0){
                    System.out.println("Yes");
                    a--;
                }else{
                    System.out.println("No");
                }
            }else if(c == 'b'){
                if(a+b > 0 && b > 0){
                    System.out.println("Yes");
                    b--;
                }else{
                    System.out.println("No");
                }
            }else{
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 34708
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
const int MOD = 1000000009;
const ll llINF = 99999999999999;



using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

ll F(ll a, ll b) {
	ll c1=0, c2=0;
	while (a > 0) {
		a /= 10;
		c1++;
	}
	while (b > 0) {
		b /= 10;
		c2++;
	}
	return max(c1, c2);
}


int main() {
	int a[3];
	m0(a);
	int N, P; cin >> N>> P;
	REP(i, N) {
		int x; cin >> x;
		if (x % 2 == 0)a[0]++;
		else a[1]++;
	}
	ll ans = 0;
	ll cnt=0;
	if (P % 2 == 0) {
		ans = myPow(2, a[0],llINF);
		for (int i = 0; i <= a[1]; i = i + 2) {
			cnt += nCr(a[1], i);
		}
		ans *= cnt;
		cout << ans << endl;
		return 0;
	}
	else  {
		ans = myPow(2, a[0], llINF);
		for (int i = 1; i <= a[1]; i = i + 2) {
			cnt += nCr(a[1], i);
		}
		ans *= cnt;
		cout << ans << endl;
		return 0;
	}
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a < b) {
        	System.out.println("a < b");
        }
        else if(a > b) {
        	System.out.println("a > b");
        }
        else {
        	System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26012
def main():
    lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    k = int(input())
    print(lst[k-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
<?php
$n = intval(fgets(STDIN));

out(0);
$minRet = in();
if($minRet == 0)exit;
out($n-1);
$maxRet = in();
if($maxRet == 0)exit;

$min = 0;
$max = $n-1;
while($min!=$max){
    $mid = intdiv($max+$min, 2);
    out($mid);
    $ret = in();
    if($ret == 0){
        exit;
    }else{
        if(($ret != $minRet) <> ($mid - $min) % 2){
            $max = $mid;
            $maxRet = $ret;
        }else{
            $min = $mid;
            $minRet = $ret;
        }
    }
}

function out($a){
    echo $a,"\n";
    flush();
}
function in(){
    $in = trim(fgets(STDIN));
    if($in == "Vacant"){
        return 0;
    }elseif($in == "Male"){
        return 1;
    }else{
        return -1;
    }
}



Measured memory_bytes: 5200
#include<iostream>
using namespace std;
#define MAX 1100
int n,m;
char t[MAX][MAX];
int u[MAX];
void init(){
  for(int i=0;i<MAX;i++){
    for(int j=0;j<MAX;j++){
      t[i][j]='.';
    }
  }
  m=0;
}
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      string str;cin>>str;
      int len=str.size();
      u[i]=len;
      m=max(m,len);
      for(int j=0;j<len;j++){
        if(j+1<len&&str[j]=='.'&&str[j+1]!='.')t[i][j]='+';
        else if(str[j]=='.')t[i][j]=' ';
        else t[i][j]=str[j];
      }
    }
    for(int j=0;j<m;j++){
      int last=-1;
      for(int i=0;i<n;i++){
        if(t[i][j]=='+'){
          if(last!=-1)
            for(int k=last+1;k<i;k++)t[k][j]='|';
          last=i;
        }else if(t[i][j]!=' '){
          last=-1;
        }
      }
    }
 
    for(int i=0;i<n;i++){
      for(int j=0;j<u[i];j++){
        cout<<t[i][j];
      }
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2392
a = int(input())

import math
def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

while True:
    if is_prime(a):
        print(a)
        break
    else:
        a+=1

Measured memory_bytes: 67480
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,result;
    cin >> N;
    if(N%2==0){
        cout << N/2 <<endl;
        return 0;
    }else if(N%2==1){
        cout << N/2+1 <<endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
	int i,A,B,C,D;
	scanf("%d%d%d%d",&A,&B,&C,&D);
	if(B<A)
		A=B;
	if(D<C)
		C=D;
	i=A+C;
	printf("%d\n",i);
	return 0;		
	
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class C
{
	public static void Main()
	{
		int N = GetInt();
		int numBXA = 0;
		int numXA = 0;
		int numBX = 0;

		int ans = 0;
		for(int i = 0; i < N; i++)
		{
			string s = GetString();
			ans += count(s, "AB");
			if((s[0] == 'B') && (s[s.Length - 1] == 'A'))
			{
				numBXA++;
			}
			else if(s[0] == 'B')
			{
				numBX++;
			}
			else if(s[s.Length - 1] == 'A')
			{
				numXA++;
			}
		}
		if(numBXA > 0)
		{
			ans += numBXA - 1;
			if(numXA > 0)
			{
				ans++;
				numXA--;
			}
			if(numBX > 0)
			{
				ans++;
				numBX--;
			}
		}
		ans += Math.Min(numXA, numBX);
		Console.WriteLine(ans);
	}


	private static int count(string str, string ptn)
	{
		int ans = 0;
		int index = str.IndexOf(ptn, 0);
		while(index != -1)
		{
			ans++;
			index = str.IndexOf(ptn, index + ptn.Length);
		}
		return ans;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13408
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int k;
    cin >> k;
    
    int sum = 0;
    for (int i = 100; i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            sum++;
        }
        if (sum == k) {
            cout << i << endl;
            return 0;
        }
    }  
}

Measured memory_bytes: 256
# A - Colorful Slimes 2
# https://beta.atcoder.jp/contests/agc026/tasks/agc026_a

# A_Colorful_Slimes_2.py

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

count = 0
last = 101
for a in A:
    if last == a:
        count += 1
        last = 101
    else:
        last = a
print(count)


Measured memory_bytes: 2940
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < ty - sy; i++) {
		    sb.append("U");
		}
		for (int i = 0; i < tx - sx; i++) {
		    sb.append("R");
		}
		for (int i = 0; i < ty - sy; i++) {
		    sb.append("D");
		}
		for (int i = 0; i < tx - sx; i++) {
		    sb.append("L");
		}
		sb.append("L");
		for (int i = 0; i <= ty - sy; i++) {
		    sb.append("U");
		}
		for (int i = 0; i <= tx - sx; i++) {
		    sb.append("R");
		}
		sb.append("D");
		sb.append("R");
		for (int i = 0; i <= ty - sy; i++) {
		    sb.append("D");
		}
		for (int i = 0; i <= tx - sx; i++) {
		    sb.append("L");
		}
		sb.append("U");
		System.out.println(sb);
	}
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const ll MAX = 10000;
static const ll INFTY = 1e12;
static const ll MOD = 1e9+7;

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



int main() {

 int M;
 cin >> M;

  cout << 24-M +24 << endl;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3628
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  hs <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  putStrLn . maybe "No" (const "Yes") . foldr step (Just (10 ^ 9)) $ hs
  where
    step _ Nothing = Nothing
    step h (Just m) | h <= m = Just h
                    | h == m + 1 = Just (h - 1)
                    | otherwise = Nothing

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 10364
#include <stdio.h>
#define MOD 1000000007

int main(void){
	long i, j, n, m;
	scanf("%ld %ld", &n, &m);
	long x[n], y[m];
	for(i = 0; i < n; i++) scanf("%ld", &x[i]);
	for(i = 0; i < m; i++) scanf("%ld", &y[i]);

	long sumx = 0;
	for(i = 0; i < n; i++){
		sumx += x[i]*(i*2-(n-1));
		if(sumx > 1e18 || sumx < -1e18) sumx %= MOD;
	}
	sumx %= MOD;
	long sumy = 0;
	for(i = 0; i < m; i++){
		sumy += y[i]*(i*2-(m-1));
		if(sumy > 1e18 || sumy < -1e18) sumy %= MOD;
	}
	sumy %= MOD;
	printf("%ld\n", sumx*sumy%MOD);

	return 0;
}


Measured memory_bytes: 1664
N, Y = map(int, input().split())

for x in reversed(range(N + 1)): # 10000
  for y in reversed(range(N + 1 - x)): # 5000
    z = N - x - y
    if 10000*x  + 5000*y + 1000*z == Y:
      print(x, y, z)
      exit()
else:
	print(-1, -1, -1)

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define optimizator ios_base::sync_with_stdio(0);
#define ll long long
#define str string
#define LOL unsigned long long int
using namespace std;
int main(){
	optimizator;
	int n;
	cin>>n;
	str a;
	cin>>a;
	if(n<3200){
		cout<<"red";
	}
	else{
		cout<<a;
	}
	
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
 int x ; 
  cin >> x; 
  if(x ==1) cout << 0; 
  if(x ==0) cout << 1 ;
  
  cout <<endl ;


}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const int M = 1e5 + 10;
const int N = (1 << 18) + 1;
const int T = 10;

int v1[N], w1[N];
vector<pair<int, int>> g[N];
pair<int, int> b[N];
pair<int, int> bb[N];

int calc(vector<int> ids) {
    vector<int> v, w;
    for (auto i: ids) {
        v.push_back(v1[i]);
        w.push_back(w1[i]);
    }
    int n = (int)ids.size();
    int cur_ptr = 0;
    for (int mask = 0; mask < (1 << n); ++mask) {
        int sumv = 0, sumw = 0;
        for (int i = 0; i < n; ++i) {
            if (mask & (1 << i)) {
                sumv += v[i];
                sumw += w[i];
            }
        }
        bb[cur_ptr++] = {sumv, sumw};
    }
    sort(bb, bb + cur_ptr);
    int ptr = 0;
    for (int i = 0; i < cur_ptr; ++i) {
        auto el = bb[i];
        if (el.first > M) break;
        if (!ptr || b[ptr - 1].second < el.second) {
            b[ptr++] = el;
        }
    }
    return ptr;
}

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> w1[i] >> v1[i];  
    }
    for (int i = 1; i < min(n + 1, (1 << T)); ++i) {
        vector<int> path;
        int cur = i;
        while (cur) {
            path.push_back(cur);
            cur /= 2;
        }
        int len = calc(path);
        g[i].resize(len);
        copy(b, b + len, g[i].begin());
    }

    int q;
    cin >> q;
    while (q--) {
        int v, l;
        cin >> v >> l;     
        if (g[v].empty()) {
            vector<int> path;
            int cur = v;
            while (g[cur].empty()) {
                path.push_back(cur);
                cur /= 2; 
            }
            int len = calc(path);
            auto& a = g[cur];

            int ptr_b = len - 1;
            int ans = 0;
            for (int i = 0; i < (int)a.size(); ++i) {
                while (ptr_b >= 0 && b[ptr_b].first + a[i].first > l) {
                    ptr_b--;
                }
                if (ptr_b >= 0) {
                    ans = max(ans, b[ptr_b].second + a[i].second);
                }
            }
            cout << ans << "\n";
        } else {
            auto it = prev(upper_bound(g[v].begin(), g[v].end(), make_pair(l, INF)));
            cout << (it->second) << "\n";
        }
    }
}

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


Measured memory_bytes: 16896
fun main (args:Array<String>) {
    val bankDeposit = readLine()!!.toLong()
    var newBankDeposit = 100L
    var yearsLater = 0
    while(newBankDeposit < bankDeposit){
        newBankDeposit += newBankDeposit * 1/100
        yearsLater++
//        println(newBankDeposit)
    }
    print(yearsLater)

}


Measured memory_bytes: 34464
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long Comb (long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);
  map<string,ll>poll;
  rep(i,N){
    string s;cin>>s;
    poll[s]++;
  }
  
  ll m=0;
  for(auto it=poll.begin();it!=poll.end();it++){
    chmax(m, it->second);
  }
  
  for(auto it=poll.begin();it!=poll.end();it++){
    if(it->second == m)
      cout<<it->first<<endl;
  }
}

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

main() {
  char c;
  cin >> c;
  if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int xi[10],yi[10];
int n;
double sum,L[10][10];
int main(){
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> xi[i] >> yi[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			L[i][j]=sqrt((xi[i]-xi[j])*(xi[i]-xi[j])+(yi[i]-yi[j])*(yi[i]-yi[j]));
		} 
	}
	int x=1;
	for(int i=1;i<n;i++) {
		x*=i;
	}
	for(int i=1;i<=n;i++){
		for(int j=1+i;j<=n;j++){
			sum=sum+x*L[i][j];
		} 
	}	
	sum=sum/x/n*2;
	printf("%.10f",sum);
	return 0;
}

Measured memory_bytes: 256
#ABC054C
n,m=map(int,input().split())
from collections import defaultdict
branch=defaultdict(set)
for i in range(m):
    a,b=map(int,input().split())
    branch[a]|={b,}
    branch[b]|={a,}

def roop(now,nonvisit,ans):
    nownonvisit=nonvisit.copy()
    nownonvisit-={now,}
    if len(nownonvisit)==0:return ans+1
    nex=branch[now].copy()
    for x in nex&nownonvisit:
        ans=roop(x,nownonvisit,ans)
    return ans

print(roop(1,{i for i in range(1,n+1)},0))

Measured memory_bytes: 3444
/*  -*- coding: utf-8 -*-
 *
 * 1596.cc: Char Swap
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 400000;
const int MAX_H = MAX_N / 2;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4];
int cns[26], cas[26][MAX_H], cis[26], cjs[26];
int ds[MAX_H], ts[MAX_H];

/* subroutines */

ll merge_sort(int as[], int tmp[], int l, int r) { // [l, r)
  ll ic = 0;

  if (l + 1 < r) {
    int m = (l + r) / 2;
  
    ic = merge_sort(as, tmp, l, m) + merge_sort(as, tmp, m, r);

    int i = l, j = m, k = l;

    while (i < m && j < r) {
      if (as[i] <= as[j]) tmp[k++] = as[i++];
      else tmp[k++] = as[j++], ic += m - i;
    }

    while (i < m) tmp[k++] = as[i++];
    while (j < r) tmp[k++] = as[j++];

    for (int i = l; i < r; i++) as[i] = tmp[i];
  }  

  return ic;
}

/* main */

int main() {
  scanf("%s", s);

  int n = 0;
  for (; s[n]; n++) cns[s[n] - 'a']++;

  for (int i = 0; i < 26; i++) {
    if (cns[i] & 1) {
      puts("-1");
      return 0;
    }
    cns[i] >>= 1;
  }

  ll sum = 0;
  for (int i = 0, k = 0, d = 0; i < n; i++) {
    int c = s[i] - 'a';
    if (cis[c] < cns[c]) {
      cas[c][cis[c]++] = k++;
      sum += d;
    }
    else
      d++;
  }

  for (int i = n - 1, j = 0; i >= 0; i--) {
    int c = s[i] - 'a';
    if (cjs[c] < cns[c]) ds[j++] = cas[c][cjs[c]++];
  }

  int h = n / 2;
  //for (int i = 0; i < h; i++) printf("%d ", ds[i]); putchar('\n');

  sum += merge_sort(ds, ts, 0, h);
  printf("%lld\n", sum);
  return 0;
}



Measured memory_bytes: 6044
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
	int n, m, A, B; cin >> n >> m >> A >> B;
	vector<int> a(n);
	vector<int> b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int maxA = max(A, a.back());
	int minB = min(B, b.front());
	if (maxA < minB) cout << "No War" << endl;
	else cout << "War" << endl;
	return 0;
}



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

struct Tea
{
    long long cost;
    long long amount;
};

bool cmp(const Tea a, const Tea b) {
    return a.cost < b.cost;
}

int main(){

    
    vector<long long> v(4);
    int N;

    cin >> v[0] >> v[1] >> v[2] >> v[3];
    cin >> N;

    vector<Tea> t(3);
    t[0].cost = v[0] * 4;
    t[1].cost = v[1] * 2;
    t[2].cost = v[2];
    //long long 全て4倍
    t[0].amount = 1;
    t[1].amount = 2;
    t[2].amount = 4;

    sort(t.begin(), t.end(), cmp);
    if(v[3] < t[0].cost * 2){
        if(N % 2 == 0){
            cout << N / 2 * v[3]  << endl;
        }
        else{
            cout << N / 2 * v[3] + t[0].cost << endl;
        }

    }
    else{
        cout << N * t[0].cost << endl;
    }






    



}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

int const N = 100000;

int main(){
    int n,m;
    cin>>n>>m;
    vector< vector<int> > v(N);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if(a>m)continue;
        v[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for(int i=m-1;i>=0;--i){
        for(vector<int>::iterator it=v[i].begin();it!=v[i].end();it++){
            q.push(*it);
        }
        if(!q.empty()){
            ans += (ll)q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    vector<int> B;
    for (int i = 0; i < N-1; i++)
    {
        int b; cin >> b;
        B.push_back(b);
    }
    long ans = B[0]+B[N-2];
    for (int i = 1; i < N-1; i++)
    {
        ans += min(B[i-1], B[i]);
    }
    
    cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  ll q, h, s, d; cin >> q >> h >> s >> d;
  ll n; cin >> n;

  ll x05 = (2*q > h) ? h : 2*q;
  ll x1 = (2*x05 > s) ? s : 2*x05;
  ll x2 = (2*x1 > d) ? d : 2*x1;

  if(2*x1 == x2) {
    cout << x1 * n << endl;
  } else if(n % 2 == 0) {
    cout << x2 * n/2 << endl;
  } else {
    cout << x2 * (n/2) + x1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;
using P = pair<ll,ll>;

int main(){
    ll H, W; cin >> H >> W;
    vvll dist(H, vll(W, -1));
    vector<vector<char>> grid(H, vector<char>(W));
    queue<P> q;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> grid[i][j];
            if(grid[i][j] == '#'){
                q.push(P(i, j));
                dist[i][j] = 0;
            }
        }
    }
    
    while(!q.empty()){
        P x = q.front();
        q.pop();
        ll h = x.first, w = x.second;
        if(0 <= h-1){
            if(grid[h-1][w] == '.'){
                dist[h-1][w] = dist[h][w] + 1;
                grid[h-1][w] = '#';
                q.push(P(h-1, w));
            }
        }
        if(h+1 < H){
            if(grid[h+1][w] == '.'){
                dist[h+1][w] = dist[h][w] + 1;
                grid[h+1][w] = '#';
                q.push(P(h+1, w));
            }
        }
        if(0 <= w-1){
            if(grid[h][w-1] == '.'){
                dist[h][w-1] = dist[h][w] + 1;
                grid[h][w-1] = '#';
                q.push(P(h, w-1));
            }
        }
        if(w+1 < W){
            if(grid[h][w+1] == '.'){
                dist[h][w+1] = dist[h][w] + 1;
                grid[h][w+1] = '#';
                q.push(P(h, w+1));
            }
        }
    }
    ll n = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            n = max(n,dist[i][j]);
        }
    }
    cout << n;
}

Measured memory_bytes: 25524
using System;
class c
{
    static void Main()
    {
        var abx = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
        double a = abx[0], b = abx[1], x = abx[2];
        double d1 = Math.Atan(2 / Math.Pow(a, 3) * (a * a * b - x));
        double d2 = Math.Atan(a * b * b / 2 / x);
        Console.WriteLine(180 / Math.PI * (a * a * b / 2 < x ? d1 : d2));
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 2050;
 ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<double> vec(n,0);
    rep(i,n) cin >> vec[i];
    
    sort(all(vec));
    double ans = vec[0];
    for(int i=1;i<n;i++){
        ans = (ans+vec[i])/2;
    }
    printf("%.12lf\n",ans);

}

Measured memory_bytes: 256
mod = 10**9 + 7

def factorial(n):
    res = 1
    for p in range(2,n+1):
        res *= p
        res %= mod
    return res

N = int(input())
S = input()

T = "L"

L = 0
R = 0

for i in range(1,2*N):
    if S[i] == "W":
        if (L - R + 1) % 2 == 0:
            R += 1
            T += "R"
        else:
            L += 1
            T += "L"
    else:
        if (L - R + 1) % 2 == 0:
            L += 1
            T += "L"
        else:
            R += 1
            T += "R"

if T[-1] == "L" or T.count("L") > N:
    print(0)
    exit()

L = 0
ans = 1

for i in range(2*N):
    if T[i] == "L":
        L += 1
    else:
        ans *= L
        ans %= mod
        L -= 1

ans *= factorial(N)
ans %= mod
print(ans)

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int  pos[2000005], cnt[2000005];
int main(){
    int a,b,c=0,d,e,f,i,j,n;
    cin>>n;
    int ar[n+5];
    memset(cnt, 0, sizeof(cnt));
    memset(pos, 0, sizeof(pos));
    for(i=1;i<=n;i++){
        cin>>ar[i];
        cnt[ar[i]]++;
    }
    sort(ar+1,ar+1+n);
    vector<int> v;
    v.push_back(ar[1]);
    for(i=2;i<=n;i++){
        if(ar[i]!=ar[i-1]) v.push_back(ar[i]);
    }
    int sze=v.size();
    for(i=0;i<sze;i++){
        a=v[i];
        while(a<=ar[n])
        {
            a+=v[i];
            pos[a]++;
        }
    }
    for(i=1;i<=n;i++){
        if(cnt[ar[i]]==1&&pos[ar[i]]==0) c++;
    }
    cout<<c;
}

Measured memory_bytes: 20716
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){

    int N;
    vector<pair<int, pair<int, int>>> v;
    cin >> N;
    for (int i = 0; i < N; ++i){
        int x,y,h;
        cin >> x >> y >> h;
        v.push_back(make_pair(h, make_pair(x,y)));
    }
    sort(v.begin(), v.end());
    
    for (int cx = 0; cx <= 100; ++cx){
        for (int cy = 0; cy <= 100; ++cy){
            bool check = true;
            int ch = v[N-1].first + abs(v[N-1].second.first - cx) + abs(v[N-1].second.second - cy);
            for (int i = 0; i < N-1; ++i){
                int h = v[i].first;
                int x = v[i].second.first;
                int y = v[i].second.second;
                if (h != max(0, ch - abs(x - cx) - abs(y - cy))){
                    check = false;
                    break;
                }
            }
            if (check) {
                cout << cx << " " << cy << " " << ch << endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
if li[0]!=0:
    print(0)
    exit()

import collections
c = collections.Counter(li)

#print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})
#print(c.items())
# dict_items([('a', 4), ('b', 1), ('c', 2)])

tmp = c.items()
cnt = list(tmp)
cnt.sort()
#print(cnt)
#[(0, 1), (1, 2), (2, 3), (3, 1)]
ans = 1
for i,c in enumerate(cnt):
    if i == 0:
        if c[1]>=2:
            print(0)
            exit()
        continue
    if c[0]!= i:
        print(0)
        exit()
    #print(cnt[i-1][1],c[1])
    ans *= cnt[i-1][1]**c[1]
print(ans%998244353)

Measured memory_bytes: 64436
import java.util.Scanner;

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

    int N = scanner.nextInt();
    scanner.nextLine();
    String[] c = scanner.nextLine().split(" ");
    for (int i = 0; i < N; i++) {
      if (c[i].charAt(0) == 'Y') {
        System.out.println("Four");
        return;
      }
    }
    System.out.println("Three");
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
   string S;
   cin>>S;
   int cnt=0;
   rep(i,S.size()-1){
       if(S[i]!=S[i+1]){
           cnt++;
       }
   }
   cout<<cnt<<endl;
    }


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    ll N, M;
    cin >> N >> M;
    PRINT((ll)pow(2, M) * ((N - M) * 100 + M * 1900));
    return 0;
}

Measured memory_bytes: 4016
#!/usr/bin/env python3

def main():
    N = int(input())
    rengas = [int(s) for s in input().split()]
    focus = 1
    count = 0
    for renga in rengas:
        if renga == focus:
            focus += 1
        else:
            count += 1
    result = count if count < len(rengas) else (-1)
    print(result)

if __name__ == "__main__":
    main()


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

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

	if (s == "Sunny")
	{
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy")
	{
		cout << "Rainy" << endl;
	}
	else if (s == "Rainy")
	{
		cout << "Sunny" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def abc063_d():
    n, a, b = map(int, input().split())
    H = [int(input()) for _ in range(n)]
    lower, upper = 0, 10**16
    d = a - b
    while upper - lower > 1:
        x = (upper + lower) // 2
        v = 0
        for hi in H:
            v += (max(0, hi - x*b) + d - 1) // d
            if v > x: break
        if v <= x: upper = x
        else: lower = x
    print(upper)

if __name__ == '__main__':
    abc063_d()

Measured memory_bytes: 13012
N, A = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)

# dp[i][j][k]
# i個の中からj個を選んで合計がkの個数
dp = Array.new(N+1).map{Array.new(N+1).map{Array.new(N*50+1, 0)}}

dp[0][0][0] = 1

1.upto(N) do |i|
  # 0個選んだ場合は合計0のなので1
  dp[i][0][0] = 1

  # 最大でi個まで選ぶ
  1.upto(i) do |j|
    1.upto(N*50) do |k|

      if x[i-1] > k
        dp[i][j][k] = dp[i-1][j][k]
      else # x[i-1] <= k
        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]]
      end
    end
  end
end

puts (1..N).map{ |j| dp[N][j][j*A] }.inject(:+)


Measured memory_bytes: 54680
var lines = [];
var N, A;

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    N = Number(lines[0]); lines.shift();
    A = lines.map(i => i.split(" ").map(i => Number(i)));

    var q = [[0, 0, 0]];
    console.log(bfs(q));

});

function bfs(q) {
    var ans = 0, counter = 0;

    while (q.length) {
        var t = q.shift();
        var y = t[0], x = t[1]; counter = t[2] + A[y][x];

        ans = Math.max(ans, counter)

        if (x + 1 < N) { q.push([y, x + 1, counter]) }
        if (y + 1 < 2) { q.push([y + 1, x, counter]) }
    }

    return (ans);
}

Measured memory_bytes: 8012
#include <bits/stdc++.h>
#define int long long
using namespace std;

int k;
string s;

signed main()
{
	cin>>k>>s;
	if (s.size()<=k)  cout<<s<<endl;
	else
	{
		for (int i=0;i<=k-1;i++)  cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

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

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    int A, B; cin >> A >> B;

    if ((A % 3 == 0) or (B % 3 == 0) or ((A + B) % 3 == 0)) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=l;i<r;i++)
using ll=long long;
const ll MOD=1000000007;
const ll MAX=1100000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    repl(i,2,MAX){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k)return 0;
    if(n<0 or k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main(){
    ll X,Y;cin>>X>>Y;
    ll a=0,b=0;
    rep(i,X+1){
        if((X-i)==(Y-2*i)*2){
            a=i,b=Y-2*i;
            break;
        }
    }
    COMinit();
    ll ans=COM(a+b,b);
    if(a+b==0)cout<<0<<endl;
    else cout<<ans<<endl;
    return 0;
}

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

namespace AtCoderABC122
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split(' ');
            long N = long.Parse(s1[0]);
            int Q = int.Parse(s1[1]);
            string S = Console.ReadLine();
            int[] ll = new int[Q];
            int[] rr = new int[Q];
            int[] ress = new int[Q];
            for (int i = 0; i < Q; i++)
            {
                string[] s2 = Console.ReadLine().Split(' ');
                ll[i] = int.Parse(s2[0]);
                rr[i] = int.Parse(s2[1]);
            }
            int[] dpres = new int[N];
            dpres[0] = 0;
            bool flag1 = false;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'A')
                {
                    flag1 = true;
                    dpres[i] = (i > 0)? dpres[i - 1] : 0;
                    continue;
                }
                if (S[i] == 'C' && flag1 == true)
                {
                    flag1 = false;
                    dpres[i] = dpres[i - 1] + 1;
                    continue;
                }
                flag1 = false;
                dpres[i] = (i > 0)? dpres[i - 1]: 0;
            }
            for (int i = 0; i < Q; i++)
            {
                int temp = 0;
                if (S[ll[i] - 1] == 'C')
                {
                    if (ll[i] > 1)
                    {
                        if (S[ll[i] - 2] == 'A')
                        {
                            temp = dpres[rr[i] - 1] - dpres[ll[i] - 2] - 1;
                        }
                        else
                        {
                            temp = dpres[rr[i] - 1] - dpres[ll[i] - 2];
                        }
                    }
                    else
                    {
                        temp = dpres[rr[i] - 1];
                    }
                }
                else
                {
                    if (ll[i] > 1)
                    {
                        temp = dpres[rr[i] - 1] - dpres[ll[i] - 2];
                    }
                    else
                    {
                        temp = dpres[rr[i] - 1];
                    }
                }
                ress[i] = temp;
            }
            for (int i = 0; i < Q; i++)
            {
                Console.WriteLine(ress[i]);
            }
        }
    }
}

Measured memory_bytes: 17604
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	pair<int, int> A[N];
	for (int i = 0; i < N; i++)
	{
		cin >> A[i].first;
		A[i].second = i+1;
	}
	sort(A, A + N);
	for (int i = 0; i < N; i++)
	{
		cout << A[i].second;
		if(i == N - 1) cout << endl;
		else cout << " ";
	}
	
	return 0;
}


Measured memory_bytes: 1536
r=input().split()
N=int(r[0])
L=int(r[1])
ans=0
ans_li=[]
for i in range(N):
    ans+=L+(i+1)-1
    ans_li.append(L+(i+1)-1)
if 0 in ans_li:
    print(ans)
elif max(ans_li)>0:
    print(ans-min(ans_li))
else:
    print(ans-max(ans_li))

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

struct str {
    int a, b, c, d;
};
int n, m, q;
vector<str> vstr;
vector<int> nums;
int ans = 0;
void dfs(int idx, int n, int num, int m)
{
    if (idx == n) {
        int a = 0;
        REP(i, q)
        {
            if (nums[vstr[i].b] - nums[vstr[i].a] == vstr[i].c)
                a += vstr[i].d;
        }
        ans = max(ans, a);
        return;
    }
    for (int i = num; i <= m; i++) {
        nums[idx]=i;
        dfs(idx + 1, n, i, m);
    }
}

int main()
{
    cin >> n >> m >> q;
    vstr.resize(q);
    REP(i, q)
    {
        cin >> vstr[i].a >> vstr[i].b >> vstr[i].c >> vstr[i].d;
        vstr[i].a--;
        vstr[i].b--;
    }
    nums.resize(n);
    dfs(0, n, 1, m);
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int gcd(int a, int b)
{
    if (a > b)
        std::swap(a, b);

    while (true)
    {
        auto mod = b % a;
        b = a;
        a = mod;

        if (mod == 0)
            return b;
    }
}

int main()
{
    using namespace std;

    int a, b;
    cin >> a >> b;

    if (b % a == 0)
    {
        cout << a + b << endl;
    }
    else
    {
        cout << b - a << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256