akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<int> A,B,C;
int main(){
int n, a,b;
  cin >>n>> a >> b;
  for(int i=0;i<n;i++)
  {
    int pi;
    cin >> pi;
    if(pi<=a)A.push_back(pi);
    else if(b<pi)C.push_back(pi);
    else B.push_back(pi);
  }
  cout << min(A.size(),min(B.size(),C.size()))<<endl;
}

Measured memory_bytes: 256
a = list(input())
ans = 0
for i in range(len(a)):
    count = 0
    for j in range(i, len(a)):
        if a[j] in ('A','C','G','T'):
            count += 1
        else:
            break
    if ans == 0 or ans <= count:
        ans = count
print(ans)

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

int main(void){
    long long n,a,b,ans=0,t1,t2;
    cin >> n >> a >> b;
    t1=n/(a+b);
    t2=n%(a+b);
    ans=t1*a;
    if(t2<a) ans+=t2;
    else ans+=a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

    ll i,j,n;
    cin>>n;
    ll ans = (n*(n+1))/2;
    for(i=2;i<=n;i++)
    {
        j = 1;
        while(i*j<=n) ans+=(i*j),j++;
    }
    cout<<ans;
}

Measured memory_bytes: 3616
//verma_ankit484

#include<bits/stdc++.h>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const ll mod = (ll) 1e9+7;

using namespace std;

int main()
{
  IOS
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  ll n;
  cin >> n;
  n--;
  n = n*(n+1)/2;
  cout << n << endl;
  return 0;
}


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

int main() {
  string N;
  cin >> N;
  
  if(N == "SUN"){cout << 7 << endl;}
  else if(N == "MON"){cout << 6 << endl;}
  else if(N == "TUE"){cout << 5 << endl;}
  else if(N == "WED"){cout << 4 << endl;}
  else if(N == "THU"){cout << 3 << endl;}
  else if(N == "FRI"){cout << 2 << endl;}
  else if(N == "SAT"){cout << 1 << endl;}
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int t = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(sc.next());
		}
		int hAns = n-1;
		double ans =Math.abs(a - h[n-1]);
		for (int i = 0; i <n ;i++) {
			double temp =Math.abs( a - (t - (h[i]*0.006)));
			if (ans > temp) {
				ans =temp;
				hAns = i;
			}
		}
		System.out.println(hAns + 1);
	}
}

Measured memory_bytes: 22996
#include<stdio.h>
main(){
  int a=0;
  int W,H,x,y,r=0;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x-r>=0&&x+r<=W){
    if(y-r>=0&&y+r<=H){
      a=1;
    }
  }
  else{
    a=0;
  }
  if(a==1){
    printf("Yes\n");
  }
  else if(a==0){
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 584
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int p = scanner.nextInt();
			if (p == 0) {
				scanner.close();
				break;
			}
			int q = scanner.nextInt();

			int[] pr = new int[p];
			int[] pc = new int[p];
			int[] ps = new int[p];
			int[] indent = new int[p];

			String[] pStrings = new String[p];
			for (int i = 0; i < p; i++) {
				pStrings[i] = scanner.next();
				if (i != 0) {
					pr[i] += pr[i - 1];
					pc[i] += pc[i - 1];
					ps[i] += ps[i - 1];
				}
				pr[i] += pStrings[i].length() - pStrings[i].replaceAll("\\(", "").length();
				pr[i] -= pStrings[i].length() - pStrings[i].replaceAll("\\)", "").length();
				pc[i] += pStrings[i].length() - pStrings[i].replaceAll("\\{", "").length();
				pc[i] -= pStrings[i].length() - pStrings[i].replaceAll("\\}", "").length();
				ps[i] += pStrings[i].length() - pStrings[i].replaceAll("\\[", "").length();
				ps[i] -= pStrings[i].length() - pStrings[i].replaceAll("\\]", "").length();
				indent[i] = pStrings[i].length() - pStrings[i].replaceAll("^\\.*", "").length();
			}

			/*
			 * indent[i]=R*(ro[i-1]-rc[i-1])+C*()+S*
			 */
			ArrayList<Integer[]> RCSs = new ArrayList<Integer[]>();
			for (int R = 1; R <= 20; R++) {
				for (int C = 1; C <= 20; C++) {
					for (int S = 1; S <= 20; S++) {
						boolean check = true;
						for (int i = 1; i < indent.length; i++) {
							int tmp = R * (pr[i - 1]) + C * (pc[i - 1]) + S * (ps[i - 1]);
							if (tmp != indent[i]) {
								check = false;
							}
						}
						if (check) {
							Integer[] add = { R, C, S };
							RCSs.add(add);
						}
					}
				}
			}

			int qr = 0, qs = 0, qc = 0;
			for (int i = 0; i < q; i++) {
				String qStrings = scanner.next();
				int ans = -1;
				for (Integer[] RCS : RCSs) {
					int master = RCS[0] * qr + RCS[1] * qc + RCS[2] * qs;
					if (ans != -1 && ans != master) {
						ans = -1;
						break;
					} else {
						ans = master;
					}
				}
				System.out.print(ans);
				if (i < q - 1) {
					System.out.print(" ");
				}
				qr += qStrings.length() - qStrings.replaceAll("\\(", "").length();
				qr -= qStrings.length() - qStrings.replaceAll("\\)", "").length();
				qc += qStrings.length() - qStrings.replaceAll("\\{", "").length();
				qc -= qStrings.length() - qStrings.replaceAll("\\}", "").length();
				qs += qStrings.length() - qStrings.replaceAll("\\[", "").length();
				qs -= qStrings.length() - qStrings.replaceAll("\\]", "").length();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 37532
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

ll popcount(const string& X) {
    ll res = 0;
    for (char c : X)if (c == '1')res++;
    return res;
}

ll popcount(ll X) {
    ll res = 0;
    while (X > 0) {
        res += X & 1;
        X >>= 1;
    }
    return res;
}

ll mpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)(res *= a) %= mod;
        (a *= a) %= mod;
        n >>= 1;
    }
    return res;
}

