akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  ll n,W;
  cin>>n>>W;
  vi w(n),v(n);
  rep(i,n) cin>>w[i]>>v[i];
  vi sum(n+1,0);
  rep(i,n) sum[i+1]=sum[i]+v[i];
  vvi dp(n+1,vi(sum[n]+1,0));
  REP(i,1,n+1){
    dp[i][sum[i]]=dp[i-1][sum[i-1]]+w[i-1];
    for(ll j=sum[i]-1;j>0;j--){
      dp[i][j]=dp[i][j+1];
      if(j<=sum[i-1]) chmin(dp[i][j],dp[i-1][j]);
      if(j>=v[i-1]) chmin(dp[i][j],dp[i-1][j-v[i-1]]+w[i-1]);
    }
  }
  out(ub(dp[n],W)-1);
  //outvv(dp);
  //outv(sum);
}

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


Measured memory_bytes: 83108
N = int(input())

divs = set()
n = 1
while n*n <= N:
    if N%n==0:
        divs.add(n)
        divs.add(N//n)
    n += 1

divs2 = set()
n = 1
while n*n <= (N-1):
    if (N-1)%n==0:
        divs2.add(n)
        divs2.add((N-1)//n)
    n += 1

ans = len(divs2) - 1
for d in divs:
    if d==1: continue
    n = N
    while n >= 1:
        if n==1:
            ans += 1
            break
        if n%d == 0:
            n //= d
        else:
            if n%d == 1:
                ans += 1
            break

print(ans)

Measured memory_bytes: 9604
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

long mod_pow(long x, long n, long p=MOD){
  if(x==0) return 0;
  long res=1;
  x %= p;
  while(n>0){
    if(n&1) res=res*x%p;
    x=x*x%p;
    n>>=1;
  }
  return res;
}
long mod_inv(long x, long p=MOD){ return mod_pow(x%p, p-2, p); }


int main(){
  int n;
  cin>>n;
  vector<int> vec(n+1);
  rep(i,n+1) cin>>vec[i], vec[i]--;
  vector<int> use(n,-1);
  int p=-1,r=-1;

  rep(i,n+1){
    if(use[vec[i]]==-1) use[vec[i]] = i;
    else {
      p = use[vec[i]];
      r = n-i;
    }
  }

  cout << n << endl;
//dbg(p,r);
  long c = n+1;
  long d = 1;
  repl(i,1,n+1){
    long k = i+1;
    c = c*(n+2-k) % MOD * mod_inv(k) % MOD;
    if(k<=p+r+1) d = d*(p+r-k+2) % MOD * mod_inv(k-1) % MOD;
    else d = 0;
    cout << (c-d+MOD)%MOD << endl;//dbg(k,c,d);
  }

  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int x, y, num1 = INT_MAX, num2 = INT_MAX, num3 = INT_MAX, num4 = INT_MAX;
  cin >> x >> y;
  if (-x<=-y) num1 = -y+x+2; // 最初と最後でBを押す
  if (-x<=y) num2 = y+x+1; // 最初だけBを押す
  if (x<=-y) num3 = -y-x+1; // 最後だけBを押す
  if (x<=y) num4 = y-x; // Bを押さない
  cout << min(num1, min(num2, min(num3, num4))) << endl;
}

Measured memory_bytes: 256
fn floor_sum(n: i64, m: i64, mut a: i64, mut b: i64) -> i64 {
    let mut res = 0;
    if a >= m {
        res += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if b >= m {
        res += n * (b / m);
        b %= m;
    }

    let y_max = (a * (n - 1) + b) / m;
    if y_max == 0 { return res; }
    let x_max = y_max * m - b;
    res += (n - (x_max + a - 1) / a) * y_max;
    res + floor_sum(y_max, a, m, (a - x_max % a) % a)
}

fn main() {
    let t: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut ans = Vec::with_capacity(t);
    for _ in 0..t {
        let (n, m, a, b): (i64, i64, i64, i64) = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            )
        };

        ans.push(floor_sum(n, m, a, b));
    }
    println!(
        "{}",
        ans.iter()
            .map(|val| val.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}

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

int main() {
  int N, tmp;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) A[i] = 0;

  for (int i = 1; i < N; i++) {
    cin >> tmp;
    A[tmp - 1] += 1;
  }

  for (int i = 0; i < N; i++) cout << A[i] << endl;

  return 0;
}

Measured memory_bytes: 4416
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
using namespace std;

int main() {
    
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    cout << min(A, B) + min(C, D) << endl;

    return 0;

}

Measured memory_bytes: 256
n = int(input())

n3 = n // 3
n5 = n // 5
n15 = n // 15

print(n*(n + 1)//2 - 3*n3*(n3 + 1)//2 - 5*n5*(n5 + 1)//2 + 15*n15*(n15 + 1)//2)

Measured memory_bytes: 9124
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	int n = -1;
	for (int i = 1; i <= N; i++) {
		if (N == i*(i + 1) / 2)n = i;
	}
	if (n == -1) {
		cout << "No" << endl;
		return 0;
	}
	vector<vector<int>> ans(n + 1, vector<int>(n));
	for (int i = 0; i < n; i++) ans[0][i] = i + 1;
	for (int i = 1; i < n; i++) for (int j = 0; j < n - i; j++) ans[i][i + j] += ans[i - 1][i + j] + n - i;
	for (int i = 0; i < n; i++) for (int j = 0; j < i + 1; j++) ans[i + 1][j] = ans[j][i];
	cout << "Yes" << endl;
	cout << n + 1 << endl;
	for (int i = 0; i < n + 1; i++) {
		cout << n << " ";
		for (int j = 0; j < n; j++) {
			cout << ans[i][j];
			if (j != N - 1)cout << " ";
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
	/*input*/
	int n, a;	cin >> n >> a;
	/*calculaiton*/
	bool falg = false;	//true:Yes fasle:No
	int mod500 = n%500;
	if(mod500 < 500){
		if(mod500 <= a){
			falg = true;
		}
	}
	/*output*/
	if(falg){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
N = int(input())

n = str(N)

res = 0

if len(n) == 1:
    res = N

else:
    nine = True
    for i in range(1, len(n)):
        if n[i] != "9":
            nine = False
            break

    if nine:
        res = int(n[0]) + 9 * (len(n) - 1)
    else:
        res = (int(n[0]) - 1) + 9 * (len(n) - 1)

print(res)

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void DumpRow(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

template<class T>
void DumpColumn(const T& A) {
    auto isFirst = true;
    for (const auto& value : A) {
        if (isFirst) {
            cout << value;
            isFirst = false;
        } else {
            cout << " " << value;
        }

    }
    cout << endl;
}

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

    ll n;
    cin >> n;
    auto v = Read(n);

    ll q;
    cin >> q;

    REP(i, q) {
        ll b, m, e;
        cin >> b >> m >> e;
        swap_ranges(v.begin()+b, v.begin() + m, v.begin()+e);
    }

    DumpColumn(v);
    return 0;
}



Measured memory_bytes: 3172
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(b/a<c){
		printf("%d\n",b/a);
	}
	else{
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


//RMQ
template<typename T>
struct SegmentTree {

private:
	T N;
	vector<T> node;//0-index
public:

	SegmentTree(T siz) {
		N = 1;
		while (N < siz) {
			N *= 2;
		}
		node.resize(2 * N - 1, INF);
	}

	void build(vector<T>& dat) {
		for (int i = 0; i < dat.size(); i++) {
			node[i + N - 1] = dat[i];
		}
		for (int i = N - 2; i >= 0; i--) {
			node[i] = min(node[2 * i + 1], node[2 * i + 2]);
		}
	}

	void update(T k, T x) {
		k += N - 1;
		node[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;//親
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	//[a,b)
	T getMin(T a, T b) {
		return getMin(a, b, 0, 0, N);
	}

	T getMin(T a, T b, T k, T l, T r) {
		if (r <= a || b <= l) {
			return INF;
		}
		if (a <= l && r <= b) {
			return node[k];
		}
		T vl = getMin(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = getMin(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}

	T find(T a, T b, T x) {
		return (find(a, b, x, 0, 0, N));
	}

	//頂点k(区間[l,r)の)の部分木について区間[a,b)内でx以下の値を持つ要素の最右位置を返す
	T find(T a, T b, T x, T k, T l, T r) {
		if (node[k] > x || r <= a || b <= l) {
			//自分の頂点がxより大きいか範囲外の場合、この区間にないため-1を返す
			return -1;
		}
		if (k >= N - 1) {
			//自分の頂点が葉なら見つかったことになるので、その位置を返す
			return (k - (N - 1));
		}
		//右の区間の部分木を見る
		T rv = find(a, b, x, 2 * k + 2, (l + r) >> 1, r);
		if (rv != -1) {
			//戻り値が-1以外なら見つかったのでその位置を返す
			return rv;
		}
		//右の部分偽になかったので左の部分木を調べる
		return (find(a, b, x, 2 * k + 1, l, (l + r) >> 1));
	}
};


int main() {

	ll n, q;
	cin >> n >> q;
	
	SegmentTree<ll> rmq(n);

	while (q--) {
		ll c, x, y;
		cin >> c >> x >> y;
		if (c == 0) {
			rmq.update(x, y);
		}
		else {
			cout << rmq.getMin(x, y + 1) << endl;
		}
	}
	

	return 0;
}


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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n,x = [int(i) for i in readline().split()]
n = int(input())
a = [int(i) for i in readline().split()]

neg = len([i for i in a if i < 0])
if neg%2 == 0:
    ans = sum(abs(i) for i in a)
else:
    ans = sum(abs(i) for i in a) - 2*min(abs(i) for i in a)

print(ans)
    







Measured memory_bytes: 15180
#include <iostream>
#include <sstream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

bool compare(const pair<int,int> &a,const pair<int,int> &b){
	if(a.second!=b.second) return a.second>b.second;
	else return a.first<b.first;
}

int main(void){
  int m;
  while(cin>>m,m){
  	cin.ignore();
    vector<pair<int,int> > score;
    for(int x=0;x<m;++x){
	    int num,f=0,t=0,sc=0,flag=0;
	    vector<int> bonus(21,1);
	    string s;
	    getline(cin,s);
	    stringstream ss;
	    ss<<s;
	    ss>>num;
	    while(!ss.eof()&&f<10){
	      int a,b;
	      ss>>a;
	      sc+=a*bonus[t];
	      if(a==10){
	      	if(f==9)flag=1;
	      	if(f!=9){
			      ++bonus[t+1];
			      ++bonus[t+2];
		      }
		      ++t;
		      if(f==9&&flag){
		      	ss>>a;
		      	sc+=a*bonus[t];
		      	++t;
		      }
	      }else{
	      	++t;
	        ss>>b;
	        if(a+b==10){
	        	if(f==9)flag=1;
	        	if(f!=9)++bonus[t+1];
	        }
	        sc+=b*bonus[t];
	        ++t;
	      }
	      if(f==9&&flag){
	        ss>>a;
	        sc+=a*bonus[t];
	        ++t;
	        break;
	      }
	      ++f;
	    }
	    score.push_back(make_pair(num,sc));
    }
    sort(score.begin(),score.end(),compare);
    for(int i=0;i<m;++i){
    	cout<<score[i].first<<" "<<score[i].second<<endl;
    }
  }
  return 0;
}

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

using namespace std;
using ll = long long;

void maxi(int &a, int b) {
	a = max(a,b);
}
const int MAXN = 5.5e3;
const int MAXK = 5.5e3;
int N, K;
ll A[MAXN];
int dp[MAXN][MAXK];

bitset<MAXK> f;

bool solve(int v) {
	if (A[v] >= K) {
		return true;
	}	
	f.reset();
	f[0] = 1;
	for (int i=0; i < N; i++) {
		if (i != v) {
			f |= (f << A[i]);
		}
	}
	for(int i = K-1; i >= K-A[v]; i--) {
		if (f[i] == 1) {
			return true;
		}		
	}
	return false;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);	
	cin >> N >> K;
	for (int i=0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A+N);
	int l=0;
	int r=N-1;
	int mid;
	while (l < r) {
		mid = (l+r)/2;
		if (solve(mid)) {
			r = mid;
		} else  {
			l = mid + 1;
		}
	}
	mid = (l+r)/2;
	if (mid == N-1) {
		mid += (!solve(mid)); 
	}
	cout << mid << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF =1LL << 60;

int main(){
  //Sieve of Eratosthenes
  int MAX= 1010101;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for(int i =2; i<MAX; i++){
    if(!is_prime[i]) continue;
    for(int j=2*i; j<MAX; j+=i){
      is_prime[j] = 0;
    }
  }

  vector<int> a(MAX, 0);
  for(int i =0; i<MAX; i++){
    if(!is_prime[i]) continue;
    if(is_prime[i] && is_prime[(i+1)/2]) a[i]=1;
  }

  vector<int> s(MAX+1, 0);
  for(int i = 0; i<MAX; i++){
    s[i+1]=s[i]+a[i];
  }

  int Q;
  cin >> Q;
  for(int q=0; q<Q; q++){
    int l, r;
    cin >> l >> r;
    r++;
    cout << s[r] -s[l] << endl;
  }
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
void solve(){
    cout << "Yes"<<endl;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a[3][3];
    bool b[3][3];
    memset(b,0,sizeof(b));
    int n;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];        
        }
    }
    cin>>n;
    int c;
    for(int i=0;i<n;i++){
        cin>>c;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(c==a[j][k])b[j][k]=1;
            }
        }
    }
    bool maki=true;
    for(int i=0;i<3;i++){
        if(!b[i][i])maki=false;
    }
    if(maki){
        solve();
        return 0;
    }
    maki=true;
    for(int i=0;i<3;i++){
        if(!b[i][2-i]){
            maki=false;
        }
    }
    if(maki){
        solve();
        return 0;
    }
    for(int i=0;i<3;i++){
        maki=true;
        for(int j=0;j<3;j++){
            if(!b[i][j]){
                maki=false;
            }
        }
        if(maki){
            solve();
            return 0;
        }
    }
    for(int i=0;i<3;i++){
        maki=true;
        for(int j=0;j<3;j++){
            if(!b[j][i]){
                maki=false;
            }
        }
        if(maki){
            solve();
            return 0;
        }
    }
    cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
class Atcoder_ABC137A
{
    static void Main(string[] args)
    {
        string[] input_string = Console.ReadLine().Split(' ');
        int A_int = int.Parse(input_string[0]);
        int B_int = int.Parse(input_string[1]);
        int sumAB = A_int + B_int;
        int minusAB = A_int - B_int;
        int SekiAB = A_int * B_int;

        int tempresult = Comparetwoint(sumAB, minusAB);
        tempresult = Comparetwoint(tempresult, SekiAB);


        //出力
        Console.WriteLine(tempresult);

        
    }
    public static int Comparetwoint(int a, int b)
    {
        int result = (a >= b) ? a : b;
        return result;
    }
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    ll ans=a*b;
    ll tmp;
    if(a<b){
        tmp=a;
        a=b;
        b=tmp;
    }
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    cout<<ans/b<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
alst = list(map(int, input().split()))
cnt = [0 for _ in range(n)]
for a in alst:
    if a > n:
        continue
    cnt[a - 1] += 1

rem = 0
for i, num in enumerate(cnt, start = 1):
    if num >= i:
        rem += i
        
print(n - rem)

Measured memory_bytes: 20592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		int t = sc.nextInt();
		int cost = Integer.MAX_VALUE;
		for(int i = 0; i< n; i++) {
			int c = sc.nextInt();
			if(t >= sc.nextInt() &&
					cost > c)
				cost = c;
		}
		if(cost == Integer.MAX_VALUE)
			System.out.println("TLE");
		else
			System.out.println(cost);
	}
}

class Scanner {
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public String[] nextArray(int length) {
		String[] array = new String[length];
		for(int i = 0; i < length; i++)
			array[i] = next();
		return array;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public double[] nextDoubleArray(int length) {
		double[] array = new double[length];
		for(int i = 0; i < length; i++)
			array[i] = nextDouble();
		return array;
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public int[] nextIntArray(int length) {
		int[] array = new int[length];
		for(int i = 0; i < length; i++)
			array[i] = nextInt();
		return array;
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public long[] nextLongArray(int length) {
		long[] array = new long[length];
		for(int i = 0; i < length; i++)
			array[i] = nextLong();
		return array;
	}
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 21332
import sys
input = sys.stdin.readline
f = lambda:map(int,input().split())

n, m = f()

lm = 0
rm = n

for i in range(m):
  l, r = f()
  lm = max(lm, l)
  rm = min(rm, r)

print(max(rm-lm+1, 0))

Measured memory_bytes: 3060
//
//  main.cpp
//  CODE 2
//
//  Created by Parsa Mrezaei on 7/13/17.
//  Copyright © 2017 Parsa Mrezaei. All rights reserved.
//

#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <stdio.h>


using namespace std;

const int MAXN = 1e5;


int main () {
    vector <int>  v;
    int n, k; cin >> n >> k;
    for (int i = 0, x; i < n; ++i)
    {
        cin >> x;
        v.push_back(x);
    }
    int ans = 0;
    sort(v.begin(), v.end(), greater<int> ());
    for (int i =0; i< k; ++i)
        ans += v[i];
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
    s,t = x-l, x+l
    if s >= right:
        right = t
        ans += 1
print(ans)


Measured memory_bytes: 21400
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int num;
            while((num = scn.nextInt()) > 0) {
                int min = scn.nextInt();
                int max = scn.nextInt();

                List<Integer> list = new ArrayList<>();
                for(int i = 0; i < num; i++) {
                    list.add(scn.nextInt());
                }
                Collections.sort(list);
                Collections.reverse(list);

                int ans = 0;
                int gap = 0;
                for(int i = min; i <= max; i++) {
                    int tmp = list.get(~-i) - list.get(i);
                    if(gap <= tmp) {
                        gap = tmp;
                        ans = i;
                    }
                }

                System.out.println(ans);
            }
        }
    }
}

Measured memory_bytes: 58012
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	int n; std::cin >> n;
	std::string str; std::cin >> str;
	int count = 0;
	for (auto i = 0; i < 1000; ++i) {
		int match = 0;
		int value = i;
		for (const auto s : str) {
			if (s - '0' == value % 10) {
				value /= 10;
				if (++match == 3) break;
			}
		}
		if (match == 3) ++count;
	}
	std::cout << count << '\n';
}


Measured memory_bytes: 384
#include<stdio.h>
void RSort(int *,int,int);
void Reverse(int *,int,int,int);
double sum=0;
int main()
{
  int i,n;
  int N[200000];
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
  }
 
  RSort(N,0,n);
 
 /* for(i=0;i<n;i++){
    printf("%d ",N[i]);
  }*/
   
  printf("%.0f\n",sum);
 
  return 0;
}
 
void RSort(int *A,int left,int right)
{
  int mid,temp;
  if(left+1<right){
    mid=(left+right)/2;
    RSort(A,left,mid);
    RSort(A,mid,right);
    Reverse(A,left,mid,right);
  }
}
 
void Reverse(int *A,int left,int mid,int right)
{
  int k,n1,n2,L[200000],R[200000],i,j;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      sum+=n1-i;
      j++;
    }
  }
}

Measured memory_bytes: 2204
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<pair<pair<string,int>, int>> p(n);

    rep(i,n){
        cin >> p[i].first.first >> p[i].first.second;
        p[i].first.second *= -1;
        p[i].second = i+1;
    }

    sort(all(p));

    rep(i,n) dunk(p[i].second);
}

Measured memory_bytes: 256
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Unboxed.Mutable as MV

main=do
    [n,k]<-map read.words<$>getLine::IO[Int]
    as<-unfoldr (B.readInt.B.dropWhile(<'!'))<$>B.getLine
    putStrLn $ ["Second", "First"] !! min 1 (f k as)

f k as = runST $ do
    kv <- MV.new (k+1) :: ST s (MV.STVector s Int)
    forM_ [0..k] $ \i -> do
        g <- fmap (gr.((-1):).sort) $ forM as $ \a -> if i-a>=0 then MV.read kv (i-a) else pure (-1)
        MV.write kv i g
    MV.read kv k

gr [a] = a+1
gr (a:b:x) | a+1>=b = gr (b:x) |otherwise = a+1


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>


int main() {
	long long n, k;

	std::cin >> n >> k;

	std::vector<long long> v(n);

	for (long long i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	std::vector<long double> exp(n);
	for (long long i = 0; i < n; i++)
	{
		long long sum = (v[i] * (v[i] + 1)) / 2;
		exp[i] = 1.0 * sum / v[i];
	}

	double ans = 0;
	double pre = 0;
	for (long long j = 0; j < k; j++)
	{
		pre += exp[j];
	}

	ans = pre;

	for (long long i = 1; i + k - 1 < n; i++)
	{
		pre -= exp[i - 1];
		pre += exp[i + k - 1];
		ans = std::max(ans, pre);
	}

	printf("%.10lf\n", ans);
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
int main() {
  int N;
  scanf("%d", &N);
  int L[10];
  int i,j; /* インデックス */
  for (i = 0; i < N; ++i) {
    scanf("%d",&L[i]);
  }

  int temp;
  for (i = 0; i < N ; ++i) {
    for	(j = i + 1; j < N; ++j) {
      if (L[i] < L[j]) {
        temp = L[i];
        L[i] = L[j];
        L[j] = temp;
      }
    }
  }

  int sum = 0;
  for (i = 1; i < N; ++i) {
    sum += L[i];
  }

  if (L[0] >= sum) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }

  return 0;
}

Measured memory_bytes: 128
//
// Created on 2020/07/05.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n;
    cin>>n;
    queue<int>q;
    vector<int>a;
    for (int i = 0; i < n; ++i) {
        int t;
        cin>>t;
        a.push_back(t);
    }
    sort(rall(a));
    ll ans = 0;
    q.push(a[1]);
    q.push(a[1]);
    ans += a[0];
    for (int j = 2; j < n; ++j) {
        int d = q.front();
        ans += d;
        q.pop();
        q.push(a[j]);
        q.push(a[j]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define endl '\n'
#define all(n)      (n).begin(), (n).end()
#define ll long long int
int a[1000001];
void go(){
	for(int i = 0; i <= 1000000; i++){
		a[i] = i;
	}
	for(int i = 3; i <= 1000000; i += 3){
		a[i] = 0;
	}
	for(int i = 5; i <= 1000000; i += 5){
		if(a[i] != 0)
		  a[i] = 0;
	}
}

void solve(){
	int n; cin >> n;
	go();
	ll sum  = 0;
	for(int i = 0; i <= n; i++){
		sum = (sum + a[i])  % 1000000000000000000;
	}
	cout << sum << endl;
	

}


int main (){
	#ifndef ONLINE_JUDGE
		freopen ("input.txt","r",stdin);
		freopen ("output.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	//Write from here.
	
		solve();
	
	return 0;
}

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

typedef unsigned long long ull;

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

    vector<int> p(n+1, k), s(n+1, 0);

    vector<int> a;
    int ai;
    for (int i = 0; i < q; i++)
    {
        cin >> ai;
        a.push_back(ai);
    }

    for (int i: a)
    {
        s[i]++;
    }

    for (int i = 1; i < n+1; i++)
    {
        if (p[i] - q + s[i] <= 0)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }
    }

    return 0;
}


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

typedef long long   ll;

struct edge{
    int u, v;    
};

const int N = int(1e5 + 10);
int father[N];
edge edges[N];
ll weight[N];
ll ret = 0LL;
ll resp[N];

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

void join(edge &ed){
    int x = find(ed.u);
    int y = find(ed.v);
    
    if(x != y){
        ret -= (weight[x] * (weight[x] - 1LL)) / 2LL;
        ret -= (weight[y] * (weight[y] - 1LL)) / 2LL;
        
        if(x < y){
            father[y] = x;
            weight[x] += weight[y];
            ret += (weight[x] * (weight[x] - 1LL)) / 2LL;
        }else{
            father[x] = y;
            weight[y] += weight[x];
            ret += (weight[y] * (weight[y] - 1LL)) / 2LL;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n, m;
    
    cin >> n >> m;
    
    for(int i = 1 ; i <= n ; i++){
        father[i] = i;
        weight[i] = 1LL;
    }
    
    for(int i = 1 ; i <= m ; i++){
        cin >> edges[i].u >> edges[i].v;
    }
    
    for(int i = m ; i >= 1 ; i--){
        resp[i] = (n * (n - 1LL)) / 2LL - ret;
        join(edges[i]);    
    }
    
    for(int i = 1 ; i <= m ; i++){
        cout << resp[i] << endl;
    }
    
	return 0;
}


Measured memory_bytes: 4096
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

n, m, x = Is()
CA = LIR(n)

ans = INF
for bit in range(1<<n):
    B = [0]*m
    money = 0
    for i in range(n):
       if bit & (1<<i):
           money += CA[i][0]
           for j in range(m):
               B[j] += CA[i][j+1]
    for j in range(m):
        if B[j] < x:
            break
    else:
        ans = min(ans, money)

if ans == INF:
    print(-1)
else:
    print(ans)


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

int N,C,K;

int main(){
    cin>>N>>C>>K;
    int T[N];
    for(int i=0;i<N;i++){
        cin>>T[i];
    }
    sort(T,T+N);
    int r=1,bus=0,time=T[0];
    for(int i=1;i<N;i++){
        if(r<C){
            if(T[i]<=time+K){
                r++;
            }else{
                bus++;
                r=1;
                time=T[i];
            }
        }else if(r==C){
            bus++;
            r=1;
            time=T[i];
        }
    }
    bus++;
    cout<<bus<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[4];
  cin>>s;
  int a=0;
  for(int i=0;i<3;i++)
  {
    if(s[i]==s[i+1])
      a++;
  }
  if(a>0)
    cout<<"Bad";
  else
    cout<<"Good";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);

  printf("%d\n",min(A,B)+min(C,D)); 

  return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  vector<int> parent(n, -1);
  function<void(int,int)> dfs = [&](int u, int pa) {
    parent[u] = pa;
    for (auto v : g[u]) {
      if (v != pa) {
        dfs(v, u);
      }
    }
  };
  dfs(0, -1);

  auto count = [&](int x, int y) {
    if (x < y) {
      return 1LL * (y - x) * (n - y);
    } else {
      return 1LL * (y + 1) * (x - y);
    }
  };

  long long ans = n;
  for (int i = 1; i < n; i++) {
    ans += count(parent[i], i);
  }
  cout << ans << '\n';
  
  return 0;
}


Measured memory_bytes: 30676
n,m,s,t=map(int,input().split())
s,t=s-1,t-1
g=[[] for _ in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  u,v=u-1,v-1
  g[u].append([v,a,b])
  g[v].append([u,a,b])
inf=float('inf')
froms=[inf]*n
froms[s]=0
fromt=[inf]*n
fromt[t]=0
from heapq import heappop,heappush
ka=set(())
todo=[[0,s]]
while todo:
  d,v=heappop(todo)
  if v in ka:continue
  ka.add(v)
  for nv,nd,_ in g[v]:
    if froms[nv]>d+nd:
      heappush(todo,[d+nd,nv])
      froms[nv]=d+nd
ka=set(())
todo=[[0,t]]
while todo:
  d,v=heappop(todo)
  if v in ka:continue
  ka.add(v)
  for nv,_,nd in g[v]:
    if fromt[nv]>d+nd:
      heappush(todo,[d+nd,nv])
      fromt[nv]=d+nd
pay=[[i,froms[i]+fromt[i]] for i in range(n)]
pay.sort(key=lambda x:x[1],reverse=True)
for i in range(n):
  while pay[-1][0]<i:
    pay.pop()
  print(pow(10,15)-pay[-1][1])


Measured memory_bytes: 165604
n = int(input())
a = list(map(int,input().split()))
b = 0
c = 0
for i in range(len(a)):
    if a[i]%2 == 0:
        b += 1
    else:
        c += 1
if c%2 == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 14108
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String S = in.next();
		int a = 0;
		for (int i = 0; i < 6; i++){
			if(S.charAt(i)=='1')a++;
		}
		System.out.println(a);
	}
}

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

int main(){
  int a,b;	cin >> a >> b;
  for(int i=1;i<2000;i++){
    if(i*8/100==a&&i*10/100==b){
      cout << i;
      return 0;
    }
  }
  cout << -1;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
bool is_war(const vector <int >& x, const vector <int >& y) {
for (int Z = -100; Z <= 100; ++Z) {
bool is_ok = true;
for (int i = 0; i < x.size(); ++i) {
if (x[i] >= Z) is_ok = false;
}
for (int i = 0; i < y.size(); ++i) {
if (y[i] < Z) is_ok = false;
}
if (is_ok) return false;
}
return true;
}
int main() {
int N, M; cin >> N >> M;
vector <int> x(N+1), y(M+1);
cin >> x[0] >> y[0];
for (int i = 0; i < N; ++i) {
cin >> x[i+1];
}
for (int i = 0; i < M; ++i) {
cin >> y[i+1];
}
if (is_war(x, y)) {
cout << "War" << endl;
}
else {
cout << "No War" << endl;
}
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, m;
    scanf("%d %d", &n, &m);

    long t = 1900 * m + 100 * (n - m);
    long multi = 1;

    for (int i = 1; i <= m; i++)
        multi *= 2;
    
    printf("%ld\n", t * multi);
    return 0;
}

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

int main() {
  int N, AC, WA, TLE, RE;
  cin >> N;
  string temp;
  AC = 0;
  WA = 0;
  TLE = 0;
  RE = 0;
  for(int i=0; i<N; i++){
    cin >> temp;
    if (temp == "AC") {
      AC += 1;
    }
    else if(temp == "WA") {
      WA += 1;
    }
    else if(temp == "TLE") {
      TLE += 1;
    }
    else if(temp == "RE") {
      RE += 1;
    }
  }
  printf("AC x %d\n", AC);
  printf("WA x %d\n", WA);
  printf("TLE x %d\n", TLE);
  printf("RE x %d\n", RE);
}

Measured memory_bytes: 3724
using System;
using System.Linq;

namespace ConsoleApp3
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var lines = Console.ReadLine().Select(x => int.Parse(x.ToString())).ToArray();
            if (lines.Sum() % 9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> a(n);
    rep(i, n) cin >> a.at(i).first >> a.at(i).second;
    vector<pair<int, int>> b(m);
    rep(i, m) cin >> b.at(i).first >> b.at(i).second;
        
    int index;
    
    rep(i, n) {
      	int manh = 999999999;
        rep(j, m) {
            int tmp = manh;
            manh = min(manh, abs(a.at(i).first-b.at(j).first)+abs(a.at(i).second-b.at(j).second));
          	//cout << tmp << " " << manh << endl;
            if(tmp != manh) index = j+1;
          	else continue;
        }
        cout << index << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    queue<pair<string, int> > nt;
    REP(i, n)
    {
        string n;
        int t;
        cin >> n >> t;
        pair<string, int> p(n, t);
        nt.push(p);
    }

    int time = 0;
    while (!nt.empty())
    {
        pair<string, int> p = nt.front();
        nt.pop();
        if (p.second > q)
        {
            time += q;
            p.second -= q;
            nt.push(p);
        }
        else
        {
            time += p.second;
            cout << p.first << " " << time << endl;
        }        
    }
}


Measured memory_bytes: 6352
#include<iostream>
int main(){
  int n,A[100];
  std::cin>>n;
  for(int i=0;i<n;i++){
    std::cin>>A[i];
  }
  for(int i=0;i<n;i++){
    if(i!=0){
      for(int j=0;j<i;j++){
	if(A[i-j]<A[i-j-1]){
	  int ex=A[i-j];
	  A[i-j]=A[i-j-1];
	  A[i-j-1]=ex;
	}//入れ替え
      }
    }
    for(int k=0;k<n;k++){
      std::cout<<A[k];//出力
      if(k<n-1)std::cout<<' ';
    }
    std::cout<<'\n';
  }
  return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;

int main() {
    int n; // number of balls
    cin >> n; 
    int k;// Bのx座標
    cin >> k;
    int ans = 0;
    for (int i = 0; i < n ; i++) {
        int x;
        cin >> x;
        int distA = x * 2;
        int distB = (k - x) * 2;
        ans += min(distA, distB);
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
while True:
    n = int(raw_input())

    if n == 0:
        break

    f = raw_input().split()

    ans = 0

    for i in range(1, len(f)):
        if f[i] == "lu" and f[i-1] == "ru":
            ans += 1
        elif f[i] == "ru" and f[i-1] == "lu":
            ans += 1
        elif f[i] == "ld" and f[i-1] == "rd":
            ans += 1
        elif f[i] == "rd" and f[i-1] == "ld":
            ans += 1

    print ans


Measured memory_bytes: 4652
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    cin >> q;
    vector<int> m(q);
    rep(i, q) cin >> m[i];
    unordered_set<int> memo;
    for (int bit = 0; bit < 1<<n; ++bit) {
        int cur = 0;
        rep(j, n) {
            if (bit>>j&1) cur += a[j];
        }
        memo.insert(cur);
    }
    rep(i, q) {
        cout << (memo.count(m[i])?"yes":"no") << endl;
    }
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    string s;
    cin>>s;
    int sr=0,sb=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='0')sr++;
        else sb++;
    }
    cout<<(long long int )min(sr,sb)*2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

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


Measured memory_bytes: 3692
# https://atcoder.jp/contests/abc122/tasks/abc122_c

import itertools
import collections
import bisect

def main():
    N, Q = map(int, input().split())
    S = list(input())

    counter = [0] * N
    for i in range(N-1):
        if "{}{}".format(S[i], S[i+1]) == 'AC':
            counter[i+1] = counter[i] + 1
        else:
            counter[i + 1] = counter[i]
    # print(counter)

    for _ in range(Q):
        l, r = map(int, input().split())
        l -= 1
        r -= 1
        print(counter[r] - counter[l])

if __name__ == '__main__':
    main()


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

int main(void){
    int n;
    cin >> n;
    vector<ll> ans;
    map<int,ll> mp;

    ll tmp = 0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        mp[a]++;
        tmp += a;
    }

    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        ll before, after;
        cin >> before >> after;
        tmp += after*mp[before];
        tmp -= before*mp[before];
        mp[after] += mp[before];
        mp[before] = 0;
        ans.push_back(tmp);
    }

    for(int i=0;i<q;i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 9876
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main(args: Array<String>) {
    val n = readInt()
    val s = readLn().toCharArray()

    val r = s.count { it == 'R' }
    val g = s.count { it == 'G' }
    val b = s.count { it == 'B' }

    var t = (r.toLong() * g.toLong() * b.toLong())

    (0..n - 3).forEach {i ->
        (i..n - 2).forEach { j ->
            val k = 2 * j - i
            if (k < n) {
                if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
                    t--
                }
            }
        }
    }
    println(t)
}


Measured memory_bytes: 36652
#include <stdio.h>
 
using namespace std;
 
const int MAX_N = 100000;
int par[MAX_N + 1];
int rnk[MAX_N + 1];
int dis[MAX_N + 1];
 
int root(int x)
{
	if(par[x]==x)return x;
	return root(par[x]);
}
 
int find(int x)
{	
    
	if(x==root(x)) return 0;
	return dis[x]+find(par[x]);
}
 
int merge(int L,int R,int D)
{	
	int x = L,y = R;
	L = root(L);
	R = root(R);
	int L_d = find(x);
	int R_d = find(y);
	if(L==R){
		if(R_d-L_d==D) return 1;
		else return 0;
	}
	if(rnk[L]<rnk[R])
	{
		par[L] = R;
		dis[L] = R_d - D - L_d;
	}
	else {
		par[R] = L;
		dis[R] = L_d + D - R_d;
		if(rnk[L]==rnk[R])rnk[L]++;
	}
	return 1;
}
 
int main()
{
	int n,m,i;
	scanf("%d %d",&n,&m);
	
	for(i=1;i<=n;i++)par[i]=i;
	
	for(i=0;i<m;i++)
	{
		int L,R,D;
		scanf("%d %d %d",&L,&R,&D);
		if(!merge(L,R,D)){
			printf("No"); return 0;
		}
		
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1408
using System;


namespace atCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int count = int.Parse(s[0]);
            int max = int.Parse(s[1]);
            int time = int.Parse(s[2]);

            int result = ((count / max) + ((count % max == 0) ? 0 : 1)) * time;


            Console.WriteLine(result.ToString());
        }
    }
}

Measured memory_bytes: 27508
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    string s;
    int ans = 0;
    cin >> s;
    rep(i, s.size()){
        if(s[i] == '+') ans++;
        else ans--;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256