akhauriyash/Code-Regression huggingface dataset:
#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()
using i64 = int_fast64_t;
using P = pair<int,int>;

const int MAX = 510000;
const i64 MOD = 1000000007;

i64 fac[MAX], finv[MAX], inv[MAX];
void comb_init() {
    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;
    }
}

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

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

    i64 cost = 0;
    for(int d = 1; d < N; d++) cost = (cost + d*(N-d) % MOD * M % MOD * M)  % MOD;
    for(int d = 1; d < M; d++) cost = (cost + d*(M-d) % MOD * N % MOD * N) % MOD;

    comb_init();
    cout << (cost * comb(N*M-2, K-2)) % MOD << endl;
}


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

long s,ans=0,mod=1000000007;

long modpow(long modpow_x,long modpow_y) {
  long modpow_return=1;
  for(long i=1;i<=modpow_y;i*=2) {
    if(modpow_y/i%2==1) modpow_return=modpow_return*modpow_x%mod;
    modpow_x=modpow_x*modpow_x%mod;
  }
  return modpow_return;
}

int main() {
  cin >> s;
  vector<long> aaa(3000);
  aaa[0]=1;
  aaa[1]=1;
  for(long i=2;i<3000;i++) aaa[i]=(aaa[i-1]*i)%mod;
  for(long i=1;i*3<=s;i++) {
    ans=(ans+aaa[s-i*3+i-1]*modpow(aaa[i-1],mod-2)%mod*modpow(aaa[s-i*3],mod-2)%mod)%mod;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().exec();
	}

	public void exec() throws IOException {
		InputUtil in = new InputUtil();
		PrintWriter out = new PrintWriter(System.out);
		int H = in.nextInt();
		int[] heapData = in.nextInt(new int[H],H);
		BinaryHeap bh = new BinaryHeap(heapData);
		for(int i=0; i<H; i++) {
			out.println(bh.show(i));
		}
		out.flush();
	}
	
	
}

class BinaryHeap {
	public int[] data = null;
	
	public BinaryHeap(int maxNodes) {
		data = new int[maxNodes];
	}
	
	public BinaryHeap(int[] data) {
		this.data = data;
	}
	
	public int get(int i) {
		return data[i];
	}
	
	public void set(int i, int value) {
		data[i] = value;
	}

	public int getParent(int i){
		if(i<=0 || data.length<=i) return -1;
		return (i+1)/2 - 1;
	}

	public int getLeft(int i){
		if(i<0 || data.length/2<=i) return -1;
		return (i+1)*2 - 1;
	}

	public int getRight(int i){
		if(i<0 || (data.length-1)/2<=i) return -1;
		return (i+1)*2;
	}
	
	public String show(int id){
		StringBuilder sb = new StringBuilder("node "+(id+1)+": key = "+data[id]+", ");
		int parentId = getParent(id);
		if(parentId != -1)
			sb.append("parent key = "+data[parentId]+", ");
		int leftId = getLeft(id);
		if(leftId != -1)
			sb.append("left key = "+data[leftId]+", ");
		int rightId = getRight(id);
		if(rightId != -1)
			sb.append("right key = "+data[rightId]+", ");
		return sb.toString();
	}
}


class InputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int nextInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    
    public int[] nextInt(int[] a, int num) throws NumberFormatException, IOException{
        int i=0;
        while(i<num) {
            for(String s: br.readLine().split(" ")){
            	if(i<num) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    }
}

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

int main() {
  int A, B, C, K;
  int score = 0;
  cin >> A >> B >> C >> K;
  
  for(int i = 0; i < K; i++){
    if(A != 0){
      A--;
      score++;
    }
    else if(B != 0){
      B--;
    }
    else if(C != 0){
      C--;
      score--;
    }
  }
  cout << score << endl;
}

Measured memory_bytes: 3552
N = int(input())
H = list(map(int, input().split()))
ans = []
a = 0

if N == 1:
    print('0')
    exit()

for i in range(N-1):
    if H[i] >= H[i+1]:
        a += 1
    else:
        a = 0
    ans.append(a)

print(max(ans))


Measured memory_bytes: 14224
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if(Math.abs(b-a) <= d && Math.abs(c-b) <=d){
            System.out.println("Yes");
            return;
        }
        if(Math.abs(a-c) <= d){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 25044
#include <stdio.h>

int main(){

	int nen = 0, c=0, a=0, n=0,ans=0;

	scanf("%d", &nen);

	for (int i = 0; i < nen; i++){
		scanf("%d%d%d", &c, &a, &n);
		
		while(1){
			if (a == 0 || c == 0 || n == 0){ break; }
			c--; a--; n--;
			ans++;

		}
		while (1){
			if (a == 0 || 2>c){ break; }
			c -= 2; a--;
			ans++;
		}
		while (2 < c){
			c -= 3;
			ans++;

		}
		printf("%d\n", ans);

		ans = 0;

	}

	return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int count = 0;
    for(int i = 0; i < 3; i++) {
      if(s.charAt(i) == 'o')
        count++;
    }
    System.out.println(700 + 100 * count);
  }

}


Measured memory_bytes: 22484
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=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 main(){
  int x;
  cin>>x;

  int ans=0;
  ans+=(x/500)*1000;
  x%=500;
  ans+=(x/5)*5;

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main()
{

	int n,count;
	int a,b, c,d;
	while(cin >> n){

		//a>=b>=c>=dと仮定
		count = 0;
		for( a = 0; a < 10; a++ ) {
			if ( a > n ) 
				continue;
			for( b = 0; b < a+1; b++ ) {
				if( a + b > n )
					continue;
				for( c = 0; c < b+1; c++ ) {
					if( a + b + c > n ) 
						continue;
					d = n - a - b- c;
					if( d > c )
						continue;
				if( a == d )//全部同じ
					count += 1;
				else if( a == c || b == d)//１つ異なる
					count += 4;
				else if( a == b && c == d )//2つずつ同じ
					count += 6;
				else if( a == b || b == c || c == d )//2つ同じ
					count += 12;
				else
					count += 24;
				}
			}
		}
		cout << count << endl;

	}

	return 0;
}

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

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		int p = (int) ceil(n / 1000.0);
		printf("%d\n", p * 1000 - n);
	}
	return (0);
}

Measured memory_bytes: 1712
#include <iostream>

using namespace std;

int main() {

	int n, num;
	bool checker[4][13 + 1];//????????????????????¨??°??????????????????
	char gara;

	cin >> n;

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 14; j++) {
			checker[i][j] = false;
		}
	}


	//??\???????¢????
	for (int i = 0; i < n; i++) {
		cin >> gara >> num;
		if (gara == 'S') {
			checker[0][num] = true;
		}
		else if (gara == 'H') {
			checker[1][num] = true;
		}
		else if (gara == 'C') {
			checker[2][num] = true;
		}
		else if (gara == 'D') {
			checker[3][num] = true;
		}
		//cout << "input " << gara << " " << num << endl;
	}

	/*
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 14; j++) {
			cout << "i= " << i << " j=" << j << " input=" << checker[i][j] << endl;
		}
	}
	*/

	//?¶????????????????????????????
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < 14; j++) {
			if (checker[i][j] == false) {
				char chara;
				if (i == 0) {
					chara = 'S';
				}
				else if (i == 1) {
					chara = 'H';
				}
				else if (i == 2) {
					chara = 'C';
				}
				else if (i == 3) {
					chara = 'D';
				}
				cout << chara << " " << j << endl;
			}
		}
	}

	return 0;

}

Measured memory_bytes: 3088
// 043.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <map>
#include <climits>
#include <algorithm>

using namespace  std;

int join(int a[], int size)
{
	
	for (int i = 0; i < size-2; ++i)
	{
		const auto diff = abs(a[i] - a[i + 2]);
		if (a[i] == a[i + 2]) a[i] = 0;		
		else if (diff == 1) { a[i] = 1; }
		else
		{
			if (a[i + 1] == 2) a[i] = 0;
			else a[i] = 2;
		}
	}

	if (size == 2) return abs(a[0]- a[1]);
	return join(a, size - 2);
}

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

	bool is_equal =
		a == b && a != c ||
		a == c && a != b ||
		b == c && b != a;
	cout << (is_equal ? "Yes" : "No");*/

	
	/*int n;
	cin >> n;
	vector<int> a(n);
	int ai;
	for (int i = 0; i < n; ++i)
	{
		cin >> ai;
		a[i] = ai;
	}

	bool is_approved = true;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] % 2 == 0)
		{
			if (a[i] % 3 != 0 && a[i] % 5 != 0)
			{
				is_approved = false;
				break;
			}
		}
	}

	cout << (is_approved ? "APPROVED" : "DENIED");*/

	int n;
	cin >> n;

	map<string, int> votes;

	int max = -1;

	string s;
	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		votes[s]++;
		if (votes[s] > max) max = votes[s];
	}


	for (const auto& item :votes)
	{
		if (item.second == max)
		{
			cout << item.first << "\n";
		}
	}
	
	
	
}



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

int main(){
  int H1,M1,H2,M2,K,A;
  cin>>H1>>M1>>H2>>M2>>K;
  A=H2*60+M2-H1*60-M1-K;
  cout<<A<<endl;
  return 0;
}

  