ll mmod(const string& s, const ll mod) {
    ll res = 0;
    for (char c : s) {
        (res <<= 1) %= mod;
        (res += c - '0') %= mod;
    }
    return res;
}

vector<int> create_f_table() {
    const int SIZE = 2e5 + 10;
    vector<int> f(SIZE);
    f[0] = 0;
    REP(i, 1, SIZE) {
        int next = i % popcount(i);
        f[i] = f[next] + 1;
    }
    return f;
}

void case_for_X_i_0(
    const vector<int>& f,
    const string& X,
    vector<int>& res
) {
    const ll N = X.size();
    const ll popx = popcount(X) + 1;
    const ll baseFX = mmod(X, popx);
    rep(i, N) if (X[i] == '0') {
        const ll diff = mpow(2, N - 1 - i, popx);
        const ll trueFX = (baseFX + diff) % popx;
        res[i] = f[trueFX] + 1;
    }
}

void case_for_X_i_1(
    const vector<int>& f,
    const string& X,
    vector<int>& res
) {
    const ll N = X.size();
    const ll popx = popcount(X) - 1;
    const ll baseFX = mmod(X, popx);
    rep(i, N)if (X[i] == '1') {
        const ll diff = mpow(2, N - 1 - i, popx);
        const ll trueFX = (((baseFX - diff) % popx) + popx) % popx;
        res[i] = f[trueFX] + 1;
    }
}

bool special_cases(
    const vector<int>& f,
    const string& X
) {
    int popx = popcount(X);
    if (2 <= popx)return false;

    const int N = X.size();
    if (popx == 0) {
        rep(i, N)cout << 1 << endl;
    }
    else if (popx == 1) {
        vector<int> res(N, 0);
        case_for_X_i_0(f, X, res);
        for (auto num : res)cout << num << endl;
    }
    else {
        assert(false);
    }
    return true;
}

int main()
{
    ll N;
    string X;
    cin >> N >> X;
    auto f = create_f_table();

    if (special_cases(f, X)) {
        return 0;
    }

    vector<int> res(N);
    case_for_X_i_0(f, X, res);
    case_for_X_i_1(f, X, res);
    for (auto num : res)cout << num << endl;
    return 0;
}


Measured memory_bytes: 5160
n = int(input())
a = list(map(int,input().split(" ")))

o = [0] * n
c = n//2
r = c
l = c - 1
for i in range(n):
    if i % 2:
        o[l] = a[i]
        l -= 1
    else:
        o[r] = a[i]
        r += 1

if n % 2:
    for i in range(n):
        if i:
            print(' ',end='')
        print(o[n-1-i],end='')
else:
    for i in range(n):
        if i:
            print(' ',end='')
        print(o[i],end='')

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

