akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [int(input()) for _ in range(N)]
A=sorted(A)
 
ans=0
cnt=1
tmp=A[0]
 
for i in range(1,N):
    if A[i]==tmp:
        cnt+=1
    else:
        if cnt%2!=0:
            ans+=1
        cnt=1
    tmp=A[i]
    
if cnt%2==1:
    ans+=1
print(ans)

Measured memory_bytes: 14044
using System;

namespace aoj5a
{
    class Program
    {
        static int Main(string[] args)
        {
            for (;;)
            {
                string[]HandW = (Console.ReadLine()).Split(' ');
                int H = int.Parse(HandW[0]);
                int W = int.Parse(HandW[1]);

                if(H+W == 0)
                {
                    return 0;
                }

                string line = null;

                for (int i = 1; i <= W; i++)
                {
                    line += '#';
                }

                for (int i = 1; i <= H; i++)
                {
                    Console.WriteLine(line);
                }

                Console.WriteLine();
            }


            
        }
    }
}

Measured memory_bytes: 8824
import collections
import heapq

from collections import defaultdict
from heapq import heappush, heappop
import sys


def main(K, N):
    P = 10 ** 9 + 7

    P25 = [1] * (K + 1)
    P26 = [1] * (K + 1)
    F = [1] * (N + K)
    INV = [1] * (N + K)
    INVF = [1] * (N + K)

    p25 = 1
    p26 = 1
    for i in range(1, K + 1):
        p25 *= 25
        p25 %= P
        P25[i] = p25

        p26 *= 26
        p26 %= P
        P26[i] = p26

    f = 1
    invf = 1
    for i in range(2, N + K):
        f *= i
        f %= P
        F[i] = f
        q, r = divmod(P, i)
        INV[i] = -INV[r] * q % P
        invf *= INV[i]
        invf %= P
        INVF[i] = invf

    def comb_rep(n, r):
        return (F[n + r - 1] * INVF[r] % P) * INVF[n - 1] % P

    ret = 0
    for i in range(K + 1):
        ret += (
            P25[i] *
            P26[K - i] % P *
            comb_rep(N, i) % P
        )
    return (ret % P)


if sys.argv[-1] == 'ONLINE_JUDGE':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'i8(i8,i8)')(main)
    cc.compile()
    exit()
else:
    from my_module import main
    K = int(input())
    S = input()
    print(main(K, len(S)))


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

