akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

struct Edge { // {{{
    int src, to;
    i64 cost;
    Edge(int src,  int to, i64 cost) : src(src), to(to), cost(cost) {}
    Edge(int to, i64 cost = 0) : Edge(-1, to, cost) {}
    Edge() {}
    bool operator< (const Edge &o) const { return cost < o.cost; }
    bool operator> (const Edge &o) const { return cost > o.cost; }
};
using Edges = vector<Edge>;
using WGraph = vector<vector<Edge>>;
using UGraph = vector<vector<int>>;
// }}}

    struct UnionFind { // {{{
        vector<int> u;
        explicit UnionFind(int n): u(n+5, -1) {}
        int  size(int i)        { return (-u[root(i)]); }
        int  root(int x)        { return (u[x] < 0)? x : u[x] = root(u[x]); }
        bool same(int x, int y) { return root(x) == root(y); }
        bool unite(int x, int y){ return (x=root(x)) == (y=root(y))? false : (u[x]+=u[y], u[y]=x, true); }
    }; // }}}

i64 kruskal(Edges &es, int V) // {{{
{
    UnionFind uf(V);
    i64 costSum = 0;

    sort(es.begin(), es.end());
    for (const auto &e : es) {
        if (uf.unite(e.src, e.to)) costSum += e.cost;
    }

    return costSum;
} // }}}

struct Node {
    int id;
    i64 x, y;
};

Node node[100010];

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

    int N;
    cin >> N;

    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        node[i] = {i, x, y};
    }

    Edges es;

    sort(node, node+N, [](const Node &a, const Node &b) { return a.x < b.x; });
    for (int i = 1; i < N; ++i) {
        es.emplace_back(node[i-1].id, node[i].id, node[i].x - node[i-1].x);
    }

    sort(node, node+N, [](const Node &a, const Node &b) { return a.y < b.y; });
    for (int i = 1; i < N; ++i) {
        es.emplace_back(node[i-1].id, node[i].id, node[i].y - node[i-1].y);
    }

    cout << kruskal(es, N) << endl;


    return 0;
}

// vim: set foldmethod=marker :


Measured memory_bytes: 8688
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;

int main() {
    int n,k;cin >> n >> k;
    int ans = 0;
    rep(i,n){
        if(i + k - 1 < n){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int n;
string s;
cin >> n;
cin >> s;
int ans = 0;
for(int i=0;i<1000;i++){
    int c[3] = {i/100,(i/10)%10,i%10};
    int step=0;
    for(int j=0;j<n;j++){
        if(s[j]==c[step]+'0')step++;
        if(step==3)break;
    }
    if(step==3)ans++;
}
fin(ans);

//////////////////////////////////////////////////////
return 0;}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1) cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1) cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD=1000000007;
const int INF=INT_MAX/3-1;
const double EPS=1e-9;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;


bool isnprime[20000000];

int main(){
    isnprime[0]=1;
    isnprime[1]=1;
    vi primes;
    for(int i=2;i<2000000;i++)
        if(!isnprime[i]){
            primes.push_back(i);
            for(int j=i*2;j<2000000;j+=i)
                isnprime[j]=1;
        }
    int k;
    while(cin>>k,k){
        auto it=lower_bound(ALL(primes),k);
        if(*it==k)
            cout<<0<<endl;
        else
            cout<<*it-*(it-1)<<endl;





    }
    return 0;
    }

