akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H, W, K;
string c[6];
string c2[6];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W >> K;
	rep(y, 0, H) cin >> c[y];

	int ans = 0;
	rep(mskH, 0, 1 << H) rep(mskW, 0, 1 << W) {
		rep(y, 0, H) c2[y] = c[y];
		rep(y, 0, H) if (mskH & (1 << y)) rep(x, 0, W) c2[y][x] = 'R';
		rep(x, 0, W) if (mskW & (1 << x)) rep(y, 0, H) c2[y][x] = 'R';

		int cnt = 0;
		rep(x, 0, W) rep(y, 0, H) if (c2[y][x] == '#') cnt++;
		if (cnt == K) ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n = 5;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int index;
    for (int i = 0; i < n; i++) {
        if (a[i] % 10 != 0) {
            b[i] = a[i] % 10;
        } else {
            b[i] = a[i];
        }
    }
    auto m = min_element(b.begin(), b.end());
    index = distance(b.begin(), m);

    for (int i = 0; i < n; i++) {
        if (i != index) {
            if (b[i] != 0 && (b[i] != a[i] || a[i] % 10 == a[i])) {
                c[i] = a[i] - b[i] + 10;
            } else {
                c[i] = a[i];
            }
        }
    }
    c[index] = a[index];

    cout << accumulate(c.begin(), c.end(), 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;

const int N=1e5+10;
pii a[N],b[N];
int nex[N];
bool vis[N];

void solve(){
    int n;
    scanf("%d",&n);
    bool flag=0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i].first),a[i].second=i;
    for(int i=1;i<=n;i++) scanf("%d",&b[i].first),b[i].second=i;
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    for(int i=1;i<=n;i++){
        if(a[i].first>b[i].first){
            printf("No\n");
            return ;
        }
        nex[a[i].second]=b[i].second;
        if(i+1<=n && a[i+1].first<=b[i].first){
            flag=1;
        }
    }
    if(flag) printf("Yes\n");
    else{
        int cnt=0,cur=1;
        while(!vis[cur]){
            cnt++,vis[cur]=1,cur=nex[cur];
        }
        if(cnt==n) printf("No\n");
        else printf("Yes\n");
    }
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 2304
import collections


def main():
    n, m = (int(z) for z in input().split())
    ctr = collections.Counter()
    for _ in range(n):
        xs = [int(z) for z in input().split()][1:]
        ctr.update(xs)
    print(sum(v == n for k, v in ctr.items()))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
a,b,c=map(int,input().split())
#aの倍数の中でbで割って余りがcになるものが存在すればよい
x=0
for i in range(1,b+1):
    if i*a%b==c:
        x+=1
if x==0:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 2940
N = int(input()) 
x = list(map(int, input().split()))
sumx = 0
ans = 0
ans1 = 0
ans2 = 0
for i in x:
  sumx += i

if sumx % N == 0:
  for i in x:
    ans += (i-sumx//N)**2
else:
  for i in x:
    ans1 += (i-sumx//N)**2
    ans2 += (i-sumx//N-1)**2
  ans = min(ans1, ans2)
    
print(ans)
  

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, k; cin >> n >> k;
  vll a(n); REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll l=0, r=n;
  while (l < r) {
    ll mid = (l + r) / 2;
    vll dp(k, false); dp[0] = true;
    REP(i, a.size()) {
      if (a[i] >= k) break;
      if (i == mid) continue;
      vll tmp_dp = dp;
      rep(j, 1, k) {
        if (j>=a[i] && !tmp_dp[j]) tmp_dp[j] = dp[j-a[i]];
      }
      dp = tmp_dp;
    }
    bool is_need = false;
    rep(i, max(0LL, k-a[mid]), k) {
      if (dp[i]) {
        is_need = true; break;
      }
    }
    if (is_need) r = mid;
    else l = mid + 1;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 384
S = input()
l = len(S)
p = [0] * l

i = 0
while i < l - 1:
    si = i
    while S[i] == 'R':
        i += 1

    d = (i - si) // 2
    p[i - 1] += d
    p[i] += d
    if (i - si) & 1:
        p[i - 1] += 1

    i += 1
i = l - 1
while i > 0:
    si = i
    while S[i] == 'L':
        i -= 1
    d = (si - i) // 2
    p[i + 1] += d
    p[i] += d
    if (i - si) & 1:
        p[i + 1] += 1

    i -= 1

print(' '.join(map(str, p)))

Measured memory_bytes: 10484
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int n, x, max;
	int a, b, c;
	int ans;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		ans = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



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

const int MAX = 1e5 + 5;

#define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, n;
	cin >> x >> n;
	vector <bool> cnt(105);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		cnt[a] = true;
	}
	for (int d = 0; d < 100; d++) {
		int l = x - d, r = x + d;
		if (l <= 0 or !cnt[l]) {
			cout << l << '\n';
			break;
		}
		if (!cnt[r]) {
			cout << r << '\n';
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
vector<long long>fact(200050);
vector<vector<int> >g;
vector<long long>dp, ans, subtree;
long long mod = 1e9 + 7;
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
long long inversemod(long long a){
    return bigmod(a, mod - 2);
}
void dfs(int v, int p){
    dp[v] = 1;
    subtree[v] = 1;
    for(int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if(to != p){
            dfs(to, v);
            subtree[v] += subtree[to];
            dp[v] = (dp[v] * dp[to]) % mod;
            dp[v] = (dp[v] * inversemod(fact[subtree[to]])) % mod;
        }
    }
    dp[v] = (dp[v] * fact[subtree[v] - 1]) % mod;
}
void dfs2(int v, int p){
    ans[v] = dp[v];
    for(int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if(to != p){
            dp[v] = (dp[v] * fact[subtree[to]]) % mod;
            dp[v] = (dp[v] * inversemod((dp[to] * fact[subtree[v] - 1]) % mod)) % mod;
            dp[to] = (dp[to] * inversemod(fact[subtree[to] - 1])) % mod;
            subtree[v] -= subtree[to];
            subtree[to] += subtree[v];
            dp[v] = (dp[v] * fact[subtree[v] - 1]) % mod;
            dp[to] = (dp[to] * fact[subtree[to] - 1]) % mod;
            dp[to] = (dp[to] * dp[v]) % mod;
            dp[to] = (dp[to] * inversemod(fact[subtree[v]])) % mod;
            dfs2(to, v);
            dp[to] = (dp[to] * fact[subtree[v]]) % mod;
            dp[to] = (dp[to] * inversemod((dp[v] * fact[subtree[to] - 1]) % mod)) % mod;
            dp[v] = (dp[v] * inversemod(fact[subtree[v] - 1])) % mod;
            subtree[to] -= subtree[v];
            subtree[v] += subtree[to];
            dp[to] = (dp[to] * fact[subtree[to] - 1]) % mod;
            dp[v] = (dp[v] * fact[subtree[v] - 1]) % mod;
            dp[v] = (dp[v] * dp[to]) % mod;
            dp[v] = (dp[v] * inversemod(fact[subtree[to]])) % mod;
        }
    }
}
int main(){
    fact[0] = 1;
    for(long long i = 1; i <= 200000; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
    int n;
    cin >> n;
    g = vector<vector<int> >(n + 3);
    dp = vector<long long>(n + 3);
    ans = vector<long long>(n + 3);
    subtree = vector<long long>(n + 3);
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 0);
    dfs2(1, 0);
    for(int i = 1; i <= n; i++){
        cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 21228
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f,N=100+5;
int X,n;
int b[N*10];
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	cin>>X>>n;
	for(i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		b[x]=1;
	}
	for(i=0;i<=100;i++)
	{
		if(X-i<=0)
		{
			cout<<X-i<<endl;
			break;
		}
		if(!b[X-i])
		{
			cout<<X-i<<endl;
			break;
		}
		if(!b[X+i])
		{
			cout<<i+X<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3764
#include <iostream>
#include <limits.h> 
using namespace std;

int main() {
    int n, min = INT_MAX, max = INT_MIN;
    long long sum=0;
    cin >> n;
    while(n) {
        int num;
        cin >> num;
        if (num < min) min=num;
        if (num > max) max=num;
        sum+=num;
        n--;
    }
    cout << min << " " << max <<" " <<sum <<endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;
 
const int N = 150005;
 
typedef class Task {
    public:
        int t, d;
 
        boolean operator < (Task b) const {
            return d < b.d;
        }
        void read() {
            scanf("%d%d", &d, &t);
			d += t;
        }
} Task;
 
int n;
Task a[N];
 
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        a[i].read();
    }
    sort(a + 1, a + n + 1);
    priority_queue<int> Q;
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        Q.push(a[i].t);
        sum += a[i].t;
        if (sum > a[i].d) {
            sum -= Q.top();
            Q.pop();
        }
    }
    printf("%d\n", (signed) Q.size());
    return 0;
}


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

int main(){
    int N=700,a,b,c,d,e;
    string ra;

    cin>>ra;

    if(ra[0]=='o')N+=100;
    if(ra[1]=='o')N+=100;
    if(ra[2]=='o')N+=100;


    cout<<N<<endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, M;
int A[10000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    for(int i = 0; i < M; i++) cin >> A[i];
    int sum = 0;
    for(int i = 0; i < M; i++) sum += A[i];
    if(sum > N){
        cout << -1 << endl;
    }else{
        cout << N-sum << endl;
    }
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> X(n); rep(i, n) cin >> X[i];
  deque<ll> q;
  ll ans = 1;
  rep(i, n) {
    q.push_back(X[i]);
    int m = q.size();
    if(q.back() < 2*m-1) {
      (ans *= m) %= mod;
      q.pop_back();
    }
  }
  int m = q.size();
  for(int i=1; i<=m; i++) (ans *= i) %= mod;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string S;
    cin >> S;
    
    if ( S.length() < 4 ) { cout << "No" << endl; return 0; }
    if ( S.substr( 0, 4 ) == "YAKI" ) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int a,b,x;
  scanf("%d%d%d",&a,&b,&x);
  if(a+b>=x){
    if(a<=x){
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 128
def check(x, y): 
    z = [0, 1, 2]
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
                break
            if x[j] == y[z[j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order or (i < 3) == sum(order) % 2:
                return True
        z = [z[2], z[0], z[1]]
        if i == 2:
            z = [z[0], z[2], z[1]]
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = input().split()
for i in range(n):
    for j in range(i+1, n, 1): 
        if check(x[i], x[j]):
            break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

Measured memory_bytes: 7832
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,A,B,ANS;
	cin>>N>>A>>B;
	if(abs(A-B)%2==0){
		cout<<abs(A-B)/2<<endl;
	}
	else{
		ll G;
		vector<pair<ll,ll>>AA,BB;
		AA.push_back(make_pair(abs(1-A),1));
		AA.push_back(make_pair(abs(N-A),2));
		BB.push_back(make_pair(abs(1-B),3));
		BB.push_back(make_pair(abs(N-B),4));
		sort(AA.begin(),AA.end());
		sort(BB.begin(),BB.end());
		if(AA[0].first<=BB[0].first){
			if(AA[0].second==1){
				G=AA[0].first;
				A=1;
				B=B-G-1;
			}
			else{
				G=AA[0].first;
				A=N;
				B=B+G+1;
			}
			//cout<<G<<":"<<A<<":"<<B<<endl;
			cout<<G+abs(A-B)/2+1<<endl;
		}
		else{
			if(BB[0].second==3){
				G=BB[0].first;
				B=1;
				A=A-G-1;
			}
			else{
				G=BB[0].first;
				B=N;
				A=A+G+1;
			}
			//cout<<G<<":"<<A<<":"<<B<<endl;
			cout<<G+abs(A-B)/2+1<<endl;
		}

	}
}

Measured memory_bytes: 632
import math

n,d = map(int,input().split())

x=[]
for i in range(n):
    x.append(list(map(int,input().split())))

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        nor = math.sqrt(sum([(x[i][k]-x[j][k])**2 for k in range(d)]))
        
        if nor.is_integer():
#            print(nor)
            ans+=1

print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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

bool dp1[4400][17000];
bool dp2[4400][17000];
constexpr int OFFSET = 8500;

int main()
{
  string S;
  cin >> S;
  S.push_back('T');
  int x, y;
  cin >> x >> y;

  vector<vector<int>> nums(2);
  int p = 0, cnt = 0;
  for (auto c : S) {
    if (c == 'T') {
      nums[p].push_back(cnt);
      cnt = 0;
      p = 1 - p;
    } else {
      cnt++;
    }
  }

  dp1[0][OFFSET] = true;
  REP(i, nums[0].size()) {
    REP(j, 17000) {
      if (i > 0 && j >= nums[0][i]) dp1[i + 1][j - nums[0][i]] |= dp1[i][j];
      if (j + nums[0][i] < 17000)    dp1[i + 1][j + nums[0][i]] |= dp1[i][j];
    }
  }

  dp2[0][OFFSET] = true;
  REP(i, nums[1].size()) {
    REP(j, 17000) {
      if (j >= nums[1][i]) dp2[i + 1][j - nums[1][i]] |= dp2[i][j];
      if (j + nums[1][i] < 17000)    dp2[i + 1][j + nums[1][i]] |= dp2[i][j];
    }
  }

  if (dp1[nums[0].size()][OFFSET + x] && dp2[nums[1].size()][OFFSET + y]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 135424
#include <math.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;

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

int main() {
  string n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n.size(); i++) {
    ans += n.at(i) - '0';
    ans %= 9;
  }
  if (ans == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3372
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int n;
ll a[200010], b[200010];

bool check(int m) {
  REP(i, n) {
    int tmp = i==0 ? 0 : b[i-1];
    int itr1 = lower_bound(b+i, b+i+n, tmp+m) - b;
    int itr2 = lower_bound(b+i, b+i+n, b[itr1]+m) - b;
    if(b[n+i-1] - b[itr2] >= m) return true;
  }
  return false;
}

signed main(void)
{
  cin >> n;
  REP(i, n) cin >> a[i];
  FOR(i, n, 2*n) a[i] = a[i-n];
  b[0] = a[0];
  FOR(i, 1, 2*n) b[i] = a[i] + b[i-1];

  // [low, high)
  ll low=1, high=b[n-1];
  while(high-low>1) {
    ll mid = (low+high)/2;
    if(check(mid)) {
      low = mid;
    } else {
      high = mid;
    }
  }
  cout << low << endl;

  return 0;
}


Measured memory_bytes: 6236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
const int inf = 1e9;

int h, w, d, a[500][500], q;
P p[100000];
int rui[100000];
int main(){
	scanf("%d%d%d", &h, &w, &d);
	rrep(i,h)rrep(j,w){
		scanf("%d", &a[i][j]);
	}
	rrep(i,h)rrep(j,w){
		int x = a[i][j];
		p[x] = P(i, j);
	}
	for(int i = 1+d;i <= h*w;i++){
		if(p[i-d].fi == 0 || p[i].fi == 0)continue;
		int x = abs(p[i-d].fi-p[i].fi)+abs(p[i-d].se-p[i].se);
		//if(i == 9)printf(" *%d %d* \n", rui[i-d], x);
		rui[i] = rui[i-d]+x;
	}
	//rrep(i,h*w)printf("%d ", rui[i]);
	scanf("%d", &q);
	int ans = 0;
	rep(k,q){
		int l, r;
		scanf("%d%d", &l, &r);
		ans = rui[r]-rui[l];
		printf("%d\n", ans);
	}
	//printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	int R,G,B,N;
	cin>>R>>G>>B>>N;
	int ans=0;
	REP(i,3001){
		REP(j,3001){
			int x=N-i*R-j*G;
			if((0<=x)&&(x%B==0)){
				//cout<<i<<" "<<j<<" "<< x<<endl;
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
f, t = [], []

for i in range(M) :
    a, b = map(int, input().split())
    
    f.append(a)
    t.append(b)
    
def get_root(idx) :
    if idx == u[idx] :
        return idx
    else :
        u[idx] = get_root(u[idx])
        return u[idx]
    
def union(a, b) :
    if get_root(a) <= get_root(b) :
        u[get_root(b)] = get_root(a)
    else :
        u[get_root(a)] = get_root(b)
cnt = 0 

for i in range(M) :
    u = [x for x in range(N)]
    
    for j in range(M) :
        if i != j :
            union(f[j] - 1, t[j] - 1)
    
    u_sets = set()
    for j in range(N) :
        u_sets.add(get_root(j))
        
    # print("DBG : ", u_sets)
    if len(list(u_sets)) != 1 :
        cnt += 1
        
print(cnt)
    

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a, b;
  for(int i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    if(tmp < 0) {
      b.push_back(tmp);
    } else {
      a.push_back(tmp);
    }
  }
  sort(a.rbegin(), a.rend());
  sort(b.begin(), b.end());
  if(b.size() == n) {
    if(k % 2 != 0) {
      reverse(b.begin(), b.end());
    }
    ll ans = 1;
    for(int i = 0; i < k; i++) {
      ans *= b[i];
      ans %= MOD;
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  } else if(a.size() >= n - 1 && k <= a.size()) {
    ll ans = 1;
    for(int i = 0; i < k; i++) {
      ans *= a[i];
      ans %= MOD;
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  } else {
    ll ans = 1;
    vector<ll> c;
    if(b.size() > 1) {
      for(int i = 0; i < b.size() - 1; i += 2) {
        c.push_back(b[i] * b[i + 1]);
      }
    }
    if(b.size() % 2 != 0) {
      c.push_back(*(b.end() - 1));
    }
    int ac = 0, cc = 0;
    for(int i = 0; i < k; i++) {
      if((a[ac] * a[ac + 1] < c[cc] && i < k - 1) || ac >= a.size()) {
        c[cc] %= MOD;
        ans *= c[cc];
        ans %= MOD;
        i++;
        cc++;
      } else {
        ans *= a[ac];
        ans %= MOD;
        ac++;
      }
    }
    if(ans < 0) {
      ans += MOD;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int a, b;
  while (true) {
    int id, maxe = 0;
    for (int i = 0; i < 5; i++) {
      cin >> a >> b;
      if (a == 0 && b == 0) return 0;
      if (maxe < a + b) {
        maxe = a + b;
        id = i;
      }
    }
    cout << "ABCDE"[id] << " " << maxe << "\n";
  }
  return 0;
}



Measured memory_bytes: 2988
#include <bits/stdc++.h>
using namespace std;
const int N = 15;
vector< pair< int,int > > a[N];
int main()
{
    int n,ans = 0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int A,x,y;
        scanf("%d",&A);
        for(int j=1;j<=A;j++)   scanf("%d %d",&x,&y),--x,a[i].push_back({x,y});
    }
    for(int i=1;i<(1<<n);i++)
    {
        int ch = 0;
        for(int j=0;j<n;j++)
        {
            if(!((1<<j)&i)) continue;
            for(auto &x:a[j])
            {
                int state = ((1<<x.first)&i) ? 1 : 0;
                ch|=state!=x.second;
            }
        }
        if(!ch) ans = max(ans,__builtin_popcount(i));
    }
    printf("%d\n",ans);
}


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

int calc(int n)
{
	int ret = 0;
	while(n > 0){
		ret += n%10;
		n /= 10;
	}

	return ret;
}

int main(void)
{
	int N, A, B;
	cin >> N >> A >> B;

	int ret = 0;
	for(int i=1; i<=N; i++){
		int sum = calc(i);
		if(sum >= A && sum <= B)
			ret += i;
	}

	cout << ret << endl;

	return 0;
}


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

signed main() {
  int n; cin >> n;
  string s; cin >> s;
  int x = 0;
  int max_x = x;

  for(int i = 0; i < n; i++) {
    if(s[i] == 'I') x++;
    if(s[i] == 'D') x--;
    max_x = max(max_x, x);
  }

  cout << max_x << endl;
  return 0;
}


Measured memory_bytes: 256
def c_s(str)
    i = -2
    kk = 0
    while 1
        i = str.index('AB', i+2)
        break if i == nil
        kk += 1
    end
    kk
end

n=gets.split.map(&:to_i)
s=$<.map(&:chomp)

ab = s.map {|ss| c_s(ss)}.inject(:+)

s.map! do |m|
    mm = 0
    mm += 1 if m.end_with?('A')
    mm += 2 if m.start_with?('B')
    mm
end
a = s.count(1)
b = s.count(2)
a_b = s.count(3)
if a == 0 && b == 0 && a_b > 0
    puts ab + a_b - 1
else 
    puts ab + [a,b].min + a_b
end


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B){
    cout<<C<<endl;
  }
  else if(A==C){
    cout<<B<<endl;
  }
  else {
    cout<<A<<endl;
  	}
  }

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
 
using namespace std;
 
int main() {
  
  long long n;
  cin >> n;
  
  long long ans = n-1;
  for (long long i = 2; i*i <= n; ++i) {
    if (n % i == 0) {
    	ans = min(ans, i + n/i - 2);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll fact[1010101],invfact[1010101];

ll comb(int n,int k){
  if(k<0||k>n)return 0;
  ll ret=fact[n]*invfact[k] %mod;
  ret=ret*invfact[n-k] %mod;
  return ret %mod;
  }

ll inv(ll n){
  ll ret=1,k=mod-2;
  while(k>0){
    if(k&1)ret=ret*n %mod;
    n=n*n %mod;
    k/=2;
    }
  return ret%mod;
  }

int main(){
  ll n;
  cin>>n;
  fact[0]=invfact[0]=1;
  rep(i,n+1)fact[i+1]=fact[i]*(i+1) %mod;
  invfact[n]=inv(fact[n]);
  rep(i,n+1)invfact[n-i-1]=invfact[n-i]*(n-i)%mod;
  ll a[n];
  a[n-1]=fact[n-1] %mod;
 
  for(ll i=n-2;i>=n-i;i--){
    a[i]=fact[i]*comb(i-1,n-1-i) %mod;
    a[i]=a[i]*fact[n-i-1]%mod;
    a[i+1]=(a[i+1]-a[i]+mod) %mod;
    }
  ll ans=0;
  for(ll i=n-1;i>=n-i;i--){
    ans+=a[i]*i;
    ans%=mod;
    }
  cout<<ans%mod<<endl;
  return 0;
  }

Measured memory_bytes: 19840
a,b=map(int,input().split())
s=input()
flag=0
if len(s)==(a+b+1):
    flag+=1
if s.count('-')==1:
    flag+=1
    if a==len(s[0:(s.index('-'))]):
        flag+=1
if flag==3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7;

int main(){
    int N,M;
    cin >> N >> M;
    int oks[N+1];
    for(int i=0;i<N+1;i++){
        oks[i] = true;
    }
    for(int i=0;i<M;i++){
        int a;cin >> a;
        oks[a] = false;
    }

    vector<long long int>dp(N+1);
    dp[0] = 1;
    for(int now=0;now<N;++now){
        for(int next=now+1;next<=min(N,now+2);++next){
            if(oks[next]){ // 次の段が安全ならば
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 500003;
int n;char s[MaxN];
int last[MaxN],dp[MaxN];
int main() {
    scanf("%d%s",&n,s+1);
    for (int i=1,p=0;i<=n;++i) {
        last[i]=p;
        if (s[i]=='0') p=i;
    }
    for (int i=1;i<=n;++i) {
        dp[i]=dp[i-1];
        if (s[i]=='0') continue;
        if (last[i]==0 || s[last[i]-1]=='0') continue;
        if (last[i]-2>=0) dp[i]=max(dp[i],dp[last[i]-2]+i-last[i]);
        if (last[i]==i-1) {
            int llast=last[last[i]];
            if (llast>=0) dp[i]=max(dp[i],dp[llast]+i-llast-2);
            if (llast+1<last[i]) dp[i]=max(dp[i],dp[llast+1]+i-llast-3);
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int left_max = 0;
        int right_min = int.MaxValue;
        for (int i = 0; i < m; i++)
        {
            input = Console.ReadLine().Split(' ');
            int l = int.Parse(input[0]);
            int r = int.Parse(input[1]);
            left_max = Math.Max(left_max, l);
            right_min = Math.Min(right_min, r);
        }
        Console.WriteLine(Math.Max(0,right_min - left_max + 1));
    }
}


Measured memory_bytes: 17340
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	char c;
	vector<char> s;
	for (int i = 0; i < 4; i++) {
		cin >> c;
		s.push_back(c);
	}
	sort(s.begin(), s.end());
	if (s[0] == s[1]) {
		if (s[1] == s[2]) {
			cout << "No";
		}
		else if (s[2]==s[3]) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main (String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int N = scanner.nextInt();
		int K = scanner.nextInt();
		
		int rem = N % K;
		if (rem == 0) {
			System.out.println("0");
		} else {
			System.out.println("1");
		}
    }
}

Measured memory_bytes: 25172
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		if(a*b >= c*d) {
			System.out.println(a*b);
		}else if(a*b <= c*d) {
			System.out.println(c*d);
		}
	}
}

Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        System.out.println(a + a*a + a*a*a);
    }

}


Measured memory_bytes: 35732
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

typedef struct {
    int index;
    int num;
} Num;

int my(const void *a, const void *b) {
  return (((const Num*)a)->num - ((const Num*)b)->num);
}

int main() {
    string s;
    cin >> s;
    int r1=0,r2=0,r3=0;
    FOR(i,3) {
        if (s[i] == 'a') r1++;
        if (s[i] == 'b') r2++;
        if (s[i] == 'c') r3++;
    }
    cout << ((r1 == 1 && r2 == 1 && r3 == 1) ? "Yes" : "No") << endl;
 return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,m;
    
    cin >> n >> m;
    vector<ll> a(n);
    priority_queue<ll> que;
    
    for (int i = 0;i < n;i++){
        cin >> a[i];
        que.push(a[i]);
    }

    while(m > 0){
        ll MAX = que.top();
        que.pop();
        que.push(MAX / 2);
        m--;
    }
    ll ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;


/*--------------------template--------------------*/


int main()
{
	cin >> n >> m;
	vi v(n);
	REP(i, n) cin >> v[i];
	sort(ALL(v));
	ll p = n - 1;
	ll dp[10001] = { 1 };
	REP(i, m + 1)
	{
		ll rem = i;
		REP(j, n)
		{
			if (m - i >= v[j]) {
				rem -= v[j];
			}
		}
		if (rem < 0) {
			continue;
		}
		while (p >= 0 && m - i < v[p]) {
			for (int j = m; j >= v[p]; j--) {
				dp[j] = (dp[j] + dp[j - v[p]]) % MOD;
			}
			p--;
		}
		ans = (ans + dp[rem]) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

struct LCA {
    vector<vector<int>> par;
    vector<int> d;
    int n;
    LCA(vector<vector<int>> graph, int root) {
        n = graph.size();
        par.resize(n, vector<int>(30));
        d.resize(n, 0);
        function<void(int, int, int)> dfs = [&](int c, int p, int depth) {
            d[c] = depth;
            par[c][0] = p;
            for (auto ch : graph[c]) {
                if (ch != p) dfs(ch, c, depth + 1);
            }
        };
        dfs(0, 0, 0);
        for (int j = 1; j < 30; j++) {
            REP(i, n) { par[i][j] = par[par[i][j - 1]][j - 1]; }
        }
    }
    int getdistance(int u, int v) { return (d[u] + d[v]) - 2 * (d[query(u, v)]); }
    int query(int u, int v) {
        if (d[u] > d[v]) {
            swap(u, v);
        }
        for (int i = 29; 0 <= i; i--) {
            if (d[u] <= d[par[v][i]]) {
                v = par[v][i];
            }
        }
        /* LCA */
        for (int i = 29; 0 <= i; i--) {
            if (par[v][i] != par[u][i]) {
                v = par[v][i];
                u = par[u][i];
            }
        }
        if (u == v) {
            return u;
        } else {
            return par[v][0];
        }
    }
};

struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
int n, m;
vector<vector<int>> graph;

signed main() {
    int n;
    cin >> n;
    vector<long long> as(n);
    REP(i, n) { cin >> as[i]; }
    int q;
    cin >> q;
    REP(i, q) {
        int b, e, t;
        cin >> b >> e >> t;
        REP(i, e - b) { swap(as[b + i], as[t + i]); }
    }
    REP(i, n - 1) { cout << as[i] << " "; }
    cout << as[n - 1] << endl;
}


Measured memory_bytes: 3208
#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;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, k, i, j, m, ans = 0;
    cin >> n >> k;
    vll a(n);
    for(i = 0; i < n; i++)
        cin >> a[i];
    for(i = 0; i <= k; i++)
    {
        for(j = 0; j <= k; j++)
        {
            if(i + j > n || i + j > k)
                continue;
            priority_queue <ll, vll, greater <ll> > h;
            ll sum = 0;
            for(ll x = 0; x < n && x < i; x++)
                h.push(a[x]), sum += a[x];
            for(ll x = 0; x < n && x < j; x++)
                h.push(a[n - 1 - x]), sum += a[n - 1 - x];
            ans = max(ans, sum);
            for(m = 1; m <= min({k - (i + j), i + j}); m++)
            {
                if(h.size() && i + j + m <= k)
                {
                    // if(i == 3 && j == 0)
                    //     cout << sum << ' ' << m <<  endl;
                    sum -= h.top();
                    h.pop(); 
                    ans = max(ans, sum);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e5 + 4;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e16;
const int inf = 1e9;

long long dp[105][N];

long long w[N], v[N];

int main () {
	boost;
	long long n, m;
	cin >> n >> m;
	for (int i = 0 ; i < n ; ++ i) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0 ; i < n ; ++ i) {
		for (int j = 0 ; j < N ; ++ j) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	dp[0][v[0]] = w[0];
	for (int i = 0 ; i < n ; ++ i) {
		for (int j = 0 ; j < N ; ++ j) {
			dp[i + 1][j] = min (dp[i][j], dp[i + 1][j]);
			if (j - v[i + 1] >= 0)
				dp[i + 1][j] = min (dp[i + 1][j], dp[i][j - v[i + 1]] + w[i + 1]);
		}
	}
	int ans = 0;
	for (int i = 0 ; i < N ; ++ i) {
		if (dp[n - 1][i] <= m)
			ans = i;
	}
	cout << ans;
}

Measured memory_bytes: 80640
#include<iostream>
#include<cmath>
using namespace std;
double x,y,dir=M_PI/2.0;
int a,b;
char c;
int main(){
  x=y=0.0;
  while(cin>>a>>c>>b&&a){
    x-=cos(dir)*(double)a;
    y+=sin(dir)*(double)a;
    dir+=b/180.0*M_PI;
    while(dir>=2.0*M_PI)dir-=2.0*M_PI;
    while(dir<0.0)dir+=2.0*M_PI;
    
  }
  cout<<(int)x<<endl<<(int)y<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<map>
using namespace std;
const long long mod = 1e9 + 7;
map<long long, long long> mp;
long long read() {
    char ch = getchar();
    long long x = 0, q = 1;
    while(ch > '9' || ch < '0') q = ch == 45 ? -1 : q, ch = getchar();
    while(ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
    return x * q;
}
long long dfs(long long n) {
    if(mp[n] != 0) return mp[n];
    else return mp[n] = ((dfs(n / 2) + dfs((n - 1) / 2) + dfs((n - 2) / 2))) % mod;
}
int main() {
    long long n;
    mp[0] = 1;
    mp[1] = 2;
    n = read();
    printf("%lld\n", dfs(n));
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
M = 26
digit = 0
N -= 1

for d in range(1, 12):
    if N < M ** d:
        digit = d - 1
        break
    N -= M ** d

name = ""

for i in range(digit + 1):
    name += chr(ord("a") + (N % M))
    N //= M

print(name[::-1])


Measured memory_bytes: 9148
#include<stdio.h>
int main(void){
  int n,m,sum=0,ans=0;
  double sou,s;
  scanf("%d%d",&n,&m);
  int a[n],i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  sou=(double)1/(4*m);
  for(i=0;i<n;i++){
    s=(double)a[i]/sum;
    if(s>=sou) ans++;
  }
  if(ans>=m) printf("Yes");
  else printf("No");
  return 0;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A + B > C + D) {
        cout << "Left" << endl;;
    } else if (A + B < C + D) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
    return 0;
}

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



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    	int n,k;
    	cin>>n>>k;
    	vector<int> vec(n);
    	for(int i=0;i<n;++i)
    	{
    		cin>>vec[i];
    	}

    	sort(vec.begin(),vec.end());
    	ll sum=0;
    	for(int i=0;i<n-k;++i)
    	{
    		sum+=vec[i];
    	}
    	cout<<sum<<endl;


    

}


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

int main()
{
    int N,ans=0,moves=0;
    cin >> N;
    vector<int> H(N+1);

    for(int i=1;i<=N;i++) {
        cin >> H[i];
    }

    for(int i=1;i<=N-1;i++) {
        if(H[i]>=H[i+1]) {
            moves++;
        }
        else {
            ans = max(ans,moves);
            moves = 0;
        }
    }
    ans = max(ans,moves);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
def operand(a, op, b):
    if op == '+':
        return int(a) + int(b)
    
    elif op == '-':
        return int(a)- int(b)

    
    elif op == '*':
        return int(a) * int(b)
    
    else:
        return int(a) // int(b) 

list = []
while True:
    a, op, b = map(str, input().split())
    if op == '?':
        break
    list.append([a, op, b])

for i in range(len(list)):
    print(operand(list[i][0], list[i][1], list[i][2]))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> h(n);
	rep(i,n) cin >> h.at(i);
	vector<int> dp(n+2,1000000000);
	dp[0]=0;
	rep(i,n){
		if(i+1<n) dp[i+1]=min(dp[i+1],dp[i]+(abs(h.at(i+1)-h.at(i))));
		if(i+2<n) dp[i+2]=min(dp[i+2],dp[i]+(abs(h.at(i+2)-h.at(i))));
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int>P;

int main() {
    int x,t,ans;
    cin>>x>>t;
    ans=x-t;
    cout<<(ans<0?0:ans)<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
flag = True
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            continue
        else:
            flag = False
            break
    else:
        continue

if flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38384
def solve(s1, s2):
    if len(s2) - len(s1) != 1:
        return "No"
    for i in range(len(s1)):
        if s1[i] != s2[i]:
            return "No"
    return "Yes"
s1 = input()
s2 = input()
print(solve(s1,s2))

Measured memory_bytes: 9000
#include<stdio.h>
#include<string.h>
int main(void)
{
	int a,n;
	char X[1000];
	scanf("%d\n",&n);
	for(a=0;a<n;a++)
	{
		gets(X);
		for(;;)
		{
			if(strstr(X,"Hoshino")==0)
				break;
			else
				strncpy(strstr(X,"Hoshino"),"Hoshina",7);
		}
		printf("%s\n",X);
	}
	return 0;
}

Measured memory_bytes: 588
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	vector<int>v;
	cin>>n;
	int A[n];
	for(int i=0; i<n; i++)
		cin>>A[i];
	v.push_back(A[0]);
	for(int i=1; i<n; i++){
		if(A[i]!=A[i-1])
			v.push_back(A[i]);
	}
	cout<<v[0];
	for(int i=1; i<v.size(); i++)
		cout<<" "<<v[i];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3828
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;                        // 任意長整数
using Real = mp::number<mp::cpp_dec_float<1024>>;// 仮数部が1024bitの浮動小数点数
#include<bits/stdc++.h>

using namespace std;
using ll = Bint;


int main()
{
    ll x, k, d; //xにいてk回d移動する
    cin >> x >> k >> d;
    if(x < 0)x = -x;
    if(x - k * d >= 0) {
        cout << x - d * k << endl;
    } else {
        ll num = x / d;
        if(num % 2 == k % 2) {
            cout << x - (x / d)*d << endl;
        } else {
            cout << -(x - (x / d + 1) * d) << endl;
        }
    }


}

Measured memory_bytes: 3696
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int c = scanner.nextInt();
			if ((n | c) == 0)
				break;
			int[] a = new int[n];
			int[] b = new int[c];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < 16; j++)
					a[i] += (scanner.nextInt() << j);
			for (int i = 0; i < c; i++)
				for (int j = 0; j < 16; j++)
					b[i] += (scanner.nextInt() << j);
			int[][] dp = new int[n + 1][1 << 16];
			for (int i = 0; i <= n; i++)
				Arrays.fill(dp[i], -1);
			dp[0][0] = 0;
			for (int i = 0; i < n; i++) {
				for (int S = 0; S < 1 << 16; S++) {
					if (dp[i][S] == -1)
						continue;
					int light = S | a[i];
					for (int j = 0; j < c; j++) {
						int pushed = light & b[j];
						int point = Integer.bitCount(pushed) + dp[i][S];
						int nx = light & ~b[j];
						dp[i + 1][nx] = Math.max(dp[i + 1][nx], point);
					}
				}
			}
			int max = 0;
			for (int i = 0; i < 1 << 16; i++)
				max = Math.max(max, dp[n][i]);
			System.out.println(max);

		}
	}
}

Measured memory_bytes: 60920