akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 200005;
const int MOD = 2019;

class TaskD {
private:
	Debugger debugger;

	long long pot5(long long x){
		return x * x * x * x * x;
	}
	pair<bool,long long> isRoot(long long x){
		long long p = 0;
		for(long long i = 0; ; i++){
			if(pot5(i) >= x){
				p = i;
				break;
			}
		}
		return {pot5(p) == x, p};
	}
public:
	void solveOne(int it){
		long long x;
		cin >> x;
		for(long long a = 0; pot5(a) <= x; a++){
			for(long long b = 0; pot5(a) + pot5(b) <= x; b++){
				if(pot5(a) + pot5(b) == x){
					cout << a << " "<<-b<<endl;
					return;
				}
			}	
		}
		for(long long a = 0; a == 0 or (pot5(a) - pot5(a-1)) <= x ; a++){
			auto ret = isRoot(pot5(a) - x);
			if(ret.first == true){
				cout << a << " "<<ret.second << endl;
				return;
			}
		}

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3660
import sys
sys.setrecursionlimit(10**9)


n=int(input())

#dpで解く再帰

memo=[-1]*(n+1)
memo[0]=0

def fuck(x):
    #print(x)
    if memo[x]!=-1:
        return memo[x]
    else:
        tmp=10**9
        #6
        i=1
        while 6**i<=x:
            tmp=min(fuck(x-6**i),tmp)
            i+=1
        #9
        i=1
        while 9**i<=x:
            tmp=min(fuck(x-9**i),tmp)
            i+=1
        #1
        tmp=min(tmp,fuck(x-1))
        memo[x]=tmp+1
        #print(x,tmp+1,memo)
        return tmp+1
fuck(n)
#print(memo)
print(memo[-1])





Measured memory_bytes: 63068
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll a[100010];

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

    bool f = 1;

    map<ll, int> mp;
    rep(i, n) mp[a[i]]++;
    if (n%3 != 0) f = 0;
    else{
        if (mp.size() != 3) f = 0;
        else {
            vector<ll> tmp;
            for(auto v : mp){
                if (v.second != n/3) f = 0;
                tmp.push_back(v.first);
            }
            ll x = tmp[0] ^ tmp[1] ^ tmp[2];
            if (x != 0) f = 0;
        }
    }

    if (mp[0] > 0){
        if (mp[0] == n) f = 1;
        else if (n%3 == 0 && mp.size() == 2 && mp[0] == n/3) f = 1;
    }

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

    return 0;
}


Measured memory_bytes: 8936
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  long long n,d,k,s=0;
  cin>>n>>d;
  k=2*d+1;
  s=n/k;
  if(n%k!=0){
      s++;
  }
  cout<<s;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1005
using namespace std;
int n, m;
int a[N][N], b[N][N], c[N][N];
char tmp[N][N];
int main() {
  scanf ("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf ("%s", tmp[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (tmp[i][j] == '#') c[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i & 1) {
      for (int j = 2; j <= m; j++) {
        a[i][j] = 1;
      }
    }
    else {
      a[i][m] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 0) {
      for (int j = 1; j < m; j++) {
        b[i][j] = 1;
      }
    }
    else b[i][1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (i & 1) {
      for (int j = 1; j <= m; j++) {
        if (c[i][j]) {
          b[i][j] = 1;
        }
      }
    }
    else {
      for (int j = 1; j <= m; j++) {
        if (c[i][j]) {
          a[i][j] = 1;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j]) printf("#");
      else printf(".");
    }
    printf("\n");
  }
  puts("");
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (b[i][j]) printf("#");
      else printf(".");
    }
    printf("\n");
  }
  return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

string s[4]={"dream","dreamer","erase","eraser"};

