akhauriyash/Code-Regression huggingface dataset:
def examC():
    N = I()
    S = SI()
    cumE = [0]*(N+1)
    for i in range(N):
        cur = 0
        if S[i]=="E":
            cur = 1
        cumE[i+1] = cumE[i] + cur
    ans = N-1
    for i in range(1,N+1):
        cur = (i-1-cumE[i-1]) + (cumE[N]-cumE[i])
        ans = min(ans,cur)
    print(ans)



import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 43376
INTEGER(16) A,B,K,AKI
READ*,A,B,K
DO I=0,K-1
  AKI=A+I
  IF(A+I>B)EXIT
  PRINT"(I0)",A+I
END DO
DO I=1,K
  IF(B-K+I<=AKI)CYCLE
  PRINT"(I0)",B-K+I
END DO  
END

Measured memory_bytes: 512
n = int(input())
a = [0] + list(map(int, input().split()))

G = [[] for _ in range(n + 1)]

for i in range(1, n + 1):
	G[a[i]].append(i)

cnt = 0
for i in range(1, n + 1):
	if a[i] in G[i] and i in G[a[i]]:
		cnt += 1
print(cnt // 2)

Measured memory_bytes: 62316
#include<iostream>
#include<cmath>
//AIZU??§???<cmath>????????????????????°sqrt?????????????????????Builder??§?????????
#include<iomanip>
//<iomanip>?????????????????????
using namespace std;

int main(){
	double x_1, y_1, x_2, y_2;
	cin >> x_1 >> y_1 >> x_2 >> y_2;
	double D = sqrt((x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (y_2 - y_1));
	cout << fixed << setprecision(8) << D << endl;
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
const int N = 3003;
char s[N], t[N], ans[N];
int dp[N][N], n, m;
int main(int argc, char const *argv[])
{
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	n = strlen(s + 1);
	m = strlen(t + 1);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if (s[i] == t[j])
				dp[i][j] = 1 + dp[i - 1][j - 1];
		}
	}
	int x = n, y = m, l = dp[n][m];
	while (x && y)
	{
		if (s[x] == t[y])
		{
			ans[l] = s[x];
			x --;
			y --;
			l --;
		}
		else if (dp[x - 1][y] >= dp[x][y - 1])
			x --;
		else
			y --;
	}
	for (int i = 1; i <= dp[n][m]; ++i)
	{
		printf("%c", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 35456
/*input
1000000000 141421 173205

*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vii;
#define pb push_back
#define print(a) for(auto x:a){cout<<x<<' ';}cout<<endl;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1e9 + 7;
int fac[200001];
int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}
 
int fast_exp(int base, int expo, int mod = MOD) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;}
	return res;}
 
int modinv(int a, int mod = MOD){return takemod(fast_exp(takemod(a), mod-2, mod), mod);}

int ncrmodp(int n, int r){
	int ans = 1;
	for(int i=n-r+1;i<=n;++i){
		ans *= i;
		ans%=MOD;
	}

	return (ans*modinv(fac[r]))%MOD;
}

void solve(){
	int n,a,b;
    cin>>n>>a>>b;
    int ans = fast_exp(2, n)-ncrmodp(n, a)-ncrmodp(n, b)-1;
    cout<<(takemod(ans))<<endl;
}

signed main(){
	IOS
	int t=1;
	fac[0] = 1;
	for(int i=1;i<=200000;++i){
		fac[i] = fac[i-1]*i;
		fac[i]%=MOD;
	}
	//cin>>t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 1920
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
const ll maxN=2e5+5 , N=1e3+1;
ll A[N];
ll n  ,  m , k ;
ll a[maxN] , b[maxN];

void solve(){
	cin>> n >> m >> k ;
	for(ll i=0;i<n ;i++) {
		cin>>a[i+1];
		a[i+1]+=a[i];
	}
	for(ll i=0;i<m ;i++){
		cin>>b[i+1];
		b[i+1]+=b[i];
	}
	ll j=m ,ans=0;
	for(ll i=0;i<=n ;i++){
		while(j>=0 && (k-a[i])<b[j])j--;
		if(j>=0)
		ans=max(ans , i+j);
	}
	cout<<ans<<endl;
}

int main(){
	//mahakal(),fast;
	ll t=1;
	// cin>>t ;
	while(t--)solve();

	return 0;
}

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

namespace ITP2_1_D
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] items = ReadIntAr();
            List<int>[] lists = new List<int>[items[0]];

            for (int i = 0 ; i < items[0] ; i++)
            {
                lists[i] = new List<int>();
            }

            for (int i = 0 ; i < items[1] ; i++)
            {
                int[] line = ReadIntAr();

                switch (line[0])
                {
                    case 0:
                        {
                            lists[line[1]].Add(line[2]);
                            break;
                        }
                    case 1:
                        {
                            if (lists[line[1]].Count == 0)
                            {
                                Console.WriteLine("");
                            }
                            else
                            {
                                Console.WriteLine(String.Join(" ", lists[line[1]].Select(x => x.ToString()).ToArray()));
                            }
                            break;
                        }
                    case 2:
                        {
                            lists[line[1]].Clear();
                            break;
                        }
                }
            }



           
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 59012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a >= 0 && c >= 0) cout << b * d << endl;
    else if(b<=0 && d<=0) cout << a*c << endl;
    else if(b<=0&& c<0) cout << a*c << endl;
    else if(b<=0 && c>=0)cout << b*c << endl;
    else if(d<=0 && a>=0) cout <<a*d << endl;
    else if(d<=0 && a<0) cout << a*c << endl;
    else cout << max(a*c, b*d) << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll func(ll a,ll b,ll& ans_x,ll& ans_y){
    if(b == 0){
        ans_x = 1;
        ans_y = 0;
        return a;
    }else{
        ll ret = func(b,(a%b),ans_y,ans_x);
        ans_y -= (a/b)*ans_x;
        return ret;
    }
}

vector<bool> IsPrime;

ll sieve(ll max){
    ll sum=0;
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    }
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(ll i=2; i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) {
            sum++;
            for(size_t j=2; i*j<=max; ++j) IsPrime[i*j] = false;
        }
    return sum;
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x,y;
    cin>>x>>y;
    if((y-2*x)%2==0 && y-2*x>=0 && (4*x-y)%2==0 && (4*x-y)>=0){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>

#define rep(i,n) for(i=0;i<(n);i++)
using namespace std;

int main() {
    int n,i,ans=0,f;
    cin>>n;
    int a[n];
    rep(i,n){
    	cin>>a[i];
    }
    sort(a,a+n);
    f=a[0];
    for(i=1;i<n;i++){
    	if(f!=a[i]){
    		ans+=a[i]-a[i-1];
    	}
    	f=a[i];
    }
    cout<<ans<<endl;
	// your code goes here
	return 0;
}

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

int main() {
    int n, k; cin >> n >> k; int ans = 0;
    int arr[n]; for (int i = 0; i < n; i ++) cin >> arr[i];
    sort(arr, arr + n); for (int i = 0; i < k ; i++) ans += arr[i];
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int gcd(int one, int two) {
	while (one != 0 && two != 0) {
		if (one > two) {
			one = one % two;

		}
		else {
			two = two % one;
		}

	}

	return std::max(one, two);

}
int main()
{
	using namespace std;
	int a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0, count = 0, nagax = 0, nagay = 0, size = 0;
	int sa[10000] = {};
	int yoko = 0, tate = 0;
	std::string output,output2,output3,output4;
	char changer;
	char changer2;

	cin >> a >> b >> c >> d;
	yoko = c - a;//負なら進行方向左
	tate = d - b;//負なら進行方向下
	while (tate > 0) {
		output += 'U';
		tate--;
	}
	while (tate < 0) {
		output += 'D';
		tate++;
	}
	while(yoko>0) {
		output += 'R';
		yoko--;
	}
	while (yoko < 0) {
		output += 'L';
		yoko++;
	}

	if (output[output.size()-1] == 'R') {
		changer = 'L';
	}
	else {
		changer = 'R';
	}
	if (output[0] == 'U')
	{
		changer2 = 'D';
	}
	else {
		changer2 = 'U';
	}

	output2 += changer;
	output2 += output[0];
	output2 += output;
	output2 += output[output.size() - 1];
	output2 += changer2;
	
	
	for (int i = 0; i < output.size(); i++) {
		if (output[i] == 'R') {
			output3 += 'L';
		}
		if (output[i] == 'L') {
			output3 += 'R';
		}
		if (output[i] == 'U') {
			output3 += 'D';
		}
		if (output[i] == 'D') {
			output3 += 'U';
		}
	}
	for (int i = 0; i < output2.size(); i++) {
		if (output2[i] == 'R') {
			output4 += 'L';
		}
		if (output2[i] == 'L') {
			output4 += 'R';
		}
		if (output2[i] == 'U') {
			output4 += 'D';
		}
		if (output2[i] == 'D') {
			output4 += 'U';
		}
	}
	cout <<output<<output3<<output2<<output4<< endl;
	
}






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*string s;
	cin >> s;
	bool ok = true;
	rep(i, 3) {
		if (s[i + 1] == s[i])ok = false;
	}
	if (ok)cout << "Good";
	else cout << "Bad";*/

	/*int N, L;
	cin >> N >> L;
	int i, m = 1e9;
	for (i = 1; i <= N; i++) {
		if (abs(m) > abs(L + i - 1))m = L + i - 1;
	}
	cout << (N * (2 * L + N - 1)) / 2 - m;*/


	/*ll A, B, C, D;
	cin >> A >> B >> C >> D;*/


	ll N, A, B;
	cin >> N;
	vector<pair<ll, ll>>v(N);
	rep(i, N) {
		cin >> v[i].second >> v[i].first;
	}
	sort(all(v));
	ll sum = 0;
	bool ok = true;
	rep(i, N) {
		sum += v[i].second;
		if (sum > v[i].first)ok = false;
	}
	if (ok)cout << "Yes";
	else cout << "No";

	return 0;
}

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

using namespace std;

const int maxn = 1e5+10;

int n,m,vis[maxn],sx,sy;
vector<int> p1,p2;
vector<int> g[maxn];

void visit(int x) {
    p1.push_back(x);
    vis[x] = 1;
    for (auto v : g[x]) {
        if (vis[v]) continue;
        visit(v);
        return;
    }
}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=m;i++) {
        int x,y;
        cin>>x>>y;
        sx=x;sy=y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vis[sx] = vis[sy] = 1;
    visit(sx);
    for (auto inf : p1) p2.push_back(inf);
    p1.clear();
    visit(sy);
    reverse(p2.begin(),p2.end());
    cout<<p1.size()+p2.size()<<endl;
    for (auto inf : p2) cout<<inf<< " ";
    for (auto inf : p1) cout<<inf<<" ";
}


Measured memory_bytes: 9720
/*2019/10/02 */
/*template*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){if(*(int*)a < *(int*)b)return -1;else if(*(int*)a == *(int*)b)return 0;else return 1;}
int desc(const void *a,const void *b){if(*(int*)a < *(int*)b)return 1;else if(*(int*)a == *(int*)b)return 0;else return -1;}
int llasc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return -1;else if(*(ll*)a == *(ll*)b)return 0;else return 1;}
int lldesc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return 1;else if(*(ll*)a == *(ll*)b)return 0;else return -1;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
 
/*
int asc_t(const void *a,const void *b){if((pair_t*)a->d < (pair_t*)b->d)return -1;else if((pair_t*)a->d == (pair_t*)b->d)return 0;else return 1;}
int desc_t(const void *a,const void *b){if((pair_t*)a->d < (pair_t*)b->d)return 1;else if((pair_t*)a->d == (pair_t*)b->d)return 0;else return -1;}
*/

int main(){
    ll n,a[200000];

    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    qsort(a,n,sizeof(ll),lldesc);
    ll xy[2]={},xy_i=0;
    
    for(int i=0;i+1<n;i++){
        if(a[i]==a[i+1]){
            xy[xy_i++]=a[i];
            i++;
        }
    }
    if(xy[0]==0||xy[1]==0){
        printf("0\n");
    }else{
        ll ans=xy[0]*xy[1];
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1788
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val bList = readLine()!!.split(" ").map { it.toInt() }
    val aList = mutableListOf<Int>()
    aList.add(bList.first())

    for(i in (1 .. bList.lastIndex)) {
        val tmp = Math.min(bList[i-1], bList[i])
        aList.add(tmp)
    }
    aList.add(bList.last())
    println(aList.sum())

}


Measured memory_bytes: 38112
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


#if 0

#else


bool check(int dt, int dx, int dy)
{
	int dist = abs(dx) + abs(dy);

	return (dt >= dist && (dt - dist) % 2 == 0);
}

int main()
{
	int N;
	scanf("%d", &N);

	vector <int> t, x, y;
	t.push_back(0);
	x.push_back(0);
	y.push_back(0);

	for (int i = 0; i < N; ++i)
	{
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);

		t.push_back(a);
		x.push_back(b);
		y.push_back(c);
	}

	bool ok = true;
	for (int i = 0; i < N; ++i)
	{
		if (!check(t[i + 1] - t[i], x[i + 1] - x[i], y[i + 1] - y[i]))
		{
			ok = false;
			break;
		}
	}

	if (ok)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}




	return 0;
}

#endif


Measured memory_bytes: 1644
#include <stdio.h>

#define MAX 100000

int n, k;
double T[MAX];

int check(double p){
  int i = 0, j;
  double s;
  for( j = 0 ; j < k ; j++){
    s = 0.0;
    while( s + T[i] <= p){
      s += T[i];
      i++;
      if( i == n ) return n;
    }
  }
  return i;
}

int solve(){
  double left = 0.0;
  double right = 100000*10000;
  double mid;
  int v;

  while( right - left > 1){
    mid = ( left + right ) / 2;
    v = check(mid);
    if( v >= n ) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  int i;
  double ans;
  scanf("%d%d", &n, &k);
  for( i = 0 ; i < n ; i++) scanf("%lf", &T[i]);
  ans = solve();
  printf("%d\n", (int)ans);

  return 0;
}




Measured memory_bytes: 2552
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ttl=[]
cnt=[]
count=0
for i in range(n):
  nxt=i+1
  grp=[]
  count=0
  pnt=[]
  pnt.append(0)
  for j in range(n):
    nxt=p[nxt-1]
    pnt.append(pnt[j]+c[nxt-1])
    count+=1
    if nxt==i+1:
      del pnt[0]
      ttl.append(pnt)
      cnt.append(count)
      break
ans=[]
for i in range(n):
  peak=ttl[i].index(max(ttl[i]))
  if k<=cnt[i]:
    ans.append(max(ttl[i][:k]))
  else:
    if ttl[i][-1]<0:
      ans.append(ttl[i][peak])
    else:
      if k%cnt[i]==0:
        ans.append(((k-peak-1)//cnt[i])*ttl[i][-1]+ttl[i][peak])
      else:
        ans.append(max((k//cnt[i])*ttl[i][-1]+max(ttl[i][0:k%cnt[i]]),((k-peak-1)//cnt[i])*ttl[i][-1]+ttl[i][peak]))
print(max(ans))

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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    string S, T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;

    if( U == S ){
        A -= 1;
    }
    else if(U == T){
        B -= 1;
    }

    cout << A << ' ' << B << endl;
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		for (;;) {
			int n = s.nextInt(), a = s.nextInt(), b = s.nextInt(), c = s
					.nextInt(), x = s.nextInt();
			if (n < 1) {
				break;
			}

			int rs[] = new int[n];
			for (int i = 0; i < n; ++i) {
				rs[i] = s.nextInt();
			}

			int count = 0, i = 0;
			for (;count <= 10000; ++count) {
				int r = rs[i];
				if (r == x) {
					++i;
				}
				x = (a * x + b) % c;
				if (i == n) {
					break;
				}
			}
			System.out.println(count > 10000 ? -1 : count);
		}
	}
}

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

//関数
    
    
    
//main関数
int main() {
    
    
    
    //入力
     int N,A,B;
     cin >>N>>A>>B;
     
    
    
    
    
    
    
    
    
    //計算
    
    
    
    //出力
    
    if((B-A)%2==0){
        cout<<"Alice"<<endl;
    }else{
        cout<<"Borys"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, i, disorder_num = 0;
    scanf("%d", &n);
    int p[n];
    for ( i = 0; i < n; i++ ) {
        scanf("%d", &p[i]);
        if ( p[i] != (i + 1) ) {
            disorder_num++;
        }
    }
    if ( disorder_num <= 2 ) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(input()) for _ in range(N)]
    
if A[0] != 0:
    print(-1)

else:
    roop = 0
    for i in range(1,N):
        num = A[i]
        if num == A[i-1]+1:
            roop += 1
        elif num <= A[i-1]:
            roop += num
        else:
            roop = -1
            break
    print(roop)
            

Measured memory_bytes: 11048
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll gcd(ll a, ll b){//計算量はO(log(max(a,b))
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll kai(ll x){
  if(x == 1) return 1;
  return x * kai(x-1) % MOD;
}

int K;
struct edge{int to, cost;};

vector<edge> E[100010];
int d[100010];

void dijkstra(){
  priority_queue<P, vector<P>, greater<P>> pque;
  rep(i, 100010) d[i] = INF;
  d[1] = 1;
  pque.push(P(1, 1));

  while(!pque.empty()){
    P p = pque.top(); pque.pop();
    int c = p.first, v = p.second;
    if(c > d[v]) continue;
    rep(i, E[v].size()){
      int next = E[v][i].to;
      int nc = E[v][i].cost;
      if(d[next] > d[v] + nc){
        d[next] = d[v] + nc;
        pque.push(P(d[next], next));
      }
    }
  }
}

int main(){
  cin >> K;
  rep(i, K){
    edge e;
    e.cost = 1; e.to = (i+1) % K;
    E[i].push_back(e);
    e.cost = 0, e.to = i*10%K;
    E[i].push_back(e);
  }
  dijkstra();
  cout << d[0] << endl;




}


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

long long n, k, q;
vector<long long> a, now;

int main() {
  cin >> n >> k >> q;
  a.resize(q);
  now.assign(n, 0);
  for(int i = 0; i < q; ++i) {
    cin >> a[i];
    ++now[(--a[i])];
  }
  for(int i = 0; i < n; ++i) {
    if((q - now[i] >= k))
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> prime = {2,3,5,7,11,13,17,19,23,29,31,
        37,41,43,47,53,59,61,67,71,73,79,83,89,97};
    vector<int> num(101, 0);
    if (N <= 9){
        cout << 0 << endl;
        return 0;
    }
    rep(i, 2, N + 1){
        int p = i;
        rep(j, 0, 25){
            if (p == 1) break;
            if (p % prime.at(j) == 0){
                p /= prime.at(j);
                num.at(prime.at(j))++;
                j--;
            }
        }
    }
    int count_2 = 0, count_4 = 0, count_14 = 0, count_24 = 0, count_74 = 0;
    rep(i, 0, 101){
        //cout << i << " " << num.at(i) << endl;
        if (num.at(i) >= 2) count_2++;
        if (num.at(i) >= 4) count_4++;
        if (num.at(i) >= 14) count_14++;
        if (num.at(i) >= 24) count_24++;
        if (num.at(i) >= 74) count_74++;
    }
    //cout << count_2 << " " << count_4 << " " << count_14 << " " << count_24 << endl;
    int ans = count_24 * (count_2 - 1) + count_14 * (count_4 - 1) + count_4 * (count_4 - 1) * (count_2 - 2) / 2 + count_74;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			str = br.readLine();
			int K = Integer.parseInt(str);
			str = br.readLine();
			String[] s = str.split(" ",0);
			int total = 0;
			for (int i = 0; i < s.length; i++) {
				int x = Integer.parseInt(s[i]);
				int dis = Math.min(x, K-x);
				total += dis;
			}
			
 
			System.out.println(total * 2);
		}catch (Exception e) {
			System.exit(0);
		}
	
	}
 
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
static const int MAX_N = 100;
static const int MAX_M = 100;
int main()
{
	/*
        ios_base::sync_with_stdio(0); cin.tie(0);
        #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
    */

    int n,m;
    int t[MAX_N+1];
    int p[MAX_M+1],x[MAX_M+1];
    
    //input
    cin>>n;
    for(int i=1;i<=n;i++)cin>>t[i];
    cin>>m;
    for(int i=1;i<=m;i++)cin>>p[i]>>x[i];

    //output
    for(int i=1;i<=m;i++){//栄養ドリンクの個数
        int ans = 0;
        for(int j=1;j<=n;j++){//問題の個数
            ans += (j==p[i]?x[i]:t[j]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

#define ll long long 
#define int ll
#define endl "\n"

signed main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//freopen("input.txt", "r", stdin); 
	//freopen("output.txt", "w", stdout);
		
	int n;
	cin >> n;
	
	cout << ((n+999)/1000)*1000 - n << endl;
		
}

Measured memory_bytes: 3648
def main():

    N, M = map(int, input().split())
    rel = []
    for _ in range(M):
        a, b = map(int, input().split())
        rel.append([a, b])

    ans = 0
    rel.sort()
    a, b = rel[0]
    ans = 1
    for i in range(1, M):
        c, d = rel[i]
        if c < b:
            a = c
            b = min(b, d)
        else:
            ans += 1
            a, b = c, d
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 20076
#include <bits/stdc++.h>
using namespace std;
int H,W,sx,sy,gx,gy,d[1000][1000];
string s[1000];
main()
{
    cin>>H>>W;
    cin>>sx>>sy;
    cin>>gx>>gy;
    --sx;--sy;--gx;--gy;
    for(int i=0;i<H;++i)cin>>s[i];
    for(int i=0;i<H;++i)for(int j=0;j<W;++j)d[i][j]=H*W;
    d[sx][sy]=0;
    deque<pair<int,int>>q;
    q.push_back({sx,sy});
    while(!q.empty())
    {
        int x=q.front().first;
        int y=q.front().second;
        q.pop_front();
        for(int i=-2;i<=2;++i)for(int j=-2;j<=2;++j)
        {
            int nx=x+i;
            int ny=y+j;
            if(nx<0||ny<0||nx>=H||ny>=W||s[nx][ny]=='#')continue;
            if(abs(i)+abs(j)<=1&&d[nx][ny]>d[x][y])
            {
                d[nx][ny]=d[x][y];
                q.push_front({nx,ny});
            }else if(d[nx][ny]>d[x][y]+1)
            {
                d[nx][ny]=d[x][y]+1;
                q.push_back({nx,ny});
            }
        }
    }
    cout<<(d[gx][gy]==H*W?-1:d[gx][gy])<<endl;
}

Measured memory_bytes: 9348
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n, ans = 1;
  char flag, s[100005];
  scanf("%lld%s", &n, s);
  flag = s[0];
  for (int i = 0; s[i]; i++)
  {
    if (flag != s[i])
    {
      ans++;
      flag = s[i];
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
using namespace std;
int main(){
  int d, n;
  cin >> d >> n;
  int ans;
  int cnt = 0;
  for(int i=1; i<=5000000; i++){
    int tmp = i;
    int t_cnt = 0;
    while(1){
      if(tmp % 100 == 0 && tmp != 0){
        t_cnt++;
        tmp = tmp / 100;
      }else{
        break;
      }
    }
    if(t_cnt == d) cnt++;
    if(cnt == n){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


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

const long long mod = 998244353;
const int maxn = 3003;

int a, b, c, d;
long long dp[maxn][maxn];

long long add_mod (long long x, long long y) {
	if (x + y < mod)
		return x + y;
	return x + y - mod;
}

long long mul_mod (long long x, long long y) {
	return (x * y) % mod;
}

long long sub_mod (long long x, long long y) {
	if (x >= y)
		return x - y;
	else
		return x + mod - y;
}

signed main () {
	scanf("%d %d %d %d", &a, &b, &c, &d);
	for (int i = a; i <= c; ++i) {
		for (int j = b; j <= d; ++j) {
			if (i == a && j == b)
				dp[i][j] = 1;
			else if (i == a)
				dp[i][j] = mul_mod(i, dp[i][j - 1]);
			else if (j == b)
				dp[i][j] = mul_mod(j, dp[i - 1][j]);
			else 
				dp[i][j] = sub_mod(add_mod(mul_mod(i, dp[i][j - 1]), mul_mod(j, dp[i - 1][j])), mul_mod(mul_mod(i - 1, j - 1), dp[i - 1][j - 1]));
		}
	}
	printf("%lld\n", dp[c][d]);
}


Measured memory_bytes: 74156
import sys
import collections
import math
from collections import Counter
from collections import deque


N, T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]


start = 0
finish = 0
total = 0
for i in range(N):
    if finish <= t[i]:
        total += finish - start
        start = t[i]
    finish = t[i] + T

total += finish - start

print(total)

sys.exit(0)


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

int q, cmd, a;
vector<int> v;

int main() {
    cin >> q;
    while (q--) {
        cin >> cmd;
        if (cmd == 0) {
            cin >> a;
            v.push_back(a);
        }
        if (cmd == 1) {
            cin >> a;
            cout << v[a] << endl;
        }
        if (cmd == 2) v.pop_back();
    }
}


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

using namespace std;


int const INF = (int)10e+6;


void min_cost_finder(vector<int> &cost, int N)
{
    int dp[N];
    dp[0] = 0;
    dp[1] = abs(cost[1] - cost[0]);

    // for(int i =0; i < N; i++)
    // {
    //     dp[i] = INF;
    // }

    for(int i = 2; i < N; i++)
    {
        
        dp[i] =  min(dp[i-1] + abs(cost[i] - cost[i-1]) , dp[i-2] + abs(cost[i] - cost[i-2]));
    // cout << dp[i] << endl;
    }


    cout << dp[N - 1] << endl;

}

int main()
{
    int N;
    cin >> N;
    vector <int> cost(N);
    for(int i = 0; i < N; i++)
    {
        cin >> cost[i] ;
    }

    // for(int i = 0; i < N; i++)
    // {
    //     cout << cost[i] ;
    // }


    // Main Algo
    min_cost_finder(cost, N);


    return 0;



}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int mod=998244353;
char s[300050];
int A[100050],B[100050],C[100050];
vector<int> a,b,c;
int main(){
	int n,i,x,ans=1;
	scanf("%d%s",&n,s+1);
	for(i=1;i<=n*3;++i)if(s[i]=='R')a.push_back(i);
	else if(s[i]=='G')b.push_back(i);
	else c.push_back(i);
	for(i=0;i<n;++i)if(a[i]<b[i])if(a[i]<c[i]){
		A[i+1]=a[i];
		if(b[i]<c[i]){B[i+1]=b[i];C[i+1]=c[i];}
		else{B[i+1]=c[i];C[i+1]=b[i];}
	}else{A[i+1]=c[i];B[i+1]=a[i];C[i+1]=b[i];}
	else if(b[i]<c[i]){
		A[i+1]=b[i];
		if(a[i]<c[i]){B[i+1]=a[i];C[i+1]=c[i];}
		else{B[i+1]=c[i];C[i+1]=a[i];}
	}else{A[i+1]=c[i];B[i+1]=b[i];C[i+1]=a[i];}
	for(i=1;i<=n;++i){
		x=upper_bound(A+1,A+n+1,B[i])-A-1;
		ans=(ll)ans*(x-i+1)%mod*i%mod;
	}
	for(i=n;i;--i){
		x=lower_bound(C+1,C+n+1,B[i])-C;
		ans=(ll)ans*(i-x+1)%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
	int n,a,b;
	scanf("%d %d %d", &n,&a,&b);
	int sum=0;
	for (int i=1;i<=n;i++){
		int digitSum=0;
		int temp=i;
		while(temp!=0){
			digitSum=digitSum+temp%10;
			temp/=10;
		}
		if(digitSum>=a&&digitSum<=b){
			sum+=i;
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 1728
from fractions import gcd
from functools import reduce
from sys import stdin

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

while(True):
    n = int(stdin.readline())
    if not n: break
    s = [list(map(int,stdin.readline().split())) for _ in range(n)]
    lcmde = lcm_list([r[1] for r in s])
    lcmnu = lcm_list([r[0]*lcmde//r[1] for r in s])
    print("\n".join( str(lcmnu*r[1]//lcmde//r[0]) for r in s))



Measured memory_bytes: 7064
using System;
using System.Linq;
class A
{
    static void Main()
    {
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long s = 1;
        for (long o = 0; o < a[0]; o++)
        {
            if (o == 0) { s *= a[1]; }
            else { s *= (a[1] - 1); }
        }
        Console.WriteLine(s);
        Console.ReadLine();
    }
}

Measured memory_bytes: 11348
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>

using namespace std;

struct pNode
{
    int id,x,y;
    pNode(){}//必不可少
    pNode(int id_,int x_,int y_):id(id_),x(x_),y(y_){}
};
struct Node
{
    int depth;
    pNode data;
    Node *l,*r;
};
int n,sx,tx,sy,ty;
static const int maxn=500010;
int len;
int ans[maxn];
pNode g[maxn];


bool cmpx(pNode a,pNode b)
{
    return a.x<b.x;
}
bool cmpy(pNode a,pNode b)
{
    return a.y<b.y;
}
void build(Node *&p,int depth,int left,int right)
{
    if(left>right)
        return;
    int mid=(left+right)/2;
    if(depth%2==0)
        sort(g+left,g+right+1,cmpx);
    else
        sort(g+left,g+right+1,cmpy);
    p=(Node *)malloc(sizeof(Node));
    p->depth=depth;
    p->data=g[mid];
    p->l=NULL,p->r=NULL;
    build(p->l,depth+1,left,mid-1);
    build(p->r,depth+1,mid+1,right);
}

void find_range(Node *&p)
{
    if(p==NULL)
        return;
    int x=p->data.x;
    int y=p->data.y;
    if(x>=sx &&x<=tx &&y>=sy &&y<=ty)
    {
        ans[len++]=p->data.id;
    }
    if(p->depth%2==0)
    {
        if(x>=sx)
            find_range(p->l);
        if(x<=tx)
            find_range(p->r);
    }else
    {
        if(y>=sy)
            find_range(p->l);
        if(y<=ty)
            find_range(p->r);
    }
}
int main()
{
    int i,j,q;
    Node *tree=NULL;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&g[i].x,&g[i].y);
        g[i].id=i;
    }
    build(tree,0,0,n-1);
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
        scanf("%d%d%d%d",&sx,&tx,&sy,&ty);
        len=0;
        find_range(tree);
        sort(ans,ans+len);
        for(j=0;j<len;j++)
            printf("%d\n",ans[j]);
        printf("\n");
    }
    return 0;
}



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

#define ll long long
#define ull unsigned long long

using namespace std;

const int INF = 1001001001;

int main() {
	int H, W, K;
	cin >> H >> W >> K;

	vector <string> s(H, "");
	for (int ii = 0; ii < H; ++ii){
		cin >> s[ii];
	}

	int ans = INF;
	for (int bit = 0; bit < (1 << (H-1)); ++bit){
		//各行を分割線によりグループ分け
		int g = 0;
		vector <int> id(H, 0);
		for (int ii = 0; ii < H; ++ii){
			id[ii] = g;
			if ( (bit>>ii) & 1 ){
				g++;
			}
		}
		g++;

		//グループごとに各列の和を取る
		vector<vector<int>> c(g, vector <int> (W, 0));
		for (int ii = 0; ii < H; ++ii){
			for (int jj = 0; jj < W; ++jj){
				c[id[ii]][jj] += s[ii][jj] - '0';
			}
		}

		//ある列の和がKを超えていたら命題が達成できずNG
		bool ok = true;
		for (int ii = 0; ii < g; ++ii){
			for (int jj = 0; jj < W; ++jj){
				if (c[ii][jj] > K){
					ok = false;
					break;
				}
			}
			if (!ok) break;
		}
		if (!ok) continue;

		//列を切っていく
		int divNum = g - 1;
		vector <int> sum(g, 0);
		for (int col = 0; col < W; ++col){
			bool overK = false;
			//あるグループの和がKを超えるまでグループ毎に和を撮り続ける
			for (int group = 0; group < g; ++group){
				sum[group] += c[group][col];
				if (sum[group] > K){
					overK = true;
					break;
				}
			}
			//あるグループの和がKを超えていたら分割し，グループ毎の和を初期化
			if (overK){
				divNum++;
				for (int group = 0; group < g; ++group){
					sum[group] = c[group][col];
				}
			}
		}

		//ansを更新
		ans = min(ans, divNum);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
double x,n,t;
cin >> n >> x >> t;
cout << (ll)(ceil(n / x) * t) << endl;
return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  int x;
  cin>>x;

  if(x>=400&&x<600){
    cout<<8<<endl;
  }else if(x>=600&&x<800){
    cout<<7<<endl;
  }else if(x>=800&&x<1000){
    cout<<6<<endl;
  }else if(x>=1000&&x<1200){
    cout<<5<<endl;
  }else if(x>=1200&&x<1400){
    cout<<4<<endl;
  }else if(x>=1400&&x<1600){
    cout<<3<<endl;
  }else if(x>=1600&&x<1800){
    cout<<2<<endl;
  }else if(x>=1800&&x<2000){
    cout<<1<<endl;
  }
  return 0;
}


Measured memory_bytes: 3636
object Main {
    def main(args: Array[String]) {
        val str = scala.io.StdIn.readLine()
        val num = scala.io.StdIn.readLine().toLong

        var count         = 0
        var first_not_num = -1
        for(i <- 0 until str.length()) {
            if(first_not_num == -1) {
                if(str(i) == '1') { count += 1 }
                else              { first_not_num = str(i).toString.toInt }
            }  
        }
        if (count.toLong >= num) println(1)
        else             println(first_not_num)
    }
}

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 200005, M = 1000000007;
int a[N];
pair <int, int> b[N];

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k;
    scanf("%d %d", &n, &k);
    int K = k;
    vector <int> pos, neg;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        b[i] = {abs(a[i]), (a[i] < 0 ? -1 : 1)};
        if (a[i] < 0) {
            neg.pb(-a[i]);
        } else {
            pos.pb(a[i]);
        }
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int sz1 = pos.size(), sz2 = neg.size();
    if (sz1 == 0) {
        ll res = 1;
        if (k & 1) {
            for (int i = 0; i < k; i++) {
                res *= neg[i];
                res %= M;
            }
            res *= -1;
            res += M;
        } else {
            for (int i = sz2 - 1, j = k - 1; j >= 0; i--, j--) {
                res *= neg[i];
                res %= M;
            }
        }
        printf("%lld", res);
        return 0;
    }
    if (k == n) {
        ll res = 1;
        for (int i = 0; i < n; i++) {
            res *= a[i];
            res %= M;
            res += M;
            res %= M;
        }
        printf("%lld\n", res);
        //printf("HI");
        return 0;
    }
    int i = sz1 - 1, j = sz2 - 1;
    vector <int> ans;
    for (; i >= 0 && k; i--, k--) {
        ans.pb(pos[i]);
    }
    vector <int> temp;
    if (k) {
        if (k & 1) {
            k++;
            ans.pop_back();
            i++;
        }
        while (k) {
            temp.pb(neg[j]);
            k--;
            j--;
        }
    }
    while (j >= 1) {
        int sz = ans.size();
        if (sz <= 1) break;
        ll hold = (ll)ans[sz-1] * ans[sz-2];
        if (hold < (ll)neg[j] * neg[j-1]) {
            ans.pop_back();
            ans.pop_back();
            temp.pb(neg[j]);
            temp.pb(neg[j-1]);
            j -= 2;
        } else {
            break;
        }
    }
    for (auto x : temp) {
        ans.pb(x);
    }
    ll res = 1;
    for (int i = 0; i < K; i++) {
        res *= ans[i];
        res %= M;
    }
    printf("%lld", res);
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N, K;
  string S;
  cin >> N >> K >> S;
  vector<int> count;
  vector<bool> zero;
  int pos = 0;
  int tmp = 0;
  char before = S[0];
  zero.push_back(S[0] == '0');
  REP(i, N)
  {
    if (S[i] == before)
      tmp++;
    else
    {
      before = S[i];
      count.push_back(tmp);
      tmp = 1;
      zero.push_back(!zero[pos]);
      pos++;
    }
  }
  count.push_back(tmp);
  int ans = 0;
  // 尺取り法
  int left = 0, right = 0;
  int select = 0; // 0の区間を何回選んだか
  int sum = 0;
  for (; left < count.size(); left++)
  {
    while (right < count.size() && select <= K)
    {
      if (zero[right])
      {
        if (select == K)
          break; // 既に0の区間をK個選んでいる
        select++;
      }
      sum += count[right];
      right++;
    }
    ans = max(ans, sum);
    if (left == right)
      right++;
    else
      sum -= count[left];
    if (zero[left])
      select--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>
#include <vector>
#include <cmath>
#include<string>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int func(int n);


int main(){
    int s;
    cin>>s;
    
    if (s % func(s)){
       cout<<"No"<<endl; 
    }else{
       cout<<"Yes"<<endl; 
    }
    
    return 0;

}

int func(int n){
        if (n<10)return n % 10;
        return n %10 + func(n/10);
    }   

Measured memory_bytes: 256
import sys
a = b = c = d = ""
def f(ab, bc, cd):
    return str(a) + ab + str(b) + bc + str(c) + cd + str(d)
if __name__ == '__main__':
    s = list(input())
    a, b, c, d = s[0], s[1], s[2], s[3]
    lst = [f('+', '+', '+'), f('+', '+', '-'), f('+', '-', '+'), f('-', '+', '+'), f('+', '-', '-'), f('-', '+', '-'), f('-', '-', '+'), f('-', '-', '-')]
    for expr in lst:
        if eval(expr) == 7:
            print(expr + "=7")
            sys.exit(0)

Measured memory_bytes: 3064
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
using namespace std;

int main() {
	int N;
	vector<long> D;
	int M;
	vector<long> T;
	cin >> N;
	D.resize(N);
	for (int i = 0; i < N; i++)
	{
		cin >> D[i];
	}
	cin >> M;
	T.resize(M);
	for (int i = 0; i < M; i++)
	{
		cin >> T[i];
	}

	sort(D.begin(), D.end());
	sort(T.begin(), T.end());
	size_t j = 0;
	for (size_t i = 0; i < T.size(); i++)
	{
		for (; j < D.size(); j++)
		{
			if (D[j] == T[i]) {
				break;
			}
		}
		if (j == D.size()) {
			cout << "NO";
			goto END;
		}
		j++;
	}
	cout << "YES";

	END:
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll ans = A * C;
    ans = std::max(A * D, ans);
    ans = std::max(B * C, ans);
    ans = std::max(ans, B * D);

    if ((A <= 0 && 0 <= B) || (C <= 0 && 0 <= D)) {
        ans = std::max(0LL, ans);
    }

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

Measured memory_bytes: 3684