akhauriyash/Code-Regression huggingface dataset:
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 3005

//Solution

string s,t,ans;
int dp[N][N];

int f(int i, int j){
    if(i < 0 || j < 0) return 0;
    int &ret = dp[i][j];
    if(~ret) return ret;
    if(s[i] == t[j]) return ret = f(i-1,j-1)+1;
    return ret = max(f(i-1,j),f(i,j-1));
}

void getString(int i, int j){
    if(i < 0 || j < 0) return;
    if(s[i] == t[j]) ans.pb(s[i]), getString(i-1,j-1);
    else if(f(i-1,j) > f(i,j-1)) getString(i-1,j);
    else getString(i,j-1);
}

void solve(){
    cin>>s>>t;
    int n = sz(s), m = sz(t);
    memset(dp,-1,sizeof(dp));
    getString(n-1,m-1);
    reverse(all(ans));
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 74476
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, XS):
    cash = 1000
    stock = 0
    for i in range(N - 1):
        price = XS[i]
        if cash >= price:
            if XS[i + 1] > price:
                # buy
                s = cash // price
                stock += s
                cash -= s * price
                continue
        if stock > 0:
            if XS[i + 1] < price:
                # sell
                cash += stock * price
                stock = 0
    # last day
    cash += stock * XS[-1]
    return cash


def main():
    # parse input
    N = int(input())
    XS = list(map(int, input().split()))
    print(solve(N, XS))


# tests
T1 = """
7
100 130 130 130 115 115 150
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
1685
"""

