akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void)
{
	int n, a, b, c, *ml, f1, f2, goukei, temp, max;
	
	scanf("%d",&n);
	
	scanf("%d %d",&a, &b);

	ml = new int [n];
		
	scanf("%d",&c);
	
	for(f1 = 0; f1 < n; f1++)
		scanf("%d",&ml[f1]);
	//??????????????°?????????????????????	
	for(f1 = 0; f1 < n-1; f1++){
		for(f2 = f1+1; f2 < n; f2++){
			if(ml[f1] < ml[f2]){
				temp = ml[f1];
				ml[f1] = ml[f2];
				ml[f2] = temp;
			}
		}
	}
	//??????????????°???????????????????????????1????????????????????????????????°
	max = c / a;

	for(f1 = 1; f1 <= n; f1++){
		goukei = 0;
		//?????????f1?????§?????????????????°???????????????
		for(f2 = 0; f2 < f1; f2++)
			goukei += ml[f2];
		//1????????????????????????????????°????¨????	
		goukei = (goukei + c) / (a + f1 * b);
		
		if(max < goukei)
			max = goukei;
			
	}
	
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 2688
M = 1000000007
fact = ->(x){ (1..x).inject{|x,s| x*s % M} }
n,m=gets.split.map(&:to_i).sort
if n == m
  puts (fact[n] * fact[m] * 2) % M
elsif n+1 == m
  puts (fact[n] * fact[m]) % M
else
  puts 0
end

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  string s;
  cin >> s;
  vector<int> ans(s.length());
  int fr = 0;
  while(fr < s.length()){
    int mid = find(s.begin() + fr, s.end(), 'L') - s.begin();
    int nex = find(s.begin() + mid, s.end(), 'R') - s.begin();
    int pos[2] = {mid,mid};
    if(mid % 2) pos[0]--;
    else pos[1]--;
    
    for(int i = fr; nex > i; i++){
      ans[pos[i%2]]++;
    }
    
    fr = nex;
  }
  for(auto itr : ans){
    cout << itr << " "; 
  }
  cout << endl;
  return 0; 
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }

    int n;
    string str;
    cin >> n >> str;

    int ans = n;

    rep(i, n - 1)
    {
        if (str[i] == str[i + 1])
            --ans;
    }

    cout << ans << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(){
  int W,Q;
  while(cin>>W>>Q,W||Q){
    string s;

    vector<int> width(W,-1);
    while(Q--){
      cin>>s;
      if(s == "s"){
        int id,w;
        cin>>id>>w;
        int idwidth = 0;
        bool ok = false;
        REP(i,width.size()){
          if(width[i] == -1)idwidth++;
          else idwidth = 0;
          if(idwidth == w){
            ok = true;
            idwidth = i - w + 1;
            REP(ct,w)width[i - ct] = id;
            break;
          }
        }
        if(ok)cout << idwidth << endl;
        else cout << "impossible" << endl;
      }else{
        int id;
        cin>>id;
        REP(i,width.size()){
          if(width[i]==id)width[i] = -1;
        }
      }
    }
    cout << "END" << endl;
  }
  return 0;
}

Measured memory_bytes: 3108
fun main(args: Array<String>) {
    var n = readLine()!!.toLong()
    var c = Math.sqrt(n.toDouble())
    var min = n
    for (i in 1..c.toInt()){
        if (n % i == 0L && n / i + i - 2 < min) min = n / i + i - 2
    }
    println(min)
}

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

bool same(int idx,string &a){
  for(int i=0;i<a.size();i++){
    if(i+idx>str.size())return 0;
    if(str[idx+i]!=a[i])return 0;
  }
  return 1;
}

bool solve(){
  string dream="dream";
  string erase="erase";
  int i=0;
  while(i<str.size()){
    if(same(i,dream)){
      i+=dream.size();
      if(i==str.size())break;
      if(str[i]=='e'&&str[i+1]=='r'&&!same(i,erase))i+=2;
    }
    else if(same(i,erase)){
      i+=erase.size();
      if(i==str.size())break;
      if(str[i]=='r')i++;
    }
    else return 0;
  }
  return 1; 
}


