akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int64_t MOD = 1e9 + 7;

int64_t dpow(int64_t x, int64_t y)
{
    if (y == 0)
    {
        return 1;
    }
    if (y % 2 == 0)
    {
        return dpow(x * x % MOD, y / 2);
    }
    else
    {
        return x * dpow(x, y - 1) % MOD;
    }
}

int64_t inv(int64_t x)
{
    return dpow(x, MOD - 2);
}

vector<vector<int>> edge;
vector<int> size;
void dfs(int node, int parent)
{
    size[node] = 1;
    for (int e : edge[node])
    {
        if (e != parent)
        {
            dfs(e, node);
            size[node] += size[e];
        }
    }
}

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

    edge.resize(n);
    size.resize(n, 0);
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(0, 0);

    int64_t result = 0;
    rep(i, n)
    {
        int64_t prod = inv(dpow(2, n - 1));
        int64_t sum = 0;
        for (int e : edge[i])
        {
            int s = size[e];
            if (s > size[i])
            {
                s = n - size[i];
            }
            int64_t w = inv(dpow(2, s));
            sum += (1 - w + MOD) % MOD * inv(w) % MOD;
            sum %= MOD;
        }
        int64_t p0 = inv(dpow(2, n - 1));
        int64_t p1 = sum * prod % MOD;

        result += ((1 - p0 + MOD) % MOD - p1 + MOD) % MOD;
        result %= MOD;
    }
    result = result * inv(2) % MOD;
    cout << result << endl;

    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



int main(){
	cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    ll idx = 1;
    ll n; cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    REP(i,n){
        if (a[i] == idx) idx++;
        // cout << idx;
    }
    if (idx == 1) {
        cout << -1;
        return 0;
    }
    cout << n - idx + 1;
    return 0;
    
}



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

int main() 
{
  int n, t=1;
  long long count=1;
  cin >> n;
  vector<long> vec(n);
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
    if(vec.at(i)==0)t = 0;
  }
  if(t==1){
    for(int i = 0; i < n; i++){
      long long a=vec.at(i);
      if(count>1000000000000000000/a){t = -1; break;}
      count*=a;
      }
  }
  switch(t){
    case 1:
      cout << count << endl;
      break;
    case 0:
      cout << t <<endl;
      break;
    case -1:
      cout << t <<endl;
      break;
  }
}

Measured memory_bytes: 4008
#include <stdio.h>

int x(int a, int b, int op){
	int n, re;

	switch(op){
	case '+' : n = a + b; printf("%d\n", n); re = 0; break;
	case '-' : n = a - b; printf("%d\n", n); re = 0;break;
	case '*' : n = a * b; printf("%d\n", n); re = 0; break;
	case '/' : n = a / b; printf("%d\n", n); re = 0; break;
	case '?' : re = 1; break;
	}

	return re;
}

int main(void){
	int a, b, op, n, re;

	do{
	scanf("%d ", &a);
	op = getchar();
	scanf(" %d\n", &b);
	
	re = x(a, b, op);
	} while (re != 1);

	return 0;
}

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

using namespace std;
#define int long long
const int N = 1e5 + 10, MOD = 998244353;
int cnt[N];

int mul(int a, int b) {return (a * b) % MOD;}
int Pow(int a, int b)
{
    int r = 1;
    for (; b; b>>=1, a = mul(a, a)) if (b & 1) r = mul(r, a);
    return r;
}

