akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    int ans = 0;
    for (int i = 0; i < (1 << h); i++)
    {
        for (int j = 0; j < (1 << w); j++)
        {
            int sum = 0;
            for (int ii = 0; ii < h; ii++)
            {
                for (int jj = 0; jj < w; jj++)
                {
                    if (((1 << ii) & i) || ((1 << jj) & j))
                    {
                        continue;
                    }
                    if (c[ii][jj] == '#')sum++;
                }
            }
            if (sum == k)
                ans++;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3660
//https://atcoder.jp/contests/abc124/tasks/abc124_a
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    vector<int> v(2);
    cin >> v[0] >> v[1];
    cout << ( v[0] == v[1] ? v[0] * 2 : *max_element( ALL(v) ) * 2 - 1 ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n,x,y,z,i,j;
  int G[100][100];

  scanf("%d",&n);
  
  for(i=0;i<n;i++) {
    for(j=0;j<n;j++)
      G[i][j] = 0;
  }
  
  for(i=0;i<n;i++) {
    scanf("%d%d",&x,&y);
    x--; /* 行列と合うよう-1 */
    for(j=0;j<y;j++) {
      scanf("%d",&z);
      z--; /* 行列と合うよう-1 */
      G[x][z] = 1;
    }
  }

  for(i=0;i<n;i++) {
    for(j=0;j<n;j++) {
      if(j)
	printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
signed main() {
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << fixed << setprecision(10) << sqrt((c - a) * (c - a) + (d - b) * (d - b)) << endl;
	ggr
}



Measured memory_bytes: 3292
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        if (s.matches("A?KIHA?BA?RA?")) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }


using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;


const int MOD = 1e9+7;
const int INF = 1e9;
vi v;
int N;
void dfs(ll x, int a, int b, int c){
	if(x > N){
		return;
	}
	if(a>0&&b>0&&c>0){
		v.push_back(x);
	}
	dfs(10*x+3,a+1,b,c);
	dfs(10*x+5,a,b+1,c);
	dfs(10*x+7,a,b,c+1);

}
int main() {
	cin>>N;
	dfs(0,0,0,0);
	int ans = v.size();
	cout<<ans<<endl;

}

Measured memory_bytes: 512
#include <iostream>
#define MOD 998244353

using namespace std;
long long steps[200001];
int main() {
    int N, K;
    int L[10], R[10];
    cin >> N >> K;
    for (int i=0; i<K; i++) {
        cin >> L[i] >> R[i];
    }

    //steps[1] = 1;
    //for (int i=1; i<N; i++) {
    //    for (int j = 0; j < K; j++) {
    //        for (int d = L[j]; d <= R[j]; d++) {
    //            if (i + d <= N) {
    //                steps[i+d] += steps[i];
    //                steps[i+d] %= MOD;
    //            }
    //        }
    //    }
    //}
    //cout << steps[N] << endl;    

    steps[1] = 0; // accum
    steps[2] = MOD-1;
    long long answer = 1;
    for (int i=1; i<N; i++) {
        for (int j = 0; j < K; j++) {
            if (i + L[j] <= N) {
                steps[i+L[j]] += answer;
                steps[i+L[j]] %= MOD;
            }
            if (i + R[j] + 1 <= N) {
                steps[i + R[j] + 1] += MOD - answer;
                steps[i + R[j] + 1] %= MOD;
            }
        }
        answer += steps[i+1] + MOD;
        answer %= MOD;
    }
    cout << answer << endl;    
    
    return 0;
}



Measured memory_bytes: 5132
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int X = Integer.parseInt(st.nextToken());
         //solve
         for(int a=0; a < 4000; a++)
         {
            long A = power(a);
            for(int b=0; b < 4000; b++)
            {
               long B = power(b);
               for(int c=-1; c <= 1; c += 2)
                  for(int d=-1; d <= 1; d += 2)
                  {
                     long aa = A*c;
                     long bb = B*d;
                     if(aa-bb == X)
                     {
                        System.out.println((a*c)+" "+(b*d));
                        return;
                     }
                  }  
            }
         }
      }
      public static long power(int x)
      {
         long res = 1L;
         for(int i=0; i < 5; i++)
            res *= x;
         return res;
      }
   }

Measured memory_bytes: 36836
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<stdio.h>



using namespace std;


int main(void)
{
	long long int a;
	cin >> a;
	cout << a * a * 3 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;

int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい


int X,t;



int main(){
	cin>>X>>t;
	cout<<max(0,X-t)<<endl;

	
	return 0;
}

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

int main(){
    int a, b, c, x;
    int count = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(500*i + 100*j + 50*k == x){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
	
	int a0, l;
	
	int[] toIntArray(int n) {
		int[] a = new int[l];
		for (int i = 0; i < l; i++) {
			a[i] = (int)(n % 10);
			n /= 10;
		}
		return a;
	}
	
	int convertMin(int[] a) {
		if (a.length > 1) {
			int n = 0;
			for (int i = 0; i < a.length; i++) {
				n = (n * 10) + a[i];
			}
			return n;
		} else {
			return a[0];
		}
	}
	
	int convertMax(int[] a) {
		if (a.length > 1) {
			int n = 0;
			for (int i = a.length - 1; i >= 0; i--) {
				n = (n * 10) + a[i];
			}
			return n;
		} else {
			return a[0];
		}
	}
	
	void swap(int[] p, int i, int j) {
		int tmp = p[i];
		p[i] = p[j];
		p[j] = tmp;
	}
	
	String solve() {
		List<Integer> dup = new ArrayList<Integer>();
		dup.add(a0);
		
		int[] a = toIntArray(a0);
		Arrays.sort(a);
		while (true) {
			int p = convertMax(a) - convertMin(a);
			for (int i = 0; i < dup.size(); i++) {
				if (dup.get(i) == p) {
					return i + " " + dup.get(i) + " " + (dup.size() - i);
				}
			}
			dup.add(p);
			a = toIntArray(p);
			Arrays.sort(a);
		}
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		String output = "";
		while (sc.hasNext()) {
			a0 = sc.nextInt();
			l = sc.nextInt();
			if (a0 == 0 && l == 0) {
				break;
			} else {
				output += solve() + "\n";
			}
		}
		sc.close();
		System.out.print(output);
	}

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

}

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

int main(){
  vector<int> D(5);
  cin>>D[0]>>D[1]>>D[2]>>D[3]>>D[4];
  sort(D.begin(),D.end());
  int K; cin>>K;
  if(D[4]-D[0]<=K){
    cout<<"Yay!"<<endl;
  }else
    cout<<":("<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
            int min = sc.nextInt();
            int max = sc.nextInt();
            int d = sc.nextInt();

            int count = 0;

            for (int i = min; i <= max; i++) {
            	if (i % d == 0) {
            		count++;
            	}
            }

            System.out.println(count);

		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}

Measured memory_bytes: 35596
import java.util.Scanner;

class Main {
    static int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long nck[][] = new long[2500][2500];
        for (int i = 0; i < 2500; i++) {
            nck[i][0] = 1;
            nck[i][i] = 1;
        }
        for (int i = 1; i < 2300; i++) {
            for (int j = 1; j < i; j++) {
                nck[i][j] = (nck[i - 1][j] + nck[i - 1][j - 1]) % MOD;
            }
        }
        for (int i = 1; i < k + 1; i++) {
            // 計算をする.
            int akamasu = i + 1;
            int amari = (n - k) - akamasu + 2;
            long red = 0;
            if (akamasu + amari - 1 > amari) {
                if (amari >= 0) {
                    red = nck[akamasu + amari - 1][amari];
                }

            }
            if (red == 0) {
                System.out.println(0);
                continue;
            }

            // kをi個のグループに分割する.
            int nokori = k - i;
            long blue = nck[nokori + i - 1][i - 1];
            long ans = red * blue % MOD;
            System.out.println(ans);
        }
        sc.close();
    }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n);
    map<int32,int64> acnt;
    REP(i,n){
        cin >> a[i];
        acnt[a[i]]++;
    }
    int64 ans = 0;
    for(auto p : acnt){
        ans += p.second * (p.second-1) / 2;
    }
    REP(i,n){
        ANS(ans - acnt[a[i]] * (acnt[a[i]]-1) / 2 + (acnt[a[i]]-1) * (acnt[a[i]]-2) / 2);
    }
    return 0;
}

Measured memory_bytes: 11136
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			
			if(op.equals("?")) {
				break;
				
			}else if(op.equals("+")) {
				System.out.println(a + b);
				
			}else if(op.equals("-")) {
				System.out.println(a - b);
				
			}else if(op.equals("*")) {
				System.out.println(a * b);
				
			}else if(op.equals("/")) {
				System.out.println(a / b);
				
			}else {
				break;     //これ必要ないかもしれない
			}
		}
		
				
	}
}


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

