akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M, Q;
  while ( cin >> N >> M >> Q, N ) {    
    vector<int> s(N, 0);
    vector<vector<int> > b(M, vector<int>(36, 1));    
    while ( Q-- ) {
      string S, B;
      cin >> S >> B;
      for ( int i = 0; i < N; i++ ) {
	if ( S[i] == '1' ) s[i] ^= 1;	
      }
      for ( int i = 0; i < N; i++ ) {
	if ( s[i] ) {
	  for ( int j = 0; j < M; j++ ) {	  
	    if ( B[j] == '0' ) b[j][i] = 0;	  
	  }
	} else {
	  for ( int j = 0; j < M; j++ ) {	  
	    if ( B[j] == '1' ) b[j][i] = 0;	  
	  }
	}
      }
    }

    for ( int i = 0; i < M; i++ ) {
      int cor = -1;
      for ( int j = 0; j < N; j++ ) {
	if ( !b[i][j] ) continue;
	if ( cor >= 0 ) {
	  cor = -1;
	  break;
	} else {
	  cor = j;	  
	}
      }

      if ( cor < 0 ) cout << '?';
      else {
	if ( cor >= 10 ) cout << (char)('A'+cor-10);
	else cout << cor;
      }
    }
    cout << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <math.h>
#define y1 yp

using namespace std;
typedef long long LL;
const int maxn = 400005;
const int N = 1e8+1;
const double pi = acos(-1.0);

int disc[maxn],tot,a[maxn],x[maxn],y[maxn],n,ans;
int val[maxn],dp[maxn],x1,y1,x2,y2,ord[maxn];
bool comp(int u,int v) {
	return x[u]<x[v];
}
void insert(int x,int v) {
	for (int i=x;i<=tot;i+=i&-i)
		val[i]=max(val[i],v);
}
int query(int x) {
	int res=0;
	for (int i=x;i;i-=i&-i)
		res=max(res,val[i]);
	return res;
}
int main()
{
	#ifdef Amberframe
		freopen("agc019c.in","r",stdin);
		freopen("agc019c.out","w",stdout);
	#endif
	scanf("%d %d",&x1,&y1);
	scanf("%d %d",&x2,&y2);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d %d",&x[i],&y[i]);
	if (x1>x2) {
		x1=N-x1;x2=N-x2;
		for (int i=1;i<=n;i++) x[i]=N-x[i];
	}
	if (y1>y2) {
		y1=N-y1;y2=N-y2;
		for (int i=1;i<=n;i++) y[i]=N-y[i];
	}
	for (int i=1;i<=n;i++)
	if (x[i]>=x1&&x[i]<=x2&&y[i]>=y1&&y[i]<=y2)
		ord[++tot]=i,disc[tot]=y[i];
	sort(ord+1,ord+tot+1,comp);
	sort(disc+1,disc+tot+1); 
	
	for (int i=1;i<=tot;i++)
	{
		int o=ord[i],x=lower_bound(disc+1,disc+tot+1,y[o])-disc;
		dp[i]=query(x)+1;insert(x,dp[i]);ans=max(ans,dp[i]);
	}
	if (ans<min(x2-x1,y2-y1)+1)
		printf("%.12lf",(x2-x1+y2-y1)*100.0-(20-5*pi)*ans);
	else
		printf("%.12lf",(x2-x1+y2-y1)*100.0-(20-5*pi)*(ans-1)+10*pi-20);
	return 0;
}

Measured memory_bytes: 9728
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int A, B;
	cin >> A >> B;
	int g = gcd(A, B);
	set<int>s;
	for (int i = 2; i * i <= g; i++) {
		while (g % i == 0) {
			s.insert(i);
			g /= i;
		}
	}
	if (g != 1)s.insert(g);
	int ans = s.size() + 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int s,n,k,i,j,a[10001][2],m[501];
	while(scanf("%d%d",&n,&k),n!=0&&k!=0){
		for(i=0;i<n;i++)m[i]=0;
		for(i=0;i<k;i++){
			scanf("%d%d",&a[i][0],&a[i][1]);
			if(a[i][0]==1)m[a[i][1]-1]=1;
		}
		for(i=0;i<n;i++){
			if(m[i]==1){
				for(j=1;j<k;j++){
					if(m[a[j][0]-1]==1&&m[a[j][1]-1]==0)m[a[j][1]-1]=2;
					if(m[a[j][1]-1]==1&&m[a[j][0]-1]==0)m[a[j][0]-1]=2;
				}
			}
		}
		m[0]=0,s=0;
		for(i=0;i<n;i++)if(m[i]!=0)++s;
		printf("%d\n",s);
	}
	return 0;
}