int32_t main()
{
    int n, mx = 0; cin >> n;
    for (int i = 0; i < n; i ++) {
        int x; cin >> x;
        if (i == 0 && x != 0) return cout << 0, 0;
        cnt[x]++;
        mx = max(mx, x);
    }
    if (cnt[0] != 1) return cout << 0, 0;
    int ans = 1;
    for (int i = 1; i <= mx; i ++) {
        ans = mul(ans, Pow(cnt[i - 1], cnt[i]));
    }
    cout << ans << "\n";

    return 0;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll arr[15], a[15] ;
vector <ll> vec ;
vector <ll> v[15] ;

ll n, m, x, ans = 1E15 ;

void check(ll ind, ll target, ll cost) {
    if (target <= 0) {
        for (int i = 0; i < vec.size(); i++) {
            for (int j = 0; j < m; j++) {
                a[j] += v[vec[i]][j] ;
            }
        }
        ll flag = 0 ;
        for (int i = 0; i < m; i++) {
            if (a[i] < x) {
                flag = 1 ;
                break ;
            }
        }
        for (int i = 0; i < m; i++) {
            a[i] = 0 ;
        }
        if (!flag) {
            ans = min(ans, cost) ;
            return ;
        }
    }
    if (ind == 0)   return ;
    check(ind - 1, target, cost) ;
    vec.push_back(ind) ;
    check(ind - 1, target - v[ind][0], cost + arr[ind]) ;
    vec.pop_back() ;

    return ;
}

int main()
{
    ll c, u ;
    cin >> n >> m >> x ;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i] ;
        for (int j = 0; j < m; j++) {
            cin >> u ;
            v[i].push_back(u) ;
        }
    }

    check(n, x, a[n]) ;
    if (ans == 1E15)  cout << -1 ;
    else    cout << ans ;

    return 0 ;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const int INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N=IN,Y=IN;
    Y/=1000;
    REP(i,N+1) {
        REP(j,N+1) {
            int k=N-i-j;
            if(k<0) continue;
            int tmp=i+j*5+k*10;
            if(tmp==Y) {
                cout<<k<<" "<<j<<" "<<i<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 256
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define v vector
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
int INF = 1e9+7;
ll inf = 1e18+7;
int MOD = 1e9+7;

void add_self(auto &a, auto b){
	a += b;
	if(a >= MOD){
		a -= MOD;
	}
}

void max_self(auto &a, auto b){
	if(b > a)	a = b;
}

void topsort(int i, v<vi>& graph, vb& visit, stack<int>& res){
	visit[i] = true;
	
	for(int x : graph[i]){
		if(!visit[x])
		topsort(x,graph,visit,res);
	}
	res.push(i);
}

const int N = 100010;

bool dp[N];

void solve(){
	int n,k;
	scanf("%d%d",&n,&k);
	vi arr(n);
	for(int i = 0; i < n ; ++i){
		scanf("%d",&arr[i]);
	}
	sort(arr.begin(), arr.end());
	for(int left = 0; left <= k; ++left){
		for(int add : arr){
			if(add + left > k)	break;
			dp[add + left] = dp[add + left] || (!dp[left]);
		}
	}
	if(dp[k] == true){
		printf("First\n");
	}
	else{
		printf("Second\n");
	}
}	



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 3824
def main():
    from collections import deque, defaultdict
    n, *uvw = map(int, open(0).read().split())
    l = defaultdict(dict)
    g = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})
        l[v].update({u: w % 2})

    l[0].update({1: 0})

    vis = [False] * (n + 1)
    col = [0] * (n + 1)

    q = deque()
    q.append([0, 1, 0])

    while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[i][j] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

    ans = '\n'.join(map(str, col[1:]))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73448
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define PI 2*acos(0)
#define INF 1e18
#define mx 200005
using namespace std;
//const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,i,j,k,z,x,sum,cnt,ans;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];
    cnt=0;
    for(i=1;i<n;i++){
        if(a[i-1]>a[i]){
            z=a[i-1]-a[i];
            cnt+=z;
            a[i]+=z;
        }
    }
    cout<<cnt;
    return 0;
}
//1028C


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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int x1 = 0, x2 = w;
    int y1 = 0, y2 = h;
    rep(i, n) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            x1 = max(x1, x);
        }
        else if (a == 2) {
            x2 = min(x2, x);
        }
        else if (a == 3) {
            y1 = max(y1, y);
        }
        else {
            y2 = min(y2, y);
        }
    }

    int ans = max(x2 - x1, 0) * max(y2 - y1, 0);

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

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

using i64 = long long int;

int imos[100005]={0};