int main() {
    int D,N;
    cin >> D >>N;
    if(D==0) {
        if (N == 100) {
            N = 101;
        }
        cout << N << endl;
    }else if(D==1) {
        if (N == 100) {
            N = 10100;
            cout << N << endl;
            exit(0);
        }
        cout << 100 * N << endl;
    }else if (D==2) {
        if (N == 100) {
            N = 1010000;
            cout << N << endl;
            exit(0);
        }
        cout << 10000 * N <<endl;
    }
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::multiprecision::cpp_int;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int n;
  cin >> n;
  cpp_int rtn = 1;
  vector<cpp_int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0\n";
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    rtn *= a[i];
    if (rtn > LINF) {
      cout << "-1\n";
      return 0;
    }
  }
  cout << rtn << endl;
}


Measured memory_bytes: 5996
#include<bits/stdc++.h>
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;
	ll k;
	cin >> n >> k;
	vector<ll> a(n), f(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> f[i];
	sort(ALL(a));
	sort(ALL(f), greater<ll>());
	ll l = -1;
	ll r = 1000000000000;
	while (r - l > 1) {
		ll mid = (l + r) / 2;
		ll p = k;
		bool b = true;
		rep(i,n) {
			ll t = 0;
			if (f[i] > mid) t = a[i];
			else if (a[i] * f[i] > mid) {
				t = (a[i] * f[i] - mid + f[i] - 1) / f[i];
			}
			if (p - t < 0) {
				b = false;
				break;
			}
			p -= t;
		}
		if (b) {
			r = mid;
		} else {
			l = mid;
		}
	}
	cout << r << endl;
}