int main(){
  cin>>str;
  cout<<(solve()? "YES":"NO")<<endl;;
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>

int main(){
    int H,W;
    while(1){
        scanf("%d%d",&H,&W);
        if(H==0 && W==0) break;
        for(int i=0;i<H;i++){
           for(int j=0;j<W;j++)
               printf("#");
           printf("\n");
        }
       printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2624
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define N '\n'
#define S ' '
#define Z '0'
#define RT return
#define elif else if
#define W(a) while(a)
#define RP(a,b,c) for(ll a=(b);a<(c);++a)
#define R(a,b) for(ll a=0;a<(b);++a)
#define RD(a,b) for(ll a=(b);a>=0;++a)
#define LI(a) for(auto &x:a)I(x)
#define P(a) cout<<"a"<<N
#define F(a) cout<<fixed<<setprecision(10)<<a
#define D(a,b,c) cout<<setfill(a)<<setw(b)<<right<<c
#define C cin.tie(0);ios::sync_with_stdio(false)
ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,v,w,x,y,z;
const int P[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
inline void I(){}
template<class T,class...A>inline void I(T&&t,A&&...a){cin>>t;I(move(a)...);}
template<class T>inline void O(T t){cout<<t<<N;}
template<class T,class...A>inline void O(T t,A...a){cout<<t<<S;O(move(a)...);}
inline ll dig(ll a){ll d=1;W(a/=10)++d;RT d;}
inline ll GCD(ll a,ll b){ll c;W(a){c=a;a=b%a;b=c;}RT b;}
inline bool isp(ll a){if(a<48){RP(i,0,15)if(P[i]==a)RT 1;}
    elif(a<2809)RT GCD(614889782588491410,a)==1;
    else {O("Error:Argument is Over-2808!");exit(1);}RT 0;}

int main(){
    C;
    ll A[3];
    LI(A);
    sort(A,A+3);
    O(abs(A[1]-A[0])+abs(A[2]-A[1]));
















}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    }
}

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

const int N=2010;
int cnt,n,m,ans,f[N],fu[N*2],d[N],del[N*2],vis[N],tp[N*2],a[N*2],b[N*2],tf[N*2];
list<int>L[N*2],li[N*2];
vector<int>g[N];
queue<int>q;
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<n;++i){
		int x,y;cin>>x>>y;
		g[x].push_back(y);g[y].push_back(x);
		++d[x];++d[y];
	}
	for(int i=1;i<=m;++i){
		cin>>a[i]>>b[i];
		li[a[i]].push_back(i);li[b[i]].push_back(i);
		L[a[i]].push_back(i);L[b[i]].push_back(i);
	}
	cnt=m;
	for(int i=1;i<=n;i++)if(d[i]<=1)q.push(i);
	for(int i=1;i<=n;i++)f[i]=i;
	while(!q.empty()){
		int x=q.front();q.pop();vis[x]=1;
		int u=-1,v=-1;
		for(;!li[x].empty();){
			int t=li[x].back();li[x].pop_back();
			if(del[t])continue;
			if(find(a[t])==find(b[t])){del[t]=1;tp[t]=0;continue;}
			if(u==-1)u=t;
			else{v=t;break;}
		}
		if(v==-1){if(u!=-1)li[x].push_back(u);}
		else{
			++cnt;a[cnt]=find(a[u])+find(b[u])-x;b[cnt]=find(a[v])+find(b[v])-x;
			li[a[cnt]].push_back(cnt);li[b[cnt]].push_back(cnt);
			fu[u]=fu[v]=cnt;del[u]=del[v]=1;
			if(find(b[u])==x)tf[u]=0;else tf[u]=1;
			if(find(a[v])==x)tf[v]=0;else tf[v]=1;
		}
		u=v=-1;
		for(;!L[x].empty();){
			int t=L[x].back();L[x].pop_back();
			if(find(a[t])==find(b[t]))continue;
			if(u==-1)u=t;
			else{v=t;break;}
		}
		if(u!=-1)++ans,L[x].push_back(u);if(v!=-1)++ans,L[x].push_back(v);
		for(int i:g[x])
			if(!vis[i]){
				f[x]=i;li[i].splice(li[i].end(),li[x]);L[i].splice(L[i].end(),L[x]);
				--d[i];if(d[i]==1)q.push(i);
			}
	}
	cout<<ans<<endl;
	for(int i=cnt;i;i--)if(fu[i])tp[i]=tp[fu[i]]^tf[i];
	for(int i=1;i<=m;++i){
		if(tp[i])swap(a[i],b[i]);
		cout<<a[i]<<' '<<b[i]<<'\n';
	}
	return 0;
}



Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
const int maxn=100005;
int n,m,a[maxn];
ll st[maxn],en[maxn],len[maxn],nowans,now;
int main() {
	scanf("%d%d",&n,&m);
	rep(i,1,n) {
		scanf("%d",a+i);
		if(i!=n) st[a[i]]++;
		if(i!=1) {
			en[a[i]]++;
			if(a[i]<a[i-1]) {
				nowans+=a[i];
				if(a[i-1]!=m) now++;
				len[a[i]]+=(a[i]+m-a[i-1])-1;
			}
			else nowans+=a[i]-a[i-1],len[a[i]]+=a[i]-a[i-1]-1;
		}
	}
	ll ans=1e18;
	nowans+=now;
	rep(i,1,m) {
		nowans-=now;
		now+=st[(i-2+m)%m+1]-en[i];
		ans=min(ans,nowans);
		nowans+=len[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2944
from collections import defaultdict
from bisect import bisect,bisect_left
N = int(input())
XYU = [input().split() for _ in range(N)]
for i in range(N):
    XYU[i][0] = int(XYU[i][0])
    XYU[i][1] = int(XYU[i][1])
dp = defaultdict(lambda :defaultdict(list))
dn = defaultdict(lambda :defaultdict(list))
d1 = defaultdict(lambda :defaultdict(list))
d2 = defaultdict(lambda :defaultdict(list))

for i in range(N):
    x,y,u = XYU[i]
    dp[u][x+y].append(x)
    dn[u][x-y].append(x)
    d1[u][x].append(y)
    d2[u][y].append(x)

for u in ['U','R','D','L']:
    for z in dp[u]:
        dp[u][z].sort()
    for z in dn[u]:
        dn[u][z].sort()
    for z in d1[u]:
        d1[u][z].sort()
    for z in d2[u]:
        d2[u][z].sort()

ans = float('inf')
for i in range(N):
    x,y,u = XYU[i]
    if u=='U':
        j = bisect_left(dp['R'][x+y],x)-1
        if j>=0:
            ans = min(ans,10*(x-dp['R'][x+y][j]))
        j = bisect(dn['L'][x-y],x)
        if j<len(dn['L'][x-y]):
            ans = min(ans,10*(dn['L'][x-y][j]-x))
        j = bisect(d1['D'][x],y)
        if j<len(d1['D'][x]):
            ans = min(ans,5*(d1['D'][x][j]-y))
    elif u=='D':
        j = bisect_left(dn['R'][x-y],x)-1
        if j>=0:
            ans = min(ans,10*(x-dn['R'][x-y][j]))
        j = bisect(dp['L'][x+y],x)
        if j<len(dp['L'][x+y]):
            ans = min(ans,10*(dp['L'][x+y][j]-x))
        j = bisect_left(d1['U'][x],y)-1
        if j>=0:
            ans = min(ans,5*(y-d1['U'][x][j]))
    elif u=='R':
        j = bisect(dp['U'][x+y],x)
        if j<len(dp['U'][x+y]):
            ans = min(ans,10*(dp['U'][x+y][j]-x))
        j = bisect(dn['D'][x-y],x)
        if j<len(dn['D'][x-y]):
            ans = min(ans,10*(dn['D'][x-y][j]-x))
        j = bisect(d2['L'][y],x)
        if j<len(d2['L'][y]):
            ans = min(ans,5*(d2['L'][y][j]-x))
    elif u=='L':
        j = bisect_left(dp['D'][x+y],x)-1
        if j>=0:
            ans = min(ans,10*(x-dp['D'][x+y][j]))
        j = bisect_left(dn['U'][x-y],x)-1
        if j>=0:
            ans = min(ans,10*(x-dn['U'][x-y][j]))
        j = bisect_left(d2['R'][y],x)-1
        if j>=0:
            ans = min(ans,5*(x-d2['R'][y][j]))

if ans==float('inf'):
    ans = 'SAFE'
    print(ans)
else:
    print(ans)



Measured memory_bytes: 292884
#include <bits/stdc++.h>
using namespace std;
const int maxc = 1e7;
int n, m = 1;
char s[200010];
int ch[maxc + 10][3], val[maxc + 10][3];
int ans[1000010];
int ndcnt = 1;
bool tag;

int tr(int x) {
	//printf("{%d}\n", x);
	if (!tag) return x;
	if (!x) return 0;
	return 3 - x;
}

void build(int p, int d) {
	if (d == n) return;
	for (int i = 0; i < 3; ++i) {
		ch[p][i] = ++ndcnt;
		val[p][i] = i;
		build(ch[p][i], d + 1);
	}
}

void dfs(int p, int d) {
	if (d == n) return;
	/*
	printf("[%d] ", p);
	for (int i = 0; i < 3; ++i)
		printf("{%d} ", val[p][i]);
	printf("\n");
	*/
	for (int i = 0; i < 3; ++i) {
		val[p][i] = tr((tr(val[p][i]) + 1) % 3);
		if (!tr(val[p][i])) dfs(ch[p][i], d + 1);
	}
	/*
	printf("[%d] ", p);
	for (int i = 0; i < 3; ++i)
		printf("{%d} ", val[p][i]);
	printf("\n");
	*/
}

void out(int p, int d, int v, int b, int now) {
	if (d == n) {
//		printf("|%d %d|\n", now, v);
		ans[now] = v; return;
	}
	for (int i = 0; i < 3; ++i)
		out(ch[p][i], d + 1, v + b * tr(val[p][i]), b * 3, now + b * i);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		m *= 3;
	build(1, 0);
	/*
	out(1, 0, 0, 1, 0);
	for (int i = 0; i < m; ++i)
		printf("%d ", ans[i]);
	return 0;
	*/
	scanf("%s", s);
	for (char *i = s; *i; ++i)
		if (*i == 'S') tag ^= 1;
		else dfs(1, 0);
	out(1, 0, 0, 1, 0);
	for (int i = 0; i < m; ++i)
		printf("%d ", ans[i]);
}


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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

typedef pair<ll, ll> ii;

void solve()
{
  int n,m;cin>>n>>m;
  vector<ii> a(n);
  for (int i=0; i<n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  SORT(a);
  ll ans=0;
  for (int i=0; i<n&&m>0; i++) {
    if (a[i].second<=m) {
      ans += a[i].second*a[i].first;
    } else {
      ans += m*a[i].first;
    }
    m-=a[i].second;
  }
  cout << ans << endl;
}

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


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl

const long long MOD = 1000000007;


int main(){
    ll n;
    cin >> n;
    ll p[n];
    rep(i, n){
        cin >> p[i];
    }
    ll count = 0;
    rep(i, n){
        if((i+1)!=p[i]){
            count++;
        }
    }
    if(count == 0 || count == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); // 文字列
		
		int check = n % 1000;
		int result = 0;
		
		if (check != 0) {
			result = 1000 - check;
		}

		System.out.println(result);
	}
}

Measured memory_bytes: 35668
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();
        var spl = s.Split(' ');
        var a = (spl[0]);
        var b = (spl[1]);

        bool atIs = a == "H";

        if(b == "H") {
            return atIs ? "H" : "D";
        } else {
            return atIs ? "D" : "H";
        }
    }
}


Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
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; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int k,n;cin>>k>>n;
  int m=0;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  reps(i,1,n){
    chmax(m,a[i]-a[i-1]);
  }
  chmax(m,k-a[n-1]+a[0]);
  cout<<k-m;
}

