akhauriyash/Code-Regression huggingface dataset:
using System;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		string s=Console.ReadLine();
		int a=0,b=0;
		for(int i=0;i<n;i++){
			if(s[i]=='('){b++;}
			else if(s[i]==')'&&b==0){a++;}
			else{b--;}
		}
		Console.WriteLine("{0}",new string('(',a)+s+new string(')',b));
	}
}

Measured memory_bytes: 13268
#include <array>
#include <iostream>
#include <utility>
#include <vector>

int N;
const int nmax = 200005;
std::array<int, nmax> ans;
std::vector<int> left, right;
std::array<std::vector<int>, nmax> adjlist;

void dfs(int u, int distance, int parent)
{
    // color[u] = distance % 2;
    if (distance % 2 == 0)
    {
        left.push_back(u);
    }
    else
    {
        right.push_back(u);
    }

    for (auto v : adjlist[u])
    {
        if (v != parent)
        {
            dfs(v, distance + 1, u);
        }
    }
}

int main()
{

    std::cin >> N;
    int a, b;
    for (size_t i = 0; i < N - 1; ++i)
    {
        std::cin >> a >> b;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }

    dfs(1, 0, -1);
    // std::cout << "left: ";
    // for (int i = 0; i < left.size(); ++i)
    //     std::cout << left[i] << " ";
    // std::cout << std::endl;
    // std::cout << "right: ";
    // for (int i = 0; i < right.size(); ++i)
    //     std::cout << right[i] << " ";
    // std::cout << std::endl;

    auto k = N / 3;
    auto num1 = k + (N % 3 == 0 ? 0 : 1);
    auto num2 = k + (N % 3 == 2 ? 1 : 0);
    auto num0 = k;
    auto ct0 = 0;
    auto ct1 = 0;
    auto ct2 = 0;

    // std::cout << "num 0, 1, 2 = " << num0 << ", " << num1 << ", " << num2 << std::endl;

    if (right.size() <= k)
    {
        for (auto u : left)
        {
            int p;
            if (ct1 < num1)
                p = 3 * (ct1++) + 1;
            else if (ct2 < num2)
                p = 3 * (ct2++) + 2;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
        for (auto u : right)
        {
            ans[u] = 3 * (++ct0);
        }
    }
    else if (left.size() <= k)
    {
        for (auto u : right)
        {
            int p;
            if (ct1 < num1)
                p = 3 * (ct1++) + 1;
            else if (ct2 < num2)
                p = 3 * (ct2++) + 2;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
        for (auto u : left)
        {
            ans[u] = 3 * (++ct0);
        }
    }
    else
    {
        for (auto u : left)
        {
            int p;
            if (ct1 < num1)
                p = 3 * (ct1++) + 1;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
        for (auto u : right)
        {
            int p;
            if (ct2 < num2)
                p = 3 * (ct2++) + 2;
            else
                p = 3 * (++ct0);
            ans[u] = p;
        }
    }

    for (int i = 1; i <= N - 1; ++i)
    {
        std::cout << ans[i] << " ";
    }
    std::cout << ans[N] << std::endl;
}


Measured memory_bytes: 21620
import sys
from heapq import heappush, heappop


def floyd(dis, V):
    for i in range(V): dis[i][i] = 0
    
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if dis[i][k] != sys.maxint and dis[k][j] != sys.maxint and dis[i][k] + dis[k][j] < dis[i][j]:
                    dis[i][j] = dis[i][k] + dis[k][j]
                    
    for i in range(V):
        if dis[i][i] < 0:
            return 'NEGATIVE CYCLE'
    return 'NO NEGATIVE CYCLE'
    
    
if __name__ == '__main__':
    line = sys.stdin.readline()
    V, E = line.split()
    V, E = int(V), int(E)
    dis = [[sys.maxint for j in range(V)] for i in range(V)]
    
    for i in range(E):
        line = sys.stdin.readline()
        a, b, w = line.split()
        a, b, w = int(a), int(b), int(w)
        dis[a][b] = w
        
        
    judge = floyd(dis, V)
    if judge == 'NEGATIVE CYCLE':
        sys.stdout.write(judge + '\n')
    else:
        for i in range(V):
            sys.stdout.write(' '.join(map(lambda x: str(x) if x < sys.maxint else 'INF', dis[i])) + '\n')
        

Measured memory_bytes: 5020
def resolve():
    H, W = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(H)]
    ops = []
    for i in range(H):
        for j in range(W):
            if A[i][j] % 2 == 0:
                continue
            if j == W-1:
                if i == H-1:
                    continue
                else:
                    A[i][j] -= 1
                    A[i+1][j] += 1
                    ops.append([i+1, j+1, i+2, j+1])
            else:
                A[i][j] -= 1
                A[i][j+1] += 1
                ops.append([i+1, j+1, i+1, j+2])
    print(len(ops))
    [print(" ".join(map(str, op))) for op in ops]


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 30820
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    string s; cin >> s;
    int a = INF, b = 0;
    rep(i,0,s.size()) {
        if(s[i] == 'A') a = min(a, i);
        if(s[i] == 'Z') b = max(b, i);
    }
    cout << b - a + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

#define INF (1 << 29)

int min(int, int);

int main(){
  int n, i, j, k, l, p[101], m[101][101];
  scanf("%d", &n);
  for(i = 0; i < n; i++)  scanf("%d %d", &p[i], &p[i+1]);
  for(i = 1; i <= n; i++) m[i][i] = 0;
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k <= j-1; k++){
	m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n", m[1][n]);
  return 0;
}

int min(int a, int b){
  return a < b ? a : b;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    LD ans = 0;
    
    int R;
    cin >> R;
    ans = R*M_PI*2;
    cout << ans << endl;
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc163/abc163_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc163/abc163_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc163/abc163_a && sh shellscripts/submit_cpp.sh
*/


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

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

  string S, T;
  cin >> S >> T;
  if(S == T){
    cout << "EQUAL" << endl;
    return 0;
  }
  if(S.size() > T.size()){
    cout << "GREATER" << endl;
    return 0;
  }
  else if(T.size() > S.size()){
    cout << "LESS" << endl;
    return 0;
  }
  for(int i=0;i<S.size();i++){
    if(S[i] > T[i]){
      cout << "GREATER" << endl;
      return 0;
    }
    else if(T[i] > S[i]){
      cout << "LESS" << endl;
      return 0;
    }
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define deb(x) cout<<#x<<" "<<x<<endl;

int main()
{
	fastio;
	string s1;
	string s2;
	cin>>s1;
	cin>>s2;
	int counter = 0;
	for (int i = 0; i < 3; i++) {
		if(s1[i] == s2[i]) counter++;
	}
	cout<<counter<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	double A,B,C,D,E,F;
	cin >> A >> B >> C >> D >> E >> F;
	double water=0,sugar=0,mac=0;
	int maxwater=0,maxsugar=0;
	REP(i,31){
		REP(j,31){
          	if(i==0&&j==0) j++;
			water = 100*A*i+100*B*j;
			REP(k,3001){
				REP(p,3001){
					sugar = C*k+D*p;
					if(water+sugar <= F && sugar/water <= E/100){
						if(mac < 100*sugar/(water+sugar)){
							mac=100*sugar/(water+sugar);
							maxwater=(int)water;
							maxsugar=(int)sugar;
						}
					}else break;
				}
			}
		}
	}
	if(maxsugar==0) maxwater=min(100*A,100*B);
	cout << maxwater + maxsugar << " " << maxsugar << endl;		
	return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
A = list(map(int, input().split()))

kyori = []
for i in range(n - 1):
    kyori.append(abs(A[i] - A[i + 1]))

kyori.append(A[0] + (k-A[-1]))

ans = k - max(kyori)
print(ans)

Measured memory_bytes: 86140
def ceil(a, b):
    return a//b+(1 if a % b else 0)


n = int(input())
x, y = 1, 1
for _ in range(n):
    t, a = [int(i) for i in input().split()]
    k = max(ceil(x, t), ceil(y, a))
    x, y = t * k, a * k
print(x+y)


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
using ll = long long;

int n, k, v[50];
int eval(int l, int r, int rem) {
	int val = 0;
	priority_queue<int, vector<int>, greater<int>> pq;
	for (int i = 0; i < l; i++)
		pq.emplace(v[i]), val += v[i];
	for (int i = r; i < n; i++)
		pq.emplace(v[i]), val += v[i];
	while (0 < rem && !pq.empty() && pq.top() < 0)
		val -= pq.top(), pq.pop(), rem--;
	return val;
}
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", v + i);
	int val = 0;
	if (n <= k)
		val = max(val, eval(n, n, k - n));
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j <= n; j++)
			if (i + (n - j) <= k)
				val = max(val, eval(i, j, k - i - (n - j)));
	printf("%d\n", val);
}

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

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; 
#define endl            '\n'
#define pb              push_back
#define vll             vector<ll> 
#define f(i,x,y)        for(i=x;i<y;i++)
#define INF             LLONG_MAX
#define fast            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<endl; 
#define pll             pair<ll,ll> 
#define ff              first
#define ss              second
#define blt(x)          __builtin_popcount(x)
ll power(ll x, ll y, ll p = 1e9+7) 
{ 

    ll res = 1;
    x = x % p;
    while(y>0) 
    { 
        if(y&1) {
            res = (res*x) % p;
        }
        x = (x*x) % p;
        y = y>>1;
    }
    return res;
}
void solve()
{
    ll i,j,k,n;
    ll mod=1e9+7;
    cin>>n;
    if(n==1)
    {
        cout<<0;
        return ;
    }
    if(n==2)
    {
        cout<<2;
        return ;
    }
    ll ans=power(10,n);
    ll a=power(9,n);
    ll b=power(8,n);
    a=(2*a)%mod;
    cout<<(ans-(a-b)+mod)%mod;


}
    
int main()
{
    
    fast
    ll t = 1;

    while(t--)
    solve();
    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
    int i, x;

    for(i = 1; i <= 10000; i++){
        scanf("%d", &x);
        if(x == 0) break;
        else printf("Case %d: %d\n", i, x);
    }

    return 0;
}


Measured memory_bytes: 3136
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N), c(40);
    rep(0, i, N)
    {
        cin >> a.at(i);
        bitset<40> bit(a.at(i));
        rep(0, j, 40)
        {
            if (bit.test(j))
            {
                c.at(j)++;
            }
        }
    }

    ll x = 0;
    ll ans = 0;
    for (ll i = 39; i >= 0; i--)
    {
        if ((x + ((ll)1 << i) <= K) && (c.at(i) < ((N + 1) / 2)))
        {
            x += (ll)1 << i;
        }
    }

    rep(0, i, N)
    {
        ans += a.at(i) ^ x;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4060
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstring>
#define N 100000
using namespace std;

int main() {
  int a[3];
  int x;
  for(int i = 0;i < 3;i++)
    cin >> a[i];
  sort(a,a+3);
  if((a[1]-a[0]) % 2 == 0){
    x = (a[1]-a[0]) / 2 + a[2]-a[1];
  }
  else{
    x = (a[1]-a[0]+1) / 2 + a[2]-a[1] + 1;
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans = A[0]

for i in range(N):
  if A[i] == 0:
    ans = 0

for i in range(1,N):
  ans = ans * A[i]
  if ans > 10**18:
    ans = -1
    break

print(ans)

Measured memory_bytes: 21652
#include<stdio.h>
#include<string.h>
const int MAX=200000+5;
char str[MAX];
int main()
{
	int start=-1,end=-1;
	scanf("%s",str);
//	printf("%d",strlen(str));
	for(int i=0;i<strlen(str);i++)
	{
		if(str[i]=='A'&&start==-1)
		{
			start=i;
		}
		if(str[i]=='Z')
		{
			end=i;
		 } 
	}
	if(end-start<0) printf("0\n");
	else if(start-end<0) printf("%d\n",end-start+1);
	return 0;

	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    int n,ans=1;
    string s,tester;
    cin>>n>>s;
    tester=s[0];
    rep(i,n-1){
        if(tester[0]!=s[i+1]) ++ans; tester=s[i+1];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  vector<ll> a(n), b(n), c(n), s(n + 1), t(n + 1), u(n + 1);
  s[0] = 0;
  t[0] = 0;
  u[0] = 0;
  rep(i, n)
    in3(a[i], b[i], c[i]);
  rep(i, n){
    s[i + 1] = max(t[i] + a[i], u[i] + a[i]);
    t[i + 1] = max(u[i] + b[i], s[i] + b[i]);
    u[i + 1] = max(s[i] + c[i], t[i] + c[i]);
  }
  out(max({s[n], t[n], u[n]}));
  memi;
}

Measured memory_bytes: 4992
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

N,M=map(int, input().split())
A=np.array([i for i in range(N+1)[1::]])


minimum = 1
maximum = N

for _ in range(M):
    L,R=map(int, input().split())

    if(R < minimum or maximum < L):
        print(0)
        exit()

    if(minimum < L):
        minimum = L
    if(R < maximum):
        maximum = R

print(maximum - minimum + 1)

Measured memory_bytes: 17116
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
char f[52][52];

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

    int h, w;
    cin >> h >> w;
    REP(i, h)REP(j,w){
        cin >> f[i][j];
        if(f[i][j] == '.') f[i][j] = '0';
    }
    REP(i, h)REP(j, w){
        if(f[i][j] == '#'){
            FOR(x, max(0,i-1), i+2)FOR(y, max(0,j-1), j+2){
                if(f[x][y] != '#') f[x][y]++;
            }
        }
    }

    REP(i, h){
        REP(j,w){
            cout << f[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    int a[3]={1,0,0},work;
    char c1,c2,g='A';
    while(scanf("%c,%c",&c1,&c2)!=EOF){
        if(c1==g){
            g=c2;
        }
        else if(c2==g)g=c1;
    }
    printf("%c\n",g);
    return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


V solve(int n, int a, int b) {
  int c = a^b;
  if (__builtin_popcount(c) % 2 == 0) 
    return V();

  if (n == 1) 
    return V({a, b});

  int d = 0;
  while (c%2 == 0) {
    c >>= 1;
    ++d;
  }
  int a1 = (a>>(d+1));
  int a2 = ((a>>d)&1);
  int a3 = a % (1<<d);
  int b1 = (b>>(d+1));
  int b2 = ((b>>d)&1);
  int b3 = b % (1<<d);

  auto res1 = solve(n-1, (a1<<d)+a3, ((a1<<d)+a3)^1);
  for (auto &e : res1) {
    e = ((e>>d)<<(d+1)) + (a2<<d) + e % (1<<d);
  }

  auto res2 = solve(n-1, ((a1<<d)+a3)^1, (b1<<d)+b3);
  for (auto &e : res2) {
    e = ((e>>d)<<(d+1)) + ((a2^1)<<d) + e % (1<<d);
  }
  res1.insert(res1.end(), all(res2));
  return res1;
}


int main() {
  ll n, a, b; cin >> n >> a >> b;

  auto ans = solve(n, a, b);

  if (ans.size()) {
    cout << "YES" << "\n";
    cout << ans << "\n";
  }
  else cout << "NO" << "\n";

  return 0;
}


Measured memory_bytes: 1776
import sys
import copy
input = sys.stdin.readline
N = int(input())
ans = 0
xy = [list(map(int, input().split())) for i in range(N)]


def maken(n):
    s = 1
    for i in range(1, n+1):
        s *= i
    return s


for i in range(N):
    xy2 = copy.deepcopy(xy)
    c = xy2[i]
    del xy2[i]
    for l in xy2:
        ans += (((c[0]-l[0])**2+(c[1]-l[1])**2)**(1/2))*(maken(N-1))
print(ans/maken(N))

Measured memory_bytes: 3572
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

class Solution {
public:
	/* time: O(n^2), space: O(n^2) */
	int league(const vector<vector<int>>& A) {
		/* Build the dependency graph of all matches */
		const int n = A.size();
		vector<vector<int>> adjLists(n * n);
		for (int i = 1; i <= n; ++i) {
			int prevMatch = -1;
			for (int j : A[i - 1]) {
				const int playerX = min(i - 1, j - 1), playerY = max(i - 1, j - 1);
				const int currMatch = playerX * n + playerY;
				if (prevMatch != -1)
					adjLists[prevMatch].push_back(currMatch);
				prevMatch = currMatch;
			}
		}

		/* Run topological sort (Kahn's algorithm) */
		vector<int> nIndegree(n * n);
		for (const auto& adjList : adjLists) {
			for (int v : adjList)
				++nIndegree[v];
		}

		queue<int> Q;
		for (int i = 0; i < n * n; ++i) {
			if (!nIndegree[i])
				Q.push(i);
		}

		int ans = 0, nVisited = 0;
		for (int depth = 1; !Q.empty(); ++depth) {
			for (int i = Q.size(); i > 0; --i) {
				const int u = Q.front();
				++nVisited, Q.pop();
				for (int v : adjLists[u]) {
					if (nIndegree[v] && !--nIndegree[v])
						Q.push(v);
				}
			}
			ans = max(ans, depth);
		}
		if (nVisited < n * n)
			return -1; /* failed */
		return ans;
	}
};

int main() {
	int n;
	cin >> n;
	vector<vector<int>> A(n, vector<int>(n - 1));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - 1; ++j)
			cin >> A[i][j];
	}

	Solution sol;
	int ans = sol.league(A);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 49188
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110000;
int N;
ll a[Max];

int main(int argc, const char * argv[]) {
    cin >> N;
    inputArray(a, N);
    sort(a, a+N);
    ll n = a[N-1];
    ll r = a[0];
    
    ll mindiff = 1LL << 60;

    rep(i, N-1) {
        // output(2*a[i] - n);
        if (chmin(mindiff, abs(2*a[i] - n))) {
            r = a[i];
        }
        // output(mindiff);
    }

    printf("%lld %lld\n", n, r);

    return 0;
}

Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int x = 0, n;
    string s;
    cin >> n >> s;
    int res = x;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'I')
            ++x;
        else --x;
        res = max(res, x);
    }
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._
import scala.collection.mutable

object Main extends App {
  case class Job(day: Int, amount: Int)

  val Array(n, m) = readLine.split(" ").map(_.toInt)

  val jobs: Seq[Job] = for {
    i <- 1 to n
  } yield {
    val line = readLine.split(" ").map(_.toInt)
    Job(line(0), line(1))
  }

  val jobGroups = jobs.groupBy(_.day)
  val queue = collection.mutable.PriorityQueue[Int]()
  var ans = 0
  (1 to m).foreach { x =>
    jobGroups.getOrElse(x, Nil).foreach { job => queue += job.amount }

    if(queue.nonEmpty) {
      ans += queue.dequeue
    }
  }
  println(ans)
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	*/
	long long int n,w;
	cin>>n>>w;

	long long int wt[n],v[n];
	for(long long int i=0;i<n;i++)
		cin>>wt[i]>>v[i];

	long long int dp[n+1][w+1];

	for(long long int i=0;i<=n;i++) {
		for(long long int j=0;j<=w;j++) {
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(wt[i-1]<=j) {
				dp[i][j]=max(dp[i-1][j-wt[i-1]]+v[i-1],
							 dp[i-1][j]);
			}
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w]<<"\n";
}

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

int main() {
  int H, N;
  cin >> H >> N;
  vector<pair<int, int>> AB(N);
  for (int i = 0; i < N; i++) {
    cin >> AB[i].first >> AB[i].second;
  }

  long long dp[H];
  dp[0] = 0;
  for (int i = 1; i <= H; i++) {
    dp[i] = -1;
    for (int j = 0; j < N; j++) {
      int tmp = max(i - AB[j].first, 0);
      dp[i] = dp[i] == -1 ? AB[j].second + dp[tmp] : min(AB[j].second + dp[tmp], dp[i]);
    }
  }
  cout << dp[H];
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
typedef vector<int> VI;
#define pb                  push_back

int solve(VI vi, int t){
    int l = 0, r = vi.size()-1, cnt = 0;
    while(l<=r){
        int c = (l+r)/2;
        cnt++;
        if(vi[c] < t){ l = c+1; continue; }
        if(vi[c] > t){ r = c-1; continue; }
        break;
    }
    return cnt;
}

int main(void){
    int n, m;
    while(cin >> n && n){
        VI vi;
        REP(i,n){
            cin >> m;
            vi.pb(m);
        }
        cin >> m;
        cout << solve(vi, m) << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    LLI T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

    if(T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2) {
        cout << "infinity";
    } else {
        LLI up   = (B1 - A1) * T1;  //上がる
        LLI down = (B2 - A2) * T2;  //下がる
        LLI dt   = up + down;

int a=0<up?1:-1;
int b=0<dt?1:-1;

        if(0 <a*b) {
            cout << 0;
        } else {
            LLI minus = 0;
            if(abs(up) % abs(dt) == 0) minus = 1;

            cout << abs(up / dt) * 2 + 1 - minus;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef unsigned long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
//---------------------------------------------
 


int main(void)
{
ll a;
cin>>a;
ll ans;

ans= floor(a/500) * 1000;

a-= floor(a/500)*500;

ans+= floor(a/5) * 5;

cout<<ans<<endl;
}

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

int dp[8001][16001];
int a[8001];

int main(){
	string s;
	int x,y;
	cin>>s>>x>>y;
	int k=0, w=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='T'){
			a[++k]=w;
			w=0;
		}
		else{
			w++;
		}
	}
	a[++k]=w;
	dp[1][a[1]+8000]=1;
	for(int i=3;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	
	dp[0][8000]=1;
	for(int i=2;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000) 
			dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
			dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	
	int ans;
	if(k%2==0){ 
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	}
	
	cout<<((ans==1)?"Yes":"No");
	return 0;
}

Measured memory_bytes: 497792
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

#累積和
sumA = [0]*(N+1)
sumB = [0]*(N+1)
for i in range(N):
    sumA[i+1] = A[i] + sumA[i]
    sumB[i+1] = B[i] + sumB[i]

ncandy = 0
for i in range(1, N+1):
    nsum = sumA[i] + (sumB[N] - sumB[i-1])
    if ncandy < nsum:
        ncandy = nsum

print(ncandy)


Measured memory_bytes: 62008
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int a[5];
int b[5];

int solve(int ed)
{
    if(ed >= 5)
    {
        int rs = 0;

        rep(i,5)
        {
            int od = (rs + 9) / 10 * 10;
            rs = od + a[b[i]];
        }

        return rs;
    }
    else
    {
        int aed = ed+1;
        int rs = inf;
        
        rep(i,5)
        {
            bool bl = false;
            rep(j,ed)
            {
                if(b[j] == i)
                    bl = true;
            }

            if(!bl)
            {
                b[ed] = i;
                int cdd = solve(aed);
                rs = min(rs, cdd);
            }
        }

        return rs;
    }

}

int main(void)
{
    rep(i,5)
    {
        cin >> a[i];
    }

    cout << solve(0) << endl;

    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans=0;
    multiset<int> mt;
    for(int i=0;i<n;i++){
        auto iter=mt.lower_bound(a[i]);
        if(iter==mt.begin()){
            ans++;
            mt.insert(a[i]);
        }
        else{
            iter--;
            mt.erase(iter);
            mt.insert(a[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5376
import java.util.Scanner;
public class Main {
	static int[] parent;
	static int[] weights;
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int users = input.nextInt();
		int connections = input.nextInt();
		parent = new int[users];
		weights = new int[users];
		for(int i = 0; i < users; i++) {
			parent[i] = i;
			weights[i] = 1;
		}
		for(int i = 0; i < connections; i++) {
			int x = input.nextInt();
			int y = input.nextInt();
			union(x, y);
		}
		
		int tries = input.nextInt();
		for(int i = 0; i < tries; i++) {
			int num = input.nextInt();
			int num1 = input.nextInt();
			check(num, num1);
		}
		input.close();

	}
	public static void union(int x, int y) {
		int r1 = find(x);
		int r2 = find(y);
		if(r1 != r2) {
			if(weights[r2] > weights[r1]) {
				parent[r1] = r2;
				weights[r2] += weights[r1];
			}else {
				parent[r2] = r1;
				weights[r1] += weights[r2];
			}
		}
	}
	public static int find(int x) {
		int curr = x;
		while(parent[curr] != curr)
			curr = parent[curr];
		return curr;
	}
	public static void check(int x, int y) {
		int num = find(x);
		int num1 = find(y);
		if(num == num1) 
			System.out.println("yes");
		else
			System.out.println("no");
	}
}



Measured memory_bytes: 100268
#include<stdio.h>

int check(int p, int n, int k, int w[])
{
	int i=0;
	for(int j =0; j<k; j++)
	{
		int sum = 0;
		
		while(sum+w[i] <= p)
		{
			sum += w[i];
			i++;
			if(i==n)
			{
				return n;
			}
		}
	}
	return i;
	
}



int puton(int n, int k, int w[])
{
	int left,right, mid, v;
	
	left = 0;
	right = 100000 * 10000; //荷物の個数*一戸当たりの最大重量
	
	while(right-left>1)
	{
		mid = (left+right)/2;
		v=check(mid, n, k, w); //mid==pをきめて何個積めるかチェック
		if(v>=n)
		{
			right = mid;
		}
		else
		{
			left=mid;
		}
	}
	return right;
	
}

int main(void)
{

	int n, k, p;

	scanf("%d %d", &n, &k);
	
	int w[n];
	
	for(int i=0; i<n; i++)
	{
		scanf("%d", &w[i]);
	}

	p = puton(n, k, w);
	
	printf("%d\n", p);
	
	return 0;
	
}


Measured memory_bytes: 2156
'use strict'
function main (input) {
  input = input.split('\n')
  const troops = input[1].split('')
  const n = Number(input[0])
  let countsW = [0]
  for (let i = 1; i <= n; i++) {
    countsW[i] = (troops[i - 1] == 'W') ? countsW[i - 1] + 1 : countsW[i - 1]
  }
  let min, cnt = 0
  for (let i = 0; i < n; i++) {
      cnt = n - (i + 1) - (countsW[n] - countsW[i + 1]) + countsW[i]
    min = (min < cnt) ? min : cnt
  }
  console.log(min)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

#define all(x) (x).begin(), (x).end()
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)

template<class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template<class T> ostream& operator<<(ostream& O, vector<T>& v) {for (T &e: v) O << e << ' '; return O;}




void _main() {
        int n, m, k; cin >> n >> m >> k;
        vector<int> a(n), b(m); cin >> a >> b;
        int ans = 0;
        for (int i = 1; i < n; i++) a[i] += a[i - 1];
        for (int i = 1; i < m; i++) b[i] += b[i - 1];

        for (int i = -1; i < n; i++) {
                int take = i == -1 ? 0 : a[i];
                if (take > k) break;
                int l = k - take;
                int j = upper_bound(all(b), l) - b.begin();
                ans = max(ans, i + j + 1);
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 6320
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T
{
    std::io::Read::bytes(std::io::stdin())
                    .map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>()
                    .parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> Vec<T>
{
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim()
        .split_whitespace()
        .map(|x|
            x.parse().ok().unwrap()
        )
        .collect()
}

fn main() {
    let numbers = read_line::<i32>();
    let k: i32 = read();
    
    let mut sum: i32 = numbers.iter().sum();
    let max: i32 = numbers.into_iter().max().unwrap();
    let mut product = max;
    for _ in 0..k {
        product *= 2;
    }
    sum = sum - max + product;

    println!("{}", sum);
}


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


int main(){
    int n;
    ll p= 1e9+7;
    cin >> n;
    vector<int> a(100005, 0);
    bool ok = true;
    ll ans;


    for(int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        a[b]++;
    }

    if(n%2 == 0){
        for(int i = 1; i <= n-1; i+=2)
        {
            if(a[i] != 2) ok = false;
        }
    }
    else
    {
        if(a[0] != 1) ok = false;
        for(int i = 2; i < n; i+=2)
        {
            if(a[i] != 2) ok = false;
        }        
    }

    if(ok){
        ans = 1;
        for(int i = 0; i < n/2; i++)
        {
            ans = ans*2%p;
        }            
    }
    else ans = 0;

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int, D: int):
    while True:
        C -= B
        if C <= 0:
            print(YES)
            break
        A -= D
        if A <= 0:
            print(NO)
            break
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61988
#include <iostream>
#define ll long long
using namespace std;

ll N;
ll W;
ll w[120];
ll v[120];

ll V[110]; //価値の累積和

// dp[n][v] nコメまでで価値の総和をvにするような最低の重量を表す
ll dp[110][100010];

ll solve(ll n,ll v_move);

int main(){//cout<<1221<<endl;
  cin>>N>>W;
  
  for(ll in=1;in<=N;in++){
    cin>>w[in]>>v[in];
  }
  V[0]=0;
  for(ll i=1;i<=N;i++){
     V[i]=V[i-1]+v[i];
  }
  for(ll i=1;i<=N;i++){
   // cout<<V[i]<<endl;
  }
  
  for(ll i = 0;i<=N;i++){
    for(ll j=0;j<=V[N];j++){
      dp[i][j] = -1;
    }
  }
 
  for(ll i=1;i<=N;i++) dp[i][0]=0;
  
  for(ll i=1;i<=V[1];i++){
    if(i==v[1]) dp[1][i]=w[1];
  //  cout<<dp[1][i]<<"  ";
  }
 
 // cout<<endl<<endl;
  
  for (ll n=2; n<=N; n++) {
    for (ll v_move=1; v_move<=V[n]; v_move++) {
      
      dp[n][v_move] = solve(n, v_move);
      
    }
   // cout<<dp[n][V[n]]<<endl;
  }
  
  ll save=0;
  
  for(ll i=V[N];i>=0;i--){
   // cout<<dp[N][i]<<"  "<<i<<endl;
    if(dp[N][i] ==-1) continue;
    if(dp[N][i]<=W) {save=i;break;}
  }
  
  
  for(int n=0;n<=N;n++){
    for (int v_move=0; v_move<=V[n]; v_move++) {
    //  cout<<dp[n][v_move]<<"  ";
    }
  //  cout<<endl;
  }
  
  
  cout<<save<<endl;
  
  return 0;
}

ll solve(ll n,ll v_move){
  ll ans=110000000000000;
  bool flag1=false,flag2=false;
  
  if(v_move-v[n]>=0){
    if(dp[n-1][v_move-v[n]] != -1){
      ans=dp[n-1][v_move-v[n]]+w[n];
      flag1=true;
    }
  }
  if(dp[n-1][v_move] !=-1){ ans=min(dp[n-1][v_move],ans);flag2=true;}
  
  if(not(flag1 || flag2)) return -1;
  else return ans;
  
}




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

int main()
{
    int x,y;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0) break;
        if(x<y){
            cout<< x << " " << y <<endl;
        } else {
            cout<< y << " " << x <<endl;
        }
    }
}


Measured memory_bytes: 2996
cn = gets.to_i
tary = gets.chomp.split.map(&:to_i)
cm = gets.to_i
ARGF.read.strip.split.map(&:to_i).each_slice(2) do |i, j|
  ary = tary.dup
  ary[i-1] = j
  puts ary.inject(&:+)
end


Measured memory_bytes: 1916
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(X, Y+1):
  if X < i <= Y and max(x) < i <= min(y):
    print("No War")
    exit()
print("War")
             


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int N; cin >> N;
    ll dataA[3], dataB[3];
    F0R(i, 3) cin >> dataA[i];
    F0R(i, 3) cin >> dataB[i];

    vpl optionsA, optionsB;
    F0R(i, 3) {
    	if (dataA[i] > dataB[i]) {
    		optionsB.pb(mp(dataB[i], dataA[i]));
    	} else if (dataA[i] < dataB[i]) {
    		optionsA.pb(mp(dataA[i], dataB[i]));
    	}
    }

    ll dp[N+1];
    F0R(i, N+1) dp[i] = i;
    F0R(i, N) {
    	dp[i+1] = max(dp[i+1], dp[i]);
    	F0R(j, sz(optionsA)) {
    		ll price = optionsA[j].f;
    		ll value = optionsA[j].s;
    		if (i+price <= N) {
    			dp[i+price] = max(dp[i+price], dp[i] + value);
    		}
    	}
    }


    ll val = dp[N];
    ll dp2[val+1];
    F0R(i, val+1) dp2[i] = i;
    F0R(i, val) {
    	dp2[i+1] = max(dp2[i+1], dp2[i]);
    	F0R(j, sz(optionsB)) {
    		ll price = optionsB[j].f;
    		ll value = optionsB[j].s;
    		if (i+price <= val) {
    			dp2[i+price] = max(dp2[i+price], dp2[i] + value);
    		}
    	}
    }

    cout << dp2[val] << endl;
    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 195584
#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
using namespace std;
int _=1 , tc=1;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
int MAXN = 46341 + 1;
int spf[46341+1];
int d,x,y;
int gcd(int a , int b){
	if(b==0)return a;
	return gcd(b , a%b);
}
void sieve(){
	for(int i = 1 ; i<MAXN ; i++)spf[i]=i;
	for(int i = 4 ; i<MAXN ; i+=2)spf[i]=2;
	for(int i = 3; i*i<MAXN; i+=2){
		if(spf[i]==i){
			for(int j = i*i ; j<MAXN ; j+=i){
				if(spf[j]==j)spf[j]=i;
			}
		}
	}
}
void extended_gcd(int a , int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
	}else{
		extended_gcd(b,a%b);
		int temp = y;
		y = x - y * (a/b);
		x = temp;	
	}
}
ll gcd(ll a , ll b){
	if(b==0)return a;
	return gcd(b , a%b);
}
ll lcm(ll a, ll b){  
    return (a*b)/gcd(a, b);  
}
void solve(){
	ll n,d,k,x,ans=0;
	cin>>x>>k>>d;
	x = abs(x);
	ll steps = x/d;
	if(k>steps){
		k-=steps;
		x-=steps*d;
		if(abs(x-d) < abs(x)){
			k--;
			x = abs(x-d);
		}
		if(k&1){
			cout<<min(abs(x-d) , abs(x+d));
		}else{
			cout<<x;
		}
	}else{
		x-= k*d;
		cout<<x;
	}
}
int main(){
	SLAY
	// cin>>_;
	while(_--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,m;
pair<int,int> e[200];
bool vis[200];
int cut;
void dfs(int u){
	vis[u]=true;
	for(int i=1;i<=m*2;i++){
		if(e[i].first==u&&i!=cut){
			int v=e[i].second;
			if(!vis[v])
				dfs(v);
		}
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>e[i].first>>e[i].second;
		e[i+m].first=e[i].second;
		e[i+m].second=e[i].first;
	}
	int cnt=0;
	for(int i=1;i<=2*m;i++){
		cut=i;
		memset(vis,false,sizeof(vis));
		dfs(1);
		for(int j=1;j<=n;j++)
			if(vis[j]==false){
				cnt++;
				break;
			}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main(){
    int k[3];
    k[0]=300000;
    k[1]=200000;
    k[2]=100000;

    int x,y;
    int ans = 0;
    cin >> x >> y;

    if(x<4){
        ans += k[x-1];
    }

    if(y<4){
        ans += k[y-1];
    }
    if(x==1&&y==1)ans += 400000;

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


Measured memory_bytes: 256