akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static boolean isTrue(ArrayList<Integer> a,int goal,boolean isX){
       /* if (a.size() == 0){
            if(goal ==0) return true;
            else return false;
        }*/
        int s = 16001;
        int[][] table = new int[a.size()+1][s];
        for(int i=0; i<table.length; i++){
            for(int j=0; j<table[0].length; j++){
                table[i][j] = 0;
            }
        }
        table[0][s/2] = 1;
        for(int i=0; i<table.length-1; i++){
            for(int j=0; j<table[0].length; j++){
                if(table[i][j] == 1){
                    table[i+1][j+a.get(i)] = 1;
                    if(!(isX && i==0)) {
                        table[i + 1][j - a.get(i)] = 1;
                    }
                }
            }
        }
        if(table[table.length-1][goal+s/2] == 1){
            return true;
        }else{
            return false;
        }
    }

    public static void main(String[] args) throws Exception {
        String[] s = br.readLine().trim().split("");
        int[] arr = inputval();
        int finalx = arr[0];
        int finaly = arr[1];
        ArrayList<Integer> x = new ArrayList<>();
        ArrayList<Integer> y = new ArrayList<>();
        int flag = 1;
        int count = 0;
        for(int i=0; i<s.length; i++){
            if(s[i].equals("T")){
                if(flag ==1){
                    x.add(count);
                }else{
                    y.add(count);
                }
                flag = -flag;
                count = 0;
            }else if(s[i].equals("F")){
                count++;
                if(i == s.length-1){
                    if(flag ==1){
                        x.add(count);
                    }else{
                        y.add(count);
                    }
                }
            }
        }
        if(isTrue(x,finalx,true) && isTrue(y,finaly,false)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }

    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    static void array_sout(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    static void array_sout(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll m = N / i;
    ll x = m * (m + 1) / 2;
    ans += x * i;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>
int main() {int RideBack[10],i,j;char T[11];while (scanf("%s",&T)!=EOF) {for (i=0;i<10;RideBack[i]=T[i]-48,i++);for (j=0;j<=8;j++) for (i=9;i>0;i--) RideBack[i]=(RideBack[i]+RideBack[i-1])%10;printf("%d\n",RideBack[9]);}return 0;}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bOut(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return d
}

var lp int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp)
	sc.Split(bufio.ScanWords)
	n, k, c := iScan(), iScan(), iScan()
	s := Scan()
	r := 0
	p, q := make([]int, 0, k), make([]int, 0, k)
	for i := 0; i < n && len(p) != k; i++ {
		if r <= 0 && string(s[i]) != "x" {
			p = append(p, i)
			r = c
		} else {
			r--
		}
	}
	r = 0
	for i := n - 1; i >= 0 && len(q) != k; i-- {
		if r <= 0 && string(s[i]) != "x" {
			q = append(q, i)
			r = c
		} else {
			r--
		}
	}
	for i := 0; i < k; i++ {
		if p[i] == q[k-i-1] {
			fmt.Println(p[i] + 1)
		}
	}
}


Measured memory_bytes: 7052
from bisect import bisect_left

N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
ans = 0
for i in range(N):
    for j in range(i+1,N):
        a = L[i]
        b = L[j]
        ans += bisect_left(L[j+1:], a+b)
print(ans)


Measured memory_bytes: 52684
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

int main(){
  ll n;cin>>n;
  ll ans=0;
  
  if(n%2==1){
    cout<<0<<endl;
  }
  
  else{
    n=n/2;
    while(n>0){
      n=n/5;
      ans+=n;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>

using lli = long long int;
int inf = 1000000007;
using namespace std;
#define sort(X) sort(X.begin(),X.end())

int N, Ma, Mb;

int main()
{
	cin >> N >> Ma >> Mb;
	int dp[410][410];
	for (int i = 0; i <= 400; i++)
		for (int j = 0; j <= 400; j++)dp[i][j] = -inf;
	dp[0][0] = 0;

	for (int i = 0; i < N; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int x = 400; x >= 0; x--) {
			for (int y = 400; y >= 0; y--) {
				if (dp[x][y] >= 0) {
					if (dp[x + a][y + b] == -inf)
						dp[x + a][y + b] = dp[x][y] + c;
					else dp[x + a][y + b] = min(dp[x + a][y + b], dp[x][y] + c);
				}
			}
		}
	}
	int ans = inf;
	int Maa = Ma;
	int Mbb = Mb;
	while (Ma <= 400 && Mb <= 400) {
		if (dp[Ma][Mb] != -inf)ans = min(ans, dp[Ma][Mb]);
		Ma += Maa, Mb += Mbb;
	}
	cout << (ans == inf ? -1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	char a,b;
	scanf("%c %c", &a, &b);

	if(a>b){
		printf(">\n");
	}else if(a==b){
		printf("=\n");
	}else{
		printf("<\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;


int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    if(k==0){
        cout<<n*n<<endl;
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(i<=k) continue;
        ll tmp=0;
        ll q=n/i;
        tmp+=(i-k)*q;
        ll r=n%i;
        if(r!=0) tmp+=max(0LL,r-k+1);
        //cout<<i<<" "<<tmp<<endl;
        ans+=tmp;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3552
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, ABs):
    ABs.sort(key=lambda x: x[1])
    time = 0
    ans = 'Yes'
    for A, B in ABs:
        time += A
        if time > B:
            ans = 'No'
            break
    print(ans)


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    ABs = [[int(i) for i in input().split()] for _ in range(N)]
    # Bs = [int(i) for i in input().split()]
    solve(N, ABs)


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

int main(){
	int n;
	scanf("%d", &n);
	bitset<32> bit(n);
	cout << bit << '\n';
	cout << bit.flip() << '\n';
	bit.flip();
	cout << (bit << 1) << '\n';
	cout << (bit >> 1) << '\n';
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

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

	cout<< ((a+b-1)/b)*c << endl;
 
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
const   ll MOD=1000000007;
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
const ll mo=-1;
int main()
{
     io;
    int T=1;
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
      ll n,k,i,j,pos=0,neg=0;
       cin>>n>>k;
       vl v(n);
       for(ll &x:v)
       {
           cin>>x;
           if(x>=0)pos++;
       }
       neg=n-pos;
       sort(all(v));
       if(n==k)
       {
           ll mul=1;
           for(i=0;i<neg;i++)mul=(mul*(mo*v[i]))%MOD;
           for(;i<n;i++)mul=(mul*v[i])%MOD;
           if(neg&1)mul=MOD-mul;
           cout<<mul;
           _

       }
       if(neg==n and (k&1))
       {
            ll mul=1;
           for(i=n-1;i>n-k;i-=2)
           {
                mul=(mul* (mo*v[i]))%MOD;
                mul=(mul* (mo*v[i-1]))%MOD;
           }
           v[n-k]*=mo;
           mul=MOD-(mul* v[n-k])%MOD;
           cout<<mul;
           _
       }
        i=max(neg,n-k),j=0;
       if(k>n-i and (k-(n-i))&1)i++;
     if(k>n-i)  j=k-(n-i);
       for(;j<neg-1 and i<n-1 and mo*v[j]>v[i];j+=2)
       {
            ll a=mo*v[j],b=mo*v[j+1];
           if(a+b>v[i]+v[i+1])i+=2;
           else if(a+b==v[i]+v[i+1] and (a-b)<v[i+1]-v[i])i+=2;
           else break;
       }
        ll mul=1;
       for(j--;j>0;j-=2)
       {
           mul=(mul* (mo*v[j]))%MOD;
           mul=(mul* (mo*v[j-1]))%MOD;
       }
       for(;i<n;i++)
       {
           mul=(mul* v[i])%MOD;
       }
       cout<<mul;
}
    return 0;
}


Measured memory_bytes: 4788
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int n, k, c[5010], r[5010], a[10010], b[10010];
VI node1[5010], node2[5010];

priority_queue<PII, VP, greater<PII> > pq;
int cheap[5010];

void bfs(int st)
{
  bool visited[5010];
  queue<int> qu;
  memset(visited, false, sizeof visited);
  
  qu.push(st);
  
  for(int i = 0; i <= r[st]; i++){
    int sz = qu.size();

    for(int j = 0; j < sz; j++){

      int now = qu.front();
      qu.pop();

      if(!visited[now]){
	visited[now] = true;
	
	if(i > 0){
	  node2[st].PB(now);
	}
	
	for(auto pt:node1[now]){
	  qu.push(pt);
	}
      }
    }
  }
}

void dijk()
{
  memset(cheap, -1, sizeof cheap);
  
  pq.push(MP(0, 1));

  int counter = 1;
  while(!pq.empty()){
    PII now = pq.top();
    pq.pop();

    if(cheap[now.S] == -1){
      cheap[now.S] = now.F;
      
      for(auto pt:node2[now.S]){
	if(cheap[pt] == -1){
	  pq.push(MP(now.F + c[now.S], pt));
	}
      }
    }
  }
}

signed main()
{
  cin >> n >> k;
  for(int i = 1; i <= n; i++){
    cin >> c[i] >> r[i];
  }
  for(int i = 1; i <= k; i++){
    cin >> a[i] >> b[i];
    node1[a[i]].PB(b[i]);
    node1[b[i]].PB(a[i]);
  }

  for(int i = 1; i <= n; i++){
    bfs(i);
  }

  dijk();

  cout << cheap[n] << endl;

  return 0;
}

Measured memory_bytes: 258752
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

class BIT
{
public:
	vector<ll> bit;
	int M;

	BIT(int M) :
		bit(vector<ll>(M + 1, 0)), M(M) {}

	int sum(ll i) {
		if (!i) return 0;
		return bit[i] + sum(i - (i&-i));
	}

	void add(ll i, ll x) {
		if (i > M) return;
		bit[i] += x;
		add(i + (i&-i), x);
	}
};

bool comps(pair<ll, ll> x, pair<ll, ll> y) {
	return x.second < y.second;
}


	
int main() {

	ll N;
	cin >> N;

	pair<ll, ll> ten[MAX];

	repn(i, N) cin >> ten[i].first >> ten[i].second;

	sort(ten + 1, ten + N + 1);

	repn(i, N) ten[i].first = i;

	sort(ten + 1, ten + N + 1, comps);

	repn(i, N) ten[i].second = i;

	ll seq[MAX];
	ll ivseq[MAX];

	repn(i, N) {
		seq[ten[i].first] = ten[i].second;
		ivseq[ten[i].second] = ten[i].first;
	}


	BIT bit(N);
	ll ld[MAX];

	repn(i, N) {
		ll j = ivseq[i];
		bit.add(j, 1);
		ld[j]=bit.sum(j - 1);
	}

	ll c[MAX];
	c[0] = 0;

	repn(i, N) {
		c[i] = (2 * c[i - 1] + 1) % MOD;
	}

	
	
	ll ans = 0;

	repn(i, N) {
		ll lu = i - 1 - ld[i];
		ll rd = seq[i] - 1 - ld[i];
		ll ru = N - 1 - ld[i] - lu - rd;

		ans += c[N];
		ans -= c[rd + ld[i]] + c[ru + lu] + c[rd + ru] + c[ld[i] + lu];
		ans += c[rd] + c[ld[i]] + c[ru] + c[lu];

		ans %= MOD;

		if (ans < 0) { ans += MOD; }
	}

	cout << ans;




	
	
	

	
	system("PAUSE");
}

Measured memory_bytes: 32504
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int dp[10005]; // dp[i] モンスターに合計iのダメージを与えるのに必要な魔力の最小値

int main () {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  rep(i,n) cin >> a[i] >> b[i];

  rep(i,10005) dp[i] = INF;
  dp[0] = 0;
  rep(i,h)rep(j,n) {
    int ni = i+a[j];
    if (ni > h) ni = h;
    chmin(dp[ni], dp[i]+b[j]);
  }

  cout << dp[h] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>

auto main () -> int {
  int n , k;
  std::cin >> n >> k;

  int a [26] = {};

  for (auto i = 0; i < n; ++ i) {
    std::string instr;
    std::cin >> instr;
    ++ a [instr [0] - 'A'];
  }

  auto res = 0;
  [&] () {
    while (true) {
      std::sort (a , a + 26 , std::greater<int>{});
      for (auto i = 0; i < k; ++ i) {
        if (a [i]) {
          -- a [i];
        }
        else {
          return;
        }
      }
      ++ res;
    }
  } ();

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

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

const int INF = 1001001001;

vector<ll> score;
Graph g;

void dfs(int v, int parent) { // vが根
    for (auto u: g[v]) {
        if (u == parent) continue;
        score[u] += score[v];
        dfs(u, v);
    }
}


int main() {
    ll n, q; cin >> n >> q;
    score.assign(n, 0);
    g.assign(n, {});

    rep(i, n-1) {
        int a, b; cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    rep(i, q) {
        int p;
        ll x;
        cin >> p >> x;
        --p;
        score[p] += x;
    }
    dfs(0, -1);
    for (auto s: score) cout << s  << " ";
    cout << endl;
}

Measured memory_bytes: 24320
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    long long N, T, A;
    cin >> N;
    T = A = 1;
    for (int i = 0; i < N; i++) {
        long long x, y;
        cin >> x >> y;
        long long n = max((T + x - 1) / x, (A + y - 1) / y);
        T = n*x;
        A = n*y;
    }

    cout << T + A << endl;

    return 0;
}

Measured memory_bytes: 256
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

index_a = -1
index_b = 0
num_books = 0
now_times = 0

for a in A :
  if now_times + a <= K :
    num_books += 1
    now_times += a
    index_a += 1
  else :
    break

temp_books = num_books
temp_times = now_times
  
while index_a > -2 :
  while index_b < len(B) and temp_times + B[index_b] <= K :
    temp_books += 1
    temp_times += B[index_b]
    index_b += 1
    if temp_books > num_books :
      num_books = temp_books
  temp_books -= 1
  temp_times -= A[index_a]
  index_a -= 1
      
print(num_books)

Measured memory_bytes: 40444
#include <cstdio>
#include <algorithm>

using namespace std;

int h, m;

void solve(){
    // ツ陳キツ針
    double l = m * 6;
    
    // ツ短ツ針
    double s = h * 30 + m / 2.0;
    
    if(l < s){
        swap(l, s);
    }
    
    // ツ角ツ度ツづーツ仰づ淞づゥ
    double diff = min(l - s, s - l + 360);
    
    if(diff < 30){
        printf("alert\n");
    }
    
    else if(diff < 90){
        printf("warning\n");
    }
    
    else {
        printf("safe\n");
    }
}

int main(){
    int n;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; ++i){
        scanf("%d:%d", &h, &m);
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main(void)
{
  char s[101];
  char ss[201];
  char p[101];

  scanf("%s",s);
  scanf("%s",p);

  strcpy(ss,s);
  strcat(ss,s);

  if(strstr(ss,p)!=NULL)
    puts("Yes");
  else
    puts("No");

  return 0;
}


Measured memory_bytes: 2116
#include<stdio.h>
int main()
{
  int n,x,i,j,k,count;
  while(scanf("%d %d",&n,&x)){
    count=0;
    if(n==0 && x==0)break;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
	for(k=j+1;k<=n;k++){
	  if(i+j+k==x)count++;
	}
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define For(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>  
#define vf vector<float>
#define pi (int,int)
#define vpi vector<pair<int,int>>
#define vs vector<string>
#define mp make_pair
#define ll long long
#define vc vector<char>
#define rng(x) x.begin(),x.end()
#define b(x) x.begin()
#define e(x) x.end()
#define F first
#define S second
#define me max_element
#define ne min_element
const int N=(1e5+2);
using namespace std;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  ll x; cin>>x;
  if(x<30) cout<<"No";
  else cout<<"Yes";
  return 0;
}


        

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 64556465;

int main()
{
ll n ;
cin >> n ;
auto keta = [](ll y){
  ll sum=0;
  ll aa=1000000;
  rep(i,6){
    aa/=10;
    ll b=y/aa;
    sum+=b;
    y-=aa*b;
  }return sum;
  };
rep(i,n-1){
  ll a=i+1;
  ll b=n-a;
  ans=min(ans,keta(a)+keta(b));
}

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


Measured memory_bytes: 256
// AtCoder ABC128: D - equeue
// 2019.9.8 bal4u

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

#define gc() getchar()
int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX 100
typedef struct { int a; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i) {
	int l, r, mi;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].a < que[i].a) mi = l; else mi = i;
	if (r < qsize && que[r].a < que[mi].a) mi = r;
	if (mi != i) {
		QUE qt = que[i]; que[i] = que[mi]; que[mi] = qt;
		min_heapify(mi);
	}
}

void deq() {
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int a) {
	int i, mi;

	i = qsize++;
	que[i].a = a;
	while (i > 0 && que[i].a < que[mi = PARENT(i)].a) {
		QUE qt = que[i]; que[i] = que[mi]; que[mi] = qt;
		i = mi;
	}
}

int N, K;
int V[55];
int q[55], sz;
inline static void chmax(int *r, int a) { if (*r < a) *r = a; }

int main()
{
	int i, j, k, s, ans;
	
	N = in(), K = in();
	for (i = 1; i <= N; i++) V[i] = in();
	ans = 0;
	for (j = N; j >= 0; j--) {
		qsize = 0, k = 0;
		s = 0; for (i = N; i > j; i--) s += V[i], enq(V[i]), k++;
		if (k > K) break;
		chmax(&ans, s);
		if (k == K) continue;
		
		for (i = 1; i <= j; i++) {
			s += V[i], enq(V[i]), k++;
			chmax(&ans, s);
			
			if (k == K) break;
			int ss = s, kk = k, ii;
			sz = 0; while (qsize && que[0].a < 0) {
				q[sz++] = que[0].a, deq();
				if (++kk == K) break;
			}

			kk = k, ii = 0; while (ii < sz && kk < K) {
				ss -= q[ii], enq(q[ii++]), kk++;
				chmax(&ans, ss);
			}
			while (ii < sz) enq(q[ii++]);
		}
	}
	printf("%d\n", ans);		
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	string s;  cin >> s;
	int ans = INF;
	for(int i = 0 ; i < s.length() - 2 ; i++){
	  int keep = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i + 2]-'0');
	  if(abs(753 - keep) < ans)  ans = abs(753 - keep);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
for ($i = 0; $i < 25; $i++) {
    for ($j = 0; $j < 15; $j++) {
        $sum = $i*4 + $j*7;
        if ($sum == $n) {
            echo "Yes";
            return;
        }
        if ($sum > $n) {
            break;
        }
    }
}

echo "No";

Measured memory_bytes: 4856
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    s = input()
    print(s[0:3])

main()


Measured memory_bytes: 9336
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>

enum class Ball {
	Black, White, None
};
struct Coordinate {
	int x, y, z;
	Coordinate operator+(const Coordinate that) const {
		return Coordinate{ x + that.x, y + that.y, z + that.z };
	}
	Coordinate& operator+=(const Coordinate that) {
		return (*this) = *this + that;
	}
	Coordinate operator-(const Coordinate that) const {
		return Coordinate{ x - that.x, y - that.y, z - that.z };
	}
	Coordinate& operator-=(const Coordinate that) {
		return (*this) = *this - that;
	}
};
constexpr std::array<Coordinate, 13> directions{
	Coordinate{1, 0, 0},
	Coordinate{0, 1, 0},
	Coordinate{0, 0, 1},
	Coordinate{1, 1, 0},
	Coordinate{1, 0, 1},
	Coordinate{0, 1, 1},
	Coordinate{1, -1, 0},
	Coordinate{1, 0, -1},
	Coordinate{0, 1, -1},
	Coordinate{1, 1, 1},
	Coordinate{-1, 1, 1},
	Coordinate{1, -1, 1},
	Coordinate{1, 1, -1}
};
class Pegs {
	std::vector<std::vector<std::vector<Ball>>> pegs;
	int size;
public:
	Pegs(int size) : size{ size }, pegs(size, std::vector<std::vector<Ball>>(size)) {};
	Coordinate put(int x, int y, Ball ball) {
		pegs[x][y].push_back(ball);
		return Coordinate{ x, y, (int)pegs[x][y].size() - 1 };
	}
	Ball getOrNone(int x, int y, int z) const {
		if (std::min({ x, y, z }) < 0 || size <= std::max({ x, y, z })) return Ball::None;
		if (pegs[x][y].size() <= z) return Ball::None;
		return pegs[x][y][z];
	}
	Ball getOrNone(const Coordinate that) const {
		return getOrNone(that.x, that.y, that.z);
	}
};
int max_seq(const Pegs& pegs, const Coordinate center) {
	int max_len = 0;
	for (const auto dir : directions) {
		auto position = center + dir;
		int len = 1;
		while (pegs.getOrNone(center) == pegs.getOrNone(position)) {
			position += dir;
			++len;
		}
		position = center - dir;
		while (pegs.getOrNone(center) == pegs.getOrNone(position)) {
			position -= dir;
			++len;
		}
		max_len = std::max(max_len, len);
	}
	return max_len;
}
int main()
{
	std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
	while (true) {
		int n, m, p; std::cin >> n >> m >> p; if (n == 0) break;
		Pegs pegs(n);
		bool ended = false;
		for (auto i = 0; i < p; ++i) {
			int x, y; std::cin >> x >> y; --x, --y;
			if (!ended && max_seq(pegs, pegs.put(x, y, ((i & 1) == 0) ? Ball::Black : Ball::White)) >= m) {
				std::cout << (((i & 1) == 0) ? "Black " : "White ") << i + 1 << '\n';
				ended = true;
			}
		}
		if (!ended) std::cout << "Draw\n";
	}
}



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

int main(){
	int a,b,c,d,e;
  	cin >> a >> b >> c >> d;
  	e = min(b,d)-max(a,c);
  	if (e<0) cout << 0 << endl;
  	else cout << e << endl;
}

Measured memory_bytes: 256
import math

line = input()
money = int(line)
happy = 0

calc_500 = math.floor(money / 500)

if calc_500 >= 1:
  happy += calc_500 * 1000
  money -= calc_500 * 500
  calc_5 = math.floor(money / 5)
  
  if calc_5 >= 1:
      happy += calc_5 * 5
      print(str(happy))
  else:
      print(str(happy))
else:
    calc_5 = math.floor(money / 5)
    if calc_5 >= 1:
      happy += calc_5 * 5
      print(str(happy))
    else:
      print(str(happy))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int a = kbd.nextInt();
        int b = kbd.nextInt();
        int pt = 0;
        for (int i = 0; i < 2; i++) {
            if (a >= b) {
                pt = pt + a;
                a--;
            } else if (a < b) {
                pt = pt + b;
                b--;
            }
        }

        System.out.println(pt);
    }
}

Measured memory_bytes: 22612
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 300005;
const LL inf = 1ll<<50;
#define rev(_) reverse(_+1,_+n+1)

LL dpL[maxn],dpR[maxn],dpM1[maxn],dpM2[maxn];
int n,t[maxn],m;LL s[maxn],tmp[maxn],f[maxn];
bool check(int u,int v,int w) {
	return (f[v]-f[u])*(w-u)<=(v-u)*(f[w]-f[u]);
}
LL calc(LL x) {return x*(x+1)/2ll;}
LL calc(LL *dp,int u,int v) {
	return dp[u]-s[v]+s[u]+calc(v-u);
}
bool check2(LL *dp,int u,int v,int w) {
	return calc(dp,u,w)<=calc(dp,v,w);
}
void calcS(LL *dp) {
	for (int i=1;i<=n;i++) s[i]=s[i-1]+t[i];
	for (int i=1;i<=n;i++) f[i]=dp[i]*2+2*s[i]+(LL)i*i;
}

int stk[maxn],top;
void solve(LL *dp) {
	stk[top=1]=0;f[0]=0;
	for (int i=1;i<=n;i++) s[i]=s[i-1]+t[i];
	for (int i=1;i<=n;i++)
	{
		while (top>1&&check2(dp,stk[top],stk[top-1],i)) --top;
		dp[i]=max(dp[i-1],calc(dp,stk[top],i));f[i]=dp[i]*2+2*s[i]+(LL)i*i;
		while (top>1&&check(stk[top-1],stk[top],i)) --top;
		stk[++top]=i;
	}
}
void solve2(LL *dpM,LL *dpL,LL *dpR,int l,int r,int _)
{
	if (l>=r) return ;
	int mid=l+r-_>>1;top=0;
	for (int i=l;i<=mid;i++)
	{
		while (top>1&&check(stk[top-1],stk[top],i)) --top;
		stk[++top]=i;
	}
	for (int i=mid+1;i<=r;i++)
	{
		while (top>1&&check2(dpL,stk[top],stk[top-1],i)) --top;
		tmp[i]=dpR[i+1]+calc(dpL,stk[top],i);
	}
	for (int i=r-1;i>mid;i--) tmp[i]=max(tmp[i+1],tmp[i]);
	for (int i=mid+1;i<=r;i++) dpM[i]=max(dpM[i],tmp[i]);
	solve2(dpM,dpL,dpR,l,mid,_);
	solve2(dpM,dpL,dpR,mid+1,r,_);
}
int main()
{
	#ifdef Amberframe
		freopen("arc066d.in","r",stdin);
		freopen("arc066d.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&t[i]);
	solve(dpL);rev(t);solve(dpR);rev(dpR);rev(t);
	
	for (int i=1;i<=n;i++) dpM1[i]=dpM2[i]=-inf;
	calcS(dpL);solve2(dpM1,dpL,dpR,0,n,0);
	rev(t);rev(dpL);rev(dpR);
	calcS(dpR);solve2(dpM2,dpR,dpL,0,n,1);
	rev(t);rev(dpL);rev(dpR);rev(dpM2);
	for (int i=1;i<=n;i++) dpM1[i]=max(dpM1[i],dpM2[i]);
	
	scanf("%d",&m);
	for (int p,x,i=1;i<=m;i++)
	{
		scanf("%d %d",&p,&x);
		LL ans=dpL[p-1]+dpR[p+1];
		ans=max(ans,dpM1[p]-x+t[p]);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 20224
#include<stdio.h>
int main(void) {
	int i,a;
	char s[5];
	a = 0;
	scanf("%s", s);
	for (i = 0; i < 4; i++) {
		if (s[i] == '+')a++;
		else if (s[i] == '-')a--;
	}
	printf("%d\n", a);
	return 0;
}

Measured memory_bytes: 128
N = int(raw_input())

inner_ab_count = 0
f_b_count = 0
l_a_count = 0
b_a_count = 0

for n in xrange(N):
    s = raw_input()
    inner_ab_count += s.count('AB')
    if s[0] == 'B':
        if s[-1] == 'A': b_a_count += 1
        else: f_b_count += 1
    elif s[-1] == 'A': l_a_count += 1

if b_a_count <= 0: result = inner_ab_count + min([l_a_count, f_b_count])
elif l_a_count + f_b_count == 0: result = inner_ab_count + b_a_count-1
else: result = inner_ab_count + b_a_count + min([l_a_count,f_b_count])
print result

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

int main() 
{
int a;
  cin >> a;
int n[a-1];
int sum[a] = {0};
int t;
  rep(i,a-1) {
    cin >> t;
    ++sum[t-1];
  }
  rep(i,a-1) cout << sum[i] << endl;
    cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 4372
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] w = new int[n];
	int[] wdif = new int[n-1];
	int s1 = 0;
	int s2 = 0;
	for(int i = 0; i < w.length; i++){
		w[i] = sc.nextInt();	
	}
	for(int t = 0; t < wdif.length; t++){
		for(int i = 0; i < w.length; i++){
			if(i<=t){
				s1 += w[i];
			}else{
				s2 += w[i];
			}
		}
		wdif[t] = Math.abs(s1 - s2);
		s1 = 0;
		s2 = 0;
	}
	System.out.println(minAr(wdif));
}

static int minAr(int[] a){
	int min=0;
	for(int i = 0; i < a.length; i++){
		if(i==0){
			min = a[i];
		}else{
			min = Math.min(min,a[i]);
		}
	}
	return min;
}
}


Measured memory_bytes: 23764
N = int(input())
A_Nonsort = list(map(int, input().split()))
A = sorted(A_Nonsort)
count = 1
tmp = 0
result = 0
first_flag = True

def check_count(count):
    while count > 3:
        q, mod = divmod(count, 3)
        count = q + mod
    if (count == 2):
        return True
    return False

for a in A:
    if (not first_flag):
        if (a != tmp):
            if (check_count(count)):
                result += 1
            count = 1
    first_flag = False
    if (a == tmp):
        count += 1
    tmp = a
else:
    if (check_count(count)):
        result += 1

print(len(list(set(A))) - result % 2)

Measured memory_bytes: 15332
def main():
    s = input()
    for i, c1 in enumerate(s):
        if c1 == 'C':
            for c2 in s[i+1:]:
                if c2 == 'F':
                    print('Yes')
                    return
            else:
                print('No')
                return
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import sys
import functools

for line in sys.stdin:
    nums = list(map(lambda x: int(x), line.split()))
    menseki = functools.reduce(lambda x, y: x * y, nums)
    syuu = functools.reduce(lambda x, y: x + y, nums) * 2
    print(str(menseki) + " " + str(syuu))



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

int main()
{
  int n;
  cin >> n;
  int l[n];
  for(int i=0; i<n;++i){
    cin >> l[i];
  }
  int c = 0;
  for(int i=0; i<n;++i){
    for(int j=i+1; j<n;++j){
      for(int k=j+1; k<n;++k){
        int e[3] = {l[i], l[j], l[k]};
        sort(e, e+3);
        if((e[0] < e[1]) && (e[1] < e[2]) && ((e[0] + e[1]) > e[2])) c++;
      }
    }
  }
  cout << c << endl;
}


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

using namespace std;
const int INF=1e9+5;
const int d=1e9+7;
typedef long long ll;
int main(){
	int H,W;
	cin>>H>>W;
	vector<vector<char>> v(H,vector<char>(W));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>v[i][j];}}
	vector<vector<ll>> dp(H,vector<ll>(W));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(v[i][j]=='#')
				dp[i][j]=0;
			else if(i==0 && j==0)
				dp[i][j]=1;
			else if(i==0){
				dp[i][j]=dp[i][j-1];}
			else if(j==0 )
				dp[i][j]=dp[i-1][j];
			else {
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
				dp[i][j]=dp[i][j]%d;}
			}}
		dp[H-1][W-1] = dp[H-1][W-1] %d;
		cout<<dp[H-1][W-1] <<endl;
}

Measured memory_bytes: 9088
#include<stdio.h>
int f[61];
void fibonacci(int n) 
{
  int i;
  f[0]=f[1]=1;
  for(i=2; i<=n; i++){
    f[i] = f[i-2] + f[i-1];
  }
}
 
int main() 
{
  int n;
  scanf("%d",&n);
  fibonacci(n);
  printf("%d\n",f[n]);
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

template<typename T>
class SegTree {
public:
  int n;
  T e;
  T (*op)(const T&, const T&);
  vector<T> data;
  SegTree(int m, T _e, T (*_op)(const T&, const T&)) : e(_e), op(_op){
    n=1;
    while(n<m) n*=2;
    data.resize(2*n, e);
  }
  SegTree(const vector<T> &v, T _e, T (*_op)(const T&, const T&)) : e(_e), op(_op){
    n=1;
    while(n<(int)v.size()) n*=2;
    data.resize(2*n, e);
    rep(i,v.size()) data[i+n] = v[i];
    for(int i=n-1; i>0; i--) data[i] = op(data[i*2], data[i*2+1]);
  }
  T query(int l, int r) const {
    T vl = e, vr = e;
    for(l+=n, r+=n; l<r; l/=2, r/=2){
      if(l&1) vl = op(vl, data[l++]);
      if(r&1) vr = op(data[--r], vr);
    }
    return op(vl,vr);
  }
  void update(int k, T a){
    k+=n;
    data[k]=a;
    while(k>0){
      k = k/2;
      data[k] = op(data[k*2], data[k*2+1]);
    }
  }
  inline T operator[](int idx) const { return data[idx+n]; }
};

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

  vector<long> rv(l+1,0);
  {
    long acc = 0;
    for(int i = l-1; i >= 0; i--){
      acc += a[i];
      long cur = (a[i]==0) ? 2 : (a[i]%2);
      rv[i] = min(acc, rv[i+1]+cur);
    }
  }
  dbg(rv);
  
  vector<long> odds(l);
  rep(i,l) odds[i] = (a[i]==0) ? 1 : (1-a[i]%2);
  SegTree<long> ov(odds, 0, [](auto &l, auto &r){return l+r;});

  dbg(odds);

  vector<long> vals(l+1);
  rep(i,l+1){
    vals[i] = ov.query(0,i) + rv[i];
  }
  dbg(vals);

  SegTree<long> st(vals, 123456789123456789LL, [](auto &l, auto &r){return min(l,r);});

  long ans = st.query(0,l+1);
  long acc = 0, pre = 0;
  rep(i,l){
    acc += a[i];
    pre = min(acc, pre + ((a[i]==0) ? 2 : (a[i]%2)));
    ans = min(ans, pre + st.query(i+1, l+1) - ov.query(0,i+1));
    dbg(i,pre, st.query(i+1, l+1), ov.query(0,i+1));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 14720
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, A, B;
int main(int argc, char **argv) {
    cin >> N >> A >> B;

    cout << min(A * N, B) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int b1 = scan.nextInt();
		int b2 = scan.nextInt();
		int b3 = scan.nextInt();
		if(b1 == 1 && b2 == 0 && b3 == 0 || b1 == 0 && b2 == 1 && b3 == 0 || b1 == 0 && b2 == 0 && b3 == 0){
			System.out.println("Close");
		} else {
			if(b1 == 1 && b2 == 1 && b3 == 0 || b1 == 0 && b2 == 0 && b3 == 1){
				System.out.println("Open");
			}
		}
	}
}

Measured memory_bytes: 17360
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

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

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


int n, q;
string s;
int ac[101010];

int main(){
	cin >> n >> q;
	cin >> s;
	for(int i = 0; i < n-1; i++){
		if(s[i] == 'A' && s[i+1] == 'C'){
			ac[i]++;
			i++;
		}
	}
	for(int i = 1; i < n; i++){
		ac[i] += ac[i-1];
	}
	for(int i = 0; i < q; i++){
		int l, r;
		cin >> l >> r;
		cout << ac[r-2] - ac[l-2] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1408
import itertools
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

#2次元配列
grid = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
sum_fee = []
a_min = min(a)
b_min = min(b)
sum_fee.append(a_min+b_min)

for l, m, n in grid:
    sum_fee.append(a[l-1] + b[m-1] - n)
    

print(min(sum_fee))

Measured memory_bytes: 88428
using System;
using System.Linq;

namespace Volume0 {
	class Program {
		public static void Main() {
			bool next = ReadAndShowLeapYears(false);
			while (next) {
				next = ReadAndShowLeapYears(true);
			}
		}

		static bool IsLeapYear(int year) {
			if (year % 400 == 0) return true;
			else if (year % 100 == 0) return false;
			else if (year % 4 == 0) return true;
			else return false;
		}

		static void ShowLeapYears(int start, int end) {
			int[] leaps = Enumerable.Range(start, end - start + 1)
				.Where(IsLeapYear)
				.ToArray();
			if (leaps.Count() == 0) Console.WriteLine("NA");
			else {
				foreach (int y in leaps) Console.WriteLine(y);
			}
		}

		static bool ReadAndShowLeapYears(bool br) {
			int[] input = Console.ReadLine().Split()
				.Select(int.Parse)
				.ToArray();
			if (input[0] == 0 && input[1] == 0) return false;
			else {
				if (br) Console.WriteLine();
				ShowLeapYears(input[0], input[1]);
				return true;
			}
		}
	}
}



Measured memory_bytes: 9664
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int N,L;
char d[22];
int p[22];

void solve() {
    rep(i,N) cin>>d[i]>>p[i];
    rep(i,N) {
        if(d[i]=='R') d[i]=1;
        else d[i]=-1;
    }
    int t=0;
    int ans;

    while(1) {
        rep(i,N) {
            p[i]+=d[i];
        }
        rep(i,N) rep(j,N) {
            if(j<=i) continue;
            if(p[i]==p[j]) {
                d[i]*=-1;
                d[j]*=-1;
            }
        }
        rep(i,N) if(p[i]==L) ans=i;
        rep(i,N) if(p[i]==0) ans=i;

        bool f=true;
        rep(i,N) f&=(p[i]>L || p[i]<0);
        if(f) break;

        t++;
    }
    cout<<t<<" "<<ans+1<<endl;
}

int main() {
    while(cin>>N>>L) {
        if(N+L==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1164
a=[]
b=[]
c=[]
c[0]=gets.chomp.split(" ").map{|s| s.to_i}
c[1]=gets.chomp.split(" ").map{|s| s.to_i}
c[2]=gets.chomp.split(" ").map{|s| s.to_i}
a[0]=0
for j in 0..2
  b[j]=c[0][j]
end

for i in 0..2
  a[i]=c[i][0]-b[0]
end

f=true
for i in 0..2
  for j in 0..2
    f=false unless c[i][j]==a[i]+b[j]
  end
end

if f
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;


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

  string S12, S34;

  S12 = S1234.substr(0,2);
  S34 = S1234.substr(2);

  int num12 = atoi(S12.c_str());
  int num34 = atoi(S34.c_str());

  if( (num12 == 0 || num12 >= 13) && (num34 >= 1 && num34 <= 12) ) cout << "YYMM";
  else if( (num12 >= 1 && num12 <= 12) && (num34 == 0 || num34 >= 13) ) cout << "MMYY";
  else if( (num12 >= 1 && num12 <= 12) && (num34 >= 1 && num34 <= 12) ) cout << "AMBIGUOUS";
  else cout << "NA";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int         // 10^18
#define INF 1000000001           // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    
    string s;cin>>s;
    if(s.size() < 4){
        P("No");
        return 0;
    }
    if(s.substr(0,4)=="YAKI"){
        P("Yes");
        return 0;
    }
    P("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int X, A;
  cin>>X>>A;

  if(X < A) cout<<0<<endl;
  else cout<<10<<endl;

  return 0;
}


Measured memory_bytes: 256