akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  int ans;
  cin >> s;
  if(s=="SUN") ans=7;
  else if(s=="MON") ans = 6;
  else if(s=="TUE") ans = 5;
  else if(s=="WED") ans = 4;
  else if(s=="THU") ans = 3;
  else if(s=="FRI") ans = 2;
  else if(s=="SAT") ans = 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int n;
    cin >> n;
	vector<int> v(n), w(n);
	int b[100001]{ 0 };
  	int c[100001]{ 0 };
	for (int i = 0; i < n / 2; i++) {
		cin >> v[i] >> w[i];
		b[v[i]]++;
		c[w[i]]++;
	}
	int max_v{ 0 };
  	int max_w{ 0 };
	int mark_v{ 0 };
  	int mark_w{ 0 };
	for (int i = 0; i < 100001; i++) {
		if (max_v < b[i]) {
			max_v = b[i];
			mark_v = i;
		}
	}
	for (int i = 0; i < 100001; i++) {
		if (max_w < c[i]) {
			max_w = c[i];
			mark_w = i;
		}
	}
	if (mark_v != mark_w) {
		cout << n - max_v - max_w;
	}
	else {
		sort(b, b + 100001, greater<int>());
		sort(c, c + 100001, greater<int>());
		cout << n - max(b[0] + c[1], b[1] + c[0]) << endl;
	}
}

Measured memory_bytes: 1792
from collections import Counter
N = int(input())
#L = [input() for _ in range(N)]
L = []
for n in range(N):
    S = input()
    L.append(S)
Dic = Counter(L)
max_value = max(Dic.values())
max_k_list = [i for i, j in Dic.items() if j == max_value]
max_k_list = sorted(max_k_list)

print(*max_k_list , sep="\n")