Measured memory_bytes: 1024
def main():
    import sys
    readline = sys.stdin.buffer.readline

    import math
    import itertools

    n = int(readline())
    xy = [list(map(int, readline().split())) for _ in range(n)]

    c = list(itertools.combinations(range(n), 2))
    ans = 0
    for a, b in c:
        ans += ((xy[a][0] - xy[b][0])**2 + (xy[a][1] - xy[b][1])**2)**(1/2)
    print(ans*2*math.factorial(n-1)/math.factorial(n))

if __name__ == '__main__':
    main()

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

int main(){
    int n, d; cin >> n >> d;
    vector<vector<double>> x(n, vector<double>(d));
    for(int i=0; i<n; i++)
        for(int j=0; j<d; j++)
            cin >> x[i][j];
    double distance = 0.0;
    int count = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            distance = 0.0;
            for(int k=0; k<d; k++){
                distance += pow(x[i][k]-x[j][k], 2);
            }
            distance = sqrt(distance);
            if(distance == ceil(distance))
                count++ ;
        }
    }
    cout << count << endl;
    return 0;
}

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

int main(){
    int N, r[100000], l[100000];
    int total= 0;
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> r[i] >> l[i];
        total += l[i] - r[i] + 1;
    }
    cout << total << endl;
}

Measured memory_bytes: 504
local m1_hp, m1_at, m2_hp, m2_at = io.read("*n", "*n", "*n", "*n")