Measured memory_bytes: 3488
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin>>N;
	int h[N+1],i,dp[N+1];
	for(i=1;i<=N;i++)
	{
		cin>>h[i];
		if(i==1)
			dp[i]=0;
		else if(i==2)
			dp[i]=abs(h[i]-h[i-1]);
		else
			dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[N]<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) {
        cin >> A.at(i);
    }
    bool flag = 1;
    for (int i : A) {
        if(i%2==0 && i%3!=0 && i%5!=0){
            flag = 0;
            break;
        }
    }
    if(flag)
        cout << "APPROVED";
    else
        cout <<"DENIED";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
ll a[maxn];
int aim, ans = 0;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    for(int i = 1; i < maxn; i++) a[i] = a[i-1] + i;
    cin>>aim;
    while(a[ans] < aim) ans++;
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    string s1, s2;
    cin >> s1 >> s2;
    int a1 = s1.size();
    int a2 = s2.size();
    if(a1 > a2){
        cout << "GREATER" << endl;
    }else if(a1 < a2){
        cout << "LESS" << endl;
    }else{
        if(s1 == s2){
            cout << "EQUAL" << endl;
        }else if(s1 > s2){
            cout << "GREATER" << endl;
        }else if (s1 < s2){
            cout << "LESS" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
int N;
void print(const std::vector<int> &v)
{
    std::for_each(v.begin(), v.end(), [](int x) {
        std::cout << x << " ";
    });
    std::cout << std::endl;
}
int fact(int n)
{
    int i, facto = 1;

    if (n == 0 || n == 1)
    {
        facto = 1;
    }
    else
    {
        for (i = 1; i <= n; i++)
        {
            facto = facto * i;
        }
    }

    return facto;
}
int main()
{
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);

    rep(i, 0, N)
    {
        cin >> P[i];
    }
    rep(i, 0, N)
    {
        cin >> Q[i];
    }
    int p1 = fact(N);
    int q1 = fact(N);

    do
    {
        p1--;
    } while (std::next_permutation(P.begin(), P.end()));
    do
    {
        q1--;
    } while (std::next_permutation(Q.begin(), Q.end()));

    cout << abs(p1 - q1) << endl;
    return 0;
}


Measured memory_bytes: 3636
//#include <iostream>
//#include <cmath>
//
//using namespace std;
//
//int main()
//{
//    int t;
//    cin >> t;
//    for (int i = 1; i <= t; i++) {
//
//    }
//    return 0;
//}
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int t;
    cin >> t;
    t %= 10;
    if ( t == 3) cout << "bon" << endl;
    else if (t == 0 || t == 1 || t == 6 || t == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

#ifdef LOCAL
  void debug() {cerr << "\n";}
  template<class First> void debug(const First& first) {cerr<<first<<"\n";}
  template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
  #define debug(...) 42
#endif


vector<vector<pair<int, int>>> edge;
vi color;
int K = 0;
void dfs(int cur_node, int parent_color) {
  if (parent_color == -1) {
    // まず、まだどこにも塗ってないときを考える
    // すべての辺に違う色を塗るだけでいい。 -> tmp_k = 辺の数
    K = edge[cur_node].size();
    int i = 0;
    for (const auto& p : edge[cur_node]) {
      int to = p.first;
      int idx = p.second;

      color[idx] = i;
      dfs(to, i);
      ++i;
    }
  } else {
    // 次に塗るのは隣接した頂点。
    // まず、1本は色が確定しているので、それ以外の色を使う。
    // もし、tmp_kより多くの色が必要なら更新してやる。
    K = max(K, (int)edge[cur_node].size());
    int i = parent_color + 1;
    i %= K;
    for (const auto& p : edge[cur_node]) {
      int to = p.first;
      int idx = p.second;

      if (color[idx] == -1) {
        color[idx] = i;
        dfs(to, i);
        ++i;
        i %= K;
      }
    }
  }
}
int main() {
  int N; cin >> N;

  edge.resize(N, vector<pii>());
  color.resize(N-1, -1);
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].emplace_back(b, i);
    edge[b].emplace_back(a, i);
  }
  dfs(0, -1);
  cout << K << endl;
  rep(i, N-1) {
    cout << color[i]+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define PB push_back
const int N=2e3+10;
template <int n> struct bit{
    int val[n];
    bit(void){memset(val,0,sizeof(val));}
    void add(int a,int pos){
        while(pos<n){
            val[pos]+=a;
            pos+=pos&-pos;
        }
        return ;
    }
    int ask(int pos){
        int ans=0;
        while(pos>0){
            ans+=val[pos];
            pos-=pos&-pos;
        }
        return ans;
    }
};
int main(){
    int n,temp,tot,dp[N],l[N],r[N];
    bit<N<<1> b[N];
    char c[10];
    scanf("%d",&n);
    memset(dp,0,sizeof(dp));
    tot=n<<1;
    for(int i=1;i<=tot;i++){
        scanf("%s",c);
        scanf("%d",&temp);
        if(c[0]=='B')l[temp]=i;
        else r[temp]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=i-1;j>0;j--){
            dp[j]=min(dp[j]+l[i-j]-1-b[j].ask(l[i-j]),dp[j-1]+r[j]-1-b[j-1].ask(r[j]));
            b[j].add(1,l[i-j]);
        }
        dp[0]+=l[i]-1-b[0].ask(l[i]);
        b[0].add(1,l[i]);
        for(int j=i;j<=n;j++){
            dp[j]+=r[i]-1-b[j].ask(r[i]);
            b[j].add(1,r[i]);
        }
    }
    for(int i=n+1;i<=tot;i++){
        for(int j=n;j>=i-n;j--){
            dp[j]=min(dp[j]+l[i-j]-1-b[j].ask(l[i-j]),dp[j-1]+r[j]-1-b[j-1].ask(r[j]));
            b[j].add(1,l[i-j]);
        }
    }
    printf("%d\n",dp[n]);
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
int n , mini , x , ans;
int main(){
	cin >> n;
	int mini = 1e9;
	for(int i = 1 ; i <= n ; i++){
		cin >> x;
		mini = min(mini , x);
		if(x == mini)ans++;
	}
	cout << ans;
}

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

int main()
{
  	int n,m;
  	cin>>n>>m;
  	vector<string> gt,temp;
  	string str;
	for(int i=0 ; i<n ; ++i)
    {
    	cin>>str;
      	gt.push_back(str);
    }
  	for(int i=0 ; i<m ; ++i)
    {
    	cin>>str;
    	temp.push_back(str);
    }
  	for(int i=0 ; i<n ; ++i)
    {
    	if((n-i)<m)
        break;
      	for(int j=0 ; j<n ; ++j)
        {
        	if((n-j)<m)
            break;
			if(gt[i][j]==temp[0][0])
            {
              	bool different=false;
				for(int o=0 ; o<m ; ++o)
                {
                	for(int p=0; p<m ; ++p)
                    {
                    	if(gt[i+o][j+p]!=temp[o][p])
                        {
                        	different=true;
                          	break;
                        }
                    }
                  	if(different)
                    break;
                }
                if(!different)
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
	cout<<"No"<<endl;
	return 0;
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  string num;
  cin >> num;

  int sum = 0;
  REP(i, num.size()) {
    sum += num[i] - '0';
  }

  if (sum % 9 == 0) {
    ANS("Yes");
  } else {
    ANS("No");
  }
  return 0;
}


Measured memory_bytes: 3760
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int r = 1;
  while(n--) {
    r = min(2*r, r+k);
  }
  printf("%d\n", r);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int prime[303]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,
149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,
317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,
509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,
719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,
937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,
1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,
1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,
1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,
1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,
1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999},n,k,cnt[303],xx[10003];
long long C(long long x,long long y){
	y=min(y,x-y);
	long long ans=1;
	for(int i=0;i<y;i++)xx[i]=x-i;
	for(int i=1;i<=y;i++){
		long long tmp=i;
		for(long long xxx=0;xxx<303&&tmp!=1;xxx++)
			while(tmp%prime[xxx]==0)
				tmp/=prime[xxx],
				cnt[xxx]++;
	}
	for(long long i=0;i<y;i++)
		for(long long xxx=0;xxx<303&&xx[i]!=1;xxx++)
			while(cnt[xxx]&&xx[i]%prime[xxx]==0)
				cnt[xxx]--,
				xx[i]/=prime[xxx];
	for(long long i=0;i<y;i++)ans=(ans*xx[i])%1000000007;
	return ans;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		if(i+1<=n-k+2)
			printf("%lld\n",(C(k-1,i-1)*C(n-k+1,i))%1000000007);
		else
			printf("0\n");
}

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

inline int64_t ceiling_div(int64_t a, int64_t b){
  int64_t ans= ((a>=0 && b > 0) || (a<=0 && b < 0)) ? (abs(a)+abs(b)-1)/abs(b)
                                                    : -abs(a)/abs(b);
  return ans;
}

int main(){
  const int Amax= 1'000'000'000;
  int64_t N,Nop;
  cin >> N >> Nop;

  vector<int64_t> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  int64_t inc= Amax;
  int64_t exc= 0;
  while(abs(inc- exc) > 1){
    int64_t mid= (inc+ exc)/ 2;

    auto is_inc= [&](int64_t mid){
      int64_t Nop_mid= 0;
      for(int i=0; i<N; i++){
        Nop_mid+= ceiling_div(data.at(i), mid)- 1;
      }

      return Nop_mid <= Nop;
    };

    if(is_inc(mid)){ inc= mid; }
    else           { exc= mid; }
  }
  
  cout << inc << endl;
}

Measured memory_bytes: 4844
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    sys.exit()

Measured memory_bytes: 3064
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, ans, d, r;
  scanf("%lld%lld%lld", &r, &d, &ans);
  for(i = 0; i < 10; ++i) 
    ans = r * ans - d, printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// union find
class union_find {
public:
    int n;
    vector<int> parent, rnk, num;
    
    union_find(int n) : n(n), parent(n), rnk(n, 0), num(n, 1) {rep(i, n) parent[i] = i; }
    
    int root(int x){ return (parent[x] == x) ? x : root(parent[x]); }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
            num[y] += num[x];
        }
        else{
            parent[y] = x;
            num[x] += num[y];
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
        n--;
    }
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    int count(int x){ return num[root(x)]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N){
        cin >> A[i];
        A[i]--;
        B[A[i]] = i;
    }
    if(N == 1){
        output(1);
        return 0;
    }
    union_find uf(N);
    ll ret = 0;
    for(int i = N - 1; i >= 0; i--){
        int j = B[i];
        ll tmp = 1;
        if(j - 1 >= 0 && A[j - 1] > i){
            
            tmp *= (uf.count(uf.root(A[j - 1])) + 1);
            uf.unite(A[j - 1], i);
//            cout << "unite" << A[j - 1] << "," << i << endl;
        }
        if(j + 1 < N && A[j + 1] > i){
           
            tmp *= (uf.count(uf.root(A[j + 1])) + 1);
            uf.unite(A[j + 1], i);
            
//            cout << "unite" << A[j + 1] << "," << i << endl;
        }
//        cout << i + 1 << "," << tmp << endl;
        ret += tmp * (i + 1);
    }
    
    output(ret);
    
    return 0;
}

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

struct Team
{
    int name, ca, time;
    int wa[11];
};

void swap( Team& a, Team& b );
void bubbleSort( Team* t, int x, int k );

int main()
{
    int m, t, p, r;
    int a, b, c, d;
    Team team[51];

    while( cin >> m >> t >> p >> r )
    {
        if( m + t + p + r == 0 )
            break;

        for( int i = 0; i < 51; i++ )
        {
            team[i].name = i;
            team[i].ca = 0;
            team[i].time = 0;
            for( int j = 0; j < 11; j++ )
                team[i].wa[j] = 0;
        }
        
        for( int i = 0; i < r; i++ )
        {
            cin >> a >> b >> c >> d;
            if( d == 0 )
            {
                team[b].ca++;
                team[b].time += a + team[b].wa[c] * 20;
            }
            else
                team[b].wa[c]++;
        }

        bubbleSort( team, t, 1 );
        bubbleSort( team, t, 0 );
        bubbleSort( team, t, 2 );

        for( int i = 1; i <= t - 1; i++ )
        {
            cout << team[i].name;
            if( team[i].ca > team[i+1].ca )
                cout << ",";
            else
            {
                if( team[i].time < team[i+1].time )
                    cout << ",";
                else
                    cout << "=";
            }
        }
        cout << team[t].name << endl;
    }
    return 0;
}

void swap( Team& a, Team& b )
{
    Team t = a;
    a = b;
    b = t;
}

void bubbleSort( Team* t, int x, int k )
{
    for( int i = 1; i <= x; i++ )
        for( int j = x; j >= 1 + i; j-- )
        {
            if( t[j].ca > t[j-1].ca && k == 1 )
                swap( t[j], t[j-1] );
            if( t[j].ca == t[j-1].ca && !k && t[j].time < t[j-1].time )
                swap( t[j], t[j-1] );
            if( t[j].ca == t[j-1].ca && k == 2 && t[j].time == t[j-1].time && t[j].name > t[j-1].name )
                swap( t[j], t[j-1] );
        }
}


Measured memory_bytes: 3100
// 10^100という数字がついているため、
// 異なる個数の数の和が二つあるとして、それらが一致することは絶対にない。
// なので、選ぶ個数それぞれについて、ありうる数を調べる
#include <bits/stdc++.h>
using namespace std;

// beetさんから引っ張ってきましたModintライブラリ
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<typename T,T MOD = 1000000007>
struct Mint{
    static constexpr T mod = MOD;
    T v;
    Mint():v(0){}
    Mint(signed v):v(v){}
    Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

    Mint pow(long long k){
    Mint res(1),tmp(v);
        while(k){
            if(k&1) res*=tmp;
            tmp*=tmp;
            k>>=1;
        }
    return res;
    }

    static Mint add_identity(){return Mint(0);}
    static Mint mul_identity(){return Mint(1);}

    Mint inv(){return pow(MOD-2);}

    Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
    Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
    Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
    Mint& operator/=(Mint a){return (*this)*=a.inv();}

    Mint operator+(Mint a) const{return Mint(v)+=a;}
    Mint operator-(Mint a) const{return Mint(v)-=a;}
    Mint operator*(Mint a) const{return Mint(v)*=a;}
    Mint operator/(Mint a) const{return Mint(v)/=a;}

    Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

    bool operator==(const Mint a)const{return v==a.v;}
    bool operator!=(const Mint a)const{return v!=a.v;}
    bool operator <(const Mint a)const{return v <a.v;}

    static Mint comb(long long n,int k){
        Mint num(1),dom(1);
        for(int i=0;i<k;i++){
            num*=Mint(n-i);
            dom*=Mint(i+1);
        }
        return num/dom;
    }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

typedef Mint<long long> P;

int main() {
    long long N, K;
    cin >> N >> K;

    vector<P> acum(N+2, P(0));
    for(int i = 1; i < acum.size(); ++i) acum[i] = P(i-1);
    for(int i = 1; i < acum.size(); ++i) acum[i] += acum[i-1];

    P res(0LL);
    for(int i = K; i <= N+1; ++i) {
        P Min = acum[i] - acum[0];
        P Max = acum[N+1]  - acum[N+1-i];
        res += Max - Min + P(1);
    }
    cout << res << endl;
    return 0;
}

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

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

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
 
int main(void){
   string s,p;
   cin >> s >> p;
       
   string ans = "No";
   for(int i = 0; i < (int)s.length(); i++){
       bool flag=true;
       for(int j = 0; j < (int)p.length(); j++){
           if(s[(i+j)%(int)s.length()] != p[j]){
               flag = false;
               break;
           }
       }
       if(flag){
           ans = "Yes";
           break;
       }
   }
   cout << ans << endl;
}


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

int compute(string num){

  if ( num[0] == num[1] &&
       num[1] == num[2] &&
       num[2] == num[3] ) return -1;

  int cnt = 0;
  string L, S;
  while(1){
    if ( num == "6174" ) break;
    L = num;
    S = num;
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    sort(S.begin(), S.end());
    int x = atoi(L.c_str()) - atoi(S.c_str());
    num[0] = '0' + x/1000; x %= 1000;
    num[1] = '0' + x/100; x %= 100;
    num[2] = '0' + x/10; x %= 10;
    num[3] = '0' + x;
    cnt++;
  }
  return cnt;
}

main(){
  string num;
  int tcase = 0;
  while(1){
    cin >> num;
    if ( num == "0000" ) break;
    tcase++;
    int a = compute(num);
    if ( a< 0 ) cout << "NA" << endl;
    else cout << a << endl;
  }
}

Measured memory_bytes: 1220
s = gets.chomp.split("")
s_length = s.length
stack = []
i = -1

while s.length > 0
  stack.push(s.pop)
  i += 1
  if i == 0
    next
  elsif stack[i] != stack[i-1]
    stack.pop(2)
    i -= 2
  end
end

puts s_length - stack.length

Measured memory_bytes: 10280
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  constexpr ll SIZE=1ll<<8;
  constexpr ll MAXN=1ll<<18;
  constexpr ll MAXW=100010;

  std::vector<ll> v(MAXN-1,0),w(MAXN-1,0);
  rep(i,0,n)std::cin>>v[i]>>w[i];

  std::vector<std::vector<ll>> dp(SIZE-1,std::vector<ll>(MAXW,0));

  rep(i,w[0],MAXW)dp[0][i]=v[0];

  rep(i,1,SIZE-1){
    rep(j,0,w[i])dp[i][j]=dp[(i-1)/2][j];
    rep(j,w[i],MAXW)dp[i][j]=std::max(dp[(i-1)/2][j],dp[(i-1)/2][j-w[i]]+v[i]);
  }

  ll q;
  std::cin>>q;

  using P=std::pair<ll,ll>;

  while(q--){
    ll a,l;
    std::cin>>a>>l;
    a--;

    if(a<SIZE-1){
      std::cout<<dp[a][l]<<"\n";
      continue;
    }

    std::vector<P> tmp(1,{0,0});
    while(a>=SIZE-1){
      ll m=tmp.size();
      rep(i,0,m){
        if(tmp[i].first+w[a]<=l)tmp.emplace_back(tmp[i].first+w[a],tmp[i].second+v[a]);
      }
      a=(a-1)/2;
    }

    ll ans=0;
    for(const auto& e:tmp){
      chmax(ans,e.second+dp[a][l-e.first]);
    }
    std::cout<<ans<<"\n";
  }

  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
  	cin >> n;
  	int l, r;
  	int ans = 0;
 	rep(i,n){
    	cin >> l >> r;
      	ans += r-l+1;
    }
 	cout << ans << endl;
	return;
}

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


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

using namespace std;

int main(){
    int n,m,k[10],s[10][10] = {},p[10],count = 0;
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        cin >> k[i];
        for(int j = 0;j < k[i];j++){
            int x;
            cin >> x;
            s[i][x-1] = 1;
        }
    }
    for(int i = 0;i < m;i++){
        cin >> p[i];
    }
    for(int bit = 0;bit < (1 << n);bit++){
        bool flag = true;
        for(int i = 0;i < m && flag;i++){
            int sum = 0;
            for(int j = 0;j < n;j++){
                if(bit & (1 << j))sum += s[i][j];
            }
            if(sum % 2 != p[i]){
                flag = false;
                break;
            }
        }
        if(flag)count++;
    }
    cout << count;
    return 0;
}

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

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

struct edge {
  int to, cost;
  edge() {}
  edge(int t, int c): to(t), cost(c) {}
};

const int INF = 1e9;
edge G[100010][2];
vector<int> d(100010);

void dijkstra(int s) {
  priority_queue< pii, vector<pii>, greater<pii> > que;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  que.push(pii(0, s));
  while (!que.empty()) {
    pii p = que.top(); que.pop();
    int v = p.second;
    if (p.first > d[v]) continue;
    for (int i = 0; i < 2; i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pii(d[e.to], e.to));
      }
    }
  }
}