Measured memory_bytes: 35944
"use strict"
function main(arg) {
    var listSize = arg.trim().split("\n")[0];
    var listBase = arg.trim().split("\n")[1].split(" ");
    var list = [];
    var trueFlg = true;
    var count = 0;

    for(var i = 1; i <= listSize; i++){
        if(listBase[(i-1)] != i){
            trueFlg = false;
            count++;
        }
    }


    if(trueFlg == true || count == 2){
        console.log("YES");
    }else{
        console.log("NO");
    }


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

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

using namespace std;

int main(){
    int A,B,K;
    vector<int> s;
    cin >>A >>B >>K;
    for (int i=1;i<=A;i++){
        if (A%i==0 && B%i==0){
            s.push_back(i);
        }
        
    }
    reverse(s.begin(),s.end());
   cout << s[K-1] << endl; 
}

Measured memory_bytes: 256
C = {}
S = input().strip()
N = len(S)
K = int(input())
for i in range(N):
    s = S[i]
    if s not in C:
        C[s]=0
    C[s] += 1
if len(C)>1:
    a = 0
    cnt = 1
    for i in range(1,N):
        if S[i]==S[i-1]:
            cnt += 1
        else:
            a += cnt//2
            cnt = 1
    a += cnt//2
    X = S+S
    b = 0
    cnt = 1
    for i in range(1,2*N):
        if X[i]==X[i-1]:
            cnt += 1
        else:
            b += cnt//2
            cnt = 1
    b += cnt//2
    d = b-a
    print(a+d*(K-1))
else:
    A = list(C.items())
    k = A[0][1]
    if k%2==0:
        print((k//2)*K)
    else:
        if K%2==0:
            a = k
            b = 2*k
            d = k
            print(a+d*((K//2)-1))
        else:
            a = k//2
            b = (k*3)//2
            d = b-a
            print(a+d*(K//2))

Measured memory_bytes: 62036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}

int main() {
  int x[5];
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  
  for(int i=0;i<5;i++){
    if(0==x[i]){
      cout << i+1;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;

const ll inf = 1145148931919810;
vector< pair<ll, ll> > v[100000];
ll d[100000];

void dfs(ll pos, ll bef, ll cost){
    for(auto u : v[pos]){
        if(u.first != bef){
            d[u.first] = min(d[u.first], cost + u.second);
            dfs(u.first, pos, d[u.first]);
        }
    }
}

int main(){
    int n; cin >> n;
    for(int i = 0; i < n - 1; ++i){
        int a, b, c; cin >> a >> b >> c;
        --a; --b;
        v[a].push_back(pair<ll, ll>(b, c));
        v[b].push_back(pair<ll, ll>(a, c));
        d[i] = inf;
    }
    d[n - 1] = inf;
    int q, k; cin >> q >> k;
    --k;
    dfs(k, -1, 0);
    for(int i = 0; i < q; ++i){
        int x, y; cin >> x >> y;
        cout << d[x - 1] + d[y - 1] << endl;
    }
    return 0;
}

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

template <typename T>
class LazySegmentTree {
	const int n;
	const T flag;
	const T id;
	vector<T> data, data2;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (data[node] != flag) {
			return data[node];
		}
		if (l <= lb && ub <= r) {
			return data[node] == flag ? data2[node] : data[node];
		}
		int left = node * 2, right = node * 2 + 1;
		if (data[node] != flag) {
			data[left] = data[node];
			data[right] = data[node];
		}
		return max(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
	void suc(int l, int r, int node, int lb, int ub, T val) {
		if (ub <= l || r <= lb) return;
		if (data[node] == val) return;
		if (l <= lb && ub <= r) {
			data[node] = val;
			return;
		}
		int left = node * 2, right = node * 2 + 1;
		if (data[node] != flag) {
			data[left] = data[node];
			data[right] = data[node];
		}
		data[node] = flag;
		suc(l, r, left, lb, (lb + ub) / 2, val);
		suc(l, r, right, (lb + ub) / 2, ub, val);
		data2[node] = max(data[left] == flag ? data2[left] : data[left], data[right] == flag ? data2[right] : data[right]);
	}
public:
	LazySegmentTree(int n_, T flag_, T id_) :
		n(size(n_)), flag(flag_), id(id_), data(n * 2, id), data2(n * 2) {}
	void update(int l, int r, T val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	ll n;
	cin >> n;
	ll res = n * (n + 1) / 2;
	LazySegmentTree<ll> lst(n + 1, -1, 0);
	for (int i = 0, x; i < n; i++) {
		cin >> x;
		ll val = x + lst.find(0, x);
		ll l = x, r = n + 1;
		while (l + 1 < r) {
			ll c = (l + r) / 2;
			if (lst.find(x, c) == val) {
				l = c;
			}
			else {
				r = c;
			}
		}
		lst.update(x, l, val);
	}
	cout << res - lst.find(0, n) << endl;
	return 0;
}

Measured memory_bytes: 7080
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int MAXN=9+3;
char s[MAXN];
int n;
ll ans;
int main(){
	scanf("%s",&s);
	n=strlen(s);
	for(int i=0;i<1<<(n-1);i++){
		int last=-1;
		ll res=0;
		for(int j=0;j<n-1;j++){
			if((i&1<<j)!=0){
				ll cur=0;
				for(int k=last+1;k<=j;k++){
					cur=cur*10+s[k]-'0';
				}
				res+=cur;
				last=j;
			}
		}
		ll cur=0;
		for(int j=last+1;j<n;j++){
			cur=cur*10+s[j]-'0';
		}
		res+=cur;
		ans+=res;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;


#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
#include <list>
list<char>theList;
const int maxn = 1e5 + 20;
char str[maxn];
void work() {
    scanf("%s", str + 1);
    int lenstr = strlen(str + 1);
    lenstr -= 2;
    if (str[1] == str[strlen(str + 1)]) lenstr--;
    if (lenstr & 1) {
        cout << "First" << endl;
    } else cout << "Second" << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define     bolt     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     F        first
#define     S        second
#define     pb       push_back
#define     ll       long long
#define     inf      3e5
#define     pi       3.141592
int main()
{
   ll n;
   cin>>n;
   ll m;
   cin>>m;
   for (ll i=0;i<m;i++)
   {
      ll a;
      cin>>a;
      n-=a;
   }
   if (n<0)
      cout<<-1;
   else
      cout<<n;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<int> pow3(16, 1);
    for(int i=1; i<=15; ++i)
        pow3[i] = pow3[i-1] * 3;

    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<int> > a(3);
        for(int i=0; i<3; ++i){
            int b;
            cin >> b;
            a[i].resize(b);
            for(int j=0; j<b; ++j)
                cin >> a[i][j];
            a[i].push_back(-1);
        }

        int ret = INT_MAX;
        for(int start=0; start<3; start+=2){
            int prev = start;
            vector<int> k(3, 0);
            int cost = 0;

            for(int i=1; i<=n; ++i){
                int curr;
                for(int j=0; j<3; ++j){
                    if(a[j][k[j]] == i){
                        curr = j;
                        ++ k[j];
                    }
                }

                if(curr == 1){
                    cost += pow3[n-i];
                    prev ^= 2;
                }else if(curr != prev){
                    cost += 2 * pow3[n-i];
                }
            }

            ret = min(ret, cost);
        }

        if(ret <= m)
            cout << ret << endl;
        else
            cout << -1 << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N, K;
  cin >> N >> K;
  vll H(N);
  rep(i, N) {
    cin >> H[i];
  }
  SORT(H);

  ll sum = 0;
  rep(i, N - K) {
    sum += H[i];
  }
  COUT(sum);
  return 0;
}

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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin >> a >> b;
    cout << (a%b == 0 ? 0 : 1) << "\n";
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

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

void solve() {
	ll a, b;
	cin >> a >> b;
	ll x = gcd(a, b);
	vector<ll> v;
	v.push_back(1);
	ll cur = x;
	for (ll i = 2; i * i <= x; i++) {
		if (cur % i == 0) {
			v.push_back(i);
			while (cur % i == 0) cur /= i;
		}
	}
	if (cur != 1) v.push_back(cur);
	cout << v.size() << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3564
#include <stdio.h>
main(){
   int x,y;
   while(1){
       scanf("%d %d\n",&x,&y);
       if(x==0 && y==0){
             break;
       }else{
             if(x>y){
                  printf("%d %d\n",y,x);
             }else{
                  printf("%d %d\n",x,y);
             }
       }
    }
    return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
int main(void)
{
	int n,m,d[1000],c[1000],a[1000][1000],x=0,y,i,j;
	scanf("%d %d", &n, &m);
	for(i=0; i<n; i++)
	scanf("%d", &d[i]);
	for(i=0; i<m; i++)
	scanf("%d", &c[i]);
	y=m-n;
	for(i=0; i<n; i++)
	{
		for(j=x; j<=y; j++)
		{
			a[i][j]=d[i]*c[j];
			if(i>0)
			a[i][j]+=a[i-1][j-1];
			if(j>x&&a[i][j]>a[i][j-1])
			a[i][j]=a[i][j-1];
		}
		x++;
		y++;
		if(y==n-2)
		y=m-1;
	}
	printf("%d\n", a[n-1][m-1]);
	
	return 0;
}


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


int main(){
    int n;
    cin >> n;
    int m=n;
    int x=0;
    while(n>0){
        x += n%10;
        n /=10;
    }
    if(m % x == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
 }


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

using namespace std;

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

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

int W, H;
string s[30];
using P = pair<int, int>;
void solve() {
    P init;
    rep(i, H) rep(j, W) if (s[i][j] == '@') init = P(i, j);
    set<P> visited;
    queue<P> que;
    que.push(init);
    visited.insert(init);

    while (que.size()) {
        auto p = que.front();
        que.pop();
        rep(k, 4) {
            auto np = p;
            np.first += dy[k];
            np.second += dx[k];
            if (np.first < 0 || np.second < 0) continue;
            if (H <= np.first || W <= np.second) continue;
            if (visited.count(np)) continue;
            if (s[np.first][np.second] == '#') continue;

            que.push(np);
            visited.insert(np);
        }
    }
    cout << visited.size() << endl;
}
int main() {
    while (cin >> W >> H, W) {
        rep(i, H) cin >> s[i];
        solve();
    }

    return 0;
}

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

typedef long long ll;
typedef long double ld;



int main(){

    	ll n,k;
    	cin >> n >> k;
    	ll h[n];
    	ll i;
    	for(i=0;i<n;i++)
            cin >> h[i];
        ll cost[n]={0};
        ll min1 = 1000000000;
        cost[0]=0;
        ll j;
        cost[1]=abs(h[1]-h[0]);
        for(i=2;i<n;i++){
            j=i-1;
            min1 = 1000000000;
            while(j>=0&&j>=i-k){
                min1=min(min1,cost[j]+abs(h[i]-h[j]));
                j--;
            }
            cost[i]=min1;
        }
        cout << cost[n-1];



}


Measured memory_bytes: 5152
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vl dp(n+2, -1);  // dp[i] : i段目(iは1-index)からスタートしてn段目にのぼる方法の数(-1のとき未確定)
    dp[n+1] = 0;
    dp[n] = 1;
    rep(i, m) {
        ll a;
        cin >> a;
        dp[a] = 0;
    }

    for(ll i = n-1; i >= 0; i--) {
        if(dp[i] >= 0) {
            continue;
        }
        dp[i] = dp[i+1] + dp[i+2];
        dp[i] %= mod;
    }
    
    out(dp[0]);
    re0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int a[n];
	for(int i=1;i<=n;i++)
		cin >> a[i-1];
	sort(a,a+n);
	cout << a[n-1]-a[0] << endl;
}

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

vector<vector<pair<int, int>>> G;
vector<long long> D;

void dfs(int current, int parent) {
  for (auto p : G.at(current)) {
    if (p.first == parent) continue;
    D.at(p.first) = D.at(current) + p.second;
    dfs(p.first, current);
  }
}

int main() {
  int N; cin >> N;
  G.resize(N);
  D.resize(N);
  for (int i = 0; i < N-1; i++) {
    int a, b, c; cin >> a >> b >> c;
    G.at(a-1).push_back(make_pair(b-1, c));
    G.at(b-1).push_back(make_pair(a-1, c));
  }
  int Q, K; cin >> Q >> K;
  D.at(K-1) = 0;
  dfs(K-1, -1);
  vector<vector<int>> xy(Q, vector<int>(2));
  for (int i = 0; i < Q; i++) cin >> xy.at(i).at(0) >> xy.at(i).at(1);
  for (int i = 0; i < Q; i++) {
    cout << D.at(xy.at(i).at(0)-1) + D.at(xy.at(i).at(1)-1) << endl;
  }
}


Measured memory_bytes: 19840
use std::io::{Read, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    let mut iter = input.split_whitespace();

    let n: i32 = iter.next().unwrap().parse().unwrap();

    for i in 1..n+1 {
        if  i%3 == 0 {
            out.write_fmt(format_args!(" {}", i)).unwrap();
            continue;
        }
        let mut x=i;
        while x!=0 {
            if x%10 == 3 {
                out.write_fmt(format_args!(" {}", i)).unwrap();
                break;
            }
            x/=10;
        }
    }
    out.write(b"\n").unwrap();
}



Measured memory_bytes: 5036
use std::io::Read;
use std::cmp::{max, min};

fn main(){
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n:i32 = iter.next().unwrap().parse().unwrap();
    let mut cnt = 0usize;
    for i in 1..n+1{
        if i.to_string().len() % 2 == 1{
            cnt += 1;
        }
    }
    println!("{}", cnt);
    
}


Measured memory_bytes: 4352
main = do
  li <- getLine
  let ans = compute $ read li
  print ans

compute :: Int -> Int
compute n | even n || mod n 5 == 0 = -1
compute n = loop n 1 (mod 7 n)

loop n c 0 = c
loop n c m = loop n (succ c) (mod (m*10+7) n)


Measured memory_bytes: 3876
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        Gcd gcd = new Gcd();
        Gcd.GcdResult res = gcd.extGcd(n[0], n[1]);
        System.out.printf("%d %d\n", res.a, res.b);
    }

}

class Gcd {
    class GcdResult {
        // xa + yb = n;
        final long a;
        final long b;
        final long gcd;

        public GcdResult(long a, long b, long gcd) {
            this.a = a;
            this.b = b;
            this.gcd = gcd;
        }
    }

    public GcdResult extGcd(long x, long y) {
        if (x < y) {
            GcdResult res = extGcd(y, x);
            return new GcdResult(res.b, res.a, res.gcd);
        }
        if (y == 0) {
            return new GcdResult(1, 0, x);
        }
        GcdResult res = extGcd(y, x % y);
        long a = res.b;
        long b = res.a - (x / y) * res.b;
        return new GcdResult(a, b, res.gcd);
    }

    public long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }
        if (y == 0) {
            return x;
        }
        return gcd(y, x % y);
    }

    public long gcd(long... n) {
        if (n.length < 2) {
            throw new IllegalArgumentException();
        }
        long res = n[0] * n[1];
        for (int i = 2; i < n.length; i++) {
            res = gcd(res, n[i]);
        }
        return res;
    }

    public long lcm(long... n) {
        if (n.length < 2) {
            throw new IllegalArgumentException();
        }
        long lcm = n[0] * n[1] / gcd(n[0], n[1]);
        for (int i = 2; i < n.length; i++) {
            lcm = lcm * n[i] / gcd(lcm, n[i]);
        }
        return lcm;
    }
}




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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n,d;
int msum=0;

ll sum[110];
int m[110];
ll c[110][10010];
int cur[110];

int main(void){
	while(cin >> n >> d){
		if(n==0&&d==0) break;
		msum=0;
		rep(i,n) sum[i]=0;

		rep(i,n){
			cin >> m[i];
			rep(j,m[i]) cin >> c[i][j];
			rep(j,m[i]) sum[i]+=c[i][j];
			cur[i]=m[i]-1;
			msum+=m[i];
		}

		bool ok=true;
		rep(loop,msum){
			ll cmax[2]={-1,-1};
			int index[2]={-1,-1};
			rep(i,n){
				rep(j,2){
					if(sum[i]>cmax[j]){
						rep(k,2-1-j) cmax[k+1]=cmax[k],index[k+1]=index[k];
						cmax[j]=sum[i],index[j]=i;
						j=2;
					}
				}
			}

			int k=index[0];
			int l=index[1];


			bool del=false;
			rep(i,n){
				if(i==k) continue;
				while(cur[i]>=0&&abs(sum[k]-(sum[i]-c[i][cur[i]]))<=d) del=true,sum[i]-=c[i][cur[i]],cur[i]--;
			}

			while(cur[k]>=0&&abs(sum[l]-(sum[k]-c[k][cur[k]]))<=d)del=true,sum[k]-=c[k][cur[k]],cur[k]--;
			if(del) continue;

			break;
		}
		rep(i,n) if(cur[i]!=-1) ok=false;
		if(ok)
			puts("Yes");
		else
			puts("No");
	}
	return 0;
}

Measured memory_bytes: 7488
k,a,b=map(int,input().split())
if a+1>=b:
    print(k+1)
    exit()
c=k-a+1
if c%2==0:
    print(max(k+1,a+(c//2)*(b-a)))
else:
    print(max(k+1,(c//2)*(b-a)+a+1))

Measured memory_bytes: 9116
#include <stdio.h>

void bubbleSort(int A[], int N){
    
    int flag = 1, j, count = 0, i;
    while ( flag ) {
        flag = 0;
        for( j = N-1; 0 < j; --j ){
            if (A[j] < A[j-1]){
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1 ;
                count ++;
            }
        }
    }
    for( i = 0; i < N; i++ ){
        printf("%d", A[i]);
        if( i != N-1 ) printf(" ");
    }
    printf("\n");
    printf("%d\n", count);
}

int main() {
    int i, N;
    scanf("%d", &N);
    int A[N];
    for( i = 0; i < N; ++i ) {
        scanf("%d", &A[i]);
    }
    bubbleSort(A, N);
    return 0;
}


Measured memory_bytes: 1924
data = [int(x) for x in input().split(' ')]
n, y = data[0], data[1]
y //= 1000
for cnt1 in range(n+1):
	for cnt5 in range(n+1-cnt1):
		cnt10 = n-cnt1-cnt5
		if cnt1+5*cnt5+10*cnt10 == y:
			print(cnt10, cnt5, cnt1)
			exit()
print(-1, -1, -1)

Measured memory_bytes: 3064
/*Har Har Mahadev*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define tr(v,it) for(auto it=v.begin(); it!=v.end(); it++)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define pie 3.141592653589793
#define INF 1e18
using namespace std;

const int N=2e5+10;
int main()
{
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        
		        long long a,b,c,d;
		        cin>>a>>b>>c>>d;
		        if(a+b>c+d)
		        	cout<<"Left";
		        if(a+b<c+d)
		        	cout<<"Right";
		        if(a+b==c+d)
		        	cout<<"Balanced";


        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = a; i < b; i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1e9
#define INFL 1e18
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

int main() {
	fast_io;
	int a,b,c; cin>>a>>b>>c;
	swap(a,b); swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<"\n";
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def main():
    number_of_A,number_of_B,number_of_C,nubmer_of_take_cards = map(int,input().split())
  
    result = 0
    if number_of_A >= nubmer_of_take_cards:
        result = nubmer_of_take_cards
    else:
        result += number_of_A
        nubmer_of_take_cards = nubmer_of_take_cards - number_of_A
        
        if number_of_B < nubmer_of_take_cards:
            nubmer_of_take_cards = nubmer_of_take_cards - number_of_B
            result = result - nubmer_of_take_cards
    
    print(result)
            
if __name__ == "__main__":
    main()
    


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

int main() {
  int n, tmp;
  ll ans = 0;
  cin >> n;
  char s[n];
  cin >> s;
  vector<int> r, g, b;
  rep(i, n) {
    if(s[i] == 'R') {
      r.push_back(i);
    } else if(s[i] == 'G') {
      g.push_back(i);
    } else {
      b.push_back(i);
    }
  }
  ans = r.size() * g.size() * b.size();
  rep(i, r.size()) {
    rep(j, g.size()) {
      if(r[i] > g[j]) {
        tmp = r[i] - g[j];
        if(g[j] - tmp >= 0 && s[g[j] - tmp] == 'B') ans--;
        if(r[i] + tmp < n && s[r[i] + tmp] == 'B') ans--;
        if(tmp % 2 == 0 && s[g[j] + (tmp / 2)] == 'B') ans--;
      } else {
        tmp = g[j] - r[i];
        if(r[i] - tmp >= 0 && s[r[i] - tmp] == 'B') ans--;
        if(g[j] + tmp < n && s[g[j] + tmp] == 'B') ans--;
        if(tmp % 2 == 0 && s[r[i] + (tmp / 2)] == 'B') ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int B[N-1];
  FOR(i,0,N-1) cin >> B[i];
  int ans = 0;
  ans += B[0] + B[N-2];
  FOR(i,1,N-1) {
    ans += min(B[i-1], B[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())

A = list(map(int,input().split()))
cnt = 0
ans = 0
for i in range(n):
    if cnt ==0 and A[i] == 0:
        continue
    elif cnt ==0 and A[i] != 0:
        cnt = A[i]
        
        ans +=cnt
    elif cnt !=0 and cnt <= A[i]:
        ans += (A[i] - cnt)
        cnt = A[i]
        

        
    elif cnt !=0 and  A[i] < cnt:
        cnt = A[i] 
        
print(ans)   

Measured memory_bytes: 12504
#include<iostream>
using namespace std;
int main()
{
  int x[5]={1,2,3,4,5};
  cin>>x[0]>>x[1]>>x[2]>>x[3]>>x[4];
  if(x[0]==0)
  {cout<<"1"<<endl;
  }
  else if(x[1]==0)
  {
    cout<<"2"<<endl;
  }
  else if(x[2]==0)
  {
    cout<<"3"<<endl;
  }
  else if(x[3]==0)
  {
    cout<<"4"<<endl;
  }
  else {
    cout<<"5"<<endl;
  }
  return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  bool flag = false;
  if(A == B && A != C){
  	flag = true;
  }
  else if (A==C && A!= B){
  	flag = true;
  }
  else if (B==C && B!=A){
  	flag = true;
  }
  
  if (flag){
  	cout << "Yes" << endl;
  }
  else
  {
  	cout << "No" << endl;
  }
 }

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

using namespace std;

using ll = long long;

int A, B, C;
ll K;
int main() {
  scanf("%d %d %d %lld", &A, &B, &C, &K);
  if (K % 2) {
    printf("%d\n", B - A);
  } else {
    printf("%d\n", A - B);
  }
  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        a:i32,
        b:i32,
        c:i32,
        d:i32
    }
    println!(
        "{}",
        if (b + c - 1) / b <= (a + d - 1) / d {
            "Yes"
        } else {
            "No"
        }
    )
}


Measured memory_bytes: 2152
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let n: usize = is.trim().parse::<usize>().unwrap();
    is.clear();
    stdin().read_line(&mut is).ok();
    let mut a = is
        .split_whitespace()
        .map(|e| e.parse::<usize>().unwrap())
        .collect::<Vec<_>>();
    let mut dp = vec![0; 100001];

    for e in a {
        dp[e] += 1;
    }

    let mut ans = 0;

    for i in 1..dp.len() {
        ans += i * dp[i];
    }
    is.clear();
    stdin().read_line(&mut is).ok();
    let q: usize = is.trim().parse::<usize>().unwrap();
    for _ in 0..q {
        let mut is = String::new();
        stdin().read_line(&mut is).ok();
        let mut itr = is.split_whitespace().map(|e| e.parse::<usize>().unwrap());
        let b = itr.next().unwrap();
        let c = itr.next().unwrap();
        ans -= b * dp[b];
        ans -= c * dp[c];
        dp[c] += dp[b];
        dp[b] = 0;
        ans += c * dp[c];
        println!("{}", ans);
    }
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  int ichi=0,ni=0,point;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(a>ichi){
      ni=ichi;
      ichi=a;
      point=i;
    }
    else if(a>ni){
      ni=a;
    }
  }
  for(int i=0;i<n;i++){
    if(i!=point) cout<<ichi<<endl;
    else cout<<ni<<endl;
  }
  return 0;
}


Measured memory_bytes: 1664
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	

L = []
for i in range(3):
	l = list(map(int, stdin.readline().rstrip().split()))
	L.append(l)
# for i in L:
# 	print(i)
N = int(input())
for _ in range(N):
	q = int(input())
	for i in range(3):
		for j in range(3):
			if(L[i][j] == q):
				L[i][j] = -1
f = 0
for i in range(3):
	if(L[i] == [-1,-1,-1]):
		f = 1
if(not f):
	if(L[0][0] == L[1][0] == L[2][0] == -1):
		f = 1
	if(L[0][1] == L[1][1] == L[2][1] == -1):
		f = 1
	if(L[0][2] == L[1][2] == L[2][2] == -1):
		f = 1
	if(L[0][0] == L[1][1] == L[2][2] == -1):
		f = 1
	if(L[0][2] == L[1][1] == L[2][0] == -1):
		f = 1
	
# for i in L:
# 	print(i)
if(f):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
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;
}

int main() {
 long double l;cin>>l;
 l=l*l*l;
 long double lb=l/27;
 cout << fixed << setprecision(10);
 cout<<lb<<endl;
}

Measured memory_bytes: 256
import math
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
p_num = 1
q_num = 1
for i in range(n-1):
    p_cnt = 0
    q_cnt = 0
    for j in range(i+1,n):
        if p[i] > p[j]:
            p_cnt += 1
        if q[i] > q[j]:
            q_cnt += 1
    p_num += p_cnt * math.factorial(n-i-1)
    q_num += q_cnt * math.factorial(n-i-1)
print(abs(p_num - q_num))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY
// memset(a,0,sizeof(a[0][0])*n*n); //2D array
//memset(a, 0, sizeof(a));  //1D array
//memset(str, 't', sizeof(str)); // string
void solve()
{
    int a,b;
    cin>>a>>b;
    int ans=-1;
    f(i,1,100000)
    {
        if(int(i*0.08)==a&&int(i*0.10)==b)
        {
            ans=i;break;
        }
    }
//    if(ans!=-1)
    cout<<ans;
//cout<<25*0.1;
}


int main()
{

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

    ll t=1;
   // cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 256
int main()
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (h = 0; h < H; h++) {
			for (w = 0; w < W; w++) {
				putchar(((h & 1) ^ (w & 1)) == 0 ? '#' : '.');		}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int dfs(int n);

vector<int> tournament[SIZE];

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

    int N;
    cin >> N;

    for(int i = 2; i <= N; ++i) {
        int a;
        cin >> a;
        tournament[a].pb(i);
    }

    cout << dfs(1) - 1 << endl;
    return 0;
}

int dfs(int n) {
    vector<int> tmp;
    for(int i = 0; i < tournament[n].size(); ++i) {
        tmp.pb(dfs(tournament[n][i]));
    }
    sort(all(tmp), greater<>());

    for(int i = 0; i < tmp.size(); ++i) {
        tmp[i] += i;
    }
    sort(all(tmp), greater<>());
    if(tmp.empty()) return 1;
    return tmp[0] + 1;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[100005];
pll B[100005];

struct UnionFind {
    UnionFind(int n) {
        rank.assign(n, 0);
        parent.resize(n);
        count.assign(n, 1);
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

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

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (rank[x] < rank[y]) {
            parent[x] = y;
            count[y] += count[x];
        }
        else {
            parent[y] = x;
            count[x] += count[y];
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }

    vector<int> rank;
    vector<int> parent;
    vector<int> count;
};

ll C[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    REP(i, M) {
        cin >> A[i].first >> A[i].second;
        A[i].first--;
        A[i].second--;
        uf.unit(A[i].first, A[i].second);
    }
    REP(i, K) {
        cin >> B[i].first >> B[i].second;
        B[i].first--;
        B[i].second--;
    }

    REP(i, N) {
        C[i] = uf.count[uf.find(i)] - 1;
    }
    REP(i, M) {
        C[A[i].first]--;
        C[A[i].second]--;
    }
    REP(i, K) {
        if (!uf.same(B[i].first, B[i].second))
            continue;
        C[B[i].first]--;
        C[B[i].second]--;
    }

    REP(i, N) {
        cout << C[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5888
#include<iostream>
#include<cstdio>
bool a[30000+11]={};
int gcd(int a,int b){
	while(a^=b^=a^=b%=a);
	return b;
}
int main(){
	int n;
	scanf("%d",&n);
	int s=0;
	int pos=1;
	for(int i=1;i<n;++i){
		while(pos%2!=0&&pos%3!=0)++pos;
		a[pos]=1;
		printf("%d ",pos);
		s+=pos;
		++pos;
	}
	for(int i=1;i<=30000;++i){
		if(!a[i]&&gcd(s,i)>1&&(s+i)%6==0){
			printf("%d",i);
			return 0;
		}
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int H,N;
    cin >> H >> N;
    vi A(N);
    in(N,A);
    int ans = 0;
    rep(i,N) ans += A[i];
    if(ans >= H) out("Yes");
    else out("No");



    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int N, M, tmp;

priority_queue<int> Q;

void solve(){
    rep(i, M){
        tmp = Q.top();
        tmp /= 2;
        Q.pop();
        Q.push(tmp);
    }

    while (!Q.empty()) {
        ans += Q.top();
        Q.pop();
    }

    cout << ans << endl;
}

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

    rep(i, N) {
        cin >> tmp;
        Q.push(tmp);
    }

    solve();
}


Measured memory_bytes: 892
s = input()
t = input()
# snum = []
# tnum = []
# for c in range(ord('a'), ord('z') + 1):
#     snum.append([i for i, x in enumerate(s) if x == chr(c)])
# for c in range(ord('a'), ord('z') + 1):
#     tnum.append([i for i, x in enumerate(t) if x == chr(c)])
# snum.sort()
# tnum.sort()
# print('Yes' if snum == tnum else 'No')


sn=[0 for i in range(26)]
tn=[0 for i in range(26)]
for i in range(len(s)):
    sn[ord(s[i])-ord('a')]+=1
    tn[ord(t[i])-ord('a')]+=1
print('Yes' if sorted(sn) == sorted(tn) else 'No')



Measured memory_bytes: 3632
#include <iostream>

using namespace std;

bool isprime(int x);

int main()
{
	int n, a[10000];
	int i, j = 0;
	int ans = 0;
	
	cin >> n;
	
	for (i = 0; i < n; i++){
		cin >> a[i];
		if (isprime(a[i]) == true){
			ans++;
		}
	}
	
	cout << ans << "\n";
	
	return (0);
}

bool isprime(int x)
{
	int i;
	
	if (x == 2){
		return (true);
	}
	
	if (x < 2 || x % 2 == 0){
		return (false);
	}
	
	i = 3;
	
	while (x >= i * i){
		if (x % i == 0){
			return (false);
		}
		i += 2;
	}
	
	return (true);
}


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

typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)

int main(void){
    string S;

    //標準入力
    cin >> S;

    if(S[2] == S[3] && S[4] == S[5])
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c = gets.split.map(&:to_i)

if a.odd? || b.odd? || c.odd?
  puts 0
  exit
end

if a == b && b == c
  puts -1
  exit
end

i = 0

while !(a.odd? || b.odd? || c.odd?)
  x = (b/2) + (c/2)
  y = (a/2) + (c/2)
  z = (a/2) + (b/2)
  a = x
  b = y
  c = z
  i += 1
end

puts i

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;

int main(){
	
	string str;
	cin >> str;
	char tmp;
	for(int i = 0; i < 4; i++){
		if (i>0){
			if (str[i]==str[i-1]){
				cout << "Bad" << endl;
				return 0;
			}
		}
	}
	cout << "Good" << endl;

	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int ans[26], n, a[200006];
ll pos = 0, cnt = 0;
int main()
{
    scanf("%d", &n);
    int k = 1;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        int flag = 1;
        for (int j = 0; j <= 20; j++)
        {
            if (a[i] & (1 << j))
                ans[j]++;
            if (ans[j] > 1)
            {
                flag = 0;
            }
        }
        if (!flag)
        {
            pos += cnt;
            while (k < i)
            {
                int ok = 1;
                for (int j = 0; j <= 20; j++)
                {
                    ans[j] -= (a[k] & (1 << j)) ? 1 : 0;
                    if (ans[j] > 1)
                        ok = 0;
                }
                k++;
                cnt--;
                if (ok)
                    break;
                else
                    pos += cnt;
            }
        }
        cnt++;
    }
    printf("%lld\n", pos + ((1 + cnt) * cnt / 2));
    return 0;
}

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n, k;
ll a[SZ];
ll md[SZ];
ll b[SZ];

unordered_map <ll, ll> m;

int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin2(n, k);
    for1(i, n) {
        cin1(a[i]);
        md[i] = (md[i-1] + a[i]) % k;
    }

    m[0] = 1;
    for1(i, n) {
        j = i-k;
        if(j >= 0) m[b[j]]--;

        b[i] = ((md[i] - i)%k + k) % k;
        ans += m[b[i]];

        m[b[i]]++;
    }

    cot1(ans);


    return 0;
}



Measured memory_bytes: 16000
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

int main(){
    int N;
    int L[1000];
    cin>>N;
    int MAX=0;
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>L[i];
        MAX=max(MAX,L[i]);
        sum+=L[i];
    }

    if(MAX<sum-MAX) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;




}

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int x,y;cin>>x>>y;
  for(int i=0;i<=x;i++){
    if(i*2+(x-i)*4==y)fin("Yes");
  }
  fin("No");
}


Measured memory_bytes: 3632