akhauriyash/Code-Regression huggingface dataset:
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    auto S = sread();
    foreach (x; 0 .. 1 << 4)
    {
        auto a = "A";
        auto s = format("%sKIH%sB%sR%s", a[0 .. (x & (1 << 0)) >> 0],
                a[0 .. (x & (1 << 1)) >> 1], a[0 .. (x & (1 << 2)) >> 2], a[0 .. (x & (1 << 3)) >> 3]);
        if (S == s)
        {
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static System.Math;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int A,B,C,D,E,F;
       

        public static void Input()
        {
            var cin = new Solve();
            var input = cin.SplitReader();
            A = input[0];
            B = input[1];
            C = input[2];
            D = input[3];
            E = input[4];
            F = input[5];
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            int ans1 = 0;
            int ans2 = 0;
            double max = 0;
            List<int> mizu = new List<int>();
            List<int> sato = new List<int>();
            for (var i = 0; i <= F / (100 * A); i++) 
            {
                for (var j = 0; j <= F / 100 * B; j++) 
                {
                    if (i == 0 && j == 0) { continue; }
                    if (100 * i * A + 100 * j * B <= F) 
                    {
                        mizu.Add(100 * i * A + 100 * j * B);
                    }
                }
            }

            for (var i = 0; i <= F / C; i++) 
            {
                for (var j = 0; j <= F / D; j++) 
                {
                    
                    if (i * C + j * D <= F)
                    {
                        sato.Add(i * C + j * D);
                    }
                }
            }

            foreach(var x in mizu)
            {
                foreach(var y in sato)
                {
                    if (x + y <= F && y <= (x / 100) * E)
                    {
                        double c = (double)y / (x + y);
                        if (c >= max)
                        {
                            max = c;
                            ans1 = x + y;
                            ans2 = y;
                        }
                    }
                }
            }


            Console.WriteLine($"{ans1} {ans2}");

            //Console.Out.Flush();
        }

        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }
}

    



Measured memory_bytes: 13320
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;

