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

typedef pair< pair<int,int> , pair<int,int> > ppp;

ll dp[3],new_dp[3];

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

  // freopen("street.in","r",stdin);
    //freopen("out.txt","w",stdout);

   int n; cin>>n;
   for(int i=0;i<n;i++){
        int input[3];
        cin>>input[0]>>input[1]>>input[2];
        memset(new_dp,0,sizeof new_dp);
        for(int j=0;j<3;j++){
            for(int m=0;m<3;m++){
                if(m!=j){
                    new_dp[m]=max(new_dp[m],dp[j]+input[m]);
                }
            }
        }
    for(int j=0;j<3;j++)
        dp[j]=new_dp[j];
   }

    cout<<max({dp[0],dp[1],dp[2]});
return 0;

}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,i,j,s,h[40],t[40],p,o,max,k;
  while(scanf("%d %d",&n,&m),n||m){
    short d[40][1<<16]={0};
    for(i=0;i<n;i++){
      for(j=h[i]=0;j<16;j++){
	scanf("%d",&s);
	h[i]=h[i]*2+s;
      }
    }
    for(i=0;i<m;i++){
      for(j=t[i]=0;j<16;j++){
	scanf("%d",&s);
	t[i]=t[i]*2+s;
      }
    }
    d[0][0]=1;
    for(i=max=0;i<n;i++){
      for(j=0;j<1<<16;j++){//printf("%d",d[i][j]);
	if(d[i][j]==0)continue;
	//for(k=16;k--;printf("%d",(j>>k)%2));printf(" %d:",d[i][j]);
	for(k=0;k<m;k++){
	  s=(j|h[i])&(~t[k]);
	  o=(j|h[i])&t[k];//printf("%s\n",bs);
	  for(p=0;o;o/=2)p+=o%2;
	  if(d[i+1][s]<d[i][j]+p)d[i+1][s]=d[i][j]+p;
	  if(max<d[i+1][s])max=d[i+1][s];
	}//printf("\n");
      }//printf("\n");
    }
    /*for(j=0;j<1<<16;j++){
      if(d[i][j]==0)continue;
      for(k=16;k--;printf("%d",(j>>k)%2));printf(" %d:",d[i][j]);
      }printf("\n");//*/
    printf("%d\n",max-1);
  }
  return 0;
}