while true do
	m2_hp = m2_hp - m1_at
	if m2_hp <= 0 then
		print("Yes")
		break
	end

	m1_hp = m1_hp - m2_at
	if m1_hp <= 0 then
		print("No")
		break
	end
end

Measured memory_bytes: 2736
#include <iostream>
#include <vector>
#include <set>

using namespace std;
long long n;
long long b;

multiset<long long> h1, h2;
long long summH1 = 0, summH2 = 0;
#define int long long
signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int aa, bb;
            cin >> aa >> bb;
            b += bb;
            h2.insert(aa);
            summH2 += aa;
            while (h2.size() > h1.size())
            {
                h1.insert(*h2.begin());
                summH1 += *h2.begin();
                summH2 -= *h2.begin();
                h2.erase(h2.begin());
            }
            if (h1.size() > 0 && h2.size() > 0)
            {
                auto ix = h1.end();
                ix--;
                long long x = *ix;

                auto iy = h2.begin();
                long long y = *iy;

                while (x > y)
                {
                    summH1 -= x;
                    summH2 += x;
                    summH1 += y;
                    summH2 -= y;

                    h2.insert(x);
                    h1.insert(y);

                    h1.erase(ix);
                    h2.erase(iy);

                    ix = h1.end();
                    ix--;
                    x = *ix;

                    iy = h2.begin();
                    y = *iy;
                }
            }
        }
        else
        {
            auto it = h1.end();
            it--;
            long long x = *it;
            long long ans = (long long)h1.size() * x - summH1 + summH2 - (long long)h2.size() * x;
            cout << x << " " << ans + b << "\n";
        }
        //cout << h1.size() << " " << h2.size() << endl;
        //cout << summH1 << " " << summH2 << endl;
    }
}