Measured memory_bytes: 6396
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		//入力表示
		int N = sc.nextInt();
		Map<String, Integer> map = new HashMap<>();

		int max = 0;
		for (int i = 0; i < N; i++) {
			String S = sc.next();

			if (map.containsKey(S)) {
				map.put(S, map.get(S) + 1);
			} else {
				map.put(S, 1);
			}
			max = Math.max(max, map.get(S));
		}
		List<String> list = new ArrayList<String>();
		for (Map.Entry<String, Integer> key : map.entrySet()) {
			if (key.getValue() == max) {
				list.add(key.getKey());
			}
		}
		Collections.sort(list);
		for (String S : list) {
			System.out.println(S);
		}
	}
}

Measured memory_bytes: 75588
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    LL n;
    cin >> n;
    vector<LL> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    LL cnt = 0;
    LL min = 2143234423141231422;
    rep(i, n) {
        if (a[i] < 0) {
            cnt++;
        }
        min = min > abs(a[i]) ? abs(a[i]) : min;
    }

    LL res = 0;
    rep(i, n) {
        res += abs(a[i]);
    }
    cout << (cnt % 2 == 0 ? res : res - 2 * min) << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll x,y;
int main(){
	cin>>x>>y;
	int ans=0;
	while(x<=y){
		x*=2;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import copy
n, m, x = map(int, input().split())
c, a = [], []

for i in range(n):
    temp = list(map(int, input().split()))
    c.append(temp[0])
    a.append(temp[1:])

# print(c, a)
ans = 10**10

def isClear(arr):
    return all(val >= x for val in arr)

def solve(idx, price, arr):
    global ans
    if idx == n:
        if isClear(arr):
            # print('clear:', arr)
            ans = min(ans, price)
        return

    # Read
    temp = copy.deepcopy(arr)
    for i in range(m):
        temp[i] += a[idx][i]

    solve(idx + 1, price + c[idx], temp)

    # Not read
    solve(idx + 1, price, arr)

score = [0]*m
solve(0, 0, score)

if ans == 10**10:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 9356
n=int(input())
INF=float("inf")
g=[[INF]*n for _ in range(n)]
ans=0
for i in range(n):
	for j,c in enumerate(map(int,input().split())):
		if i!=j:
			g[i][j]=c
for i in range(n):
	for j in range(i):
		m=min(a+b for a,b in zip(g[i],g[j]))
		if g[i][j]>m:
			print(-1)
			exit()
		if g[i][j]<m:
			ans+=g[i][j]
print(ans)

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main(){
	llong N, K;
	string S;

	cin >> N >> K;
	cin >> S;

	S[K-1] = S[K-1]-'A'+'a';

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
package main
import . "fmt"
import "sort"
import "strings"
func main() {
  var s,t string
  var as,at []string
  Scan(&s)
  Scan(&t)
  as = strings.Split(s,"")
  at = strings.Split(t,"")
  sort.Strings(as)
  sort.Sort(sort.Reverse(sort.StringSlice(at)))
  s = strings.Join(as,"")
  t = strings.Join(at,"")
  if s < t {
    Println("Yes")
  } else {
    Println("No")
  }
}

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

ll minll(ll x, ll y){
    if(x>y) return y;
    else return x;
}

int main(){
    string s;
    ll k;
    cin >> s;
    cin >> k;
    bool ok = true;
    for(ll i=0;i<minll(ll(s.size()),k);i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int b[100010];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	b[1]=0;
	b[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;++i){
		b[i]=min(b[i-1]+abs(a[i-1]-a[i]),b[i-2]+abs(a[i-2]-a[i]));
	}
	cout<<b[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_QUIZ_MAX		100										// 最大問題数
#define D_POINT_MAX		100										// 最大点数

// 内部変数
static int si1Point[D_QUIZ_MAX * D_POINT_MAX];					// 点数リスト
static int siMax;												// 最大点

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j;
	char lc1Buf[1024], lc1Out[1024];

	// データ初期化
	memset(si1Point, D_OFF, sizeof(si1Point));					// 点数リスト
	siMax = 0;													// 最大点

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 初期点数
	si1Point[0] = D_ON;

	// 問題数取得
	int liQCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liQCnt);

	// 点数取得
	for (i = 0; i < liQCnt; i++) {
		int liPoint;
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
		fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
		sscanf(lc1Buf, "%d", &liPoint);

		// 点数加算
		for (j = siMax; j >= 0; j--) {
			if (si1Point[j] == D_ON) {		// あり
				int liSum = liPoint + j;
				si1Point[liSum] = D_ON;			// セット

				// 最大点更新
				if (siMax < liSum) {
					siMax = liSum;
				}
			}
		}
	}

	// 最大表示点取得
	int liMax = 0;
	for (i = siMax; i > 0; i--) {
		if (si1Point[i] == D_ON) {		// あり
			if (i % 10 != 0) {				// 表示可
				liMax = i;
				break;
			}
		}
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liMax);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

const int Mod = 1000000007;

void prod_matrix(int N, long long a[][51], long long b[][51], long long c[][51])
{
	int i, j, k;
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			for (k = 1, c[i][j] = 0; k <= N; k++) c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % Mod;
		}
	}
}

void pow_matrix(int N, long long a[][51], long long K, long long b[][51])
{
	int i, j;
	long long c[51][51], d[51][51];
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			b[i][j] = (i == j)? 1: 0;
			c[i][j] = a[i][j];
		}
	}
	for (; K > 0; K >>= 1) {
		if (K % 2 == 1) {
			prod_matrix(N, b, c, d);
			for (i = 1; i <= N; i++) for (j = 1; j <= N; j++) b[i][j] = d[i][j];
		}
		prod_matrix(N, c, c, d);
		for (i = 1; i <= N; i++) for (j = 1; j <= N; j++) c[i][j] = d[i][j];
	}
}

int main()
{
	int i, j, N;
	long long K, a[51][51];
	scanf("%d %lld", &N, &K);
	for (i = 1; i <= N; i++) for (j = 1; j <= N; j++) scanf("%lld", &(a[i][j]));
	
	long long b[51][51], ans = 0;
	pow_matrix(N, a, K, b);
	for (i = 1; i <= N; i++) for (j = 1; j <= N; j++) ans += b[i][j];
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main()
{
    string sh;
    int tmp=0;
    getline(cin,sh);
    vector <int> a,b;
    a.push_back(0);
    for (char i : sh) {
        if(i =='_') a.push_back(tmp);
        else if(i =='/') a.push_back(++tmp);
        else a.push_back(--tmp);
    }
    auto it=a.begin();
    while(it!=a.end())
    {   int area=0,judge=1;
        auto result=find(it+1,a.end(),*it);
          if(result!=a.end()) {
            for (auto i = it+1; i != result; i++) {
                judge *= (*i<=*it);
                area += (*it-*i);
            }
            if(judge>0&&area>0) {b.push_back(area);it=result;}
            else it++;
        }
        else it++;
    }
    if(b.begin()!=b.end()) {
        cout << accumulate(b.begin(), b.end(), 0) << endl;
        cout <<b.end()-b.begin();
        for (auto i = b.begin(); i != b.end(); i++) {
            cout << " "<< *i;
        }
        cout << endl;
    }
    else cout<<0<<endl<<0<<endl;
    return 0;
}



Measured memory_bytes: 3324
import sys
sys.setrecursionlimit(1000000)
 
N = int(input())
X = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    X[u-1].append((v-1, w%2))
    X[v-1].append((u-1, w%2))
 

D = [-1] * N
def calc(i, c):
    D[i] = c
    for j, w in X[i]:
        if D[j] < 0:
            calc(j, D[i]^w)
 
calc(0, 0)
for d in D:
    print(d)

Measured memory_bytes: 76464
import numpy as np


N, H = map(int, input().split())

A = [None] * N
B = [None] * N

for n in range(N):
    A[n], B[n] = map(int, input().split())

A = sorted(A, reverse=True)
B = sorted(B, reverse=True)

S = np.cumsum(B)
try:
    S = S[:int(np.where(S >= H)[0])+1]
except:
    pass

result = H

for i, s in enumerate(S):
    result = min(result, i + 1 + int(np.ceil(max(0, H - S[i]) / A[0])))

print(result)


Measured memory_bytes: 22292
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define debug(a) cout << a << endl
#define pr(a) printf("%d ",a)
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define ull unsigned long long
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf=0x3f3f3f3f;
const int MAXN = 1e5 + 10;
ll n,W;
ll w[105],v[105];
ll dp[MAXN];
int ans;
int main()
{
	sll(n,W);
	ms(dp,inf);
	for(int i=1;i<=n;++i)
	{
		sll(w[i],v[i]);
	}
	dp[0]=0;
	for(int i=1;i<=n;++i)
	for(int j=1e5;j>=v[i];j--)
	{
		dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
		if(dp[j]<=W)ans=max(ans,j);
	}
	printf("%d\n",ans);
 } 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;

int main() {
    int n; cin >> n;
    int v[n],c,ans=0;
    for(int i = 0;i < n;i++){
        cin >> v[i];
    }
    for(int i = 0;i < n;i++){
        cin >> c;
        if(v[i] - c > 0){
            ans +=v[i] - c;
        }
    }
    cout << ans;
}


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

int main() {
  ll N, K;
  cin >> N >> K;
  if (N >= K) {
    N -= K * (N / K);
  }
  N = min(N, abs(N - K));
  N = min(N, abs(N - K));
  cout << N << endl;
}


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

int N,M,K,a,d;
int x[MAX],y[MAX],z[MAX];

int main(){
  scanf("%d %d %d %d",&N,&a,&d,&M);
  for(int i=0;i<M;i++)scanf("%d %d %d",&x[i],&y[i],&z[i]);
  scanf("%d",&K);
  stack<int> st;
  for(int i=M-1;i>=0;i--){
    if(K<y[i]||z[i]<K)continue;
    if(x[i]==0)K=z[i]+y[i]-K; 
    else st.push(x[i]);
  }
  int ans=a+d*(K-1);
  while(!st.empty()){
    if(st.top()==1)ans++;
    else ans/=2;
    st.pop();
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 5476
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
signed main(void){
    int n; cin>>n;
    vector <pair<int,int>> data(n);
    rep(i,n){
        int a; cin>>a;
        data[i] = { a, i+1};
    }
    sort(data.begin(),data.end());
    rep(i,n){
        cout<<data[i].S<<' ';
    }
}


Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main()
{
	bool Card[52] = { false };

	int		n;
	cin >> n;
	cin.ignore();

	int		c;
	char	s;

	for (int i = 0; i < n; i++)
	{
		cin >> s >> c;
		cin.ignore();

		switch (s)
		{
		case 'S':
			Card[c - 1] = true;
			break;
		case 'H':
			Card[c + 13 - 1] = true;
			break;
		case 'C':
			Card[c + 13 * 2 - 1] = true;
			break;
		case 'D':
			Card[c + 13 * 3 - 1] = true;
			break;
		default:
			break;
		}
	}

	for (int i = 0; i < 52; i++)
	{
		if (Card[i] == false)
		{
			int		suit = i / 13;
			int		numb = i % 13 + 1;

			switch (suit)
			{
			case 0:
				cout << "S " << numb << "\n";
				break;
			case 1:
				cout << "H " << numb << "\n";
				break;
			case 2:
				cout << "C " << numb << "\n";
				break;
			case 3:
				cout << "D " << numb << "\n";
				break;
			default:
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    string t;
    cin >> t;
    if (t[2] == t[3] && t[4] == t[5])Yes;
    else No;
    return 0;
}


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

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

int main() {
	int w, h, c; cin >> w >> h >> c;
	int n(gcd(w, h));
	cout << w*h/n/n*c << endl;
	return 0;
}

Measured memory_bytes: 3100
n = int(input())
s = [input().split() for i in range(n)]
sum = 0

for locate in s:
    t = int(locate[0])
    x = int(locate[1])
    y = int(locate[2])
    if x+y <= t:
        if (x+y)%2==0 and t%2==0:
            sum += 1
        elif (x+y)%2!=0 and t%2!=0:
            sum += 1

if sum == n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 32144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vi a(n);
    for(int i =0 ; i < n; i++) cin >> a[i];
    sort(all(a));
    cout << a[n-1] - a[0];
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,n,d) for(ll i=0;i<n;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
v<ll> fact;
//factorial
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <=n; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= M;
    }
}
// modular exponentiation 
ll binpow(ll val, ll deg)
{
    if (!deg)
        return 1 % M;
    if (deg & 1)
        return binpow(val, deg - 1) * val % M;
    ll res = binpow(val, deg >> 1);
    return (res * res) % M;
}
//combination
ll C(ll n, ll i)
{
    if(n<i) return 0;      
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= M;
    // using fermat little theorum
    div = binpow(div, M - 2); // modular inverse  
    return (res * div) % M; 
}

int main() {
	//your code goes here
	IOS;
	ll n,m;       
	ll j,y,z,t,x,i,q;  
	ll h,w,k;
	
	cin>>h>>w>>k;
	char s[h][w];
	
	rep(i,h){
	      rep(j,w){
	            cin>>s[i][j];
	            
	      }
	}
	//cout<<sum;
	
	
	      ll ans=0;
	      for(i=0;i<pow(2,h);i++){
	            for(j=0;j<pow(2,w);j++){
	                  ll c=0;
	               rep(a,h){
	                     rep(b,w){
	                           if(i>>a&1){
	                                 if(j>>b&1){
	                                       if(s[a][b]=='#')
	                                       c++;
	                                 }
	                           }
	                     }
	               }   
	               if(c==k)
	               ans++;
	                  
	                  
	            }
	      }
	      
	      cout<<ans;
	      
	
	
	return 0;
}

Measured memory_bytes: 4128
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;

int main() {
	ll ans = 0, n, a[200000],memo=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] = a[i] - i - 1;
	}
	sort(a, a + n);
	if (n % 2 == 1) {
		int cen = a[n / 2];
		for (int i = 0; i < n; i++) {
			ans += abs(a[i] - cen);
		}
	}
	else {
		for (int j = 0; j < 2; j++) {
			int cen =a[ n / 2 - 1 + j];
			for (int i = 0; i < n; i++) {
				if(j==0)memo += abs(a[i] - cen);
				else ans += abs(a[i] - cen);
			}
		}
		ans = min(memo, ans);
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        
        SegmentTreeRSQ st = new SegmentTreeRSQ(n);
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < q; i++){
            if(sc.next().equals("0")){
                st.add(Integer.parseInt(sc.next()) -1, Integer.parseInt(sc.next()));
            }else{
                sb.append(st.getSum(Integer.parseInt(sc.next()) -1, Integer.parseInt(sc.next()), 0, 0, st.n));
                sb.append(System.lineSeparator());
            }
        }
        System.out.print(sb);
    }
    
    static class SegmentTreeRSQ {
        int n;
        int[] node;

        public SegmentTreeRSQ(int size) {
            n = 1;
            while(n < size) n <<= 1;
            node = new int[2*n-1];
            Arrays.fill(node, 0);
        }
        void add(int i, int x){
            i += n-1;
            node[i] += x;
            while(i > 0){
                i = (i-1)/2;
                node[i] = node[i*2+1] + node[i*2+2];
            }
        }
        int getSum(int a, int b, int k, int l, int r){
            if(r <= a || b <= l) return 0;
            if(a <= l && r <= b){
                return node[k];
            }else{
                int vl = getSum(a, b, k*2+1, l, (l+r)/2);
                int vr = getSum(a, b, k*2+2, (l+r)/2, r);
                return vl + vr;
            }
        }
    }
}


Measured memory_bytes: 74400
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long

const int N = 1000300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
ll n,k;
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int a,b;
cin>>a>>b;
cout<<max(a+b,max(a*b,a-b));

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   int n=kbd.nextInt();
   int[] X= new int[n];
   for(int i=0;i<n;i++){
     X[i]=kbd.nextInt();
   }
   long a=0;
   long b=1000000;
   for(int i=1;i<=100;i++){
     for(int j=0;j<n;j++){
     int m=Math.abs(X[j]-i);
     a=m*m+a;
   }
   b=Math.min(a,b);
   a=0;
   }

System.out.println(b);
 }
}


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