int main(){
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        if(a > b)swap(a, b);
        imos[a-1]++;
        imos[b-1]--;
    }

    int acc = 0;
    bool ok = true;
    for(int i=0;i<n;++i){
        acc += imos[i];
        if(acc%2){
            ok = false;
            break;
        }
    }

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


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

typedef long long lint;

int N, Q, D[100005];
lint T, A[100005];

void solve(int x) {
	int i = x + D[x];
	while (0 <= i && i < N && D[i] == D[x]) i += D[x];
	lint ans = A[x] + T * D[x];
	if ((D[x] == 1 && i < N) || (D[x] == -1 && 0 <= i)) {
		int li = (D[x] == -1 ? i : i-1), ri = (D[x] == -1 ? i+1 : i);
		lint L = A[li] + T, R = A[ri] - T;
		if (L > R) {
			lint C = A[li] + (A[ri] - A[li]) / 2;
			ans = (D[x] == -1 ? max(ans, C) : min(ans, C));
		}
	}
	cout << ans << endl;
}

int main() {
	cin >> N >> T >> Q;
	for (int i=0; i<N; ++i) {
		cin >> A[i] >> D[i];
		if (D[i] == 2) D[i] = -1;
	}
	
	for (int i=0; i<Q; ++i) {
		int x;
		cin >> x;
		--x;
		solve(x);
	}
}


Measured memory_bytes: 4264
S=input()
count=0
first=False
OK=False
memo=S[0]
for i in range(4):    
    if S[i]==S[0]:
        count+=1
    elif (S[i]!=S[0] and first==False):
        memo=S[i]
        first=True
    elif (S[i]!=S[0] and first==True):
        if S[i]==memo:
            OK=True


if (count==2 and OK==True):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'


string s;
int cnt;
char ch;
ll k;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> s >> k;

int n = s.size()-1;

rep(i, 0, n){
if(s[i]=='1')cnt++;
else { ch=s[i]; break;}
}

if(cnt>=k){
    cout << 1 << endl;
}
else cout << ch << endl;






return 0;}
///....


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, m, k, in, count = 0;
	unsigned int res = 0, filter;
	scanf("%d %d", &n, &m);
	for(int i = 0; i < m; i++)
		res |= 1 << i;

	for(int i = 0; i < n; i++){
		scanf("%d", &k);
		filter = 0;
		for(int j = 0; j < k; j++){
			scanf("%d", &in);
			filter |= (1 << (in - 1));
		}
		res &= filter;
	}
	for(int i = 0; i < m; i++)
		if(res & (1 << i))count++;
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
t = [1]*N
for i in range(M):
  f, e = list(map(int, input().split()))
  if H[f-1] < H[e-1]:
    t[f-1] -= 1
  elif H[f-1] > H[e-1]:
    t[e-1] -= 1
  else:
    t[f-1] -= 1
    t[e-1] -= 1
print(sum([1 for j in t if j == 1]))

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

#define int long long 

signed main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	for(int i=0;i<n;++i) cin >> w[i];

	int pre = 0;
	int suf = accumulate(w.begin(),w.end(),0LL);
	
	int ans = 1e18;
	for(int i=0;i<n;++i)
	{
		pre += w[i];
		suf -= w[i];
		ans = min(ans,abs(pre-suf));
	}
	
	cout << ans;
}



Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_2-C: Stable Sort

#include <cstring>
#include <algorithm>
#include <iostream>

struct Card {
  char suit;
  unsigned int rank;
};

static void print_cards(const Card cards[], const unsigned int n)
{
  const char* sep = "";
  for (unsigned int i = 0u; i < n; ++i) {
    const Card* const cardp = &cards[i];
    std::cout << sep << cardp->suit << cardp->rank;
    sep = " ";
  }
  std::cout << std::endl;
}

static void bubble_sort(Card cards[], const unsigned int n)
{
  for (unsigned int j = 0u; j < n-1; ++j) {
    for (unsigned int i = n-1; i > j; --i) {
      if (cards[i].rank < cards[i-1].rank) {
        std::swap(cards[i], cards[i-1]);
      }
    }
  }
}