int main()
{
	int W, H = 0;
	char c = '#';
	cin >> H >> W;
	do {
		for (int i = 0; i < H; i++)
		{
			if (i % 2 == 0)
			{
				c = '#';
			}
			else
			{
				c = '.';
			}
			for (int j = 0; j < W; j++)
			{
				cout << c;
				if (c == '#')
				{
					c = '.';
				}
				else
				{
					c = '#';
				}
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	} while ((H != 0) || (W != 0));//?¶??¶??????¶
	return 0;
}

Measured memory_bytes: 3084
#include "stdio.h"
#include "math.h"

double x1,x2;
double yy1,yy2;

int main(){
	scanf("%lf %lf %lf %lf",&x1,&yy1,&x2,&yy2);
	double ans=sqrt((x1-x2)*(x1-x2)+(yy1-yy2)*(yy1-yy2));
	printf("%f\n",ans);
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define sort(a) sort((a).begin(),(a).end())
#define rev(a) reverse((a).begin(),(a).end())
using db = double;
using namespace std;
typedef long long ll;


int main() {
  int n, y;
  cin >> n >> y;
  rep(i,2001) {
    rep(j,2001) {
      if (10000*i+5000*j+1000*(n-i-j) == y && n-i-j >= 0) {
        cout << i << " " << j << " " << n-i-j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


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

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

using ll = long long;
using namespace std;

int main(){
    string s , t;
    cin >> s;
    cin >> t;

    int pos = -1;
    rep(i, s.size()){
        if(s[i] == '?' || s[i] == t[0]){
            int j = 0;
            while((s[i+j] == '?' || s[i+j] == t[j]) && i+j < s.size()){
                //cout << s[i+j];
                j++;
            }
            if(j >= t.size())pos = i;
        }
        //cout << "&" << pos << endl;
    }
    if(pos < 0){
        cout << "UNRESTORABLE";
        return 0;
    }
    rep(i, t.size()){
        s[pos+ i] = t[i];
    }
    rep(i, s.size())if(s[i] == '?')s[i] = 'a';

    rep(i, s.size())cout << s[i];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define ld long double
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define printv(a) {\
    for (auto y : a) cout << y << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define pii pair<int,int> 
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
#define readfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int mod = 998244353, x = 864197532, N = 20, logN = 18, K = 350, all = (1 << N) - 1;

int main () {
	int n, k;
	cin >> n >> k;
	vector <int> len(n);
	fop (i,0,n) cin >> len[i];
	auto ask = [&](int x) {
		lli ans = 0;
		fop (i,0,n) {
			ans += ((len[i] - 1) / x);
		}
		return ans <= k;
	};
	int l = 0, r = 1e9 + 87;
	while (r - l > 1) {
		(ask(l + r >> 1) ? r : l) = l + r >> 1;
	}
	cout << r << endl;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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 p;
vector<int> fac(3100);
vector<int> ifac(3100);

int mpow(int x, int n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    int ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % p;
        x = x*x % p;
        n = n >> 1;
    }
    return ans;
}

int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % p;
    return tmp * fac[a] % p;
}


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

    cin >> p;
    vector<int> a(p);

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

    vector<int> coef(p);
    for(int i = 0; i < p; i++) coef[i] = 0;

    fac[0]  = 1;
    ifac[0] = 1;
    for(int i = 0; i < 3000; i++){
        fac[i+1]  = fac[i] * (i+1) % p;
        ifac[i+1] = ifac[i] * mpow(i+1, p-2) % p;
    }

    int c;
    for(int i = 0; i < p; i++){
        if(a[i] == 1){
            for(int j = 0; j < p; j++){
                c = (comb(p-1, p-1-j)%p) * (mpow(-i, p-1-j)%p) % p;
                coef[j] -= c;
                if(coef[j] < 0){
                    coef[j] += (abs(coef[j] % p) + 1) * p;
                }
                coef[j] = coef[j] % p;
            }
            coef[0] += 1;
            coef[0] = coef[0] % p;
        }
    }

    for(int i = 0; i < p; i++){
        cout << coef[i] << " ";
    }
    cout << endl;


    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	
	int k[n+5];
	
	for(int i=1;i<=n;i++)
	{
		cin>>k[i];
	}
	
	int minv=999999;
	for(int i=1;i<=n;i++)
	{
		int a=0,b=0;
		for(int j=1;j<=i;j++)
		{
			a+=k[j];
		}
		
		for(int j=i+1;j<=n;j++)
		{
			b+=k[j];
		}
		
		if(minv>abs(a-b))
		{
			minv=abs(a-b);
		}
	}
	
	cout<<minv;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    char str[256];
    scanf("%d",&n);
    scanf("%s",str);
    if(n%2){
        printf("No\n");
        return 0;
    }
    
    for(int i=0;i<n/2;i++){
        if(str[i]!=str[i+n/2]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, P> DP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

//// UnionFind
struct UnionFind{
	vector<int> v;
	UnionFind(int n) : v(n, -1) {}

	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
		return true;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int n;
double x[111],y[111],z[111],r[111];
vector<DP> es;

double dist(int i,int j){
	return sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2)+pow(z[i]-z[j],2));
}

bool judge(int i,int j){
	if(dist(i,j)<=r[i]+r[j])return true;
	else return false;
}

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		rep(i,n){
			cin>>x[i]>>y[i]>>z[i]>>r[i];
		}
		es.clear();
		UnionFind uf(n);
		rep(i,n)rep(j,i){
			if(judge(i,j))uf.unite(i,j);
			else{
				es.pb(DP(dist(i,j)-r[i]-r[j],P(i,j)));
			}
		}
		sort(all(es));
		double res=0;
		rep(i,es.size()){
			if(uf.same(es[i].se.fi,es[i].se.se))continue;
			res+=es[i].fi;
			uf.unite(es[i].se.fi,es[i].se.se);
		}
		printf("%.3f\n", res);
	}
	return 0;
}

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

int main()
{
	long double a, b, c; cin >> a >> b >> c;
	
	string ans = "No";

	long double tmp_ab = a + b + 2 * sqrt(a)*sqrt(b);

	if (tmp_ab < c ) {
		ans = "Yes";
	}

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

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

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

  vector<int> c(n);
  vector<vector<int>> M(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    int node;
    int d;
    cin >> node >> d;
    node--;

    for (int j = 0; j < d; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      M[i][tmp] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << M[i][j];
      if (j != n - 1) { cout << " "; }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    bool arr[100005];

    for(int i=0;i<100005;i++)
        arr[i]=false;
    arr[0]=false;
    for(int i=0;i<n;i++)
    {
        arr[a[i]]=true;
    }
    for(int i=0;i<=(k-a[0]);i++)
    {
        if(arr[i]==false)
        {
            for(int j=0;j<n;j++)
            {
                if(i+a[j]<=k)
                {
                    arr[i+a[j]]=true;
                }
            }
        }

    }
    if(arr[k]==true)
    {
        cout<<"First";
    }
    else
    {
        cout<<"Second";
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>

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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }




int main() {
    ll x;
    cin >> x;
    YES(x == 3 || x == 5 || x == 7);
}


Measured memory_bytes: 256
MOD = 10**9 + 7
N,K= map(int,input().split())
A = list(map(int,input().split()))
#N = 100000
#K = 10
#A = list(range(N))

A.sort()

if K == 1:
    print(0)
    exit()

n = 100001
fact = [1]*(n+1)
inv = [1]*(n+1)
ifact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = (fact[i-1]*i) % MOD
    inv[i] = pow(i,MOD-2,MOD)
    ifact[i] = (ifact[i-1]*inv[i]) % MOD

def nCr(n,r):
    return (fact[n] * ifact[r] * ifact[n-r]) % MOD

ans = 0

for i in range(K-1,N):
    ans += A[i] * nCr(i,K-1)
    ans %= MOD

for i in range(N-K+1):
    ans -= A[i] * nCr(N-i-1,K-1)
    ans %= MOD

'''
for l in range(N):
    for r in range(l+K-1,N):
        temp = (A[r]-A[l]) * nCr(r-l-1,K-2)
        ans = (ans + temp) % MOD
        '''

print(ans)






Measured memory_bytes: 63472
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 998244353;
int main() {
    int N; cin >> N;
    string S; cin >> S;
    array<int, 8> B = {};
    Int ans = 1;
    for (int i = 0; i < 3*N; i++) {
        int b = (S[i] == 'R' ? 1 : S[i] == 'G' ? 2 : 4);
        if (B[7 ^ b]) {
            ans = ans * B[7 ^ b] % MOD;
            B[7 ^ b] -= 1;
        } else if (b != 1 && B[1]) {
            ans = ans * B[1] % MOD;
            B[1] -= 1;
            B[1 ^ b] += 1;
        } else if (b != 2 && B[2]) {
            ans = ans * B[2] % MOD;
            B[2] -= 1;
            B[2 ^ b] += 1;
        } else if (b != 4 && B[4]) {
            ans = ans * B[4] % MOD;
            B[4] -= 1;
            B[4 ^ b] += 1;
        } else {
            B[b] += 1;
        }
    }
    for (int i = 1; i <= N; i++) ans = ans * i % MOD;
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

int main()
{
	string divide[4] = { "dream", "dreamer", "erase", "eraser" };

	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	for (int i = 0; i < 4; i++) {
		reverse(divide[i].begin(), divide[i].end());
	}

	for (int i = 0; i < s.size();) {
		bool isDivide = false;
		for (int j = 0; j < 4; j++) {
			string d = divide[j];
			if (s.substr(i, d.size()) == d) {
				isDivide = true;
				i += d.size();
			}
		}
		if (!isDivide) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;
  
int main() {
  int X,t;
  cin >> X >> t;
  cout << max(X-t,0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;

ll x[100005];
ll y[100005];

int main() {

	ll n, m;

	scanf("%lld %lld", &n, &m);

	int i;

	for (i = 0; i < n; i++) {
		scanf(" %lld",&x[i]);
	}
	for (i = 0; i < m; i++) {
		scanf(" %lld", &y[i]);
	}

	ll sum1 = 0ll;
	ll mod = 1000000007ll;

	ll j;

	for (j = 0ll; j < (ll)n; j++) {
		ll a = j - (n - 1 - j);
		ll tmp = x[(int)j] % mod;
		tmp *= a;
		tmp %= mod;
		sum1 += tmp;
		sum1 %= mod;
	}

	ll sum2 = 0ll;

	for (j = 0ll; j < (ll)m; j++) {
		ll a = j - (m - 1 - j);
		ll tmp = y[(int)j] % mod;
		tmp *= a;
		tmp %= mod;
		sum2 += tmp;
		sum2 %= mod;
	}

	ll ans = sum1 % mod;

	ans *= sum2;

	ans %= mod;

	printf("%lld\n",ans);

	return 0;
}

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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int N,T; cin>>N>>T;
    vint c(N), t(N);
    rep(i,N)cin>>c[i]>>t[i];
    int ans = inf;
    rep(i,N){
        if(t[i]<=T)ans = min(ans,c[i]);
    }
    if(ans == inf)cout<<"TLE"<<endl; 
    else cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

using namespace std;

int
main() {
  string s;
  cin>>s;

  int ans = 0;
  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
    ans = 1;
 
  cout<<ans<<endl;
  return 0;
}



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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

bool isNoNeed(const vector<int>& a, int K, int x) {
  //cout << x << endl;
  int N = a.size();
  vector<int> b(a);
  b.erase(b.begin() + x);
  vector<vector<bool>> dp(N, vector<bool>(K, false));
  dp[0][0] = true;
  REP(i,N - 1)REP(j,K) {
    dp[i + 1][j] = dp[i + 1][j] || dp[i][j];
    if(j + b[i] < K) dp[i + 1][j + b[i]] = dp[i + 1][j + b[i]] || dp[i][j];
  }
  /*
  REP(i,N) {
    REP(j,K) cout << " " << dp[i][j];
    cout << endl;
  }
  */
  for(int i = max(0, K - a[x]); i < K; ++i) {
    if(dp[N - 1][i]) return false;
  }
  return true;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  REP(i,N) cin >> a[i];
  sort(ALL(a));

  int res = 0;
  if(isNoNeed(a, K, 0)) {
    for(int p = 1<<30; p; p >>= 1) {
      if(res + p < N && isNoNeed(a, K, res + p)) res += p;
    }
    ++res;
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 3640
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    A,B=pin()
    S=input()
    for i in range(A+B+1):
        if i==A:
            if S[i]!="-":
                print("No")
                return
        else:
            if S[i]=="-":
                print("No")
                return
    print("Yes")
        
#%%submit!    
resolve()

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

int main(){
    long long n,a,b,now,back,tired,ans = 0;
    cin >> n >> a >> b;
    cin >> back;
    for(int i = 0;i < n - 1;i++){
        cin >> now;
        tired = (now - back) * a;
        ans += min(tired,b);
        back = now;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int ans = 0;
    int cnt = 0;
    while(ans != X){
        ans += Z;
        ans += Y;
        cnt++;
        if(X - ans < Y + 2 * Z)
            break;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0586

"""
import sys
from sys import stdin
from itertools import product
input = stdin.readline


def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True


def solve(n, c):
    if c >= 0:
        dummy = int('9'*n + str(c) + '9'*n)
    else:
        dummy = int('9'*n + '9'*n)

    # https://www.ioi-jp.org/joi/2005/2006-m1-prob_and_sol/2006-m1-t5-review.html
    if n > 4:
        return dummy

    found = False
    ans = -1
    for p in product('9876543210', repeat=n):
        if p[0] == '0':
            continue
        t = ''.join(p)
        if c >= 0:
            ans = int(t + str(c) + t[::-1])
        else:
            ans = int(t + t[::-1])
        if is_prime(ans):
            found = True
            break

    if found:
        return ans
    else:
        return dummy


def main(args):
    n, c = map(int, input().split())
    result = solve(n, c)
    print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7884
import fractions
from functools import reduce

mod = 10**9 + 7

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
a = list(map(int, input().split()))
a_ = []
for i in range(n):
    a_.append(pow(a[i], mod - 2, mod))

num_lcm = lcm(*a) % mod
ans = 0
for i in range(n):
    ans = (ans + num_lcm * a_[i] % mod) % mod

print(ans)

Measured memory_bytes: 6264
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
signed main()
{
    int a;
    string s;
    cin>>a>>s;
    if(a<3200)
        cout<<"red";
    else cout<<s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int N, i;
	cin >> N >> i;
	cout << N - i + 1 << endl;
}

Measured memory_bytes: 256
s = input()

def func(st,char):
    ans = [None] * (len(st) - 1)
    for i in range(len(ans)):
        if st[i] == c or st[i + 1] == c:
            ans[i] = c
        else:
            ans[i] = st[i]
    # print(ans)
    return ''.join(ans)
m = 10 ** 5
for i in range(26):
    work = s
    c = chr(ord('a') + i)
    # print(c)
    cnt = 0
    while len(set(list(work))) != 1:
        work = func(work, c)
        cnt += 1
        # print(s, len(set(list(s))))
    m = min(m, cnt)
print(m)



Measured memory_bytes: 42604
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,a,b;
	cin>>n>>a>>b;
	int quo=n/(a+b),rem=n%(a+b);
	quo*=a;
	quo+=min(rem,a);
	cout<<quo<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
if N == 1:
    print(0)
    exit()


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


primes = factorization(N)

count = 0
for p in primes:
    c = 0
    t = 0
    for i in range(1, 10 ** 9):
        c += i
        t += 1
        if c > p[1]:
            count += t - 1
            break
        elif c == p[1]:
            count += t
            break

print(count)


Measured memory_bytes: 9404
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

int a[3];

int main(){
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	cout << a[0] << " " << a[1] << " " << a[2] << "\n";
	return 0;
}

Measured memory_bytes: 3148
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll facmemo[200000] = {};

ll factorial(ll n) {//階乗
	if (facmemo[n] != 0) return facmemo[n];
	if (n == 0) return 1;
	ll ret = n * factorial(n-1);
	ret %= MODU;
	return facmemo[n] = ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
	if (r == 0) return 1;
	if (n < r) return 1;
	return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU);
}

bool sankaku(int a, int b, int c) {
	return a <= b + c && b <= a + c && c <= b + a;
}

signed main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	ll ans = 0;
	REP(i, n)
		cin >> a[i];

	sort(ALL(a));

	rep(i,k-1,n) {
		ans += ncr(i, k-1) * a[i] % MODU;
		ans %= MODU;
	}

	REP(i, n - k + 1) {
		ans -= ncr(n-i-1, k-1) * a[i];
		ans %= MODU;
	}

	cout << (ans + MODU) % MODU << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;

const ll inf = numeric_limits<ll>::max();
const int lim = 1000;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, w;
    cin >> n >> w;

    ll v[n], p[n], dp[n * lim + 1];
    for(int i = 0; i < n; i++) cin >> p[i] >> v[i];

    fill(dp, dp + lim * n + 1, inf);
    dp[0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = lim * n; j >= 0; j--)
            if(j - v[i] >= 0 && dp[j - v[i]] != inf)
                dp[j] = min(dp[j], dp[j - v[i]] + p[i]);
    }

    for(int i = lim * n; i >= 0; i--)
        if(dp[i] <= w){
            cout << i << endl;
            return 0;
        }
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    vector<int> A(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ll sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    sort(A.rbegin(), A.rend());
    vector<int> res(N);
    queue<int> que;

    int ptr = 0;
    que.push(0);

    vector<int> used(N);

    while(!que.empty()) {
        int v = que.front();
        used[v] = 1;
        res[v] = A[ptr];
        ptr++;
        que.pop();
        for(int nv : G[v]) {
            if(used[nv])
                continue;
            que.push(nv);
        }
    }
    cout << sum - A[0] << endl;
    rep(i, N) cout << res[i] << " ";
    cout << endl;
    return 0;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 100400;
const ll inf = 1e18+5;

int main() {
	fastio;
	ll x,y;
	cin>>x>>y;
	if(x*4>=y && y%2==0 && y>=x*2) yes;
	else no;
	return 0;
	}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i = i + 2) {
        int cnt = 0;
        int limit = sqrt(n);
        for (int j = 1; j <= n; j = j + 2) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int f[42][42];

int dp[1 << 20];

int const MOD = 1000000007;

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

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      f[i][j] = -1;
    }
  }
  for (int i = 0; i < k; i++) {
    int who, where, what;
    scanf("%d%d%d", &who, &where, &what);
    --who;
    --where;
    f[who][where] = what;
  }
  for (int i = 0; i < 1 << (n - 1); i++) dp[i] = 0;
  dp[0] = 1;
  for (int q = 0; q < m; q++) {
    for (int pos = 0; pos < n - 1; pos++) {
      for (int mask = 0; mask < 1 << (n - 1); mask++) {
        if (((mask >> pos) & 1) == 1) {
          continue;
        }
        int nmask = mask ^ (1 << pos);
        int npos = pos + 1;
        while (npos < n - 1 && ((nmask >> npos) & 1) == 0) {
          ++npos;
        }
        if (npos < n - 1) {
          nmask &= ~(1 << npos);
        }
        add(dp[nmask], dp[mask]);
      }
    }
    int ones = 0;
    int zeros = 0;
    for (int i = 0; i < n - 1; i++) {
      if (f[q][i] == 0) {
        zeros |= 1 << i;
      } else if (f[q][i] == 1) {
        ones |= 1 << i;
      }
    }
    for (int mask = 0; mask < 1 << (n - 1); mask++) {
      if ((mask & ones) != ones || (~mask & zeros) != zeros) {
        dp[mask] = 0;
      }
    }
    // printf("q = %d\n", q);
    // for (int mask = 0; mask < 1 << (n - 1); mask++) {
    //   printf(" mask = %d, val = %d\n", mask, dp[mask]);
    // }
  }
  int ans = 0;
  for (int i = 0; i < 1 << (n - 1); i++) add(ans, dp[i]);
  printf("%d\n", ans);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan= new Scanner(System.in);
		String s=scan.next();
		int c=0;
		for(int i=0;i<s.length()-1;i++)
		{
			if(s.charAt(i)==s.charAt(i+1))
			{
				c=1;
			}
		}
		if(c==1)System.out.println("Bad");
		else System.out.println("Good");

	}

}


Measured memory_bytes: 26700
#include <bits/stdc++.h>
using namespace std;
 
int N, A[300000];
 
int main(){
    cin >> N;
    for(int i=0;i<3*N;i++)    cin >> A[i];
    
    sort(A, A+3*N, greater<int>());
 
    int64_t ans = 0;
    for(int i=1;i<N*2;i+=2)  ans += A[i];
 
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n)
    {
        cin >> h[i];
    }
    int counter = 0;
    rep(i,n)
    {
        if (h[i]>=k)
        {
            counter++;
        }
        
    }

    cout << counter << endl;
}

Measured memory_bytes: 640
from string import ascii_lowercase
import sys
table = dict(zip(ascii_lowercase, [0 for _ in range(len(ascii_lowercase))]))

for s in sys.stdin:
    for c in s:
        if c.lower() in table:
            table[c.lower()] += 1
for k, v in table.items():
    print("{} : {}".format(k, v))



Measured memory_bytes: 6684
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ab = max(a-b, b-a);
  int ac = max(a-c, c-a);
  int bc = max(c-b, b-c);
  if(d>=ac) cout << "Yes" << endl;
  else if(d>=ab&&d>=bc) cout << "Yes" << endl;
  else  cout << "No" << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		char[] inS = stdin.next().toCharArray();
		List<Integer> xList = new ArrayList<>();
		List<Integer> yList = new ArrayList<>();
		boolean moveX = true;
		int move = 0;
		for (char s : inS) {
			if (s == 'F') {
				move++;
			}
			else {
				if (moveX) {
					xList.add(move);
					moveX = false;
				}
				else {
					yList.add(move);
					moveX = true;
				}

				move = 0;
			}
		}
		if (move > 0) {
			if (moveX) {
				xList.add(move);
			}
			else {
				yList.add(move);
			}
		}

		int inX = stdin.nextInt() - xList.remove(0);
		int inY = stdin.nextInt();

		Collections.sort(xList);
		Collections.reverse(xList);
		Collections.sort(yList);
		Collections.reverse(yList);

		String result = "No";
		if (check(inX, xList) && check(inY, yList)) {
			result = "Yes";
		}

		System.out.println(result);
	}

	private static boolean check(int target, List<Integer> list) {
		for (int move : list) {
			if (target > 0) {
				target -= move;
			}
			else {
				target += move;
			}
		}

		return target == 0;
	}
}


Measured memory_bytes: 24276
M,*li = [list(map(int,i.split())) for i in open(0)]
M = M[0]
row = [[x-y,x+y] for x,y in li]
row.sort(key = lambda x:x[1])
ans = 0
s = -1*float('inf')
for rs,rt in row:
    if s <= rs:
        ans += 1
        s = rt
print(ans)

Measured memory_bytes: 43772
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        new Main().solve();
    }

    void solve(){

        String s;
        int q;

        Scanner sc = new Scanner(System.in);
        s = sc.next();
        q = Integer.parseInt(sc.next());                

        int count = 0;

        LinkedList<String> string = new LinkedList<String>();
        for(int i=0; i<s.length(); i++){
            String s1 = "";
            s1 = String.valueOf(s.charAt(i));
            string.push(s1);
        }

        boolean first = false;           //trueのときリストのfirst が先頭
        while(count < q){
            int t = Integer.parseInt(sc.next());
            if(t == 1){                       //反転
                first = !first;
            }
            else{
                int f = Integer.parseInt(sc.next());
                String c = sc.next();

                if(first){
                    if(f == 1){
                        string.addFirst(c);
                    }
                    else{
                        string.addLast(c);
                    }
                }
                else{
                    if(f == 1){
                        string.addLast(c);
                    }
                    else{
                        string.addFirst(c);
                    }
                }
            }
            count ++;
        }
        sc.close();
        
        String output;
        StringBuilder sb = new StringBuilder();
        if(first){
            ListIterator<String> it = string.listIterator(0);
            while(it.hasNext()){
                sb.append(it.next());
            }
        }
        else{
            ListIterator<String> it = string.listIterator(string.size());
            while(it.hasPrevious()){
                sb.append(it.previous());
            }
        }
        output = sb.toString();

        System.out.println(output);
    }
}

Measured memory_bytes: 110996
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
P_Y = [[int(_) for _ in input().split()] for _ in range(M)]
datalist = []

for i, j in enumerate(P_Y):
    datalist.append([i, j[0], j[1], 0])

datalist = sorted(datalist, key=lambda x: (x[1], x[2]))
num = 1
city = datalist[0][1]
datalist[0][3] = num

for i in range(1, M):
    if datalist[i][1] == datalist[i-1][1]:
        num += 1
        datalist[i][3] = num
    else:
        num = 1
        datalist[i][3] = num

datalist = sorted(datalist, key=lambda x: x[0])
for i in datalist:
    print(str(i[1]).zfill(6) + str(i[3]).zfill(6))

Measured memory_bytes: 46076
import java.io.*;
 
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String strArr[] = str.split(" ");
 
        int w, h, x, y, r;
 
        w = Integer.parseInt(strArr[0]);
        h = Integer.parseInt(strArr[1]);
        x = Integer.parseInt(strArr[2]);
        y = Integer.parseInt(strArr[3]);
        r = Integer.parseInt(strArr[4]);
 
        if(x+r<=w && x-r>=0 && y+r<=h && y-r>=0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24296
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

////////////////////////////////////////////////////////////////////

struct UnionFind {
	vector<ll> par,siz; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(ll N) : par(N),siz(N, 1LL) { //最初は全てが根であるとして初期化
		for (ll i = 0; i < N; i++) par[i] = i;
	}
   


	ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(ll x, ll y) { // xとyの木を併合
		ll rx = root(x); //xの根をrx
		ll ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		if(siz[rx]<siz[ry]) swap(rx,ry);
        siz[rx]+=siz[ry];
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

    ll size(ll x){
        return siz[root(x)];
    }
};

int main() {
ll n,k;
cin>>n>>k;

k=(n-1)*(n-2)/2-k;
if(k<0){
    cout<<-1<<endl;
    return 0;}


int edge[n+1][n+1];
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
if(i>=j){
    edge[i][j]=-5;
    continue;
}
if(i==1){
    edge[i][j]=1;
}
if(i!=1){
    edge[i][j]=0;
}
    }
}
  
  


int fin=0;
ll cnt=0;
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        if(cnt==k){fin=1;
        break;
        }
        else{
            if(edge[i][j]==0){
                cnt++;
                edge[i][j]=1;
            }
        }

    }
    if(fin) break;
}

cout<<k+n-1<<endl;
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        if(edge[i][j]==1){
            cout<<i<<" "<<j<<endl;

        }
    }
}
return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while(a >= b and k)
	{
		b*=2;
		k--;
	}
	while(b >= c and k)
	{
		c*=2;
		k--;
	}
	if(a < b and b < c)
		cout<<"Yes";
	else
		cout<<"No";
	
}


Measured memory_bytes: 3636
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    vector<ll> num(N + 1, 0);
    vector<ll> ans;
    for (ll i = N - 1; i >= 0; i--) {
        ll sum = 0;
        for (ll j = i + 1; j <= N; j += i + 1) {
            sum += num[j];
        }
        if (sum % 2 != a[i]) {
            ans.push_back(i + 1);
            num[i + 1]++;
        }
    }

    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for (ll i = 0; i < ans.size(); i++) {
        cout << ans[i] << " \n"[i == ans.size() - 1];
    }
}

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

int gcd(int a,int b){
  if(a%b==0){
    return b;
  }
  else{
    return gcd(b,a%b);
  }
}

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(C%gcd(A,B)==0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}
  
  

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc149/tasks/abc149_c

def sosuu?(n)
  x = Math.sqrt(n).to_i

  x.downto(2) do |i|
    return false if n % i == 0
  end
  true
end

X = gets.to_i

loop do
  break if sosuu?(X)
  X += 1
end

puts X


Measured memory_bytes: 1788
from bisect import *
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
C.sort()

ans = 0
for b in B:
    a = bisect_left(A,b)
    c = n - bisect_right(C,b)
    ans += a*c
print(ans)


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

#define pb push_back
#define fr first
#define sc second
typedef pair<int,int> pii;
typedef vector<int> vi;
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
  int mount[10];
  for(int i=0;i<10;i++){
    cin>> mount[i];
  }

  sort(mount,mount+10);
  printf("%d\n%d\n%d\n",mount[9],mount[8],mount[7]);
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int b[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	std::sort(b,b+a);
	printf("%d",b[a-1]);
	int at=0;
	int val=mod;
	for(int i=0;i<a-1;i++){
		if(ABS(b[a-1]-2*b[i])<val){
			at=i;
			val=ABS(b[a-1]-2*b[i]);
		}
	}
	printf(" %d\n",b[at]);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define CFS cin.tie(nullptr);ios::sync_with_stdio(false);
#define CST(x) cout<<fixed<<setprecision(x);
using namespace std;
constexpr int IINF = numeric_limits<int>::max();
constexpr long LINF = numeric_limits<long>::max();
constexpr int MOD = (int) 1e9 + 7;
// constexpr int MOD = 998244353;

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

Measured memory_bytes: 3632