using namespace std;
typedef long long ll;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << max(a * b, c * d) << "\n";
}


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

using namespace std;

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

  int N; cin>>N;
  vector<int> P(N), Q(N);
  for (auto& p : P) cin>>p;
  for (auto& p : P) p--;
  for (auto& p : Q) cin>>p;
  for (auto& p : Q) p--;
  vector<int> fact(N);
  fact.back() = 1;
  for (int i = N-2; i >= 0; i--) {
    fact[i] = fact[i+1] * (N-i-1);
  }
  int a=0, b=0;
  int pa = N, pb = N;
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (P[j] > pa)
        P[j]--;
      if (Q[j] > pb)
        Q[j]--;
    }
    a += (P[i]*fact[i]);
    b += (Q[i]*fact[i]);
    pa = P[i];
    pb = Q[i];
  }
  cout << abs(a-b) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int base = 1;
		int res = Integer.MAX_VALUE;
		
		while (base < n) {
			int remain = n - base;
			res = Math.min(res, findDigit(remain) + 1);
			base *= 10;
		}
		System.out.println(res);
	}
	
	private static int findDigit(int num) {
		int res = 0;
		while (num > 0) {
			res += (num % 10);
			num /= 10;
		}
		return res;
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <math.h>
#include <cctype>
using namespace std;
int a[1000000];
int answer[1000000];
int main(){
    int n;
    int k;
    int x;
    cin >> k >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++){
        if(i==1){
            if(k-a[n]+a[i] >= a[i+1]-a[i]){
                answer[i] = a[n]-a[i];
            }
            else{
                answer[i] = k - (a[i+1] - a[i]);
            }
        }
        else if(i==n){
            if(k-a[n]+a[1] >= a[i]-a[i-1]){
                answer[i] = a[n]-a[1];
            }
            else{
                answer[i] = k - (a[i] - a[i-1]);
            }
        }
        else{
            if(a[i]-a[i-1] >= a[i+1]-a[i]){
                answer[i] = k - (a[i] - a[i-1]);
            }
            else{
                answer[i] = k - (a[i+1] - a[i]);
            }
        }
    }
    x = k+1;
    for(int i=1;i<=n;i++){
        if(answer[i] < x){
            x = answer[i];
        }
    }
    cout << x << endl;

    return 0;

}

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