static void selection_sort(Card cards[], const unsigned int n)
{
  for (unsigned int i = 0u; i < n-1; ++i) {
    unsigned int min_j = i;
    for (unsigned int j = i+1; j < n; ++j) {
      if (cards[j].rank < cards[min_j].rank) {
        min_j = j;
      }
    }
    if (i != min_j) {
      std::swap(cards[i], cards[min_j]);
    }
  }
}

int main()
{
  unsigned int n;
  std::cin >> n;
  Card cards1[n], cards2[n];
  for (unsigned int i = 0u; i < n; ++i) {
    std::cin >> cards1[i].suit;
    std::cin >> cards1[i].rank;
  }
  std::memcpy(cards2, cards1, sizeof(cards1));

  bubble_sort(cards1, n);
  print_cards(cards1, n);
  std::cout << "Stable" << std::endl; // bubble sort is stable

  selection_sort(cards2, n);
  print_cards(cards2, n);
  if (std::memcmp(cards1, cards2, sizeof(cards1)) == 0) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
}

// eof

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

//-------------------------------------------------
//--Union Find tree
//-------------------------------------------------
class UnionFind
{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;
public:
    UnionFind(int n):par(n),rank(n),sz(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        if (rank[rx]<rank[ry]){
            par[rx] = par[ry];
            sz[ry] += sz[rx];
        }else{
            par[ry] = par[rx];
            sz[rx] += sz[ry];
            if (rank[rx]==rank[ry]) rank[rx]++;
        }
    }
    int size(int x){
        return sz[root(x)];
    }
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi xtoi(N),ytoi(N),ytox(N);
    vi ys(N);
    rep(i,N){
        int x,y; cin>>x>>y; x--; y--;
        xtoi[x]=ytoi[y]=i;
        ytox[y]=x;
        ys[x]=y;
    }
    vector<bool> used(N);
    UnionFind uf(N);
    rep(y,N){
        if (used[y]) continue;
        int sz = ys.size();
        used[y]=true;
        FOR(i,ytox[y]+1,sz-1){
            if (y>ys[i]) break;
            used[ys[i]]=true;
            uf.unite(ytoi[y], ytoi[ys[i]]);
        }
        int Max = *max_element(ys.begin()+ytox[y],ys.end());
        ys.erase(ys.begin()+ytox[y],ys.end());
        ys.pb(Max);
    }
    rep(i,N){
        cout<<uf.size(i)<<endl;
    }
    return 0;
}


Measured memory_bytes: 8660
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;


int main() {
  int n; cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  sort(d.begin(),d.end());
  int ans = d[d.size()/2]-d[d.size()/2-1];
  cout << ans << endl;
  return 0;
}

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

int main() {
  string s;
  cin>>s;
  if(s[5]=='0'&&(s[6]=='1'||s[6]=='2'||s[6]=='3'||s[6]=='4')) cout<<"Heisei";
  else cout<<"TBD";
}

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