namespace ABC088_B
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(a => a).ToList();
            int scoreAlice = input.Where((v, i) => i % 2 == 0).Sum();
            int scoreBob = input.Where((v, i) => i % 2 != 0).Sum();
            Console.WriteLine(scoreAlice - scoreBob);
        }
    }
}


Measured memory_bytes: 13396
#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>;
int main() {
  int N, K; cin >> N >> K;
  vector<int> P(N,0);
  rep(i,N) cin >> P[i];
  sort(P.begin(),P.end());
  int ans = 0;
  rep(i,K) ans += P[i];
  cout << ans << endl;


	return 0;
}



Measured memory_bytes: 3620
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,v,w,x,y,t;
	ll		ans = 0;
	string	s;
	cin >> a >> v;
	cin >> b >> w;
	cin >> t;
	
	if (v <= w) {
		cout << "NO" << endl;
		return 0;
	}
	c = abs(a-b);
	x = abs(v-w);
	if (x*t >= c) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3616
<?php
$n=trim(fgets(STDIN));
$p=explode(" ",trim(fgets(STDIN)));
$ans=0;
for($i=1;$i<$n-1;$i++){
if(($p[$i-1]>$p[$i]&&$p[$i]>$p[$i+1])||($p[$i-1]<$p[$i]&&$p[$i]<$p[$i+1])){
++$ans;
}
}
echo $ans;

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

