akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int x = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();

        out.println((x - a) % b);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

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

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

    long double ans = 0; 
    for (int i = 0; i < n; i++)
    {
        long double x;
        string u;

        cin >> x >> u;
        if(u == "JPY")ans += x;
        else ans += x * 380000.0;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
 
vector <int> v;

pair <int, int> Calc(int a)
{
	int first = 0, second = 0;
	v.clear();			
	while(a)
	{
		v.pb(a % 10);
		a /= 10;
	}
	second = v[0], first = v.back();
	return mp(first, second);
}

long long res;
vector <int> what;
int d[101][101];

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	int n;
	cin >> n;
	for(int a = 1; a <= n; a++)
	{
		pair <int, int> cur = Calc(a);
		d[cur.F][cur.S]++;
	}
	for(int i = 0; i < 10; i++)
		for(int j = 0; j < 10; j++)
			res += d[i][j] * d[j][i];
	cout << res;
}                                

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

const int maxn = 1e6+1000;
typedef long long LL;
struct Node
{
    int v;
    LL w;
    Node(int v = 0,LL w = 0):v(v),w(w) {}
};


vector<Node> G[maxn];


int R,C;
int n;


LL A[maxn];
bool vis[maxn];



const LL INF = 0x3f3f3f3f3f3f3f3f;

int seq[maxn];
int cur;

bool dfs(int u)
{
    seq[cur++] = u;
    for(int i = 0;i < G[u].size();++i)
    {
        int v = G[u][i].v;
        LL w = G[u][i].w;

        if(!vis[v])
        {
            vis[v] = 1;
            A[v] = w-A[u];
            if(!dfs(v)) return false;
        }
        else
        {
            if(A[v] + A[u] != w) return false;

        }
    }
    return true;

}


bool bfs(int s)
{
    int b = 0, e = 1;
    seq[0] = s;
    vis[s] = true;
    A[s] = 0;
    while (b < e) {
      for (int j = 0; j < (int) G[seq[b]].size(); j++) {
        int u = G[seq[b]][j].v;
        int w = G[seq[b]][j].w;
        if (vis[u]) {
          if (A[seq[b]] + A[u] != w) {
            return false;
            }
          continue;
        }
        seq[e] = u;
        A[u] = w - A[seq[b]];
        vis[u] = true;
        e++;
      }
      b++;
    }
    cur = e;

    return true;
}

bool judge()
{

    memset(vis,0,sizeof(vis));
    for(int i = 1;i <= R+C;++i)
        if(!vis[i])
        {
            vis[i] = 1;
            A[i] = 0;

            cur = 0;
            if(!dfs(i)) return false;

            LL Minr = INF;
            LL Minc = INF;

            for(int j = 0;j < cur;++j)
            {
                int t = seq[j];
                if(t <= R)
                    Minr = min(Minr,A[t]);
                else
                    Minc = min(Minc,A[t]);

            }
            if(Minr + Minc < 0) return false;

        }
    return true;
}

int main()
{
   // freopen("./test.txt","r",stdin);
    scanf("%d %d",&R,&C);
    scanf("%d",&n);
    for(int i = 1;i <= n;++i)
    {
        int a,b;
        LL w;
        scanf("%d %d %lld",&a,&b,&w);
        b += R;
        G[a].push_back(Node(b,w));
        G[b].push_back(Node(a,w));
    }
    if(judge())
        puts("Yes");
    else
        puts("No");

    return 0;
}


Measured memory_bytes: 36608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int N,M; cin >> N >> M;
    vector<string> A(N);
    vector<string> B(N);
    
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];
    
    int D = N-M;
    
    bool isAns = false;
    
    for(int i = 0; i <= D; i++){
        for(int j = 0; j <= D; j++){
            
            bool isCheck = true;
            
            for(int row = 0; row < M; row++){
                for(int col = 0; col < M; col++){
                    
                    if(A[row+i][col+j]!=B[row][col]){
                        isCheck = false;
                        break;
                    }
                }
                if(isCheck==false) break;
            }
            
            if(isCheck) isAns = true;
            isCheck = true;

        }
        
    }
    
    
    if(isAns) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}