int main(void){
	string t;
	cin >> t;

	
	bool update=true;
	while(update){
		const int tn=t.size();
		if(tn==0) break;
		update=false;
		rep(i,4){
			const int sn=s[i].size();	
			if(sn<=tn and t.substr(tn-sn,sn)==s[i]){
				rep(loop,sn) t.pop_back();
				update=true;
				break;
			}
		}
		//cout << t << endl;
	} 

	if(t.size()==0)
		puts("YES");
	else
		puts("NO");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <math.h>
using namespace std;


int main()
{
	int n;
	string s;
	cin >> n >> s;

	int i, tmp = 0;
	int left = 0, right = 0;
	for (i = 0; i < n; i++) {
		s[i] == '(' ? tmp++ : tmp--;
		if (tmp < 0) {
			tmp = 0;
			left++;
		}
	}
	right = tmp;

	string ans;
	for (i = 0; i < left; i++) ans += '(';
	ans += s;
	for (i = 0; i < right; i++) ans += ')';

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//10進数を2進数に変換_63個の要素を持つ配列
vector<int> Convert10to2(ll n) {
	vector<int> ans(63);
	rep(i, 63) {
		ans[i] = n % 2;
		n -= n % 2;
		n /= 2;
	}
	return ans;
}
//2進数を10進数に変換_63個の要素を持つ配列
ll Convert2to10(vector<int> a) {
	ll ans=0;
	ll j = 1;
	rep(i, a.size()) {
		ans += a[i] * j;
		if (i != a.size() - 1) {
			j *= 2;
		}
	}
	return ans;
}
//XORを計算
vector<int> CalcXOR2to2(vector<int> a, vector<int> b) {
	rep(i, 63) {
		if (a[i] != b[i]) {
			a[i] = 1;
		}
		else {
			a[i] = 0;
		}
	}
	return a;
}

//最大公約数
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a%b);
}

