akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
  int n,m,j=0;
  double a[300000],b[300000],f[300000],g[300000];
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    f[i] = a[i];
    g[i] = b[i];
    for(int l=0;l<i;l++){
      if(a[i]==f[l] && b[i] ==b[l]){
        break;
      }
    }
      if(sqrt(a[i]*a[i]+b[i]*b[i]) <= m){
        j++;
      }
      else{
        j+=0;
      }
  }
  cout<<j<<'\n';
  return 0;
}

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

template<class T>
T gcd(T a, T b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

vector<pair<ll, ll>> f(ll x) {
    vector<pair<ll, ll>> y;
    for (ll i = 2; i * i <= x; i++) {
        if (x % i != 0) continue;
        ll cnt = 0;
        while (x % i == 0) {
            cnt++;
            x /= i;
        }

        y.push_back(make_pair(i, cnt));
    }

    if (x != 1) y.push_back(make_pair(x, 1));
    return y;
}

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

    vector<pair<ll, ll>> p = f(gcd(a, b));
    cout << p.size() + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

a.sort()

k = 0;
i = len(a)-1
side = [0, 0]

while i >= 0:
	if a[i] == a[i-1]: 
		side[k] = a[i]
		k += 1
		i -= 1
	if k == 2:
		break
	i -= 1
print(side[0]*side[1])
		
	

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    string s;
    cin >> N >> s;

    map<pair<string, string>, int> mp;
    for (int bits=0; bits<(1<<N); ++bits) {
        string s1 = "", s2 = "";
        for (int i=0; i<N; ++i) {
            if (bits & (1<<i)) s1 += s[i];
            else s2 = s[i] + s2;
        }
        ++mp[make_pair(s1, s2)];
    }
    ll res = 0;
    for (int bits=0; bits<(1<<N); ++bits) {
        string s1 = "", s2 = "";
        for (int i=0; i<N; ++i) {
            if (bits & (1<<i)) s1 += s[i+N];
            else s2 = s[i+N] + s2;
        }
        res += mp[make_pair(s2, s1)];
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 87040
from collections import Counter


N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)

for i, a in enumerate(A):
    S[i + 1] = (S[i] + a - 1) % K

C = Counter()
ans = 0
for j in range(1, N + 1):
    C[S[j - 1]] += 1
    if (j - K) >= 0:
        C[S[j - K]] -= 1

    ans += C[S[j]]


print(ans)


Measured memory_bytes: 41224
import ast

def pattern(li, el, space, acc, xs):
  if len(li) != 1:
    acc.append(el)
    acc.append(space)
    al = li.pop(0)
    pattern(list(li), al, '+', list(acc), xs)
    pattern(list(li), al, '', list(acc), xs)
  else:
    acc.append(el)
    acc.append(space)
    al = li.pop(0)
    acc.append(al)
    xs.append(ast.literal_eval(''.join(acc)))

li = list(input())
el = li.pop(0)
xs = []

if len(li) != 0:
  pattern(list(li), el, '+', [], xs)
  pattern(list(li), el, '', [], xs)

if len(li) != 0:
  print(sum(xs))
else:
  print(int(el))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

i64 dp[2001][2001];
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; i64 x; cin >> N >> x;
    vector<i64> a(N);
    rep(i, N) cin >> a[i];
    i64 sum = 0;
    rep(j, N) {
        dp[0][j] += sum;
        sum += x;
    }
    rep(i, N) {
        i64 mi = 1.0e16;
        rep(j, N) {
            mi = min(mi, a[(i + j) % N]);
            dp[i + 1][j] = dp[i][j] + mi;
        }
    }
    i64 ans = 1.0e16;
    rep(j, N) ans = min(ans, dp[N][j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31616
n = int(input())
def sgs(digit):
  ans = []
  if digit == 1:
    return ["7", "5", "3"]
  else:
    sgs_pre = sgs(digit - 1)
    for str in sgs_pre:
      ans.append(str + "7")
      ans.append(str + "5")
      ans.append(str + "3")
    else:
      return ans
digit = len(str(n))
counter = 0
for i in range(3, digit+1):
  for num in sgs(i):
    if "7" in num and "5" in num and "3" in num:
      if int(num) <= n:
        counter += 1
print(counter)

Measured memory_bytes: 41712
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
	string s;
	cin>>s;
	map<char,ll> mp;
	for(ll i=0;i<4;i++)
		mp[s[i]]++;
	for(auto x:mp)
	{
		if(x.second!=2)
		{
			cout<<"No";
			return;
		}
	}
	cout<<"Yes";
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}

Measured memory_bytes: 3548
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from heapq import *

def main():
	n,d,a=MI()
	Q=[]
	heapify(Q)
	for _ in range(n):
		x=LI()
		heappush(Q,x)

	ans=0
	now=0
	li=[[10**10,0]]
	heapify(li)
	while Q:
		#print(Q,li,ans,now)
		if Q[0][0]<li[0][0]:
			x,h=heappop(Q)
			if h-now>0:
				k=(h-now-1)//a+1
				ans+=k
				now+=k*a
				heappush(li,[x+2*d+1,-k*a])
		else:
			x,h=heappop(li)
			now+=h
	print(ans)
















if __name__ == "__main__":
	main()


Measured memory_bytes: 117732
#include<stdio.h>

int main(){

    int N;
    scanf("%d", &N);

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

    int max = 1;
    int max_index = 1;
    int max_number = 0;
    int second_max = 1;

    for(int i = 0; i < N; i += 1){

        if(A[i] > max){
            max = A[i];
            max_index = i;
            max_number = 1;
        }else if(A[i] == max){
            max_number += 1;
        }
    }

    for (int i = 0; i < N; i += 1){

        if(A[i] < max && A[i] > second_max){
            second_max = A[i];
        }
    }

    if (max_number > 1){
        for (int i = 0; i < N; i += 1){
            printf("%d\n", max);
        }
    }else{
        for (int i = 0; i < N; i += 1){

            if (i == max_index){
                printf("%d\n", second_max);
            }
            else{
                printf("%d\n", max);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<string,ll> P;
typedef pair<P,int> P2;
bool judge(const P2 &p,const P2 &p2){
  if(p.first.first>p2.first.first) return false;
  else if(p.first.first<p2.first.first) return true;
  else{
    return p.first.second>p2.first.second;
  }
}
int main(){
  vector<P2> vec;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    ll p;
    cin>>s>>p;
    vec.push_back(P2(P(s,p),i+1));
  }
  sort(vec.begin(),vec.end(),judge);
  for(int i=0;i<n;i++){
    cout<<vec[i].second<<endl;
  }
}


Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append(v)

s, t = map(int, input().split())
s -= 1
t -= 1
#dfs
from_s = [[-1]*3 for _ in range(n)]
d_s = deque()
d_s.append((s, 0))
from_s[s][0] = 0
while d_s:
    p, count = d_s.popleft()
    next_count = (count + 1) % 3
    for c in edges[p]:
        if from_s[c][next_count] != -1:
            continue
        from_s[c][next_count] = from_s[p][count] + 1
        d_s.append((c, next_count))
if from_s[t] == -1:
    print(-1)
else:
    print(from_s[t][0]//3)


Measured memory_bytes: 100700
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    int n;
    cin>>n;
    cout<<(n*(n+1))/2;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m,a,ans=0;
	priority_queue<ll> q;
	cin >> n >> m;
	rep(i,n){
		cin >> a;
		q.push(a);
	}
	rep(i,m){
		ll tmp=q.top()/2;
		q.pop();
		q.push(tmp);
	}
	rep(i,n){
		ll tmp=q.top();
		ans+=tmp;
		q.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
/****19-Aug-2020*****/
#include<bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ss              set<string> //insert() .top()
#define si              set<int>
#define pii             pair<int,int>
#define vi              vector<int> //push_back()
#define mii             map<int,int>
#define pq              priority_queue<int> //insert()
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define M(arr,n,type)   type *arr=new type[n];
#define T(x)            int x; cin>>x; while(x--)
#define FOR	        for(int i=0;i<n;i++)
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define Mamun           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*erase(start_index,delete_length)*/
/*int myfun(int a,int b)
{
    return a>b;
}
*/
/*sort(vect.rbegin(),vect.rend())*/

void solve(){
    int x;cin>>x;
    if(x==0)cout<<1<<endl;
     if(x==1)cout<<0<<endl;

}



int main()
{
    Mamun;
    //freopen("input.txt","r",stdin);


      solve();


    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>
#include <sstream>
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //for writing to files
    //freopen('input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string seq;
    cin >> seq;
    vector<int> arr;
    for (int i = 0; i < seq.size(); i++) {
        if (seq[i] == '1') {
            arr.PB(1);
        } else if (seq[i] == '0') {
            arr.PB(0);
        } else {
            if (arr.size() > 0) {
                arr.pop_back();
            }
        }
    }
    for (auto x : arr) {
        cout << x;
    }

    return 0;
}


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

P = 0
for i in range(1, N+1):
    if i < K:
        cnt = 0
        while True:
            i *= 2
            cnt += 1
            if i >= K:
                P += 1 / (2 ** cnt)
                break
    else:
        P += 1

print(P / N)

Measured memory_bytes: 2940
X,Y=map(int,input().split())
mod=10**9+7
"""2a+b=X 2b+a=Yを満たすabの並び替え"""
###a+b=(X+Y)/3,a-b=X-Y
###a,b>=0 かつ X+Y(mod3)==0
if (X+Y)%3!=0:
    print("0")##immposible
else:
    a=min(((X+Y)//3+(X-Y))//2,((X+Y)//3-(X-Y))//2)
    b=max(((X+Y)//3+(X-Y))//2,((X+Y)//3-(X-Y))//2)
    ###(a+b)combination a
    c=1
    d=1
    if a>0 and b>=0:
        for i in range(a):
            c*=(a+b-i)
            c=c%mod
            d*=(i+1)
            d=d%mod
        print((c*pow(d,mod-2,mod))%mod)
    elif a==0 and b>0:
        print("1")
    else:
        print("0")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 2050
#define mod 1000000007
using namespace std;
typedef long long LL;

int n, k, tp;
LL fac[N*N], inv[N*N], infac[N*N], F[N][N];

void inc(LL &x, LL y) {x=(x+y)%mod;}

inline LL C(LL n, LL m) {
	if (n < m) return 0LL;
	if (n == m || m == 0) return 1LL;
	return 1LL * fac[n] * infac[m] % mod * infac[n-m] % mod;
}

int main() {
	cin >> n >> k;
	tp = (2000+1) * (2000+1);
	if (k == 1) return puts("1"), 0;
	fac[0] = fac[1] = 1LL;
	for (int i=2;i<=tp;i++)
		fac[i] = 1LL * fac[i-1] * i % mod;
	
	inv[0] = inv[1] = 1LL;
	for (int i=2;i<=tp;i++)
		inv[i] = 1LL * (mod-mod/i) * inv[mod%i] % mod;
	
	infac[0] = infac[1] = 1LL;
	for (int i=2;i<=tp;i++)
		infac[i] = 1LL * infac[i-1] * inv[i] % mod;
		
	F[0][0] = 1LL;
	
	for (int i=0;i<=n;i++)
		for (int j=i;j<=n;j++) {
			if (i) inc(F[i][j], F[i-1][j]);
			if (j) inc(F[i][j], 1LL * F[i][j-1] * C(i+(j-1)*(k-1)+k-2, k-2) % mod);
		}
	
	LL ans = 1LL * F[n][n] * fac[n] % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 131328
#!/usr/bin/env ruby

gets
a = gets.split.map(&:to_i)

@cnt = 0

def mergesort lst
  _mergesort_ lst.dup
end

def _mergesort_ lst
  return lst if (len = lst.size) <= 1
  lst2 = lst.pop(len >> 1)

  _merge_(_mergesort_(lst), _mergesort_(lst2))
end

def _merge_ lst1, lst2
  len1, len2 = lst1.size, lst2.size
  result = Array.new(len1 + len2)
  a, b = lst1[0], lst2[0]
  i, j, k = 0, 0, 0
  loop do
    if a <= b
      result[i] = a
      i += 1
      j += 1
      break unless j < len1
      a = lst1[j]
    else
      @cnt += len1 - j
      result[i] = b
      i += 1
      k += 1
      break unless k < len2
      b = lst2[k]
    end
  end
  while j < len1
    result[i] = lst1[j]
    i += 1
    j += 1
  end
  while k < len2
    result[i] = lst2[k]
    i += 1
    k += 1
  end
  result
end

mergesort(a)
puts @cnt

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto& x: a) cin >> x;
    vector<vector<int>> g(n);
    for (int _ = 1; _ < n; _++) {
        int x,y;
        cin >> x >> y;
        --x;--y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<int> dp(n+1, 2e9), len(n);
    dp[0] = 0;
    function<void(int,int)> dfs = [&](int u, int p){
        int k = lower_bound(dp.begin(), dp.end(), a[u]) - dp.begin();
        len[u] = max(len[u], k);
        int old = dp[k];
        dp[k] = a[u];
        for (int v: g[u])if(v!=p){
            len[v] = max(len[v], len[u]);
            dfs(v, u);
        }
        dp[k] = old;
    };
    dfs(0,-1);
    for (auto& x: len) {
        cout << x << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 36612
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

#define ll long long int
#define MOD 1000000007
#define INF 1e9 + 5
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define pb push_back

struct item {
	ll v,wt;
};


ll solve(vector<item> ar,int N, int W) {
	ll dp[N+1][W+1];

	for(int w= 0; w <=W; w++)dp[1][w] = 0;
	dp[1][ar[1].wt] = ar[1].v;
	/*
	dp(i,w) -> sum of weights of subset of items selected from number 1 to i with 
	weight exactly equal to w(i).
	
	if there is only one item, dp[1][x] (where 0<=x<=W), all conditions where x != w(i)
	will be zero. 
	but if x == w(i) dp[1][x] = value of first item.
	*/

	for(int i = 2; i <= N; i++) {
		for(int w = 0; w<= W; w++) {
			if(ar[i].wt <= w) 
				dp[i][w] = max(dp[i-1][w], ar[i].v + dp[i-1][w-ar[i].wt]);
			else 
				dp[i][w] = dp[i-1][w];
		}
	}
	return *max_element(dp[N], dp[N] + W + 1);

}

int main() {
	fast
	int t=1;
	// cin>>t;
	while(t--) {
		int n,w;
		cin>>n>>w;
		vector<item> ar(n+1);

		for(int i = 1; i <= n; i++) cin>>ar[i].wt>>ar[i].v;

		cout<<solve(ar,n,w)<<"\n";

	}
	return 0;
}


Measured memory_bytes: 78336
import java.util.Scanner;

/**
 * コンソールテスト用Main クラス
 *
 * @author RisaTozawa
 */
public class Main {

	/* コンストラクタ */
	Main() {
	//何もしない
	}

	/**
	 * Atcorder 提出
	 * @return
	 *
	 */

	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int tmpS = 0;
		int h = 0;
		int tmpM = 0;
		int m = 0;
		int s = 0;
		int division = 60;

		tmpS = scanner.nextInt();

		/* 秒 */
		s = tmpS % division;
		/* 分 */
		tmpM = tmpS / division;
		m = tmpM % 60;
		/* 時間 */
		h = tmpM / division;

		System.out.println(h + ":" + m + ":" + s);

	}
}



Measured memory_bytes: 26256
n,x = gets.split(' ').map(&:to_i)
m = n.times.map{gets.to_i}

#Xからmの総和を引く
msum = m.inject(:+)
powder_re = (x - msum)

#余で一番小さいドーナツを可能な限り作る
minimal_daunut = m.min
daunuts0 = (powder_re / minimal_daunut)

#合計、出力
daunuts1 = m.size
puts (daunuts0 + daunuts1)

Measured memory_bytes: 3836
while True:
    H, W = map(int, input().split())
    
    if H == 0 and W ==0:
        break
    
    for i in range(H):
        for j in range(W):
            if i%2 == j%2:
                print('#', end='')
            else:
                print('.', end='')

        print('\r')
        
    print('\r')


Measured memory_bytes: 7040
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <stdio.h>
#define rep(i,o,u) for(int i = o;i <= u; i++)
typedef unsigned long long ll;
using namespace std;
struct point{
	double x;double y;
};
void solve(int n,point a,point b){
	if(n == 0) return ;
	point s,t,u;
	double th = M_PI * 60.0 / 180.0;
	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
	solve(n-1,a,s);
	printf("%0.8f %0.8f\n",s.x,s.y);
	solve(n-1,s,u);
	printf("%0.8f %0.8f\n",u.x,u.y);
	solve(n-1,u,t);
	printf("%0.8f %0.8f\n",t.x,t.y);
	solve(n-1,t,b);
}
int main(){
	int n;
	cin >> n;
	point p1,p2;
	p1.x = 0;p1.y = 0;
	p2.x = 100;p2.y = 0;
	printf("%0.8f %0.8f\n",p1.x,p2.y);
	solve(n,p1,p2);
	printf("%0.8f %0.8f\n",p2.x,p2.y);
	return 0;
}

Measured memory_bytes: 3220
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
using namespace std;
typedef long long LL;
#define ms(a,b) memset(a,b,sizeof(a))
#define eps 1e-8
const int MAXN=1e5+100;

int main ()
{
    int N;
    cin>>N;
    int a=N%10;
    int b=N/10%10;
    int c=N/100%10;
    int d=N/1000%10;
    int ok=0;
    if(d==c&&c==b) ok=1;
    if(c==b&&b==a) ok=1;
    printf("%s",ok?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
import bisect

N, H = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ma = max(A)
B.sort()
idx = bisect.bisect_left(B, ma)
ans = 0
point = 0
for i in range(N - 1, idx - 1, -1):
    ans += 1
    point += B[i]
    if point >= H:
        print(ans)
        break
else:
    diff = H - point
    ans += (diff + ma - 1) // ma
    print(ans)


Measured memory_bytes: 11316
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if( a / (b+c) * (b+c) + c <= a){
        cout << a/(b+c) << endl;
    }else{
        cout << a/(b+c) - 1 << endl;
    }
}


Measured memory_bytes: 256
import sys
from math import sqrt, floor

def divisors(n):
    res = set()
    for i in range(1, floor(sqrt(n)) + 1):
        if not n % i:
            res.add(i)
            res.add(n // i)
    return res - set([1])

n = int(sys.stdin.readline().rstrip())

def main():
    res = divisors(n - 1) 
    cnt = len(res)
    for i in divisors(n):
        m = n
        while not m % i:
            m //= i
        if (m - 1) % i == 0:
            cnt += 1
    print(cnt)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
const int N = 100005;
int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--)
    {
        string s;
      	cin >> s;
      	if(s == "ABC"){
          cout << "ARC";
        }else{
          cout << "ABC";
        }
      
    }
}


Measured memory_bytes: 3636
// 血液型グループ
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	int[] blood = new int[4];
	int i=1;
	while(kbd.hasNext()){
	    String p = kbd.nextLine();
	    int x = 2;
	    int y = p.length();
	    if(i>=10) x++;
	    if(i>=100) x++;

	    p = p.substring(x, y);
	    //System.out.println(p);
	    if(p.equals("A")) blood[0]++;
	    else if(p.equals("B")) blood[1]++;
	    else if(p.equals("AB")) blood[2]++;
	    else if(p.equals("O")) blood[3]++;
	    
	    i++;
	}
	
	for(i=0; i<blood.length; i++)
	    System.out.println(blood[i]);
    }
}

Measured memory_bytes: 17156
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }


int main(int argc, char const *argv[]) {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  cout << a[0]+a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

ll n;

int main(){
	cin >> n;
	ll ans = n / 11 * 2;
	if (n % 11 != 0)ans++;
	if (n % 11 > 6)ans++;
	cout << ans << endl;
}


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

int main(){
    long long r, d, x;
    cin >> r >> d >> x;
    rep(i,10){
        x = r*x - d;
        cout << x << endl;
    }
}

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

int main()
{
    int N;
    cin >> N;
    int count = 0;
    vector<int> a;

    for(int i=0; i<N; i++)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    
    int next = 0;
    for(int i=0; i<N; i++)
    {
        count += 1;
        next = a[next] - 1;
        if(next==1)
        {
            cout << count << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3928
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        sc.nextLine();
        
        int[] a = new int[n+1];
        for(int i = 0; i < n+1; i++){
            a[i] = sc.nextInt();
        }
        sc.nextLine();
        
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            b[i] = sc.nextInt();
        }
        
        long monster = 0;
        for(int i = 0; i < n; i++){
            if(b[i] > a[i]){
                monster += a[i];
                b[i] -= a[i];
                if(b[i] > a[i+1]){
                    monster += a[i+1];
                    a[i+1] = 0;
                }else{
                    monster += b[i];
                    a[i+1] -= b[i];
                }
            }else if(b[i] == a[i]){
                monster += a[i];
            }else{
                monster += b[i];
            }
        }
        
        System.out.println(monster);
    }
}

Measured memory_bytes: 65180
from collections import deque
from heapq import heappop,heappush
inf=float("INF")
dq=[]

n,m,k,s=map(int,input().split())
p,q=map(int,input().split())

c=[0]*k
z_dist=[inf]*n
for i in range(k):
    c[i]=int(input())-1
    z_dist[c[i]]=0
    heappush(dq,(0,c[i]))
    
g=[[] for i in range(m)]
a=[0]*m
b=[0]*m
for j in range(m):
    aj,bj=map(int,input().split())
    g[aj-1].append(bj-1)    
    g[bj-1].append(aj-1) 
    a[j]=aj-1
    b[j]=bj-1
  
cc=[p]*n    
    
while dq:
    total,node=heappop(dq)
    for to in g[node]:
        if z_dist[to]>total+1:
            z_dist[to]=total+1
            heappush(dq,(total+1,to))

for i in range(n):
    if z_dist[i]<=s:
        cc[i]=q

g=[[] for i in range(n)]
for i in range(m):
    if (not a[i] in c) and (not b[i] in c):
        g[a[i]].append((b[i],cc[b[i]]))
        g[b[i]].append((a[i],cc[a[i]]))

hq=[]
rst=0
heappush(hq,(0,rst)) 

dist=[inf]*n
dist[rst]=0
while len(hq)>0:
    dd,state = heappop(hq)
    for v,dv in g[state]:
        if dist[v]>dist[state]+dv:
            dist[v]=dist[state]+dv
            heappush(hq,(dist[v],v))

print(dist[n-1]-cc[n-1])





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

int main()
{
  long long int S;
  cin >> S;

  const int x2 = 1000000000;
  int y2 = 1;
  int x3 = -1;
  int y3 = -1;
  for (int i = 0; i <= 1000000000; i++)
  {
    if ((i + S) % x2 == 0)
    {
      y3 = (i + S) / x2;
      x3 = i;
      break;
    }
  }
  cout << "0 0 " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string s1;
	string s2 = "CODEFESTIVAL2016";
	cin >> s1;
	int x = 0;
	for (int i = 0; i < 16; i++) {
		if (s1[i] != s2[i]) {
			x++;
		}
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(LL n){
	string s = toString(n);
	REP(i, SZ(s)) {
		if (s[i] == '1') {
			s[i] = '9';
		} else {
			s[i] = '1';
		}
	}
	cout << s << endl;
}


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



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

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        for(int i=0;i<a;i++)
        cout<<b;
    }
    else
    {
        for(int i=0;i<b;i++)
        cout<<a;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	ll n,x;
	cin>>n>>x;
	ll a[n];
	ll i;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	i=0;
	while(i<n-x){
		if(a[i]<a[i+x]){
			cout<<"Yes\n";
		}
		else{
			cout<<"No\n";
		}
		i++;
	}
}

Measured memory_bytes: 5152
N = int(input())
A = list(map(int, input().split()))
count = 0
money = 1000
kabu = 0
temp = A[0]
while count < N:
    if A[count] > temp:
        kabu = money // temp
        money = money % temp
        money += kabu * A[count]
        kabu = 0
    temp = A[count]
    count += 1

print(money)

Measured memory_bytes: 9148
#include <bits/stdc++.h> 
 
using namespace std;
 
 template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

int main(){
    string S;
    cin>>S;
    int g=0,p=0;
    int win=0,lose=0;
    REP(i,SZ(S)){
        if(S[i]=='g'){
            if(p<g){
                win++;p++;
            }else{
                g++;
            }
        }else{
            if(p<g){
                p++;
            }else{
                lose++;g++;
            }
        }
    }
    cout<<win-lose<<endl;
    return 0;
}


Measured memory_bytes: 512
Scanf.scanf "%d %d" (fun n k ->
    let x = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in

    let rec loop p acc =
        if p = n then acc else
            let s1 = x.(p - k + 1) in
            let s2 = x.(p) in
            let v1 = if s1 < 0 && s2 <= 0 then abs s1 else
                     if s1 >= 0 && s2 > 0 then s2 else
                         min (abs s1 * 2 + s2) (abs s1 + s2 * 2)
            in
            let acc = min acc v1 in
            loop (p + 1) acc
    in
    loop (k - 1) max_int |> Printf.printf "%d\n"
)

Measured memory_bytes: 6696
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string a, b, c; cin >> a >> b >> c;
	
	printf("%c%c%c\n", a[0] + ('A' - 'a'), b[0] + ('A' - 'a'), c[0] + ('A' - 'a'));
	return 0;
}


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
        
    sort(a,a+n);
    ll ctemp = (a[n-1]+2-1)/2;
    ll mx = 1e19;
    ll ans = 0;
    for(int i=0;i<n-1;i++){
       if(mx>abs(ctemp-a[i])){
           mx=abs(ctemp-a[i]);
           ans = a[i];
       }
    }
    printf("%lld %lld",a[n-1],ans);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>

int main(){
	int input;
	int h, m, s;

	std::cin >> input;
	if (input < 60){
		h = 0;
		m = 0;
		s = input;
	}
	else if (input < 3600){
		h = 0;
		m = input / 60;
		s = input % 60;
	}
	else{
		h = input / 3600;
		m = (input - h * 3600) / 60;
		s = (input - h * 3600) % 60;
	}

	std::cout << h << ":" << m << ":" << s << std::endl;

	return 0;
}


Measured memory_bytes: 3092
fun main(args: Array<String>) {
    abc127d()
}

private data class Operation(val amount: Int, val value: Long)

fun abc127d() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val numbers = readLine()!!.split(" ").map { it.toLong() }
        .sorted().toMutableList()
    val operations = (1..m).map { readLine()!!.split(" ").map { it.toLong() } }
        .map { Operation(it[0].toInt(), it[1]) }.sortedByDescending { it.value }

    val changeValues = mutableListOf<Long>()
    op@ for (operation in operations) {
        val changeValue = (1..operation.amount).map { operation.value }
        for (cv in changeValue) {
            if (changeValues.size >= n) break@op
            changeValues.add(cv)
        }
    }

    // 二分探索したほうがよさそうではある
    var changes = changeValues.size
    for (i in changeValues.indices) {
        if (changeValues[i] <= numbers[i]) {
            changes = i
            break
        }
    }

    val answer = (changeValues.take(changes) + numbers.drop(changes)).sum()

    println(answer)
}


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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}


 
int main() {

  ll N;

  cin >> N;

  if(N % 2 != 0){
    cout << 0 << endl;
    return 0;
  }

  ll five = 0, div = 10;

  while(N >= div){
    five += N / div;
    div *= 5;
  }

  cout << five << endl;
  // cout << setprecision(8) << ans << endl;  // For double
}



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


int main() 
{
    string s;
    cin >> s;
    if(s=="Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if(s=="Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int pot(int a, int b){
  if(b == 0) return 1;
  int ret = pot(a, b / 2);
  if(b & 1) return mul(a, mul(ret, ret));
  return mul(ret, ret);
}

int inv(int a){
  return pot(a, mod - 2);
}

const int maxn = 1e6 + 6;
int mf[maxn];

void init(){
  for(int i = 1; i < maxn; i++){
    mf[i] = i;
  }
  for(int i = 2; i < maxn; i += 2){
    mf[i] = 2;
  }
  for(int i = 3; i < maxn; i += 2){
    if(mf[i] == i){
      for(ll j = 1ll * i * i; j < maxn; j += i){
        mf[j] = i;
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  vi a(n);
  init();
  map <int, int> mp;
  for(int& x : a){
    cin >> x;
    int num = x;
    map <int, int> tmp;
    while(num > 1){
      tmp[mf[num]]++;
      num /= mf[num];
    }
    for(auto it = tmp.begin(); it != tmp.end(); it++){
      int a, b;
      tie(a, b) = *it;
      mp[a] = max(mp[a], b);
    }
  }
  int lcm = 1;
  for(auto it = mp.begin(); it != mp.end(); it++){
    int a, b;
    tie(a, b) = *it;
    lcm = mul(lcm, pot(a, b));
  }
  int res = 0;
  for(int x : a){
    res = add(res, mul(lcm, inv(x)));
  }
  cout << res;
}

Measured memory_bytes: 4736
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;

int main()
{

	int Q;
	cin >> Q;
	vi l(Q, 0), r(Q, 0);
	rep(i, Q) cin >> l[i] >> r[i];
	int ans = 0;
	
	bool sosu[100000];
	rep(i, 100000) sosu[i] = true;
	sosu[0] = false;

	repr(i, 1, 100000)
	{
		if (sosu[i] == true)
		{
			for (int j = 2; (i + 1) * j <= 100000; j++)
			{
				sosu[(i + 1) * j - 1] = false;
			}
		}

	}

	int sum[100001] = { 0 };
	sum[0] = 0;
	sum[1] = 0;
	sum[2] = 0;
	repr(num, 3, 100000 + 1)
	{
		if (sosu[num - 1] == true && sosu[(num + 1) / 2 - 1] == true)
		{
			sum[num]++;
		}
	}

	rep(i, 100000)
	{
		sum[i + 1] += sum[i];
	}


	rep(i, Q)
	{
		cout << sum[r[i]] - sum[l[i] - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main(void){
  
  int a,n,i; 
  cin>>n;
  string s="APPROVED";
  for(i=0;i<n;i++){
    cin>>a;
  	if((a%2==0))if((a%3!=0)&&(a%5!=0))s="DENIED";
    
  }
  cout<<s;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
ll p[50], x[50];
ll dfs(ll level, ll X) {
	if (X <= 1)return 0;
	else if (X < x[level - 1])return dfs(level - 1, X - 1);
	else if (X <= x[level - 1] + 1)return p[level - 1];
	else if (X == x[level - 1] + 2)return p[level - 1] + 1;
	else if (X < 2 * x[level - 1] + 1)return p[level - 1] + dfs(level - 1, X - x[level - 1] - 2) + 1;
	else return p[level - 1] * 2 + 1;
}
int main(void) {
	ll N, X;
	cin >> N >> X;
	p[0] = x[0] = 1;
	rep(i, 1, 50) {
		p[i] = p[i - 1] * 2 + 1;
		x[i] = x[i - 1] * 2 + 3;
	}
	printf("%lld\n", dfs(N, X));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
		int a,s,d;
		scanf("%d %d %d",&a,&s,&d);
		if(a==1&&s==0&&d==0||a==0&&s==1&&d==0||a==0&&s==0&&d==0){
				printf("Close\n");
				}
		else{
			printf("Open\n");
			}
	return 0;
}	

Measured memory_bytes: 1012
#include<iostream>
#include<cstdio>
using namespace std;
int y,m,d;
string s;
main()
{
    while(cin>>s,s!="#")
    {
        cin>>y>>m>>d;
        if(y>31||y==31&&m>4)y-=30,s="?";
        cout<<s<<" "<<y<<" "<<m<<" "<<d<<endl;
    }
}


Measured memory_bytes: 3044
#include <bits/stdc++.h>
	#define endl '\n'
	#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
	#define ll long long 
	using namespace std;
	const int N = 1e5+10;
	const int M = 1e9+7;

	int main(){
		FIO;
		string s,t;
		cin >> s >> t;
		int a = s.size(), b = t.size();
		int dp[a+1][b+1];
		// vector<>
		memset(dp,0,sizeof(dp));
		for (int i = 0; i <= a; ++i)
		{
			for (int j = 0; j <= b; ++j)
			{
				if(i == 0 || j == 0)
				{
					dp[i][j] = 0;
				}
				else if(s[i-1]==t[j-1])
				{
					dp[i][j] = 1 + dp[i-1][j-1];
				}
				else
				{
					dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				}
			}
			// cout << dp[i][b] << " ";
		}
		int index = dp[a][b];
		char lcs[index+1]; 
		lcs[index] = '\0';
	   	int i = a,j = b;
	   	while( i > 0 && j > 0)
	   	{
	   		if(s[i-1] == t[j-1])
	   		{
	   			lcs[index-1] = s[i-1]; 
	   			i--;j--;index--;
	   		}
	   		else if(dp[i-1][j] > dp[i][j-1])
	   		{
	   			i--;
	   		}
	   		else
	   		{
	   			j--;
	   		}
	   	}
	   	printf("%s",lcs);
		return 0;  
	}

Measured memory_bytes: 35456
#include<cstdio>

#define MAXN 100
int n,A[3][MAXN+5];
int K[2][MAXN+5],Max;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++) {
			scanf("%d",&A[i][j]);
			K[i][j]=K[i][j-1]+A[i][j];
		}
	for(int i=1;i<=n;i++) {
		int sum=K[1][i]+K[2][n]-K[2][i-1];
		if(sum>Max)	Max=sum;
	}
	printf("%d\n",Max);
	return 0;
}

Measured memory_bytes: 128