akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=605;
const int MOD=1e9+7;
int add (int x,int y)   {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y)   {return (LL)x*y%MOD;}
int dec (int x,int y)   {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
	if (y==1) return x;
	int lalal=Pow(x,y>>1);
	lalal=mul(lalal,lalal);
	if (y&1) lalal=mul(lalal,x);
	return lalal;
}
int n,k;
int pos[N];
int g[N];
int sum[N];
int ans=0;
int f[N][N];
void solve (int l,int r)
{
	if (f[l][r]!=-1) return ;
	f[l][r]=0;
	if ((sum[r]-sum[l-1])&1) return ;
	for (int u=l;u<=r;u++)
		if (pos[u]!=0&&(pos[u]<l||pos[u]>r)) return ;
	int now=g[sum[r]-sum[l-1]];
	for (int u=l;u<r;u++)
	{
		solve(l,u);
		now=dec(now,mul(f[l][u],g[sum[r]-sum[u]]));
	}
	f[l][r]=now;
	ans=add(ans,mul(now,g[n-2*k-(sum[r]-sum[l-1])]));
}
int main()
{
	memset(f,-1,sizeof(f));
	scanf("%d%d",&n,&k);n<<=1;
	for (int u=1;u<=k;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		pos[x]=y;pos[y]=x;
	}
	g[0]=1;for (int u=2;u<=n;u+=2) g[u]=mul(u-1,g[u-2]);
	for (int u=1;u<=n;u++) sum[u]=sum[u-1]+(pos[u]==0);
	for (int u=1;u<=n;u++)
	for (int i=u;i<=n;i++)
	solve(u,i);
	printf("%d\n",ans);
	return 0;
}

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 2e5+5; 

ll n,k; 
ll arr[N];
vector<ll> v;

int main(){
	fast;
	cin >> n >> k;
	rep(i,1,n) cin >> arr[i];

	v.pb(1);
	set<ll> s;
	s.insert(1);
	ll curr = 1;
	ll cnt = 0;
	
	ll tmpK = k;
	
	while(s.find(arr[curr]) == s.end()){
        v.pb(arr[curr]);
        s.insert(arr[curr]);
        curr = arr[curr];
        cnt++;
	}
	v.pb(arr[curr]);
	cnt++;
	
	if(k <= cnt){
	    cout << v[k] << endl;
	}
	else{
	    ll ele = arr[curr];
	    ll f_ind = -1,s_ind = -1;
	    
	    rep(i,0,v.size()-1){
	        if(v[i] == ele){
	            if(f_ind == -1){
	                f_ind = i;
	            }
	            else{
	                s_ind = i;
	            }
	        }
	    }
	    
	    ll cycle = s_ind - f_ind;
	    k -= f_ind;
	    ll ind_ = f_ind + (k % cycle);
	    cout << v[ind_] << endl;
	}
}