Measured memory_bytes: 256
x = int(input())
b_flg = True
try_n = x - 1
roop_c = 0
if x == 2:
    print(x)
else:
    while b_flg:
        try_n += 1
        for n in range(2, try_n):
            roop_c += 1
            if try_n % n == 0: # 素数でないことが確定した場合
                break
            else:
                if roop_c == try_n - 2:
                    b_flg = False
    print(try_n)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a) for (int i = (a); i >= 0; --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int mod = 1000000007;

int N, M;
int x[100005];
int y[100005];

signed main() {
    cin >> N >> M;
    REP(i, N) cin >> x[i];
    REP(i, M) cin >> y[i];

    int xans = 0;
    REP(i, N) { xans = (xans + (x[i] * i - x[i] * (N - i - 1)) % mod) % mod; }
    int yans = 0;
    REP(i, M) { yans = (yans + (y[i] * i - y[i] * (M - i - 1)) % mod) % mod; }
    int ans = xans * yans % mod;
    cout << ans << endl;

    return 0;
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c){
    cout<<1<<endl;
  }
  if(a!=b && b!=c && c!=a){
    cout<<3<<endl;
  }
  if(a==b && b!=c || b==c && c!=a ||c==a && a!=b){
    cout<<2<<endl;
  }
  return 0;
}

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

using namespace std;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

const int INF = 1 << 30;

int N, K, P[500000];
int pos[500000];
vector< int > g[500000];