Measured memory_bytes: 9600
(r, c) = [int(i) for i in input().split()]
last_row = [0 for _ in range(c+1)]
 
for _ in range(r):
    row = [int(i) for i in input().split()]
    for cc in range(c):
        last_row[cc] += int(row[cc])
        print(row[cc], end=' ')
 
    print(sum(row))
 
last_row[-1] = sum(last_row)
print(' '.join([str(a) for a in last_row]))

Measured memory_bytes: 7768
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  char cur = 'A';
  lint ans = 0;
  for (auto c : s) {
    if (c <= cur) {
      ans++;
    }
    cur = c;
  }

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



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

int main(void){
    std::string s;
    std::cin >> s;
    int size = s.size();
    char mark = 'R';
    std::vector<int> rpos, lpos;
    std::vector<int> a(size);
    rpos.push_back(0);
    for(int i = 0; i < size; i++){
        if(s[i] != mark){
            if(mark == 'R'){
                lpos.push_back(i);
                mark = 'L';
            }else{
                rpos.push_back(i);
                mark = 'R';
            }
        }
    }
    int rpos_size = rpos.size();
    int tot, tmp;
    for(int i = 0; i < rpos_size; i++){
        if(i == rpos_size - 1) {
            tot = size - rpos[i];
            tmp = (size - 1 - lpos[i]) / 2;
        }else{
            tot = rpos[i+1] - rpos[i];
            tmp = (rpos[i+1] - 1 - lpos[i]) / 2;
        }
        tmp += (lpos[i] - rpos[i]) / 2;
        tmp++;
        a[lpos[i]] = tmp;
        a[lpos[i] - 1] = tot - tmp;
    }

    for(int i = 0; i < size; i++){
        std::cout << a[i] << " ";
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 4248
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  string o,e;
  cin >> o >> e;
  int i;
  for(i = 0;i < o.size();++i){
    cout << o.at(i);
    if(i < e.size()){
      cout << e.at(i);
    }else{
      cout << endl;
    }
  }
  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 = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        List<String> s = new ArrayList<>();
        for(int i = 0; i < N; i++)
            list.add(sc.nextInt());
        sc.close();
        for(int i = 0; i < N; i++){
            for(int j = list.size()-1; j>=0; j--){
                if(list.get(j) == j+1){
                    s.add(Integer.toString(j+1));
                    list.remove(j);
                    break;
                }
            }
        }
        if(list.size() != 0){
            System.out.println(-1);
        } else {
            for(int i = N-1; i >= 0; i--){
                System.out.println(s.get(i));
            }
        }
    }
}

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

bool rec(int target, const vector<int>& A) {
    if (target == 0) {
        return true;
    }
    if (A.size() > 1) {
        vector<int> A1(A.begin(), A.end()-1);
        if (rec(target, A1)) {
            return true;
        }
        if (rec(target-A.back(), A1)) {
            return true;
        }
    }
    else {
        if (target == A.back()) {
            return true;
        }
    }
    return false;
}

int main() {
    int aSize;
    cin >> aSize;
    vector<int> A(aSize);
    for (auto&& a : A) {
        cin >> a;
    }

    int qSize;
    cin >> qSize;
    vector<int> Q(qSize);
    for (auto&& q : Q) {
        cin >> q;
    }

    for (int q : Q) {
        const bool result = rec(q, A);
        if (result) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }

}