Measured memory_bytes: 15400
#include <stdio.h>
 int main()
{
 char number[1001];
 int i, sum;
 while(1)
{
 scanf("%s", number);
 if(number[0]=='0')break;
 sum=0;
 for(i=0;
number[i]!='\0';
i++)
{
 sum+=number[i]-'0';
 }
 printf("%d\n", sum);
 }
 return 0;
 } 


Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<=20&&b<=20&&c<=20){
		for(int i=1;i>=1;i++){
			if(c>=1&&b<a){
				b++;
				c--;
			}
			else{
				break;
			}
		}
	}
	cout<<c<<endl;
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        for (int i = 0; i < 5; i++) {
            a[i] = sc.nextInt();
        }
        
        for(int i = 0; i < 5; i++) {
            if (a[i] == 0)
                System.out.println(i + 1);
        }
    }
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<pair<int, int>> ps;
    for(int i=0, j=n-1; i <= j;)
    {
        while(i<n && s.at(i) != 'L') i++;
        while(j>=0 && s.at(j) != 'L') j--;
        if(i > j) break;
        ps.push_back(make_pair(i, j));
        while(i<n && s.at(i) == 'L') i++;
        while(j>=0 && s.at(j) == 'L') j--;
        if(i > j) break;
        ps.push_back(make_pair(i, j));
    }
    // for(int i=0; i<ps.size(); i++) cout << ps.at(i).first << ", " << ps.at(i).second << endl;

    for(int i=0; i<k; i++)
    {
        if(ps.empty()) break;
        pair<int, int> p = ps.back();
        ps.pop_back();
        if(s.at(p.first) == 'L')
        {
            s.erase(p.first, p.second-p.first+1);
            s.insert(p.first, string(p.second-p.first+1, 'R'));
        }
        else if(s.at(p.first) == 'R')
        {
            s.erase(p.first, p.second-p.first+1);
            s.insert(p.first, string(p.second-p.first+1, 'L'));
        }
    }
    // cout << s << endl;

    int ans = 0;
    char c = s.front();
    for(int i=1; i<n; i++)
    {
        if(s.at(i) == c) ans++;
        else c = s.at(i);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 972
(defmacro put-ans (n v)
  `(princ (coerce (make-array ,n :initial-element ,v) 'string)))

(let* ((a (read))
       (b (read))
       (a-char (char (write-to-string a) 0))
       (b-char (char (write-to-string b) 0)))
  (if (> a b)
      (put-ans a b-char)
      (put-ans b a-char)))


Measured memory_bytes: 17508
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

bool b = 0;

void solve(int A[], int i, int M){
    if(b == 0){
        if(M - A[i] == 0)
            b = 1;
        else if(A[i] == '\0')
            b = 0;
        else{
            if(M-A[i] > 0)
                solve(A,i+1,M-A[i]);
            solve(A,i+1,M);
        }
    }
}

int main(){
    int n;
    scanf("%d",&n);
    int A[n+1];
    for(int i=0; i<n; i++)
        scanf("%d",&A[i]);
    A[n] = '\0';

    int q;
    scanf("%d",&q);
    int Q[q];
    for(int i=0; i<q; i++){
        scanf("%d",&Q[i]);
        solve(A,0,Q[i]);
        if(b == 1){
            printf("yes\n");
            b = 0;
        }else
            printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);
    	int a=sc.nextInt();
    	int b=sc.nextInt();
    	int c=sc.nextInt();
    	int d=sc.nextInt();
    	
    	int l=a+b;
    	int r=c+d;
    	
    	
    	if(r>l) {
    		System.out.println("Right");
    	}else if(l>r) {
    		System.out.println("Left");
    	}else {
    		System.out.println("Balanced");
    	}
    	
    }

}







Measured memory_bytes: 21588
#include<iostream>
#include<string>
using namespace std;
int main(){

  string O,E;
  cin>>O>>E;
  for(size_t i=0;i<=O.length()+E.length()-1;i++){
  
    if(i%2==0){
    
      cout<<O[i/2];
    }
    else{
    
      cout<<E[i/2];
    }
  }
  return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read().ToInt();
            var ans = 0;
            var r2 = ReadSplit();
            var next = 1;
            for (int i = 0; i < n; i++)
            {
                var a = r2[i].ToInt();
                if (a == next)
                {
                    next++;
                }
                else
                {
                    ans++;
                }
            }
            if (ans == r2.Length)
            {
                WriteRead("-1");
                return;
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 30172
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
p,q=0,0
for i in range(n):
    a=A[i]
    b=B[i]
    if a>b:
        q+=a-b
    else:
        if (b-a)%2==0:
            p+=(b-a)//2
        else:
            p+=(b-a)//2+1
            q+=1
if q<=p:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;

int main(){
	string N,S;cin >> N >> S;
	if(N[0] == S[2] && S[0] == N[2] && N[1] == S[1]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String input = in.nextLine();
        int size = input.codePointCount(0, input.length());

        boolean started = false;
        int count = 0;
        int result = 0;
        for(int i = 0; i < size; i++) {
            int c = input.codePointAt(i);


            count += 1;
            switch (c) {
                case 'A':
                    if (!started) {
                        count = 1;
                    }
                    started = true;
                    break;
                case 'Z':
                    result = count;
                    break;
            }
        }
        out.print(result);
    }
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
}


Measured memory_bytes: 15612
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
typedef long long ll;
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

ll n;

int main() {
    cin >> n;

    ll a, b;
    for (ll i = sqrt(n); i >= 1; i--) {
        if (n % i == 0) {
            a = i;
            b = n / i;
            break;
        }
    }
    cout << (a - 1) + (b - 1) << endl;
}


Measured memory_bytes: 256
climate = list(input())

rainy = climate.count('R')
sunny = climate.count('S')

if rainy == 1:
    print(1)
elif rainy == 3:
    print(3)
elif rainy == 2:
    if (climate[0] == 'R' and climate[2] == 'R'):
        print(1)
    else:
        print(2)
else:
    print(0)

Measured memory_bytes: 9108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_9_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var cards = Console.ReadLine();
                if (cards == "-")
                {
                    return;
                }

                var times = 0;
                {
                    var input = Console.ReadLine();
                    times = int.Parse(input);
                }

                for (var i = 0; i < times; ++i)
                {
                    var input = Console.ReadLine();
                    var splitIndex = int.Parse(input);

                    var next = "";
                    for (var h = 0; h < cards.Length; ++h)
                    {
                        var index = (splitIndex + h) % cards.Length;
                        next += cards[index];
                    }
                    cards = next;
                    //cards = cards.Substring(splitIndex) + cards.Substring(0, splitIndex);
                }

                Console.WriteLine(cards);
            }
        }
    }
}

Measured memory_bytes: 5664
n, m, k = [int(v) for v in input().split()]
alist = [int(v) for v in input().split()]
blist = [int(v) for v in input().split()]

consumed = 0
max_count = 0

i = 0
while i < len(alist) and consumed + alist[i] <= k:
    consumed += alist[i]
    i += 1

j = 0
while j < len(blist) and consumed + blist[j] <= k:
    consumed += blist[j]
    j += 1

count = i + j
max_count = count

i -= 1

while i >= 0:
    consumed -= alist[i]
    count -= 1
    while j < len(blist) and consumed + blist[j] <= k:
        consumed += blist[j]
        j += 1
        count += 1
        if count > max_count:
            max_count = count
    i -= 1

print(max_count)


Measured memory_bytes: 111716
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

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

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

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

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

void solve() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int ans = A[0];
	for (int i = 1; i < N; ++i) {
		ans = gcd(ans, A[i]);
	}
	cout << ans << endl;
}

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

	solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

    string s;
    cin >> s;

    int n=s.size();
    int ans=true;
    rep(i,n) {
        if(i%2==0) {
            if(s[i]=='h'&&s[i+1]=='i') ;
            else {
                ans=false;
            }
        }
    }

    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

 return 0;
}

Measured memory_bytes: 256
b = []
3.times{ b << gets.split.map(&:to_i) }
gets
h = []
while n = gets
  h << n.chomp.to_i
end
3.times{|i|
  3.times{|j|
    b[i][j] = 0 if h.include?(b[i][j])
  }
}
ans = "No"
b.each{|r|
  ans = "Yes" if r.inject(:+) == 0
}
3.times{|i|
  ans = "Yes" if b[0][i] + b[1][i] + b[2][i] == 0
}
ans = "Yes" if b[0][0] + b[1][1] + b[2][2] == 0
ans = "Yes" if b[0][2] + b[1][1] + b[2][0] == 0
puts ans

Measured memory_bytes: 1788
#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
string t,u; ll n, m,k,q, ans, sum = 0, r,s,p;
int main() {
    cin >> n >> k >> r >> s >> p >> t;
    rep(i, n) {
        if (i >= k) {
            if (t[i] != t[i - k]) {
                if (t[i] == 'r') sum += p;
                else if (t[i] == 's') sum += r;
                else sum += s;
            }
            else if(i + k < n) {
                if (t[i] == t[i + k]) {
                    if (t[i] == 'r') t[i] = 's';
                    else t[i] = 'r';
                }
            }
        }
        else {
            if (t[i] == 'r') sum += p;
            else if (t[i] == 's') sum += r;
            else sum += s;
        }
    }
    cout << sum << endl;
}

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

int main() {
    int temp;
    char ch;

    while(true) {
        temp = 0;
        while ((ch = getchar()) != '\n') {
            temp += ch - '0';
        }

        if (temp == 0) {
            break;
        } else {
            cout << temp << endl;
        }
    }

    return 0;
}


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

int main()
{
    string Sp, T;
    cin >> Sp >> T;

    if (Sp.size() < T.size())
    {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    string res = "UNRESTORABLE";
    for (int l = 0; l <= Sp.size() - T.size(); l++)
    {
        bool b = true;
        for (int i = 0; i < T.size(); i++)
        {
            if (Sp.at(l + i) != '?' && Sp.at(l + i) != T.at(i))
            {
                b = false;
                break;
            }
        }
        if (b)
        {
            string S = Sp;
            for (int i = 0; i < T.size(); i++)
            {
                S.at(l + i) = T.at(i);
            }
            for (int i = 0; i < S.size(); i++)
            {
                S.at(i) = (S.at(i) == '?') ? 'a' : S.at(i);
            }

            if (res == "UNRESTORABLE")
            {
                res = S;
            }
            else
            {
                res = min(res, S);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
/*
 * atcoder/abc120_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

string S;
int counter[2] = {0};

void solve() {
  cin >> S;
  for (auto&& c: S) {
    counter[c-'0']++;
  }
  cout << min(counter[0], counter[1]) * 2 << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	char c;
	scanf("%c",&c);
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
		printf("vowel\n");
	}
	else{
		printf("consonant\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll N, A, B, ans;

	cin >> N >> A >> B;

	if (A > B) ans = 0;
	else if (N == 1 && (A != B)) ans = 0;
	else if (N == 1) ans = 1;
	else ans = 1 + (B - A) * (N - 2);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[233];
int main()
{
    memset(dp,0x3f,sizeof dp);
    dp[0]=0;
    for (int i=0;i<=100;++i)
        for (int j=1;j<=5;++j)
            dp[i+j]=min(dp[i+j],dp[i]+1);
    int x;scanf("%d",&x);
    int a=x/100,b=x%100;
    if (a>=dp[b]) puts("1");
    else puts("0");
    return 0;
}


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

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

  ll M; cin >> M;
  ll K; cin >> K;

  ll MAX = 1 << M;
  if (K >= MAX) {
    cout << "-1\n";
    return 0;
  }

  if (M == 0) {
    if (K == 0) cout << "0 0\n";
    else cout << "-1\n";
    return 0;
  }

  if (M == 1) {
    if (K == 0) cout << "0 0 1 1\n";
    else cout << "-1\n";
    return 0;
  }

  deque<ll> d;
  d.emplace_back(K);
  for (int i = 0; i < MAX; i++) {
    if (i == K) continue;
    d.emplace_back(i);
    d.emplace_front(i);
  }
  d.emplace_back(K);

  for (int i = 0; i < d.size(); i++) {
    cout << d[i] << " ";
  }
  return 0;
}

Measured memory_bytes: 3968
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n+1);
  Vi B(n);
  VIN(A)
  VIN(B)
  REP(i,n){
      if(A[i] <= B[i]){
          B[i] -= A[i];
          c += A[i];
          A[i] = 0;

          if(A[i+1] <= B[i]){
              B[i] -= A[i+1];
              c += A[i+1];
              A[i+1] = 0;
          } else {
              A[i+1] -=  B[i];
              c += B[i];
              B[i] = 0;
          }
      } else {
          A[i] -= B[i];
          c += B[i];
          B[i] = 0;
      }
  }
  OUT(c);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

template <typename T>
struct SegTree {
    typedef function<T(T, T)> F;
    int n;
    F f;
    T ti;
    vector<T> dat;
    SegTree(){}
    SegTree(F f, T ti): f(f), ti(ti){}

    void init(int n_) {
        n = 1;
        while(n < n_) n <<= 1;
        dat.assign(n<<1, ti);
    }

    void build(const vector<T> &v) {
        int n_ = v.size();
        init(n_);
        for(int i = 0; i < n_; ++i) dat[n+i] = v[i];
        for(int i = n-1; i; --i) dat[i] = f(dat[(i<<1)|0], dat[(i<<1)|1]);
    }

    void set_val(int k, T x) {
        dat[k += n] = x;
        while(k >>= 1) dat[k] = f(dat[(k<<1)|0], dat[(k<<1)|1]);
    }

    T query(int a, int b) {
        if(a >= b) return ti;
        T vl = ti, vr = ti;
        for(int l = a+n, r = b+n; l < r; l >>= 1, r >>= 1) {
            if(l&1) vl = f(vl, dat[l++]);
            if(r&1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }

    template <typename C>
    int find(int st, C &check, T &acc, int k, int l, int r) {
        if(l+1 == r) {
            acc = f(acc, dat[k]);
            return check(acc) ? k-n : -1;
        }
        int m = (l+r)>>1;
        if(m <= st) return find(st, check, acc, (k<<1)|1, m, r);
        if(st <= 1 && !check(f(acc, dat[k]))) {
            acc = f(acc, dat[k]);
            return -1;
        }
        int vl = find(st, check, acc, (k<<1)|0, l, m);
        if(~vl) return vl;
        return find(st, check, acc, (k<<1)|1, m, r);
    }

    template <typename C>
    int find(int st, C &check) {
        T acc = ti;
        return find(st, check, acc, 1, 0, n);
    }
};

int n;

int main() {
    cin >> n;
    vector<ll> hvec(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> hvec.at(i);
        hvec.at(i)--;
    }
    vector<ll> avec(n, 0);
    for(int i = 0; i < n; ++i) cin >> avec.at(i);

    auto f = [](ll a, ll b) { return max(a, b); };
    SegTree<ll> seg(f, 0);
    seg.build(vector<ll>(n, 0));
    for(int i = 0; i < n; ++i) {
        ll pre = seg.query(0, hvec.at(i));
        seg.set_val(hvec.at(i), pre+avec.at(i));
    }
    cout << seg.query(0, n) << endl;
}

Measured memory_bytes: 11904
using System;
using System.Collections.Generic;
 
namespace ALDS1_3
{
    class Program
    {
        public struct Process
        {
            public readonly string n;
            public readonly int t;
            public Process(string n, int t)
            {
                this.n = n;
                this.t = t;
            }
        }
 
        static void Main()
        {
            var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            var b = new Queue<Process>();
               
            for (var i = 0; i < a[0]; i++)
            {
                var c = Console.ReadLine().Split();
                var d = c[0]; var e = int.Parse(c[1]);
                b.Enqueue(new Process(d, e));
            }
 
            var f = 0;
 
            while (b.Count > 0)
            {
               var g = b.Dequeue();
               var k = g.n;
               var v = g.t;
               f += v < a[1] ? v : a[1];
               v -= a[1];
               if (v <= 0)
                   Console.WriteLine("{0} {1}", k, f);
               else
                   b.Enqueue(new Process(k, v));
            }
        }
    }
}

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

int main() {
    int x,y,X,Y,c;
    cin >> x >> y;
    X = x < 0 ? -x : x;
    Y = y < 0 ? -y : y;
    c = (Y - X) * (Y - X < 0 ? -1 : 1);
    if(X < Y) {
        if(x < 0) c++;
        if(y < 0) c++;
    } else if(X == Y) {
        if(x != y) c++;
    } else {
        if(x > 0) c++;
        if(y > 0) c++;
    }
    cout << c << endl;
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  preprocess();
  int n; cin>>n;
  vector<long double> ar(n);
  rep(i,0,n) cin>>ar[i];
  long double ans = 0;
  rep(i,0,n) {
    ans = ans + (1/ar[i]);
  }
  ans = 1/ans;
  cout<<ans<<endl;
}



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

ans = 0
for i in range(N):
    ans += B[A[i]-1]
    if i != N-1 and A[i+1] == A[i]+1:
        ans += C[A[i]-1]

print(ans)

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

int main()
{
	string s; cin >> s;
	char B[26]{0};
	for (int i = 0; i < s.size(); ++i)
		B[s[i]-'a']++;
	for (int i = 0; i < 26; ++i)
		if (!B[i])
		{
			cout << char(97+i) << endl;
			return 0;
		}
	cout << "None" << endl;
}



Measured memory_bytes: 3732
#include "bits/stdc++.h"
using namespace std;


int n;
int m;


vector<int> v[802];


vector<int> g[802];

int ng[802];
int us;

vector<int> lb[2];
bool use[820];
bool zz[820];
inline void dfs(int b, int fl) {
	use[b] = true;
	zz[b] = fl;
	lb[fl].push_back(b);
	for (int go : g[b]) {
		if (use[go] == false) {
			dfs(go, fl ^ true);
		}
		else {
			if (zz[go] == fl) {
				puts("-1");
				exit(0);
			}
		}
	}
}
vector < pair < vector<int>, vector<int> > > V;
vector<int> vv[2];
bool con[1002][1002];
int be[820];

bool dp[1000][1000];
int pr[1000][1000];

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
		con[a][b] = true;
	}
	for (int i = 0; i < n; i++) {
		us++;
		for (int go : v[i]) {
			ng[go] = us;
		}
		for (int j = 0; j < n; j++) {
			if (ng[j] != us) {
				if (i == j)continue;
				g[i].push_back(j);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (use[i] == false) {
			dfs(i,false);
			V.push_back(make_pair(lb[0], lb[1]));
			lb[0].clear();
			lb[1].clear();
		}
	}
	dp[0][0] = true;
	for (int i = 0; i < V.size(); i++) {
		for (int j = 0; j < 810; j++) {
			if (dp[i][j]) {
				dp[i + 1][j + V[i].first.size()] = true;
				dp[i + 1][j + V[i].second.size()] = true;
				pr[i + 1][j + V[i].second.size()] = true;
			}
		}
	}
	int mint = INT_MAX;
	int pos = -1;
	for (int j = 0; j < 810; j++) {
		if (dp[V.size()][j]) {
			int a = j;
			int b = n - j;
			int z = a*(a - 1) / 2 + b*(b - 1) / 2;
			mint = min(mint, z);
		}
	}
	cout << mint << endl;
	return 0;	return 0;
}

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



int main() {
  string S; cin >> S;
  string sok = "hihihihihi";
  bool ans = false;
  if(S.size()%2 == 0 && S == sok.substr(0, S.size())) ans = true;
  



  cout << (ans ? "Yes" : "No") << endl;

	return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 


int main()
{
    long N;
    std::cin >> N;
    std::vector<long> A;
    for(long i=0; i<N-1; i++){
        long temp;
        std::cin >> temp;
        A.push_back(temp);
    }
            long now=0;
    std::sort(A.begin(),A.end());
    for(long i=0; i<N; i++){
        long count=0;
        for(long j=now; j<N; j++){
            if(A[j]!=i+1){
                now=j;
                break;
            }else{
                count++;
            }
        }
        std::cout << count << std::endl;
    }
    return 0;
}

Measured memory_bytes: 5368
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 100005
using namespace std;
typedef long long ll;
ll fac[maxn];
ll sum[maxn];
int st[maxn];

int main()
{
	int top=0;
	ll n;
	cin>>n;
	while(n)
	{
		if(n%26==0)
			st[++top]=26,n/=26,n--;
		else
			st[++top]=n%26,n/=26;
	}
	for(int i=top;i>=1;i--)
		printf("%c",st[i]+'a'-1);
	printf("\n");
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s,s1;
 int m;
 cin>>m;
 for(int j=0;j<m;j++){
  int ans=0,a=1;
  cin>>s>>s1;
  for(int i=0;i<s.size();i++){   
   if(s[i]=='m'){ans+=a*1000; a=1;}
   else if(s[i]=='c'){ans+=a*100; a=1;}
   else if(s[i]=='x'){ans+=a*10; a=1;}
   else if(s[i]=='i'){ans+=a; a=1;}
   else a=(int)(s[i])-48;
  }
  a=1;
  for(int i=0;i<s1.size();i++){
   if(s1[i]=='m'){ans+=a*1000; a=1;}
   else if(s1[i]=='c'){ans+=a*100; a=1;}
   else if(s1[i]=='x'){ans+=a*10; a=1;}
   else if(s1[i]=='i'){ans+=a; a=1;}
   else a=(int)(s1[i])-48;   
  }

  int cnt=0,cnt1=0,cnt2=0;

  while(1){
   if(ans>=1000){
    ans-=1000;
    cnt++;
   }
   else if(ans>=100){
    ans-=100;
    cnt1++;
   }
   else if(ans>=10){
    ans-=10;
    cnt2++;
   }
   else break;
  }
   
  if(cnt!=0){
   if(cnt!=1)cout<<cnt;
   cout<<'m';
  }
  if(cnt1!=0){
   if(cnt1!=1)cout<<cnt1;
   cout<<'c';
  }
  if(cnt2!=0){
   if(cnt2!=1)cout<<cnt2;
   cout<<'x';
  }
  if(ans!=0){
   if(ans!=1)cout<<ans;
   cout<<'i';
  }
  cout<<endl;  
 }  
 return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,x,cnt=0;
    cin >> n >> x;
    vector<int> chld(n);
    for(int i=0;i<n;i++)
        cin >> chld.at(i);
    sort(chld.begin(),chld.end());
    for(int i=0;i<n;i++){
        x -= chld.at(i);
        if(x>=0)
            cnt++;
        else
            break;
    }
    if(x>0)
        cnt--;
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, m, dmax[1005];
    vector<P3> es;
    cin >> n >> m;
    fill(dmax,dmax+n,-LLINF/3);
    REP(i,m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        es.push_back({c,{a,b}});
    }
    dmax[0] = 0;
    REP(i,n){
        for(auto &e : es){
            ll from = e.second.first, to = e.second.second, cost = e.first;
            if(dmax[to] < dmax[from] + cost){
                dmax[to] = dmax[from] + cost;
            }
        }
    }
    ll memo = dmax[n-1];
    REP(i,n){
        for(auto &e : es){
            ll from = e.second.first, to = e.second.second, cost = e.first;
            if(dmax[to] < dmax[from] + cost){
                dmax[to] = dmax[from] + cost;
            }
        }
    }
    if(memo < dmax[n-1]){
        cout << "inf" << endl;
    }
    else{
        cout << dmax[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define pb       push_back
#define mp       make_pair
#define mod      1000000007
#define first    ff
#define second   ss
#define pi       acos(-1.0)
#define test     int t;cin>>t;while(t--)
typedef long long ll;
using namespace std;
vector<int>node[10001];

int main()
{


     ios::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);

        int n,m;
        cin>>n>>m;
        string s;
        int ans=0;
        for(int i=n;i<=m;i++)
        {
            s=to_string(i);
            int flag=1;
            int k=s.size();
            for(int i=0;i<k/2;i++)
            {
                if(s[i]!=s[k-i-1])
                    flag=0;
            }
            if(flag)
                ans++;

        }
        cout<<ans<<endl;



      return 0;

 }

Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n, k, q;

  cin >> n >> k >> q;

  vector<int> num(n, 0);

  int a;

  for (int i = 0; i < q; i++){
    cin >> a;
    num[--a]++;
  }


  for (int i = 0; i < n; i++){
    if (q - num[i] < k)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }


  return 0;
}


Measured memory_bytes: 1024
// :pray: :steph:
// :pray: :bakekaga:

#include <iostream>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>

#define ll long long
#define eps 1e-8
#define MOD 1000000007

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

// change if necessary
#define MAXN 1000000

using namespace std;

int n, w;
ll dp[100001];

vector<array<int, 2>> vals;

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

    cin >> n >> w;
    vals = vector<array<int, 2>>(n);

    for (int i = 0; i < n; i++) {
        cin >> vals[i][0] >> vals[i][1];
    }

    for (int i = 0; i < n; i++) {
        for (int j = w; j >= vals[i][0]; j--) {
            dp[j] = max(dp[j], dp[j - vals[i][0]] + vals[i][1]);
        }
    }

    for (int i = 1; i <= w; i++) {
        dp[i] = max(dp[i], dp[i - 1]);
    }

    cout << dp[w] << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int h, w, i, j, flag;

    scanf("%d %d", &h, &w);
    while((h!=0) && (w!=0)) {
        for(i=0;i<h;i++) {
            if (i % 2 == 1)
                flag = 1;
            else if (i % 2 == 0)
                flag = 0;
            for(j=0;j<w;j++) {
                if(flag == 0) {
                    printf("#");
                    flag = 1;
                } else if(flag==1) {
                    printf(".");
                    flag = 0;
                }
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &h, &w);
    }   
    return 0;
}

Measured memory_bytes: 2684
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]


INF = float("inf")
MOD = 10**9 + 7


def main():
    K = input()
    if K[-1] not in "1379":
        print(-1)
        return
    K = int(K)

    count = 0
    ans = 7
    for k in range(10**6):
        ans = ans % K
        count += 1
        if ans == 0:
            print(count)
            return
        else:
            ans = ans*10+7
    print(-1)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9224
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<vector<i64>> g;
vector<pair<i64, i64>> res;
vector<bool> vis, fix;
vector<i64> cnt;
void dfs(i64 u, i64 p) {
  vis[u] = true;
  for (i64 v : g[u]) {
    if (v == p) continue;
    if (vis[v] && !fix[v]) {
      res.emplace_back(u, v);
      cnt[u]++;
    } else if (!vis[v]) {
      dfs(v, u);
    }
  }
  fix[u] = true;
  if (p <= 0) return;
  if (cnt[u] % 2 == 0) {
    res.emplace_back(p, u);
    cnt[p]++;
  } else {
    res.emplace_back(u, p);
    cnt[u]++;
  }
}

int main() {
  cin >> n >> m;
  init_n(g, n + 1);
  for (i64 i = 0; i < m; ++i) {
    i64 a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (m % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }

  init_n(vis, n + 1);
  init_n(fix, n + 1);
  init_n(cnt, n + 1);
  dfs(1, 0);

  for (i64 u = 1; u <= n; ++u) {
    cerr << u << '\t' << cnt[u] << endl;
    // assert(cnt[u] % 2 == 0);
  }

  for (auto e : res) {
    cout << e.first << ' ' << e.second << '\n';
  }
  return 0;
}


Measured memory_bytes: 15600
use proconio::*;

fn calc(mut a: Vec<(u32, i32)>, item: (u32, i32)) -> Vec<(u32, i32)> {
    let mut b = a.iter().map(|a| (a.0 + item.0, a.1 + item.1)).collect::<Vec<_>>();
    let mut c = Vec::with_capacity(a.len() * 2);
    while !(a.is_empty() || b.is_empty()) {
        if a.last().unwrap().1 >= b.last().unwrap().1 {
            c.push(a.pop().unwrap());
        } else {
            c.push(b.pop().unwrap());
        }
    }
    for p in a.into_iter().chain(b.into_iter()).rev() {
        c.push(p);
    }
    c.reverse();
    for i in 1..c.len() {
        c[i].0 = std::cmp::max(c[i].0, c[i - 1].0);
    }
    c
}

#[fastout]
fn run() {
    input! {
        n: usize,
        mut item: [(u32, i32); n],
        q: usize,
        ask: [(usize, i32); q],
    }
    item.insert(0, (0, 0));
    let mut memo = vec![vec![]; n + 1];
    memo[1] = vec![(0, 0), item[1]];
    let batch = 11;
    for i in 2..=std::cmp::min(n, 1 << batch) {
        memo[i] = calc(memo[i / 2].clone(), item[i]);
    }
    for (start, width) in ask {
        let ans = if start < (1 << batch) {
            memo[start].iter().filter(|p| p.1 <= width).max().unwrap().0
        } else {
            let mut dp = vec![(0, 0)];
            let mut pos = start;
            while pos >= (1 << batch) {
                dp = calc(dp, item[pos]);
                pos /= 2;
            }
            let memo = &memo[pos];
            let mut i = 0;
            let mut j = memo.len();
            let mut ans = 0;
            while i < dp.len() && j > 0 {
                if dp[i].1 + memo[j - 1].1 <= width {
                    ans = std::cmp::max(ans, dp[i].0 + memo[j - 1].0);
                    i += 1;
                } else {
                    j -= 1;
                }
            }
            ans
        };
        println!("{}", ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 38124
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int n,m;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%d",&n,&m);

	if(n==m) puts("Yes");
	else puts("No");

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

ll a[MAX_N];
int n,Q;

ll cnt(ll x)
{
	int l=0,r=0;
	ll res=0;
	ll win=0;
	while(r<=n+1){
		if(win<=x){
			win += a[r];
			r++;
		}else{
			res += r-l-1;
			win -= a[l];
			l++;
		}
	}
	return res;
}

int main()
{
	scanf("%d%d",&n,&Q);
	rep(i,n){
		scanf("%lld",&a[i]);
	}
	a[n] = (1LL<<60);
	rep(i,Q){
		ll x;
		scanf("%lld",&x);
		printf("%lld\n",cnt(x));
	}
	return 0;
}

Measured memory_bytes: 3984
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(s: chars);

    if s.iter().all(|&c| c == s[0]) {
        println!("{}", s.len());
        return;
    }

    let n = s.len();
    let mut ok = (n + 1) / 2;
    let mut ng = n;
    while ng - ok > 1 {
        let k = (ng + ok) / 2;
        assert!(k < n);
        assert!(n - k < k);
        if s[(n - k)..k].iter().all(|&c| c == s[n - k]) {
            ok = k;
        } else {
            ng = k;
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 4352
X, K, D = map(int, input().split())

if abs(X) // D > K:
    print(abs(X) - K * D)
    exit()

mod = abs(X) % D
if (K - (abs(X) // D)) % 2 == 0:
    print(mod)
else:
    print(abs(mod - D))


Measured memory_bytes: 61876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ln '\n';
int lim=1e6;
int inf=1e9+7;
vector<vector<long double> > dp;

long double solve(int i,int j,long double* p,int n)
{
    if(i==n)
    {
        if(j==0)
            return 1;
        else
            return 0;
        
    }
    
    if(dp[i][j]!=-1)
        return dp[i][j];

    long double ans1=(1-p[i])*solve(i+1,j,p,n);

    //long double ans2=0;
    
    if(j>0)
        ans1= ans1 + (p[i])*(solve(i+1,j-1,p,n));
        
    dp[i][j]=ans1;
    return dp[i][j];
}

int main()
{    
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    long double p[n];

    for(int i=0;i<n;i++)
        cin>>p[i];
    
    dp.resize(n,vector<long double>(n+1,-1));
    long double ans=0;

    for(int j=(n/2+1);j<=n;j++)
        ans+=solve(0,j,p,n);
    
    cout<<setprecision(10)<<ans<<ln;
}


Measured memory_bytes: 141312
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define SUM(vec) accumulate(ALL((vec)), 0)

// func declaration
template <class T> void printVec(vector<T>);
template <class T> void calcVec(vector<T>&, int, char);
bool checkMultiple(vector<int>&, int);
int ctoi(const char);

// const
const int INF = 10000000;

/*MEMO
辞書順
abc < abcd, atcoder < atlas
*/

int main() {
    int N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;

    
    return 0;
}


// function
template <class T> void printVec(vector<T> vec) {
    // 1要素ずつ、空白・改行なしで出力
    REP(i, vec.size()) {
        cout << vec.at(i);
    }
    cout << endl;
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    if (ch == '+') {
        REP(i, vec.size()) {
            vec.at(i) += num;
        }
    } else if (ch == '-') {
        REP(i, vec.size()) {
            vec.at(i) -= num;
        }
    } else if (ch == '*') {
        REP(i, vec.size()) {
            vec.at(i) *= num;
        }
    } else if (ch == '/'){
        REP(i, vec.size()) {
            vec.at(i) /= num;
        }
    } else if (ch == '%') {
        REP(i, vec.size()) {
            vec.at(i) %= num;
        }
    }
}

bool checkMultiple(vector<int> &vec, int num) {
    // vecの中身が、全てnumの倍数かどうかのチェック
    int count = 0;
    REP(i, vec.size()) {
        if (vec.at(i)%num != 0) count++;
    }
    return (count == 0);
}

int ctoi(const char c) {
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}


Measured memory_bytes: 256