T2 = """
6
200 180 160 140 120 100
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
1000
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 62272
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <iomanip>
#include<cmath>
#include<stdio.h>
#include<map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
#define please return
constexpr auto AC = 0;
using namespace std;
int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int ans = min(a * b, c);
	cout << ans << endl;
	


		please AC;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 101010

int main()
{
    int n;
    cin >> n;
    vector<int> f(INF);
    rep(i,n+1)f[i]=0;
    FOR(i,sqrt(n)+1,1){
        FOR(j,sqrt(n)+1,1){
            FOR(k,sqrt(n)+1,1){
                f[i*i+j*j+k*k+i*j+j*k+k*i]++;
            }
        }
    }
    FOR(i,n+1,1){
        cout << f[i] << endl;
    }
}

Measured memory_bytes: 3660
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int sub(llong a, int b, int MOD) {
   int res = ((a % MOD) - (b % MOD) + MOD) % MOD;
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N, K;
   cin >> N >> K;
   VI A(N+1);
   FOR(i, 1, N)
      cin >> A[i];

   //K = min(K, N+10);

   vector<llong> prefix_sum(N+1);
   FOR(n, 1, N)
      prefix_sum[n] = prefix_sum[n-1] + A[n];

   //FOR(n, 1, N)
   //   cerr << prefix_sum[n] << ' ';
   //cerr << endl;

   map<int,int> freq;
   freq[0] = 1;

   long long res = 0;
   for (int n = 1; n <= N; ++n) {
      int j = n - K;
      if (j >= 0) {
         --freq[ sub(prefix_sum[j], j, K) ];
      }

      int t = sub(prefix_sum[n], n, K);

   // cerr << "n: " << n << "  t: " << t << "  freq: " << freq[t] << endl;
      res += freq[t];

      ++freq[t];
   }
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 12032
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int d = sc.nextInt();
		int n = sc.nextInt();
		
		// 計算
		int result = 0;
		result = (int)pow(100, d) * n;
		if(n == 100) result += (int)pow(100, d);
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23764
struct Rin{}
impl Rin{
    fn input(&self)->String{
        let mut x=String::new();
        std::io::stdin().read_line(&mut x).ok();
        x
    }
    fn inputs(&self)->String{
        let s=self.input().trim().to_string();
        s
    }
    fn inputn(&self)->i32{
        let n:i32=self.input().trim().parse().unwrap();
        n
    }
    fn inputvs(&self)->Vec<String>{
        let vs=self.input().trim().split(' ').map(|x|x.to_string()).collect();
        vs
    }
    fn inputvn(&self)->Vec<i32>{
        let vn=self.input().trim().split(' ').map(|x|x.to_string().parse().unwrap()).collect();
        vn
    }
}

fn main(){
    let rin=Rin{};
    let v=rin.inputvn();
    let a=v[0]; let b=v[1]; let c=v[2]; let mut k=v[3];
    let mut ans=0;
    if a>=k{
        println!("{}",k);
    }else if a+b>=k{
        println!("{}",a);
    }else{
        println!("{}",a-(k-a-b));
    }
}

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

int main() {

	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0)
			ans++;

	}
		cout << ans << "\n";
		
	

}

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

#define ll long long int
const ll mod=1e9+7;
char ch[]={'A','C','G','T','L'};
string tar="AGC";

ll dp[110][10][10][10];
ll n;

bool check(int first,int sec,int th,int fr)
{
    string str=string(1,ch[first])+string(1,ch[sec])+string(1,ch[th])+string(1,ch[fr]);
    string temp=str;
    if(temp.substr(0,3)==tar || temp.substr(1,3)==tar) return false;

    swap(temp[0],temp[1]);
    if(temp.substr(0,3)==tar || temp.substr(1,3)==tar) return false;

    temp=str;
    swap(temp[1],temp[2]);
    if(temp.substr(0,3)==tar || temp.substr(1,3)==tar) return false;

    temp=str;
    swap(temp[2],temp[3]);
    if(temp.substr(0,3)==tar || temp.substr(1,3)==tar) return false;

    return true;
}

ll cholo(ll id, ll first,ll mid,ll last)
{
    if(id>=n) return 1ll;

    ll &ret=dp[id][first][mid][last];
    if(~ret) return ret;

    ll sum=0;
    for(ll i=0;i<4;i++){
        if(check(first,mid,last,i)) sum=(sum + cholo(id+1,mid,last,i))%mod;
    }
    return (ret=sum);
}

int main()
{
    cin>>n;
    memset(dp,-1,sizeof dp);
    ll ans=cholo(0,4,4,4);
    cout<<ans<<'\n';
}

//ATGC


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

#define f(i,x,y)			for(int i=x; i<y; i++)
#define ll 					long long 
#define pb 					push_back
#define mp 					make_pair
#define F 					first
#define S 					second
#define N 					100005
#define mod 				1000000007

int n;
int dp[N][2];
vector <vector <int> > t(N);

ll func(int s, int i, int pr)
{
	
	if(dp[s][i] != -1)
		return dp[s][i];

	ll ans = 0;

	ll w1 = 1;
	for(auto x : t[s])
	{
		if(x != pr)
		{
			w1 = ((w1%mod) * (func(x,0,s)%mod))%mod;
		}
	}
	ans = w1%mod;
	if(i==0)
	{
		ll w2 = 1;
		for(auto x : t[s])
		{
			if(x != pr)
			{
				w2 = ((w2%mod) * (func(x,1,s))%mod);
			}
		}
		ans = (ans+w2)%mod;
	}
	return dp[s][i] = ans;
}

int main()
{
	cin>>n;
	memset(dp,-1,sizeof(dp));
	//dp[0] =1;
	f(i,0,n-1)
	{
		int a,b;
		cin>>a>>b;
		t[a].pb(b);
		t[b].pb(a);
	}

cout<<(func(1,0,-1))%mod;

return 0;
}

Measured memory_bytes: 14848
/*
	---------O7Oo7oO7O-------------
*/

#include <bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
#define all(v) v.begin(),v.end()

const int mod = 1000 * 1000 * 1000 + 7;

const int mxN = 2e5 + 5;

int parent[mxN], sz[mxN], a[mxN];

void init()
{
	for (int i = 0; i < mxN; i++)
	{
		parent[i] = i;
		sz[i] = 1;
	}
}

int find(int v)
{
	if (v == parent[v])
		return v;
	else
		return parent[v] = find(parent[v]);
}


void Union(int a, int b)
{
	int x = find(a);
	int y = find(b);

	if (x != y)
	{
		if (sz[x] < sz[y])
			swap(x, y);

		parent[y] = x;
		sz[x] += sz[y];


	}
}
int Bin_expo(int n, int b)
{
	int res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * n) % mod;

		}
		n = (n * n)  % mod;


		b /= 2;

	}
	return res % mod;
}


int32_t main()
{
	IOS

	int n, m;
	cin >> n >> m;
	init();
	int mx = 0;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		Union(a, b);

	}

	for (int i = 1; i <= n; i++)
		mx = max(mx, sz[i]);

	cout << mx << "\n";



	return 0;
}




Measured memory_bytes: 6788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,ans,cnt,sum;
  while(cin >> a >> b){
    if(a==0 and b==0){
      break;
    }
    ans=0;
    for(int i0=0;i0<2;i0++){
      for(int i1=0;i1<2;i1++){
        for(int i2=0;i2<2;i2++){
          for(int i3=0;i3<2;i3++){
            for(int i4=0;i4<2;i4++){
              for(int i5=0;i5<2;i5++){
                for(int i6=0;i6<2;i6++){
                  for(int i7=0;i7<2;i7++){
                    for(int i8=0;i8<2;i8++){
                      for(int i9=0;i9<2;i9++){
                        cnt=i0+i1+i2+i3+i4+i5+i6+i7+i8+i9;
                        sum=i1*1+i2*2+i3*3+i4*4+i5*5+i6*6+i7*7+i8*8+i9*9;
                        if(cnt==a and sum==b){
                          ans++;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

int main() 
{
    int n, m;
    cin >> n >> m;
    map<int, priority_queue<pair<int,int>>> mp;
    rep(i,m) {
        int p, y;
        cin >> p >> y;
        mp[p].emplace(-y, i);
    }

    vector<pair<int, int>> V(m); // <p,x>
    for (auto v : mp) {
        int p = v.first;
        auto Q = v.second;
        int x = 1;
        while(!Q.empty()) {
            auto pir = Q.top(); Q.pop();
            V[pir.second] = make_pair(p, x);
            x++;
        }
    }

    rep(i,m) {
        printf("%06d%06d\n", V[i].first, V[i].second);
    }

    
    
    return 0;
}


Measured memory_bytes: 13184
N=int(input())
ans=0

A=list(map(int,input().split()))
zentai=sum(A)
ruiseki_WA=[]
kasu=0
for i in range(N):
    kasu+=A[i]
    ruiseki_WA.append(kasu)
hako=sum(A)
for i in range(N):
    ans+=A[i]*(hako-ruiseki_WA[i])   
print(ans%(10**9+7)) 

Measured memory_bytes: 101540
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

char lower(char c){
    if(c == 'A'){
        return 'a';
    } else if(c == 'B'){
        return 'b';
    } 
    return 'c';
}
int main(){
    int N;
    int K;
    string S;
    cin >> N >> K;
    cin >> S;
    S[K - 1] = lower(S[K - 1]);
    cout << S << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const ll INF = 1000000000000000000;

ll pwr (ll a, int b)
{
    if(b == 0)
        return 1;
    if(b & 1)
    {
        ll aux = pwr(a, (b ^ 1));
        if(INF / aux < a)
            return INF;
        return aux * a;
    }
    ll aux = pwr(a, (b >> 1));
    if(INF / aux < aux)
        return INF;
    return aux * aux;
}

ll n;

vector <ll> vd;

void fd (ll x)
{
    vd.clear();
    for(ll i = 1; i * i <= x; i++)
        if(x % i == 0)
        {
            vd.push_back(i);
            if(i * i != x)
                vd.push_back(x / i);
        }
    sort(vd.begin(), vd.end());
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    ll ans = 0;
    fd(n - 1);
    ans += vd.size() - 1;
    fd(n);
    for(ll d : vd)
    {
        if(d == 1)
            continue;
        int l = 0, r = 40;
        while(l < r)
        {
            int mid = ((l + r + 1) >> 1);
            if(n % pwr(d, mid) != 0)
                r = mid - 1;
            else
                l = mid;
        }
        if((n / pwr(d, l) - 1) % d == 0 && (n - 1) % d != 0)
            ans++;
    }
    cout << ans << "\n";
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#define rep(i, j, n) for (int i = (j); i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; i >= (j); --i)
using namespace std;
using ll = long long;
constexpr int INF = 1 << 30;

int dist[808][808];

int main()
{
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> a(h);
  rep(i, 0, h) cin >> a[i];

  int sx, sy;
  rep(i, 0, h) rep(j, 0, w)
  {
    if (a[i][j] == 'S')
    {
      sx = j, sy = i;
    }
    dist[i][j] = INF;
  }

  dist[sy][sx] = 0;
  queue<pair<int, int>> q;
  q.emplace(sy, sx);
  int dx[4] = {0, -1, 1, 0};
  int dy[4] = {1, 0, 0, -1};
  while (q.size())
  {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    rep(i, 0, 4)
    {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (0 <= ny && ny < h && 0 <= nx && nx < w && dist[ny][nx] == INF && a[ny][nx] == '.')
      {
        dist[ny][nx] = dist[y][x] + 1;
        q.emplace(ny, nx);
      }
    }
  }

  // 2
  rep(i, 0, h) rep(j, 0, w)
  {
    if (dist[i][j] <= k)
      dist[i][j] = 0;
    if (dist[i][j] == 0)
      q.emplace(i, j);
  }
  while (q.size())
  {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    rep(i, 0, 4)
    {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (0 <= ny && ny < h && 0 <= nx && nx < w && dist[ny][nx] > dist[y][x] + 1)
      {
        dist[ny][nx] = dist[y][x] + 1;
        q.emplace(ny, nx);
      }
    }
  }

  int ans = INF;
  rep(i, 0, h) ans = min(ans, min(dist[i][0], dist[i][w - 1]));
  rep(i, 0, w) ans = min(ans, min(dist[0][i], dist[h - 1][i]));

  cout << (ans + k - 1) / k + 1;
  return 0;
}


Measured memory_bytes: 11996
using System;

namespace abc088A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int A = int.Parse(Console.ReadLine());
            int B = N % 500;
            if (B <= A)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
from pprint import pprint
n=int(input())
a=[int(i) for i in input().split()]
d={}
cnt=0
for i in a:
    if str(i) not in d:
        d[str(i)]=1
    else:
        d[str(i)]+=1
for i in d:
    if int(i)>d[i]:
        cnt+=d[i]
    else:
        if int(i)<d[i]:
            cnt+=d[i]-int(i)
print(cnt)


Measured memory_bytes: 23964
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct UnionFind{
  Int n,num;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),num(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    num--;
  }
  Int size(Int x){
    return r[find(x)];
  }
  Int count() const{
    return num;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,r;
  cin>>n>>r;
  vector<Int> ps(n);
  for(Int i=0;i<n;i++) cin>>ps[i],ps[i]--;

  UnionFind uf(n);
  for(Int i=0;i<n;i++) uf.unite(i,ps[i]);

  vector<Int> vs;
  for(Int i=0;i<n;i++)
    if(uf.find(i)==i) vs.emplace_back(uf.size(i));

  const Int BS = 600;
  vector<Int> cnt(BS,0);
  for(Int v:vs)
    if(v<BS) cnt[v]++;

  vector<Int> dp(n+1,0);
  dp[0]=1;
  for(Int w=1;w<BS;w++){
    vector<Int> nx(n+1,-1);
    for(Int i=0;i<=n;i++){
      if(dp[i]) chmax(nx[i],cnt[w]);
      if(nx[i]>0&&i+w<=n) chmax(nx[i+w],nx[i]-1);
    }
    for(Int i=0;i<=n;i++) dp[i]=nx[i]>=0;
  }

  for(Int v:vs){
    if(v<BS) continue;
    for(Int i=n;i>=0;i--)
      if(i+v<=n) dp[i+v]|=dp[i];
  }

  cout<<(dp[r]?"Yes":"No")<<endl;
  return 0;
}



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

using namespace std;

int main(){
	char a[10000];
	cin>>a;
	if(a[0]==a[1] && a[1]==a[2])
	{
		cout<<"Yes";
		return 0;
	}
	if(a[2]==a[3] && a[1]==a[2])
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  int four = 0, two = 0;
  rep(i, N) {
    if(!(a[i]%4))
      four++;
    else if(!(a[i]%2))
      two++;
  }
  int rem = N-four*2;
  if(rem <= 1) {
    cout << "Yes" << endl;
    return 0;
  }
  rem -= two;
  if(rem <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,m,xx;
int mi=100000000;
vector<int> v;
int c[15],a[15][15];
void dfs(){
	if(v.size()==n){
		int k[m+1],s=0;
		memset(k,0,sizeof(k));
		for(int i=1;i<=v.size();i++){
			if(v[i-1]==1){
				for(int j=1;j<=m;j++){
					k[j]+=a[i][j];
				}
				s+=c[i];
			}
		}
		//cout<<endl;
		int f=1;
		for(int i=1;i<=m;i++){
			if(k[i]<xx){
				f=0;
			}
		}
		if(f){
			mi=min(mi,s);
		}
	}else{
		v.push_back(0);
		dfs();
		v.pop_back();
		v.push_back(1);
		dfs();
		v.pop_back();
	}
}
int main(){
	cin>>n>>m>>xx;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}	
	dfs();
	cout<<(mi>10000000?-1:mi)<<endl;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
 
const int L = 14;
const int M = 1046527;
char H[M][L]; /* Hash Table */ int getChar(char ch) {
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G')return 3; else if (ch == 'T') return 4;
} /* convert a string into an integer value */
long long getKey(char str[]) {
    long long sum = 0, p = 1, i;
    for (i = 0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}
 
int h1(int key) { return key % M; }
 
int h2(int key) { return 1 + (key % (M - 1)); }
 
int find(char str[]) {
    long long key, i = 0;
    key = getKey(str);
    while (1) {
        int h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1; else if (strlen(H[h]) == 0) return 0;
        i++;
    }
    return 0;
}
 
void insert(char str[]) {
    long long i = 0, key;
    key = getKey(str);
    while (1) {
        int h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return;
        else if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return;
        }
        i++;
    }
    return;
}
 
int main() {
    int i, n;
    char str[L], com[9];
    for (i = 0; i < M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf(" %s %s", com, str);
        if (com[0] == 'i') { insert(str); } else { if (find(str)) { printf("yes\n"); } else { printf("no\n"); }}
    }
    return 0;
}


Measured memory_bytes: 16992
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 200005;

vector<int> g[N];
int cnt[N];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  queue<pair<int, int>> q;
  int sz = g[1].size();
  for (int i = 0; i < sz; i++) q.push({g[1][i], 1});
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    if (cnt[p.first] == 0) {
      cnt[p.first] = p.second;
      sz = g[p.first].size();
      for (int i = 0; i < sz; i++) {
        q.push({g[p.first][i], p.first});
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (cnt[i] == 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++) cout << cnt[i] << endl;
  return 0;
}

Measured memory_bytes: 20040
import math
def solve():
  n,a,b,c,d = (int(i) for i in input().split())
  if a > b: a,b = b,a
  ans = 'NO'
  for i in range(n):
    if a+ i*c -(n-i-1)*d <= b <= a + i * d - (n - i - 1) * c:
     ans ='YES'
  return ans
if __name__ == '__main__':
  print(solve())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3,ans;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;
//void swap(ll *x,ll *y){
//  ll z = *x;
//  *x = *y;
//  *y = z;
//}
//ll gcd(ll x,ll y){
//  if(y == 0){
//    return x;
//  }
//  return gcd(y,x%y);
//}
int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  sort(all(vec));
  ll sum = 0;
  rep(i,n){
    REP(j,i+1,n){
      auto Iter1 = lower_bound(all(vec), vec[i] + vec[j]);
      tmp1 = (ll)(Iter1 - vec.begin());
      //cout << Iter1 - vec.begin();
      //cout << max((ll)0,tmp1-j-1);
      sum += max((ll)0,tmp1-j-1);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[111][111],n,L[111],R[111];

int dfs(int l,int r){
	if(dp[l][r]!=-1)return dp[l][r];
	int res=1e9;
	for(int i=l;i<r;i++){
		res=min(res,dfs(l,i)+dfs(i+1,r)+L[l]*R[i]*R[r]);
	}
	return dp[l][r]=res;
}

signed main(){
	memset(dp,-1,sizeof(dp));
	r(i,111)dp[i][i]=0;
	cin>>n;
	r(i,n)cin>>L[i]>>R[i];
	cout<<dfs(0,n-1)<<endl;
}


Measured memory_bytes: 3164
if __name__ == '__main__':
    n = int(input())
    w = list(map(int, input().split()))

    a = w[0]
    b = sum(w) - a

    result = 1000000
    for i in range(1, n):
        a += w[i]
        b -= w[i]
        result = min(result, abs(a-b))

    print(result)


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

int eight[5] = {105, 135, 165, 189, 195};

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    if(n >=105) cnt++;
    if(n >= 135) cnt++;
    if(n >= 189) cnt++;
    if(n >= 165) cnt++;
    if(n >= 195) cnt++;
    cout << cnt << endl;
    return 0;
 }





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int N, L;

int main() {
    cin >> N >> L;
    int left = L;
    int right = N + L - 1;

    int eat;
    if (right <= 0) eat = right;
    else if (left >= 0) eat = left;
    else eat = 0;

    int ans = (right * (right + 1) - left * (left - 1)) / 2 - eat;
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
m = [[0] * 3 for i in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    m[i][0] = a + b
    m[i][1] = a
    m[i][2] = b

m.sort(reverse=True)

takahashi = 0
aoki = 0

for i in range(n):
    if i % 2 == 0:
        takahashi += m[i][1]
    else:
        aoki += m[i][2]

print(takahashi - aoki)

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

int main() {
  int N, L[100];
  cin >> N;
  rep(i,N) cin >> L[i];
  sort(L,L+N);
  
  int MAX = L[N-1];
  int SUM = 0;
  rep(i,N-1) SUM += L[i];
  cout << (MAX < SUM ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    int k , a , b; cin >> k >> a >> b;
    int flag = 0;
    for (int i = a ; i <= b ; i++)
        if (i % k == 0){
            flag = 1;
            break;
        }
    if (flag) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3652
a = [int(input()) for i in range(10)]
b=[]
b=sorted(a, reverse=True)[:3]
print(b[0]+b[1]+b[2],end=' ')
c= [int(input()) for i in range(10)]
d=[]
d=sorted(c, reverse=True)[:3]
print(d[0]+d[1]+d[2])


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

int n,k,m,a,b,c,d;
string s;

int main() {
  cin >> a >> b >> c;
  cout << (a==b && c==a? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//Awwawa! Dis cold yis ratten buy waxberry!
#include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll c[55][55];
ll sum[55];
int n, k, s, t;
int a[maxn];
int qr[300005];
int ns[300005];
int id[maxn];
int main() {
	for (int i = 0; i < 55; i++)
		for (int j = 0; j <= i; j++) {
			if (j == 0 || j == i) c[i][j] = 1;
			else c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	cin >> n >> k >> s >> t;
	for (int i = 0; i <= n; i++) {
		sum[i] = 0;
		for (int j = 1; j <= k; j++)
			sum[i] += c[i][j];
	}
	int cnt = 0;
	while (n--) {
		int r;
		scanf("%d", &r);
		if ((r & s) == s && ((t & r) == r)) a[++cnt] = r;
	}
	ll ans = 0;
	int dv = (t ^ s);
	for (int l = dv; 1; l = (l - 1) & dv) {
		int df = 1;
		for (int j = 0; j < 18; j++)
			if (l & (1 << j)) df *= -1;
		for (int i = 1; i <= cnt; i++) {
			qr[a[i] & l]++;
			id[i] = qr[a[i] & l];
		}
		for (int i = 1; i <= cnt; i++) {
			int p = qr[a[i] & l];
			if (p == id[i]) ans += df * sum[p];
		}
		for (int i = 1; i <= cnt; i++)
			qr[a[i] & l] = 0;
		if (l == 0) break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4824
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
  int A,B,C; cin >> A >> B >> C;
  if(A == B && B == C && A%2==0 && B%2==0 && C%2==0){
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  rep(i,100000000){
    if(A&1 | B&1 | C&1) break;
    int a = A,b = B,c = C;
    A = (b+c)/2;
    B = (c+a)/2;
    C = (a+b)/2;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
K, S = map(int, input().split())
ans = 0
for Z in range(K+1):
  r = S - Z
  if r < 0:
    ans += 0
  elif r <= K:
    ans += r+1
  elif r <= K*2:
    ans += (K+1)*2 - (r+1)
print(ans)

Measured memory_bytes: 3060
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Measured memory_bytes: 41648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

int n, k, d[100];
set<int> se;

int main(){
  cin >> n >> k;
  rep(i, k){
    int d;
    cin >> d;
    rep(j, d){
      int u;
      cin >> u;
      se.insert(u);
    }
  }
  cout << n - se.size()<<endl;
}
    

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

int main(){
    int n,q;
    cin>>n>>q;
    vector<vector<int> > a(n);
    while(q--){
        int y;
        cin>>y;
        if(y==0){
            int t,x;
            cin>>t>>x;
            a[t].push_back(x);
        }
        else if(y==1){
            int t;
            cin>>t;
            for(auto it=a[t].begin();it!=a[t].end();it++){
                if(it!=a[t].begin())cout<<" ";
                cout<<*it;
            }
            cout<<endl;
        }
        else{
            int t;
            cin>>t;
            a[t].clear();
        }
    }
    return 0;
}


Measured memory_bytes: 5780
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a=0,b=0,tmp;
	for(int i=0;i<4;i++){
		cin>>tmp;
		a+=tmp;
	}
	for(int i=0;i<4;i++){
		cin>>tmp;
		b+=tmp;
	}
	cout<<max(a,b)<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
#define pii pair<int,int>
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> data(int(1e5+2));
    fill(All(data),0LL);
    ll now = 0;
    rep(i,n){
        data[a[i]]++;
        now+=a[i];
    }
    int q;
    cin >> q;

    rep(i,q){
        int b,c;
        cin >> b >> c;
        now += (c-b)*(data[b]);
        cout << now << endl;
        data[c]+=data[b];
        data[b]=0;

    }
}

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

int main(){
  int n;
  string s;
  cin>>n>>s;
  vector<int> black(n+1);
  vector<int> white(n+1);
  black[0]=0; white[0]=0;
  rep(i,n){
    if(s[i]=='#'){
      black[i+1]=black[i]+1;
      white[i+1]=white[i];
    }
    if(s[i]=='.'){
      black[i+1]=black[i];
      white[i+1]=white[i]+1;
    }
  }
  int ans=INT_MAX;
  rep(i,n+1){
    int now = black[i]-black[0] + white[n]-white[i];
    ans=min(ans,now); 
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 5216
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint choose(ll n, ll k) {
  mint x = 1, y = 1;
  for(ll i=0; i<k; i++) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

void solve(long long n, long long a, long long b){
  mint ans = mint(2).pow(n)-1;
  ans -= choose(n, a);
  ans -= choose(n, b);
  std::cout << ans.x  << std::endl;
}

int main(){
  long long n;
  scanf("%lld",&n);
  long long a;
  scanf("%lld",&a);
  long long b;
  scanf("%lld",&b);
  solve(n, a, b);
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int h, w; cin >> h >> w;
  vector<vector<char> > a(h, vector<char>(w));
  REP(i, h) REP(j, w) cin >> a[i][j];

  REP(i, a.size()) {
    bool white = true;
    REP(j, w) {
      if (a[i][j] == '#') {
        white = false;
        break;
      }
    }
    if (white) {
      a.erase(a.begin() + i);
      --i;
    }
  }
  REP(j, a[0].size()) {
    bool white = true;
    REP(i, a.size()) {
      if (a[i][j] == '#') {
        white = false;
        break;
      }
    }
    if (white) {
      REP(i, a.size()) a[i].erase(a[i].begin() + j);
      --j;
    }
  }

  REP(i, a.size()) {
    REP(j, a[i].size()) {
      cout << a[i][j];
    }
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[4];
		for(int i = 0; i < str.length; i++) {
			str[i] = sc.nextLine();
		}
		sc.close();
		int lenSort = Integer.parseInt(str[0]);
		int[] sorted = stringToIntArray(str[1], lenSort);
		int lenUn = Integer.parseInt(str[2]);
		int[] unsorted = stringToIntArray(str[3], lenUn);
		if (sortedCheck(sorted)) {
			int n = 0;
			for(int u: unsorted) {
				if (binarySearch(sorted, u, 0, sorted.length - 1) > 0) {
					n++;
				}
			}
			System.out.println(n);
		}
	}
	
	public static boolean sortedCheck(int[] nums) {
		int n = nums[0];
		for(int i: nums) {
			if(n <= i) {
				n = i;
			}
			else return false;
		}
		return true;
	}
	
	public static int[] stringToIntArray(String str, int len) {
		String[] strings = str.split(" ", len);
		int[] nums = new int[strings.length];
		for(int i = 0; i < strings.length; i++) {
			nums[i] = Integer.parseInt(strings[i]);
		}
		return nums;
	}
	
	public static int binarySearch(int[] sorted, int x, int start, int end) {
		if (start <= end) {
			int mid = (start + end) / 2;
			if (sorted[mid] == x)
				return 1;
			else if (sorted[mid] > x)
				return binarySearch(sorted, x, start, mid - 1);
			else
				return binarySearch(sorted, x, mid + 1, end);
		}
		return -1;
	}
}



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

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

typedef pair<ll,ll> pll;

int main(){
    ll A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
    pll res = pll(0,A*100);
    for(ll a = 0; a <= F; a+=100*A){
        for(ll b = 0; a + b <= F; b+=100*B){
            ll water = a + b;
            ll maxsugar = min(F-water,E*(water/100));
            //cout << res.first << " res " << res.second << endl;
            //cout << "a: "<< a << " b: " << b << endl;
            //cout << "water " << water << endl;
            //cout << "maxsugar " << maxsugar << endl;
            for(ll c = 0; c <= maxsugar; c+=C){
                for(ll d = 0; c + d <= maxsugar; d+=D){
                    ll sugar = c + d;
                    //cout << sugar << " water" << water << endl;
                    pll tmp = pll(sugar,water);
                    //cout << tmp.first << " tmp " << tmp.second << endl;
                    if(res.first*(tmp.first+tmp.second) < tmp.first*(res.first+res.second)){
                        res = tmp;
                        //cout << "yaaaaaa" << endl;
                    }
                }
            }
        }
    }
    cout << res.first+res.second << " " << res.first << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i = 0; i < N; i++){
    cin >> P[i];
  }
  int minP = P[0];
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(P[i] <= minP){
      cnt++;
      minP = P[i];
    }
  }
  cout << cnt << endl;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;


vector<ll> A(1010),B(1010),C(1010);



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


	int n,m;cin>>n>>m;

	map<ll,ll> mp;

	rep(i,n){
		ll a,b;cin>>a>>b;

		mp[a] +=b;
	}

	ll ans =0;
	for(auto e : mp){

		ll mi = min((ll)e.second, (ll)m);

		m -=mi;

		ans += e.first*mi;

		if(m ==0)break;
	}

	writeln(ans);

}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	int x; cin>>x;
	int ans=0;
	int sum=0;
	for(int i=1; i<=n; i++) {
		int a;
		cin>>a;
		sum+=a;
		if(sum>x) {
			break;
		}
		ans=i;
	}
	ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, T, ans = INF;
    cin >> N >> T;
    for(int i = 0; i < N; i++) {
        int c, t;
        cin >> c >> t;
        if(T >= t) {
            ans = min(ans, c);
        }
    }
    if(ans != INF) {
        cout << ans << endl;
    } else {
        cout << "TLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli N,A;
  cin >> N;
  vector<lli>P(5);
  rep(i,5)cin >> P[i];
  Sort(P);
  if(N%P[0]==0)A=N/P[0]+4;
  else A=N/P[0]+5;
  Out(A);
}


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

public class Main {
	
	static final char[][] tres = {"<>^".toCharArray(),
			"^.v".toCharArray(),
			"v<>".toCharArray()};
	
	static char[][] ret;
	
	static void putV(int i, int j) {
		ret[i][j] = '^';
		ret[i+1][j] = 'v';
	}
	
	static void putH(int i, int j) {
		ret[i][j] = '<';
		ret[i][j+1] = '>';
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		int M = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		ret = new char[N][M];
		for (int i = 0; i < ret.length; i++) {
			Arrays.fill(ret[i], '.');
		}
		if (N % 2 == 1) {
			int to = M;
			if (M % 2 == 1 && N >= 3 && M >= 3) to -= 3;
			for (int j = 0; A > 0 && j + 1 < to; j+= 2) {
				A--;
				putH(N-1, j);
			}
		}
		if (M % 2 == 1) {
			int to = N;
			if (N % 2 == 1 && N >= 3 && M >= 3) to -= 3;
			for (int i = 0; B > 0 && i + 1 < to; i+= 2) {
				B--;
				putV(i, M - 1);
			}
		}
		boolean special = N%2 == 1 && M %2 == 1 && N >= 3 && M >= 3;
		for (int i = 0; i + 1 < N; i+=2) {
			for (int j = 0; j + 1 < M; j+=2) if (!special || i + 3 < N || j + 3 < M) {
				if (A > B) {
					putH(i,j);
					A--;
					if (A > 0) {
						putH(i+1,j);
						A--;
					}
				} else {
					if (B > 0) {
						putV(i,j);
						B--;
					}
					if (B > 0) {
						putV(i,j+1);
						B--;
					}
				}
			}
		}
		if (N%2 == 1 && M %2 == 1 && N >= 3 && M >= 3) {
			if (A == 2 && B == 2) {
				A = B = 0;
				for (int i = 0; i < 3; i++) {
					for (int j = 0; j < 3; j++) {
						ret[N - 3 + i][M - 3 + j] = tres[i][j];
					}
				}
			}
			if (A > 0) {
				putH(N-1, M-3);
				A--;
			}
			if (B > 0) {
				putV(N-3, M-1);
				B--;
			}
			if (A > 0) {
				putH(N-3, M-3);
				A--;
				if (A > 0) {
					putH(N-2, M-3);
					A--;
				}
			} else if (B > 0) {
				putV(N-3, M-3);
				B--;
				if (B > 0) {
					putV(N-3, M-2);
					B--;
				}
			}
		}
		
		if (A + B > 0) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
			for (int i = 0; i < ret.length; i++) {
				System.out.println(new String(ret[i]));
			}
		}
	}
}


Measured memory_bytes: 28540
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
	ll n;
    ll k;
    cin >> n >> k;
    ll inp;
    vector<ll> a(n);
    vector<ll> perm(n);
    for(ll i = 0; i < n; i++){
        cin >> inp;
        a.at(i) = inp;
        if(i < n - k) perm.at(i) = 0;
        else perm.at(i) = 1;
    }

    ll ans = 20000000000 * n;
    do{
        vector<ll> dummy = a;
        ll sum = 0;
        for(ll i = 0; i < n; i++){
            if(perm.at(i) == 1 && i > 0){
                ll max = * max_element(dummy.begin(), dummy.begin() + i);
                if(dummy.at(i) <= max){
                    sum += max - dummy.at(i) + 1;
                    dummy.at(i) = max + 1;
                }
            } 
        }
        ans = min(ans, sum);
    }while(next_permutation(perm.begin(),perm.end()));
    

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


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

int main()
{
    long i,n,m[1000000],max,min,sum;
    i = 0;
    sum = 0;
    cin >> n;
    do
        {
            cin >> m[i];
            if (i == 0)
                {
                    max = m[i];
                    min = m[i];
                }
            else 
                {
                    if (max < m[i])
                        max = m[i];
                    if (min > m[i])
                        min = m[i];
                }

            sum = sum + m[i];
            ++i;
        }
    while (i < n);
    cout << min << " " << max << " " << sum << endl;
    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}


Measured memory_bytes: 3628