#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
typedef long double ld;
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
const int N=2e5+5;
int mod=100000000;
/*int k1, k2;
ll dp[10][10][100][100];
ll solve(int n1, int n2, int last1, int last2)
{
    if(n1==0&&n2==0)
        return 1;
    if(dp[last1][last2][n1][n2]!=-1)
        return dp[last1][last2][n1][n2];

    ll &ans=dp[last1][last2][n1][n2];
    ans=0;
    if(last1<k1&&n1)
    {
        ans=(ans+solve(n1-1,n2,last1+1,0))%mod;

    }
    if(last2<k2&&n2)
    {
         ans=(ans+solve(n1,n2-1,0,last2+1))%mod;
    }
    // cout<<n1<<" "<<n2<<" "<<last1<<" "<<last2<<" "<<ans<<endl;
    return ans;

}*/
    ll n,arr[N], co[N], ans=0;

int main()
{
    FIO
    cin>>n;
    for(int i=0;i<n+1;i++)
        cin>>arr[i];
    for(int i=0;i<n;i++)
    {
        cin>>co[i];

    }
    for(int i=0;i<n;i++)
    {
        ans+=min(co[i],arr[i]);
   //    cout<<co[i]<<" "<<arr[i]<<" ";
        if(co[i]>arr[i])
        {

            co[i]-=arr[i];
            ans+=min(co[i],arr[i+1]);
            if(co[i]>=arr[i+1])
                arr[i+1]=0;
            else
                arr[i+1]-=co[i];
        }
   // cout<<ans<<" \n";
    }
    cout<<ans;
return 0;

}