int main(){
    string s;
    cin >> s;
    string ans;
    for(int i = 0; i < s.size(); i++){
        if(s.at(i) == '0'){
            ans += '0';
        }
        else if(s.at(i) == '1'){
            ans += '1';
        }
        else if(s.at(i) == 'B' && ans != ""){
            ans.pop_back();
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]

def match(x,y):
    for i in range(M):
        for j in range(M):
            if A[x+i][y+j] != B[i][j]:
                return False
    return True

found = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if match(i,j):
            found = True
            
print("Yes") if found else print("No")  

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

int main() {
  int N,i,j,k;
  cin >> N;
  vector<int> a(N);
  for(i=0;i<N;i++){  
  cin >> a.at(i);
  }  
  j=a.at(0);
  for(i=0;i<N;i++){ 
  if(j==2){
  break;
  }
  j=a.at(j-1);
  }
  if(i<N-1){
  cout << i+1 << endl;
  }
  else{
  cout << -1 <<endl;
  }
}
  

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

int main(){

  int n,p,i;
  while( cin >> n >> p ){
    if(n==0)break;

    vector<int> V(n);
    int count = 0;

    for(i = 0; i < n; i++){
      if(p == 0){
        p += V[i]; V[i] = 0;
      }
      else if(p != 0){
        p--; V[i]++;
      }

      if(p == 0){
        for(int j = 0; j < n; j++){
          if(V[j] != 0) count++;
        }
      }
      if(count == 1) break;
      //cout << count << " ";
      count = 0;
      if(i == n-1) i = -1;
    }
    cout << i << endl;
  }

	return 0 ;
}



Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vi v;
	rep(i, n - 1) {
		if(s[i] == 'R' && s[i + 1] == 'L') {
			v.push_back(i);
		}
	}
	int ans[N];
	rep(i, n) ans[i] = 0;
	int j = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'R' && i > v[j]) j++;
		if(s[i] == 'R') {
			if((v[j] - i) % 2 == 0) {
				ans[v[j]]++;
			}
			else {
				ans[v[j] + 1]++;
			}
		}
		else if(s[i] == 'L') {
			if((i - v[j]) % 2 == 0) {
				ans[v[j]]++;
			}
			else {
				ans[v[j] + 1]++;
			}
		}
	}
	rep(i, n - 1) cout << ans[i] << ' ';
	cout << ans[n - 1] << endl;
}


Measured memory_bytes: 1280
import math
import itertools
import sys

x, y = [int(x) for x in input().split()]

if (x+y) % 3:
  print(0)
  sys.exit()

total_move = (x+y) // 3
move_a = 2 * total_move - x

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = total_move
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(total_move,move_a,mod)

print(a)


Measured memory_bytes: 82456
import math
a, b, x = map(int, input().split())

V = a * a * b

if x > V/2:
    c = (x / a) * 2 / a - b
    print(math.degrees(math.atan((b-c)/a)))
else:
    c = (x / a) * 2 / b
    print(math.degrees(math.atan(b/c)))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	
	bool flg=1;
	if(a==b && b==c) flg=0;
	if(a!=b && b!=c && c!=a) flg=0;
	cout << (flg ? "Yes" : "No") << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;
typedef unsigned long long ull;

#define F first
#define S second
#define en end()
#define bg begin()
#define rev reverse
#define mp make_pair
#define pb push_back
#define y1 y1234567890
#define um unordered_map                         
#define all(x) x.bg, x.en
#define sqr(x) ((x) * (x))
#define sz(x) (int)x.size()

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;

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

const int N = 505;

int n, m, x, y, a[N][N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	cin >> n >> m >> x >> y;

	if (n % x == 0 && m % y == 0) {
		cout << "No";
		return 0;
	}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			a[i][j] = 1000;

	for (int i = x; i <= n; i += x)
		for (int j = y; j <= m; j += y)
			a[i][j] = -1000 * (x * y - 1) - 1;

	cout << "Yes" << endl;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			cout << a[i][j] << " ";
		cout << endl;
	}

	return 0;
}


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

using namespace std;

int main(){
int x,y;
int leg;
string s = "No";

cin >> x >> y;

for(int i = 0;i <= x;i++){
    leg = i*4 + (x-i)*2;
    if(leg == y){
	s = "Yes";
	break;
    }
}

cout << s << endl;

return 0;
}


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

bool isM(string f, string s);
int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    string s1 = (s.substr(0,1));
    string s2 = (s.substr(1,1));
    string s3 = (s.substr(2,1));
    string s4 = (s.substr(3,1));
    if (isM(s1, s2))
    {
        if (isM(s3, s4))
        {
            cout << "AMBIGUOUS" << endl;
        }
        else
        {
            cout << "MMYY" << endl;
        }
    }
    else
    {
        if (isM(s3, s4))
        {
            cout << "YYMM" << endl;
        }
        else
        {
            cout << "NA" << endl;
        }
    }
    return 0;
}