Measured memory_bytes: 2028
//46
#include<iostream>
#include<map>
#include<string>

using namespace std;

int main(){
  map<string,int> bg;
  int n;
  string b;
  while((cin>>n).ignore()>>b){
    bg[b]++;
  }
  cout<<bg["A"]<<endl<<bg["B"]<<endl<<bg["AB"]<<endl<<bg["O"]<<endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
#define reply cin >> (s); if (((string)s) == "Vacant") return 0
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7
// https://atcoder.jp/contests/apc001/tasks/apc001_c

vector<int> seats;

void setSeat(int n, string s) {
    if (s == "Male") seats[n] = 1;
    else seats[n] = 2;
}

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

    // 0: Unknown
    // 1: Male
    // 2: Female
    seats = vector<int>(n, 0);

    vector<int> initList = {0, n - 1, n / 2};
    for (auto &&i : initList)
    {
        cout << i << endl;
        reply;
        setSeat(i, s);
    }

    int lidx, ridx;
    if ((n / 2 + 1) % 2 == 0) {
        // 要素数が偶数
        if (seats[0] == seats[n / 2]) { // 同性ペア
            lidx = 0;
            ridx = n / 2;
        } else {
            lidx = n / 2;
            ridx = n - 1;
        }
    } else {
        // 要素数が奇数
        if (seats[0] != seats[n / 2]) { // 異性ペア
            lidx = 0;
            ridx = n / 2;
        } else {
            lidx = n / 2;
            ridx = n - 1;
        }
    }

    for (int cnt = 17; cnt > 0; cnt--)
    {
        int mid = (lidx + ridx) / 2;
        cout << mid << endl;
        reply;
        setSeat(mid, s);

        int lnum = mid - lidx + 1;
        int rnum = ridx - mid + 1;
        if (seats[lidx] == seats[ridx]) {
            // 同性ペアの区間＝偶数個の区間
            if (seats[lidx] == seats[mid]) {
                if (lnum % 2 == 0) ridx = mid;
                else lidx = mid;
            } else {
                if (lnum % 2 == 1) ridx = mid;
                else lidx = mid;
            }
        } else {
            // 異性ペアの区間＝奇数個の区間
            if (((ridx - lidx) / 2) % 2 == 0) {
                if (seats[lidx] != seats[mid]) ridx = mid;
                else lidx = mid;
            } else {
                if (seats[lidx] == seats[mid]) ridx = mid;
                else lidx = mid;
            }
        }
    }
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll a, b, c, k;
    ll p[200010];
    string s;

    cin >> a >> b >> c >> k;

    if (k <= a){
      cout << k << endl;
    } else if (k <= a + b){
      cout << a << endl;
    } else if (k <= a + b + c){
      cout << a - (k - a - b) << endl;
    } else { 
      cout << a - c << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
/*----------------------------------------------*/

signed main(){
  string s;
  cin>>s;
  rep(i,s.length()) cout<<'x';
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18#include <cmath>

long a, b, c, k;

int main(){
    scanf("%ld%ld%ld%ld", &a,&b,&c,&k);
    if(k > a + b){
        printf("%ld\n", a - (k-a-b));
    }else if(k > a){
        printf("%ld\n", a);
    }else{
        printf("%ld\n",k);
    }
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 110;
int n;
int a[N], b[N], c[N], d[N];
vi G[N + N];
namespace MaxMatch{
    const int N = 5050;
    int link[N],vis[N];
    int dfs(int c,vi g[]){
        for(auto t : g[c])
            if(!vis[t]){
                vis[t] = true;
                if(link[t]==-1||dfs(link[t],g))
                    return link[t]=c,1;
            }
        return 0;
    }
    int solve(int n,int m,vi g[]){
        fill_n(link,m,-1);
        int ret=0;
        rep(i,0,n){
            memset(vis,0,m*sizeof(int));
            ret += dfs(i,g);
        }
        return ret;
    }
}
int main(){
	scanf("%d", &n);
	rep(i, 0, n) scanf("%d%d", a + i, b + i);
	rep(i, 0, n) scanf("%d%d", c + i, d + i);
	rep(i, 0, n) {
		rep(j, 0, n) {
			if(a[i] < c[j] && b[i] < d[j])
				G[i].pb(n + j), G[n + j].pb(i);
		}
	}
	printf("%d\n", MaxMatch::solve(n + n, n + n, G) / 2);
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		
		Command[] cmds = new Command[n];
		for (int i = 0; i < n; i++) {
			int op = sc.nextInt();
			int val = -1;
			if (op != 2) {
				 val = sc.nextInt();
			}
			cmds[i] = new Command(op, val);
		}
		List<Integer> arr = new ArrayList<>();
		for (Command c : cmds) {
			switch(c.op) {
			case 0:
				arr.add(c.val);
				break;
			case 1:
				System.out.println(arr.get(c.val));
				break;
			case 2:
				arr.remove(arr.size() - 1);
				break;
			}
		}
	
	}
}

class Command {
	public int op;
	public int val;
	public Command(int op, int val) {
		this.op = op;
		this.val = val;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 57436
#include<bits/stdc++.h>
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 hyou[10][10];
int H, W, C, ans;
int D[4] = {1, 0, -1, 0};
bool used[10][10];

void bfs(int c , int (&H3)[10][10]) {
	H3[1][1] = 0;
	rep(i, 10) rep(j, 10) used[i][j] = false;
	int px = 1, py = 1;
	queue<pair<int, int>> dq;
	dq.push(make_pair(px, py));
	while(!dq.empty()) {
		px = dq.front().first;
		py = dq.front().second;
		dq.pop();
		for (int i = 0; i < 4 ;i++)  {
			int nx = px + D[i];
			int ny = py + D[3 - i];
			if(used[ny][nx] == 0 and ( H3[ny][nx] == c or H3[ny][nx] == 0)) {
				H3[ny][nx] = 0;
				dq.push(make_pair(nx, ny));
				used[ny][nx] = 1;
			}
		}
	}
}
		
void dfs(int k, int (&H3)[10][10]) {
	int H2[10][10] ;
	rep(i, 10) rep(j, 10) H2[i][j] = H3[i][j];
	if (k == 5) {
		bfs(C, H2);
		int cnt = 0;
		rep1(i, H) rep1(j , W) {
			if (H2[i][j] == 0){
			cnt += 1;
			}
		}
		ans = max(cnt, ans);
		return;
	}
	rep1(i, 7){
		rep(i, 10) rep(j, 10) H2[i][j] = H3[i][j];
		bfs(i, H2);
		dfs(k + 1, H2);
	}
	return;
}
int main() {
	while(cin >> H >> W >> C, H) {
		ans = 0;
		rep(i, 10) rep(j, 10) hyou[i][j] = -1;
		rep1(i, H) rep1(j,W) cin >> hyou[i][j];
		bfs(hyou[1][1], hyou);
		int hyou2[10][10];
		//rep(i, n) rep(j, n) hyou2[i][j] = hyou[i][j];
		dfs(1, hyou) ;
		cout << ans << endl;
	}
}
		





Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;



int main() {
	int n, a, b; cin >> n >> a >> b;
	vector<ll> v(n);
	vector<vector<ll> > c(n + 1, vector<ll>(n + 1));
	c[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		c[i][0] = 1;
		for (int j = 1; j <= n; j++) {
			if (i < j) c[i][j] = 0;
			else c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
		}
	}

	for (int i = 0; i < n; i++) cin >> v[i];
	sort(v.rbegin(), v.rend());
	double ans = 0;
	for (int i = 0; i < a; i++) ans += v[i];
	ans /= a;
	cout << fixed << setprecision(10) << ans << endl;
	int cnt = 0, l = 0, r = 0;
	for (int i = 0; i < n; i++) {
		cnt += v[i] == v[0];
		l += v[i] == v[a - 1];
		r += i < a && v[i] == v[a - 1];
	}
	if (cnt < a) {
		cout << c[l][r] << endl;
		return 0;
	}
	ll s = 0;
	for (int i = a; i <= min(cnt, b); i++) s += c[cnt][i];
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <tuple>
#include <functional>
#include <limits>
#include <utility>
#include <string>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    vector<int> stack;

    unordered_map<string, function<int(int, int)>> operations
    {
        { "+", plus<int>() }, { "-", minus<int>() }, { "*", multiplies<int>() }
    };

    string symbol;
    while(cin >> symbol)
    {
        auto it(operations.find(symbol));

        if(it != end(operations))
        {
            int x(stack.back());
            stack.pop_back();

            int y(stack.back());
            stack.pop_back();

            stack.push_back(it->second(y, x));
        }
        else
        {
            stack.push_back(stoi(symbol));
        }
    }

    cout << stack.back() << endl;

    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%2==1){
            int cnt=0;
            for(int j=1;j<=i;j++){
                if(i%j==0)
                cnt++;
            }
            if(cnt==8)
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	
	ll a , b, k;cin >> a >> b >> k;
	
	int cou = 0;
	for(int i = 100;i >= 0;i--){
		if(a % i == 0 && b % i == 0){
			cou++;
			if(cou == k){
				cout << i << endl;
				return 0;
			}
		}
	}
	
	return 0;
}


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

int main(){
	int n,m;
	cin>>n>>m;
	if(m==1)
	    cout<<0<<endl;
	else{
	    int i=1;
	    while(n*i-(i-1)<m){
			    i++;
	    }
	    cout<<i<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

const ll infty = 1000000000000000;

int N;
ll A[100010];
bool op[100010];
ll dp[100010][3];

int main () {
  cin >> N;
  for (auto i = 0; i < N; i++) {
    cin >> A[i];
    if (i < N-1) {
      char c;
      cin >> c;
      op[i] = (c == '+');
    }
  }
  dp[0][0] = A[0];
  dp[0][1] = -infty;
  dp[0][2] = -infty;
  for (auto i = 1; i < N; i++) {
    if (op[i-1]) {
      dp[i][2] = dp[i-1][2] + A[i];
      dp[i][1] = dp[i-1][1] - A[i];
      dp[i][0] = max(dp[i-1][1] - A[i], dp[i-1][0] + A[i]);
    } else {
      dp[i][2] = max(dp[i-1][2] + A[i], dp[i-1][1] + A[i]);
      dp[i][1] = max(dp[i-1][1] + A[i], dp[i-1][0] - A[i]);
      dp[i][0] = max(dp[i-1][1] + A[i], dp[i-1][0] - A[i]);
    }
  }
  /*
  for (auto i = 0; i < N; i++) {
    cerr << "dp[" << i << "] "
         << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
  }
  */
  cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
}


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

int main(){
  int X,Y;
  cin >> X >> Y;
  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      int A=i,B=j;
      if(A+B==X && A*2+B*4==Y){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}
      
  

Measured memory_bytes: 3596
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    A = list(map(int,input().split()))
    ans = 1
    befc = 1 - A[0] 
    if A[0] > 1:
        return -1
    tmp = sum(A[1::])
    for i in range(1,N+1):
        curc = min(befc * 2, tmp)
        if curc < A[i]:
            return -1
        ans += curc
        befc = curc - A[i]
        tmp -= A[i]
    return ans

if __name__ == '__main__':
    print(main())


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

int main(){
  int N; cin >>N;
  int W[N];

  for(int i=0;i<N;i++){
    int w; cin >>w;
    if(i==0){
      W[i] = w;
    } else {
      W[i] = W[i-1]+w;
    }
  }

  int ans=W[N-1];
  for(int i=0;i<N-1;i++){
    if(ans>abs(W[N-1]-W[i]*2)) ans = abs(W[N-1]-W[i]*2);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
def colchange(x):
    if x==1:
        return 0
    elif x==0:
        return 1
H,W,A,B=map(int,input().split())
table=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(0,A):
        table[i][j]=colchange(table[i][j])
for i in range(0,B):
    for j in range(W):
        table[i][j]=colchange(table[i][j])
#print(table)
for i in range(H):
    print(*table[i],sep="")


Measured memory_bytes: 80604
T = input()

status = True
while status:
    if "P?" in T:
        T = T.replace("P?","PD")
    else:
        status = False

status3 = True
while status3:
    if "?D" in T:
        T = T.replace("?D","PD")
    else:
        status3 = False

status2 = True
while status2:
    if "D?" in T:
        T = T.replace("D?","DD")
    else:
        status2 = False

status4 = True
while status4:
    if "?" in T:
        T = T.replace("?","D")
    else:
        status4 = False

print(T)


Measured memory_bytes: 9380
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 1e13 + 1;

struct Edge {
  int from, to, cost;
  Edge(int from, int to, int cost): from(from), to(to), cost(cost) {}
};

int N, M;
vector<Edge> es;
vector<ll> c;

void bellmanFord(int s) {
  c.at(s) = 0;
  rep(i, N) {
    rep(j, M) {
      Edge e = es.at(j);
      if (c.at(e.from) != INF && c.at(e.to) > c.at(e.from) + e.cost) {
        c.at(e.to) = c.at(e.from) + e.cost;
      }
    }
  }
}

int main() {
  cin >> N >> M;
  c.resize(N, INF);

  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;

    es.emplace_back(a, b, -c);
  }

  bellmanFord(0);
  ll ans = -c.at(N - 1);
  bellmanFord(0);

  if (-c.at(N - 1) != ans) {
    cout << "inf" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,M,Q;
int A[101010];
int col[1500000];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};

UF<1407070> uf1,uf2,uftail;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>Q;
	FOR(i,Q) {
		cin>>A[i];
		for(j=A[i];j<14*M;j+=M) col[j]=1;
	}
	
	ll pat;
	int num[3]={};
	if(M%7==0) {
		FOR(i,M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf1(i,i+1);
			if(col[i]==0 && (i+7<M) && col[i+7]==0) uf1(i,i+7);
		}
		FOR(i,2*M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf2(i,i+1);
			if(col[i]==0 && (i+7<2*M) && col[i+7]==0) uf2(i,i+7);
		}
		FOR(i,M) if(col[i]==0 && uf1[i]==i) num[0]++;
		FOR(i,2*M) if(col[i]==0 && uf2[i]==i) num[1]++;
		pat=7*N/M;
	}
	else {
		FOR(i,7*M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf1(i,i+1);
			if(col[i]==0 && (i+7<7*M) && col[i+7]==0) uf1(i,i+7);
		}
		FOR(i,14*M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf2(i,i+1);
			if(col[i]==0 && (i+7<14*M) && col[i+7]==0) uf2(i,i+7);
		}
		FOR(i,7*M) if(col[i]==0 && uf1[i]==i) num[0]++;
		FOR(i,14*M) if(col[i]==0 && uf2[i]==i) num[1]++;
		pat=N/M;
	}
	cout<<num[0]+(pat-1)*(num[1]-num[0])<<endl;
	
}



int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 56576
#include<stdio.h>
int main(void) {
    int N;
    int A, B;
    int sum1, sum10, sum100, sum1000, sum10000; //一の位, 十の位, 百の位, 千の位
    int sumN; //各桁の和
    int sum = 0; //総和

    scanf("%d %d %d", &N, &A, &B);

    for (int n = 1; n <= N; n++) {
        if (1 <= n && n < 10) {
            sum1 = n;
            sumN = sum1;
        }
        else if (10 <= n && n < 100) {
            sum10 = n / 10;
            sum1 = n - sum10 * 10;
            sumN = sum10 + sum1;
        }
        else if (100 <= n && n < 1000) {
            sum100 = n / 100;
            sum10 = (n - sum100 * 100) / 10;
            sum1 = (n - sum100 * 100) - sum10 * 10;
            sumN = sum100 + sum10 + sum1;
        }
        else if (1000 <= n && n < 10000) {
            sum1000 = n / 1000;
            sum100 = (n - sum1000 * 1000) / 100;
            sum10 = ((n - sum1000 * 1000) - sum100 * 100) / 10;
            sum1 = ((n - sum1000 * 1000) - sum100 * 100) - sum10 * 10;
            sumN = sum1000 + sum100 + sum10 + sum1;
        }
        else {
            sum10000 = n / 10000;
            sum1000 = (n - sum10000 * 10000) / 1000;
            sum100 = ((n - sum10000 * 10000) - sum1000 * 1000) / 100;
            sum10 = (((n - sum10000 * 10000) - sum1000 * 1000) - sum100 * 100) / 10;
            sum1 = (((n - sum10000 * 10000) - sum1000 * 1000) - sum100 * 100) - sum10 * 10;
            sumN = sum10000 + sum1000 + sum100 + sum10 + sum1;
        }
        if (1 <= A && A <= B && B <= 36) {
            if (A <= sumN && sumN <= B) {
                sum += n;
            }
        /*sum1 = 0;
        sum10 = 0;
        sum100 = 0;
        sum1000 = 0;*/
        }
    }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    bool flag = 0;
    double ans = 0.5000000 * H * W;
    if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y)
    {
        flag = 1;
    }
    cout << setprecision(10) << ans << " ";
    cout << flag << endl;
}


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

int main() {
    
    ll n;
    cin>>n;
    ll arr[3*n];
    ll arr_rev[3*n];
    for(ll i=0;i<3*n;i++)
    {
        cin>>arr[i];
        arr_rev[3*n-i-1] = arr[i];
    }
    ll prefix_sum1[3*n];
    priority_queue <ll, vector<ll>, greater<ll>> top_n;
    
    prefix_sum1[0] = arr[0];
    top_n.push(arr[0]);
    for(ll i=1;i<n;i++)
    {
        prefix_sum1[i] = prefix_sum1[i-1] + arr[i];
        top_n.push(arr[i]);
    }
    
    for(ll i=n; i<3*n-n; i++)
    {
        if(arr[i] > top_n.top())
        {
          prefix_sum1[i] = prefix_sum1[i-1] - top_n.top() + arr[i];
            top_n.pop();
            top_n.push(arr[i]);
        }
        else
            prefix_sum1[i] = prefix_sum1[i-1];
    }
    
//    for(int i=n-1; i<3*n-n;i++)
//    {
//        cout<<prefix_sum1[i]<<"\t";
//    }
    
    ll prefix_sum2[3*n];
    priority_queue <ll> bottom_n;
    prefix_sum2[0] = arr_rev[0];
    bottom_n.push(arr_rev[0]);
    for(ll i=1;i<n;i++)
    {
        prefix_sum2[i] = prefix_sum2[i-1] + arr_rev[i];
        bottom_n.push(arr_rev[i]);
    }
    
    
    for(ll i=n; i<3*n-n; i++)
    {
        if(arr_rev[i] < bottom_n.top())
        {
            prefix_sum2[i] = prefix_sum2[i-1] - bottom_n.top() + arr_rev[i];
            bottom_n.pop();
            bottom_n.push(arr_rev[i]);
        }
        else
            prefix_sum2[i] = prefix_sum2[i-1];
    }
//    cout<<"\n";
    ll ans = -922337203685477580;
    for(int i=3*n-n-1,j=n-1; i>=n-1 && j<3*n-n; i--, j++)
    {
//        cout<<prefix_sum2[i]<<"\t";
        ans  = max(ans, prefix_sum1[i] - prefix_sum2[j]);
    }
    
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 10996
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        //Scanner scanner = new Scanner(System.in);
        String str = scanner.readLine();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        Integer n = Integer.parseInt(scanner.readLine());
        LinkedList<Character> list = new LinkedList<>();
        for (char ch : str.toCharArray())
            list.add(ch);
        boolean isR = false;
        for (int i = 0; i < n; i ++){
            String[] s1 = scanner.readLine().split(" ");
            if (s1[0].equals("1"))
                isR = !isR;
            else if (s1[0].equals("2")){
                if (s1[1].equals("1")){
                    if (isR)
                        list.add(s1[2].charAt(0));
                    else
                        list.addFirst(s1[2].charAt(0));
                }
                else if (s1[1].equals("2")){
                    if (isR)
                        list.addFirst(s1[2].charAt(0));
                    else
                        list.add(s1[2].charAt(0));
                }
            }
        }
        scanner.close();
        StringBuffer stringBuffer = new StringBuffer();
        for (char ch : list)
            stringBuffer.append(ch);
        if (isR) out.println(stringBuffer.reverse());
        else out.println(stringBuffer);
        out.flush();
    }
}


Measured memory_bytes: 65504
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);

  int total = 0;
  rep(i,n) {
      cin >> a[i];
      total+=a[i];  
  }
  int lim = (total+(4*m)-1) / (4*m);
  int cnt = 0;
  rep(i,n) {
      if(lim <= a[i]) cnt++;
  }
  if(cnt >= m) cout << "Yes" <<endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 int main(){
   
  

   while(1){
   std::string s;
   (std::getline(std::cin, s)) ;
  
  if(s==".") break ;
  
  bool ok=1 ; 
  bool ko=1 ;
  bool p=1 ;
  int w= 0;
  int sa = 0 ;
  int as = 0 ;
   ll k= s.size() ;
   stack<int>  A; 
    rep(i,k-1){
    if(s[i]=='(') {
      sa++ ;
      A.push(1) ;
    }
    if(s[i]==')') {
      sa-- ;
      if(!A.empty()){
       int x= A.top() ;
       if(x!=1) p=0 ;
       A.pop() ;
      }
    }
    if(s[i]=='[') {
      as++ ;
      A.push(-1) ;
    }
    if(s[i]==']') {
      as-- ;
      if(!A.empty()){
        int x= A.top() ;
        if(x!=-1) p=0 ;
        A.pop() ;
      }
    }
    if(sa<0) ok=0 ;
    if(as<0) ko=0 ;
    
    
    }

      if(ok==1&&ko==1&&sa==0&&as==0&&p==1){
       
      cout<<"yes"<<endl;
         
      }
      else cout<< "no"<<endl ;
      
    
  
      
      
   }
   return 0 ;
 }




Measured memory_bytes: 3152
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll now = 0;
    ll tn=0;
    ll an=0;
    REP(i,n){
        ll t,a;
        cin >> t >> a;
        ll ok = (LLINF)/(t+a);
        ll ng = 0;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            bool f = true;
            if(mid*(t+a)<now){
                f = false;
            }else{
                if(mid*t<tn||mid*a<an){
                    f = false;
                }
            }
            if(f){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        now = ok*(t+a);
        tn = ok*t;
        an = ok*a;
    }
    cout << now << endl;

    return 0;
}

Measured memory_bytes: 3560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i=0; i<n; i++){
			String strArray[] = br.readLine().split(" ");
			int nballs[] = new int[10];
			int b=0,c=0;
			boolean judge = true;

			for(int j=0; j<nballs.length; j++){
				nballs[j] = Integer.parseInt(strArray[j]);

				if(b<nballs[j]){
					b=nballs[j];
				}else if(c<nballs[j]){
					c=nballs[j];
				}else{
					judge=false;
					break;
				}

			}
			System.out.println(judge ? "YES" : "NO");

		}
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

unsigned long long n, ans;

int main() {
  cin >> n;
  int upp = sqrt(n) + 0.5;
  FOR(i, 1, upp) if (n / i == n % i) ans += i;
  FOR(i, 1, upp - 1) if ((n - i) % i == 0 && (n - i) / i > upp) {
    ans += (n - i) / i;
  }
  cout << ans;
}


Measured memory_bytes: 256
'use strict'
 
function Main(input) {
    var params = input.split('\n')[0];
    
    let sum = 0;
    params.split('').map(c => {
        if (c == '1') sum++;
    })
    console.log(sum);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int st[60];

int main() {
	int n,p,pp;
	while(n=in(),pp=in()){
		p=pp;
		memset(st,0,sizeof(st));
		int i=0;
		while(true){
			if(p){
				st[i]++;
				p--;
				if(st[i]==pp)break;
			}else{
				p+=st[i];
				st[i]=0;
			}
			i++;
			i%=n;
		}
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long Int;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n/100 > 2) n -= 800; else n += 800;
    if (n%100/10 > 2) n -= 80; else n += 80;
    if(n%10 == 9) n -= 8; else n += 8;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val s = sc.next
    val unb = findUnbalance(s)
    println(unb(0) + " " + unb(1))
  }
  def findUnbalance(s: String) =  {
    if (s.length < 2) {
      Array(-1, -1) 
    } else if (s.length == 2) {
      if (s(0) == s(1)) Array(1, 2) else Array(-1, -1)
    } else {
    val N = s.length
    var unb = Array(-1, -1)
    for (i <- 0 until N-2) {
      val s1 = s(i)
      val s2 = s(i+1)
      val s3 = s(i+2)
      if (s1 == s2) unb = Array(i+1, i+2)
      if (s2 == s3) unb = Array(i+2, i+3)
      if (s1 == s3) unb = Array(i+1, i+3)
    }
    val u = unb
    u
    }
  }

}

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

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;
        
        int sum2 = 0, sum5 = 0;
        
        for( int i = n; i > 0; i-- )
        {
            int n2 = i, n5 = i;
            while( 1 )
            {
                if( n2 % 2 == 0 )
                {
                    sum2++;
                    n2 /= 2;
                }
                else
                    break;
            }
            while( 1 )
            {
                if( n5 % 5 == 0 )
                {
                    sum5++;
                    n5 /= 5;
                }
                else
                    break;
            }
        }
        if( sum2 < sum5 )
            cout << sum2 << endl;
        else
            cout << sum5 << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
  
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    if(n == 1){
        cout << a[0] << endl;
        return 0;
    }
    if(n % 2 == 0){
        rep(i, n){
            if(i == n - 1){
                cout << a[n - 2] << endl;
            }else{
                if(i < n / 2){
                    cout << a[n - 1 - i * 2] << " ";
                }else{
                    cout << a[(i - n / 2) * 2] << " ";
                }
            }
        }
    }else{
        rep(i, n){
            if(i == n - 1){
                cout << a[n - 2] << endl;
            }else{
                if(i < n / 2 + 1){
                    cout << a[n - 1 - i * 2] << " ";
                }else{
                    cout << a[(i - n / 2 - 1) * 2 + 1] << " ";
                }
            }
        }
    }
}

Measured memory_bytes: 3712
import java.util.Scanner;


public class Main{
	
	static Scanner sc = new Scanner(System.in);

	static int loan = 100000, week;
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		week = sc.nextInt();
		
		return true;
	}
	
	public static void solve(){
		
		for(int i = 0; i < week; i++){
			loan *= 1.05;
			if(loan % 1000 != 0){
				loan += 1000 - loan % 1000;
			}
		}
		System.out.println(loan);
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc054/tasks/abc054_c

int p[10][10];

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

    int a, b;
    REP(i, M) {
        cin >> a >> b;
        p[a][b] = 1;
        p[b][a] = 1;
    }

    vector<int> perm(N-1);
    REP(i, N-1) perm[i] = i + 2;
    sort(perm.begin(), perm.end());

    int ans = 0;
    do {
        int now = 1;
        for (int i = 0; i < perm.size(); i++) {
            if (!p[now][perm[i]]) break;
            now = perm[i];
            if (i == perm.size()-1) ans++;
        }
    } while(next_permutation(perm.begin(), perm.end()));

    cout << ans << "\n";

    return 0;
}


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

int find(vector<int> &root, int x){
    if (x == root[x]) return x;
    root[x] = find(root, root[x]);
    return root[x];
}
bool check(vector<int> &root, int x, int y){
    return find(root, x) == find(root, y);
}
void unions(vector<int> &root, vector<int> &size, int x, int y){
    x = find(root, x);
    y = find(root, y);
    if (size[x] <= size[y]) root[x] = y;
    else root[y] = x;
    if (size[x] == size[y]) size[x]++;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i<n; i++) cin >> p[i];
    vector<int> root(n+1);
    for (int i = 1; i <= n; i++) root[i] = i;
    vector<int> size(n+1);
    for (int i = 0; i < n+1; i++) size[i] = 0;
    int s,t;
    for (int i = 0; i<m; i++){
        cin >> s >> t;
        if (!check(root, s, t)) unions(root, size, s, t);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (p[i-1] == i || check(root, p[i-1], i)) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 1408
#include <iostream>

using namespace std;

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

    int a_num, c_num;
    if(k>=a){
        a_num = a;
        k -= a_num;
    }
    else{
        a_num = k;
        k = 0;
    }
    if(k>=b){
        k -= b;
    }
    else{
        k = 0;
    }
    if(k>=c){
        c_num = c;
        k -= c_num;
    }
    else{
        c_num = k;
        k = 0;
    }

    int sum = 1 * a_num - 1 * c_num;

    cout << sum;

    return 0;
}

Measured memory_bytes: 3592
/*input

*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb          push_back
#define pp          pop_back
#define nl          cout << "\n"
#define MIN(con)    (*min_element(ALL(con)))
#define MAX(con)    (*max_element(ALL(con)))
#define NX(cont)    next_permutation(ALL(cont))
#define PX(cont)    prev_permutation(ALL(cont))
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define all(c)      c.begin(),c.end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sp          cout << " "
#define ifalse      ios_base::sync_with_stdio(false),cin.tie(NULL)
#define debug(x)    cout << #x << " = " << x << "\n";

using ll = long long;
using ld = long double;
 
template <typename T> T GCD(T a, T b) { ll t; while(a){ t=a; a=b%a; b=t; } return b; }
template <typename T> T LCM(T a, T b) { return (a*b) / GCD(a, b); }
template <typename T> string toString(T a) { return to_string(a); }
template <typename T> void toInt(string s, T &x) { stringstream str(s); str >> x; }

ll add(ll x, ll y, ll MOD) { x += y; if(x >= MOD) x -= MOD; return x; }
ll sub(ll x, ll y, ll MOD) { x -= y; if(x < 0) x += MOD; return x; }
ll mul(ll x, ll y, ll MOD) { return ((x % MOD) * (y % MOD)) % MOD; }

ll powr(ll a, ll b, ll MOD) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a, MOD);
    a = mul(a, a, MOD);
    b >>= 1;
  }
  return x;
}

ll inv(ll a, ll MOD) { return powr(a, MOD-2, MOD); }
const ll INF =  1e18;
const int SINF = 1e9;
const ll MOD = 1e9 + 7;

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/************************************START***************************************/
const int N = 100005;

int main()
{
  ifalse;
  int a, b;
  cin >> a >> b;
  int d = max(a, b);
  if(d == a) {
    a --;
  }
  else if(d == b) {
    b --;
  }
  d += max(a, b);
  cout << d;
  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int N;
	int a[100];
	cin >> N;
	int s=0;
	for(int i=0;i<N;i++){
		cin >> a[i];
		s+=a[i];
	}
	int d=abs(a[0]*N-s);
	int ret=0;
	for(int i=1;i<N;i++){
		if(abs(a[i]*N-s)<d){
			ret=i;
			d=abs(a[i]*N-s);
		}
	}
	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 256