const int D_MAX_V = 1010;
const int D_v_size = 1010;
struct D_wolf {
	int t, c, r;
	D_wolf() { t = c = r = 0; }
	D_wolf(int t1, int c1, int r1) {
		t = t1; c = c1; r = r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from, int to, int cap) {
	D_G[from].push_back(D_wolf(to, cap, D_G[to].size()));
	D_G[to].push_back(D_wolf(from, 0, D_G[from].size() - 1));
}
void D_bfs(int s) {
	for(int i = 0; i < D_v_size; i++)D_level[i] = -1;
	queue<int> Q;
	D_level[s] = 0;
	Q.push(s);
	while(Q.size()) {
		int v = Q.front();
		Q.pop();
		for(int i = 0; i < D_G[v].size(); i++) {
			if(D_G[v][i].c>0 && D_level[D_G[v][i].t] < 0) {
				D_level[D_G[v][i].t] = D_level[v] + 1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v, int t, int f) {
	if(v == t)return f;
	for(; D_iter[v] < D_G[v].size(); D_iter[v]++) {
		int i = D_iter[v];
		if(D_G[v][i].c>0 && D_level[v] < D_level[D_G[v][i].t]) {
			int d = D_dfs(D_G[v][i].t, t, min(f, D_G[v][i].c));
			if(d > 0) {
				D_G[v][i].c -= d;
				D_G[D_G[v][i].t][D_G[v][i].r].c += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for(;;) {
		D_bfs(s);
		if(D_level[t] < 0)return flow;
		for(int i = 0; i < D_v_size; i++)D_iter[i] = 0;
		int f;
		while((f = D_dfs(s, t, 99999999))>0) { flow += f; }
	}
	return 0;
}
int W, H;
int toV(int i, int j) {
	return W * i + j;
}

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

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

	int Test;
	cin >> Test;
	for(int t = 1; t <= Test; t++) {
		cin >> W >> H;
		int r[20][20];
		int sum = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> r[i][j];
				sum += r[i][j];
			}
		}

		for(int i = 0; i < H * W + 2; i++) {
			D_G[i].clear();
			D_level[i] = D_iter[i] = 0;
		}

		int S = H * W, T = S + 1;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if((i + j) % 2 == 0) {
					add_edge(S, toV(i, j), r[i][j]);
					add_edge(toV(i, j), T, 0);
					for(int k = 0; k < 4; k++) {
						int ni = i + dy[k], nj = j + dx[k];
						if(ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
						add_edge(toV(i, j), toV(ni, nj), 1e9);
					}
				}
				else {
					add_edge(S, toV(i, j), 0);
					add_edge(toV(i, j), T, r[i][j]);
				}
			}
		}

		cout << "Case " << t << ": " << sum - max_flow(S, T) << endl;
	}

}

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

#define ucin ios::sync_with_stdio(0), cin.tie(0)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int qpow(int a, int b) {
	int ans = 1;
	for(; b >= 1; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) ans = (ll) ans * a % mod;
	return ans;
}
char s[N]; 
bool ok(int l, int r) {
	for(int i = l; i <= r; i ++)
		if(s[i] != s[r - i + 1]) return 0;
	return 1;
}
int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	puts(ok(1, n) && ok(1, (n - 1) / 2) && ok((n + 3) / 2, n) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left

A, B, Q = map(int, sys.stdin.readline().split())
S = []
for _ in range(A):
    S.append(int(sys.stdin.readline()))
T = []
for _ in range(B):
    T.append(int(sys.stdin.readline()))

# S.sort()
# T.sort()
for _ in range(Q):
    x = int(sys.stdin.readline())

    #print("x", x)
    # 前後の神社、寺の距離を求める
    s_pos = bisect_left(S, x)
    if s_pos == 0:
        s_left = -float("inf")
    else:
        s_left = S[s_pos-1]
    if s_pos == A:
        s_right = float("inf")
    else:
        s_right = S[s_pos]
    #print("s", s_left, s_right)

    t_pos = bisect_left(T, x)
    if t_pos == 0:
        t_left = -float("inf")
    else:
        t_left = T[t_pos-1]
    if t_pos == B:
        t_right = float("inf")
    else:
        t_right = T[t_pos]
    #print("t", t_left, t_right)

    left_min = min(x - s_left, x - t_left)
    left_max = max(x - s_left, x - t_left)
    right_min = min(s_right - x, t_right - x)
    right_max = max(s_right - x, t_right - x)
    print(min(left_max, right_max,
                2 * (x - s_left) + (t_right - x), 2 * (x - t_left) + (s_right - x),
                2 * (t_right - x) + (x - s_left), 2 * (s_right - x) + (x - t_left)))

Measured memory_bytes: 105080
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char str[101],answer[101];
    gets(str);
    int lens=strlen(str),i,lena=0;
    for(i=0;i<lens;i++)
        switch(str[i])
        {
            case '0':answer[lena]='0';lena++;break;
            case '1':answer[lena]='1';lena++;break;
            case 'B':if(lena!=0) lena--;break;
        }
    for(i=0;i<lena;i++)
        printf("%c",answer[i]);
    printf("\n");
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
long long int Max(long long int a,long long int b){
    if(a>=b)return a;
    else return b;
}
long long int comb(long long int n,long long int r){
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
    long long int i,j;
    rep(i,0,n+1){
        v.at(i).at(0)=1;
        v.at(i).at(i)=1;
    }
    rep(i,0,n+1){
        rep(j,0,i)v.at(i).at(j)=v.at(i-1).at(j-1)+v.at(i-1).at(j);
    }
    return v.at(n).at(r);
}
int main(void){
    long long int H,i=0,ans=0;
    cin>>H;
    while(H>1){
        H/=2;
        i++;
    }
    ans=pow(2,i+1)-1;
    cout<<ans<<endl;
}

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

using namespace std;

#define INF 1<<30
#define LINF 1ll<<60ll
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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(a>b){a=b;return true;}return false;}

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)

ll gcd(ll a,ll b){ // log N
    while((a%=b)&&(b%=a));
    return a+b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

ll maxim(ll a,ll b){ // b以下でaの倍数の最大をもとめる
    return (b/a)*a;
}

int main(){
    int t;
    ll a,b,c,d;
    ll min;
    cin>>t;
    REP(counter,t){
        cin>>a>>b>>c>>d;
        if(a<b){ // もともと足りないね
            cout<<"No"<<endl;
            continue;
        }
        if(d<b){ // 供給過少
            cout<<"No"<<endl;
            continue;
        }
        min=a-maxim(gcd(b,d),a+b-c-1);
        //cout<<min<<endl;
        if(min+d<b){ // 追加しても足りない
            cout<<"No"<<endl;
            continue;
        }
        if(min<d&&min>c){ // 追加できない…
            cout<<"No"<<endl;
            continue;
        }
        if(min<0)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
        //cout<<"Yes"<<endl; // それ以外
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> m(H + 1, vector<char>(W + 1, '#'));
  REP(i, H) {
    REP(j, W) {
      cin >> m[i][j];
    }
  }

  vector<vector<int>> Wid(H, vector<int>(W));
  vector<vector<int>> Hei(H, vector<int>(W));

  int tmp = 0;
  int start;
  REP(i, H) REP(j, W){
    if (m[i][j] == '#') {
      Wid[i][j] = -1;
      continue;
    }
    start = j;
    while(m[i][j] != '#') j++;
    for(int cnt = start; cnt < j; cnt++) Wid[i][cnt] = j - start;
  }
  REP(j, W) REP(i, H){
    if (m[i][j] == '#') {
      Hei[i][j] = -1;
      continue;
    }
    start = i;
    while(m[i][j] != '#') i++;
    for(int cnt = start; cnt < i; cnt++) Hei[cnt][j] = i - start;
  }

  int mmax = 0;
  REP(i, H) REP(j, W){
    if (m[i][j] != '#'){
      mmax = max(mmax, Wid[i][j] + Hei[i][j]);
    }
  }

  // REP(i, H) {
  //   REP(j, W) cout << Wid[i][j];
  //   cout << endl;
  // }
  cout << (mmax - 1) << endl;

  return 0;
}


Measured memory_bytes: 35712
from bisect import bisect_right

N,M,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
B = [0]+list(map(int,input().split()))
for i in range(1,N+1,1):
    A[i]=A[i-1]+A[i]
for i in range(1,M+1,1):
    B[i]=B[i-1]+B[i]

ans = 0
for i in range(0,N+1,1):
    j = bisect_right(B,K-A[i])-1
    if K-A[i]>=0:
        ans = max(ans,i+j)
print(ans)

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

using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int

#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define mod 998244353
ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}

vvi bit;//1-based indexing
void bit_updatey(ll x,ll y,ll m,ll val)
{
    while(y<m)
    {
        bit[x][y]+=val;
        y+=(y&(~y+1));
    }
}
void bit_update(ll x,ll y,ll m,ll val)
{
    while(x<m)
    {

        bit_updatey(x,y,m,val);
        x+=(x&(~x+1));
    }
}


ll bit_sum(ll x,ll y)
{
    ll s=0;
    ll y1=y;
    while(x>0)
    {
        y=y1;
        while(y>0)
         {
            s+=(bit[x][y]);
            y-=(y&(~y+1));
        }
        x-=(x&(~x+1));
    }
    return s;
}
ll query(ll a,ll b,ll c,ll d)
{
    ll x1=min(a,c);
    ll y1=min(b,d);
    ll x2=max(a,c);
    ll y2=max(b,d);
    return bit_sum(x2,y2)-bit_sum(x1-1,y2)-bit_sum(x2,y1-1)+bit_sum(x1-1,y1-1);
}
int main()
{

ll r,h;
cin>>r>>h;
vector<vector<char>>g(r,vector<char>(h));
rep(i,0,r)
{
    rep(j,0,h)cin>>g[i][j];
}
vvi dp(r,vi(h,INT_MAX));
if(g[r-1][h-1]=='#')dp[r-1][h-1]=1;
else dp[r-1][h-1]=0;
repr(i,r-1,-1)
{
    repr(j,h-1,-1)
    {
        if(g[i][j]=='.')
        {
            if(j+1<h)dp[i][j]=dp[i][j+1];
            if(i+1<r)dp[i][j]=min(dp[i][j],dp[i+1][j]);
        }
        else
        {
            if(j+1<h)
            {
                dp[i][j]=dp[i][j+1];
                if(g[i][j+1]=='.')dp[i][j]++;

            }

            if(i+1<r)dp[i][j]=min(dp[i][j],dp[i+1][j]+(g[i+1][j]=='.'? 1: 0));
        }
    }

}
    cout<<dp[0][0];
}



Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)

int main()
{
	string a, b;
	cin >> a >> b;

	int str = _stringtoi(a + b);
	double result = sqrt(str);

	if (ceil(result) == result) {
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

const int maxn=500005;
typedef long long ll;

int read()
{
	int f=0; char c=getchar();
	while(c>'9' || c<'0') c=getchar();
	while(c<='9' && c>='0') {f=f*10+c-'0'; c=getchar();}
	return f;
}

int a,b,c,d;

int main()
{
//	while(1) cout<<read()<<endl;
	int T=1; //cin>>T;
	while(T--)
	{
		cin>>a>>b>>c;
		cout<<c<<' '<<a<<' '<<b<<endl;
	}
	return 0;
}

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

#define int long long

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

string S, T;
int q;
int a[110000], b[110000], c[110000], d[110000];
int imos_S[110000], imos_T[110000];

signed main() {
    cin >> S >> T >> q;
    for (int i = 1; i <= S.length(); i++) {
        imos_S[i] = S[i - 1] == 'A' ? 1 : 2;
        imos_S[i] += imos_S[i - 1];
    }
    for (int i = 1; i <= T.length(); i++) {
        imos_T[i] = T[i - 1] == 'A' ? 1 : 2;
        imos_T[i] += imos_T[i - 1];
    }
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    for (int i = 0; i < q; i++) {
        if ((imos_S[b[i]] - imos_S[a[i] - 1]) % 3 ==
            (imos_T[d[i]] - imos_T[c[i] - 1]) % 3) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 5760
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long int
#define tii tuple<ll,ll,ll>

bool f[200010];
bool s[200010];

int main()
{
    ll n,m;
    cin >> n >> m;
    for(int i = 0;i < m;i++)
    {
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        if(a == 0)
        {
            f[b] = true;
        }
        if(b == n-1)
        {
            s[a] = true;
        }
    }
    for(int i = 0;i < n;i++)
    {
        if(f[i] && s[i])
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

int t[1005][1005];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m>>a>>b;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(i<b && j<a)c=1;
			else if(i>=b && j>=a)c=1;
			else c=0;
			cout<<c;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1280
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
using namespace std;

int main() {
   vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int answer=vec.at(1)+vec.at(0);
  int k;
  cin >> k;
  int d=vec.at(2);
  for(int i=0;i<k;i++){
    d=d*2;
  }
  cout << answer+d << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define INF INT_MAX
#define INFLL _I64_MAX
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;

int main(void)
{
	int n, h, max=0, ans=0;

	cin>>n>>h;

	vector<int> a(n), b(n);

	rep(i, n){
		cin>>a[i]>>b[i];
	}
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());

	rep(i, n){
		if(max<a[i]) max=a[i];
	}

	rep(i, n){
		if(max>b[i]||h<=0) break;
		h-=b[i];
		ans++;
	}

	while(h>0){
		h-=max; ans++;
	}
	cout<<ans<<endl;
}



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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;

	int ans=0;
	for(int i=0;i<3;i++){
		int tmp=0;
		for(int j=i;j<3;j++){
			if(s[j]=='S')break;

			tmp++;

		}
		ans=max(ans,tmp);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    int ans, s, d;
    
    ans = abs(a-b);
 
    ans = ans/2;

    if (a > b) {
        s = a - ans;
        d = b + ans;
    } else {
        s = b - ans;
        d = a + ans;
    }

    if (s == d) {
        cout << s << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    

    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

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

      //dp[i] = maximum value by taking exact weight of i.
      long[] dp = new long[W+1];
      for(int i = 0; i < N; i++){
        int weight = sc.nextInt();
        int value = sc.nextInt();
        for(int wt = W; wt >= 0; wt--){
          if(wt >= weight){
          	dp[wt] = Math.max(dp[wt], dp[wt - weight] + value);
          }
        }
        //for(int wt = W - weight; wt >= 0; wt--){
          //dp[wt] = Math.max(dp[wt + weight], dp[wt] + value);
        //}
      }
   
   	  long ans = 0;
      for(int i = 0; i <= W; i++){
      	ans = Math.max(ans, dp[i]);
      }
      System.out.println(ans);
   
      if(sc != null)
        sc.close();
  }
}


Measured memory_bytes: 21972
D, G = map(int, input().split())
plist, clist = [], []

for _ in range(D):
    p,c = map(int, input().split())
    plist.append(p)
    clist.append(c)

def dfs(i, s, not_used):
    if i==D:
        if len(not_used)==0:
            return True, 0
        u = max(not_used)
        for p in range(plist[u-1]):
            if s + p * (u*100) >= G:
                return True, p
        return False, 0
    
    check1, num1 = dfs(i+1, s+plist[i]*(i+1)*100+clist[i], not_used)
    check2, num2 = dfs(i+1, s, not_used+[i+1])

    if check1 and check2:
        if num1 + plist[i] <= num2:
            return True, num1 + plist[i]
        else:
            return True, num2
    
    if check1:
        return True, num1 + plist[i]
    
    if check2:
        return True, num2
    
    else:
        return False, 0
    

_, ans = dfs(0, 0, [])

print(ans)

Measured memory_bytes: 3192
#include <iostream>
#include <vector>

using namespace std;

int main(){
	vector<int> a(5);

	for (int i = 0; i < 5; i++) {
		cin >> a.at(i);
	}

	for (int i = 0; i < 5; i++) {
		if (a.at(i) == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3620
n = int(input())
if n == 1:
    print(0)
else:
    cnt_ls = [0] * 41
    cnt = 0
    add = 1
    for i in range(1, 41):
        cnt_ls[i] = add
        cnt += 1
        if cnt == add + 1:
            add += 1
            cnt = 0

    f_ls = []
    tmp = n
    for i in range(2, int(-(-(n ** 0.5) // 1)) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            f_ls.append(cnt)
    if tmp != 1:
        f_ls.append(1)
    if f_ls == []:
        f_ls.append(1)

    ans = 0
    for i in f_ls:
        ans += cnt_ls[i]

    print(ans)


Measured memory_bytes: 63532
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int N; cin >> N;
   ll dp[100100][3]; //0:A, 1:B, 2:C
   rep(i, N) {
       rep(j, 3) {
           dp[i][j] = 0; //i+1日目がjの時の最大幸福
       }
   }
	ll happy[3];
   rep(j, 3) {
		cin >> happy[j];
		dp[0][j] = happy[j];
	}
	rep1(i, N - 1) {
		rep(j, 3) {
			cin >> happy[j];
		}
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + happy[0];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + happy[1];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + happy[2];
	}
	ll ans = max({dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]});
	cout << ans << endl;
   return 0;
}

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

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

    int N;
    cin >> N;
    string S1, S2;
    cin >> S1 >> S2;
    ll ans = 1;
    // 一つ左が縦ならtrue, 横ならfalse
    bool flag;
    for (int i = 0; i < N; i++) {
        //縦かどうか
        if (S1[i] == S2[i]) {
            if (i == 0)
                ans *= 3;
            else if (flag)
                ans = ans % INF * 2;
            else if (!flag)
                ans = ans % INF * 1;
            flag = true;
        } else {
            if (i == 0)
                ans *= 6;
            else if (flag)
                ans = ans % INF * 2;
            else if (!flag)
                ans = ans % INF * 3;
            i++;
            flag = false;
        }
    }
    cout << ans % INF << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int K, N;
  cin >> N >> K;
  vector<int> h(N);
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  
  sort(all(h));
  int ans = INT_MAX;
  for(int i = 0; i < N - K + 1; i++){
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,K=get_i
MOD=10**9+7
$fac=array(N+1)
$fac_inv=array(N+1)
$inv=array(N+1)
def comb_init()
  $fac[0]=$fac[1]=1
  $fac_inv[0]=$fac_inv[1]=1
  $inv[1]=1
  2.upto(N) do|i|
    $fac[i]=$fac[i-1]*i%MOD
    $inv[i]=MOD-$inv[MOD%i]*(MOD/i)%MOD
    $fac_inv[i]=$fac_inv[i-1]*$inv[i]%MOD
  end 
end
def comb(n,k)
  return 0 if n<k
  return 0 if n<0 or k<0
  return $fac[n]*($fac_inv[k]*$fac_inv[n-k]%MOD)%MOD
end
comb_init()
1.upto(K) do|i|
    puts (comb(N-K+1,i)*comb(K-1,i-1))%MOD
end

Measured memory_bytes: 14408
using System;
using System.Linq;
using System.Text;

namespace ITP1_5_C_Print_a_Chessboard
{
    class Program
    {
        static string buildCheck(int h, int w)
        {
            var even = string.Join( "", Enumerable.Range( 0, w ).Select( i => i % 2 == 0 ? "#" : "." ).ToArray() );
            var odd = string.Join( "", Enumerable.Range( 0, w ).Select( i => i % 2 == 0 ? "." : "#" ).ToArray() );
            return Enumerable.Range( 0, h ).Select( i => i % 2 == 0 ? even : odd )
                .Aggregate( new StringBuilder(), (acc, s) => acc.AppendLine( s ) ).ToString();
        }
        static void Main(string[] args)
        {
            string[] input = null;
            do
            {
                if ( input != null )
                {
                    var size = input.Select( int.Parse ).ToArray();
                    Console.WriteLine( buildCheck( size[ 0 ], size[ 1 ] ) );
                }
                input = Console.ReadLine().Split( ' ' );
            } while ( input[ 0 ] != "0" || input[ 1 ] != "0" );
        }
    }
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define read(x) int x; cin>>x;
#define print(x) for(int i=0; i<(int) x.size(); i++) cout<<x[i]<<" "; cout<<endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;

const ll INFLL = (ll) 1e16;
const int INF = (int) 1e8;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	read(k)
	string s;
	cin>>s;
	
	int n = (int) s.size();
	if(n<=k) cout<<s<<endl;
	else {
		cout<<s.substr(0, k)<<"..."<<endl;
	}
	return 0;
}


Measured memory_bytes: 3616
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;
const ll INF = 1LL<<50;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    return a / GCD(a, b) * b;
}

int main(){

int N;
cin>>N;
ll A[N],B[N],count=0,sumA=0,sumB=0;
rep(i,N){
    cin>>A[i];
    sumA+=A[i];
}
vector<ll> res;
ll dem=0;
rep(i,N){
    cin>>B[i];
    sumB+=B[i];
    if(B[i]>A[i]){
        count++;
        dem+=B[i]-A[i];
    }
    else{
        res.push_back(A[i]-B[i]);
    }
}
if(sumA<sumB){
    cout<<-1<<endl;
    return 0;
}
sort(all(res));
reverse(all(res));
rep(i,res.size()){
    if(dem>0){
        dem-=res[i];
        count++;
    }
}
cout<<count<<endl;

return 0;
}

Measured memory_bytes: 5576
#include <bits/stdc++.h>
#define maxx 100100
using namespace std;
int dp[maxx],vis[maxx];
vector<int>ladj[maxx];
int ans = 0;

void dfs(int x){
	if(!vis[x]){
		vis[x] = 1;
		for(auto e:ladj[x]){
			if(!vis[e]) dfs(e);
			dp[x] = max(dp[x],dp[e]+1);
			ans = max(dp[x],ans);
		}
	}
}

int main(){
    ios_base::sync_with_stdio(false);    
    cin.tie(NULL);
 
    int n,m;
    cin >> n >> m;
 
    int x,y;
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        ladj[x].push_back(y);
    }
 
    for(int i = 1; i <= n; i++){
		if(vis[i] != 1) dfs(i);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 12636
n, ma, mb = (int(x) for x in input().split())
ABC = [tuple(int(x) for x in input().split()) for _ in range(n)]
m = n // 2
D = dict()
E = dict()
for bit in range(1, 1<<m):
    sum_a = 0
    sum_b = 0
    sum_c = 0
    for i in range(m):
        if bit & 1<<i:
            a, b, c = ABC[i]
            sum_a += a
            sum_b += b
            sum_c += c
    s = mb * sum_a - ma * sum_b
    if s in D:
        D[s] = min(D[s], sum_c)
    else:
        D[s] = sum_c

k = n - m
for bit in range(1, 1<<k):
    sum_a = 0
    sum_b = 0
    sum_c = 0
    for i in range(k):
        if bit & 1<<i:
            a, b, c = ABC[m + i]
            sum_a += a
            sum_b += b
            sum_c += c
    s = mb * sum_a - ma * sum_b
    if s in E:
        E[s] = min(E[s], sum_c)
    else:
        E[s] = sum_c

ans = 10**18
if 0 in D:
    ans = min(ans, D[0])
if 0 in E:
    ans = min(ans, E[0])
for s, c in D.items():
    if -s in E:
        ans = min(ans, D[s] + E[-s])
if ans == 10**18:
    print(-1)
else:
    print(ans)


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n = 0;
    cin >> n;

    vi a(n, 0);
    rep(i,0,n) cin >> a[i];

    ll r = 1000, s = 0;
    rep(i,0,n-1){
        if(a[i] < a[i+1]){
            s = r/a[i];
            r += s*(a[i+1]-a[i]);
        }
    }

    cout << r << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 3832
import sys
 
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
 
def main():
    K = int(input())
    h = K / (60 * 60)
    m = (K % (60 * 60))/60
    s = K % 60
    print(str(int(h)) + ":" + str(int(m)) + ":" + str(int(s)))
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 5596
import sys
from numpy import *
n, *a = map(int, sys.stdin.read().split())
a = int_(bincount(a, [1] * n, n))
print(pow(2, n // 2, 10 ** 9 + 7) if not a[0] > (n & 1) and all([x == 2 or x == 0 for x in a[1:]]) else 0)


Measured memory_bytes: 23016
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
# def LIST(): return list(map(str, input().split()))
# def LIST(): return list(input())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, Y = map(str, input().split())
# print(int(X))
if X < Y:
    print("<")
elif X > Y:
    print(">")
else:
    print("=")

Measured memory_bytes: 5148
#include<stdio.h>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  long long sum[N+1];
  sum[0] = 0;
  for (int i=1 ; i<=N ; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i-1] + a[i];
  }
  long long res = 1000000000000000000LL;
  long long x, y;
  for (int i=1 ; i<N ; i++) {
    x = sum[i];
    y = sum[N] - sum[i];
    res = min(res, abs(x-y));
  }
  printf("%lld\n", res);
}

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

typedef long long int ll;



int main()
{
    ll h, w, ans;
    cin >> h >> w;
    ans = w * h;
    vector<string> s(h);
    vector<vector<ll>> m(h,vector<ll>(w));
    for(ll i = 0;i < h;i++){
        cin >> s[i];
    }
    for(ll i = 0;i < h;i++){
        for(ll j = 0;j < w;j++){
            m[i][j] = -1;
        }
    }
    queue<tuple<ll,ll,ll,char,ll>> t;
    t.push(tuple<ll,ll,ll,char,ll>(0,0,-1,s[0][0],0));
    while(!t.empty()){
        ll d[2] = {0, 1}, l[2] = {1, 0};
        tuple<ll,ll,ll,char,ll> tmp = t.front();
        t.pop();
        for(ll j = 0;j < 2;j++){
            tuple<ll,ll,ll,char,ll> k;
            get<0>(k) = get<0>(tmp) + d[j];
            get<1>(k) = get<1>(tmp) + l[j];
            get<4>(k) += get<4>(tmp);
            if(get<0>(k) < h && get<1>(k) < w ){
                get<3>(k) = s[get<0>(k)][get<1>(k)];
                get<2>(k) = j;
                if(get<3>(tmp) == '.' && get<3>(k) == '#'){
                    get<4>(k)++;
                }
                if(m[get<0>(k)][get<1>(k)] > get<4>(k) || m[get<0>(k)][get<1>(k)] == -1){
                    m[get<0>(k)][get<1>(k)] = get<4>(k);
                    if(get<0>(k) == h - 1 && get<1>(k) == w - 1){
                        ans = min(ans, get<4>(k));
                    }
                    t.push(k);
                }
            }
        }
    }

    if(s[0][0] == '#'){
        ans++;
    }

    cout << ans;
 
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;
const int mod = 1e9 + 7;
    
long long int f(vector<long long int>& v, int x) {
    if (x == 0) return 1;
    if (x < 3) return 0;
    if (v[x] != -1) return v[x];
    v[x] = 0;
    for (int i = 3; i <= x; i++) {
        v[x] += f(v, x - i);
        v[x] %= mod;
    }
    return v[x];
}

int main() {
    int s;
    cin >> s;
    vector<long long int> v(s + 1,  -1);
    f(v, s);

    cout << max((long long int)0, v[s]) << endl;
}




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

char m(char a, char b){
    if(a == 'T' and b == 'F') return 'F';
    else return 'T';
}

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

    int n;
    cin >> n;
    vector<char> C(n);
    for(int i = 0; i < n; i++){
        cin >> C[i];
    }

    char bef = m(C[0], C[1]);
    for(int i = 2; i < n; i++){
        bef = m(bef, C[i]);
    }

    cout << bef << endl;


    return 0;
}


Measured memory_bytes: 3212
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	scanner.Split(bufio.ScanWords)

	sizeA := nextInt()
	a := make([]int, sizeA)
	for i := 0; i < sizeA; i++ {
		a[i] = nextInt()
	}

	sizeB := nextInt()
	b := make([]int, sizeB)
	for i := 0; i < sizeB; i++ {
		b[i] = nextInt()
	}

	var aIsLarger bool
	var breaked = false
	i := 0
	for i = 0; i < max(sizeA, sizeB); i++ {
		// fmt.Println(sizeA, sizeB, i)
		if i >= sizeB {
			aIsLarger = true
			breaked = true
			break
		} else if i >= sizeA {
			aIsLarger = false
			breaked = true
			break
		} else if a[i] < b[i] {
			aIsLarger = false
			breaked = true
			break
		} else if a[i] > b[i] {
			aIsLarger = true
			breaked = true
			break
		}
	}
	// fmt.Println(i, breaked, aIsLarger, sizeA, sizeB)
	if !breaked && (i == max(sizeA, sizeB)) {
		aIsLarger = true
	}

	if aIsLarger {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}



Measured memory_bytes: 1112
#!/usr/bin/env python3

def main():
    A, B, C = map(int, open(0).read().split())

    m = A*B*C
    ans = min(abs(2*A*C*(B//2) - m), abs(2*C*B*(A//2) - m), abs(2*B*A*(C//2) - m))

    print(ans)


main()

Measured memory_bytes: 2940
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)
	a := make([]int, 4)
	for i := 0; i < 4; i++ {
		n, err := strconv.Atoi(string(s[i]))
		if err != nil {
			panic(err)
		}
		a[i] = n
	}
	fmt.Println(solve(a, 0, a[0], fmt.Sprintf("%d", a[0]), ""))
}

func solve(a []int, i, ans int, f, op string) string {
	if i == 4 {
		if ans == 7 {
			return fmt.Sprintf("%s=%d", f, ans)
		}
		return ""
	}

	if op == "+" {
		ans += a[i]
		f += fmt.Sprintf("+%d", a[i])

	} else if op == "-" {
		ans -= a[i]
		f += fmt.Sprintf("-%d", a[i])
	}
	if res := solve(a, i+1, ans, f, "+"); res != "" {
		return res
	}
	if res := solve(a, i+1, ans, f, "-"); res != "" {
		return res
	}
	return ""
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n,a[105],m;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        m+=a[i];
    }
    m/=n;
    int x=0,y=0;
    for(int i=0;i<n;i++){
        x+=(m-a[i])*(m-a[i]);
        y+=(m+1-a[i])*(m+1-a[i]);
    }
    printf("%d",min(x,y));
}

Measured memory_bytes: 256
// おもむろにbit全探索をググる
// 結局実装わかんなくて解説をパクっただけ、理解まったくしてないよね君
// しかもWAだし馬鹿なのか？

package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	F := make([][]int, N)
	for i := 0; i < N; i++ {
		F[i] = make([]int, 10)
		for j := 0; j < 10; j++ {
			var k int
			fmt.Scan(&k)
			F[i][j] = k
		}
	}
	P := make([][]int, N)
	for i := 0; i < N; i++ {
		P[i] = make([]int, 11)
		for j := 0; j < 11; j++ {
			var k int
			fmt.Scan(&k)
			P[i][j] = k
		}
	}
	ans := -(1 << uint64(36))
	for bit := 1; bit < (1 << uint64(10)); bit++ {
		tmp := 0
		for i := 0; i < N; i++ {
			c := 0
			for j := 0; j < 10; j++ {
				if (bit>>uint64(j))&1 == 1 && F[i][j] == 1 {
					c += 1
				}
			}
			tmp += P[i][c]
		}
		ans = max(ans, tmp)
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#define DIV 100000
using namespace std;

long long d,S[100010];

int main(){
	long long n, m, k, t = 0;
	long long ans = 0;
	cin >> n >> m; S[0] = 0;
	for (int i = 1; i < n; i++){
		cin >> d; S[i] = S[i - 1] + d;
	}
	while (m--){
		cin >> k;
		ans += abs(S[t] - S[t + k]);
		ans = ans%DIV;
		t += k;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1936
using System;

public class Class1
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        string[] input = Console.ReadLine().Split(' ');

        int[] an = new int[input.GetLength(0)];

        for(int i = 0;i < input.GetLength(0); i++)
        {
            an[i] = int.Parse(input[i]);
        }

        int max = 0;
        int min = 1001;

        for(int i = 0; i < an.GetLength(0); i++)
        {
            if(an[i] > max)
            {
                max = an[i];
            }
            if(an[i] < min)
            {
                min = an[i];
            }
        }

        int ans = max - min;

        Console.WriteLine(ans);




    }
}

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

namespace ABCTemplate_B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var b = new ProblemB();
        }
    }

    public class ProblemB
    {
        public ProblemB()
        {
            
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            // 文字列の入力
            string[] input2 = Console.ReadLine().Split(' ');
            var ai = input2.Select(x => int.Parse(x)).ToList();
            ai.Sort();
            ai.Reverse();

            var s = ai.Sum();
            var q = s / (4.0 * m);
            var flag = true;
            
            for (var i = 0; i < m;i++)
            {
                if (ai[i] < q)
                {
                    flag = false;
                }
            }
            var result = flag ? "Yes" : "No";
            //出力
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13396
def main():
    S = input()
    K = int(input())
    if len(set(S)) == 1:
        print((len(S) * K)//2)
        return
    result = 0
    piyo = 0
    hoge = S[0]
    huga = 1
    first = 0
    for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
    if first == 0:
        first = huga
    if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
    print(piyo * K + result)
main()


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

#define ll long long
#define pb push_back

const int maxn = 3e5 + 20;

int b[maxn];

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

	int n;
	cin >> n;

	for(int i = 0; i < n - 1; i++)
		cin >> b[i];

	ll res = 0;
	for(int i = 0; i < n; i++)
	{
		int k = 1e6;
		if(i)
			k = min(k , b[i - 1]);
		if(i < n - 1)
			k = min(k , b[i]);
		res += k;
	}

	cout << res << endl;
}










 


Measured memory_bytes: 256