akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int BITS = 18;

int main() {
    int N, K, S, T;
    cin >> N >> K >> S >> T;

    if ((S | T) != T) {
        cout << 0 << '\n';
        return 0;
    }

    vector<int> A;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;

        if ((a & S) != S || (a | T) != T)
            continue;

        A.push_back(a);
    }

    N = int(A.size());
    K = min(K, N);

    vector<vector<int64_t>> choose(N + 1, vector<int64_t>(N + 1, 0));

    for (int i = 0; i <= N; i++) {
        choose[i][0] = choose[i][i] = 1;

        for (int j = 1; j < i; j++)
            choose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1];
    }

    vector<int64_t> up_to_K(N + 1, 0);

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= K; j++)
            up_to_K[i] += choose[i][j];

    vector<int> freq(1 << BITS, 0);
    int64_t answer = 0;
    int overall = S ^ T;

    for (int mask = overall; ; mask = (mask - 1) & overall) {
        for (int &a : A)
            freq[a & mask]++;

        int64_t sum = 0;

        for (int &a : A) {
            sum += up_to_K[freq[a & mask]];
            freq[a & mask] = 0;
        }

        answer += (__builtin_popcount(mask) % 2 == 0 ? +1 : -1) * sum;

        if (mask == 0)
            break;
    }

    cout << answer << '\n';
}


Measured memory_bytes: 4328
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
 
const int maxN = 1 << 19;

pair <int, int> A[maxN], B[maxN];
int p[maxN];

void ans(bool ok)
{
	printf("%s\n", ok ? "Yes" : "No");
	exit(0);
}

void solve()
{
	int n;
	scanf ("%d", &n);
	FOR(i, 0, n)
		scanf ("%d", &A[i].st), A[i].nd = i;
	FOR(i, 0, n)
		scanf ("%d", &B[i].st), B[i].nd = i;
	
	sort(A, A+n);
	sort(B, B+n);
	FOR(i, 0, n)
		if (A[i].st > B[i].st)
			ans(false);
	FOR(i, 1, n)
		if (A[i].st <= B[i-1].st)
			ans(true);
			
	FOR(i, 0, n)
		p[A[i].nd] = B[i].nd;

	int len = 0, v = 0;
	do
	{
		len++;
		v = p[v];
	}
	while (v != 0);
	ans(len != n);
}
 
int main()
{
	int t;
	t = 1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}



Measured memory_bytes: 4736
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  lli a, b ,k;
  scanf("%lld%lld%lld", &a, &b, &k);

  lli s, t;
  s = max(a - k, 0);
  t = max(b - (k - (a - s)), 0);
  printf("%lld %lld\n", s, t);
  return 0;
}


Measured memory_bytes: 128
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto ss = readln.chomp;
  int res0, res1;
  foreach (i, s; ss) {
    if (i % 2) {
      if (s == '0') {
        res0++;
      } else {
        res1++;
      }
    } else {
      if (s == '0') {
        res1++;
      } else {
        res0++;
      }
    }
  }
  min(res0, res1).writeln;
}


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, l;
	string s;
	vector<string> ss;
	cin >> n >> l;
	rep(i, n) {
		cin >> s;
		ss.push_back(s);
	}
	sort(all(ss));
	rep(i, n) {
		cout << ss[i];
	}
	cout << endl;
}	


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
//  文字列を置換する
std::string Replace(std::string String1, std::string String2, std::string String3)
{
	std::string::size_type  Pos(String1.find(String2));

	while (Pos != std::string::npos)
	{
		String1.replace(Pos, String2.length(), String3);
		Pos = String1.find(String2, Pos + String3.length());
	}

	return String1;
}