bool isM(string f, string s)
{
    int fi = stoi(f);
    int si = stoi(s);
    if (fi == 0)
    {
        if(si ==0){
            return false;
        }
        return true;
    }
    else if (fi == 1)
    {
        if (si == 1 || si == 2)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    size_t ans=0;
    for(int i=1; i<n; ++i){
        unordered_set<char> lcs;
        for(int j=0; j<i; ++j){
            lcs.insert(s[j]);
        }
        unordered_set<char> ss;
        for(int j=i; j<n; ++j){
            if(lcs.find(s[j])!=lcs.end()) ss.insert(s[j]);
        }
        ans=max(ans, ss.size());
    }
    cout << ans << endl;
    return 0;
}


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

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

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int dist[300];
bool visited[300];
priority_queue<i_i, vector<i_i>, greater<i_i>> que;
int N, E, T;
int W[300];
int G[1000];
int C[1000];
int S[1000][10];
vector<int> State[1000];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> E >> T;
    T--;
    for(int i = 0; i < N; i++) {
        dist[i] = 1e9;
    }
    for(int i = 0; i < N; i++) {
        cin >> W[i];
        if(W[i] == 1) {
            dist[i] = 1;
            que.push({1, i});
        }
    }
    for(int i = 0; i < E; i++) {
        cin >> G[i];
        G[i]--;
        cin >> C[i];
        for(int j = 0; j < C[i]; j++) {
            cin >> S[i][j];
            S[i][j]--;
        }
    }
    while(!que.empty()) {
        i_i tmp = que.top();
        que.pop();
        int now = tmp.second;
        int cost = tmp.first;
        if(visited[now]) continue;
        visited[now] = true;
        //cerr << now << " " << cost << endl;
        for(int i = 0; i < E; i++) {
            for(int j = 0; j < C[i]; j++) {
                if(S[i][j] == now) {
                    //cerr << "push: " << now << " to " << i << endl;
                    State[i].push_back(cost);
                }
            }
            if(State[i].size() == C[i]) {
                //cerr << "complete: " << i << endl;
                sort(State[i].begin(), State[i].end());
                int ans = 0;
                for(int j = 0; j < State[i].size(); j++) {
                    chmax(ans, (int)State[i].size() - 1 - j + State[i][j]);
                }
                if(chmin(dist[G[i]], ans)) {
                    que.push({ans, G[i]});
                }
            }
        }
    }
    if(dist[T] == 1e9) dist[T] = -1;
    cout << dist[T] << endl;
    return 0;
}


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

typedef long long ll;
const ll INF = 1e13;
int N;
ll a[410];
ll dp[410][410];
ll asum[410];

ll Sum(int l, int r)
{
    return asum[r] - asum[l - 1];
}

ll cost(int l, int r)
{
    if(dp[l][r] != -1) return dp[l][r];
    ll res = 0;
    if(l == r) return dp[l][r] = 0;
    res += Sum(l, r);
    ll cmin = INF;
    for(int m = l; m < r; m++)
    {
        cmin = min(cmin, cost(l, m) + cost(m + 1, r));
    }
    res += cmin;
    return dp[l][r] = res;
}

int main()
{
    cin >> N;
    for(int i = 0; i < N; i++) cin >> a[i];
    asum[0] = 0;
    for(int i = 1; i <= N; i++) asum[i] = asum[i - 1] + a[i - 1];
    memset(dp, -1, sizeof(dp));
    cout << cost(1,N) << endl; 
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  string s,t;
  cin>>s>>t;
  ll S=s.size(),T=t.size(),ans=MOD;
  rep(i,S-T+1){
    ll score=0;
    rep(j,T){
      if(s[i+j]!=t[j]){
        score++;
      }
    }
    ans=min(ans,score);
  }
  cout<<ans;
}

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