Measured memory_bytes: 3160
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)    
    


Measured memory_bytes: 3188
//************************
//*  Date: 2018.8.18     *
//*  Problem: 106D       *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,q;
vector <int> dis[510];

int main()
{
 cin>>n>>m>>q;
 rep(i,m)
 {
  int x,y;
  scanf("%d%d",&x,&y);
  dis[x].pb(y);
 }
 repn(i,n) sort(dis[i].begin(),dis[i].end());
 rep(i,q)
 {
  int x,y,ans=0;
  scanf("%d%d",&x,&y);
  for(int j=x;j<=y;j++)
  {
   //cout<<j<<' '<<upper_bound(dis[j].begin(),dis[j].end(),y)-dis[j].begin()<<endl;
   ans+=upper_bound(dis[j].begin(),dis[j].end(),y)-dis[j].begin();
  }
  printf("%d\n",ans);
 }
 rt0;
}

Measured memory_bytes: 2176
s = input()
n = len(s)

if s == 'keyence':
    print('YES')
    exit()

for i in range(0, n):
    for j in range(i+1, n+1):
        if s[0:i] + s[j:] == 'keyence':
            print('YES')
            exit()
        # print(s[i:j])
print('NO')


Measured memory_bytes: 9072
#include <iostream>
#include <string>
#include <map>
#include <algorithm>


int n, m, k, p;
std::string s, o;
std::map<std::string, int> mp;