int main(void) {
  int K;
  cin >> K;

  for (int i = 0; i < K; i++) {
    G[i][0] = edge((i + 1) % K, 1);
    G[i][1] = edge(i * 10 % K, 0);
  }
  dijkstra(1);
  cout << d[0] + 1 << endl;

  return 0;
}

Measured memory_bytes: 2812
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i)
  DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i)  
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end())
#define SSCLEAR(ss) ss.str("");ss.clear(stringstream::goodbit)
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string n;
  while(cin >> n){
  TSTART();
  stringstream ss;
  int rank;
  int ans = 0;
  bool special = true;
  REP(i,SZ(n)){
    ss << n[i];
    ss >> rank;
    ans += rank;
    SSCLEAR(ss);
    if(i == 0 && n[i] != '1'){
      special = false;
    }else if(i != 0 && n[i] != '0'){
      special = false;
    }
  }
  if(special){
    ans = 10;
  }
  cout << ans << endl;
  TSTOP();
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())

int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
using namespace std;

//contemp
int H,W;
string grid[25][25];

int bfs(int bx, int by){
    string grid2[25][25];
    
    int han[25][25];
    REP(i,25){
        REP(j,25){
            han[i][j] = INF;
        }
    }
    queue<int> Q;
    Q.push(bx);
    Q.push(by);
    han[by][bx] = 0;
    while(!Q.empty()){
        int x = Q.front();Q.pop();
        int y = Q.front();Q.pop();

        REP(i,4){
            int nx = x + dr[i];
            int ny = y + dc[i];

            if(grid[ny][nx] == "." && han[ny][nx] == INF){
                han[ny][nx] = han[y][x] + 1;
                Q.push(nx);Q.push(ny);
            }
        }
    }
    int ans = 0;
    REP(i,H+2){
        REP(j,W+2){
            if(han[j][i] != INF){
                ans = max(ans,han[j][i]);
            }
        }
    }
    return ans;
}
int main(){ 
    cin >> H >> W;
    REP(i,H+2){
        REP(j,W+2){
            if(i == 0 || j == 0 || i == H+1 || j == W+1){
                grid[i][j] = '!';
            }else{
                char a;
                cin >> a;
                grid[i][j] = a;
            }
        }
    }
    int ans = 0;
    REP(i,H+2){
        REP(j,W+2){
            if(grid[i][j] == "." )
            ans = max(ans,bfs(j,i));
        }
    }
    cout << ans <<endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println(Math.max(Math.max(a + b, a - b), a * b));
		
		sc.close();
		
	}
}




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

