akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a_list = list(map(int, input().split()))
fours = []
twos = []
others = []

for a in a_list:
    if a % 4 == 0:
        fours.append(a)
    elif a % 2 == 0:
        twos.append(a)
    else:
        others.append(a)

if len(twos) > 0:
    if len(fours) - len(others) < 0:
        print('No')
    else:
        print('Yes')

else:
    if len(fours) - len(others) < -1:
        print('No')
    else:
        print("Yes")

Measured memory_bytes: 14252
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)
#include <iomanip>

using namespace std;
#define ll long long

int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0;
  for(int i=1; i<=N; i++) {
    if(i >= K)
      ans += 1.0 / N;
    else
      ans += 1.0 / N * pow(0.5, ceil(log2(1.0 * K / i)));
  }
  cout << setprecision(15) << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,h;
    cin>>n>>h;
    ll a[n],b[n];
    rep(i,n)cin>>a[i]>>b[i];
    sort(a,a+n,greater<ll>());
    sort(b,b+n,greater<ll>());
    ll curb=0;
    ll cnt=0;
    while(curb<n&&b[curb]>a[0]&&h>0){
        h -= b[curb];
        curb++;
        cnt++;
    }
    if(h>0)cnt+=h/a[0]+ll(h%a[0]!=0);
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mmp make_pair
#define st first
#define nd second
#define rd third
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define itr pair <int, pii>
#define PQ priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define Rep(i, n) for (int (i) = 0; (i) <= (int)(n); i++)
#define For(i, a, n) for (int (i) = (a); (i) <= (int)(n); i++)
#define Forn(i, a, n) for (int (i) = (a); (i) >= (int)(n); i--)
#define FORD(i, n) for (int (i) = (int)(n) - 1; i>= 0; i--)
#define rep(i, n) for (int (i) = 1; (i) <= (int)(n); i++)
#define EACH(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define DEBUG(x) cout << #x << " = " << (x) << endl;
#define PR(a, n) {cout << #a << " = "; FOR(_, 1, n) cout << a[_] << ' '; puts(""); }
#define PRO(a, n) { cout << #a << " = "; REP(_, n) cout << a[_] << ' '; puts(""); }
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

const int INF = 1 << 30;
const int N = 1005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

inline ll read()
{
	ll x = 0; int f = 1, c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

int n; 
map <int, bool> u; 

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	n = read(); 
	REP(i, n)
	{
		int x = read(); 
		if (u[x] == true)
		{
			puts("NO"); 
			return 0; 
		}
		u[x] = true; 
	}
	
	puts("YES"); 
	return 0;
}


Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