Measured memory_bytes: 1792
nums = int(input())
ary = list(range(nums))
check_number = [0 for i in range(nums+2)]
for i in range(nums):
    ary[i] = int(input())

ary.sort()
check = 0
count = 0
result = 0
x = 0
for i in ary :
    if check == i:
        check_number[x] += 1
    else:
        check = i
        x += 1
        check_number[x] = 1

for i in check_number:
    if i % 2 == 1:
        result += 1
print (result)

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

int main() {
  int a , b , c , d;
  cin >> a >> b >> c >> d;
  
  if((a+b) > (c+d)){
    cout << "Left" << endl;
  }
  else if((a+b) < (c+d)){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3484
w,h,n= map(int,input().split())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
l=0
d=0
for j in range(n):
    if s[j][2]==1 and s[j][0]>l:
        l=s[j][0]
    elif s[j][2]==2 and s[j][0]<w:
        w=s[j][0]
    elif s[j][2]==3 and s[j][1]>d:
        d=s[j][1]
    elif s[j][2]==4 and s[j][1]<h:
        h=s[j][1]

if h-d>0 and w-l>0:
    print((h-d)*(w-l))
else:
    print(0)


Measured memory_bytes: 3064
# AOJ 1601: Short Phrase
# Python3 2018.7.13 bal4u

a = [5,7,5,7,7]

while True:
	n = int(input())
	if n == 0: break
	ans = 0
	w = [len(input()) for i in range(n)]
	for i in range(n):
		k = s = 0
		for j in range(i, n):
			s += w[j]
			if s == a[k]:
				s, k = 0, k+1
				if k == 5: ans = i+1; break
			elif s > a[k]: break
		if ans: break
	print(ans)



Measured memory_bytes: 5612
S = input()
N = len(S)
max_n = 0
for n in range(N):
    for m in range(n, N):
        s = S[n:m+1]
        if all("ATCG".count(ss) == 1 for ss in s):
            max_n = max(max_n, len(s))
print(max_n)


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

int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n)cin >> a[i];
	bool r = true;
	rep(i,n){
		if(a[i] % 2 == 0){
			if(a[i] % 3 != 0 && a[i] % 5 != 0 )r = false;
		}
	}
	if(r)cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
}

Measured memory_bytes: 256