int main() {
  int N, M;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }
  cin >> M;
  vector<pair<int, int>> PX(M);
  for (int i = 0; i < M; i++) {
    int P;
    int X;
    cin >> P >> X;
    PX[i] = make_pair(P, X);
  }
  for (int i = 0; i < M; i++) {
    queue<ll> time;
    for (int j = 0; j < N; j++) {
      if (j == PX[i].first - 1) {
        time.push(PX[i].second);
      }
      else {
        time.push(T[j]);
      }
    }
    ll sum = 0;
    while(!time.empty()) {
      sum += time.front();
      time.pop();
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define m 1046527
int a[m];
long long int trans(char op[]) {
	int i,n=1,num;
	long long int sum=0;
	for(i=0; i<strlen(op); i++) {
		switch(op[i]) {
			case'A':
				num=1;break;
			case'C':
				num=2;break;
			case'G':
				num=3;break;
			case'T':
				num=4;break;
			default:
				num=0;break;
		}
		sum=sum+num*n;
		n=5*n;
	}
	return sum;
}
int h1(long long int data) {
	int j;
	j=data%m;
	return j;
}
int h2(long long int data) {
	int j;
	j=1+(data%(m-1));
	return j;
}
int h(long long int data,int i) {
	int j;
	j=(h1(data)+i*h2(data))%m;
	return j;
}
int insert(long long int data) {
	int i=0;
	while(1) {
		if(a[h(data,i)]==-1) {
			a[h(data,i)]=data;
			return 0;
		} else {
			i++;
		}
	}
}
int find(long long int data) {
	int i=0;
	while(1) {
		int j=h(data,i);
		if(a[j]==data) {
			return 1;
		} else if(a[j]==-1||i>m)
			return 0;
		else
			i++;
	}
}
int main() {
	int n,i,j=0;
	char name[100],op[15],out[1000000];
	scanf("%d",&n);
	for(i=0; i<m; i++) {
		a[i]=-1;
	}
	for(i=0; i<n; i++) {
		op[15]="aaaaaaaaaaaaaaa";
		scanf("%s %s",name,op);
		if(name[0]=='i') {
			insert(trans(op));
		} else {
			out[j]=find(trans(op));
			j++;
		}
	}
	for(i=0; i<j; i++) {
		if(out[i]==1)
			printf("yes\n");
		else
			printf("no\n");
	}
	return 0;
}


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

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

  if (N % 1111 == 0 || N % 1110 <= 9 || N % 1000 % 111 == 0) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    
    
    
    int n;
    cin >> n;
    
    int table[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
    int nn = 0;
    rep(i, 10) if (table[i] > n) { nn = i; break; }
    // cout << nn << endl;
    
    // 下位bitから1, 2, ...って割り振るか
    
    int a[n][n];
    fill_n(*a, n * n, 0);
    
    rep(i, n) {
        rep(j, n) {
            if (i == j) continue;
            rep(k, nn) {
                if ((i & (1 << k)) == ((j & (1 << k)))) {
                    continue;
                } else {
                    a[i][j] = k + 1;
                    break;
                }
            }
        }
    }
    rep(i, n - 1) {
        rep3(j, i + 1, n) {
            if (j > i + 1) cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }
}



Measured memory_bytes: 1408
import java.util.*;
import static java.lang.System.out;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for (int i = a; i <= b ; i++) {
            if(isKaibunNum(i)){
                count += 1;
            }
        }
        out.print(count);
    }

    private static boolean isKaibunNum(int n){
        CharSequence sb = new StringBuilder(String.valueOf(n));
        int l = sb.length();

        if(l==1){
            return true;
        }
        int checkCount = l/2;

        for (int i = 0; i < checkCount ; i++) {
            char left = sb.charAt(i);
            char right = sb.charAt(l-1-i);
            if(left != right){
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 35528
import java.util.Scanner;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int a = nextInt();
        int b = nextInt();

        if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
            out("Possible");
        } else {
            out("Impossible");
        }
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}

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

bool sugar(int x,int y,int z){
  int i=0;
  while(x*i<=z){
    if((z-x*i)%y==0) return true;
    i++;
  }
  return false;
}

int main() {
  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;
  int best_noudo=0;
  int best_whole=0;
  int best_sugar=0;
  vector<int>water;
  for(int i=0;i<31;i++){
    for(int j=0;j<31;j++){
      int x=A*i+B*j;
      if(x*100<=F&&x!=0) water.push_back(x);
    }
  }
  
  int w=water.size();
  for(int i=0;i<w;i++){
    int x=water.at(i);
    int j=min(x*E,F-100*x);
    double data=0;
    while(true){
      if(sugar(C,D,j)){
        data=j;
        break;
      }
      j--;
    }
    if(best_whole*data>=best_sugar*(100*x+data)){
      best_whole=100*x+data;
      best_sugar=data;
      best_noudo=data/x;
    }
  }
  cout << best_whole << " " << best_sugar << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};

mint choose(ll n, ll a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

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

    ll X, Y;
    cin >> X >> Y;

    if((X+Y)%3==0){
      ll n = (X+Y)/3;
      X-=n, Y-=n;
      if(X<0 || Y<0) cout << 0 << endl;
      else cout << choose(X+Y,X) << endl;
    }
    else{
      cout << 0 << endl;
    }
}

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

int main() {

  int N;
  cin >> N;
  int a[N];

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

  for(int i=0; i<N; i++) {
    for(int j=0; j<i; j++) {
      if(abs(a[i] - a[j]) > maxi) 
	maxi = abs(a[i] - a[j]);
    }
  }
  cout << maxi << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int S,h,m,s;
    scanf("%d",&S);
    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = S - h * 3600 - m *60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}			


Measured memory_bytes: 2148
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  return ~~Math.min(intShift(),intShift())+~~Math.min(intShift(),intShift());
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
600
300
220
420
`);

Measured memory_bytes: 19784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int l1 = h1 * 60 + m1, l2 = h2 * 60 + m2;
    int ans = l2 - l1 - k;
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    vi A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    string S;
    cin >> S;

    vi B(1, 0);
    int ans = 0;
    for (int i = N - 1; i >= 0; i--) {
      for (ll b : B) A[i] = min(A[i], A[i] ^ b);
      if (A[i] == 0) continue;
      if (S[i] == '0')
        B.push_back(A[i]);
      else {
        ans = 1;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <limits.h>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    long long quot = abs(x / d);
    
    if(quot >= k){
        cout << (long long)((__int128_t)x - (__int128_t)k*(__int128_t)d) << endl;
        return 0;
    }
    
    long long ans = x - quot*d;
    k -= quot;
    if(k%2 == 0) cout << ans << endl;
    else         cout << abs(ans-d) << endl;
    
    return 0;
}

Measured memory_bytes: 3592
N,M = map(int,input().split())
SC = [tuple(map(int,input().split())) for i in range(M)]

if N==1:
    r = range(10)
elif N==2:
    r = range(10,100)
else:
    r = range(100,1000)
for n in r:
    n = str(n)
    for s,c in SC:
        if n[s-1] != str(c):
            break
    else:
        print(n)
        exit()
print(-1)

Measured memory_bytes: 3064
n,a,b=map(int,input().split())
h=[int(input()) for _ in range(n)]

def hantei(p):
    global a,b
    tp = p
    fa = a - b
    for sh in h:
        sh -= b * p
        if sh > 0:
            tp -= (sh+fa-1) // fa
            if tp < 0:
                return False
    return True


def nibun(l,r):
    if r == l:
        return l
    f = (l+r)//2
    if hantei(f):
        return nibun(l,f)
    else:
        return nibun(f+1,r)

print(nibun(1,10**9))

Measured memory_bytes: 7072
N,K = map(int,input().split())
x = list(map(int,input().split()))
ans = float('inf')
for i in range(N-K+1):
    l,r = x[i],x[i-1+K]
    if l*r > 0:
        ans = min(ans,max(abs(l),abs(r)))
    else:
        ans = min(ans,max(abs(l),abs(r))+min(abs(l),abs(r))*2)
print(ans)

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 最大公約数（a > b）
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

// 最小公倍数（a > b）
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

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

  ll ab1 = b / c - (a - 1) / c;
  ll ab2 = b / d - (a - 1) / d;

  ll l = lcm(max(c, d), min(c, d));
  ll ab3 = b / l - (a - 1) / l;
  cout << (b - a + 1) - (ab1 + ab2 - ab3) << endl;

  return 0;
}


Measured memory_bytes: 256