int main(){
    ll n,m,q; cin >> n >> m >> q;
    vector<ll> a(q),b(q),c(q),d(q);
    
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--; 
        }
    ll ans= 0;
   
    
    for(ll k1=1;k1<=m;k1++){
        for(ll k2=k1;k2<=m;k2++){
            for(ll k3=k2;k3<=m;k3++){
                for(ll k4=k3;k4<=m;k4++){
                    for(ll k5=k4;k5<=m;k5++){
                        for(ll k6=k5;k6<=m;k6++){
                            for(ll k7=k6;k7<=m;k7++){
                                for(ll k8=k7;k8<=m;k8++){
                                    for(ll k9=k8;k9<=m;k9++){
                                        for(ll k10=k9;k10<=m;k10++){
                                            ll A[] = {k1,k2,k3,k4,k5,k6,k7,k8,k9,k10};
                                            ll check = 0;
                                            for(ll i=0;i<q;i++){
                                                if(A[b[i]] - A[a[i]] == c[i]){
                                                    check += d[i];
                                                }
                                            }
                                            ans = max(ans,check);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
n,m = map(int,input().split())
if m==0:
    print(-1)
    exit()
es = [[] for _ in range(n+1)]
for _ in range(m):
    u,v = map(int,input().split())
    es[u].append(v)
s,t = map(int,input().split())

INF = 10**9
dist = [[INF,INF,INF] for _ in range(n+1)]

d = 0
q = [s]

while q:
    d += 1
    r = d%3
    qq = []
    for u in q:
        for v in es[u]:
            if dist[v][r] == INF:
                dist[v][r] = d
                qq.append(v)
    q = qq

d = dist[t][0]
print(-1 if d==INF else d//3)

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

#define rep(i,n) for(int i=0;i<n;i++)
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;

//条件式 ? 真の場合の文 : 偽の場合の文
//abs(x) = (x の絶対値)
//string S  S,at(i),S += T,S += c,S.size(),S.substr(l)l文字目から最後まで,
///S.substr(l, r)l文字目からl+r-1文字目 n文字目から0個で空列を返せる
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//swap(a, b)    c
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool,b.size() 要素が小さい順
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1; 変数[key] = value; 変数.erase(key); 変数.at(key); 変数.count(key)所属判定　変数.size()
//find(all(x), key)boolソート済みのベクトル
//*lower_bound(all(x),k)以上の最小の要素,*uppper_bound(all(x),k)より大きい最小の要素
//char('0'+cnt) 数字cntからcharへの変換
//int(char-'0') charからintへの変換


int main(){

    string s;
    cin >> s;
    if(s.size() < 4){
        cno;
        return 0;
    }
    bool ok = true;
    string y = "YAKI";
    rep(i,4){
        if(s.at(i) != y.at(i)) ok = false;
    }
    if(ok) cyes;
    else cno;
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int main(){
    string s;
    while(cin >> s){
        if(s == "#") break;
        char table[10][10];
        int posy = 0,posx = 0;
        rep(i,s.size()){
            if(s[i] == 'b') {
                table[posy][posx] = 'b';
                posx++;
            }
            else if(s[i] == '/') {
                posy++;
                posx = 0;
            }
            else {
                int tmp = s[i]-'0';
                for(int j=0; j<tmp; j++) {
                    table[posy][posx] = '.';
                    posx++;
                }
            }
        }
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--; posy++;
        swap(table[a][b],table[c][d]);
        vector<char> vec;
        rep(i,posy){
            int cnt = 0;
            bool flag = false;
            rep(j,posx){
                if(table[i][j] == 'b') {
                    if(flag == true) {
                        vec.push_back(cnt+'0');
                        cnt = 0;
                    }
                    vec.push_back('b');
                    flag = false;
                }
                else {
                    cnt++;
                    flag = true;
                }
            }
            if(flag == true) {
                vec.push_back(cnt+'0');
                flag = false;
            }
            if(i != posy-1) vec.push_back('/');
        }
        rep(i,vec.size()) cout << vec[i];
        cout << endl;
    }
    return 0;
}


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

int main(){
	
	int n,m; cin>>n>>m;
	vector<ll> a(n);
	for(auto &i:a) {
		cin>>i;
		i/=2;
	}
	ll l = a.at(0);
	for(int i=1; i<n; i++){
		
		if(l%a.at(i)==0&&(l/a.at(i))%2==0){
			cout << 0 << endl;
			return 0;
		}
		if(a.at(i)%l==0&&(a.at(i)/l)%2==0){
			cout << 0 << endl;
			return 0;
		}
		l = a.at(i)/__gcd(a.at(i),l)*l;
		if(l>m){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (m/l+1)/2 << endl;
	
	
}


Measured memory_bytes: 1024
#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>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3648
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 2e5 + 10;
const int P = 1e9 + 7;
int res[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n;
  cin >> n;
  int ak = 1;
  int pop = MAX-1;
  R(i,n){
    int c;
    cin >> c;
    if(c != pop){
      res[pop] = ak;
      ak += res[c];
      if(ak >= P) ak -= P;
      pop = c;
    }
  }
  cout << ak << "\n";
}


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


int dp[10001];
int main()
{
	cout << fixed << setprecision(10);
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	REP(i, n)cin >> a[i] >> b[i];

	// 減らしたhp    仕様mp

	REP(i, h + 1)
	{
		dp[i] = INF;
	}
	dp[0] = 0;
	REP(i, h)
	{
		if (dp[i] == INF)continue;
		REP(j, n)
		{
			chmin(dp[min(h, i + a[j])], dp[i] + b[j]);
		}
	}
	cout << dp[h];
	return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())

flg = True

C=1
while flg:
  M = min(A,B)
  flg = False
  for m in range(M,1,-1):
    if A%m==0 and B%m==0:
      B=int(B/m)
      A=int(A/m)
      C=C*m
      flg = True
      break
      
print(A*B*C)




Measured memory_bytes: 38768
S = input()
slen = len(S)

def function(p, c, idx):
    n = c+int(S[idx])
    if idx == slen-1:
        return p+n
    else:
        return function(p+n, 0, idx+1) + function(p, n*10, idx+1)

print(function(0,0,0))


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>

int main()
{
	long long int N;
	scanf("%ld", &N);

	long long int ans = N*(N+1)/2;
	
	long long int f = (N-N%3)/3;
	long long int b = (N-N%5)/5;
	long long int fb = (N-N%15)/15;
	
	ans = ans - 3*(f*(f+1)/2) - 5*(b*(b+1)/2) + 15*(fb*(fb+1)/2);
	
	printf("%ld", ans);
	
}


Measured memory_bytes: 1728
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

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

	while (N != 0) {
		int count_find = 0;

		for (int i = 1; i < N; i++) {
			int sum = i;
			for (int j = i+1; sum < N; j++) {
				sum += j;
			}
			if (sum == N) {
				count_find++;
			}	
		}
		cout << count_find << endl;
		
		cin >> N;
	}

	return 0;
}

Measured memory_bytes: 3032
#6
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
ans1=0
for i in range(x):
    if i in a:
        ans+=1
    
for j in range(x+1,n+2):
    if j in a:
        ans1+=1
        
print(min(ans,ans1))

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

#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define dforsn(i,s,n) for(int i=(int)(n-1);i>=int(s);i--)
#define si(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(),a.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define filein(a) freopen(a,"r",stdin)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long int tint;

vi cant;

int main() {
	fastio;

	int n,m;
	cin >> n >>m;
	cant = vi(n+1,0);

    forn(i,m){
        int a,b;
        cin >> a >> b;
        cant[a]++;
        cant[b]++;
    }
    bool res=true;
    forn(i,n+1){
        res&=!(cant[i]%2);
    }
    if(res)cout << "YES" << endl;
    else cout << "NO" << endl;

	return 0;
}


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

int main(){
    int r,c;
    cin >> r >> c;
    int B[r+1][c+1];
    for(int i = 0; i < r; i ++){
        for(int j = 0; j < c; j ++){
            cin >> B[i][j];
        }
    }
    for(int i = 0;i < r; i ++){
        B[i][c] = 0;
        for(int j = 0; j < c; j ++){
         B[i][c] += B[i][j];   
        }
    }
    for(int i = 0;i < c+1; i ++){
        B[r][i] = 0;
        for(int j = 0; j < r; j ++){
            B[r][i] += B[j][i];
        }
    }
    for(int i = 0;i < r+1; i ++){
        for(int j = 0; j < c+1; j ++){
            if(j == c) cout << B[i][j] <<endl;
            else cout << B[i][j] << " " ;
        }
    }
    return 0;
}


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

using namespace std;

#define int long long

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

#ifdef DBG
#define log(item) cout << #item << " " << item << endl
#define loga(array, val) cout << #array << "[" << val << "] " << array [ val ] << endl
#else
#define log(item)
#define loga(array, val)
#endif

typedef vector<int> VI;
typedef pair<int, int> PII;

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

int A, B, C, D;

int lcm(int a, int b){
    int r, x, tmp;
 
  x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;

}

signed main(){
    cin >> A >> B >> C >> D;

    int lcmv = lcm(C, D);

    cout << 
        (B - A + 1) 
        - (B / C - (A - 1) / C) 
        - (B / D - (A - 1) / D)
        + (B / lcmv - (A - 1) / lcmv) << endl;
    return 0;
}


Measured memory_bytes: 256
# Me
class Check():
    def __init__(self):
        self.now_t, self.now_x, self.now_y = 0, 0, 0

    def do(self, t, x, y):
        distance = ((x - self.now_x) + (y - self.now_y))
        duration = t - self.now_t
        if duration < distance:
            return False

        if (distance - duration) % 2 != 0:
            return False

        self.now_t, self.now_x, self.now_y = t, x, y
        return True


N = int(input())
c = Check()
for i in range(N):
    a = [int(x) for x in input().split()]
    if not c.do(a[0], a[1], a[2]):
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 45272
#include<iostream>
using namespace std;
int main(){
  int n,min=10000000,suma,sumb,tmp;
  cin >> n;
  int w[n];
  for(int i=0;i<n;i++){
    cin >> w[i];
  }
  for(int i=1;i<n;i++){
    suma=sumb=0;
    for(int j=0;j<n;j++){
      if(i<j){
        suma+=w[j];
      }else{
        sumb+=w[j];
      }
    }
    tmp = abs(suma-sumb);
    min = (min<tmp)?min:tmp;
  }
  cout <<min <<endl;
}


Measured memory_bytes: 256
s=input()[::-1]
n=len(s)
b=[0]
m=0
d=1
for i in range(n):
  m+=int(s[i])*d
  m%=2019
  d*=10
  d%=2019
  b.append(m)
from collections import Counter
c=Counter(b)
ans=0
for i in range(2020):ans+=c[i]*(c[i]-1)//2
print(ans)

Measured memory_bytes: 16404
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


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

	if (a * c > a * d)
	{
		ans = a * c;
	}
	else
		ans = a * d;

	if (ans < b * c)
		ans = b * c;
	if (ans < b * d)
		ans = b * d;

	cout << ans << endl;

	
}

Measured memory_bytes: 3620
def main():
    n = int(input())
    x = []
    y = []
    h = []
    for i in range(n):
        xx, yy, zz = map(int, input().split())
        x.append(xx)
        y.append(yy)
        h.append(zz)
    for i in range(n):
        if h[i] != 0:
            idx = i
    for xx in range(101):
        for yy in range(101):
            H = h[idx] + abs(xx - x[idx]) + abs(yy - y[idx])
            flag = True
            for i in range(n):
                if h[i] != max(H - abs(xx - x[i]) - abs(yy - y[i]), 0):
                    flag = False
                    break
            if flag:
                print(xx, yy, H)
                return

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N, K;
pii S[100010];
int tn[100010];
priority_queue<pii, vector<pii>, greater<pii>> pq;

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

	int t, d;
	cin >> N >> K;
	rep(i, 0, N)
	{
		cin >> S[i].second >> S[i].first;
	}

	sort(S, S + N);

	int res = 0;
	set<int> tns;
	rrep(i, N - K, N)
	{
		res += S[i].first;
		pq.push(S[i]);
		tn[S[i].second]++;
		tns.insert(S[i].second);
	}
	int tnss = tns.size();

	res += tnss * tnss;

	int ans = res;

	rrep(i, 0, N - K)
	{
		if (tn[S[i].second] == 0)
		{
			while (!pq.empty())
			{
				auto p = pq.top();
				pq.pop();
				if (tn[p.second] > 1)
				{
					tn[p.second]--;
					tn[S[i].second]++;
					tnss++;
					res -= p.first - S[i].first;
					res += tnss * tnss - (tnss - 1)*(tnss - 1);
					chmax(ans, res);
					break;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6900
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main(){
    long long N,K;

    cin >> N >> K;

    vector<long long> A(100002, 0);

    for(int i = 0; i < N; i++){
        int a,b;
        cin >> a >> b;

        A[a] += b;
    }

    int i = 1;
    long long sum = 0;
    while(1){
        sum += A[i];
        if(sum >= K){
            break;
        }
        i++;
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<=n;i++)
typedef long long ll;
using namespace std;
int main()
{
   int N,x;
   cin >> N >> x;
   vector<int>a(N);
   rep(i,0,N){
       cin >> a[i];
   }

   ll ans=0;
   if(a[0]>x){
       ans+=a[0]-x;
       a[0]=x;
   }
   rep(i,1,N){
       if(a[i]+a[i-1]>x){
           ans+=(a[i]+a[i-1])-x;
           a[i]=x-a[i-1];
       }
   }

   cout << ans << endl;
}

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

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


int main()
{
    string S;
    cin >> S;
    int K;
    cin >> K;

    // dp[i][j][k] = 上から i までみて j 個 non-digit を使ってた時、の場合の数
    int N = S.size();
    vector<vector<vector<long long>>> dp(N, vector<vector<long long>>(K+1, vector<long long>(2, 0)));
    dp[0][0][0] = dp[0][1][1] = 1;
    dp[0][1][0] = S[0]-'1';

    REP(i, N-1){
        REP(j, K+1){
            dp[i+1][j][0] = dp[i][j][0];  // 下で 0 を選んだ場合
            if(j >= 1) dp[i+1][j][0] += 9*dp[i][j-1][0];  // 下で 1~9 を選んだ場合
            if(S[i+1] == '0'){
                dp[i+1][j][1] = dp[i][j][1];  // 最上位を選び続けるやつ
            }else{
                dp[i+1][j][0] += dp[i][j][1];  // 上から 0 を選んでくるやつ
                if(j >= 1){
                    dp[i+1][j][0] += (S[i+1]-'1')*dp[i][j-1][1];  // 上から 0 以外を選んでくるやつ
                    dp[i+1][j][1] = dp[i][j-1][1];  // 最上位を選び続けるやつ
                }
            }
        }
    }
    cout << dp[N-1][K][0] + dp[N-1][K][1] << endl;
    
    return 0;
}

Measured memory_bytes: 888
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int a=sc.nextInt();
  int b=sc.nextInt();
  int arr[]=new int[n+1];
  // int arr[][]=new int[n][n];
  // for(int i=0;i<n-1;i++){arr[i][i+1]=1;}
  	
  for(int i=0;i<n-1;i++)
  {
  	for(int j=i+1;j<n;j++)
  	{

  		int k1=i+1;
  		int j1=j+1;
  		if(k1<=a && j1>=b){arr[a-k1+1+j1-b]+=1;}
  			else if(k1<=a){arr[Math.min(j1-k1,b-j1+1+a-k1)]+=1;}
  			else if(k1>=a && j1<=b){arr[Math.min(j1-k1, k1-a+1+b-j1)]+=1;}
  			else if(k1>=a){arr[Math.min(j1-k1, j1-b+1+k1-a)]+=1;}
  			else{arr[j1-k1]+=1;}


  	}
  }
for(int i=1;i<n;i++){System.out.println(arr[i]);}
  }
}


Measured memory_bytes: 24404
#include <iostream>
#include <cstdio>

using namespace std;

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

	int a;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ans += a - 1;
	}

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


Measured memory_bytes: 256
N = input()
a = map(int, raw_input().split())

memo = [0 for i in range(9)]
for i in a:
	if(i < 3200):
		memo[i / 400] = memo[i / 400] + 1
	else:
		memo[8] = memo[8] + 1;

cnt = 0
for i in range(8):
	if memo[i] > 0:
		cnt = cnt + 1;
free = memo[8]

if cnt == 0:
	print 1, memo[8]
else:
	print cnt, memo[8] + cnt

Measured memory_bytes: 2568
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int n, m;
	cin >> n >> m;

	vector<Int> x(n);
	vector<Int> y(m);

	for (Int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (Int i = 0; i < m; i++) {
		cin >> y[i];
	}

	mint tempx = 0;
	mint tempy = 0;

	for (Int i = 0; i < n-1; i++) {
		tempx += (i + 1) * (n - i - 1) * (x[i + 1] - x[i]);
	}
	for (Int i = 0; i < m-1; i++) {
		tempy += (i + 1) * (m - i - 1) * (y[i + 1] - y[i]);
	}
	mint ans = tempx * tempy;

	cout << ans << "\n";

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}
 
int main() {
    ll n;
    cin >> n;
    n--;
    string s = "";
    int i = 0;
    for(;;) {
        if(i > 0) n--;
        s = (char)(n % 26 + 97) + s;
        n /= 26;
        if(n == 0) break;
        i++;
    }
    cout << s << endl;
    
}

Measured memory_bytes: 3604
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

vector<ll> costs;
ll dp[200001];
ll fact[200000];

ll power(ll a, ll b)
{
  if (b == 0)
    return 1;
  
  if (b == 1)
    return a;
  else if (b%2 == 0)
  {
    ll temp = power(a, b/2);
    return (temp * temp) % mod;
  }
  else
    return (power(a, b-1) * a) % mod;
}

int main()
{
  int n;
  scanf("%d", &n);
  
  fact[0] = 1;
  
  for(int i = 1; i <= n; i++)
    fact[i] = (fact[i-1] * i) % mod;
  
  for(int i = 0; i < n; i++)
  {
    int num;
    scanf("%d", &num);
    costs.push_back(num);
  }
  
  sort(costs.begin(), costs.end(), greater<int>());
  
  dp[1] = (costs[0] * 2) % mod;
  
  for(int i = 2; i <= n; i++)
  {
    dp[i] = (dp[i-1] * 4) % mod;
    ll temp = 0;
    
    ll power2n = power(2, i-2);
    
    temp += (((costs[i-1] * (power2n)) % mod) * (i+1)) % mod;
    
    temp *= (power2n * 4) % mod;
    dp[i] += temp % mod;
    
    dp[i] %= mod;
  }
  
  printf("%lld\n", dp[n]);
  
  return 0;
}


Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    ll h;
    cin >> h;
    ll p;
    for(ll i=2;;i*=2)
    {
        if(h<i)
        {
            p = i;
            break;
        }
    }
    cout << p-1 << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def ret_ans(n):
    li = [1]
    li.extend([6 ** i for i in range(0, 15) if 6 ** i <= n])
    li.extend([9 ** i for i in range(1, 15) if 9 ** i <= n])
    li.sort(reverse=True)
    
    s = set([n])
    cnt = 1
    while True:
        ts = set(s)
        for e in li:
            for c in s:
                if c - e == 0:
                    return cnt
                if c - e > 0:
                    ts.add(c - e)
        s = ts
        cnt += 1
 

def solve():
    print(ret_ans(int(input())))

if __name__=="__main__":
    solve()


Measured memory_bytes: 65636
import numpy

N = input()
A = map(int, raw_input().split())

sum = 0
for i in range(N-1):
 sum=sum+abs(A[i]-A[i+1])
sum=sum+abs(A[0])
sum=sum+abs(A[N-1])

print (sum -abs(A[0]-0) -abs(A[1]-A[0]) +abs(A[1]-0))
for i in range(N-2):
 mag=-abs(A[i+1]-A[i]) -abs(A[i+2]-A[i+1]) +abs(A[i]-A[i+2])
 print (sum +mag)
print (sum -abs(A[N-1]-A[N-2]) -abs(0-A[N-1]) +abs(0-A[N-2]))

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

int gcd(int x, int y);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}


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

#include <math.h>
#include <stdlib.h>


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

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_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int A, B;
    cin >> A >> B;
    A--; B--;

    int h = 100;
    int w = 100;
    vector<string> S(h, "");
    for(int i = 0; i < h; i++){
        for(int j = 0 ; j < w/2; j++){
            S[i] = S[i]+"#";
        }
        for(int j = w/2; j < w; j++){
            S[i] = S[i]+ ".";
        }
    }

    bool flag = true;
    int y = 0;
    int x = 0; 
    while(A > 0){
        S[y][x] = '.';
        y+= 2;
        if(y >= h){
            y = 0;
            x+=2;
        }
        A--;
    }

    y = 0;
    x = 0;
    while(B > 0){
        S[y][w-x-1] = '#';
        y+= 2;
        if(y >= h){
            y = 0;
            x+=2;
        }
        B--;
    }

    cout << h << " " << w << endl;
    for(int i = 0; i < h; i++) cout << S[i] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = N;
  for (int i = 0; i <= N; i++){
    int money6 = i;
    int money9 = N-i;
    int times = 0;
    while (money6 > 0){
      times += money6 % 6;
      money6 /= 6;
    }
    while(money9 > 0){
      times += money9 % 9;
      money9 /= 9;
    }
    ans = min(ans, times);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
for i in range(3,n+1):
    x = i
    if x % 3 == 0:
        print(' {0}'.format(i), end='')
        continue

    while x != 0:
        if x % 10 == 3:
            print(' {0}'.format(i),end='')
            break
        x //= 10

print()

Measured memory_bytes: 6740
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;
const int MAX_V = 100010;

struct edge{
   int to, cost;
   edge(int to, int cost):to(to), cost(cost){}
};

vector<edge> G[MAX_V];

struct Dijkstra{
    vector<int> d, dp;
    Dijkstra(){}
    Dijkstra(int V){
        d.resize(V, INF);
        dp.resize(V, 0);
    }
    void calc(int s){
        d[s] = 0;
        dp[s] = 1;
        priority_queue<P, vector<P>, greater<P> > q;
        q.push(P(d[s], s));
        while(!q.empty()){
            P p = q.top(); q.pop();
            int from = p.second;
            int cost = p.first;
            if(d[from] < cost) continue;
            rep(i, 0, G[from].size()){
                int next = G[from][i].to;
                int newCost = cost + G[from][i].cost;
                if(d[next] > newCost){
                    d[next] = newCost;
                    dp[next] = dp[from];
                    q.push(P(newCost, next));
                }else if(d[next] == newCost){
                    dp[next] = (dp[next] + dp[from]) % mod;
                }
            }
        }
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<int> u(m), v(m), d(m);
    rep(i, 0, m){
        cin >> u[i] >> v[i] >> d[i];
        u[i]--; v[i]--;
        G[u[i]].push_back({v[i], d[i]});
        G[v[i]].push_back({u[i], d[i]});
    }
    Dijkstra ds1(n), ds2(n);
    ds1.calc(s);
    ds2.calc(t);
    int len = ds1.d[t];
    int ans = ds1.dp[t] * ds1.dp[t] % mod;
    rep(i, 0, n){
        if(ds1.d[i] * 2 == len){
            ans = (ans - ds1.dp[i] * ds1.dp[i] % mod * ds2.dp[i] % mod * ds2.dp[i] % mod + mod) % mod;
        }
    }
    rep(i, 0, m){
        if(ds1.d[u[i]] > ds1.d[v[i]]) swap(u[i], v[i]);
        int pre = 2 * ds1.d[u[i]];// + ds2.d[v[i]];
        int aft = 2 * ds1.d[v[i]];// + ds2.d[u[i]];
        // if(ds1.d[u[i]] + d[i] != ds1.d[v[i]]) continue;
        if(ds1.d[u[i]] + d[i] + ds2.d[v[i]] != len) continue;
        if(pre < len && len < aft){
            ans = (ans - ds1.dp[u[i]] * ds1.dp[u[i]] % mod * ds2.dp[v[i]] % mod * ds2.dp[v[i]] % mod + mod) % mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23508
#include<stdio.h>
   
int main(){
   
int hcnt,bcnt,i,j,a[4]={0},b[4]={0};
 
while(scanf("%d %d %d %d\n", &a[0],&a[1],&a[2],&a[3])!=EOF){
   scanf("%d %d %d %d\n", &b[0],&b[1],&b[2],&b[3]);
   hcnt=0;
   bcnt=0;

   for(i = 0; i < 4; i++)
      for(j=0;j<4;j++)
      {
        if(i==j){
          if(a[i] == b[j]) hcnt = hcnt+1;
        }else{
          if(a[i] == b[j]) bcnt = bcnt+1; 
        }
      }

    printf("%d %d\n", hcnt,bcnt);  
}
   
    return 0;
}

Measured memory_bytes: 600
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class NewClassC
{
    static void Main(string[] args)
    {
        var line1 = Console.ReadLine().Trim();
        var N = int.Parse(line1);

        int max = 1;
        var dict = new Dictionary<string, int>();
        for (var i = 0; i < N; i++)
        {
            var line2 = Console.ReadLine().Trim();
            int k;
            if (dict.TryGetValue(line2, out k))
            {
                dict[line2] = k + 1;
                max = Math.Max(max, k + 1);
            }
            else
            {
                dict.Add(line2, 1);
            }
        }

        var maxs = dict.Where(v => v.Value == max).Select(v => v.Key).ToList();
        maxs.Sort(StringComparer.OrdinalIgnoreCase);

        Console.WriteLine(string.Join("\n", maxs));

    }
}


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

int keta(int n) {
    int res;
    for(int i = 0; i < 100; i++) {
        n = n / 10;

        if(n == 0) {
            res = i + 1;
            break;
        }
    }
    return res;
}

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    rep(i, 1000000) {
        c = c - b;
        if(c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a = a - d;
        if(a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}


Measured memory_bytes: 3672
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 1000009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int n,a[maxn];

int main()
{
    //freopen("d:\\in.txt","r",stdin);
    scanf("%d",&n);
    int x=0,y=0,z=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            x++;
        else if(a[i]%2==0)
            y++;
        else
            z++;
    }
    //printf("%d %d %d\n",x,y,z);
    if(z-x>1)
        printf("No\n");
    else if(y&&z-x==1)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int n;
int q,d,x;
deque<int>v;
int main(){
    cin>>n;
    while(n--){
        cin>>q>>d;
        if(q==0){
            cin>>x;
            if(d==0)v.push_front(x);
            else v.push_back(x);
        }
        if(q==1)cout<<v[d]<<endl;
        if(q==2){
            if(d==0)v.pop_front();
            else v.pop_back();
        }
    }
    return 0;
}



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

using namespace std;

int main()
{
	const string Class[11] = { "light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy" };

	const double Class_Weight[12] = { 0.0, 48.0, 51.0, 54.0, 57.0, 60.0, 64.0, 69.0, 75.0, 81.0, 91.0, 1000.0 };

	const int DATASETS = 1000;

	double Weight[DATASETS]; int C = 0;

	while (cin >> Weight[C])
	{
		C++;
	}

	for (int i = 0; i < C; i++)
	{
		for (int j = 0; j < 11; j++)
		{
			if (Class_Weight[j] < Weight[i] && Weight[i] <= Class_Weight[j + 1])
			{
				cout << Class[j] << endl;
			}
		}
	}

	return 0;
}

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

 
int main() {
	int k;
	cin>>k;
	ll val=7;
	int count=0;
	bool temp=true;
	if(k%2==0)
	{
		cout<<-1<<endl;
	}
	else
	{
		while(true)
		{
			if(val%k==0)
			{
				count++;
				break;
			}
			else if(count>k)
			{
				temp=false;
				break;
			}
			else
			{
				val=(val%k)*10+7;
				count++;
			}
		}
		if(temp)
		{
			cout<<count<<endl;
		}
		else
		{
			cout<<-1<<endl;
		}
	}
	
	
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front()) {
        cout << "YES" << endl;
    } else
        cout << "NO" << endl;
}

Measured memory_bytes: 3608
N, d1, xx = map(int, raw_input().split())

d = d1*1.0
x = xx*1.0

res = 0.0

while N > 1:
    res += (2*d + (2*N-1)*x) / 2
    d *= 1.0 + 1.0 / N
    d += x * 5.0/(2*N)
    x *= 1.0 + 2.0 / N
    N -= 1

print "{:.12f}".format(res + d + x/2)

Measured memory_bytes: 2568
#include <cstdio>

int n,x,y;

int main()
{
	scanf("%d%d%d",&n,&x,&y);
	if ((n>1) && (x<=y))
		printf("%lld\n",1LL*(n-1)*(y-x)+x-y+1);
	else
		if ((n==1) && (x==y))
			printf("1\n");
		else
			printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
    char s[15],t[15],u[15];
    int a,b,d1,d2;
    scanf("%s %s",s,t);
    scanf("%d %d",&a,&b);
     scanf("%s",u);
    if(strcmp(u,s)==0)
    {
        printf("%d %d\n",a-1,b);
    }
    else if(strcmp(u,t)==0)
    {
        printf("%d %d\n",a,b-1);
    }
    return 0;
}


Measured memory_bytes: 128
import numpy as np

n = int(input())

a = []
for i in range(n):
    a.append(int(input()))

a = np.array(a)

max_a = a.max()
ans = np.array([max_a for i in range(n)])

max_ind = np.where(a == max_a)[0]

if len(max_ind) == 1:
    b = np.sort(a)
    ans[max_ind] = b[-2]

for i in ans:
    print(i)

Measured memory_bytes: 21860
#include <iostream>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = false;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct edge1 { ll from, to, cost; };
double pai = 3.141592653589793;

int main() {
	ll n, a[100010];
	cin >> n;
	a[0] = 0;
	a[n + 1] = 0;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	ll sum = 0;
	for (int i = 1;i <= n + 1;i++) {
		sum += abs(a[i] - a[i - 1]);
	}
	for (int i = 1;i <= n;i++) {
		if (i == n) {
			ll ans = 0;
			a[n] = 0;
			for (int i = 1;i <= n;i++) {
				ans += abs(a[i] - a[i - 1]);
			}
			cout << ans << endl;
		}
		else if (i == 1) {
			ll ans = 0;
			int j = a[1];
			a[1] = 0;
			for (int i = 2;i <= n + 1;i++) {
				ans += abs(a[i] - a[i - 1]);
			}
			cout << ans << endl;
			a[1] = j;
		}
		else {
			cout << sum - (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i])) + abs(a[i - 1] - a[i + 1]) << endl;
		}
	}
}

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

int main()
{
    int N;
    string S;
    string T;
    
    cin >> N;
    cin >> S;
    cin >> T;

    for(int i=0; i<N; i++){
        cout << S[i];
        cout << T[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin>>N>>M;
  vector<pair<long long,long long>>AB(N);
  for(int X=0;X<N;X++){
    int A,B;
    cin>>A>>B;
    AB[X]=make_pair(A,B);
  }
  sort(AB.begin(),AB.end());
  long long K=0;
  long long F=0;
  for(int X=0;X<N;X++){
    long long C,D;
    tie(C,D)=AB[X];
    if(F+D<=M){
      K+=C*D;
      F+=D;
    }
    else{
      K+=C*(M-F);
      F+=M-F;
      break;
    }
  }
  cout<<K<<endl;
}

Measured memory_bytes: 4804