Measured memory_bytes: 5576
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,a[100010],to[100010];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    { scanf("%d",&a[i]);
        to[a[i]]++;
    }
    int ans=0;
    for(int i=1;i<=100000;++i)
        ans=max(ans,to[i-1]+to[i]+to[i+1]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
function Main(input){
	var temp = 'Yes';
	input = input.split('');
	for(var i = 1; i < input.length+1;i++){
		if(i%2 == 0){
			if(input[i-1] === 'R'){
				temp = 'No';
				break;
			}
		} else {
			if(input[i-1] === 'L'){
				temp = 'No';
				break;
			}
		}
	}
	console.log(temp);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
from itertools import permutations
from heapq import heappush, heappop
def inpl(): return tuple(map(int, input().split()))
N, M, R = inpl()
inf = float("inf")
G = {n: {} for n in range(N+1)}
Des = inpl()

for _ in range(M):
    a, b, c = inpl()
    G[a][b] = c
    G[b][a] = c

def dijkstra(s):
    D = [inf for _ in range(N+1)]
    D[s] = 0
    HQ = [(0, s)]
    checked = [False for _ in range(N+1)]
    n = N + 1
    while HQ:
        c1, a = heappop(HQ)
        if D[a] < c1 or checked[a]: continue
        for b, c2 in G[a].items():
            if c1 + c2 < D[b]:
                D[b] = c1 + c2
                heappush(HQ, (D[b], b))
        checked[a] = True
        n -= 1
        if not n: break
    return [D[des] for des in Des]

C = []
for s in Des:
    C.append(dijkstra(s))

res = inf
for E in permutations(range(len(Des)), len(Des)):
    res = min(res, sum([C[E[i]][E[i+1]] for i in range(len(Des)-1)]))

print(res)

Measured memory_bytes: 6644
SUM = 7

def get_Operator(i):
    if i == 1: return "+"
    else: return "-"
def solve(S):
    n = [int(c) for c in S]
    operators = [1, -1]
    for i in operators:
        for j in operators:
            for k in operators:
                if(n[0] + i * n[1] + j * n[2] + k * n[3] == SUM):
                    foamula = (str(n[0]) + get_Operator(i) + str(n[1]) + get_Operator(j) + str(n[2]) + get_Operator(k) + str(n[3]) + "=7")
                    return foamula
def main():
    S = input()
    print(solve(S))
    
main()

Measured memory_bytes: 3064
//🤦‍♀️🤦‍♀️😒
#include<iostream>
using namespace std;
int main()
{
  int a[3];
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
  }int f=0,s=0;
  for(int i=0;i<3;i++)
  {
    if(a[i]==5)
      ++f;
    else if(a[i]==7)
      ++s;
    else 
      break;
  }
  if(f>=2 && s>=1)
  {
    cout<<"YES";
  }
  else
    cout<<"NO";
}


Measured memory_bytes: 3568
from math import floor
N,A,B,C,D = map(int,input().split())
mod = 10**9+7
factorials = [None for i in range(N+1)]
factorials[0] = 1
for i in range(1, N+1):
    factorials[i] = (factorials[i-1]*i) % mod
def inv(x):
    ret = 1
    k = mod - 2
    y = x
    while k:
        if (k & 1):
            ret = (ret * y) % mod
        y = (y * y) % mod
        k //= 2
    
    return ret

finv = [0]*(N+1)
finv[N] = inv(factorials[N])
for i in range(N, 0, -1):
    finv[i-1] = (finv[i]*i)%mod
def calc(i,j,k):
    tmp = finv[N-j]
    tmp = (tmp*finv[k])%mod
    tmp = (tmp*factorials[N-j+i*k])%mod
    y = finv[i]
    ret = 1
    while k:
        if (k & 1):
            ret = (ret * y) % mod
        y = (y * y) % mod
        k //= 2
    return (ret*tmp) % mod

dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(B+1):
    dp[i][0] = 1
ls = [0]+list(range(C,D+1))
l = len(ls)
for i in range(A,B+1):
    for j in range(1,N+1):
        tmp = 0
        for k in ls:
            if k > j/i:
                break
            tmp = (tmp + dp[i-1][j-i*k]*calc(i,j,k)) % mod
        dp[i][j] = tmp
print(dp[B][N])

Measured memory_bytes: 50652
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

int t[200][200];
int gxx,gyy;
int dfs(int x,int y,int c){
	if( t[y][x] != c ) return false;
	if( y == gyy && x == gxx) {
		return true;
	}
	t[y][x] = 0;
	if( dfs(x+1,y,c) ) return true;
	if( dfs(x-1,y,c) ) return true;
	if( dfs(x+0,y-1,c) ) return true;
	if( dfs(x+0,y+1,c) ) return true;
	
	return false;

}
int main(){
	int w,h;
	while(cin >> w >> h && w ){
		memset(t,0,sizeof(t));
		int xs,ys,xg,yg;
		cin >> xs >> ys >> xg >> yg;
		gxx = xg;
		gyy = yg;
		int n;
		cin >> n;
		for(int _ = 0 ; _ < n ; _++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			if(!d){
				rep(i,2)rep(j,4) t[y+i][x+j] = c;
			}else{
				rep(i,4)rep(j,2) t[y+i][x+j] = c;
			}
		}
		if( t[ys][xs] == 0 ){
			cout << "NG" << endl;
		}else{
			cout << (dfs(xs,ys,t[ys][xs])?"OK":"NG") << endl;
		}
		
	}
}

Measured memory_bytes: 1320
use std::cmp::min;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: u64 = read();
    let b: u64 = read();
    let n: u64 = read();
    let x = min(b - 1, n);
    println!("{}", a*x/b);
}