int main(){
    while(std::cin >> n){
        if(n == 0) break;

        for(int i = 0; i < n; i++){
            std::cin >> s >> p;

            mp[s] = p;
        }

        std::cin >> m;
        for(int i = 0; i < m; i++){
            std::cin >> o >> k;

            int tmp = 0;
            for(int j = 0; j < k; j++){
                std::cin >> s;
                tmp += mp[s];
            }
            mp[o] = std::min(mp[o], tmp);
        }

        std::cin >> s;
        std::cout << mp[s] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3156
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  list.sort(function(a,b){
  	return a - b;
  });
  var M = -list[0] + list[N - 1];
  for(var i = 1; i < N - 1; i++){
    M += Math.abs(list[i]);
  }
  myout(M);
  var output = new Array(N - 1);
  var L = list[0];
  var R = list[N - 1];
  for(var i = 1; i < N - 1; i++){
    if(list[i] < 0){
      output[i - 1] = R + " " + list[i];
      R -= list[i];
    }else{
      output[i - 1] = L + " " + list[i];
      L -= list[i];
    }
  }
  output[output.length - 1] = R + " "+ L;
  myout(myconv(output, 9));
}


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

int main() {
int64_t N,A,B;
cin >> N >> A >> B;
int64_t x = N / (A+B);
int64_t y = N - (A+B)*x;
int64_t ans;
if(y <= A) ans = N - B * x;
else ans = A * x + A;
cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int a[n + 1], b[m + 1];
	a[n] = x, b[m] = y;
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];
	sort(a, a + n + 1);
	sort(b, b + m + 1);
	if (a[n]<b[0])cout << "No ";
	cout << "War" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	long int n, b, r,bn;
	scanf("%ld %ld %ld", &n, &b, &r);
	bn = n / (b + r)*b;
	if (n % (b + r) > b) {
		bn = bn + b;
	}
	else {
		bn = bn + n % (b + r);
	}
	printf("%ld", bn);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    map<string, ll> mp;
    rep(i, n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

}


Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main() {
	string word;
	stack<int> s;
	int num1, num2;

	while (cin >> word) {
		if (word == "+") {
			num1 = s.top(); s.pop();
			num2 = s.top(); s.pop();
			s.push(num1 + num2);
		}
		else if (word[0] == '-') {
			num1 = s.top(); s.pop();
			num2 = s.top(); s.pop();
			s.push(num2 - num1);
		}
		else if (word[0] == '*') {
			num1 = s.top(); s.pop();
			num2 = s.top(); s.pop();
			s.push(num1 * num2);
		}
		else if (word[0] == '\n')
			break;
		else 
			s.push(atoi(word.c_str()));
	}
	cout << s.top() << endl;
	return 0;
}

Measured memory_bytes: 3224
// AOJ 2614: Almost Same Substring
// 2017.12.31 bal4u@uu

#include <stdio.h>
#include <string.h>

int slen, tlen, diff;
char s[300005];
char t[300005];
int zf[600005];
int zr[600005];
char buf[600005];

void Zalgo(int *z, char *s, int n)
{
	int i, j, k;

	z[0] = n;
    i = 1, j = 0;
    while (i < n) {
		while (i+j < n && s[j] == s[i+j]) ++j;
        z[i] = j;
        if (j == 0) { ++i; continue;}
        k = 1;
        while (i+k < n && k+z[k] < j) z[i+k] = z[k], ++k;
        i += k; j -= k;
    }
}

int main()
{
	int i, w, ans;
	char *p, *q;

	fgets(s, sizeof(s), stdin);
	slen = strlen(s)-1;
	if (*(s+slen) < ' ') *(s+slen) = 0;	else slen++;
	fgets(t, sizeof(t), stdin);
	tlen = strlen(t)-1;
	if (*(t+tlen) < ' ') *(t+tlen) = 0;	else tlen++;

	memcpy(buf, t, tlen);
	memcpy(buf+tlen, s, slen);
	Zalgo(zf, buf, slen+tlen+1);

	p = buf, q = t+tlen;
	while (q > t) *p++ = *--q;
	q = s+slen;
	while (q > s) *p++ = *--q;
	Zalgo(zr, buf, slen+tlen+1);

	ans = 0, w = tlen-1;
	for (i = tlen; i <= slen; i++) {
		ans += (zf[i]+ zr[slen+tlen-i] == w);
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 6288
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#include <stack>
#include <bitset>
#include <map>

using namespace std;

int solve();

int main(void) {
//	FILE *fpin = freopen("data.txt", "r", stdin);
	while (solve()) {}
	return 0;
}

int solve() {

	int A, B, C;
	cin >> A >> B >> C;

	if (C >= A && C <= B) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

#define int long long

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

using namespace std;

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

const long long INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
const int MOD=1e9+7;
signed main(){
	int n;
	cin>>n;
	int a[210000];
	rep(i,1,n+1)cin>>a[i];
	int cnt[210000]={};
	rep(i,1,n+1)cnt[a[i]]=cnt[a[i]-1]+1;
	int m=0;
	rep(i,n+1)chmax(m,cnt[i]);
	cout<<n-m<<endl;
}

Measured memory_bytes: 3584
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: f64,
        b: f64,
        x: f64,
    }
    let ans = if a * a * b / 2.0 < x {
        // 底面が水で満たされた状態で溢れる。
        let c = 2.0 * x / (a * a) - b;
        ((b - c) / a).atan() / (2.0 * std::f64::consts::PI) * 360.0
    } else {
        let c = 2.0 * x / a / b;
        (b / c).atan() / (2.0 * std::f64::consts::PI) * 360.0
    };
    println!("{}", ans);
}


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

int main(void) {
  int n;
  cin >> n;
  
  vector<int> F(50);
  F.at(0) = F.at(1) = 1;
  for (int i = 2; i <= n; i++) F.at(i) = F.at(i-1) + F.at(i-2);

  cout << F.at(n) << endl;


}


Measured memory_bytes: 3092
#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 << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}


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

using namespace std;

void Main() {
    int N;
    cin >> N;
    set<int> A;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (A.count(a) > 0) {
            A.erase(a);
        }
        else {
            A.insert(a);
        }
    }
    cout << A.size() << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 8100
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  int a[100];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    printf("%d", a[n - i - 1]);
  }
  printf("\n");
}



Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
#define INF 100000000
int po[8];
int t;
int result;
vector<int> ans;
vector<int> anss;

int Stoi(string s){
    if(s == "") return 0;
    else{

        int res = 0;
        int n = (int)s.size();
        n--;
        for(int i = 0; i < s.size(); i++){
            res += (int)(s[i] - '0') * po[n];
            n--;
        }

        return res;
    }
}

void rec(vector<int>& a, string num, int idx, string tmp, int sum){

    tmp += num[idx];
    if(idx == (int)num.size() - 1){
        ans.push_back(Stoi(tmp));
        sum += Stoi(tmp);
        if(sum <= t){
            if(result == sum){
                a.push_back(sum);
            }else if(result < sum || result == INF){
                result = sum;
                anss = ans;
            }
        }
        ans.pop_back();
        return;
    }

    //切らない
    rec(a, num, idx + 1, tmp, sum);

    //切る
    ans.push_back(Stoi(tmp));
    sum += Stoi(tmp);
    tmp = "";
    rec(a, num, idx + 1, tmp, sum);
    ans.pop_back();
    return;
}