signed main(){
  string s, t; cin >> s >> t;
  bool ok = true;
  for(int i = 0; i < s.size(); i++) if(s[i] != t[i]) ok = false;
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3640
def main():
    n = int(input())
    A = list(map(int,input().split()))
    ans = 0
    for i in range(n):
        if (i+1)%2 == 1 and A[i]%2 == 1:
            ans += 1
    print(ans)
    return
if __name__ == "__main__":
    main()

Measured memory_bytes: 61700
/*お店で１０００円札で支払う場合のおつりはいくらか？*/

#include<stdio.h>



int main(void){
    int payment;/*1~10000*/
    int have = 1000;

    scanf("%d",&payment);
    while(have < payment){
        have = have +  1000;
    }
    printf("%d\n",have - payment);

    return 0;

}


Measured memory_bytes: 1728
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = R[0]
R.pop(0)
for i in R:
    if profit < i - mn:
        profit = i - mn
        if 0 > i - mn:
            mn = i
    elif mn > i:
        mn = i

print(profit)

Measured memory_bytes: 15660
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

const int INF = 1001001001;

using namespace std;

vector<int> to[100005];

int main() {
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	queue<int> q;
	vector<int> dist(n, INF);
	vector<int> pre(n, -1);
	dist[0] = 0;
	q.push(0);
	while (!q.empty()) {
		int v = q.front(); q.pop();
		for (int u : to[v]) {
			if (dist[u] != INF)continue;
			dist[u] = dist[v] + 1;
			pre[u] = v;
			q.push(u);
		}
	}

	cout << "Yes" << endl;
	rep(i, n) {
		if (i == 0)continue;
		int ans = pre[i];
		++ans;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 10612
a, b = map(int, input().split())

grid = []
for _ in range(50):
    grid.append(["."] * 100)

for _ in range(50):
    grid.append(["#"] * 100)

i = 51
j = 0
for _ in range(a - 1):
    grid[i][j] = "."
    j += 2
    if j >= 100:
        i += 2
        j = 0

i = 0
j = 0
for _ in range(b - 1):
    grid[i][j] = "#"
    j += 2
    if j >= 100:
        i += 2
        j = 0

print(100, 100)
for row in grid:
    print(*row, sep="")


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
int main(){
    char x[2],y[2];
    cin>>x[0]>>y[0];
    if(x[0]==y[0])cout<<"="<<"\n";
    else if(x[0]<y[0])cout<<"<"<<"\n";
    else cout<<">"<<"\n";
    return 0;
}



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

int main() {
 char b;
   cin>>b;
  if(b=='A'){
    cout<<'T'<<endl;
  }
  else if(b=='G'){
    cout<<'C'<<endl;
  }
    else if(b=='T'){
      cout<<'A'<<endl;
}
      else if(b=='C'){
        cout<<'G'<<endl;
      }
}
      

Measured memory_bytes: 256
// Problem : C - Big Array
// Contest : AtCoder - AtCoder Beginner Contest 061
// URL : https://atcoder.jp/contests/abc061/tasks/abc061_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n,k;cin>>n>>k;
map<int,int> mp;
for(int i=0;i<n;i++)
{
	int a,b;cin>>a>>b;
	mp[a]+=b;
}
int cnt=0;
auto it=mp.begin();
while(cnt<k)
{
	cnt+=it->se;
	it++;
}
it--;
cout<<it->f;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	int ans = max(a + a -1, max(a + b, b + b - 1));
	printf("%d\n",ans);
	return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
                                        
                                  class pas{
                                    	public:
                                    	int x,y;
                                    	pas(int x=0,int y=0):x(x),y(y) {}
                                    	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                    	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                    	pas operator * (int a) {return pas(x*a,y*a);}
                                    	pas operator / (int a) {return pas(x/a,y/a);}
                                    //	double absv() {return sqrt(norm());}
                                    	int norm() {return x*x+y*y;}
                                    	bool operator < (const pas &p) const{
                                    		return x != p.x ? x<p.x: y<p.y;
                                    	}
                                    	bool operator == (const pas &p) const{
                                    		return x==p.x && y==p.y;
                                    	}
                                    };
int n,V,W,K,N,L,R;
vector<int>ve;

//int dp[2][10001]={0};
int a[1010] ;
int s;
           signed main(){
      cin>>n;
           	cout<<n*32<<endl;
          
           }
             

Measured memory_bytes: 3080
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
    string s;
    cin >> s;
    string S;
    for(int i = 0; i < s.size(); i = i + 2 ){
       S += s[i];
    }
cout << S << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int Ans[10001];
int main() {
    int n;
    scanf("%i", &n);
    for (int x = 1; x * x <= n; x++) {
        for (int y = 1; y * y <= n; y++) {
            for (int z = 1; z * z <= n; z++) {
                int ans = x * x + y * y + z * z + x * y + y * z + z * x;
                if (ans <= n) Ans[ans]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        printf("%i\n", Ans[i]);
    }
}


Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1<<17;

ll mod;
class BIT2{
public:
  int n;
  ll bit0[MAX_N+1],bit1[MAX_N+1];//1????????????

  BIT2(){n = MAX_N;memset(bit0,0,sizeof(bit0));memset(bit1,0,sizeof(bit1));}
  BIT2(int n){this->n=n;memset(bit0,0,sizeof(bit0));memset(bit1,0,sizeof(bit1));}
  
  ll sum(ll *b,int i){
    ll s=0;
    while(i>0){
      s=(s+b[i])%mod;
      i-=i&-i;
    }
    return s;
  }

  void add(ll *b,int i,ll v){
    while(i<=n){
      b[i]=(b[i]+v)%mod;
      i+=i&-i;
    }
  }

  //[a,b]???x?????????(1<=a)
  void add (int a,int b,ll x){
    add(bit0,a,-x*(a-1));
    add(bit1,a,x);
    add(bit0,b+1,x*b);
    add(bit1,b+1,-x);
  }

  //[a,b]???sum?????????(1<=a)
  ll sum(int a,int b){
    ll res=0;
    res+=sum(bit0,b)+sum(bit1,b)*b;
    res-=sum(bit0,a-1)+sum(bit1,a-1)*(a-1);
    return (res+mod)%mod;    
  }
};

string i2S(ll num){
  string res;
  if(num==0)return "0";
  while(num) res=(char)(num%10+'0')+res,num/=10;
  return res;
}

int main(){
  while(1){
    ll A,B;
    cin>>A>>B>>mod;
    if(!A&&!B&&!mod)return 0;
    vector<string> num;
    for(ll i=A;i<=B;i++)num.push_back(i2S(i));
    sort(num.begin(),num.end());
  
    ll ans = 0, n = B-A+2;
    BIT2 T(n);
    T.add(1,n,1);
    
    for(ll i=A;i<=B;i++){
      int idx = lower_bound(num.begin(),num.end(),i2S(i))-num.begin()+1;
      ll val = T.sum(idx,idx);
      ans=(ans+val)%mod;
      T.add(idx,n,val);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 10484
def eq(s, t)
  n = s.size
  n.times do |i|
    return false if s[i] != '?' && t[i] != '?' && s[i] != t[i]
  end
  true
end

s = gets.chomp
t = gets.chomp

(s.size - t.size+1).times.to_a.reverse.each do |i|
  if eq(t, s[i...i+t.size])
    ans = s.chars
    (i...i+t.size).each do |idx|
      ans[idx] = t[idx-i]
    end
    ans.each_with_index do |c, i|
      if c == '?'
        ans[i] = 'a'
      end
    end
    puts ans.join('')
    exit
  end
end

puts :UNRESTORABLE


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

// 0119 B-0563 18:00 ~ 19:00

int main() {
	int n, m;
	while(cin >> n >> m) {
		if(n == 0 && m == 0) break;

		vector<ll> v(n);
		rep(i, n) cin >> v[i];

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

		vector<ll> p;
		rep(i, n) p.push_back(v[i]);

		rep(i, n) {
			REP(j, i, n) {
				p.push_back(v[i] + v[j]);
			}
		}

		sort(p.begin(), p.end());
		ll ans = 0;
		rep(i, p.size()) {
			int id = upper_bound(p.begin(), p.end(), m - p[i]) - p.begin();
			if(id == 0) {
				if(p[i] <= m) ans = max(ans, p[i]);
			}
			else ans = max(ans, p[i] + p[id-1]);
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 9196
n,m,c = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
ans = 0
for i in range(n):
    count = c
    l = list(map(int,input().split(" ")))
    for j in range(m):
        count += ar[j] * l[j]
    if count > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


ll N, A, B;
vector<ll> h;

bool solve(ll n ){
    ll cnt = 0;
    rep(i,h.size()){
        if(h[i]/B <= n-1) continue;
        cnt += ((h[i]- n*B)/ (A-B));
        if((h[i]-n*B)%(A-B) != 0) cnt ++;
    }
    if(cnt > n) return false;
    else return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> A >> B;
    rep(i,N){
        ll inp; cin >> inp;
        h.pb(inp);
    }
    
    ll l = 0;
    ll r = 1e14;
    
    while(l+1 < r){
        ll m = (l+r)/2;
        if(solve(m)) r = m;
        else l = m;
    }
    
    cout << r << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}
 
void add_mod(ll& a, ll b){
    b += MOD;
    a += b;
    a %= MOD;
}

int n;
string s[334];

bool check(int b){
	int i,j;
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(s[i][(j+b)%n] != s[j][(i+b)%n]){
				return false;
			}
		}
	}
	return true;
}

int main(void){
	int i,j,ans=0;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> s[i];
	}
	for(i=0; i<n; ++i){
		if(check(i)){
			ans += n;
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int maxn = 1;
const double EPS = 1e-8;

int le[27];
class AColorfulSubsequence {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n;
		string s;
		in >> n >> s;
		for(int i = 0; i < 27; ++i)le[i] = 1;
		for(int x: s)le[x-'a']++;
		ll res = 1;
		for(int i = 0; i < 27; ++i)res = (res * 1LL * le[i]) % MOD;
		out << res - 1;
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	AColorfulSubsequence solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 512
from decimal import Decimal, getcontext

getcontext().prec = 1000
a,b,c = map(int,input().split())

sq_a = Decimal(a).sqrt()
sq_b = Decimal(b).sqrt()
sq_c = Decimal(c).sqrt()

eps = Decimal(10) ** (-100)

cond = sq_a + sq_b + eps < sq_c
answer = 'Yes' if cond else 'No'
print(answer)

Measured memory_bytes: 5076
# AGC009A - Multiple Array
import sys
input = sys.stdin.readline


def main():
    # decide from the last one
    n = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(n))
    ans = 0
    for i, j in A[::-1]:
        if i == 0 or j == 1:
            continue
        r = (i + ans) % j
        if r != 0:
            ans += j - (i + ans) % j
    print(ans)


if __name__ == "__main__":
    main()

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

void print( const vector<pair<string, int>>& a ) {
	size_t n = a.size();

	for( size_t i = 0; i < n; ++i ) {
		cout << a.at( i ).first;

		if( i < n-1 ) { cout << ' '; }
	}

	cout << endl;
}

void bubbleSort( vector<pair<string, int>>& A, int N ) {
	for( int i = 0; i < N; ++i ) {
		for( int j = N-1; j > i; --j ) {
			if( A.at( j ).first.at( 1 ) < A.at( j-1 ).first.at( 1 ) ) {
				swap( A.at( j ), A.at( j-1 ) );
			}
		}
	}
}

int selectionSort( vector<pair<string, int>>& A, int N ) {
	int count = 0;

	for( int i = 0; i < N; ++i ) {
		int minj = i;

		for( int j = i; j < N; ++j ) {
			if( A.at( j ).first.at( 1 ) < A.at( minj ).first.at( 1 ) ) {
				minj = j;
			}
		}

		if( i != minj ) {
			swap( A.at( i ), A.at( minj ) );
			count += 1;
		}
	}

	return count;
}

bool isStable( const vector<pair<string, int>>& A, int N ) {
	for( int i = 1; i < N; ++i ) {
		const auto& x = A.at( i );
		const auto& y = A.at( i-1 );

		if( x.first.at( 1 ) == y.first.at( 1 ) && x.second < y.second ) {
			return false;
		}
	}

	return true;
}

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

	vector<pair<string, int>> a( N );
	for( int i = 0; i < N; ++i ) {
		cin >> a.at( i ).first;
		a.at( i ).second = i;
	}

	vector<pair<string, int>> b( a );
	bubbleSort( b, N );
	print( b );
	cout << (isStable( b, N ) ? "Stable" : "Not stable") << endl;

	b = a;
	selectionSort( b, N );
	print( b );
	cout << (isStable( b, N ) ? "Stable" : "Not stable") << endl;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    ll s,c; cin >> s >> c;

    if(2*s >= c) {
        cout << min(s, c/2) << endl;
        return 0;
    }
    else {
        cout << s + (c-2*s)/4 << endl;
        return 0;
    }
}



Measured memory_bytes: 256
#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 main(int argc, char **argv) {
    llong X, Y;
    cin >> X >> Y;

    llong cur = Y / X;
    llong res = 0;
    while(cur != 0) {
        cur /= 2;
        res++;
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#define p 1000000007

int c[200002], ni[200002];
int H, W, A, B;

inline long long ksm(long long a, int k)
{
    long long ans = 1;
    while(k)
    {
        if(k & 1)
            ans = ans * a % p;
        a = a * a % p;
        k >>= 1;
    }
    return ans;
}

inline void init()
{
    c[0] = 1;
    ni[0] = 1;
    int maxn = H+W-2;
	for(register int i = 1; i <= maxn; i += 1)
	    c[i] = (long long)c[i-1] * i % p;
	ni[maxn] = ksm(c[maxn], p-2);
	for(register int i = maxn; i; i -= 1)
		ni[i-1] = (long long)ni[i] * i % p;
}

inline long long C(int m, int n)
{
    return (long long)c[m] * ni[n] % p * ni[m-n] % p;
}

int main()
{
    scanf("%d%d%d%d", &H, &W, &A, &B);
    init();
    int AW = A+W-1, HA = H-A-2, AO = A-1, HO = H-A-1;
    long long ans = C(H+W-2, W-1);
    long long rem = 0;
    for(register int i = 1; i <= B; i += 1)
    {
        rem += C(AW-i, AO) * C(HA+i, HO) % p;
        if(rem >= p)
            rem -= p;
    }
    ans = (ans - rem + p) % p;
    printf("%lld", ans);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int a[22], b[22], p[22];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
		p[i] = i;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	for(int i = 1; i <= n; i ++)
		cin >> b[i];
	int A = 0, B = 0, c= 0;
	do
	{
		c++;
		int foo = 0, hoo = 0;
		for(int i = 1; i <= n; i ++)
		{
			if(p[i] != a[i])
				foo = 1;
			if(p[i] != b[i])
				hoo = 1;
		}
		if(foo == 0)
			A = c;
		if(hoo == 0)
			B = c;
		
	}while(next_permutation(p + 1, p + n + 1));
	cout << abs(A - B);




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		int count = 0;
		count = B / A;
		
		if(C < count) {
			System.out.println(C);
		}else {
			System.out.println(count);
		}
	}

}


Measured memory_bytes: 22736
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long X, Y;
long long cnt;

int main()
{
	scanf("%lld %lld", &X, &Y);

	while(X <= Y)
	{
		X *= 2;
		cnt++;
	}

	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int tmp;
  if(A>C){
    tmp = A;
	A = C;
	C = tmp;
	tmp = B;
	B = D;
	D = tmp;
  }
  if(B<=D){
    if(B-C>=0){
	  cout << B-C << endl;
	}else{
	  cout << 0 << endl;
	}
  }else{
    if(D-C>=0){
	  cout << D-C << endl;
	}else{
	  cout << 0 << endl;
	}
  }
  return 0;
}




Measured memory_bytes: 256
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	_ = readInt()
	K := readInt() - 1
	S := readBytes()

	S[K] = S[K] - 'A' + 'a'
	println(string(S))
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a,b,tmp;
int main()
{
	scanf("%d%d",&a,&b);
	if(a>b) tmp=b,b=a,a=tmp;
	for(int i=1;i<=b;++i) printf("%d",a);
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int k, x; cin>>k>>x;
    if (k * 500 >= x) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3572
N = int(input())
a = [int(ai) for ai in input().split()]
from collections import Counter
c = Counter(a)
best = 0
for x in c.keys():
    count = c[x] + c.get(x-1, 0) + c.get(x+1, 0)
    best = max(count, best)
print(best)

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

int main(){
  char buf[1030];
  int n,bi,ki;
  int kcount=0,kcode=0;
  char kdata[10][10]={{0,5,3,3,3,3,3,4,3,4},".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
  cin >> n;

  for (int i=0;i<n;i++){
    cin >> buf;
    bi=-1;
    kcode=0;
    kcount=0;
    while (buf[++bi]!='\0'){
      if (buf[bi]=='0'&&kcode>0){
        ki=(kcount-1)%kdata[0][kcode];
	cout << kdata[kcode][ki];
	kcode=0;
	kcount=0;
      }
      if (buf[bi]>='1'&&buf[bi]<='9'){
	kcode=buf[bi]-'0';
	kcount++;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first
#define y second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int N;
vector<ll> X;
int M;
ll K;
vector<int> A;

vector<int> add(const vector<int> &a, const vector<int> &b) {
    vector<int> X(N-1);
    for (int i = 0; i < N-1; i++) {
        X[i] = a[b[i]];
    }
    return X;
}

int main(int,char**) {
    ios_base::sync_with_stdio(false);
    
    cin >> N;
    X.resize(N); rv(X); 
    cin >> M >> K;
    A.resize(M); rv(A);
    for(int&a:A) --a;

    vector<int> P(N-1), R;
    for (int i = 0; i < N-1; i++) {
        P[i] = i;
    }
    R = P;

    for(int a:A) {
        swap(P[a-1],P[a]);
    }

    while (K) {
        if (K&1) {
            R = add(R, P);
        }
        P = add(P, P);
        K /= 2;
    }

    ll c = X[0];
    printf("%d\n", X[0]);
    for (int i = 0; i < N-1; i++) {
        c += X[R[i]+1] - X[R[i]];
        printf("%lld\n", c);
    }

}


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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// #define ll long long
// bool isEven(ll n) {return (n%2!=0)?false:true;}

using namespace std;

//atcoder - dp
//a

int a[100005], memo[100005];
int n;

int dp(int i)
{
	if(i>=n-1)
		return 0;
	if(memo[i]!=-1)
		return memo[i];
	if(i<n-2)
	{
		memo[i] = min(abs(a[i]-a[i+1])+dp(i+1),
							abs(a[i]-a[i+2])+dp(i+2));
	}
	else if(i==n-2)
		memo[i] = abs(a[i]-a[i+1]) + dp(i+1);

	return memo[i];
}

int main()
{
	cin>>n;
	FOR0(i, n)
	{
    	cin>>a[i];
    	memo[i] = -1;
	}


	cout<<dp(0)<<endl;

}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	int N, K;
	int A[50];
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N, greater<int>());

	long long sum = 0;
	//for (int i = 0; i < K; i++) cout << A[i] << " ";
	for (int i = 0; i < K; i++)  sum += A[i];

	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int GetMaxs(int date[], int n){
	int max=0, maxn=0;
	for(int i=0; i<n; i++){
		if(max<date[i]){
			max = date[i];
			maxn = i;
		}
	}
	return (maxn);
}

int main(void){
	int m[5],am,pm;
	string s;
	while(cin>>am>>pm,am){
		m[0] = am + pm;
		for(int i=1; i<5; i++){
			cin>>am>>pm;
			m[i] = am + pm;
		}
		s = 'A' + GetMaxs(m,5);
		cout << s << " " << m[GetMaxs(m,5)] <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n, m;
  cin >> n >> m;
  int x[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      x[i][j] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    x[a - 1][b - 1]++;
    x[b - 1][a - 1]++;
  }
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      cnt += x[i][j];
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 256
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

S = int(input())
sum =1
N=1
if S<3:
    print(0)
elif S<6:
    print(1)
else:
    while 1:
        N+=1
        a=S-3*N
        if 0>a:
            break
        X = comb(a+N-1,N-1)
        sum+=X
    print(sum%(1000000000+7))

Measured memory_bytes: 9144
n, c, k = map(int, input().split())

times = [int(input()) for _ in range(n)]
times.sort()

first = times[0]
cnt = 1
result = 0
for t in times[1:]:
    if t > first + k or cnt >= c:
        first = t
        cnt = 1
        result += 1
    else:
        cnt += 1
print(result + 1)


Measured memory_bytes: 7888
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();

    String mae = S.substring(0, N/2) ;
    String ato = S.substring(N/2, N);
    
    if(N % 2 == 1){
      System.out.println("No");
    }else if(mae.equals(ato)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

}
}


Measured memory_bytes: 22100
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    X, Y, Z, K = map(int, input().split())
    A, B, C = [sorted(map(int, input().split())) for _ in range(3)]

    AB = [a + b for a in A for b in B]
    AB = sorted(AB, reverse=True)[:K]

    ABC = [ab + c for ab in AB for c in C]
    ABC = sorted(ABC, reverse=True)[:K]
    for i in ABC:
        print(i)

if __name__ == '__main__':
    main()


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

#define pb push_back
typedef long long ll;

const int len = 1e5+5, mod = 1e9+7;
const ll inf = 1e18;
ll ar[len];
int lim[2][len], dp[2][len], tree[2][4*len];
vector<int> st1, st2;

int add(int a, int b){
    return (a+b)%mod;
}

void update(int p, int l, int r, int i, int v, int t){
    if (l == r)
        tree[t][p] = dp[t][l] = v;
    else{
        int mid = (l+r)/2;
        if (i <= mid)
            update(2*p, l, mid, i, v, t);
        else
            update(2*p+1, mid+1, r, i, v, t);

        tree[t][p] = add(tree[t][2*p], tree[t][2*p+1]);
    }
}

int query(int p, int l, int r, int i, int j, int t){
    if (i <= l && r <= j)
        return tree[t][p];
    if (r < i || j < l)
        return 0;

    int mid = (l+r)/2;
    return add(query(2*p, l, mid, i, j, t), query(2*p+1, mid+1, r, i, j, t));
}

int main(){
    int n;
    ll a, b;
    scanf("%d %lld %lld", &n, &a, &b);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &ar[i]);
    ar[0] = -inf;

    for (int i = n, j = n, k = n; i >= 1; i--){
        while (ar[i] - ar[j] < a) j--;
        while (ar[i] - ar[k] < b) k--;

        lim[0][i] = j;
        lim[1][i] = k;
    }

    //for (int i = 1; i <= n; i++)
      //  printf("i = %d, lim0 = %d, lim1 = %d\n", i, lim[0][i], lim[1][i]);

    update(1, 0, n, 0, 1, 0);
    update(1, 0, n, 0, 1, 1);

    st1.pb(0), st2.pb(0);

    for (int i = 2; i <= n; i++){
        int cur1 = query(1, 0, n, 0, lim[0][i], 1);
        int cur2 = query(1, 0, n, 0, lim[1][i], 0);

        if (ar[i]-ar[i-1] < a)
            while (!st1.empty())
                update(1, 0, n, st1.back(), 0, 0), st1.pop_back();
        if (ar[i]-ar[i-1] < b)
            while (!st2.empty())
                update(1, 0, n, st2.back(), 0, 1), st2.pop_back();

        update(1, 0, n, i-1, cur1, 0);
        update(1, 0, n, i-1, cur2, 1);

        st1.pb(i-1), st2.pb(i-1);

        /*
        printf("i = %d\n", i);
        for (int j = 0; j <= n; j++)
            printf("%d ", dp[0][j]);
        printf("\n");

        for (int j = 0; j <= n; j++)
            printf("%d ", dp[1][j]);
        printf("\n");
        */
    }

    int ans = 0;
    for (int i = 0; i <= n; i++)
        ans = add(ans, add(dp[0][i], dp[1][i]));

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 6132
n=int(input())
s=input()
count=0
for i in range(1,n):
  if s[i]=='E':
    count+=1
m=count
for i in range(1,n):
  if s[i-1]=='W':
    count+=1
  if s[i]=='E':
    count-=1
  m=min(m,count)
print(m)


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <assert.h>
#include <cstdlib>
#include <climits>
#define ll long long
#define x first
#define y second
#define vec vector
#define pb push_back
#define sz(v) (int)v.size()
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define repb(i, b, a) for(ll i = b - 1; i >= a; --i)
#define vin(v) {for(ll i = 0; i < sz(v); ++i) cin >> v[i];}
#define endl '\n'
using namespace std;

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    vec<int> v(n);
    vin(v);
    ll ans = 0;
    rep(i, 0, n)
    {
        ans += (d + v[i] - 1) / v[i];
    }
    cout << ans + x << endl;
}

Measured memory_bytes: 256