Measured memory_bytes: 5728
//最大値と2番目に大きい数の表示
#include <iostream>
using namespace std;
int main(){
  int n,i,my_max=0,my_sec=0,cnt=0;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++){
	cin >> a[i];
    if(my_max<a[i]){
      my_max=a[i];
    }else if(my_sec<a[i]){
      my_sec=a[i];
    }
  }
  for(i=0;i<n;i++){
    if(my_max==a[i]){
      cnt++;
    }
  }    
  for(i=0;i<n;i++){
    if(my_sec!=0){
      if(my_max!=a[i]){
        cout << my_max << endl;
      }else if(cnt>1){
        cout << my_max << endl;
      }else{
        cout << my_sec << endl;
      }
    }else{
      cout << my_max << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2432
// ITP1_2_D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;

bool func(int Ct, int Cu, int Cl, int Cr, int W, int H)
{
    if (Ct < 0 || H < Ct)return false;
    if (Cu < 0 || H < Cu)return false;
    if (Cl < 0 || W < Cl)return false;
    if (Cr < 0 || W < Cr)return false;
    return true;
}

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    //  円の上下左右のポイントが四角の中にあればいい
    int Ct, Cu, Cl, Cr;//   上下左右
    Ct = y + r;
    Cu = y - r;
    Cl = x - r;
    Cr = x + r;
    if (func(Ct, Cu, Cl, Cr, W, H))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



Measured memory_bytes: 3096
import sys
import math

from collections import defaultdict
from collections import deque
import heapq
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s

n = load()
v = load_list()

heapq.heapify(v)
while len(v) > 1:
    e1 = heapq.heappop(v)
    e2 = heapq.heappop(v)
    heapq.heappush(v, (e1+e2)/2.0)

print(heapq.heappop(v))
    


Measured memory_bytes: 3552
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

ll a, b, x;

int main(){
    ios::sync_with_stdio(0);
    cin >> a >> b >> x;
    cout << (b/x + 1) - (a == 0 ? 0 : (a-1LL)/x + 1) << "\n";
    return 0;
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	Matrix a(n,Array(n));
	REP(i,n) REP(j,n) cin>>a[i][j];

	Array dp1((1LL<<n),0);
	REP(bit,(1LL<<n)){
		Array as;
		REP(i,n) if(bit&(1LL<<i)) as.push_back(i);
		REP(i,as.size()) rep(j,i+1,as.size()) dp1[bit]+=a[as[i]][as[j]];
	}

	Array dp2((1LL<<n),0);
	REP(mask,(1LL<<n)){
		Array as;
		REP(i,n){
			if(!(mask&(1LL<<i))) as.push_back(i);
		}

		ll m=as.size();
		REP(bit,(1LL<<m)){
			ll x=0;
			REP(i,m) if(bit&(1LL<<i)) x+=(1LL<<as[i]);
			chmax(dp2[mask+x],dp2[mask]+dp1[x]);
		}
	}

	cout<<dp2[(1LL<<n)-1]<<en;
}

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

    solve();
    return 0;
}

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

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count = 0;
  
  for(int a = 0; a <= A; a++){
    if(X >= 500 * a){
      for(int b = 0; b <= B; b++){
        int t = X - (500 * a + 100 * b);
        if(0 <= t && t <= 50 * C){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,s,a,b,c,ans=0;
	cin>>k>>s;
	for(int i=0;i<=s;i++)
		{a=i;
		for(int j=0;j<=s;j++)
			{b=j;
			c=s-a-b;
			if(a<=k and b<=k and c<=k and a>=0 and b>=0 and c>=0) ans++;
			}
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n, a[200005];
vector<int> G[200005];
int b[200005], ans[200005];
void init(){
    n = read();
    for (int i = 1; i <= n; ++i)
        a[i] = read();
    for (int i = 1; i < n; ++i){
        int u = read(), v = read();
        G[u].push_back(v);
        G[v].push_back(u);
    }
    fill(b, b + n + 1, INF);
}
void dfs(int cur, int fa){
    int pos = lower_bound(b, b + n + 1, a[cur]) - b;
    int tmp = b[pos];
    b[pos] = a[cur];
    ans[cur] = lower_bound(b, b + n + 1, INF) - b;
    for (int x: G[cur]){
        if (x == fa) continue;
        dfs(x, cur);
    }
    b[pos] = tmp;
}
void solve(){
    dfs(1, 0);
    for (int i = 1; i <= n; ++i)
        printf("%d\n", ans[i]);
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 31324
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string s,t;
int main(){
    cin >> s >> t;
    rep(i,sz(s)){
        s = *(s.end()-1) + s;
        s.pop_back();
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);


int main()
{
    int64 t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    int64 d1 = (a1 - b1) * t1;
    int64 d2 = (a2 - b2) * t2;

    // d1が負ならAとBを入れ替えてd1を正にする
    if (d1 < 0)
    {
        d1 = -d1;
        d2 = -d2;
    }

    // d1とd2が同符号：差は広まる一方
    if (d2 > 0)
    {
        cout << 0 << endl;
        return 0;
    }

    // d1 > 0, d2 < 0が確定

    // d1 > |d2|：やはり差は広まる一方
    if (d1 > -d2)
    {
        cout << 0 << endl;
        return 0;
    }
    // d1 = |d2|：無限回追いつく
    if (d1 == -d2)
    {
        cout << "infinity" << endl;
        return 0;
    }

    // d1 < |d2|が確定
    // |d1 - |d2|| = |d1 + d2| = -d1 - d2
    int64 peak = d1 / (-d1 - d2) + 1;
    int64 mod = d1 % (-d1 - d2);
    if (mod == 0)
    {
        cout << (2 * (peak - 1)) << endl;
    }
    else
    {
        cout << (2 * peak - 1) << endl;
    }

    return 0;
}


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

#define MAX_H 2000
#define MAX_W 2000

char data[MAX_H][MAX_W];
int len_v[MAX_H][MAX_W];
int len_h[MAX_H][MAX_W];

int main(void){
	char buffer[2048];
	fgets(buffer, sizeof(buffer), stdin);
	char *tok = strtok(buffer, " ");
	const int H = atoi(tok);
	tok = strtok(0, " ");
	const int W = atoi(tok);
	
//	char data[H][W];
	for(int y = 0; y < H; y ++){
		fgets(buffer, sizeof(buffer), stdin);
		for(int x = 0; x < W; x ++){
			data[y][x] = buffer[x];
		}
	}
	
	for(int y = 0; y < H; y ++){
		char* col = data[y];
		int len_l[W];
		int len_r[W];
		if(col[0] == '.'){
			len_l[0] = 1;
		}else{
			len_l[0] = 0;
		}
		if(col[W - 1] == '.'){
			len_r[W - 1] = 1;
		}else{
			len_r[W - 1] = 0;
		}
		for(int x = 1; x < W; x ++){
			if(col[x] == '.'){
				len_l[x] = len_l[x - 1] + 1;
			}else{
				len_l[x] = 0;
			}
			if(col[W - x - 1] == '.'){
				len_r[W - x - 1] = len_r[W - x] + 1;
			}else{
				len_r[W - x - 1] = 0;
			}
		}
		int* len_col = len_v[y];
		for(int x = 0; x < W; x ++){
			if(col[x] == '.'){
				len_col[x] = len_l[x] + len_r[x] - 1;
			}else{
				len_col[x] = 0;
			}
//			printf("%d, ", len_col[x]);
		}
//		puts("");
	}
	
	
	for(int x = 0; x < W; x ++){
		int len_u[H];
		int len_d[H];
		if(data[0][x] == '.'){
			len_u[0] = 1;
		}else{
			len_u[0] = 0;
		}
		if(data[H - 1][x] == '.'){
			len_d[H - 1] = 1;
		}else{
			len_d[H - 1] = 0;
		}
		for(int y = 1; y < H; y ++){
			if(data[y][x] == '.'){
				len_u[y] = len_u[y - 1] + 1;
			}else{
				len_u[y] = 0;
			}
			if(data[H - y - 1][x] == '.'){
				len_d[H - y - 1] = len_d[H - y] + 1;
			}else{
				len_d[H - y - 1] = 0;
			}
		}
		for(int y = 0; y < H; y ++){
			if(data[y][x] == '.'){
				len_h[y][x] = len_u[y] + len_d[y] - 1;
			}else{
				len_h[y][x] = 0;
			}
//			printf("%d, ", len_h[y][x]);
		}
//		puts("");
	}
	int max = 0;
	for(int y = 0; y < H; y ++){
		for(int x = 0; x < W; x ++){
			const int count = len_h[y][x] + len_v[y][x] - 1;
			if(count > max){
				max = count;
			}
		}
	}
	printf("%d\n", max);
	
	return 0;
}





Measured memory_bytes: 35328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextInt();
        long ans = (x / 500) * 1000;
        x %= 500;
        ans += x / 5 * 5;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    string S;
    cin>>S;
    ll X, Y;
    cin>>X>>Y;
    ll T=0;
  	ll Sz=S.size();
    while(S.at(T)=='F'){
        X--;
        T++;
      	if(T==Sz){
          	Yes(X==0&&Y==0);
          	return 0;
        }
    }
    ll U=1;
    vector<vector<ll>> W(2, vector<ll>(0));
    ll J=0;
    for(ll i=T+1; i<Sz; i++){
        if(S.at(i)=='T'){
            if(J>0)W[U].push_back(J);
            J=0;
            U=1-U;
            continue;
        }
        J++;
    }
    if(J>0)W[U].push_back(J);
    J=0;
    U=1-U;
    ll SzX=W[0].size();
    vector<vector<bool>> dp(SzX+1, vector<bool>(16610, false));
    dp[0][8005]=true;
    rep(i, SzX){
        rep(j, 16610){
            if(dp[i][j]){
                dp[i+1][j-W[0][i]]=true;
                dp[i+1][j+W[0][i]]=true;
            }
        }
    }
    ll SzY=W[1].size();
    vector<vector<bool>> dp2(SzY+1, vector<bool>(16610, false));
    dp2[0][8005]=true;
    rep(i, SzY){
        rep(j, 16610){
            if(dp2[i][j]){
                dp2[i+1][j-W[1][i]]=true;
                dp2[i+1][j+W[1][i]]=true;
            }
        }
    }
    Yes(dp[SzX][8005+X]&&dp2[SzY][8005+Y]);
}
     

Measured memory_bytes: 8576
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int A[] = new int[N];
		int sum = 0;
		int ans = 0;

		for(int a = 0; a < N; a++){
			A[a] = stdIn.nextInt();
			sum += A[a];
		}

		for(int b = 0; b < N; b++){
			if(A[b] >= sum / 4.0 / M){
				ans++;
			}
		}
		if(ans >= M){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		stdIn.close();
	}
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[100][4][4], mod;
bool done[100][4][4];
char grid[100][2];
int n;
ll dp(int a, int t, int b)
{
	if (a == n) return 1;
	if (done[a][t][b]) return memo[a][t][b];
	ll ans = 0;

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{

			if (grid[a-1][0] == grid[a][0] && t != i) continue;
			if (grid[a-1][0] != grid[a][0] && t == i) continue;
			if (grid[a-1][1] == grid[a][1] && b != j) continue;
			if (grid[a-1][1] != grid[a][1] && b == j) continue;
			if (grid[a][0] == grid[a][1] && i != j) continue;
			if (grid[a][0] != grid[a][1] && i == j) continue;
			ans+=dp(a+1, i, j);
			ans%=mod;
		}
	}
	done[a][t][b] = true;
	return memo[a][t][b] = ans;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf(" %c", &grid[i][0]);
	}
	for (int i = 0; i < n; i++)
	{
		scanf(" %c", &grid[i][1]);
	}
	ll ans = 0;
	mod = 1000000007;
	int a = 0;
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (grid[a][0] == grid[a][1] && i != j) continue;
			if (grid[a][0] != grid[a][1] && i == j) continue;
			ans+=dp(1, i, j);
			ans%=mod;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split())
A =list(map(int, input().split()))
B =list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
AB =[]
ABC = []
for i in range(X):
    for j in range(Y):
        ab = A[i] + B[j]
        AB.append(ab)
AB.sort(reverse = True)
for i in range(min(K, X*Y)):
    for j in range(Z):
        abc = AB[i] + C[j]
        ABC.append(abc)
ABC.sort(reverse = True)
for i in range(K):
    print(ABC[i])

Measured memory_bytes: 139136
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<map>
#include<list>
#include<string>
#include<algorithm>
 
using namespace std;

int main(){
  int num;
  cin >> num;
  int a = num/1000;
  int b = (num - 1000*a)/100;
  int c = (num - 1000*a - 100*b) / 10;
  int d = (num - 1000*a - 100*b - 10*c);
  if(a+b+c+d==7){
    cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
  }else if(a+b+c-d==7){
    cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
  }else if(a+b-c+d==7){
    cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
  }else if(a-b+c+d==7){
    cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
  }else if(a-b-c+d==7){
    cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
  }else if(a-b+c-d==7){
    cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
  }else if(a-b-c-d==7){
    cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
  }else if(a+b-c-d==7){
    cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
  }
}



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

using namespace std;

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

using ll = long long;
const long long MOD = 1e9+7;

using P = pair<int, int>;

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

    auto high = [](int i){
        while (10 <= i) i /= 10;
        return i;
    };
    auto low = [](int i){ 
        return i % 10;
    };

    map<P, int> cnt;
    for (int i = 1; i <= n; i++) {
        int h = high(i), l = low(i);
        cnt[P(h, l)]++;
    }

    ll ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            ans += (ll)cnt[P(i, j)] * cnt[P(j, i)];
        }
    }
    cout << ans << endl;
}   

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

int main() {
  int n;
  cin >> n;
  vector<long int> h(n);
  for(int i = 0; i < n; i++) cin >> h[i];

  vector<long int> v(n);
  for(int i = 0; i < n; i++) v[i] = h[i];

  sort(v.begin(), v.end());
  // for(int i = 0; i < n; i++) cout << v[i] << " ";

  for(int i = 0; i < n; i++) {
    if(abs(h[i] - v[i]) > 1) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n ;cin >> n;
	vector<bool> ispairAB(n);
	vector<bool> ispairCD(n);
	rep(i,n)
	{
		ispairAB[i]=false;
		ispairCD[i]=false;
	}
	vector<pair<int, int>> AB;
	vector<pair<int, int>> CD;
	rep(i,n)
	{
		int foo,fooo;
		cin >> foo >> fooo;
		AB.emplace_back(foo,fooo);
	}
	rep(i,n)
	{
		int foo,fooo;
		cin >> foo >> fooo;
		CD.emplace_back(foo,fooo);
	}
	sort(ALL(AB));
	sort(ALL(CD));
	int c=0;
	rep(i,n)
	{
		int max=-1;
		int maxnum=-1;
		for(int j=0;j<n&&AB[j].first<CD[i].first;j++)
		{
			if( (!ispairAB[j])&&(!ispairCD[i]))
			if(AB[j].second<CD[i].second)
			{	
				if(max<AB[j].second)
				{
					max=AB[j].second;
					maxnum = j;
				}
			}
		}
		if(max!=-1)
		{
			ispairCD[i]=true;
			ispairAB[maxnum]=true;
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

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


class BIT{
  private:
	int bit[500010]={};

  public:
	int sum(int i){
      if (i==0) return 0;
  	  int s=0;
      while (i>0){
        s+=bit[i];
        i-=i&(-i);
      }
      return s;
    }

    void add(int n,int i,int k){
      while (i<=n){
        bit[i]+=k;
        i+=i&(-i);
      }
    }
  
};


int main(void){
  int n,i,j,q,t;
  string s;
  BIT cl[27];
  
  cin >> n >> s >> q;
  
  for (i=0;i<n;i++){
    cl[s[i]-'a'].add(n,i+1,1);
  }
  
  for (i=0;i<q;i++){
    cin >> t;
    if (t==1){
      
      int iq;
      char c;
      cin >> iq >> c;
      cl[s[iq-1]-'a'].add(n,iq,-1);
      cl[c-'a'].add(n,iq,1);
      s[iq-1]=c;
      
    }else{
      
      int l,r,res=0;
      cin >> l >> r;
      for (j=0;j<26;j++){
        if (cl[j].sum(r)-cl[j].sum(l-1)>0) res++;
      }
      cout << res << endl;
      
    }
  }
  
  return 0;
}

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

int main() {
    int n,m,x,y;cin>>n>>m>>x>>y;
    int a[n],b[m];

    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    for(int i=0;i<m;++i){
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+m);
    int ans=0;
    if(a[n-1]<b[0]){
        for(int i=a[n-1]+1;i<=b[0];++i){
            if(x<i && y>=i){
                ans=1;
                break;
            }
        }
    }
    if(ans==1) cout<<"No War"<<endl;
    else    cout<<"War"<<endl;
	return 0;
}

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

int g[201][201];

int main() {
  int n; scanf("%d", &n);
  
  for(int i = 1; i <= 200; ++i) {
    for(int j = 1; j <= 200; ++j) {
      g[i][j] = g[j][i] = __gcd(i, j);
    }
  }

  int ans = 0;

  for(int a = 1; a <= n; ++a) {
    for(int b = 1; b <= n; ++b) {
      for(int c = 1; c <= n; ++c) {
        ans += g[a][g[b][c]];
      }
    }
  }
  printf("%d", ans);
  return 0;
}

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

int main()
{
	double a,b;
	while(cin >> a >> b)
	{
		if(a < 35.50 && b < 71.00) cout << "AAA" << endl;
		else if(a < 37.50 && b < 77.00) cout << "AA" << endl;
		else if(a < 40.00 && b < 83.00) cout << "A" << endl;
		else if(a < 43.00 && b < 89.00) cout << "B" << endl;
		else if(a < 50.00 && b < 105.00) cout << "C" << endl;
		else if(a < 55.00 && b < 116.00) cout << "D" << endl;
		else if(a < 70.00 && b < 148.00) cout << "E" << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
import sys
input = sys.stdin.readline
import heapq as hp

Q = int(input())
Query = []
for _ in range(Q):
    N = int(input())
    KLR = [list(map(int, input().split())) for _ in range(N)]
    Query.append((N, KLR))

for N, KLR in Query:
    basic = 0
    Ls = [[] for _ in range(N)]
    Rs = [[] for _ in range(N)] 
    for k, l, r in KLR:
        if l > r:
            basic += r
            Ls[k-1].append(l-r)
        elif r > l:
            if k != N:
                basic += l
                Rs[k].append(r-l)
            else:
                basic += l
        else:
            basic += r
    
    ans = basic
    q1 = []
    for i in reversed(range(N)):
        for l in Ls[i]:
            hp.heappush(q1, -l)
        if q1:
            p = -hp.heappop(q1)
            ans += p
    
    q2 = []
    for i in range(N):
        for r in Rs[i]:
            hp.heappush(q2, -r)
        if q2:
            p = -hp.heappop(q2)
            ans += p
    
    print(ans)

Measured memory_bytes: 132136
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    mp[a]++, mp[b]++;
  }
  bool ok = true;
  for (auto a : mp) {
    if (a.second % 2) ok = false;
  }
  cout << (ok ? "YES" : "NO") << endl;
  return 0;
}

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

int main()
{
	double n,cnt=0;
	cin >> n;
	
	for (int i = 1; i <= n; ++i)
	{
		if (i%2 != 0)
		{
			cnt++;
		}
	}
	cout << cnt/n << endl;
}

Measured memory_bytes: 256
#include<map>
#include<string>
#include<iostream>

using namespace std;

int main()
{
	map<char,string> en;
	en[' ']="101";		en['\'']="000000";	en[',']="000011";
	en['-']="10010001";	en['.']="010001";	en['?']="000001";
	en['A']="100101";	en['B']="10011010";	en['C']="0101";
	en['D']="0001";		en['E']="110";		en['F']="01001";
	en['G']="10011011";	en['H']="010000";	en['I']="0111";
	en['J']="10011000";	en['K']="0110";		en['L']="00100";
	en['M']="10011001";	en['N']="10011110";	en['O']="00101";
	en['P']="111";		en['Q']="10011111";	en['R']="1000";
	en['S']="00110";	en['T']="00111";	en['U']="10011100";
	en['V']="10011101";	en['W']="000010";	en['X']="10010010";
	en['Y']="10010011";	en['Z']="10010000";

	map<string,char> de;
	de["00000"]='A';	de["00001"]='B';	de["00010"]='C';
	de["00011"]='D';	de["00100"]='E';	de["00101"]='F';
	de["00110"]='G';	de["00111"]='H';	de["01000"]='I';
	de["01001"]='J';	de["01010"]='K';	de["01011"]='L';
	de["01100"]='M';	de["01101"]='N';	de["01110"]='O';
	de["01111"]='P';	de["10000"]='Q';	de["10001"]='R';
	de["10010"]='S';	de["10011"]='T';	de["10100"]='U';
	de["10101"]='V';	de["10110"]='W';	de["10111"]='X';
	de["11000"]='Y';	de["11001"]='Z';	de["11010"]=' ';
	de["11011"]='.';	de["11100"]=',';	de["11101"]='-';
	de["11110"]='\'';	de["11111"]='?';

	string s,z[5];
	for(int i=1;i<5;i++)	z[i]+=z[i-1]+'0';
	while(getline(cin,s)){
		string code;
		for(int i=0;i<s.length();i++)		code+=en[s[i]];
		if(code.length()%5!=0)				code+=z[5-code.length()%5];
		for(int i=0;i<code.length();i+=5)	cout<<de[code.substr(i,5)];
		cout<<endl;
	}

	return 0;
}

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

int main()
{
    int a[5], k;
    for(int i = 0; i < 5; ++i) cin >> a[i];
    cin >> k;
    for(int i = 0; i < 5; ++i) {
        for(int j = i; j < 5; ++j) {
            if(k < abs(a[i] - a[j])) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}


Measured memory_bytes: 256
def gcd( x, y ):
	if 1 < y < x:
		return gcd( y, x%y )
	else:
		if y == 1:
			return 1
		return x

a, b = [ int( val ) for val in raw_input( ).split( " " ) ]
if a < b:
	a, b = b, a
print( gcd( a, b ) )

Measured memory_bytes: 4204
n=gets.to_i
p=q=0
(0..n-1).each{|i|
  t,h=gets.chomp.split;
  case t<=>h
  when -1 then
    q+=3
  when 0 then
    p+=1
    q+=1
  when 1 then
    p+=3
  end
}
puts "#{p} #{q}"

Measured memory_bytes: 6100
#include<stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1000000

int n, M[MAX][MAX];

void dijkstra();

int main() {
	int i, j, k, c, u, v;
	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			M[i][j] = INFTY;
		}
	}

	for (i = 0; i < n; i++) {
		scanf("%d%d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d%d", &v, &c);
			M[u][v] = c;
		}
	}

	dijkstra();
	return 0;
}

void dijkstra() {
	int u, minv, i, j, v, sum = 0;
	int d[MAX], p[MAX], color[MAX];

	for (i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}
	d[0] = 0;
	color[0] = GRAY;
	while (1) {
		minv = INFTY;
		u = -1;
		for (i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}

		if (u == -1) break;
		color[u] = BLACK;
		for (v = 0; v < n; v++) {
			if (color[v] != BLACK && M[u][v] != INFTY) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	for (i = 0; i < n; i++) {
		if (d[i] == INFTY) {
			printf("%d -1\n", i);
		}
		else {
			printf("%d %d\n", i, d[i]);
		}
	}
}



Measured memory_bytes: 2104
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
		int N = nextInt();
		int mod = 1000000007;
		int[] dp = new int[200005];
		dp[0] = 1;
		int mae = 0;
		for(int i = 0; i < N; i++){
			int C = nextInt();
			if(C == mae){
				continue;
			}
			dp[C] = (int)(((long)dp[C] + dp[mae]) % mod);
			mae = C;
		}
		myout(dp[mae]);
	}
	//Method addition frame start



	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	@SuppressWarnings("unchecked")
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}


Measured memory_bytes: 50860
A,B,K = map(int,input().split())
n = 0
ans = []
for i in range(K):
  n = i
  if A+i <= B:
    ans.append(A+i)
  else:    
    break
for j in range(K-1,-1,-1):
  if B-j > A+n:
    ans.append(B-j)
ans.sort()
for k in range(len(ans)):
  print(ans[k])

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

public class Main {

	void run () {
		Scanner sc = new Scanner(System.in);
		
		int[] array = new int[10];
		for (int i=0;i<10;i++) {
			array[i] = sc.nextInt();
		}
		
		Arrays.sort(array);
		
		System.out.println(array[9]);
		System.out.println(array[8]);
		System.out.println(array[7]);
	}

	public static void main(String[] args) {
		new Main().run();
	}
	
}

Measured memory_bytes: 26172
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

#bit全探索
l = set()
for bit in range(1 << n):
    sum = 0
    for i in range(n):
        if bit & (1 << i):
            sum += A[i]
    l.add(sum)

for i in m:
    if i in l:
        print("yes")
    else:
        print("no")


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

int main()
{
   long int x;
   cin>>x;
   
   long int p=1,s=0;
   
   while(x>0)
   {
       s+=p;
       p*=2;
       x/=2;
   }
   cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<int>> vv;
typedef unordered_map<char, int> um;

int n;
string s;

void default_vv(vv& w) {
    um h;
    rep(i, n) {
        if (h.count(s[i])) w[h[s[i]]].push_back(i);
        else {
            h[s[i]] = w.size();
            w.push_back({i});
        }
    }
}

inline vv make_vv(vv& w, int len) {
    vv x;
    um h;
    for (vector<int> v : w) {
        if (v.size() == 1) continue;
        if (v.back() - v[0] < len) continue;
        for (int i : v) {
            if (i != n - len) {
                if (h.count(s[i+len])) x[h[s[i+len]]].push_back(i);
                else {
                    h[s[i+len]] = x.size();
                    x.push_back({i});
                }
            }
        }
        h.clear();
    }
    return x;
}

int main() {
    cin >> n >> s;
    int len = 0;
    vv w;
    default_vv(w);
    while (w.size()) w = make_vv(w, ++len);
    cout << len - 1 << endl;
}


Measured memory_bytes: 800
#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#include <array>
#include <iterator>



using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl;
typedef pair < int, int> P;



int N, A[10000], B[10000];
int main() {
	cin >> N;
	rep(i, N - 1) {
		cin >> B[i];
	}
	A[0] = B[0];
	B[N - 1] = INF;
	for (int i = 1; i < N; i++) {
		A[i] = min(B[i - 1],B[i]);
	}
	int ans = 0;
	rep(i, N) {
		
		ans += A[i];
	}
	cout << ans << endl;

	
	


}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		String result = "No";
		if(n%10 == 9 || n/10 == 9) result = "Yes";
		
		// 出力
		System.out.println(result);
		
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define mp make_pair
#define ln '\n'
#define pb push_back
#define ll long long
using namespace std;

ll a[100010];

int main(){
    int n;
    scanf("%d",&n);

    for(int i=0;i<n;i++) 
        scanf("%lld",&a[i]);
    
    int zero=0;

    for(int i=0;i<n;i++)if(a[i]==0) 
        zero++;
    
    if(zero >0){
        // a[i] contains 0
        printf("0\n");
        return 0;   
    }

    long long prod =1;

    for(int i=0;i<n;i++){
        if(a[i ] <=1000000000000000000/ prod ){
            // This condition is equivalent to prod*a[i] <=10ˆ18
            prod *=a[i];
        } else {
            printf("-1\n");
            return 0;
        }
    }
    
    printf("%lld\n",prod );
}

Measured memory_bytes: 4488
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>

#define ll long long int

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


int main()
{
  ll n;
  char foot[100][2]={};
  int i;

  while(1){
    cin>>n;
    if(n==0)break;
    int sum=0;
    for(i=0;i<n;i++)
      cin>>foot[i][0]>>foot[i][1];
    for(i=1;i<n;i++){
           if(foot[i-1][1]==foot[i][1]){
	sum++;
	i++;
      }
    }
    cout<<sum<<endl;
  }

}

Measured memory_bytes: 1160
#include <stdio.h>

main() {
  int a,t,i, m, s, e;

  scanf("%d%d%d%d", &i,&m,&s,&e);
  a=i+m+s+e;
  scanf("%d%d%d%d", &i,&m,&s,&e);
  t=i+m+s+e;
  if(a>t) printf("%d\n", a);
  else printf("%d\n", t);;
  return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
int main(void){
	int a, b;
	scanf("%d %d", &a, &b);
	if (a == b){
		printf("a == b\n");
	}
	else if (a < b){
		printf("a < b\n");
	}
	else printf("a > b\n");

	return 0;
}

Measured memory_bytes: 580
import itertools
import fractions
def main():
  a,b = map(int,input().split())
  ans = 0
  for i in range(2):
    if a >= b:
      ans += a
      a -=1
    else:
      ans += b
      b -=1
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 5048
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>

namespace adaptor = boost::adaptors;
namespace mp = boost::multiprecision;

void solve()
{
    int64_t N;
	std::cin >> N;
	std::vector<mp::cpp_int> A(N);
	bool zero = false;
	for (int64_t i = 0; i < N; i++)
	{
		std::cin >> A[i];
		if (A[i] == 0)
		{
			std::cout << "0" << std::endl;
			zero = true;
		}
	}
	if (zero) return;

	mp::cpp_int ans = 1;
	for (int64_t i = 0; i < N; i++)
	{
		ans *= A[i];
		if (ans > (mp::cpp_int)pow(10, 18))
		{
			ans = -1;
			break;
		}
	}	


	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 6432
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

// 1indexed2dimention[]
class bit2d{
    public:
    vector<vector<ll> >v;
    ll h, w;
    bit2d(ll H = 0, ll W = 0){
        h = H + 5;
        w = W + 5;
        v = vector<vector<ll> >(h + 5, vector<ll>(w + 5, 0));
    }
    void add(ll x, ll y, ll val){
        for(ll yy = y; yy <= h; yy += yy & -yy){
            for(ll xx = x; xx <= w; xx += xx & -xx){
                v[yy][xx] += val;
            }
        }
    }
    ll sum_of_1_to_idx(ll x, ll y){
        if(x <= 0 || y <= 0)return 0;
        if(x > w || y > h)return 0;
        ll s = 0;
        for(ll yy = y; yy > 0; yy -= yy & -yy){
            for(ll xx = x; xx > 0; xx -= xx & -xx){
                s += v[yy][xx];
            }
        }
        return s;
    }
    ll sum(ll x1, ll y1, ll x2, ll y2){
        ll s = 0;
        s += sum_of_1_to_idx(x2, y2);
        s -= sum_of_1_to_idx(x2, y1 - 1);
        s -= sum_of_1_to_idx(x1 - 1, y2);
        s += sum_of_1_to_idx(x1 - 1, y1 - 1);
        return s;
    }
};

int main(){

	ll H, W, h, w;
	cin >> H >> W >> h >> w;
	bit2d bit(H, W);
	rep1(y, H)rep1(x, W){
		ll pre_y = y - h + 1;
		ll pre_x = x - w + 1;
		if(pre_x < 1 || pre_y < 1)bit.add(x, y, 3000);
		else{
			ll sum = bit.sum(pre_x, pre_y, x, y);
			bit.add(x, y, -(sum + 1));
		}
	}
	if(bit.sum(1, 1, W, H) <= 0)cout << "No" << endl;
	else{
		cout << "Yes" << endl;
		rep1(y, H){
			rep1(x, W){
				cout << bit.sum(x, y, x, y);
				if(x < W)cout << " ";
				else cout << endl;
			}
		}
	}

    return 0;
}

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

#define INF 1e9
using namespace std;
using ll = long long;

int main() {

    ll N; cin >> N;

    if (N == 0) {
        cout << '0' << endl;
        return 0;
    }

    string S;

    while (N != 0) {
        ll a;
        a = N % (-2);
        if (a < 0) {
            a += 2;
        }

        S += a + '0';

        N = (N - a) / (-2);
    }

    reverse(S.begin(), S.end());

    cout << S << endl;
}

Measured memory_bytes: 256
N, *S = open(0).read().split()
N = int(N)
ans = 0
for p in range(N):
  flag = False
  for i in range(N):
    for j in range(N):
     x = i
     y = (j-p)%N
     a,b = y, (x+p)%N
     if S[i][j] != S[a][b]:
       flag = True
       break
    if flag:
      break
  else:
    ans+= N
print(ans)
     

Measured memory_bytes: 42092
#include<stdio.h>
#include<stdlib.h>

int main() {
    int N, *d;
    scanf("%d",&N);
    d = (int *)malloc(sizeof(int)*N);

    int i,j;
    for (i=0; i<N; i++)  scanf("%d",d+i);

    int hp=0;
    for (i=0; i<N-1; i++)
        for (j=i+1; j<N; j++)
            hp += d[i] * d[j];

    printf("%d", hp);

    free(d);
    return 0;
}

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

int main() {
    int k, x;
    cin >> k >> x;

    cout << (k * 500 >= x ? "Yes" : "No") << endl;
    
    return 0;
}

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

int main(){

    int h,w;
    int temp;
    cin>>h>>w;

    char s[51][51];
    char ans[51][51];

    for(int i=0;i<h;i++){

        for(int j=0;j<w;j++){

            cin>>s[i][j];

        }


    }

    for(int i=0;i<h;i++){

        for(int j=0;j<w;j++){
            temp=0;
            if(s[i-1][j-1]=='#') temp++;
            if(s[i-1][j]=='#') temp++;
            if(s[i-1][j+1]=='#') temp++;
            if(s[i][j-1]=='#') temp++;
            if(s[i][j+1]=='#') temp++;
            if(s[i+1][j-1]=='#') temp++;
            if(s[i+1][j]=='#') temp++;
            if(s[i+1][j+1]=='#') temp++;

            if(s[i][j]=='#') ans[i][j]='#';
            else ans[i][j]='0'+temp;
        }


    }

        for(int i=0;i<h;i++){

            for(int j=0;j<w;j++){

                cout<<ans[i][j];

            }
        cout<<endl;

        }

}

Measured memory_bytes: 256
n, y = map(int, input().split())
y //= 1000
D = y-n
for a in range(D//9 + 1):
  D2 = D-9*a
  if D2%4:
    continue
  else:
    b = D2//4
    if n-a-b >= 0:
      print(a, b, (n-a-b))
      exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
n, k = gets.chomp.split.map(&:to_i)
d = []
a = []

k.times do
d << gets.split.map(&:to_i)
a << gets.split.map(&:to_i)
end
b = (1..n).to_a
a = a.flatten
a.length.times do |i|
  if b.include?(a[i])
    b.delete(a[i])
  end
end
puts b.length

Measured memory_bytes: 14360
N = int(input())
A = [input() for i in range(N)]
count = 0
if len(A) != len(set(A)):
    print("No")
else:
    for i in range(0, N - 1):
        if A[i][len(A[i]) - 1] !=  A[i + 1][0]:
            print("No")
            count = 1
            break
    if count == 0:
        print("Yes")

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

int main(){
  long long int n,k,x,ans;
  cin >> n >> k;
  priority_queue<int> pq;
  for(int i = 0; i < n; i++){
    cin >> x;
    pq.push(x);
  }
  
  for(int i = 0; i < k; i++){
    pq.pop();
    if(pq.size()==0) break;
  }
  
  while(!pq.empty()){
    ans += pq.top();
    pq.pop();
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 1400
N,M=[int(i) for i in input().split()]
X=sorted([int(i) for i in input().split()])
W=X[-1]-X[0]
L=sum(sorted(list(map(lambda x: x[1]-x[0], zip(X,X[1:]))))[::-1][:N-1])
print(0) if N>=M else print(W-L)

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    if (N == 7 || N == 5 || N == 3) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,c,d;
  cin >> n;
  a = n/1000;
  b = (n-a*1000)/100;
  c = (n-a*1000-b*100)/10;
  d = n-a*1000-b*100-c*10;
  
  if (a == b){
    if(b == c){
      cout << "Yes" << endl;
    }
    else{
    cout << "No" << endl;
    }
    
  }
  else{
    if(b == c){
      if(c == d){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
    else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
/*Reconstruction of a Tree
Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree.

Input
In the first line, an integer n, which is the number of nodes in the binary tree, is given.
In the second line, the sequence of node IDs obtained by the preorder tree walk is given separated by space characters.
In the second line, the sequence of node IDs obtained by the inorder tree walk is given separated by space characters.

Every node has a unique ID from 1 to n. Note that the root does not always correspond to 1.

Output
Print the sequence of node IDs obtained by the postorder tree walk in a line. Put a single space character between adjacent IDs.

Constraints
1≤n≤40*/ 
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r){
	if(l>=r)
		return;
	int root=pre[pos++];
	int m=distance(in.begin(),find(in.begin(),in.end(),root));
	rec(l,m);
	rec(m+1,r);
	post.push_back(root);
}

void slove(){
	pos=0;
	rec(0,pre.size());
	for(int i=0;i<n;i++){
		if(i)
			cout<<" ";
		cout<<post[i];
	} 
	cout<<endl;
}

int main(){
	int k;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>k;
		pre.push_back(k);
	}
	for(int i=0;i<n;i++){
		cin>>k;
		in.push_back(k);
	}
	
	slove();
	
	return 0;
}


Measured memory_bytes: 3156