int main() {
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    cin >> P[i];
    --P[i];
    pos[P[i]] = i;
  }

  {
    auto f = [](int a, int b) { return max(a, b); };
    SegmentTree< int > seg(N, f, -INF);
    for(int i = 0; i < N; i++) {
      auto ret = seg.query(max(0, pos[i] - K + 1), pos[i]);
      if(ret != -INF) {
        g[pos[ret]].emplace_back(pos[i]);
      }

      ret = seg.query(pos[i], min(N, pos[i] + K));
      if(ret != -INF) {
        g[pos[ret]].emplace_back(pos[i]);
      }

      seg.update(pos[i], i);
    }
  }


  vector< int > deg(N);
  for(int i = 0; i < N; i++) for(int j : g[i]) ++deg[j];
  priority_queue< int, vector< int >, greater<> > que;
  for(int i = 0; i < N; i++) if(deg[i] == 0) que.emplace(i);
  vector< int > ord;
  while(que.size()) {
    auto p = que.top();
    que.pop();
    ord.emplace_back(p);
    for(auto to : g[p]) {
      if(--deg[to] == 0) que.emplace(to);
    }
  }

  vector< int > ans(N);
  for(int i = 0; i < N; i++) ans[ord[i]] = i + 1;
  for(int i = 0; i < N; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 42236
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int count = 0;


		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				for (int k = 0; k <= c; k++) {
					int sum = 500 * i + 100 * j + 50 * k;
					if (sum == x) {
						count++;
					}

				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    cin >>n >>x;

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

    int d=0;
    int count=1;

    for (int i=2; i<=n+1;i++) {
        if(d+l[i-2]>x){
            break;
        }
        count++;
        d=d+l[i-2];
    }
    cout <<count <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

int main() {
	int A1, A2, A3; cin >> A1 >> A2 >> A3;

	int ans = min({abs(A1 - A2) + abs(A2 - A3),abs(A2 - A3) + abs(A3 - A1) ,abs(A3 - A1) + abs(A1 - A2) });
	cout << ans << endl;
	
	return 0;
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  deque<char> dq;
  string s; cin >> s;
  for(int i = 0,sz = (int)s.length(); i < sz; ++i)dq.push_back(s[i]);
  bool f = true;
  int q; cin >> q;
  for(int i = 0; i < q; ++i){
    int o; cin >> o;
    if(o == 1)f = !f;
    else{
      int k; cin >> k;
      char d; cin >> d;
      if(k == 1){
	if(f)dq.push_front(d);
	else dq.push_back(d);
      } else {
	if(f) dq.push_back(d);
	else dq.push_front(d);
      }
    }
  }
  if(f){
    for(auto it = dq.begin();it!=dq.end();++it)cout << *it;
  }else{
    for(auto it = dq.rbegin();it!=dq.rend();++it)cout << *it;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    vector<ll> T(2), A(2), B(2);
    for(int i = 0; i < 2; ++i)  cin >> T[i];
    for(int i = 0; i < 2; ++i){
        cin >> A[i];
        A[i] *= T[i];
    }
    for(int i = 0; i < 2; ++i){
        cin >> B[i];
        B[i] *= T[i];
    }
    if(A[0] + A[1] == B[0] + B[1]){
        cout << "infinity\n";
        return 0;
    }
    if(A[0] + A[1] < B[0] + B[1])   swap(A, B);
    ll foo = B[0] - A[0];
    if(foo < 0){
        cout << 0 << endl;
        return 0;
    }
    ll bar = A[0] + A[1] - B[0] - B[1];
    ll ans = foo / bar * 2;
    if(foo % bar != 0)  ++ans;
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

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

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

    if (n == 2) {
        cout << max(a[0], a[1]) << endl;
        return 0;
    }

    vi gf = vi(n);
    gf[0] = a[0];
    for (int i = 1; i < n; ++i) {
        gf[i] = gcd(gf[i - 1], a[i]);
    }

    vi gb = vi(n);
    gb[0] = a[n - 1];
    for (int i = 1; i < n; ++i) {
        gb[i] = gcd(gb[i - 1], a[n - i - 1]);
    }

    vi gm = vi(0);
    for (int i = 0; i < n - 1; ++i) {
        gm.push_back(gcd(gf[i], gb[n - 3 - i]));
    }
    gm.push_back(gf[n - 2]);
    gm.push_back(gb[n - 2]);
    sort(ALL(gm));

    cout << gm[gm.size() - 1] << endl;
    return 0;
}


Measured memory_bytes: 2044
sa = input()
sb = input()
sc = input()

card = sa[0]
sa = sa[1:]
while 1:
	if card == "a":
		if not sa:
			print("A")
			break
		else:
			card = sa[0]
			sa = sa[1:]
	elif card == "b":
		if not sb:
			print("B")
			break
		else:
			card = sb[0]
			sb = sb[1:]
	else:
		if not sc:
			print("C")
			break
		else:
			card = sc[0]
			sc = sc[1:]


Measured memory_bytes: 3064
X, Y = map(int, input().split())

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n-i) % mod
        rf = rf * (i+1) % mod
    return nf * pow(rf, mod-2, mod) % mod

def main():
    if (X+Y) % 3 or X > 2*Y or Y > 2*X:
        print(0)
        return
    n = (X+Y) // 3
    r = Y - n
    print(combination(n, r))

main()



Measured memory_bytes: 3064
require 'matrix'

N, C = gets.chomp.split(" ").map(&:to_i)
D = []
C.times{
  D << gets.chomp.split(" ").map(&:to_i)
}
G = Array.new(3)
(0..2).each{|i| G[i] = Array.new(C, 0)}
N.times{|i|
  wk = gets.chomp.split(" ").map(&:to_i)
  (0...wk.size).each{|j| G[(i+j+2) % 3][wk[j]-1] += 1}
}

M = Matrix.rows(D, false)
MG = Matrix.rows(G, false)
t = MG * M
c = []
(0..2).each{|i|
  c << t.row(i).to_a.each_with_index.sort_by{|x, | x}[0, 3]
}
ans = c[0].product(c[1], c[2]).select{|(x, i), (y, j), (z, k)| i!=j && j!=k && i!=k}.map{|(x, i), (y, j), (z, k)| [x+y+z, i, j, k]}.sort_by{|x, | x}

puts ans.first[0]


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define pe(x) cout << (x) << endl
#define ps(x) cout << (x) << ' ' 
int N,M;
int s[100100];
bool check(int X){ // M以上かかる
	//ps("X ");pe(X);
	if(s[0]>=1+X)return true;
	int cur = 1;
	//for(int i=0;i<N;i++)cout << s[i] << endl;
	int cnt = lower_bound(s,s+N,1+X)-s;
	int beat = 0;
	//cout << "cnt " << cnt << endl;
	
	while(cnt<N){
		int k = lower_bound(s,s+N,cur)-s;
		//ps("cur") << cur << endl;
		//ps("k");pe(k);
		int b = -1;
		if(s[k]>=cur+X){
			assert(k>0);
			b=abs(s[k-1]-cur);
		}else{
			if(k>0){
				if(abs(s[k]-cur)>abs(s[k-1]-cur)){
					b=abs(s[k-1]-cur);
				}else b=abs(s[k]-cur);
			}else{
				b = abs(s[k]-cur);
			}
		}
		int up = max(1,X-b);
		//ps("cnt");pe(cnt);
		//ps("up");pe(up);
		cur += up;
		beat++;
		cnt = lower_bound(s,s+N,cur+X)-s;
		//pe(beat);
	}
	//cout << "beat "  << beat << endl;
	beat++;
	return beat>=M;
}
bool solve(){
	cin >> N >> M;
	if(N+M==0)return false;
	for(int i=0;i<N;i++){
		cin >> s[i];
	}
	if(s[N-1]<=M){
		cout << -1 << endl;
		return true; 
	}
	int l=1,r=2000000;
	while(r-l>1){
		int mid = (l+r)/2;
		if(check(mid))l=mid;
		else r=mid;
	}
	if(l+1<=s[0])cout << -1 << endl;
	else cout << l << endl;
	return true;
}
int main(){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 3468
from _collections import deque
n,m=map(int,input().split())
X=[[] for _ in range(n)]
visited=[0]*(n+1)
ANS=[0]*n
ANS[0]=1
for i in range(m):
    a,b=map(int,input().split())
    X[a-1].append(b-1)
    X[b-1].append(a-1)

q=deque([0])
visited[0]=1
while len(q)>0:
    s=q.popleft()
    for x in X[s]:
        if visited[x]:
            continue
        q.append(x)
        ANS[x]=s
        visited[x]=1
print('Yes')
for ans in ANS[1:]:
    print(ans+1)

Measured memory_bytes: 35676
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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;

int main(){
    int N;
    cin >> N;
    ll s[N];
    rep(i, N){
        cin >> s[i];
    }

    ll ans = 0;
    REP(i,1, N){
        ll res = 0;
        ll c = i;
        ll tmp1 = 0;
        ll tmp2 = N-1;
        ll res1 = 0;
        if ((N - 1) % c == 0) {
//            cout << tmp1 << " 1 " << tmp2 << endl;
            while(tmp1 < tmp2 ) {

                res1 += s[tmp1] + s[tmp2];
                chmax(res, res1);
                tmp1 += c;
                tmp2 -= c;
            }
            chmax(ans, res);
        } else {
//            cout << tmp1 << " 2 " << tmp2 << endl;
            while(tmp1 < N - 1 - c && tmp2 > c) {

                res1 += s[tmp1] + s[tmp2];
                chmax(res, res1);
                tmp1 += c;
                tmp2 -= c;
            }
            chmax(ans, res);
        }

//        cout << ans << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
s = input().split()
W=int(s[0])
H=int(s[1])
x=int(s[2])
y=int(s[3])
r=int(s[4])

#row column:boolean
row = (r<=x)and(x<=W-r)
column = (r<=y)and(y<=H-r)

if row and column:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5596
#include <stdio.h>

#define N 500000
#define SENTINEL 1e9

int cnt;

void merge(int* A, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	int L[N], R[N];
	int i, j, k;

	for (i = 0; i <= n1 - 1; i++)
		L[i] = A[left + i];
	for (i = 0; i <= n2 - 1; i++)
		R[i] = A[mid + i];

	L[n1] = R[n2] = SENTINEL;
	i = j = 0;

	for (k = left; k <= right - 1; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
		}
	}
	cnt += (i + j);
}

void mergeSort(int* A, int left, int right) {
	int mid;

	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}

}

int main() {
	int i, n, S[N];

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &S[i]);

	mergeSort(S, 0, n);

	for (i = 0; i < n; i++) {
		printf("%d", S[i]);
		if (i < n - 1)
			printf(" ");
	}
	printf("\n%d\n", cnt);

	return 0;
}

Measured memory_bytes: 5492
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
constexpr char ZERO = '0';
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while(ZERO <= *pos) n = n * 10 + *pos++ - ZERO;
    pos++;
    while(ZERO <= *pos) m = m * 10 + *pos++ - ZERO;
    pos++;
    while(ZERO <= *pos) k = k * 10 + *pos++ - ZERO;
    nn = n;
    pos++;
    rep(i, n) {
        while(ZERO <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - ZERO;
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while(ZERO <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while(ZERO <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - ZERO;
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + ZERO;
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7900
# -*- coding: utf-8 -*-

s = input()
bitlist = []
for i in range(2**(len(s)-1)):
    bitlist.append([int(x) for x in list(bin(i)[2::].zfill(len(s)-1))])
for bit in bitlist:
    formula = s[0]
    ans = int(s[0])
    for i, sign in enumerate(bit):
        if sign == 0:#プラスとする
            formula += '+'
            ans += int(s[i+1])
        else:#マイナスとする
            formula += '-'
            ans -= int(s[i+1])
        formula += s[i+1]
    #print(formula)
    #print(ans)
    if ans == 7:
        print(formula + '=7')
        break

Measured memory_bytes: 3064
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

ans = 0
for i in range(n):
    t1 = min(aa[i], bb[i])
    aa[i] -= t1
    bb[i] -= t1
    ans += t1
    t2 = min(aa[i+1], bb[i])
    aa[i+1] -= t2
    bb[i] -= t2
    ans += t2
print(ans)

Measured memory_bytes: 24204
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
  double N, K, ans = 0;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) ans += i >= K ? 1.0 / N : 1.0 / (pow(2, ceil(log2((double)K / i))) * N);
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int> a(n+1,0);
  for (int i=1;i*i<=n;i++) {
    for (int j=1;i*i+j*j+i*j<=n;j++) {
      for (int k=1;i*i+j*j+k*k+i*j+i*k+j*k<=n;k++) {
        a[i*i+j*j+k*k+i*j+i*k+j*k]++;
      }
    }
  }
  for (int i=1;i<=n;i++) {
    cout<<a[i]<<"\n";
  }
  return 0;
}


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

int main(){
  string S ; 
  cin >> S ; 
  int N = S.size() ; 
  
  int cnt_R = 0 ;
  int cnt_B =  0;
  for(int i = 0 ; i < N ; i++){
    if(S.at(i) == '1' ){
      cnt_B++ ; 
    }
    else{
      cnt_R++ ; 
    }
  }
  cout << min(cnt_R , cnt_B)*2 << endl ; 
  
}

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

int gcd(int x, int y)
{
  if(y==0) return x;
  return gcd(y, x%y);
}

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  rep(i,n) cin >> a[i]; 
  
  vector<int> l(n), r(n);
  
  for(int i=0; i<n-1; i++)
  {
    l[i+1] = gcd(l[i], a[i]);
  }
  
  for(int i=n-1; i>=1; i--)
  {
    r[i-1] = gcd(r[i],a[i]);
  }
  
  int ans = 1;
  
  rep(i,n) ans = max(ans, gcd(l[i],r[i]));
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

#define MAX(x, y) ((x)>=(y) ? (x):(y))
#define MIN(x, y) ((x)<=(y) ? (x):(y))

int main() {
    int n;
    scanf("%d", &n);
    int minr;
    scanf("%d", &minr);
    int ans = -1 << 30;
    for(int i = 1; i < n; ++i) {
        int r;
        scanf("%d", &r);
        ans = MAX(ans, r - minr);
        minr = MIN(minr, r);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2752
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

/*
vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}
*/

int main() {
	int k,x;
	cin>>k>>x;
	rep(i,x-k+1,x+k)print(i);

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <stdio.h>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();

        int N;
        cin >> N;
        vector<double> P(N);
        rep(i, 0, N) cin >> P[i];

        vector<vector<double> > dp(N + 1, vector<double>(N + 1));
        dp[0][0] = 1;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j <= i; ++j) {
                dp[i + 1][j + 1] += dp[i][j] * P[i];
                dp[i + 1][j] += dp[i][j] * (1 - P[i]);
            }
        }

        double ans = 0.0;

        for(int i = N / 2 + 1; i <= N; ++i){
            ans += dp[N][i];
        }

//        cout << ans << endl;
        printf("%.9lf", ans);


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)

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

    map<string, int> c;
    rep(i, 0, n) {
        string s;
        cin >> s;
        c[s]++;
    }
    cout << "AC x " << c["AC"] << endl;
    cout << "WA x " << c["WA"] << endl;
    cout << "TLE x " << c["TLE"] << endl;
    cout << "RE x " << c["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3612
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5+5, LG = 17, MOD = 1e9+7;
const int SQ = 450;
const long double EPS = 1e-7;
int n, k;
int C[2005][2005];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  int n, k;
  cin >> n >> k;
  vector<int> v={0};
  for(int i = 1; i * i <= n; i++){
    v.pb(i);
    v.pb(n/i);
  }

  sort(v.begin(),v.end());
  v.resize(unique(v.begin(),v.end())-v.begin());

  vector<int> to(v.size());
  for(int i = 1; i * i <= n; i++){
    int a = lower_bound(v.begin(),v.end(),i)-v.begin();
    int b = lower_bound(v.begin(),v.end(),n/i)-v.begin();
    to[a] = b;
    to[b] = a;
  }
  vector<int> dp(v.size(), 1);
  for(int i = 1; i < k; i++){
    vector<int> old = dp;
    dp=vector<int>(v.size(),0);
    for(int j = 1; j < v.size(); j++){
      dp[to[j]] += 1ll * (v[j] - v[j-1]) * old[j] % MOD;
//      cout<<dp[to[j]]<<' '<<to[j]<<endl;
      if(dp[to[j]]>=MOD)dp[to[j]]-=MOD;
    }
    for(int j = v.size() - 1; j; --j)(dp[j-1]+=dp[j])%=MOD;
  }

  int ans = 0;

  f(i,1,v.size())
    (ans+=1ll*(v[i]-v[i-1])*dp[i]%MOD)%=MOD;

  cout<<ans<<'\n';


  return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  vector<ll> time(n);
  sort(time.begin(), time.end());
  ll l = -1, r = 1e13;
  while(l + 1 < r) {
    ll c = (l + r) / 2;
    bool ok = [&]{
      ll t = 0;
      rep(i, n) {
        t += max(0LL, a[i] - c / f[i]);
      }
      return t <= k;
    }();
    if(ok) r = c;
    else l = c;
  }
  cout << r << endl;
}


Measured memory_bytes: 3328
class SNS
  def initialize(n)
    @group_tbl = []
    @priority = []
    n.times{|i|
      @group_tbl[i] = i
      @priority[i] = 0
    }
  end

  def setGroup(i, j)
    ii = theGroup(i)
    jj = theGroup(j)
    if @priority[ii] > @priority[jj] then
      @group_tbl[jj] = ii
    else
      @group_tbl[ii] = jj
      @priority[jj] += 1 if @priority[ii] == @priority[jj]
    end
  end

  def isSameGroup(i, j)
    return theGroup(i) == theGroup(j)
  end

  def theGroup(i)
    @group_tbl[i] = theGroup(@group_tbl[i]) if i != @group_tbl[i]
    return @group_tbl[i]
  end
end
n, m = gets.split.map(&:to_i)

sns = SNS.new(n)

m.times{
  i, j = gets.split.map(&:to_i)
  sns.setGroup(i, j)
}
q = gets.to_i
q.times{
  s, t = gets.split.map(&:to_i)
  if sns.isSameGroup(s, t)
    puts "yes"
  else
    puts "no"
  end
}

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

int main() {
  int n,x;
  cin >> n;
  int a[200010],b[200010];
  for (int i=0; i<n; i++){
  cin >> x;
  a[i] = x;
  b[i] = x;
  }
  int p,q;
  sort(b, b + n, greater< int >());
  p = b[0];
  q = b[1];
  //cout << p << q << endl;
  for (int i=0; i<n; i++){
  if (a[i] <= q) cout << p << endl;
  else cout << q << endl;
  }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;

int main(){
  int a,b;
  cin >> a>>b;
  if(a==b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var s string 
  fmt.Scan(&s)
  n := len(s)
  cnt := 0
  for i := 0; i < n/2; i++ {
    if s[i] != s[n-1-i] {cnt++}
  }
  fmt.Println(cnt)
}

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

using namespace std;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if ((10 * a + b) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
    string s;
    while( cin >> s ){
        int n = s.size();
        for( int i = 0; i < n; i++ ){
            cout << "x";
        }
        cout << endl;
    }
}
/*
7 2
0 1 0 0 0 1 0
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const long long MAXN = 100100;

vector<long long> v1[MAXN];
    long long n,m;
    long long up[MAXN];
    long long down[MAXN];
    vector<long long> pref[MAXN];
    vector<long long> suff[MAXN];
int add(int x, int y){ x+=y;if(x>=m) x-=m;return x;}

int mul(int x, int y){ x=(long long)x*y%m;return x;}
void fix(long long x){
    for(auto& y:v1[x]){
        v1[y].erase(find(v1[y].begin(),v1[y].end(),(long long)x));
        fix(y);
    }
}
void dfs(int x){
    down[x]=1;
    for(auto&y:v1[x]){
        dfs(y);
        down[x]=mul(down[x],down[y]+1);
    }
    int sz=v1[x].size();
   // cout<<sz<<endl;
    pref[x].resize(sz+1);
    suff[x].resize(sz+1);
    pref[x][0]=suff[x][sz]=1;
    for(int i=0;i<sz;i++){
        pref[x][i+1]=mul(pref[x][i],1+down[v1[x][i]]);
        //cout<<x<<" "<<i+1<<" "<<pref[x][i+1]<<endl;
    }
    for(int i=sz-1;i>=0;i--){
        suff[x][i] = mul(suff[x][i+1],1+down[v1[x][i]]);
        //cout<<x<<" "<<i<<" "<<suff[x][i]<<endl;
    }
}
void dfs2(long long x){
    //cout<<1234<<endl;
    for(int i=0;i<v1[x].size();i++){
        int y=v1[x][i];
        up[y]=mul(up[x],mul(pref[x][i],suff[x][i+1]));
        up[y] = add(up[y],1);
        
        dfs2(y);
    }
}
int main(){

    cin>>n>>m;
    for(long long i=1;i<n;i++){
        long long x,y;
        cin>>x>>y;
        v1[x].push_back(y);
        v1[y].push_back(x);
    }
    fix(1);
    
    dfs(1);
    up[1] = 1;
    dfs2(1);
    for(long long i=1;i<=n;i++){
        //cout<<up[i]<<" "<<down[i]<<" ";
        cout<<mul(up[i],down[i])<<endl;
    }
}

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

int main() {
  int N,A,B,P;
  cin >> N >> A >> B;
  
  P = N * A;
  
  
  if (B >= P ) {
    cout << P << endl;
  }
  else {
    cout << B << endl;
  }
}

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

int main(){
  string a,b;
  cin >>a>>b;
  if (a.length()>b.length()){
    cout<<"GREATER"<<endl;
    return 0;
  }
      
  if (a.length()<b.length()){
    cout<<"LESS"<<endl;
    return 0;
  }
  if (a==b){
    cout<<"EQUAL"<<endl;
    return 0;
  } 
  for (int i=0;i<a.length();i++){
    if(a.at(i)>b.at(i)){
      cout<<"GREATER"<<endl;
      return 0;
    }
    if(a.at(i)<b.at(i)){
      cout<<"LESS"<<endl;
      return 0;
    }
  }
  return 0;
}

  

Measured memory_bytes: 256
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    t=list(map(int,input().split()))
    s.append(t)

fuman=[]
for i in range(26):
    fuman.append(c[i]*66795)

for i in range(d):
    p=fuman.index(max(fuman))
    if s[i][p]>10000:
        print(p+1)
        q=364-i
        fuman[p]=(q**2+q)*c[p]//2
        for j in range(26):
            if j!=p:
                fuman[j]-=c[j]*(i+1)
    else:
        p=s[i].index(max(s[i]))
        print(p+1)
        q=364-i
        fuman[p]=(q**2+q)*c[p]//2
        for j in range(26):
            if j!=p:
                fuman[j]-=c[j]*(i+1)

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

using namespace std;

int main(){
	int n, k;
	cin>>n>>k;
	int count =0;
	for(int i = 0; i<n;i++){
		int d;
		cin>>d;
		if(d>=k) count++;
		}
	cout<<count;
	return 0;
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
using namespace std ;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0) ;
    cout.tie(0) ;
    long long t ;
    map <string , int > mp ;
    cin >> t ;
    cin.ignore() ;
    while(t--)
    {
        string str ;
        getline(cin , str) ;
        mp[str]++ ;
    }
    cout <<"AC x "<<mp["AC"]<<"\n" ;
    cout <<"WA x "<<mp["WA"]<<"\n" ;
    cout <<"TLE x "<<mp["TLE"]<<"\n" ;
    cout <<"RE x "<<mp["RE"]<<"\n" ;
}


Measured memory_bytes: 3660
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N;
	cin >> N;
	vector<LL> A(N + 1), B(N);
	IN(A); IN(B);
	LL ans = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] <= B[i]) {
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;
			int res = min(A[i + 1], B[i]);
			ans += res;
			A[i + 1] -= res;
			B[i] -= res;
		}
		else {
			int res = min(A[i], B[i]);//A[i]>B[i]
			ans += res;
			A[i] -= res;
			B[i] -= res;//B[i] = 0;
		}
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


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

int main()
{
  char S[5], T[5];
  int res=0;
  cin >> S;
  cin >> T;

  if(S[0]==T[0]) res++;
  if(S[1]==T[1]) res++;
  if(S[2]==T[2]) res++;
  
  cout << res << endl;
}

    


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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> c(h);
	for (auto&& s : c) cin >> s;
	bool isValid = true;
	for (int i = 0; i < h && isValid; i++)
		for (int j = 0; j < w && isValid; j++)
			isValid = c[i][j] == '.' ||
				(i > 0 && c[i-1][j] == '#') ||
				(i < h-1 && c[i+1][j] == '#') ||
				(j > 0 && c[i][j-1] == '#') ||
				(j < w-1 && c[i][j+1] == '#');
	cout << (isValid ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n;
	vector<ll> d(n);
	map<ll, int> mp;
	rep(i, n) {
		cin >> d[i];
		mp[d[i]]++;
	}
	sort(all(d));
	cin >> m;
	vector<ll> t(m);
	rep(i, m) cin >> t[i];
	bool elf = true;
	rep(i, m) {
		if (mp[t[i]] == 0) elf = false;
		else {
			mp[t[i]]--;
		}
	}
	cout << (elf ? "YES" : "NO") << endl;
	return 0;
}


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

int main(){
    int N;
    vector<int> d(110);
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> d.at(i);
    }
    sort(d.begin(), d.end(), greater<int>());
    int ans = N;
    for (int i = 0; i < N; i++)
    {
        if(d.at(i)==d.at(i+1)) {
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	r = int(input())
	print(r ** 2)
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 3700
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int n, a[200];
    cin >> n;
    int flag = 0, count = 0; 
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    do{
        for(int i=0;i<n;i++){
            if(a[i]%2 == 0)
                a[i] = a[i]/2;
            else
                flag = 1;
        }
        if(flag == 0)
            count++;
    }while(flag == 0);
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int( input())
    for x in range(1,3501):
        for y in range(1, 3501):
            if 4*x*y <= N*(x+y):
                continue
            if N*x*y%(4*x*y-N*(x+y)) == 0:
                print(x, y, N*x*y//(4*x*y-N*(x+y)))
                return
if __name__ == '__main__':
    main()


Measured memory_bytes: 39024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a < b && b < c) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26248