int main(){
  int n,a,b,j=0,k=0,l=0,ans;
  cin >> n >> a >> b;
  vector<int> p(n),q(n),r(n),s(n);
  for(int i=0;i<n;i++)cin >> p.at(i);
  for(int i=0;i<n;i++){
    if(p.at(i)<=a)j++;
    else if(a+1<=p.at(i) && p.at(i)<=b)k++;
    else if(b+1<=p.at(i))l++;
  };
  ans = min(j,k);
  if(ans > l)ans=l;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main()
{
	ll k,a,b;
	cin>>k>>a>>b;
	ll prev=(a/k)*k;
    if(prev==a||(prev+k)<=b){
    	cout<<"OK"<<endl;
	}
    else{
    	cout<<"NG"<<endl;
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111




	void solve(){



 	

		ini(n);
		ini(n1);
		map<int,int>map1;
		FOR(i,0,n1){
			ini(x);
			ini(x1);
			map1[x]++;
			map1[x1]++;
		}	
		FORR(x,map1)if(x.second%2)return out("NO");
		return out("YES");







	}









































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
const int N=2e2+20;
const int inf=1e9;
//vector<int,pair<int,int> >e[N]; 
int dist[N][N];//dist[u][v] u->v shortest path
struct edge{
	int a,b,c;
}e[1100];
int n,m;
void Floyd()
{
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);		
			}
		}
	}
}
int main()
{
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++)
		{	
			for(int j=1;j<=n;j++)
			{
				if(i==j)
				dist[i][j]=0;
				else
				dist[i][j]=inf;
			}
		}
		for(int i=0;i<m;i++)
		{
			cin>>e[i].a>>e[i].b>>e[i].c;	
			dist[e[i].a][e[i].b]=e[i].c;//无中间结点 
			dist[e[i].b][e[i].a]=e[i].c;
		}
		Floyd();
		//边e[i]{u,v,w}有两种情况
		// w>dist[u][v] 则这条边不会经过任何两个点最短路
		// w=dist[u][v]
		int ans=0;   
		for(int i=0;i<m;i++)
		{
			if(dist[e[i].a][e[i].b]<e[i].c)
			ans++; 
		} 
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
X, Y = map(int, input().split())
ans = 0