int main(){
    
    po[0] = 1;
    for(int i = 1; i < 8; i++){
        po[i] = po[i - 1] * 10;
    }

    //cout << Stoi("157") << " " << Stoi("") << endl;

    while(1){
        string num; cin >> t >> num;
        if(!t) break;
        vector<int> a;
        result = INF;
        rec(a, num, 0, "", 0);
        
        for(int i = 0; i < a.size(); i++){
            if(result == a[i]){
                result = -1;
                break;
            }
        }
        if(result == INF) cout << "error" << endl;
        else if(result == -1) cout << "rejected" << endl;
        else{
            cout << result << " ";
            for(int i = 0; i < (int)anss.size(); i++){
                if(i == (int)anss.size() - 1) cout << anss[i] << endl;
                else cout << anss[i] << " ";
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main{
  public static void main(String[] args)throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int numAll = Integer.parseInt(br.readLine());
    String[] dataStr = br.readLine().split(" ");
    int data = 0;
    
    for(int i=0; i<numAll; i++){
      data = Integer.parseInt(dataStr[i]);
      if((data%2 == 0 && data%3 != 0) && (data%2 == 0 && data%5 != 0)){
        System.out.println("DENIED");
        return;
      }
    }
    System.out.println("APPROVED");
  }
}

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

int main(){
    long h,w;
    cin >> h >> w;
    if(h == 1 || w == 1) cout << 1 << endl;
    else if(h%2 == 0 || w%2 == 0) cout << (h*w)/2 << endl;
    else cout << ((h*w)/2)+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxn=1e5+5;
int a[3];
string s[Maxn];
int main(){
	cin>>n>>a[0]>>a[1]>>a[2];
	rep(i,n){
		cin>>s[i];
	}
	vector<int>keep;
	rep(i,n){
		int x=s[i][0]-'A',y=s[i][1]-'A';
		if(!a[x]&&!a[y]){
			keep.clear();break;
		}else if(a[x]>a[y]){
			a[x]--;a[y]++;keep.push_back(y);
		}else if(a[x]<a[y]){
			a[x]++;a[y]--;keep.push_back(x);
		}else{
			if(i!=n-1&&(s[i+1][0]-'A'==x||s[i+1][1]-'A'==x)){
				a[x]++;a[y]--;keep.push_back(x);
			}else{
				a[x]--;a[y]++;keep.push_back(y);
			}
		}
//		cout<<"A:"<<a[0]<<' '<<"B:"<<a[1]<<' '<<"C:"<<a[2]<<endl;
	}
	if(SZ(keep)==0){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
		for(auto x:keep){
			cout<<char(x+'A')<<endl;
		}
	}
	return 0;
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}


int main(void){
    char c[2][3];
    int i;
    for (i = 0; i < 6; i++){
        scanf(" %c", &c[i/3][i%3]);
    }
    for (i = 0; i < 3; i++){
        if (c[0][i] != c[1][2-i]){
            printf("NO\n");
            return 0;
        }
    }

    printf("YES\n");
    return 0;
}


Measured memory_bytes: 128
def lscan; gets.split.map(&:to_i);end
n = lscan
a = gets.split.map(&:to_i)
sorted = a.sort

cnt = 0
(0..a.length - 1).each do |i|
  cnt += 1 if a[i] != sorted[i]
end

puts cnt <= 2 ? 'YES' : 'NO'

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main() {
    int n,y,m,d;
    cin >> n;
    while(cin >> y >> m >> d){
        int sum=0;
        if(y%3==1){
            if(m%2==1){sum =(y/3)*590 + (m/2)*39 + d;}
            else{sum = (y/3)*590 + (m/2-1)*39+20 + d;}
        }
        if(y%3==2){
            if(m%2==1){sum =(y/3)*590+195 + (m/2)*39 + d;}
            else{sum = (y/3)*590+195 + (m/2-1)*39+20 + d;}
        }
        if(y%3==0){
            sum =(y/3-1)*590+390 + (m-1)*20 + d;
        }
        cout << 333*590+1 - sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> x(5);
  for(int i=0;i<5;i++){
    cin>>x.at(i);
    if(x.at(i)!=i+1){
      cout<<i+1<<endl;
    }
  }


}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  if(n < 1200)
    out("ABC");
  else
    out("ARC");
  memi;
}

Measured memory_bytes: 256
#include <stdio.h>
/*長方形の中に円が含まれるかを判定*/
int main(void)
{
    int a, b;
    char op;
    while (1)
    {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?')
        {
            break;
        }
        switch (op)
        {
        case '+':
            printf("%d\n", a + b);
            break;

        case '-':
            printf("%d\n", a - b);
            break;
        case '*':
            printf("%d\n", a * b);
            break;
        case '/':
            printf("%d\n", a / b);
            break;
        default:
            break;
        }
    }
}


Measured memory_bytes: 2032