vector<string> split(const string &str, char delim) {
	vector<string> res;
	size_t current = 0, found;
	while ((found = str.find_first_of(delim, current)) != string::npos) {
		res.push_back(string(str, current, found - current));
		current = found + 1;
	}
	res.push_back(string(str, current, str.size() - current));
	return res;
}
int solve(string st) {
	vector<int>v;
	int num=0;
	for (auto c : st) {
		if (c == '0') {
			if(num)v.push_back(num);
			num=0;
		}
		else {
			num++;
		}
	}
	if (num)v.push_back(num);
	vector<vector<int>>dp(v.size()+1,vector<int>(4,0));
	dp[0][0]=0;
	for (int i = 0; i < v.size(); ++i) {
		for (int used = 0; used < 4; ++used) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][used]);
			if (i == 0)continue;
			if (used == 3) {
				if (v[i - 1] >= 2) {

					dp[i + 1][2] = max(dp[i + 1][2], dp[i][used] + v[i]);
					dp[i + 1][1] = max(dp[i + 1][1], dp[i][used] + 1);
					if (v[i] >= 2) {

						dp[i + 1][3] = max(dp[i + 1][3], dp[i][used] + v[i] - 1);
					}
				}
			}
			else if(used==2) {
			}
			else if(used==1){
				if (v[i - 1] >= 2) {
					dp[i + 1][2] = max(dp[i + 1][2], dp[i][used] + v[i]);
					dp[i + 1][1] = max(dp[i + 1][1], dp[i][used] + v[i - 1]-1);
					if (v[i] >= 2) {

						dp[i + 1][3] = max(dp[i + 1][3], dp[i][used] + v[i] - 1);
					}
				}
			}
			else {
				dp[i+1][2]=max(dp[i+1][2],dp[i][used]+v[i]);
				dp[i+1][1]=max(dp[i+1][1],dp[i][used]+v[i-1]);
				if (v[i] >= 2) {

					dp[i + 1][3] = max(dp[i + 1][3], dp[i][used] + v[i] - 1);
				}
			}
		}
		dp[i+1][1]=max(dp[i+1][1],dp[i+1][0]);
		dp[i+1][2]=max(dp[i+1][2],dp[i+1][1]);
		
	}
	int ans=max(dp[v.size()][0],dp[v.size()][1]);
	ans=max(ans,dp[v.size()][2]);
	ans=max(ans,dp[v.size()][3]);
	return ans;
}
int main() {

	int N;cin>>N;
	string st;cin>>st;
	st="0"+st+"0";
	int num=0;
	vector<string>asts;
	int l=0;
	for (int i = 0; i < st.size(); ++i) {
		if(st[i]=='0')num++;
		else num=0;
		if (num == 2) {
			asts.push_back(st.substr(l,i-l+1));
			l=i+1;
		}
	}
	asts.push_back(st.substr(l, st.size() - l + 1));
	//st=Replace(st,"00"," ");
	//auto sts(split(st,' '));
	int sum=0;
	for (auto st : asts) {
		sum+=solve(st);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 4888
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines

s = readline().rstrip()
q = readline()
queries = readlines()
s = deque(s)
tot_1 = 0
for i in queries:
    if i[0] == '1':
        tot_1 += 1
        continue
    c = i[4]
    if (tot_1 + int(i[2])) % 2 == 0:
        s.append(c)
    else:
        s.appendleft(c)
ans = "".join(s) if tot_1 % 2 == 0 else "".join(reversed(s))
print(ans)

Measured memory_bytes: 21096
### SNIPPET
  # array = [*1..q].map { |_| gets.split.map(&:to_i) }
  # n = gets.split.map(&:to_i)
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select! { |num| num.even? }  # => [2, 4]
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さh = a * Math.sin(w / 180.0 * Math::PI)
  # 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end
n = gets.to_i
a = gets.split.map(&:to_i)

a.select! {|num| num.even?}

res = a.all? do |d|
  if d % 3 == 0 || d % 5 == 0
    true
  else
    false
  end
end

puts res ? "APPROVED" : "DENIED"

Measured memory_bytes: 1788
s = []
p = []
for i in 0..2
  s[i] = gets.chomp.split("")
  p[i] = s[i].count
end
nxt = 0
while 1
  p[nxt] -= 1
  if p[nxt] == -1
    break
  end
  c = s[nxt].shift
  if c == "a"
    nxt = 0
  elsif c == "b"
    nxt = 1
  elsif c == "c"
    nxt = 2
  end
end
if nxt == 0
  puts "A"
elsif nxt == 1
  puts "B"
elsif nxt == 2
  puts "C"
end

Measured memory_bytes: 1788
from heapq import heapify, heappop, heappush
N,H = map(int,input().split())
HQ = []
for i in range(N):
  a,b = map(int,input().split())
  heappush(HQ,(-a,0)) #IDとして0なら何度でも使える
  heappush(HQ,(-b,1))
ans = 0
prev_damage = -1
prev_id = -1
while H > 0:
  damage, ID = heappop(HQ); damage *= -1 #ダメージを正に
  if damage == prev_damage and prev_id == 0 and prev_id == ID:
    nokori = (H+damage-1)//damage
    ans += nokori
    print(ans)
    exit()
  H -= damage
  ans += 1
  prev_damage = damage; prev_id = ID
  if ID == 0:
    heappush(HQ,(-damage, ID))
print(ans)


Measured memory_bytes: 94892
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    vector<int> a(n);
    for(auto &x:a)scanf("%d",&x);
    ll ans=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i+j>n || i+j>k || i+j==0)continue;
            priority_queue<int,vector<int>, greater<int>> q;
            ll s=0;
            debug(i,j);
            for(int l=0;l<i;l++){
                s+=a[l];
                q.push(a[l]);
            }
            for(int l=0;l<j;l++){
                s+=a[n-1-l];
                q.push(a[n-1-l]);
            }
            debug(s);
            int cur=i+j;
            while(q.top()<0 && cur<k){
                debug(q.top());
                cur++;
                s-=q.top();
                q.pop();
                if(q.empty())break;
            }
            ans=max(s,ans);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int H, W; 
vector<string> s;
vector<pair<int, int>> p;
int used[14];


bool func(int pos, int c, bool odd) {
	if (c >= H/2) {

		bool u[14] = {};
		int cen = 0;
		
		if (H & 1) {
			for (auto i : p) {
				u[i.first] = u[i.second] = true;
			}
			for (int i = 0; i < H; i++) {
				if (!u[i]) cen = i;
				u[i] = false;
			}
		}

		for (int i = 0; i < W; i++) {
			if (u[i]) continue;
			for (int j = i + 1; j < W; j++) {
				if (u[j]) continue;
				bool flag = true;
				for (auto t : p) {
					int a = t.first, b = t.second;
					flag &= s[a][i] == s[b][j] && s[a][j] == s[b][i];
				}
				if (H & 1) flag &= s[cen][i] == s[cen][j];
				if (flag) {
					u[i] = u[j] = true;
					break;
				}
			}
		}

		int cnt = 0;
		for (int i = 0; i < W; i++) cnt += !u[i];
		if (cnt == 0) {
			return true;
		}
		if (cnt == 1 && W & 1) {
			for (int i = 0; i < W; i++) {
				if (u[i]) continue;
				bool flag = true;
				for (auto t : p) {
					flag &= s[t.first][i] == s[t.second][i];
				}
				if (flag) {
					return true;
				}
			}
		}
		
		return false;
	}

	if (used[pos] != -1) return func(pos + 1, c, odd);

	bool ret = false;
	for (int i = pos + 1; i < H; i++) {
		if (used[i] != -1) continue;
		used[pos] = used[i] = pos;
		p.push_back({ pos, i });
		
		ret |= func(pos + 1, c + 1, odd);
		
		p.pop_back();
		used[pos] = used[i] = -1;
		if (ret) break;
	}

	if (odd) {
		used[pos] = pos;
		ret |= func(pos + 1, c, false);
		used[pos] = -1;
	}

	return ret;
}

int main() {
	cin >> H >> W;
	s = vector<string>(H);
	for (int i = 0; i < H; i++) cin >> s[i];
	for (int i = 0; i < H; i++) used[i] = -1;
	cout << (func(0, 0, H&1) ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <stdlib.h>
#include <queue>
#include <set>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

const int N = 100003 + 1;
vector<bool> isp(N, true);
void sieve()
{
  isp[0] = false;
  isp[1] = false;
  for (auto i = 0; i <= N; i++)
  {
    if (isp[i])
    {
      for (auto j = 2; i * j <= N; j++)
        isp[i * j] = false;
    }
  }
}

int main()
{
  sieve();
  ll k;
  cin >> k;

  for (auto i = k; i <= N; i++)
  {
    if (isp[i])
    {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
/*
 * Given an H*W-sized, 0/1-valued matrix, find the area of the largest
 * rectangle containing only 0s.
 *
 * 1 <= H, W <= 1400
 */

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

int m[1400][1400];

int main() {
  int h, w;
  cin >> h >> w;
  int A{0};
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      cin >> m[i][j];
  vector<int> d(w, -1), l(w), r(w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j)
      if (m[i][j])
        d[j] = i;
    stack<int> st;
    for (int j = 0; j < w; ++j) {
      while (!st.empty() && d[st.top()] <= d[j])
        st.pop();
      l[j] = st.empty() ? -1 : st.top();
      st.push(j);
    }
    while (!st.empty())
      st.pop();
    for (int j = w - 1; j >= 0; --j) {
      while (!st.empty() && d[st.top()] <= d[j])
        st.pop();
      r[j] = st.empty() ? w : st.top();
      st.push(j);
    }
    for (int j = 0; j < w; ++j)
      A = max(A, (i - d[j]) * (r[j] - l[j] - 1));
  }
  cout << A << endl;
}



Measured memory_bytes: 10752
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> pos, neg;
    vector<pair<ll, ll>> p;
    ll zero = 0;
    for (ll i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        p.emplace_back(abs(a), a > 0 ? 1 : (a == 0 ? 0 : -1));
        if (a == 0)
            zero++;
        else if (a > 0)
            pos.emplace_back(a);
        else
            neg.emplace_back(a);
    }
    ll np = pos.size(), nn = neg.size();

    // Must choose 0
    if (k > np + nn) {
        cout << 0;
        return 0;
    }

    sort(neg.rbegin(), neg.rend());
    sort(p.rbegin(), p.rend());

    // Can only choose from negative numbers, choose those with the least absolute value
    if (nn == n && k % 2 == 1) {
        ll ans = 1;
        for (ll i = 0; i < k; ++i)
            ans = ans * neg[i] % MOD;
        if (ans < 0)
            ans += MOD;
        cout << ans;
        return 0;
    }

    // Choose those with the largest absolute value
    ll bal = 0;
    for (ll i = 0; i < k; ++i)
        bal += p[i].second == -1;
    if (bal % 2 == 0) {
        ll ans = 1;
        for (ll i = 0; i < k; ++i)
            ans = ans * p[i].first % MOD;
        if (ans < 0)
            ans += MOD;
        cout << ans;
        return 0;
    }

    // Need to adjust one element
    ll x1 = -1, y1 = -1, x2 = -1, y2 = -1;
    // - => +
    {
        ll x = k - 1;
        while (x >= 0 && p[x].second == 1)
            x--;
        ll y = k;
        while (y < n && p[y].second == -1)
            y++;
        if (x >= 0 && y < n)
            x1 = x, y1 = y;
    }

    // + => -
    {
        ll x = k - 1;
        while (x >= 0 && p[x].second == -1)
            x--;
        ll y = k;
        while (y < n && p[y].second == 1)
            y++;
        if (x >= 0 && y < n)
            x2 = x, y2 = y;
    }

    if (x1 == -1) {
        swap(p[x2], p[y2]);
    } else if (x2 == -1) {
        swap(p[x1], p[y1]);
    } else {
        ll left = (ll)p[x1].first * p[y2].first;
        ll right = (ll)p[x2].first * p[y1].first;
        if (left < right)
            swap(p[x1], p[y1]);
        else
            swap(p[x2], p[y2]);
    }
    ll ans = 1;
    for (ll i = 0; i < k; ++i)
        ans = ans * p[i].first * p[i].second % MOD;
    if (ans < 0)
        ans += MOD;
    cout << ans;
}


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

int main(){
    long double a,b;
    cin >> a >> b;
    cout << setprecision(1000) << floor(a*b);
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define forr(i,z,u,l) for(i=z;i<u;i+=l)
#define f(i,n) for(i=0;i<n;i++)
using namespace std;
#define F first
#define S second
#define vi vector<int>
#define vll vector<long long>
#define vld vector<long double>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vb vector<bool>
#define all(v) v.begin(),v.end()
#define ump unordered_map
#define dbg(x) cout<<#x<<" : "<<x << endl;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvpll vector<vector<pll>>
#define endl "\n"
const ll M = 1e9 + 7;


long long pow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void solve()
{
	string a;
	cin>>a;
	ll ans=0;
	for(auto i:a){
		ans = (ans + (i-'0')) % 9;
	}
	if(ans == 0)
		cout << "Yes" << endl;
	else cout << "No" << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	
	
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define rep0(i, n) for(int i=0; i<(int)(n);i++)
using namespace std;
typedef int64_t lint;

int main(){
    string s, t;
    cin >> s >> t;
    set<lint> sabc[26]; //a,b,c...が何文字目にくるか
    
    rep0(i, s.length() * 2)
    {
        sabc[s[i % s.length()]-'a'].insert(i + 1);
    }

    lint used = 0; //現在の文字位置
    lint pos = 0; //直前の文字の位置
    lint sloop = 0; //sを何度繰り返すか
    rep0(i, t.length())
    {
        if(sabc[t[i]-'a'].size() == 0)
        {// もしsに存在しない文字を使っていたら不可能
            used = -1;
            break;
        }
        lint sc = *sabc[t[i]-'a'].lower_bound(pos + 1);
        used = s.length() * sloop + sc;
        if(sc > s.length()){
            sloop++;
            pos = sc - s.length();
        }
        else pos = sc;
    }
    cout << used << endl;
    return 0;
}

Measured memory_bytes: 9856
N =int(input())
ans = 1
t = [int(i) for i in input().split()]
for i in t:
    if i == 0:
        print(0)
        exit()
for i in t:
    ans = ans * i
    if ans > (10**18):
        print(-1)
        exit()

print(ans)
exit()


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

int abs( int a )
{
    return a < 0 ? -a : a;
}

int min( int a, int b )
{
    return a < b ? a : b;
}

int dp[100001];
// void calcMin( int* a, int n, int k )
// {
//     dp[1] = fabs( a[0] - a[1] );

//     for( int i = 2; i < n; i++ )
//     {
//         int min = 10000;
//         for( int j = i - 1; j >= 0 && j >= i - k; j-- )
//         {
//             int b = dp[j] + fabs( a[j] - a[i] );
//             if( b < min )
//                 min = b; 
//         }
//         dp[i] = min;
//     }
// }

void get_res( int* a, int n, int k )
{
    dp[0] = 0;
    for( int i = 0; i < n; i++ )
        for( int j = 1; j < k+1; j++ )
	    if(i >= j){
            dp[i] = min( dp[i], dp[i-j] + abs( a[i] - a[i-j] ) );
	    }
}


int main()
{
    int n, k;

    cin >> n >> k;

    int a[n];

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

    for( int i = 1; i < 100001; i++ )
        dp[i] = 2000000000;
    dp[0] = 0;

    get_res( a, n, k );
    cout << dp[n-1] << endl;
    // for( int i = 0; i < n; i++ )
    //     cout << dp[i] << " ";
    // cout << endl;

    return 0;
}



Measured memory_bytes: 1024
x1, y1, x2, y2 = list(map(int, input().split(' ')))
d_x = (x2 - x1)
d_y = (y2 - y1)
print('%d %d %d %d' % (x2 - d_y, y2 + d_x, x2 - d_y - d_x, y2 + d_x - d_y))


Measured memory_bytes: 2940
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        sv: [String; n]
    };

    let mut table: HashMap<String, usize> = HashMap::new();
    for s in sv {
        *table.entry(s).or_insert(0) += 1;
    }
    let max = *table.values().max().unwrap();
    let mut set = BTreeSet::new();
    for (s, c) in table {
        {
            if c == max {
                set.insert(s);
            }
        }
    }
    for s in set {
        println!("{}", s);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 26572
def main():
    bounces = 1
    n,x = map(int,input().split())
    L = list(map(int,input().split()))
    d = 0
    for i in range(1,n+1):
        d += L[i-1]
        if d > x:
            break
        bounces += 1

    print(bounces)

main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define Maxn 1000000 + 10
using namespace std;
int n;
int h;
int result = 0;
map<ll,ll>id;
map<ll,ll>::iterator it;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        id[x]=i;
    }
    for(it=id.begin(); it!=id.end(); it++)//遍历即可
        cout<<it->second<<" ";
    
    cout << endl;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x;cin >> x;return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
const ll N = 2e5 + 5;
ll a[N];
ll n, k;
bool chk(ll x){
    ll cuts = 0;
    fo(i, n){

        if(a[i] > x)cuts += (a[i]/x) - 1 + (a[i]%x > 0);
    }
    //cout << x << "  " << cuts << nl;
    return (cuts <= k);
}
void solve(){
    cin >> n >> k;
    //ll a[n];
    ll mx = 0;
    fo(i, n)cin >> a[i], mx = max(mx, a[i]);
    ll l = 1, r = mx,ans;
    while(l <= r){
        ll mid = l + (r - l)/2;
        if(chk(mid))r = mid - 1,ans = mid;
        else l = mid + 1;
    }
    ANS;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 5320
k=input()
a=list(map(int,input().split()))
p=1
count=0
if(len(a)==0):
    print("0")
elif 0 in a:
    print("0")
else:
    while(count<len(a)):
        p*=a[count]
        count+=1
        if(p>pow(10,18)):
            print("-1")
            break
    if(p<=pow(10,18)and len(a)>0):
        print(p)

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

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  for(int i=0;i<n;i++){
  cin >> a[i];
  }
  long long b[200010];
  b[0] =0;
  for(int q=0;q<k;q++){b[0]+=a[q];}
  long long km=b[0];
  for(int i=1;i<n-k+1;i++){
    b[i] = b[i-1]-a[i-1]+a[i+k-1];
    km=max(km,b[i]);
  }
  double ans=(double)(km+k)/2;
  printf("%.12lf\n",ans);
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
const int mod = 1e9 + 7;
ll power(ll a, ll b)
{
    ll ans = 1 % mod;
    while (b > 0)
    {
        if (b & 1)
        {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    ll mx = -1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    int len = 0;
    while (mx)
    {
        mx = mx >>= 1;
        len++;
    }
    vector<ll> cnt0(len + 1), cnt1(len + 1);
    for (int i = 1; i <= n; i++)
    {
        ll cur = a[i];
        int t = 0;
        for (int j = 0; j < len; j++)
        {
            if (cur >> j & 1)
            {
                cnt1[j]++;
            }
            else
            {
                cnt0[j]++;
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < len; i++)
    {
        ans = (ans + cnt0[i] * cnt1[i] % mod * power(2, i) % mod) % mod;
    }
    cout << ans << "\n";
    //cout << len << "\n";
    return 0;
}

Measured memory_bytes: 5572
import math


def main():
  n, k = map(int, input().split())

  if n == 2:
    if k == 0:
      print(1)
      print(1, 2)
    else:
      print(-1)

    return

  v = math.factorial(n - 1) // math.factorial(n - 3) // 2

  if k > v:
    print(-1)
    return

  nodes = [(0, i) for i in range(1, n)]
  s = 1
  d = 2

  while v > k:
    nodes.append((s, d))
    d += 1
    v -= 1

    if d == n:
      s += 1
      d = s + 1

  print(len(nodes))

  for s, d in nodes:
    print(s + 1, d + 1)


if __name__ == '__main__':
  main()


Measured memory_bytes: 44784
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+3;
const long long mod=1000000000+7;
long long p[maxn],tmp[maxn];
int n;
int fa[maxn],sz[maxn];
long long dp[maxn][maxn];
vector<int> edge[maxn];
void dfs(int u)
{
	int siz=edge[u].size();
	sz[u]=dp[u][1]=1;
	for(int i=0;i<siz;i++)
	{
		int v=edge[u][i];
		if(v!=fa[u])
		{
			fa[v]=u;
			dfs(v);
			for(int j=1;j<=sz[u]+sz[v];j++) tmp[j]=0;
			for(int j=1;j<=sz[u];j++)
				for(int k=1;k<=sz[v];k++)
				{
					if(u!=0) tmp[j+k]+=dp[v][k]*dp[u][j],tmp[j+k]%=mod;
					if(!(k&1)) tmp[j]-=(dp[u][j]*dp[v][k])%mod*p[k]%mod,tmp[j]=(tmp[j]+mod)%mod;
				}
			sz[u]+=sz[v];
			for(int j=1;j<=sz[u];j++) dp[u][j]=tmp[j];
		}
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++) 
	{
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	p[0]=1;
	for(int i=1;i<=n;i+=2) p[i+1]=p[i-1]*i%mod;
	edge[0].push_back(1);
	dfs(0);
	printf("%lld\n",(mod-dp[0][1])%mod);
	return 0;
}
/*
10
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7
*/
/*
672
*/

Measured memory_bytes: 195200
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out);) {
			int N = sc.nextInt();
			int[] C = new int[N];
			int[] S = new int[N];
			int[] F = new int[N];
			for (int i = 0; i < N - 1; i++) {
				C[i] = sc.nextInt();
				S[i] = sc.nextInt();
				F[i] = sc.nextInt();
			}
			for (int i = 0; i < N; i++) {
				int t = S[i];
				for (int j = i; j < N - 1; j++) {
					if (S[j] > t) {
						t = S[j];
					} else if (t % F[j] > 0) {
						t += F[j] - (t % F[j]);
					}
					t += C[j];
				}
				pw.println(t);
			}
			pw.flush();
		} catch (Exception e) {
		}
	}
}

Measured memory_bytes: 26020
//Generated at 2019-08-17 20:37:54 UTC+8
//Created by Alphagocc
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN=3e5;
const ll P=817;
const ll MOD=1145141919;

ll H[MAXN],POW[MAXN];

int main()
{
    string s;
    cin >> s;
    int n=s.size();
    for (int i=1;i<=n;i++)
    {
        H[i]=(H[i-1]*P+s[i-1])%MOD;
    }
    POW[0]=1;
    for (int i=1;i<=n;i++)
    {
        POW[i]=POW[i-1]*P%MOD;
    }
    int ans=1;
    int pos=0,l1=1,l2=1;
    while(pos+l1+l2<=n)
    {
        ll t1=(H[pos+l1]-H[pos]+MOD)%MOD;
        ll t2=(H[pos+l1+l2]-H[pos+l1]+MOD)%MOD;
        //cout << t1 <<" "<< t2 << endl;
        if (l1!=l2||(t1*POW[l1]%MOD!=t2))
        {
            //cout << pos << " "<< l1 << " "<< l2 << endl;
            pos+=l1;
            l1=l2,ans++;
            l2=1;
        }else
        {
            l2++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4228
/*#include <iostream>
#include <string>
using namespace std;

int main(){
	 ios::sync_with_stdio(false);
	string a, b;
	int x, i = 0;
	cin >> a >> b;
	for(int i = 0;a[i];i++){
		i = a.find(b, i);
		if(i == -1)break;
		cout << i << endl;
	}
	while((x = a.find(b, i)) != -1){
		cout << x << endl;
		i = x + 1;
	}
	return 0;
}*/

#include <iostream>
using namespace std;string t,p;int main(){ios::sync_with_stdio(false);cin>>t>>p;for(int i=0;t[i];i++){i=t.find(p, i);if(i==string::npos)break;cout<<i<<'\n';}return 0;}

Measured memory_bytes: 4664
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int cnt = 0;
        sc.close();
        while (C != 0 && B >= A) {
            B = B - A;
            --C;
            cnt++;
        }
        System.out.println(cnt);

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,K;
    cin>>N>>K;
    cout <<((N+1)/2>=K?"YES":"NO")<<"\n";
}


Measured memory_bytes: 892
s = input()

s_1 = int(s[0:2])
s_2 = int(s[2:4])

if (s_1>12 or s_1<1) and (s_2>12 or s_2<1):
    print('NA')
elif s_1<=12 and s_1>=1 and s_2<=12 and s_2>=1:
    print('AMBIGUOUS')
elif s_1<=12 and s_1>=1:
    print('MMYY')
else:
    print('YYMM')

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

bool vis[MAXn*3];
int main(){
    IOS();
    int n,x;
    cin >> n >> x;
    if (n == 2) {
        if (x == 2) {
            cout << "Yes" << endl;
            cout << "1\n2\n3" << endl;
        }
        else {
            cout << "No" << endl;
        }
        return 0;
    }
    int mx = 2*n-1;
    if (x == 1 || x == mx) return cout << "No" << endl,0;
    
    deque<int> dq;
    for (int i=-1;i<=1;++i) {
        dq.eb(x+i);
        vis[x+i] = true;
    }
    if (x+2 <= mx) {
        dq.emplace_front(x+2);
        vis[x+2] = true;
        int cnt = 0;
        for (int i=1;i<=mx;++i) {
            if (vis[i]) continue;
            if (cnt < n-3) dq.emplace_front(i),cnt++;
            else dq.eb(i);
        }
    }
    else {
        dq.eb(x-2);
        vis[x-2] = true;
        int cnt = 0;
        for (int i=1;i<=mx;++i) {
            if (vis[i]) continue;
            if (cnt < n-2) dq.emplace_front(i),cnt++;
            else dq.eb(i);
        }
    }
    cout << "Yes" << endl;
    for (int i=0;i<mx;++i) {
        cout << dq.front() << endl;
        dq.pop_front();
    }
}


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

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

    int n = 3;
    vector<string> S(n);
    for(int i = 0; i < n; i++){
        cin >> S[i];
    }

    vector<int> A(n, 0);
    int now = 0, ans = -1;
    while(true){
        if(S[now].size() == A[now]){
            break;
        }
        char tp = S[now][A[now]];
        A[now]++;
        now = (int)(tp - 'a');
    }

    cout << char((int)('A' + now)) << endl;

    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(void)
{
	int n,i,a,s,d,f,x[101],w[101],q[101],j,o;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		x[i]=0;
		w[i]=0;
		q[i]=0;
	}	
	for(i=1;i<=n*(n-1)/2;i++){
		scanf("%d %d %d %d",&a,&s,&d,&f);
		if(d<f){
			x[s]+=3;
		}
		if(f<d){
			x[a]+=3;
		}	
		if(d==f){
			x[a]++;
			x[s]++;
		}
	}
	for(i=1;i<=n;i++){
		w[i]=x[i];
	}	
	o=0;
	for(i=1;i<=n-1;i++){
		for(j=i+1;j<=n;j++){
			if(x[i]<x[j]){
				o=x[j];
				x[j]=x[i];
				x[i]=o;
			}
		}
	}	
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(w[i]==x[j]){
				w[i]=j;
				break;
			}
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",w[i]);
	}	
	return 0;	
}

Measured memory_bytes: 2748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

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

int main() {

  ll N, M, Q;

  cin >> N >> M >> Q;

  ll ray[502][502] = {};

  // vector<vector<ll>> ray;
  //
  // ray.resize(500+1);
  // for (int i = 0; i < N + 1; i++) ray[i].resize(500+1);

  ll a, b;
  for (ll i = 0; i < M; i++){
    cin >> a >> b;
    ray[a][b]++;
  }

  for (int i = 1; i < N + 1; i++){
    for (int j = 1; j < N + 1; j++){
      ray[i][j+1] += ray[i][j];
    }
  }

  for (int i = N; i >= 1; i--){
    for (int j = 1; j < N + 1; j++){
      ray[i-1][j] += ray[i][j];
    }
  }

  vector<ll> ans;
  for (ll i = 0; i < Q; i++){
    cin >> a >> b;
    ans.push_back(ray[a][b]);
  }

  // for (int i = 1; i < N + 1; i++){
  //   for (int j = 1; j < N + 1; j++){
  //     cout <<ray[i][j];
  //   }
  //   cout << endl;
  // }


  for (ll i = 0; i < Q; i++){
    cout << ans[i] << endl;
  }


  return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N;
constexpr int Nmax = 100000;
vector<plint> D;
vector<int> to[Nmax];

plint dfs(int now, int prev)
{
    lint d = 0, subtreesz = 1;
    for (auto nxt : to[now]) if (nxt != prev)
    {
        plint pa = dfs(nxt, now);
        d += pa.first + pa.second;
        subtreesz += pa.second;
    }
    return plint(d, subtreesz);
}

int main()
{
    cin >> N;
    D.resize(N);
    REP(i, N)
    {
        cin >> D[i].first;
        D[i].second = i;
    }

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

    map<lint, vector<pint>> ma; // requiredD -> [(childId, stSz)]

    while (!D.empty())
    {
        lint Dnow, id_now;
        tie(Dnow, id_now) = D.back();
        D.pop_back();

        int stsz = 1;

        if (ma.count(Dnow))
        {
            for (auto pa : ma[Dnow])
            {
                to[id_now].push_back(pa.first);
                to[pa.first].push_back(id_now);
                stsz += pa.second;
            }
            ma.erase(Dnow);
        }
        ma[Dnow + 2 * stsz - N].push_back(pint(id_now, stsz));
    }

    vector<pint> res;
    REP(s, N) for (auto t : to[s]) if (s < t) res.push_back(pint(s, t));

    // dbg(dfs(D[0].second, -1));
    if (res.size() != N - 1 || dfs(D[0].second, -1).first != D[0].first) cout << -1 << endl, exit(0);

    for (auto pa : res) cout << pa.first + 1 << " " << pa.second + 1 << endl;
}


Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  ll N, K;
  cin >> N >> K;
  ll d = N / K;
  ll ans = d * d * d;

  if (K % 2 != 0) {
    cout << ans << endl;
    return 0;
  }

  ll dd = 0;
  if (N - (K / 2) >= 0) {
    dd = (N - (K / 2)) / K + 1;
  }
  ans += dd * dd * dd;
  cout << ans << endl;
}


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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;
  bool ans = true;
  rep(i, a, c + 1) {
    if (s[i] == '#' && s[i + 1] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }

  rep(i, b, d + 1) {
    if (s[i] == '#' && s[i + 1] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  if (c > d) {
    ans = false;
    rep(i, b, d + 1) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') {
        ans = true;
      }
    }
  }
  printf("%s\n", (ans) ? "Yes" : "No");
}


Measured memory_bytes: 640
N, M, X = map(int, input().split())
book = [tuple(map(int, input().split())) for _ in range(N)]

INF = float('inf')


def calc(index, cost, point):
    if index == N:
        if len(list(filter(lambda p: p < X, point))) > 0:
            return INF
        return cost

    np = point[:]
    for i, a in enumerate(book[index][1:]):
        np[i] += a

    return min(calc(index + 1, cost, point), calc(index + 1, cost + book[index][0], np))


res = calc(0, 0, [0 for _ in range(M)])
print(res if res != INF else -1)


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

#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
vector<pii> v1, v2;
multiset<int> m;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  v1.resize(N);
  v2.resize(N);
  for(int i=0; i<N; ++i)
    cin >> v1[i].fi >> v1[i].se; 
	for(int i=0; i<N; ++i)
    cin >> v2[i].fi >> v2[i].se;
  sort(all(v1));
  sort(all(v2));
  int id = 0, res = 0;
  for(auto x: v2){
    while(id < sz(v1) && v1[id].fi < x.fi) m.insert(v1[id++].se);
    auto it = m.lb(x.se);
    if(it != m.begin()){
      ++res;
      m.erase(prev(it));
    }
  } 
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  vector<ll> from_left(n+1, 0);
  vector<ll> from_right(n+1, 0);
  rep(i, n) {
    from_left[i+1] = from_left[i];
    if (s[i] == 'W') from_left[i+1]++;
  }
  repr(i, n-1) {
    from_right[i] = from_right[i+1];
    if (s[i] == 'E') from_right[i]++;
  }
  ll ans = INF;
  rep(i, n+1) {
    ans = min(ans, from_left[i] + from_right[i]);
  }
  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 8192
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>

using namespace std;

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

#define EPS 1e-10
#define EQUAL(a, b) (fabs((a)-(b))<EPS)

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		double x1, y1, x2, y2, x3, y3, x4, y4;
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
		puts(EQUAL((x2-x1)*(y4-y3), (y2-y1)*(x4-x3)) ? "YES" : "NO");
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	long long a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	
	if (a > b) swap(a, b);
	
	long long p = a + v * t;
	long long q = b + w * t;
	
	if (q <= p) {
		cout << "YES" << '\n';
	} else {
		cout << "NO" << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 3636
def main():
    H, W = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(H)]
    A = [[i, j, k] for i, a in enumerate(A) for j, k in enumerate(a)]
    for i in range(W, len(A), 2 * W):
        A[i: i + W] = A[i + W - 1:i - 1:-1]
    i = 0
    ans = []
    count = 0
    while i < len(A):

        if A[i][2] % 2 != 0:
            j = 1
            while i + j < len(A):
                if A[i + j][2] % 2 != 0:
                    for k in range(i, i + j):
                        ans.append([A[k][0], A[k][1], A[k + 1][0], A[k + 1][1]])
                        count += 1
                    i += j
                    break
                j += 1
            else:
                break
        else:
            pass
        i += 1
    print(count)
    for a in ans:
        print(' '.join(list(map(lambda x: str(x + 1), a))))

if __name__ == '__main__':
    main()


Measured memory_bytes: 49416
package main

import (
	"fmt"
)

func main() {
	q := readInt64() // 1/4
	h := readInt64() // 1/2
	s := readInt64() // 1
	d := readInt64() // 2
	n := readInt64()

	e := s
	if e > q*4 {
		e = q * 4
	}
	if e > h*2 {
		e = h * 2
	}

	f := d
	if d > e*2 {
		f = e * 2
	}

	needYen := int64(n/2) * f
	if n%2 == 1 {
		needYen += e
	}

	fmt.Println(needYen)
}

func readInt64() int64 {
	var a int64
	fmt.Scan(&a)
	return a
}


Measured memory_bytes: 512