if X == 1:
    ans += 300000
elif X == 2:
    ans += 200000
elif X == 3:
    ans += 100000

if Y == 1:
    ans += 300000
elif Y == 2:
    ans += 200000
elif Y == 3:
    ans += 100000

if X == 1 and Y == 1:
    ans += 400000

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vi::iterator vit;
typedef vi::reverse_iterator vrit;
#define pb push_back
const int MX=100005;
vi G[MX];
int n;
int dp(int k,int f){
	int v=0,v2=0;
	for(auto i:G[k])if(i!=f){
		int r=dp(i,k);
		v2|=(r&v),v|=r;
	}
	int it=0;while((1<<it)<=v2)it++;
	while((v>>it)&1)it++;
	return (v|(1<<it))&(~((1<<it)-1));
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;cin>>a>>b;
		G[a].pb(b),G[b].pb(a);
	}
	cout<<31-__builtin_clz(dp(1,0))<<endl;
	return 0;
}

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

using namespace std;

int a[111111];
int main()
{
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
		scanf("%d", a + i);
	if (a[k - 1] != 2) {
		cout << -1 << endl;
		return 0;
	}
	auto x = 2ll, y = 2ll;
	k--;
	while (k--) {
		x = (x + a[k] - 1) / a[k] * a[k];
		y = (y + a[k + 1] - 1) / a[k] * a[k];
		if (x > y) {
			cout << -1 << endl;
			return 0;
		}
	}
	y = y + a[0] - 1;
	cout << x << ' ' << y << endl;
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
#define ll long long
using namespace std;
struct edge{int x, y, next;}a[N*2];
int n, w[N], x, y, l, p[N], ff, f[N], du[N], root;
inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}
inline void dp(int x, int fa){
	if(!a[p[x]].next){f[x]=w[x]; return;}
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y)dp(a[i].y, x);
	if(!ff)return;
	int mx=0; ll sum=0, R, s;
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y){mx=max(mx, f[a[i].y]); sum+=f[a[i].y];}
	if(mx*2>=sum)R=sum-mx; else R=sum>>1;
	s=sum-w[x];
	if(s<0||s>R){ff=0; return;}
	f[x]=sum-s*2;
}
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)scanf("%d", &w[i]);
	l=0; memset(p, 0, sizeof(p)); memset(du, 0, sizeof(du));
	for(int i=1; i<=n-1; i++){scanf("%d%d", &x, &y); add(x, y); add(y, x); du[x]++; du[y]++;}
	if(n==2){if(w[1]==w[2])printf("YES"); else printf("NO"); return 0;}
	for(int i=1; i<=n; i++)if(du[i]>=2)root=i;
	ff=1; dp(root, 0); if(ff&&f[root])ff=0;
	if(ff)printf("YES"); else printf("NO");
	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    int totalvote=0;
    rep(i,n){
        cin>>a.at(i);
        totalvote += a.at(i);
    }
    double threshold = (double)totalvote/(double)(4*m);
    int temp = 0;
    rep(i,n)if((double)a.at(i)>=(double)threshold)temp++;
    if(temp > m-1)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3616