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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(K);
    for(int k=0; k<K; k++) cin >> A[k];

    create_mod_tables(N);

    static int64_t dp[21][2001];
    dp[0][0] = 1;
    for(int k=0; k<K; k++) for(int i=0; i<=N; i++){
        if(dp[k][i] == 0) continue;
        for(int j=0; j+i<=N && j <= A[k]; j++){
            int64_t res = dp[k][i];
            mul(res, comb_mod(N-i, j));
            mul(res, comb_mod(N-j, A[k]-j));
            add(dp[k+1][i+j], res);
        }
    }
    cout << dp[K][N] << endl;
    return 0;
}


Measured memory_bytes: 512
#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(){
    string S;
    cin>>S;
    if(S=="ABC"){
        cout << "ARC" << endl;
    }else{
        cout <<"ABC" <<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "AC" << endl; exit(0); }
void no() { cout << "WA" << endl; exit(0); }

int main() {
    string s; cin >> s;
    int l = s.size();
    if(s[0] != 'A') no();
    if('A' <= s[1] && s[1] <= 'Z') no();
    if('A' <= s[l-1] && s[l-1] <= 'Z') no();
    int cnt[100]; rep(i, 100) cnt[i] = 0;
    FOR(i, 2, l-1) {
        cnt[s[i] - 'A']++;
    }
    if(cnt['C' - 'A'] != 1) no();
    FOR(i, 'A', 'Z'+1) {
        if(i == 'C') continue;
        if(cnt[i - 'A'] > 0) no();
    }
    yes();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    ll i;
    ll a[N];
    a[0]=0;
    for(i=1;i<N;i++){
      if(s[i-1]=='A' && s[i]=='C')a[i]=a[i-1]+1;else a[i]=a[i-1];
    }
    ll l,r;
    for(i=0;i<Q;i++){
      cin >> l >> r;
      cout <<a[r-1]-a[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////


typedef struct _ufTree{ 
	typedef long idx_type;
	
	vector<idx_type> par;
	vector<idx_type> rank;

	//n要素で初期化
	void init(idx_type n){
		par.assign(n,0);
		rank.assign(n,0);	
		for(idx_type i=0;i<n;i++) par[i]=i;
	}
	
	//木の根を求める
	idx_type root(idx_type x){
		if(par[x]==x) return x;
		else return par[x]=root(par[x]);
	}
	
	//xとyが同じ集合に属するかを調べる
	bool same(idx_type x,idx_type y){
		return root(x)==root(y);
	}
	
	//xとyの属する集合を併合
	void unite(idx_type x,idx_type y){
		x=root(x);
		y=root(y);
		if(x==y) return;
		if(rank[x]<rank[y]) par[x]=y;
		else{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
}ufTree;

int main(){
	int n,m;
	cin >> n >> m;
	int p[100010];
	rep(i,0,n){
		cin >> p[i];
		p[i]--;
	}
	
	ufTree u;
	u.init(n);
	//cout << "2" << endl;
	rep(i,0,m){
		int x,y;
		cin >> x >> y;
		x--; y--;
		u.unite(x,y);
	}
	
	int cnt=0;
	rep(i,0,n){
		if( u.same( p[i] , i ) ) cnt++;
	}
	//cout << "3" << endl;
	
	cout << cnt << endl;

	ret 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
int a,b,c,d,i,j,k;
int main(void){
        scanf("%d %d %d %d",&a,&b,&c,&d);
        for(;;){
                c = c - b;
          		if(c < 1){
                        printf("Yes");
                  		return 0;
                }
          		a = a - d;
                if(a < 1){
                        printf("No");
                  		return 0;
                }
        }
}


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

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

  int k, s; cin >> k >> s;

  int ans = 0;
  rep(i, k+1) rep(j, k+1) {
    int z = s-i-j;
    if(0<=z && z<=k) ans++;
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long

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

    ll ans = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
#include<algorithm>
#include<functional>
using namespace std;
#define all(v) v.begin(),v.end()
#define indexOf(v,x) (find(all(v),x)-v.begin())
	
string to_s(int n){
	stringstream ss;
	ss<<n;
	string s;
	ss>>s;
	return s;
}
int to_i(string s){
	int res=0;
	for(int i=0;i<s.size();i++){
		res *= 10;
		res += s[i]-'0';
	}
	return res;
}
int main(){
	int a,b,c,L;
	string s;
	while(cin>>a>>L,a||L){
		vector<int> v;
		v.push_back(a);
		while(1){
			s = to_s(a);
			s += string(L-s.size(),'0');
			sort(all(s),greater<char>());
			b = to_i(s);
			sort(all(s));
			c = to_i(s);
			a = b-c;
			int k = indexOf(v,a);
			if(k!=v.size()){
				cout<<k<<' '<<a<<' '<<v.size()-k<<endl;
				break;
			}
			v.push_back(a);
		}
	}
	return 0;
}

Measured memory_bytes: 1256
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = input();
    let s: Vec<char> = s.chars().collect();
    if s.len() % 2 != 0 {
        println!("No");
        return;
    }
    for i in 0..s.len() {
        if i % 2 == 0 {
            if s[i] != 'h' {
                println!("No");
                return;
            }
        } else {
            if s[i] != 'i' {
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  int ans=0;
  while(ans<1012){
    ans++;
    int a=ans*0.08;
    if(a!=A)continue;
    int b=ans*0.1;
    if(b!=B)continue;
    break;
  }
  if(ans==1012)cout<<"-1"<<endl;
  else cout<<ans<<endl;
}
      

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

const int MAX = 3000;
const int MOD = 1000000007;

long long 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 COM(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() {
    COMinit();
    
    int N, K;
    cin >> N >> K;
    for (int i = 1; i <= K; i++) {
        long long ans = COM(N-K+1, i) * COM(K-1, i-1);
        cout << ans % MOD << endl;
    }
}

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

int main(){
  long i,n,min = 1000000,max = -1000000,sum=0,x;

  cin >> n;

  for(i=0;i<n;i++){

    cin >> x;
    sum += x;
    if( x < min){
      min = x;
    }
    if( x > max){
      max = x;
    }
  }
  cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3112
N = int(input())
M = 10**6 + 1

counts = [0 for _ in range(M)]
for a in list(map(int, input().split())):
  counts[a] += 1

integers = [0,0] + [1 for _ in range(M-2)]
max_count = 0
for i in range(M):
  if integers[i] >= 1:
    count = 0
    for j in range(i,M,i):
      count += counts[j]
      integers[j] = 0
    max_count = max(max_count,count)

if max_count == N:
  answer = 'not coprime'
elif max_count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)

Measured memory_bytes: 225400
my $s = <STDIN>;
my @dat =  split(/ /,$s);
my $K =  $dat[0] ;


my @data;
my $count=9;
for(my $i=1;$i<10;$i++){
    #$data[0][$i-1]=$i;
    $data[$i-1]=$i;
}
if($K<10){ print "$data[$K-1]";exit;}
while(){
  my $num = @data;
  my @newdata;
  for(my $j=0;$j<$num;$j++){
    for(my $m=-1;$m<=1;$m++){
        my $tn = substr($data[$j], -1, 1);
        my $nx =  $tn +$m;
        if($nx == -1 ){next;}
        if($nx == 10 ){next;}
        my $newnum = "$data[$j]$nx";
        $count++;
        if($count >= $K){print "$newnum";exit}
        #print "$count $newnum\n";
        push ( @newdata,$newnum);
    }
  }
  @data = @newdata;
}


Measured memory_bytes: 7936
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int s = scan.nextInt();

        int hour = s / (60 * 60);
        int min = (s - (hour * 60 * 60)) / 60;
        int sec = s - (min * 60) - (hour * 60 * 60);

        System.out.println(hour + ":" + min + ":" + sec);
    }
}





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

int sutiakonnpu(const void* x, const void* y) {
	return strcmp(x, y);
}

int cmp(const void* x, const void* y) {
	char a = *(const char*)x, b = *(const char*)y;
	return a < b ? -1 : a > b;
}

int N;
char s[114514][12];

int main(void) {
	int i;
	int start;
	int64_t mizuhasu = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%11s", s[i]) != 1) return 1;
		qsort(s[i], strlen(s[i]), sizeof(*s[i]), cmp);
	}
	qsort(s, N, sizeof(*s), sutiakonnpu);
	s[N][0] = '\0';
	start = 0;
	for (i = 1; i <= N; i++) {
		if (strcmp(s[start], s[i]) != 0) {
			int64_t num = i - start;
			mizuhasu += num * (num - 1) / 2;
			start = i;
		}
	}
	printf("%" PRId64 "\n", mizuhasu);
	return 0;
}


Measured memory_bytes: 2556
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	int a[n],sum=0,f=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=0;i<n;i++){
		if(sum>2*a[i]);
		else f=0;
	}
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main() {
  string s, t;
  cin >> s;
  cin >> t;

  if (s.size() == 0 || t.size() == 0) {
    cout << endl;
    return 0;
  }

  const int row_size = t.size() + 1;
  vector<int16_t> table((s.size() + 1) * row_size, 0);
  // s - row, t - column.
  uint16_t value = 0;
  for (int i = 1; i <= s.size(); i++) {
    for (int j = 1; j <= t.size(); j++) {
      value = max<int16_t>(table[(i - 1) * row_size + j],
                                    table[i * row_size + j - 1]);
      if (s[i - 1] == t[j - 1]) {
        value = max<int16_t>(value, table[(i - 1) * row_size + j - 1] + 1);
      }
      table[i * row_size + j] = value;
    }
  }

  string result(value, '?');
  for (int i = s.size(), j = t.size(); i > 0 && j > 0 && value > 0;) {
    auto letter = s[i - 1];
    if (letter == t[j - 1]) {
      result[--value] = letter;
      i--;
      j--;
    } else {
      if (table[(i - 1) * row_size + j] > table[i * row_size + j - 1]) {
        i--;
      } else {
        j--;
      }
    }
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 17920
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
 
        while(true){
            int n=sc.nextInt(),r=sc.nextInt();
            if(n==0) break;
 
            int[] card=new int[n];
            for(int i=0;i<n;i++) card[i]=n-i;
            for(int i=0;i<r;i++){
                int p=sc.nextInt()-1;
                int c=sc.nextInt();
                int[] next=new int[n];
                for(int j= p ;j<p+c;j++) next[j-p]=card[j];
                for(int j= 0 ;j< p ;j++) next[c+j]=card[j];
                for(int j=p+c;j< n ;j++) next[ j ]=card[j];
                card=next;
            }
            System.out.println(card[0]);
        }
 
        return;
    }
}


Measured memory_bytes: 37292
#include<bits/stdc++.h>
using namespace std;
int n, v[100002];
int winn(int turn)
{
    int odd = 0, even = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(v[i] % 2 == 0)
            ++even;
        else
            if(v[i] == 1)
                ++odd;
    }
    if(even % 2 == 1)
        return turn;
    if(even < n - 1)
        return 3 - turn;
    if(odd)
        return 3 - turn;
    for(int i = 1; i <= n; ++i)
        if(v[i] % 2 == 1)
            --v[i];
    int cmm = v[1];
    for(int i = 1; i <= n; ++i)
        cmm = __gcd(cmm, v[i]);
    for(int i = 1; i <= n; ++i)
        v[i] /= cmm;
    return winn(3 - turn);
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    int tu = winn(1);
    if(tu == 1)
        cout << "First";
    else
        cout << "Second";
    return 0;
}


Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;


class DRainFlowsIntoDams {
public:
    ll N;
    ll A[100000];

    void solve(std::istream& in, std::ostream& out) {
        in >> N;
        REP(i, N) in >> A[i];
        ll sum = 0; REP(i, N) sum += A[i];
        ll s = 0; REP(i, N) if (i % 2 == 0) s += A[i] * 2;
        ll A1 = s - sum;
        ll tmp = A1; out << tmp;
        REP(i, N-1) { tmp = 2 * A[i] - tmp; out << " " << tmp; }
        out << endl;
    }
};


int main() {
    DRainFlowsIntoDams solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 2048
from collections import deque

N = int(input())
h = list(map(int,input().split()))

stack = deque([])
prevPoint = -1

for i in range(N) :
    if h[i] == 0 :
        stack.append((prevPoint+1 , i))
        prevPoint = i
    elif i >= N - 1 :
        stack.append((prevPoint+1,N))

ans = 0

while stack :
    start , end = stack.pop()

    if start >= end :
        ans += h[start]
        h[start] = 0
        continue


    minus = min(h[start:end])
    ans += minus

    prevPoint = start - 1
    for i in range(start,end) :
        h[i] -= minus
        if h[i] == 0 :
            stack.append((prevPoint+1,i))
            prevPoint = i
        elif i >= end - 1 :
            stack.append((prevPoint+1,end))

print(ans)



Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

const int MX=100005;

int main()
{
    int n,cnt=0;
    cin>> n;
    for(int a=1;a<=n;a++){
        for(int b=1;a*b<n;b++){
            cnt++;
        }
    }
    cout<< cnt <<endl;
    return 0;
}

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

int main(void) {

    string str;
    cin >> str;
    int ans = str.length();

    int n = str.length();
    for (int i = 0; i < 26; ++ i) {
        string s = str;
        int step = 0;
        while ( s.length() > 1 ) {
//            if (i == 'v' - 'a') cerr << step << ' ' << s << endl;
            bool flag = true;
            for (char ch: s) if (ch != i + 'a') flag = false;
            if (flag) break;

            ++ step;
            string t;
            for (int j = 0; j < s.length(); ++ j) if (s[j] != i + 'a' && (j + 1 < s.length() && s[j + 1] == i + 'a')) {
                for (int k = j; k < s.length() - 1; ++ k) if (s[k + 1] == 'a' + i){
                    t += i + 'a';
                } else {
                    t += s[k];
                }
                break;
            } else {
                t += s[j];
            }
            if (t == s) t.pop_back();
            s = t;
        }
        ans = min(ans, step);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

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; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 N, A, B;
  cin >> N >> A >> B;

  i64 ab = A + B;

  i64 c = N / ab, d = N % ab;

  i64 result = c * A + min(A, d);

  cout << result;
}
#endif


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

using namespace std;

const long long MAX_BIT = 60;

long long a, b;

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

    cin >> a >> b;

    long long diffBit = 0ll;
    for (long long bit = MAX_BIT; bit >= 0ll; bit--) {
        if ((a & (1ll << bit)) + (b & (1ll << bit)) != (1ll << bit)) {
            a = a & ~(1ll << bit);
            b = b & ~(1ll << bit);
        } else {
            diffBit = 1ll << bit;

            break;
        }
    }

    b = b & ~diffBit;

    long long mostSignificantBit = 0ll;
    for (long long bit = MAX_BIT; bit >= 0ll; bit--) {
        if ((b & (1ll << bit)) > 0) {
            mostSignificantBit = 1ll << bit;

            break;
        }
    }

    cout << (diffBit - a) + max(1ll, min(diffBit, (diffBit - a) + max(1ll, 2 * mostSignificantBit))) << endl;

    return 0;
}


Measured memory_bytes: 256
/*
 * ID: ITP1_3_D
 * Problem: devisors
 */

#include <stdio.h>

int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    int i;
    int count = 0;
    for (i = a; i <= b; i++)
        if ( c % i == 0)
            count++;

    printf("%d\n", count);

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  if (B < A){
    cout << 0;
  } else if (N == 1){
    if (A == B){
      cout << 1;
    } else {
      cout << 0;
    }
  } else {
    long long m = A * (N - 1) + B;
    long long M = A + B * (N - 1);
    cout << M - m + 1;
  }
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<'\n'

int main(){
    int n;
    cin >> n;
    string s,t,tes;
    cin >> s >> t;
    REP(i,n){
        tes = s.substr(i,n-i);
        if(tes==t.substr(0,n-i))break;
        tes="";
    }
    COUT(2*n-tes.size());
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define SUBIF(a, b, x) ((x) ? (b) : (a))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647LL
#define MOD 1000000007LL
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int a, b;


PII solve(){
	if(a < b) swap(a, b);
	int cnt = 1;
	int r = a%b;
	while(r > 0){
		a = b;
		b = r;
		r = a%b;
		cnt++;
	}
	return { b, cnt };
}


int main(){
	while(cin >> a >> b, a && b){
		PII ans = solve();
		cout << ans.first << ' ' << ans.second << endl;
	}

	return 0;
}


Measured memory_bytes: 3072
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def f(A, n):
    L = [0] + sorted([a % n for a in A if a % n != 0])
    R = [n - a for a in L[1:]] + [0]
    for i in range(len(L) - 1):
        L[i + 1] += L[i]
        R[len(L) - i - 2] += R[len(L) - i - 1]

    res = 10 ** 20
    for l, r in zip(L, R):
        res = min(res, max(l, r))
    return res


def main():
    N, K = read_values()
    A = read_list()
    S = sum(A)
    
    res = 0
    for n in range(1, int(S ** 0.5) + 1):
        if S % n != 0:
            continue
        m = S // n
        if f(A, n) <=  K:
            res = max(res, n)
        if f(A, m) <=  K:
            res = max(res, m)
    print(res)
        

if __name__ == "__main__":
    main()


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

int main() {
  string s1;
  string s2;
  string s;
  
  while(cin >> s1 && s1 != "-") {
    cin >> s2 >> s;

    int a=0, b=0, c=0;
    char now = s2[b++];
    string ans;
    while (a<s1.size()||b<s2.size()) {
//      cout << now << endl;
      if (now == s[c]) {
        now = s1[a++];
        c++;
      } else {
        ans += now;
        now = s2[b++];
      }
    }
    if (now != s[c])
      ans += now;
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef tuple<int, int, int, int> ANS;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

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

int main() {
    int H, W;
    cin >> H >> W;
    auto a = make_v(H, W, 0);
    REP(i, 0, H) {
        REP(j, 0, W) {
            cin >> a[i][j];
        }
    }
    vector<ANS> ans;
    REP(i, 0, H) {
        REP(j, 0, W - 1) {
            if (a[i][j] % 2 == 1) {
                ans.emplace_back(i, j, i, j + 1);
                a[i][j]--;
                a[i][j + 1]++;
            }
        }
    }
    REP(i, 0, H - 1) {
        if (a[i][W - 1] % 2 == 1) {
            ans.emplace_back(i, W - 1, i + 1, W - 1);
            a[i][W - 1]--;
            a[i + 1][W - 1]++;
        }
    }
    cout << ans.size() << endl;
    REP(i, 0, ans.size()) {
        int b, c, d, e;
        tie(b, c, d, e) = ans[i];
        cout << b + 1 << " " << c + 1 << " " << d + 1 << " " << e + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 5232
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        ans += s[i] == t[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll C[100005]={};
int n,m;
vector<int> v[100005];
int main() {
	int h,w;
	string s[401];
	cin>>h>>w;
	rep(i,0,h){
		cin>>s[i];
	}
	queue<Pa> que;
	queue<P> que2;
	bool d[401][401]={};
	int kx[4]={1,-1,0,0},ky[4]={0,0,1,-1};
	ll ans=0;
	ll wh=0,br=0;
	rep(i,0,h){
		rep(j,0,w){
			if(!d[i][j]){
				if(s[i][j]=='#')que.push(Pa(0,P(i,j)));
				if(s[i][j]=='.')que.push(Pa(1,P(i,j)));
				wh=0,br=0;
				while(!que.empty()){
					Pa pa=que.front();que.pop();
					int ma=pa.first,y=pa.second.first,x=pa.second.second;
					if(d[y][x])continue;
					d[y][x]=1;
					if(s[y][x]=='#')br++;
					if(s[y][x]=='.')wh++;
					for(int i=0;i<4;++i){
						if(Inframe(y,ky[i],x,kx[i],h,w)){
							if(ma==0&&s[y+ky[i]][x+kx[i]]=='.')que.push(Pa(1,P(y+ky[i],x+kx[i])));
							if(ma==1&&s[y+ky[i]][x+kx[i]]=='#')que.push(Pa(0,P(y+ky[i],x+kx[i])));
						}
					}
				}
				ans+=wh*br;
			}
		}
	}

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


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    ll h;
    cin >> h;

    ll num = 1;
    ll ans = 0;
    while (h > 0) {
        ans += num;
        num <<= 1;
        h >>= 1;
    } 

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

Measured memory_bytes: 256
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N, R, D, count, ans = 0, sqrt = 0 ;
  cin >> N ;
  int Ans[N+1] = {} ;
  while(sqrt * sqrt <= N ) sqrt++ ;
  for(int x=1;x<sqrt;x++){
    for(int y=1;y<sqrt;y++){
      for(int z=1;z<sqrt;z++){
        ans = x*x + y*y + z*z + x*y + y*z + z*x ;
        if(ans <= N) Ans[ans]++ ;
      }
    }
  }
  for(int i=1;i<(N+1);i++){
    cout << Ans[i] << endl ;
  }
  return 0 ;
}  

Measured memory_bytes: 3576
#include <cmath>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <fstream>
using namespace std;

#define maxn 100010
#define inf 1000000000000000000LL
#define ll long long

int main() {
    // freopen("test.in", "r", stdin);
    int k, t;
    cin >> k >> t;

    int maxv1 = 0;
    for (int i = 1; i <= t; ++i) {
        int x;
        cin >> x;
        maxv1 = max(maxv1, x);
    }
    k -= maxv1;

    int dif = maxv1 - k;
    if (dif <= 1) {
        cout << 0;
    } else {
        cout << dif-1;
    }
}


Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let s: String = parse_line().unwrap();
    let keyence = "keyence";
    let mut ans = "NO";

    if s.starts_with(keyence) || s.ends_with(keyence) {
        ans = "YES";
    } else {
        let mut s = s.chars();
        let mut k = keyence.chars();
        let mid: Option<char> = loop {
            if let Some(c) = k.next() {
                if s.next() != Some(c) {
                    break Some(c);
                }
            } else {
                break None;
            }
        };
        if {
            loop {
                if let Some(c) = k.next_back() {
                    if s.next_back() != Some(c) {
                        break false;
                    }
                } else if mid.is_some() {
                    if s.next_back() == mid {
                        break true;
                    } else {
                        break false;
                    }
                } else {
                    break true;
                }
            }
        } {
            ans = "YES";
        }
    }
    println!("{}", ans);
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<string> s(n);
    for(i = 0;i < n;++i){
        cin >> s.at(i);
    }
    ll ans = -1;
    for(i = 0;i < n;++i){
        vector<ll> cnt(n,-1);
        cnt.at(i) = 1;
        queue<ll> que;
        que.emplace(i);
        bool flag = false;
        while(!que.empty()){
            ll now = que.front();
            ll dist = cnt.at(now);
            que.pop();
            rep(j,n){
                if(s.at(now).at(j) == '0') continue;
                if(cnt.at(j) == -1){
                    cnt.at(j) = dist+1;
                    que.emplace(j);
                }else{
                    if(abs(dist - cnt.at(j)) == 1){
                        continue;
                    }else{
                        flag = true;
                        break;
                    }
                }
            }
            if(flag) break;
        }
        if(flag){
            flag = false;
            continue;
        }
        ll tmpans = -1;
        rep(j,n){
            tmpans = max(tmpans, cnt.at(j));
        }
        ans = max(ans,tmpans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll N,A,B;
  cin >> N >> A >> B;
  if(A>B || N<=1) {
    if(A==B){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
    return 0;
  }
  cout << (B-A)*(N-2)+1 << endl;
}


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

int N;
int A[210];

int main(){
    cin >>N;
    for(int i =0; i < N; i++){
        cin >> A[i];
    }
    int res = 0;

    while(true){
        bool exist_odd = false;
        for(int i =0; i < N; i++){
            if(A[i]%2 !=0 ) exist_odd =true;
        }
        if(exist_odd) break;
        for(int i =0; i < N; i++){
            A[i] /=2;
        }
        res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m;
string s, t;
map<ll, char> mp;
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
int main() {
    cin>>n>>m;
    cin>>s>>t;

    if(n<m){
        ll tmp=n;
        n=m;
        m=tmp;

        string str=s;
        s=t;
        t=str;
    }
    ll lcm=n/gcd(n, m)*m;

    bool flag=true;
    REP(i, 0, t.size()){
        mp[(lcm/m)*i+1]=t[i];
    }
    REP(i, 0, s.size()){
        ll idx=(lcm/n)*i+1;

        if(mp.find(idx)==mp.end()) continue;

        if(mp[idx]!=s[i]){
            flag=false;
            break;
        }
    }

    if(flag) cout<<lcm<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 5248
#include <assert.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

#define BUF_SIZE (20000+1) //入力バッファサイズ（ヌル終端領域込み）
#define INVALID_AREA (-1) // 水たまりの面積の無効値

struct Stack{
    size_t capacity;
    size_t size;
    int* buf;
};

struct Stack* stack_new(size_t capacity)
{
    struct Stack* stack=malloc(sizeof(struct Stack));
    assert(stack);
    stack->buf=malloc(sizeof(int)*capacity);
    assert(stack->buf);
    stack->capacity=capacity;
    stack->size=0;
    return stack;
}

void stack_delete(struct Stack* stack)
{
    free(stack->buf);
    free(stack);
}

bool stack_empty(struct Stack* stack){
    return stack->size==0;
}

size_t stack_size(struct Stack* stack)
{
    return stack->size;
}

void stack_push(struct Stack* stack, int item)
{
    assert(stack->size<stack->capacity);
    stack->buf[stack->size]=item;
    ++stack->size;
}

int stack_pop(struct Stack* stack){
    assert(!stack_empty(stack));
    assert(stack->size<=stack->capacity);
    --stack->size;
    return stack->buf[stack->size];
}

void merge_area(struct Stack* area_stack)
{
    int accumerated_area=0;
    int area=stack_pop(area_stack);
    while(area!=INVALID_AREA){
        accumerated_area+=area;
        area=stack_pop(area_stack);
    }
    stack_push(area_stack, accumerated_area);
}

int main(void){
    char* buf=malloc(sizeof(char)*BUF_SIZE);
    assert(buf);
    fgets(buf, BUF_SIZE, stdin);

    size_t len=strlen(buf);
    struct Stack* index_stack=stack_new(len); // '/'に対応する'\'のインデックスを保持（台形面積の計算に使用）
    struct Stack* area_stack=stack_new(len); // 現在までにできた水たまり

    for(int i=0; i<len; ++i){
        if(buf[i]=='\\'){
            stack_push(index_stack, i);
            stack_push(area_stack, INVALID_AREA);
        } else if(buf[i]=='/'){
            if(stack_empty(index_stack)){
                // これまでの水たまりはこれからできる水たまりにはマージされない。マージを防ぐために無効値を置いておく
                stack_push(area_stack, INVALID_AREA);
            } else{
                int j=stack_pop(index_stack);
                int upper_len=i-j+1, lower_len=i-j-1;
                int area=(upper_len+lower_len)/2;
                stack_push(area_stack, area);
                merge_area(area_stack);
            }
        }
    }

    struct Stack* result_stack=stack_new(stack_size(area_stack));
    int sum_area=0;
    while(!stack_empty(area_stack)){
        int area=stack_pop(area_stack);
        if(area==INVALID_AREA){
            continue;
        }
        sum_area+=area;
        stack_push(result_stack, area);
    }

    printf("%d\n%ld", sum_area, stack_size(result_stack));
    while(!stack_empty(result_stack)){
        printf(" %d",stack_pop(result_stack));
    }
    printf("\n");

    stack_delete(result_stack);
    stack_delete(area_stack);
    stack_delete(index_stack);
    free(buf);

    return 0;
}



Measured memory_bytes: 2108
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <numeric>

int main()
{
    int l, n, min_abs, sum = 0;
    std::cin >> n >> l;
    std::vector<int> a(n);

    min_abs = std::abs(l);
    for (int i = 0; i < n; i++)
    {
        if (std::abs(min_abs) > std::abs(l + i))
            min_abs = l + i;
        sum += l + i;
    }

    std::cout << sum - min_abs << std::endl;
    return 0;
}

Measured memory_bytes: 256
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
cnt=0
c=collections.Counter(a)
values=list(c.values())
key=list(c.keys())
for i in range(len(key)):
    l.append([key[i],values[i]])
#print(l)
for i in range(len(key)):
    if l[i][1]>l[i][0]:
        cnt=cnt+(l[i][1]-l[i][0])
    elif l[i][1]<l[i][0]:
        cnt=cnt+l[i][1]
print(cnt)

Measured memory_bytes: 25328
#include<stdio.h>

int main(){
  int i;
  int a,b,c;
  int n;
	int number;

  scanf("%d",&n);
	while(scanf("%d %d %d",&a,&b,&c)!=EOF){
    if(a*a==b*b+c*c||b*b==a*a+c*c||b*b+a*a==c*c){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
}
  return 0;
}

Measured memory_bytes: 580
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::cmp::min;

#[fastout]
fn main() {
    input! {
        a: isize,
        b: isize,
        _c: isize,
        k: isize,
    }
    let ans = if k <= a + b {
        min(a, k)
    } else {
        a - (k - a - b)
    };
    println!("{}", ans);
}


Measured memory_bytes: 2148
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(1000000);
    vector<int>b(1000000);
    cin>>a[0]>>b[0];
    for(int i=0;i<n;i++){
        cin>>a[i+1];
    }
     for(int i=0;i<=n;i++){
     	a[i]+=100;
    }
    for(int i=0;i<m;i++){
        cin>>b[i+1];
    }
    for(int i=0;i<=m;i++){
    	b[i]+=100;
    }
    sort(a.begin(),a.end(),greater<>());
    sort(b.begin(),b.end(),greater<>());
    if(a[0]>=b[m]){
        cout<<"War"<<endl;
    }
    else{
        cout<<"No War"<<endl;
    }
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int h,a,ans,sum=0;
  cin>>h>>a;
  long long ar[a];
  for(int i=0;i<a;i++)
  {
    cin>>ar[i];
    sum+=ar[i];
  }
  if(sum>=h)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)

int main(){
	int N, M, X, i, j;
	scanf("%d%d%d", &N, &M, &X);
	vector<int> C(N);
	vector<vector<int>> A(N, vector<int>(M));
	for(i = 0; i < N; i++){
		scanf("%d", &C[i]);
		for(j = 0; j < M; j++){
			scanf("%lld", &A[i][j]);
		}
	}
	int ans = inf;
	for(int s = 0; s < (1 << N); s++){
		vector<int> Asum(M, 0);
		int Csum = 0;
		for(i = 0; i < N; i++){
			if((s | (1 << i)) == s){
				Csum += C[i];
				for(j = 0; j < M; j++){
					Asum[j] += A[i][j];
				}
			}
		}
		int f = 1;
		for(j = 0; j < M; j++){
			if(Asum[j] < X){
				f = 0;
			}
		}
		if(f == 1){
			ans = min(ans, Csum);
		}
	}
	if(ans == inf){
		printf("-1\n");
	}
	else{
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3796
#include <iostream>

int main () {
  // 入力
  int a_weight, b_weight, c_weight, d_weight;
  std::cin >> a_weight >> b_weight >> c_weight >> d_weight;

  // おもりの傾き
  int left_weight = a_weight + b_weight;
  int right_weight = c_weight + d_weight;
  std::string tilt;
  if (left_weight > right_weight) {
    tilt = "Left";
  } else if (left_weight < right_weight) {
    tilt = "Right";
  } else {
    tilt = "Balanced";
  }

  // 出力
  std::cout << tilt << std::endl;

  return 0;
}


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

int main() {
    string S;
    int sunukecount=0;
    cin>>S;
    rep(i,6){
        if(S.at(i)=='1'){
            sunukecount+=1;
        }
    }
    cout<<sunukecount<<endl;
return 0;}
/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long cot[105];
ll ans=0;
int main()
{
    int n;
    memset(cot,0,sizeof(cot));
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int t=i;
        for(int j=2;j*j<=t;j++)
            while(t%j==0) cot[j]++,t/=j;
        if(t>1) cot[t]++;
    }
    for(int i=2;i<=100;i++)
        for(int j=2;j<=100;j++)
            for(int k=j+1;k<=100;k++)
            {
                if(i==j||i==k) continue;
                if(cot[i]>=2&&cot[j]>=4&&cot[k]>=4) ans++;
            }
    for(int i=2;i<=100;i++)
        for(int j=2;j<=100;j++)
    {
        if(i==j) continue;
        if(cot[i]>=4&&cot[j]>=14) ans++;
    }
    for(int i=2;i<=100;i++)
        for(int j=2;j<=100;j++)
    {
        if(i==j) continue;
        if(cot[i]>=2&&cot[j]>=24) ans++;
    }
    for(int i=2;i<=100;i++)
        if(cot[i]>=74) ans++;
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<queue>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)

vector<int> need[2];
int masu[555][555];
int visit[555][555];
class S{
public:
  int x,y;
  int n;
  S(int x,int y,int n):x(x),y(y),n(n){};
  bool operator<(const S& a)const{
    return n>a.n;
  }
};
int main(){
  while(1){
  int n;
  cin>>n;
  if(n==0)break;
  int dx[]={1,0,-1,0};
  int dy[]={0,1,0,-1};
  need[0].clear();
  need[1].clear();
  rep(p,2){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    rep(i,b){
      rep(j,a){
	cin>>masu[j][i];
      }
    }
    rep(i,b){
      rep(j,a){
	visit[j][i]=0;
      }
    }
    priority_queue<S> que;
    que.push(S(c-1,d-1,1));
    need[p].push_back(0);
    int now=-1;
    while(1){
      if(que.empty()==1){
	break;
      }
      S u=que.top();
      que.pop();
      if(u.x<0 || u.y<0||u.y>=b||u.x>=a)continue;
      if(visit[u.x][u.y]==1){
	continue;
      }
      //printf("!%d %d %d\n",u.x,u.y,u.n);
      visit[u.x][u.y]=1;
      now=max(now,masu[u.x][u.y]);
      need[p].push_back(now);
      
      rep(i,4){
	que.push(S(u.x+dx[i],u.y+dy[i],masu[u.x+dx[i]][u.y+dy[i]]));
      }
    }
  }
  /*
  rep(i,2){
    rep(j,need[i].size()){
      printf("%d\n",need[i][j]);
    }puts("");
    }*/
  int ans=101000000;
  rep(i,max(need[0].size(),need[1].size())){
    if(i>=need[0].size())continue;
    if(n-i<0)continue;
    if(n-i>=need[1].size())continue;
    ans=min(ans,need[0][i]+need[1][n-i]);
  }
  printf("%d\n",ans);
}
}

Measured memory_bytes: 5748
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

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

    bool is_prime[(int)1e5 + 1];
    fill(is_prime, is_prime + (int)1e5 + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= sqrt((int)1e5); i++)
    {
        if (is_prime[i])
        {
            for (int j = i + i; j <= (int)1e5; j += i)
            {
                is_prime[j] = false;
            }
        }
    }

    bool is_similar[(int)1e5 + 1];
    fill(is_similar, is_similar + (int)1e5 + 1, false);
    for (int i = 3; i < (int)1e5 + 1; i += 2)
    {
        if (is_prime[i] && is_prime[(i + 1) / 2])
        {
            is_similar[i] = true;
        }
    }

    //[0, index]までの和（indexを含むので注意）
    int cum_sum[(int)1e5 + 1] = {};
    for (int i = 3; i < (int)1e5 + 1; i++)
    {
        cum_sum[i] = cum_sum[i - 1];
        if (is_similar[i])
        {
            cum_sum[i]++;
        }
    }

    int l[n], r[n];
    rep(i, n)
    {
        cin >> l[i] >> r[i];
        if (l[i] <= 2)
        {
            l[i] = 3;
        }
    }

    rep(i, n)
    {
        cout << cum_sum[r[i]] - cum_sum[l[i] - 1] << endl;
    }
}

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

using namespace std;

typedef long long ll;

const int MAXN = 1000;
const ll MOD = 1e9 + 7;

int H, W;
ll dp[MAXN][MAXN];
vector<string> grid;

bool wall(int i, int j) {
    return grid[i][j] == '#';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> H >> W;
    grid.resize(H);
    for (int i = 0; i < H; i++)
        cin >> grid[i];
    dp[0][0] = 1;
    for (int i = 1; i < H; i++)
        dp[i][0] = wall(i, 0) ? 0 : dp[i - 1][0];
    for (int j = 1; j < W; j++)
        dp[0][j] = wall(0, j) ? 0 : dp[0][j - 1];
    for (int i = 1; i < H; i++)
        for (int j = 1; j < W; j++)
            dp[i][j] = wall(i, j) ? 0 : (dp[i - 1][j] + dp[i][j - 1]) % MOD;
    cout << dp[H - 1][W - 1] << endl;
}


Measured memory_bytes: 9088