int sum(vector<int> x) {
	int ans = 0;
	rep(i, x.size()) {
		ans += x[i];
	}
	return ans;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> x(8);
	rep(i, m) {
		int a;
		cin >> a;
		if (a == 8) {
			x[7] = 8;
		}
		if (a == 9 || a==6) {
			x[6] = max(x[6], a);
		}
		if (a == 5 || a== 3 || a==2) {
			x[5] = max(x[5], a);
		}
		if (a == 4) {
			x[4] = 4;
		}
		if (a == 7) {
			x[3] = 7;
		}
		if (a == 1) {
			x[2] = 1;
		}
	}
	vector<vector<int>> h(n + 1);
	h[0].resize(10);
	FOR(i,1, n+1) {
		vector<int> z(10);
		rep(j, 8) {
			vector<int> z2(10);
			if (x[j] > 0) {
				if (i - j == 0) {
					z2[x[j]]++;
				}
				else if (i - j > 0 && sum(h[i-j])> 0) {
					z2 = h[i - j];
					z2[x[j]]++;
				}
			}
			if (sum(z) < sum(z2)) {
				z = z2;
			}
			else if (sum(z) == sum(z2)) {
				rrep(k, 10) {
					if (z[k] < z2[k]) {
						z = z2;
					}
					else if (z[k] > z2[k]) {
						break;
					}
				}
			}
		}
		h[i] = z;
	}

	auto ans = h[n];
	rrep(i, 10) {
		rep(j, ans[i]) {
			cout << i;
		}
	}
	cout << endl;

	return 0;
}



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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		cout << (n-1)/2 <<endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	sort(all(a));
	int low = 1, high = N;
	int x = count(all(a), a[0]);
	int y = count(all(a), a[N - 1]);
	high -= (y + 1) / 2;
	low += x;
	dump(low, high);
	bool ng = false;
	if (a[N - 1] - a[0] >= 2) {
		ng = true;
	}
	else if (a[0] < a[N - 1]) {
		if (low > high || low > a[N - 1] || high < a[N - 1])
			ng = true;
	}
	else {
		if (a[0] != N - 1 && a[0] > high) {
			ng = true;
		}
	}
	cout << (ng ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 640
//
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,m,c;
	cin >> n >> m >> c;
	// vector<vector<int>> mat;
	vector<int> b;
	int tmp;
	for (int i = 0; i < m; ++i)
	{
		cin >> tmp;
		b.push_back(tmp);
	}

	int sum = 0;
	int res = 0;
	for (int i = 0; i < n; ++i)
	{
		// mat.push_back(new vector<int>);
		for (int j = 0; j < m; ++j)
		{
			cin >> tmp;
			sum += tmp * b[j];
		}
		sum += c;
		if(sum > 0) res ++;
		sum = 0;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

vector<int> z_algo(string S){
	vector<int> Z(S.size());
	Z[0] = S.size();
    int i = 1, j = 0;
    while(i < S.size()){
        while(i + j < S.size() && S[j] == S[i + j]) j++;
        Z[i] = j;
        if(j == 0) { i++; continue; }
        int k = 1;
        while(i + k < S.size() && k + Z[k] < j){
            Z[i + k] = Z[k];
            k++;
        }
        i += k; j -= k;
    }
	return Z;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<int> z1 = z_algo(s);
    int n = s.length();
    bool ok = true;
    if(z1[1] == n - 1){
    	cout << n << "\n1\n";
    	return 0;
    }
    for(int i=1;i<=n/2;i++){
    	if(n % i == 0 && z1[i] == n - i){
    		ok = false;
    	}
    }
    if(ok){
    	cout << "1\n1\n";
    	return 0;
    }
    bool pre[n]; // [0,i];
    memset(pre,0,sizeof(pre));
    for(int i=1;i<n;i++){
    	int num = z1[i] + i;
    	for(int j=i*2-1;j<num; j += i) pre[j] = true;
    }
    
    ////////
    reverse(be(s));
    vector<int> z2 = z_algo(s);
    bool suf[n];
    memset(suf,0,sizeof(suf));
    for(int i=1;i<n;i++){
    	int num = z2[i] + i;
    	for(int j=i*2-1;j<num; j += i) suf[j] = true;
    }
    ///////
    int ans = 0;
    for(int i=0;i<n-1;i++){
    	if(!pre[i] && !suf[n-i-2]) ans++;
    }
    printf("2\n%d\n",ans);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll H, W;
    cin >> H >> W;
    //if(H%3==0 || W%3==0){
    //    cout<<0<<endl;
    //    return 0;
    //}
    ll res = LLONG_MAX;
    for(int i=0;i<H;i++){
        auto v1 = i*W;
        auto v2 = (H-i)*(W/2);
        auto v3 = (H-i)*(W-(W/2));
        auto vmin = min(v1, min(v2, v3));
        auto vmax = max(v1, max(v2, v3));
        auto diff = vmax - vmin;
        if(diff<res) res = diff;
    }
    for(int i=0;i<W;i++){
        auto v1 = i*H;
        auto v2 = (W-i)*(H/2);
        auto v3 = (W-i)*(H-(H/2));
        auto vmin = min(v1, min(v2, v3));
        auto vmax = max(v1, max(v2, v3));
        auto diff = vmax - vmin;
        if(diff<res) res = diff;
    }
    {
        auto v1 = (H/3) * W;
        auto v2 = (2*H/3 - H/3) * W;
        auto v3 = (H - 2*H/3) * W;
        auto vmin = min(v1, min(v2, v3));
        auto vmax = max(v1, max(v2, v3));
        auto diff = vmax - vmin;
        if(diff<res) res = diff;
    }
    {
        auto v1 = (W/3) * H;
        auto v2 = (2*W/3 - W/3) * H;
        auto v3 = (W - 2*W/3) * H;
        auto vmin = min(v1, min(v2, v3));
        auto vmax = max(v1, max(v2, v3));
        auto diff = vmax - vmin;
        if(diff<res) res = diff;
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 200000 + 5;

class TaskC {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		double hourSize, minuteSize;
		cin >> hourSize >> minuteSize;
		double h, m;
		cin >> h >> m;
		double ang = abs(h + m/60 - m/5) * 30;
		ang = min(ang, 360 - ang);
		double PI = acos(-1);
		ang = ang * PI / 180;
		double distance = hourSize * hourSize + minuteSize * minuteSize - 2 * hourSize * minuteSize * cos(ang);
		distance = sqrt(distance);
		
		cout<<setprecision(10) << distance << endl;
		
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


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

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

    int sub[n+1];
    memset(sub, 0, sizeof(sub));
    for(int i=0; i<n-1; i++) {
        sub[a[i]]++;
    }
    for(int i=1; i<=n; i++) {
        cout << sub[i] << "\n";
    }
}

Measured memory_bytes: 5188
//Dragon_warrior7(IITK)
// #pragma GCC optimize("O0") 
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define vll vector<ll>
#define rub cerr << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
inline void read(vector<ll> &v);
inline ll max(ll a,ll b);
inline ll min(ll a,ll b);
inline ll gcd(ll a ,ll b);
void storepowers(int n,vector<int> &a);
#define debug 0
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{if(debug)cout<<"Case #"<<test<<':'<<'\n';
cin>>n;
map<ll,ll> mp;
ll ans=0;
for(int i=1;i<=n;i++)
{
    cin>>temp;
    ll needed=i-temp;
    ans+=mp[needed];
    //cout<<i<<' '<<ans<<'\n';
    mp[temp+i]++;
}
cout<<ans;
if(debug)cout<<'\n';
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
 	//cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}
void storepowers(int n,vector<int> &a)
{
    a.resize(n+1);
    a[0]=1;
    for(int i=1;i<=n;i++)
    a[i]=a[i-1]*2;
    return ;
}
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
inline void read(vector<ll> &v)
{for (int i = 0; i < v.size(); i++)cin>>v[i];}


Measured memory_bytes: 26288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

ll dp[3010][3010][5];

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll r,c,k;
	cin>>r>>c>>k;
	vector<vector<ll>> g(r+10,vector<ll>(c+10,0));
	rep(i,k){
		ll x,y,v;
		cin>>x>>y>>v;
		g[x][y]=v;
	}
	rep(i,3010)rep(j,3010)rep(k,5) dp[i][j][k]=-1;
	dp[1][1][0]=0;
	if(g[1][1]){
		dp[1][1][1]=g[1][1];
	}
	rep(i,r+1)rep(j,c+1)rep(k,4){
		if(dp[i][j][k]==-1) continue;
		chmax(dp[i+1][j][0],dp[i][j][k]);
		chmax(dp[i][j+1][k],dp[i][j][k]);
		if(g[i+1][j]){
			chmax(dp[i+1][j][1],dp[i][j][k]+g[i+1][j]);
		}
		if(g[i][j+1] && k<3){
			chmax(dp[i][j+1][k+1],dp[i][j][k]+g[i][j+1]);
		}
	}
	ll ans=0;
	rep(k,4){
		chmax(ans,dp[r][c][k]);
	}
	cout<<ans<<endl;
}

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

using ll = long long;
using p = pair<string, int>;

int main()
{
    int n, max_cnt = 0;
    cin >> n;
    
    map<string, int> m;
    set<string> set;

    string tmp;
    for(int i = 0; i < n; ++i)
    {
        cin >> tmp;
        m[tmp]++;
        max_cnt = max(m[tmp], max_cnt);
    }

    for(auto &i: m)
    {
        if(i.second == max_cnt)
            cout << i.first << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 19180
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

vector<ll> a;
vector<ll> p;

ll f(int n, ll x) {
    if (n == 0) return 1;
    if (x == 1) return 0;
    if (x <= a[n-1]+1) return f(n-1,x-1);
    if (x == a[n-1]+2) return p[n-1]+1;
    if (x <= 2*a[n-1]+2) return p[n-1]+1+f(n-1,x-a[n-1]-2);
    if (x == 2*a[n-1]+3) return 2*p[n-1]+1;
}

int main() {
    int n;
    ll x;
    cin >> n >> x;
    a.resize(n+1);
    a[0] = 1;
    rep(i,n) {
        a[i+1] = a[i]*2+3;
    }
    p.resize(n+1);
    p[0] = 1;
    rep(i,n) {
        p[i+1] = p[i]*2+1;
    }
    ll ans = f(n,x);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
n = int(input())
A = [int(i) for i in input().split()]
dp = [0] * n

dp[1] = abs(A[0] - A[1])
for i in range(2, n):
    dp[i] = min(abs(A[i-2] - A[i]) + dp[i-2], abs(A[i-1] - A[i]) + dp[i-1])
    
print(dp[-1])

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

using namespace std;

using VecPair = vector<pair<int, int>>;

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

	VecPair items(N);

	for (int i = 0; i < N; i++) {
		cin >> items[i].first >> items[i].second;
	}

	vector<vector<int>> matrix(N + 1, vector<int>(W + 1));

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			if (!(i && j)) matrix[i][j] = 0;
			else if(j >= items[i - 1].second) matrix[i][j] = max(matrix[i - 1][j], matrix[i - 1][j - items[i - 1].second] + items[i - 1].first);
		    else matrix[i][j] = matrix[i - 1][j];
        }
	}

	cout << matrix[N][W] << endl;
    
    for (int i = 0; i < N + 1; i++) {
		for (int j = 0; j < W + 1; j++) {
			//cout << matrix[i][j] << " ";
        }
       // cout << endl;
	}

	return 0;
}


Measured memory_bytes: 6812
#include<bits/stdc++.h>
using namespace std;
char s;
long long int ans=0,ansn=0,n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        if(s=='I') ansn++;
        else if(s=='D') ansn--;
        ans=max(ans,ansn);
    }
    cout<<ans;
    return 0;
}

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

int main(){
    string s, ans = "AC";
    cin >> s;
    
    int count = 0;
    
    if (s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    
    if (!(islower(s[1]))) {
        cout << "WA" << endl;
        return 0;
    }
    
    if (!(islower(s[s.size() - 1]))) {
        cout << "WA" << endl;
        return 0;
    }
    
    for (int i = 2; i < s.size() - 1; i++) {
        if (s[i] == 'C') {
            count++;
        } else if (!(islower(s[i]))) {
            ans = "WA";
            break;
        }
    }
    
    if (count != 1) {
        ans = "WA";
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        int num1 = scan.nextInt();
        int num2 = scan.nextInt();

        if((num1 * num2) % 2 == 0) {
          System.out.println("Even");
        }else {
          System.out.println("Odd");
        }
        
      }
}

Measured memory_bytes: 23124
# D - Road to Millionaire


def million(n, a):
    wallet = 1000
    i = 0
    while i < n - 1:
        highest_price = a[i]
        cheapest_price = a[i]
        # 直近の最高値と最安値を取得する
        for j in range(i + 1, n):
            if highest_price > a[j]:
                break
            if highest_price < a[j]:
                highest_price = a[j]
            if cheapest_price > a[j]:
                cheapest_price = a[j]
        if highest_price > cheapest_price:
            # 取引する
            stock = wallet // cheapest_price
            wallet = wallet - stock * cheapest_price
            wallet = wallet + stock * highest_price
            i = j
        else:
            i += 1
    return wallet


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    print(million(n, a))


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

vector<vector<int>> T, U;
vector<bool> check;
set<int> Ts, Us;

void dfs(int i) {
    if (check[i]) return;
    check[i] = true;
    for (auto j : T[i]) {
        Ts.insert(j);
        if (!check[j]) dfs(j);
    }
    for (auto j : U[i]) {
        Us.insert(j);
    }
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    T.resize(N), U.resize(N), check.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        for (int j = 0; j < A[i]; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            if (y == 1)
                T[i].push_back(x);
            else
                U[i].push_back(x);
        }
    }

    int ret = 0;
    for (int i = 0; i < 1 << N; i++) {
        for (int j = 0; j < N; j++) check[j] = false;
        Ts.clear(), Us.clear();
        for (int j = 0; j < N; j++) {
            if (i & (1 << j)) {
                dfs(j);
                Ts.insert(j);
            }
        }
        int cnt = 0;
        for (auto a : Ts) {
            if (find(Us.begin(), Us.end(), a) != Us.end()) {
                cnt = 0;
                break;
            }
            cnt++;
        }
        ret = max(ret, cnt);
    }


    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // 

    // freopen("output.out", "w", stdout);

    int n; cin >> n;
    cout << (n == 0 ? "1" : "0");

    return 0;
}

Measured memory_bytes: 3620
K, X = map(int, input().split())
lim = 1000000
ans = []
if K + X -1 < lim and X -K + 1 > -lim:
  for i in range(X-K+1, K+X):
    ans.append(i)
elif K + X -1 < lim and X - K + 1 < -lim:
  for i in range(-lim, K+X):
    ans.append(i)
elif K + X -1 > lim and X - K + 1 > -lim:
  for i in range(X-K+1, lim):
    ans.append(i)
else:
  for i in range(-lim, lim):
    ans.append(i)
print(*ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>

using namespace std;

const int MOD = 1000000007;

long long solve(const string& S){
    vector<long long> dp(54, 0);
    dp[0] = 1;
    for(auto& c : S){
        vector<long long> next(54, 0);
        for(int has1=0;has1<2;has1++){
            for(int lead0=0;lead0<3;lead0++){
                for(int trail0=0;trail0<3;trail0++){
                    for(int sec1=0;sec1<3;sec1++){
                        int idx =  ((has1 * 3 + lead0) * 3 + trail0) * 3 + sec1;
                        if(c == '0' || c == '?'){
                            if(!has1){
                                int nlead0 = (lead0 == 2 ? 1 : lead0+1);
                                next[((has1 * 3 + nlead0) * 3 + trail0) * 3 + sec1] += dp[idx];
                            } else {
                                int ntrail0 = (trail0 == 2 ? 1 : trail0+1);
                                next[((has1 * 3 + lead0) * 3 + ntrail0) * 3 + sec1] += dp[idx];
                            }
                        }
                        if(c == '1' || c == '?'){
                            if(!has1){
                                next[((3 + lead0) * 3 + trail0) * 3 + sec1] += dp[idx];
                            } else {
                                if(lead0 == 0){
                                    if(trail0 == 0){
                                        next[((has1 * 3 + lead0) * 3 + trail0) * 3 + min(sec1+1, 2)] += dp[idx];
                                    } else {
                                        next[((has1 * 3 + lead0) * 3 + trail0 - 1) * 3 + sec1] += dp[idx];
                                    }
                                } else {
                                    if(trail0 == 0){
                                        next[((has1 * 3 + lead0 - 1) * 3 + trail0) * 3 + sec1] += dp[idx];
                                    } else if(trail0 == 1) {
                                        next[((has1 * 3 + lead0) * 3 + 0) * 3 + sec1] += dp[idx];
                                    } else {
                                        next[((has1 * 3 + 3 - lead0) * 3 + 0) * 3 + sec1] += dp[idx];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for(auto& t : next) t %= MOD;
        dp = next;
    }
    long long res = 0;
    for(int trail0=0;trail0<3;trail0++){
        for(int sec1=trail0;sec1<3;sec1++){
            int idx =  27 + 3 * trail0 + sec1;
            res = (res + dp[idx]) % MOD;
        }
    }
    return res;
}

int main(){
    string S; cin >> S;
    cout << solve(S) << endl;
}

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

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

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

    bool is_rising = false;
    long long money = 1000;
    long long stock = 0;
    // if (As[0] < As[1])
    // {
    //     stock = money / As[0];
    //     money -= As[0] * stock;
    //     is_rising = true;
    // }
    for (int i = 0; i < N - 1; i++)
    {
        if (i == 0)
        {
            if (As[0] < As[1])
            {
                stock = money / As[0];
                money -= As[0] * stock;
                is_rising = true;
            }
        }
        else
        {
            if (is_rising)
            {
                if (As[i] > As[i + 1]) // 上昇から下降の時
                {
                    // 全て売る
                    money += As[i] * stock;
                    stock = 0;
                    is_rising = false;
                }
            }
            else
            {
                if (As[i] < As[i + 1]) // 下降から上昇の時
                {
                    // できるだけ買う
                    stock = money / As[i];
                    money -= As[i] * stock;
                    is_rising = true;
                }
            }
        }

        if (i + 1 == N - 1) // 最後の時
        {
            // 全て売る
            money += As[i + 1] * stock;
            stock = 0;
        }
        // cout << "i=" << i << "のとき" << money << endl;
    }

    cout << money << endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<string>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  vector<int> broken(n+1);
  rep(i,m) {
    int a;
    cin >> a;
    broken[a] = 1;
  }
  vector<int> dp(n+2);
  const int mod = 1000000007;
  dp[n] = 1;
  for (int i=n-1; i>=0; i--) {
    if (broken[i]) {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i+1] + dp[i+2]) % mod;
  }
  cout << dp[0] << endl;
}
  

Measured memory_bytes: 1024
class Q1043
#  def bubble
  def makeTeam n,team
    ary = Array.new(n)
    for i in 0..n-1
      s = gets.split(" ").map {|x| x.to_i}
      ary[i] = team.new(s[0], s[1], s[2], s[3])
    end
    ary = ary.sort{|a, b| (b.a == a.a) ? ((b.p == a.p) ? a.i <=> b.i : a.p <=> b.p) : b.a <=> a.a }
    #ary[1] = 2
    mem = Array.new(1001, 0)
    sum = 0
    for i in 0..n-1
      if sum < 10 then 
        if mem[ary[i].u] < 3 then
          sum += 1
          mem[ary[i].u] += 1
          puts ary[i].i
        end
      elsif sum < 20 then
        if mem[ary[i].u] < 2 then
          sum += 1
          mem[ary[i].u] += 1
          puts ary[i].i
        end
      elsif sum < 26 then
        if mem[ary[i].u] < 1 then
          sum += 1
          mem[ary[i].u] += 1
          puts ary[i].i
        end
      end
    end
  end
  
  def doIt
    n = gets.to_i
    team = Struct.new("Team", :i, :u, :a, :p)
    while n > 0
      makeTeam n,team
      n = gets.to_i
    end
  end
end

Q1043.new.doIt

Measured memory_bytes: 2496
N = int(input())
A = [0] + sorted(map(int,input().split()))

def check(i,A):
    a = sum(A[:i+1])
    for b in A[i+1:]:
        if a*2>=b:
            a += b
        else:return False
    return True

def binary_search(A,func):
    l = 0
    r = len(A)
    if func(0,A):return -1
    if not func(r,A):return r
    while l+1<r:
        i = (l+r)//2
        if func(i,A):
            r = i
        else:
            l = i
    return l

l = binary_search(A,check)
print(N-l)

Measured memory_bytes: 14308
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>

// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

inline bool chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

inline bool chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//桁数取得
template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}
//整数乗
ll llpow(ll a, ll n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        ll rep = a;
        for (ll i = 1; i < n; i++)
        {
            rep *= a;
        }
        return rep;
    }
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

template <typename T>
T amarinasi(T a, T b)
{
    if (a % b == 0)
    {
        return a / b;
    }
    else if (a % b > 0)
    {
        return a / b + 1;
    }
    else
    {
        return a / b - 1;
    }
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------
const double pi = 3.14159265358979323846264;

//素数列挙longlong型配列
std::vector<ll> sosuurekkyo(ll max)
{
    vector<bool> tmp;
    vector<ll> ret;
    if (max + 1 > tmp.size())
    {                              // resizeで要素数が減らないように
        tmp.resize(max + 1, true); // IsPrimeに必要な要素数を確保
    }
    tmp[0] = false; // 0は素数ではない
    tmp[1] = false; // 1は素数ではない

    for (ll i = 2; i * i <= max; ++i)
    { // 0からsqrt(max)まで調べる
        if (tmp[i])
        { // iが素数ならば
            for (ll j = 2; i * j <= max; ++j)
            {                       // (max以下の)iの倍数は
                tmp[i * j] = false; // 素数ではない
            }
        }
    }
    for (ll i = 0; i <= max; i++)
    {
        if (tmp[i])
        {
            ret.push_back(i);
        }
    }
    return (ret);
}

int main()
{
    ll n;
    cin >> n;
    ll cnt = 0;
    for (auto f : sosuurekkyo(5000000))
    {
        if (f == 2)
        {
            continue;
        }
        if (f % 5 != 1)
        {
            continue;
        }
        cout << f << " ";
        cnt++;
        if (cnt == n)
        {
            break;
        }
    }
    cout << endl;
}

Measured memory_bytes: 8076
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N,A[100000],i,x;
  cin>>N;
  x=N;
  for(i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A,A+N);
  for(i=0;i<N-1;i++){
    if(A[i]==A[i+1]){
      x=x-2;
      i++;
    }
  }
  cout<<x<<endl;
  
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long ans,n,a[101010],b[101010];
int main()
{
	cin>>n;
	for(int i=0;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		if(b[i]>a[i])
		{
			ans+=a[i];
			b[i]-=a[i];
			a[i]=0;
			if(b[i]>a[i+1])
			{
				ans+=a[i+1];
				b[i]-=a[i+1];
				a[i+1]=0;
			}
			else
			{
				ans+=b[i];
				a[i+1]-=b[i];
				b[i]=0;
			}
		}
		else
		{
			ans+=b[i];
			a[i]-=b[i];
			b[i]=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int m = max(a,max(b,c));
    if (a+b+c-m==m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

ll N;
ll L[200];

int main() {
  //
  cin >> N;
  rep(i, 0, N) { cin >> L[i]; }

  ll ans = 0;
  rep(i, 0, N - 2) {
    rep(j, i + 1, N - 1) {
      rep(k, j + 1, N) {
        ll li = L[i];
        ll lj = L[j];
        ll lk = L[k];
        if (li == lj || lj == lk || lk == li) {
          continue;
        }

        if (li < lj + lk && lj < lk + li && lk < li + lj) {
          ++ans;
        }
      }
    }
  }

  cout << ans;
}


Measured memory_bytes: 3620
import scala.io.StdIn

object Main extends App {

  val Array(n, k) = StdIn.readLine().trim.split(' ').map(_.toInt)
  val list = (0 until n).map{ _ => StdIn.readLine().trim.toLong}.toVector
    
  def judge(p: Long): Long = {
    var i = 0
    var j = 0
    while(j < k){
      var c = 0L
      while(i < n && c + list(i) <= p){
        c += list(i)
        i += 1
      }
      j = if(i == n) k else j + 1
    }
    i
  }

  var left: Long = 0
  var right: Long = 100000 * 10000
  var mid: Long  = 0

  while(right - left > 1){
    mid = (left + right) / 2
    val v = judge(mid)
    if(v >= n){
      right = mid
    } else {
      left = mid
    }
  }

  println(right)

}


Measured memory_bytes: 61608
def main():
    n, a, b, c, d = map(int, raw_input().split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = raw_input()
    ok = False
    while b < d:
        if s[b - 1] == '.' and s[b + 1] == '.':
            ok = True
        if s[b + 1] == '.':
            b += 1
        elif b + 2 < n and s[b + 2] == '.':
            b += 2
        else:
            break
    if b != d:
        print 'No'
        return
    if b + 1 < n and s[b - 1] == '.' and s[b + 1] == '.':
        ok = True
    while a < c:
        if s[a + 1] == '.':
            a += 1
        elif a + 2 < n and s[a + 2] == '.':
            a += 2
        else:
            break
    if a != c:
        print 'No'
    elif c < d or ok:
        print 'Yes'
    else:
        print 'No'


if __name__ == '__main__':
    main()


Measured memory_bytes: 33004
#include <stdio.h>

int main() {
    int i, n, x, xmin = 2000, xmax = 0;
    scanf("%d", &n);

    for ( i=0; i<n; ++i ) {
	scanf("%d", &x);
	if ( x < xmin ) xmin = x;
	if ( x > xmax ) xmax = x;
    }

    printf("%d\n", xmax - (xmin + xmax)/2);
    return 0;
}



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


int main(){
    string s;
    cin>>s;
    if(s=="AAA") cout<<"No"<<endl;
    else if(s=="BBB") cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp13
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 1;
            while (true)
            {
                int b;
                b = int.Parse(Console.ReadLine());
                
                if (b == 0)
                {
                    break;
                }
                Console.WriteLine("Case {0}: {1}", a, b);
                a++;
            }
        }
    }
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int n;
	cin >> n;
 
	double p[n];
	rep(i, n) cin >> p[i];
 
	double dp[n+1][n+1];
	rep(i, n+1) rep(j, n+1) dp[i][j] = 0.0;
	// dp[i][j] : コインをi枚使い、表がj枚である確率
 
	dp[0][0] = 1.0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= i; j++){
			if(j-1 >= 0) dp[i][j] = dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1.0 - p[i-1]);
			else dp[i][j] = dp[i-1][j] * (1.0 - p[i-1]);
		}
	}
 
	double ans = 0.0;
	for(int i = n / 2 + 1; i <= n; i++) ans += dp[n][i];
	cout << fixed << setprecision(11) << ans << endl;
}

Measured memory_bytes: 70656
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    internal static void Main(string[] args) {
        int N = int.Parse(ReadLine());
        var a = ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
        var dic = new Dictionary<int, int>();

        for (int i = 0; i < 100000; i++) {
            dic.Add(i, 0);
        }

        for (int i = 0; i < N; i++) {
            dic[a[i]]++;
        }

        var cnt = 0;
        var values = dic.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Value).ToArray();

        for (int i = 0; i < 99998; i++) {
            var sum = values[i] + values[i + 1] + values[i + 2];
            cnt = Math.Max(sum, cnt);
        }

        WriteLine(cnt);
    }
}

Measured memory_bytes: 26976
import sys
def s():
 n,k=map(int,input().split())
 w=list(map(int,sys.stdin.readlines()))
 def f():
  c=t=0
  for j in w:
   t+=j
   if t>m:
    t=j
    c+=1
    if c>=k:return 0
  return 1
 l,r=max(w),sum(w)
 while l<r:
  m=(l+r)//2
  if f():r=m
  else:l=m+1
 print(r)
if'__main__'==__name__:s()


Measured memory_bytes: 15824
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int d; cin >> d;
    cout << "Christmas";
    for (int i = d; i < 25; i++)
    {
        cout << " Eve";
    }
    cout << endl;
    return 0;
}

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 = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		int wa = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			wa += A[i];
		}
		sc.close();
		// Arrays.sort(A);
		double nov = (double)wa / (4 * M);
		int ok = 0;
		for(int i = N - 1; i >= 0; i--) {
			ok += A[i] >= nov ? 1 : 0;
			// System.out.println(ok + " " + A[i] + " " + nov);
		}
		System.out.println(ok >= M ? "Yes" : "No");
	}
}



Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    double L;
    cin >> L;
    printf("%.10lf", (L / 3) * (L / 3) * (L / 3));
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   int A,B;
   scanf("%d %d",&A,&B);
   if(A>=13)
   {
   	printf("%d\n",B);
   }
   else if(A<13 && A>5)
   {
   	B=B*0.5;
   	printf("%d\n",B);
   }
   else
    printf("0\n");
   
   return 0;
}

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

int main() {
	int n, m; scanf("%d%d", &n, &m);
	ll a = 0, b = 0;
	rep(i, n) {
		ll x; scanf("%lld", &x);
		(a += x*(i - (n - i - 1))) %= MOD;
	}
	rep(i, m) {
		ll y; scanf("%lld", &y);
		(b += y*(i - (m - i - 1))) %= MOD;
	}
	printf("%lld\n", (a * b) % MOD);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forit(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define REP(i,f,t) for(int i=f;i<(int)t;++i)
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int inf = 1e9+5;

int n,k,i,j;
int main(){
	fast_io;
	cin >> n;
	vector<vector<ll>> dp(n,vector<ll>(n));
	vector<ll> a(n);
	for(ll &x : a)cin>>x;
	for(int L = n - 1; L>=0;--L){
        for(int R = L; R<n;++R){
            if(L==R)dp[L][R]=a[L];
            else{
                dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
            }
        }
	}
	cout << dp[0][n-1];
}


Measured memory_bytes: 70656