Measured memory_bytes: 2104
/*宣言*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main()
{
	int h, w, a[26][26];
	int x, y, ans[26][26] = { 0 }, kyo;
	cin >> h >> w;
	rep(i, h)
	{
		rep(j, w)
		{
			cin >> a[i][j];
		}
	}
	for (x = 0; x < h; x++)
	{
		for (y = 0; y < w; y++)
		{
			for (int i = 0; i < h; i++)
			{
				{
					for (int j = 0; j < w; j++)
					{
						{
							kyo = 0;
							if (i < x&&j < y)
								kyo = min(x - i, y - j);
							if (i < x&&j > y)
								kyo = min(x - i, j - y);
							if (i > x&&j < y)
								kyo = min(i - x, y - j);
							if (i > x&&j > y)
								kyo = min(i - x, j - y);
							ans[x][y] += kyo*a[i][j];
						}
					}
				}
			}
		}
	}
	int anss = 100000000;
	rep(i, h)
	{
		rep(j, w)
		{
			if (anss > ans[i][j])
				anss = ans[i][j];
		}
	}
	cout << anss << endl;
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    string a;
    int ca = 0;
    int cb = 0;
    int cc = 0;
    int cd = 0;
    string ac = "AC";
    string wa = "WA";
    string tle = "TLE";
    string re = "RE";
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a == ac){
            ca++;
        }
        else if(a == wa){
            cb++;
        }
        else if(a == tle){
            cc++;
        }
        else if(a == re){
            cd++;
        }
    }

    cout << "AC" << " " << "x" << " " << ca << endl;
    cout << "WA" << " " << "x" << " " << cb << endl;
    cout << "TLE" << " " << "x" << " " << cc << endl;
    cout << "RE" << " " << "x" << " " << cd << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int func(int x){
    if(x % 2 == 0){
        return x/2;
    }
    else{
        return 3 * x + 1;
    }
}


int main(){
    int s;
    int a[10000];
    for(int i=0; i<10000; i++) a[i] = 0;

    cin >> s;
    int tmp = s;
    int num = 1;
    while(1){
        if(a[tmp] == 1) break;
        else a[tmp] = 1;
        
        tmp = func(tmp); num++;
    }
    cout << num << endl;
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl

ll n;
ll a[200001];
bool isOK(ll m){
  stack<pii> st;
  REP(i,n){
    // a[i+1]>a[i]なら末尾に1をa[i+1]-a[i]個足すだけ
    if(a[i+1]>a[i]){
      st.push(make_pair(1,a[i+1]-a[i]));
      continue;
    }
    // pcは削る文字数
    ll pc = a[i] - a[i+1];
    // 文字列の長さをa[i+1]に揃える
    while(!st.empty() && pc>0){
      pii tp = st.top();
      st.pop();
      if(pc<tp.second){
        st.push(make_pair(tp.first,tp.second-pc));
      }
      pc = max(pc-tp.second,(ll)0);
    }

    // 以降は+1を試みる（可能ならする）操作

    // 末尾にmが並んでる場合全部popして、popした桁数をmisslenに記録しておく
    ll misslen = 0;
    while(!st.empty() && st.top().first>=m){
      misslen += st.top().second;
      st.pop();
    }
    // 全ての桁がmだった場合は+1出来ないので失敗
    if(st.empty()) return false;

    // この時点で+1可能なことは確定しているので、+1の操作を行う
    // mより小さい、最も後ろにある文字を+1する
    pii tp = st.top();
    st.pop();
    if(tp.second>1) st.push(make_pair(tp.first,tp.second-1));
    st.push(make_pair(tp.first+1,1));
    // popした桁を1で補完する
    if(misslen>0) st.push(make_pair(1,misslen));
  }
  return true;
}
int main() {
  cin >> n;
  REP(i,n) cin >> a[i+1];

  // めぐる式二分探索（今回は解の値域が1以上n以下で、nはOKが確定）
  ll ok=n,ng=0;
  while(abs(ok-ng)>1){
    ll m = (ok+ng)/2;
    if(isOK(m)) ok = m;
    else ng = m;
  }

  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    ll N, K;
    cin >> N >> K;
    int *A = new int[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    sort(A, A+N);

    int sum = 0;
    for(int i = 0; i < K; i++){
        sum += A[i];
    }

    cout << sum << endl; 
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	string s;cin>>s;
	int x,y;cin>>x>>y;
	vector<int> g,h; g.push_back(0);
	bool flag = true;
	for(char c:s){
		if(c == 'F') (flag ? g : h).back()++;
		else{
			flag ^= 1;
			(flag ? g : h).push_back(0);
		}
	}
	int dpx[17000],dpy[17000];
	rep(i,0,17000){ dpx[i] = -1; dpy[i] = -1; }
    dpx[8000] = 0; dpy[8000] = 0;
	dpx[g[0] + 8000] = 1;
	rep(i,1,g.size()){
		int rec[17000] = {};
		rep(j,0,17000){
			if(dpx[j] == i){
				if(j + g[i] < 17000) rec[j + g[i]] = 1;
				if(j - g[i] >= 0) rec[j - g[i]] = 1;
			}
		}rep(j,0,17000){
			if(rec[j]) dpx[j] = i + 1;
		}
	}rep(i,0,h.size()){
		int rec[17000] = {};
		rep(j,0,17000){
			if(dpy[j] == i){
				if(j + h[i] < 17000) rec[j + h[i]] = 1;
				if(j - h[i] >= 0) rec[j - h[i]] = 1;
			}
		}rep(j,0,17000){
			if(rec[j]) dpy[j] = i + 1;
		}
	}
	if(dpx[x + 8000] == g.size() && dpy[y + 8000] == h.size()){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 512
fun main(args:Array<String>) {
  val n = readLine()!!
  val b1 = n.toList().map(Char::toString).map(String::toInt).sum()
  val b2 = n.toInt()

  when( b2%b1 ) { 
    0 -> "Yes" 
    else -> "No"
  }.run(::println)
}

Measured memory_bytes: 33824
import Data.List
import Text.Printf

xyToIndx n x y = x + y * n

setValue n x y v sq = (take i sq) ++ [v] ++ (drop (i+1) sq)
    where i = xyToIndx n x y

isFilled n x y sq = (sq!!(xyToIndx n x y))/=0

findPos :: Int->Int->Int->[Int]->(Int,Int)
findPos n x y sq
    | x<0               = findPos n (n-1) y sq
    | x>=n              = findPos n 0 y sq
    | y>=n              = findPos n x 0 sq
    | isFilled n x y sq = findPos n (x-1) (y+1) sq
    | otherwise         = (x,y)

buildSquare :: Int->Int->Int->Int->[Int]->[Int]
buildSquare n x y v sq
    | v==(n*n)  = sq
    | otherwise = buildSquare n x' y' v' $ setValue n x' y' v' sq
        where (x',y') = findPos n (x+1) (y+1) sq
              v' = v + 1

initSquare :: Int->[Int]
initSquare n = buildSquare n x y 1 sq
    where x = (n-1) `div` 2
          y = (n-1) `div` 2 + 1
          sq = setValue n x y 1 $ take (n*n) $ repeat 0

printSquare :: Int->[Int]->IO ()
printSquare n [] = return ()
printSquare n sq = do
    let sq' = take n sq
    let sq'' = drop n sq
    mapM_ (printf "%4d") sq'
    printf "\n"
    printSquare n sq''

solve :: Int -> IO ()
solve n = do
    printSquare n (initSquare n)

main = do
    str <- getContents 
    mapM_ solve $ takeWhile (/=0) $map (\x->read x::Int) $ lines $ str

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

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

    int cnt = 0;
    int tmp = 0;
    while(tmp < N){
        tmp += 1 + 2*D;
        cnt++;
    }

    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
using namespace std;
int A[105];
int main()
{
    // std::ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
	int n,i,j,mini=INT_MAX,cost;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>A[i];
	for(i=-100;i<=100;i++){
		for(j=cost=0;j<n;j++)
			cost+=(i-A[j])*(i-A[j]);
		mini=min(mini,cost);
	}
	cout<<mini;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans = 0
prev = 0
s = []
for a in A:
    now = prev + a
    s.append(now)
    prev = now

start = 0
last = s[-1]
for i in s[:-1]:
    ans += (i - start) * (last - i)
    start = i
    
    
print(ans%(10**9+7))

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> A(N),B(N),C(N);
  
  for(int i=0;i<N;i+=2){
    A[i] = K;
    K++;
  }
  for(int i=1;i<N;i+=2){
    A[i] = K;
    K++;
  }
  for(int i=1;i<N;i+=2){
    B[i] = K;
    K++;
  }
  for(int i=0;i<N;i+=2){
    B[i] = K;
    K++;
  }
  for(int i=0;i<N;i++){
    C[i] = K;
    K++;
  }
  
  for(int i=0;i<N;i++){
    if(A[i]+B[i]>C[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  for(int i=0;i<N;i++) cout << A[i] << " " << B[i] << " " << C[i] << endl;
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef std::vector<ll> vi;
int visited[100005] = {0} ;
long long int ans = 0 ;
long long int n , c ;



int main() {

  cin >> n >> c ;
  long long int total[n + 1] = {0};
  std::vector< pair<long long int , long long int > > a ;
  for (int i = 0; i < n; ++i)
  {
    long long int rr,  ff ;

    cin >> rr >> ff ;
    a.push_back(pair<long long int , long long int>(rr, ff));

  }
  a.push_back({0, 0});
  sort(a.begin(), a.end() );

  for (int i = 1; i <= n; ++i)
  {

    total[i] = total[i - 1] + a[i].second ;
  }

  long long best[n + 1] = {0};
  long long best2[n+1] = {0};
  long long curbest = 0 ;
  long long curbest2 = 0 ;
  for (int i = 1; i <= n; ++i)
  {
    curbest = max(curbest , total[i - 1] - ( 2* a[i - 1].first));
    best[i] = curbest;
    curbest2 = max(curbest2 , total[i - 1] - (  a[i - 1].first));
    best2[i] = curbest2;

  }
  long long b[n + 1] = {0};

  for (int i = 1; i <= n; ++i)
  {
    b[i] = total[n] - total[i - 1];
  }

  for (int i = 0; i <= n; ++i)
  {
    ans = max(total[i] - a[i].first, ans);
  }
  for (int i = 0; i <= n; ++i)
  {
    ans = max(total[n] - total[i] - c +  a[i].first , ans);
  }
  for (int i = 0; i <= n; ++i)
  {
    ans = max(best[i] + b[i] -  (c - a[i].first) , ans);
    ans = max(best2[i] + b[i] - 2 *  (c - a[i].first) , ans);
  }








  cout << ans << endl;


}


Measured memory_bytes: 5104
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e9+7;
const int MAX_SIZE = 3e3+5;

char a[MAX_SIZE], b[MAX_SIZE];

void max_self(pair<int,ii>& f, const int score, const ii pos) {
    if(f.first < score) {
        f.first = score;
        f.second = pos;
    }
}

int main() {
    
    scanf("%s",a);
    scanf("%s",b);
    
    int sa = strlen(a);
    int sb = strlen(b);
    
    vector<vector<pair<int,ii>>> dp(MAX_SIZE);
    
    for(int i = 0; i <= sa; ++i) {
        dp[i].assign(MAX_SIZE, pair<int,ii>(0, ii(-1, -1)));
    }
    
    for(int r = 0; r < sa; ++r) {
        for(int c = 0; c < sb; ++c) {
            
            if(a[r] == b[c]) {
                max_self(dp[r+1][c+1], dp[r][c].first+1, ii(r, c));
            }
            
            max_self(dp[r+1][c], dp[r][c].first, ii(r, c));
            max_self(dp[r][c+1], dp[r][c].first, ii(r, c));
        }
    }
    
    //~ debug() << imie(dp);
    
    ii pos = ii(-1, -1);
    int mx = 0;
    
    for(int r = 0; r <= sa; ++r) {
        for(int c = 0; c <= sb; ++c) {
            if(dp[r][c].first > mx) {
                mx = dp[r][c].first;
                pos = ii(r, c);
            }
        }
    }
    
    string s = "";
    
    while(pos != ii(-1, -1)) {
        ii newPos = dp[pos.first][pos.second].second;
        if(newPos != ii(-1, -1) && newPos == ii(pos.first-1, pos.second-1)) {
            s += a[newPos.first];
            assert(a[newPos.first] == b[newPos.second]);
        }
        pos = newPos;
    }
    
    if(s.size() > 0) reverse(s.begin(), s.end());
    
    cout << s << endl;
    
    //~ printf("%d\n", max(dp[sa][sb].first, max(dp[sa][sb-1].first, dp[sa-1][sb].first)));
    
    return 0;
}




Measured memory_bytes: 106112
#include <bits/stdc++.h>
#define debug(x) //cout << #x << " = " << x << endl;
#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long ll;

ll start(const string a, const string b){
  if( a[0] == b[0] )
    return 3LL;
  else
    return 6LL;
}

ll transition(const string a, const string b, int i){
  if( a[i] == b[i] ){
    if( a[i+1] == b[i+1] ) return 2LL;
    else return 2LL;    
  }else{
    if( a[i+1] == b[i+1] ) return 1LL;
    else return 3LL;
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  
  //const ll mod = 1000000007;
  const ll mod = 1e9+7;

  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;

  ll ans = start(s1, s2);
  debug(ans);

  int i = 0;
  if( ans == 6 )
    i++;

  while( i < s1.size()-1 ){
    ll tr = transition(s1, s2, i);
    ans = (ans*tr)%mod;
    debug(ans);
    if( s1[i+1] == s2[i+1] )
      i++;
    else
      i += 2;
    if( i == s1.size()-1) break;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
    int n;
    int cnt=0;
    scanf("%d",&n);
    while(n--)
    {
        int x;
        scanf("%d",&x);
        while(x%2==0)
        {
            cnt++;
            x/=2;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

        long N = scanner.nextLong();
        long A = scanner.nextLong();
        long B = scanner.nextLong();

        // N = (A + B) * x + c
        // ans = A * x + min(A, c)
        long x = N / (A + B);
        long c = N % (A + B);
        System.out.println(A * x + Math.min(A, c));

    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
using ll=long long;

int main(){
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<s.size();i++){
        s[i]+=n;
        if(s[i]>90){
            s[i]-=26;
        }
        cout<<s[i];
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int[] aeve = new int[(n+1)/2];
        
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
            if(i%2==0){
                aeve[i/2] = a[i];
            }
        }
        
        Arrays.sort(a);
        
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i=0; i<n; i++){
            map.put(a[i], i%2);
        }
        
        long cnt = 0L;
        for(int i=0; i<aeve.length; i++){
            cnt += map.get(aeve[i]);
        }
        
        System.out.println(cnt);
        
    }
}


Measured memory_bytes: 48784
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
 
using namespace std;
 
struct segtree {
    vector<long long> dat;
    int n;
 
    segtree(int n_) {
        n = 1;
 
        while (n < n_) n *= 2;
 
        dat.resize(2*n, 0);
    }
 
    void update(int i, int x) {
        i += n - 1;
        int diff = x - dat[i];
        dat[i] = x;
 
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] += diff;
        }
    }
 
    long long query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r == -1) r = n;
 
        if (r <= a || l >= b) return 0;
 
        if (a <= l && r <= b) {
            return dat[k];
        }
 
        long long lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
        long long rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
 
        return lv + rv;
    }
};

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

    int N; cin >> N;
    vector<int> a(N), b(N);
 
    segtree P(N), Q(N);
    vector<pair<int, int>> A, B;
 
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
        A.push_back(make_pair(a[i], b[i]));
    }
 
    sort(begin(A), end(A));
 
    for (int i = 0; i < N; ++i) {
        B.push_back(make_pair(A[i].second, i));
    }
 
    sort(begin(B), end(B));
     
    for (int i = 0; i < N; ++i) {
        P.update(i, A[i].first);
        Q.update(i, 1);
    }
 
    long long ma = 0;
 
    for (pair<int, int>& d : B) {
        int l = 0, r = N;

        long long PP, QQ;
 
        for (int j = 0; j < 20; ++j) {
            int mid = (l + r) / 2;

            PP = P.query(0, mid + 1);
            QQ = Q.query(0, mid + 1);
 
            if (PP <= d.first * QQ) {
                l = mid;
            } else {
                r = mid;
            }
        }
 
        if (PP <= d.first * QQ) {
            ma = max(ma, QQ);
        }
 
        P.update(d.second, 0);
        Q.update(d.second, 0);
    }
 
    cout << ma << endl;
}

Measured memory_bytes: 29916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  rep(i,N)cin >> v[i];
  int maxi = 0;
  vector<int> w(N,0);
  rep(i,N-1){
    if(v[i]>=v[i+1]){
      w[i+1] = w[i]+1;
    }
  }
  rep(i,N) maxi = max(maxi,w[i]);
  cout << maxi << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(int(s.at(i))+n<=90){
            cout<<char((int)s.at(i)+n);
        }
        else{
            cout<<char((int)s.at(i)+n-90+64);
        }
    }

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        List<Integer> integers = new ArrayList<>();
        try (Scanner scanner = new Scanner(System.in)) {
            while (scanner.hasNextInt()) {
                integers.add(scanner.nextInt());
            }
        }
        integers.sort(Comparator.reverseOrder());
        integers.stream()
                .limit(3)
                .forEach(System.out::println);
    }
}

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int k = 0;
    cin >> k;
    string ans = "";
    rep(i, k) {
        ans += "ACL";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3512
<?php
$n = intval(fgets(STDIN));
$str = trim(fgets(STDIN));
$Q = intval(fgets(STDIN));


function op($a, $b){return $a | $b;}

for($i = 0; $i < $n; $i++){
  $array[] = 1<<(ord($str[$i])-97);
}
$seg = new SegTree($array);

while($Q--){
  list($q, $a, $b) = explode(" ", trim(fgets(STDIN)));
  if($q == "1"){
    $seg->set($a-1, 1<<(ord($b)-97));
  }else{
    $ret[] = popcount($seg->get($a-1, $b));
  }
}
echo implode("\n", $ret);


class SegTree{
  public $tree;
  public $bits;
  function __construct($n){
    if(is_array($n)){
      $array = $n;
      $n = count($array);
      $this->bits = max(1, ceil(log($n)/log(2)));
      for($i = $n, $I = 2**$this->bits; $i < $I; ++$i){
        $array[] = 0;
      }
      $this->tree[0] = $array;
      $this->rollupAll();
    }else{
      $this->bits = max(1, ceil(log($n)/log(2)));
      for($i = 0; $i < $this->bits; ++$i){
        $this->tree[$i] = array_fill(0, 2**($this->bits-$i), 0);
      }
    }
  }
  function rollupAll(){
    for($i = 1; $i < $this->bits; ++$i){
      for($j = 0, $J = 2**($this->bits - $i); $j < $J; $j++){
        $this->tree[$i][$j] = op($this->tree[$i-1][($j<<1)], $this->tree[$i-1][($j<<1)+1]);
      }
    }
  }
  function set($i, $amount){
    $this->tree[0][$i] = $amount;
    for($j = 1, $J = $this->bits; $j < $J; ++$j){
      $this->tree[$j][$i>>$j] = op($this->tree[$j-1][$i>>$j<<1], $this->tree[$j-1][($i>>$j<<1) + 1]);
    }
  }
  function get($f, $t){
    $sum = 0;
    $tree = $this->tree;
    $bits = $this->bits;
    $i = 0;
    while($f!=$t){
      $treei = $tree[$i];
      if(($f >> $i) & 1 == 1){
        $sum = op($sum, $treei[$f>>$i]);
        $f+=1<<$i;
      }
      if(($t >> $i) & 1 == 1){
        $sum = op($sum, $treei[($t>>$i)-1]);
        $t-=1<<$i;
      }
      ++$i;
    }
    return $sum;
  }
}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 55912
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
void mul(int &a, int b) {
	a = (a * 1ll * b) % mod;
}
int solve(int a, int b) {
	int n = a + b;
	int ans = 1;
	for (int i = 1; i <= n; i++) {
		if (i & 1) {
			mul(ans, a);
			a--;
		} else mul(ans, b), b--;
	}
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	int ans = (solve(n, m) + solve(m, n)) % mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
mes = {11:"a",12:"b",13:"c",14:"d",15: "e",21:"f",22:"g",23:"h",24:"i",25:"j"
    ,31:"k",32:"l",33:"m",34:"n",35:"o",41:"p",42:"q",43:"r",44:"s",45:"t"
    ,51:"u",52:"v",53:"w",54:"x",55:"y",61:"z",62:".",63:"?",64:"!",65:" "}
while True:
    try:N=input()
    except:break
    if len(N) % 2 == 1:print("NA");continue
    word=""
    for i in range(0,len(N),2):
        if int(N[i:i + 2]) in mes:word +=mes[int(N[i:i + 2])]
        else:word="NA";break
    print(word)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin >>a>>b>>c;

int d = b-a+1;

if(d >= a){
	cout << "OK" <<endl;
}
else if(b %a == 0||c%a ==0)cout << "OK" <<endl;
else{
	cout << "NG" <<endl;
}

}

Measured memory_bytes: 3632
import java.util.*;

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

      if(s.equals(t.substring(0, s.length())) && t.length()-s.length()==1){
          System.out.println("Yes");
      }else
          System.out.println("No");



    }
}


Measured memory_bytes: 35680
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll onenum[ohara];
ll rui[ohara];
pair<pair<ll,ll>,ll> p[100];
ll p_cou=0;
ll tans=0;
ll dp[ohara+100000];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n)cin>>a[i];
    /////
    cnt=2;
    rui[0]=1;
    rrep(i,1,45){
        rui[i]=cnt;
        cnt*=2;
    }
    /////
    rep(i,n){
        ll pos=a[i];
        while(1){
            if(pos==0)break;
            if(pos==1){onenum[0]++;break;}
            rrrep(i,44,1){
                if(pos>=rui[i]){
                    pos%=rui[i];
                    onenum[i]++;
                    break;
                }
            }
        }
    }

    cnt=0;

    rrrep(i,44,0){
        if(onenum[i]<n-onenum[i]){
            p[cnt++]=make_pair(make_pair((n-onenum[i])*rui[i],(onenum[i])*rui[i]),rui[i]);
        }
        else{
            p[cnt++]=make_pair(make_pair((onenum[i]*rui[i]),0LL),0);
        }
    }
    sort(p,p+cnt);
    reverse(p,p+cnt);
    ll val=0;
    rep(i,cnt){
        //cerr<<p[i].fi<<" "<<p[i].se<<"\n";
        if(val+p[i].se>k)ans+=p[i].fi.se;
        else{
        val+=p[i].se;
        ans+=p[i].fi.fi;
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 8448
s = input()

if len(s) % 2 == 1:
    s_1 = s[:len(s)//2]
    s_2 = ''.join(list(reversed(s[len(s)//2+1:])))
else:
    s_1 = s[:len(s)//2]
    s_2 = ''.join(list(reversed(s[len(s)//2:])))
    
c = 0
for i in range(len(s_1)):
    if(s_1[i] != s_2[i]):
        c += 1

print(c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define re register
int to[60][60],to1[60][60],tt[60][60],nm[60],nm1[60],d[60],ans,ff[60],in[60];
void dfs1(re int a,re int fa)
{
	ff[a]=fa;
	for(re int i=1;i<=nm1[a];i++)
	{
		re int x=to1[a][i];
		if(x==fa)continue;
		dfs1(x,a);
	}
}
void dfs(re int a,re int fa)
{
	in[a]=1;
	for(re int i=1;i<=nm[a];i++)
	{
		re int x=to[a][i];
		if(x==fa)continue;
		if(tt[a][x])dfs(x,a);
	}
}
int main()
{
	re int n,t;
	scanf("%d",&t);
	for(;t--;)
	{
		ans=1<<20;
		re int x,y;
		scanf("%d",&n);
		for(re int i=1;i<=n;i++)nm[i]=nm1[i]=0;
		memset(tt,0,sizeof(tt));
		for(re int i=1;i<n;i++)
		{
			scanf("%d%d",&x,&y);
			to[x][++nm[x]]=y;
			to[y][++nm[y]]=x;
		}
		for(re int i=1;i<n;i++)
		{
			scanf("%d%d",&x,&y);
			tt[x][y]=tt[y][x]=1;
			to1[x][++nm1[x]]=y;
			to1[y][++nm1[y]]=x;
		}
		for(re int i=1;i<=n;i++)
		{
			dfs1(i,0);
			for(re int j=1;j<=n;j++)in[j]=0,d[j]=nm[j];
			dfs(i,0);
			re int num=0;
			while(1)
			{
				re int j;
				for(j=1;j<=n;j++)if(d[j]<=1&&!in[j]&&in[ff[j]])break;
				if(j>n)break;
				in[j]=1;
				for(re int jj=1;jj<=nm[j];jj++)d[to[j][jj]]--;
				num++;
			}
			re int j;
			for(j=1;j<=n;j++)if(!in[j])break;
			if(j>n)ans=min(ans,num);
			for(re int j=1;j<=n;j++)d[j]=nm[j],in[j]=0;
			in[0]=1;
			while(1)
			{
				re int j;
				for(j=1;j<=n;j++)if(d[j]<=1&&!in[j]&&in[ff[j]])break;
				if(j>n)break;
				in[j]=1;
				for(re int jj=1;jj<=nm[j];jj++)d[to[j][jj]]--;
			}
			for(j=1;j<=n;j++)if(!in[j])break;
			if(j>n)ans=min(ans,n);
		}
		if(ans!=(1<<20))printf("%d\n",ans);
		else puts("-1");
	}
}

Measured memory_bytes: 256
import math
import pprint
import fractions
import collections
import itertools
N,M,X=map(int,input().split())
books=[list(map(int,input().split())) for _ in range(N)]
mincost=float("inf")
cando=0
for i in range(pow(2,N)):
    bit=[0]*N
    cost=0
    skill=[0]*M
    flag=1
    for j in range(N):
        if (i>>j)&1:
            bit[j]=1
    #print(bit)
    for j in range(N):
        if bit[j]==1:
            cost=cost+books[j][0]
            for k in range(1,M+1):
                skill[k-1]=skill[k-1]+books[j][k]
    for j in range(M):
        if skill[j]<X:
            flag=0
    if flag==1:
        mincost=min(mincost,cost)
        cando=1
if cando==1:
    print(mincost)
else:
    print("-1")

Measured memory_bytes: 73432
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll a,p;
	rl2(a,p);
	p+=3*a;
	p/=2;
	wl(p);
	NL;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
#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 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 / 2;
    } else {
        return modpow(m, n - 1) * m;
    }
}

int main() {
    int a, b;
    cin >> a >> b;
    if (a == b){
        for (int i = 0; i < a; i++){
            cout << b;
        }
    }else if(a > b){
        for (int i = 0; i < a; i++){
            cout << b;
        }
    }else{
        for (int i = 0; i < b; i++){
            cout << a;
        }  
    }
}

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

double x[55], y[55];
double len(double x, double y) {
  return sqrt(x*x + y*y);
}
double dist(int i, int j) {
  return len(x[i] - x[j], y[i] - y[j]);
}
bool obtuse(double ax, double ay, double bx, double by) {
  return ax*bx + ay*by >= 0;
}
bool obtuse(int i, int j, int k) {
  return obtuse(x[j] - x[i], y[j] - y[i], x[k] - x[j], y[k] - y[j]);
}

int main() {
#ifdef LOCAL_EXEC
//    freopen("sample.in", "r", stdin);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#endif

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  double ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      ans = max(ans, dist(i, j)/2);
      for (int k = 0; k < n; k++) {
        if (k == i || k == j) continue;
        if (obtuse(i, j, k) || obtuse(j, k, i) || obtuse(k, i, j)) continue;
        double a = dist(i, j), b = dist(j, k), c = dist(k, i);
        double s = (a + b + c)/2;
        double area = sqrt(s*(s - a)*(s - b)*(s - c));
        if (area < 1e-16) continue;
        double r = (a*b*c)/(4*area);
        ans = max(ans, r);
      }
    }
  }
  cout << fixed << setprecision(10) << ans << '\n';

	return 0;
}

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

#define     int long long
#define     pii pair<int,int>
#define     x first
#define     y second
#define     __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define     MOD 1000000007
#define     INF 100000000
#define     nll cout << "\n"
#define     nl "\n"
#define     MAX 10000003
#define     print(v) cout << v << " "
#define     dbgv(v) cout << v << nl
#define     asdf(v) cout << v << nl
#define     pasdf(p) cout << p.x << " " << p.y << nl
#define     dbg cout << "dbg\n"
#define     vi vector<int>
#define     vl vector<ll>
#define     pb push_back
#define     con continue


int xx[] = {-1, -1, -1, 1, 1, 1};
int yy[] = {-1, 0, 1, -1, 0, 1};

int smallPrimeFactor[MAX];

void seive(){
    for(int i = 1; i < MAX; i++){
        smallPrimeFactor[i] = i;
    }
    for(int i = 2; i < MAX; i++){
        if(smallPrimeFactor[i] == i){
            for(int j = i*2; j < MAX; j+=i){
                smallPrimeFactor[j] = min(i, smallPrimeFactor[j]);
            }
        }
    }
}

int NOD(int n){
    int nod = 1;
    while(smallPrimeFactor[n] != n){
        int pf = smallPrimeFactor[n];
        int cnt = 0;
        while(n%pf == 0){
            cnt++;
            n /= pf;
        }
        nod = nod*(cnt+1);
    }
    if(n > 1)nod*=2;
    return nod;
}

int32_t main(){
    seive();
    int n;
    while(cin >> n){
        int ans = 1;
        for(int i = 2; i <= n; i++){
            ans = ans + i*NOD(i);
        }
        asdf(ans);
    }
    return 0;
}


Measured memory_bytes: 81700
import collections

N = input().strip()
N = int(N)
dic = collections.defaultdict(lambda: 0)

for i in range(N):
    x,y = input().strip().split(" ")
    x = int(x)
    y = int(y)

    dic[y] += x

prev_time = 0
result = "Yes"

for k,v in sorted(dic.items(),key=lambda x:x[0]):
    if v+prev_time > k:
        result = "No"
        break
    prev_time += v

print(result)

Measured memory_bytes: 44216