akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.00000000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 550555;
const int L = 21;
const int M = 2155;

void solve() {
    ll x;
    cin >> x;

    ll n = 100;
    for (int i = 1; i <= 1e6; i++){
        n = n*1.01;
        if (n >= x){
            cout << i;
            return;
        }
    }

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  int sum=0;
  s = to_string(n);
  for(int i=0;i<s.length();++i){
    sum+=s[i]-'0';
  }
  if(n%sum==0){
    cout<<"Yes";}
  else{
    cout<<"No";
  }
  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n;cin>>n;
    int a[n+2],b[n+1];
    rep1(i,n+1)cin>>a[i];
    rep1(i,n)cin>>b[i];
    ll sum = 0;
    for(int i=1;i<=n;i++){
        sum+=min(a[i],b[i]);
        sum+=min(a[i+1],b[i]-min(a[i],b[i]));
        a[i+1]-=min(a[i+1], b[i]-min(a[i],b[i]));
    }
    co(sum);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s.size()==1)
	{
		cout<<1<<endl;
		return 0;
	}
	int ans=s.size();
	for(int i=1;i<s.size();i++)
		if(s[i]!=s[i-1])
			ans=min(ans,max(i,(int)s.size()-i));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 using namespace std;
 
 double a[500000];
 
 int main() {
          int n;
          double mean;
           int ans;
          while(true) {
                  cin >> n;
                  if (n == 0) break;
 
                  for(int i = 0;i < n;i++) cin >> a[i];
 
                  mean = 0;
                  ans = 0;
 
                  for(int i = 0;i < n;i++) mean += a[i];
 
                  mean /= n;
 
                  for(int i = 0;i < n;i++) {
                          if (a[i] <= mean) ans += 1;
                  }
 
                  cout << ans<< "\n";
          }
  }


Measured memory_bytes: 3284
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


n, k = map(int, input().split())
a = list(map(int, input().split()))

b = gcd_list(a)
if max(a) >= k and k % b == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 16280
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int n, m, s, i, j, u, v, a[103], b[103], c[53], d[53], is, pv, pr, nv, nr, rid;
	ll di[53][5003] = {}, ds, ans;
	vector<P> g[53];
	priority_queue<Pl, vector<Pl>, greater<Pl>> pq;

	scanf("%d%d%d", &n, &m, &s);
	for (i = 0; i < m; i++) {
		scanf("%d%d%d%d", &u, &v, &a[i], &b[i]);
		g[u - 1].push_back(P(v - 1, i));
		g[v - 1].push_back(P(u - 1, i));
	}
	for (i = 0; i < n; i++) {
		scanf("%d%d", &c[i], &d[i]);
	}

	for (i = 0; i < n; i++) for (j = 0; j <= 5000; j++) {
		di[i][j] = (ll)1e18;
	}

	pq.push(Pl(0ll, min(s, 5000)));
	di[0][min(s, 5000)] = 0;
	while (!pq.empty()) {
		Pl p = pq.top();
		pq.pop();
		ds = p.first;
		is = p.second;
		pv = is / 5001;
		pr = is % 5001;
		if (di[pv][pr] < ds) {
			continue;
		}

		nv = pv;
		nr = pr + c[pv];
		if (nr <= 5000 && di[nv][nr] > ds + d[pv]) {
			di[nv][nr] = ds + d[pv];
			pq.push(Pl(di[nv][nr], nv * 5001 + nr));
		}

		for (i = 0; i < g[pv].size(); i++) {
			rid = g[pv][i].second;
			nv = g[pv][i].first;
			nr = pr - a[rid];
			if (nr < 0) continue;
			if (di[nv][nr] > ds + b[rid]) {
				di[nv][nr] = ds + b[rid];
				pq.push(Pl(di[nv][nr], nv * 5001 + nr));
			}
		}
	}

	for (i = 1; i < n; i++) {
		ans = (ll)1e18;
		for (j = 0; j <= 5000; j++) {
			ans = min(ans, di[i][j]);
		}
		printf("%lld\n", ans);
	}

	return 0;
}

Measured memory_bytes: 9548
nodes = Array.new(100){0}
readlines.each do |line|
	frm, to = line.split.map(&:to_i)
	if frm == 0 && to == 0
		if nodes[1].odd? && nodes[2].odd? && nodes.drop(3).all?{|i| i.even?}
			puts("OK")
		else
			puts("NG")
		end
		nodes = Array.new(100){0}
	else
		nodes[frm] += 1
		nodes[to] += 1
	end
end

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

// brute force OK for N and K <= 100?
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int N;
    cin >> N;

    vector<int> vals;
    for (int i = 0; i < N; ++i) {
        int val;
        cin >> val;
 
        vals.push_back(val);
    }

    int minSum = 2147000000;
    for (int position = 1; position < 101; ++position) {
        int sum = 0;
        for (int val : vals) {
            sum += pow((position - val), 2);
        }

        minSum = (sum < minSum) ? sum : minSum;
    }
        
    cout << minSum;

    return 0;
}

/*
file=c
g++ -W -Wall -pedantic --std=c++17 -ggdb3 -o out ${file}.cpp && ./out


49
14 14 2 13 56 2 37
14 14 2 13 56 2 37
14 14 2 13 56 2 37
14 14 2 13 56 2 37
14 14 2 13 56 2 37
14 14 2 13 56 2 37
14 14 2 13 56 2 37

ans: should be 7 * 2354 = 16478



*/


Measured memory_bytes: 256
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;

$X = $sc->nextInt();
$fx = array_sum(str_split($X));
if ($X % $fx == 0) {
    echo 'Yes';
}else{
    echo 'No';
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[])
{
    int r,c;
    cin >> r >> c;
    vector<int> dummy;
    vector<vector<int>> mat;
    vector<int> lastrow;
    auto accum = [&](vector<int>& tmp)->void{
    tmp.push_back(accumulate(tmp.begin(),tmp.end(),0));
    };

    for (int row = 0; row < r; row++)
    {
        dummy.clear();
        for (int col = 0; col < c; col++)
        {
            int tmp;
            cin >> tmp;
            dummy.push_back(tmp);
        }
        accum(dummy);
        mat.push_back(dummy);
    }
    for (int i = 0; i < c+1; i++)
    {
        int tmp = 0;
        for (int j = 0; j < r; j++)
        {
            tmp += mat[j][i];
        }
        lastrow.push_back(tmp);
    }
    mat.push_back(lastrow);

    for (int i = 0; i < r+1; i++)
    {
        for (int j = 0; j < c+1; j++)
        {
            cout << mat[i][j];
            if(i==r && j==c) continue;
            if(j!=c) cout << " ";
        }
        if(i<r+1) cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3208
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        int count = 0;
        char[] l = new char[S.length()];
        for(int i = 0; i < S.length(); i++){
            l[i] = S.charAt(i);
        }
        if(S.length() % 2 == 0){
            for(int i = 0; i < S.length()/2; i++){
                if(l[i] != l[S.length()-1 - i]) count++;
            }
        }else{
            for(int i = 0; i < (S.length()-1)/2; i++){
                if(l[i] != l[S.length()-1 - i]) count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = (int)s.size();
    int ans = 0;
    rep(i,n){
        if(s[i] == '('){
            ans++;
        }else if(s[i] == ')'){
            ans--;
        }else{
            cout << ans << endl;
            return 0;
        }
    }
}



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

#define int long long

#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
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s,t;
    cin>>s>>t;
    reverse(all(t));
    if(s==t)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n =sc.nextInt();
		int[] h = new int[100000001];
		boolean flag=false;
		for(int i=0;i<n;i++) {
			if(i==0) h[i]-=1;
			h[i]=sc.nextInt();
			if( i!=0 && h[i]>h[i-1] ) { //単調減少列が作れるかになっていた
					h[i]--;
			}
		}
		for(int i=0;i<n;i++) {
			if(i!=0 && h[i]<h[i-1]) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 462804
#include <iostream>
#include <complex>
#include <cstdio>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

typedef complex<double> P;

double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}


int main(){
    double x, y;
    cin >> x >> y;
    P p0(x, y);
    cin >> x >> y;
    P p1(x, y);

    int Q;
    cin >> Q;
    REP(q, Q) {
        cin >> x >> y;
        P p2(x, y);

        P vec1 = p1 - p0;
        P vec2 = p2 - p0;

        P ret = p0 + vec1 * dot(vec1, vec2) / dot(vec1, vec1);
        printf("%.10lf %.10lf\n", ret.real(), ret.imag());
    }

    return 0;
}

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

using namespace std;

int n, m, ans;
bool edge[8][8];
int perm[8];

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edge[a][b] = edge[b][a] = true;
  }
  
  for (int i = 0; i < n; i++) {
    perm[i] = i;
  }
  
  do {
    bool f = true;
    for (int i = 0; i < n-1; i++) {
      if (not edge[perm[i]][perm[i+1]]) {
        f = false;
      }
    }
    if (f) ans++;
  } while (next_permutation(perm + 1, perm + n));
  
  cout << ans << endl;
  return 0;
}

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

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

  if(a+b == 15) cout << '+' << endl;
  else if(a*b == 15) cout << '*' << endl;
  else cout << 'x' << endl; 
  
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if ( L == R ) {
    cout << "Balanced" << endl;
  }
  if ( L > R ) {
    cout << "Left" << endl;
  }
  if ( L < R ) {
    cout << "Right" << endl;
  }
}

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

int main(void){
	int N,M;
	std::array<int,50> cities{0};
	std::cin>>N>>M;

	for(int i=0;i<M;i++){
		int a,b;
		std::cin>>a>>b;
		cities.at(a-1) += 1;
		cities.at(b-1) += 1;
	}

	for(int i=0;i<N;i++){
		std::cout<<cities.at(i)<<std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  ll n, hp;  cin >> n >> hp;
  vector<pair<ll, ll>> sword(n);
  for(int i=0; i<n; i++){
    cin >> sword[i].first >> sword[i].second;
  }
    

  sort(sword.begin(), sword.end());
  vector<ll> poi;
  for(int i=0; i<n-1; i++)
    if(sword[n-1].first<sword[i].second) poi.push_back(sword[i].second);
  
  poi.push_back(sword.back().second);
  sort(poi.begin(), poi.end(), greater<ll>());
  ll cnt=0;
  
  while(0<hp && cnt<poi.size()){
    hp -= poi[cnt];   cnt += 1;
  }

  if(0<hp)
    cnt += hp/sword.back().first + min(1LL, hp%sword.back().first);
  
  cout << cnt << endl;  

  
}


Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <cmath>


using namespace std;



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

  int a, b;
  cin >> a >> b;

  int maxProfit = b - a;
  int minPrice  = min(a, b);

  for (int i = 2; i < n; i++) {
    int input;
    cin >> input;

    maxProfit = max(maxProfit, input - minPrice);
    minPrice  = min(minPrice, input);
  }

  cout << maxProfit << endl;
}

Measured memory_bytes: 1160
S = input()
# L = len(S) % 2
youtube = 0

for i in range(len(S)):
  if i % 2 == 0: # 奇数
    if S[i] == "L":
      youtube += 1
  else:#偶数
    if S[i] == "R":
      youtube += 1
if youtube > 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    string s;cin >> s;
    vector<set<ll>> v(26);
    rep(i,n){
        ll a=s[i]-'a';
        v[a].ins(i);
    }
    ll q;cin >> q;
    rep(i,q){
        ll type;cin >> type;
        if(type==1){
            ll b;cin >> b;b--;
            char c;cin >> c;
            v[s[b]-'a'].erase(b);
            v[c-'a'].insert(b);
            s[b]=c;
        }
        else{
            ll b,c;cin >> b >>c;b--;c--;
            ll k=0;
            rep(j,26){
                auto iter=v[j].lower_bound(b);
                if(iter!=v[j].end()){
                    if(*iter<=c)k++;
                }
            }
            cout << k <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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 gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}



int main(){

  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(14);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  //cerr << now << '\n';
  rep(d,D){
    rep(q,26){
      if(chmax(now,calc(t,d,q))){
        //cerr << "!";
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d=mt()%365, q=mt()%26;
    if(chmax(now,calc(t,d,q))){
      t[d]=q;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3680
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    two = 0
    four = 0
    for a in A:
        if a % 4 == 0:
            four += 1
        elif a % 2 == 0:
            two += 1
    if N % 2 == 1:
        if four * 2 + two + 1 >= N:
            print("Yes")
        else:
            print("No")
    else:
        if four * 2 + two >= N:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 14252
#include <stdio.h>
#include <math.h>

int main(void) {

  int n;
  scanf("%d", &n);
  long mod = pow(10,9)+7;
  int prime[1001];
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i <= 1000; i++) {
    prime[i] = 1;
  }
  for (int i = 2; i <= 1000; i++) {
    if (prime[i] == 1) {
      for (int j = 2; i*j <= 1000; j++) {
        prime[i*j] = 0;
      }
    }
  }
  long factors[1001];
  for (int i = 1; i <= 1000; i++) {
    factors[i] = 0;
  }
  long number;
  for (int i = 2; i <= n; i++) {
    number = i;
    for (int j = 2; j <= i; j++) {
      if (prime[j] == 1) {
        if (number%j == 0) {
          number /= j;
          factors[j]++;
          while (number%j == 0) {
            number /= j;
            factors[j]++;
          }
        }
      }
    }
  }
  long sum = 1;
  for (int i = 2; i <= n; i++) {
    if (factors[i] > 0) {
      sum *= factors[i]+1;
      sum %= mod;
    }
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define pi 3.14159
#define ll long long 
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = s; 
    for (int i=1; i<n;i++) 
        s += s1;
    return s; 
}
string getString(char x) {
    string s(1, x); 
    return s;    
} 

void optimizeIO(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
}

vector<ll> primeFactors(ll n)  { 
    vector<ll> v;
    if(n%2==0) v.pb(2); 
    while (n % 2 == 0)  {  
        n = n/2;  
    }  
    for (ll i = 3; i <= sqrt(n); i = i + 2) {  
        if(n%i==0) v.pb(i);
        while (n % i == 0) {  
            n = n/i;  
        }  
    } 
    if (n > 2)  v.pb(n);
    return v;
}  
bool isPrime(ll n){
    if (n <= 1)  return false; 
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
} 
int main(){
    optimizeIO();
    int n;
    cin>>n;
    n%=26;
    string s;
    cin>>s;
    rep(i,0,s.length()){
        // cout<<s[i]+n<<endl;
        s[i]= isupper(s[i]+n) ? s[i]+n:s[i]+n-26;
    }
    cout<<s<<endl;
    
}


Measured memory_bytes: 256
import sys;sys.setrecursionlimit(int(1e7))

N = int(input())

tree = [[] for _ in range(N+1)]
depth = [None]*(N+1)

ABC = [ tuple(map(int,input().split())) for _ in range(N-1)]
Q,K = map(int,input().split())
XY = [tuple(map(int,input().split())) for _ in range(Q)]

for abc in ABC:
    tree[abc[0]].append((abc[1],abc[2]))
    tree[abc[1]].append((abc[0],abc[2]))

def DFS(v,p,d):
    depth[v] = d
    for e in tree[v]:
        if e[0] != p:
            DFS(e[0], v, d + e[1])

DFS(K,0,0)

for i in range(Q):
    print(depth[XY[i][0]] + depth[XY[i][1]])

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int N;
    cin>>N;
    Vi A(N);
    REP(i,N) cin>>A[i];
    sort(ALL(A));
    cout<<abs(A[0]-A[N-1])<<endl;
    return 0;
}

Measured memory_bytes: 256
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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


char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    int count = 0;
    REP(i, 0, n){
        int a, b; cin >> a >> b;
        if(a == b){
            count++;
        }else{
            count = 0;
        }
        if(count >= 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;

int v;
ll dis[105][105];

void warshall_floyd() {
    rep(k,v)rep(i,v)rep(j,v) {
        if (dis[i][k] == inf || dis[k][j] == inf) continue;
        dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
    }
}

int main() {
    int e;
    cin >> v >> e;
    rep(i,v)rep(j,v) dis[i][j] = inf;
    rep(i,e) {
        int a, b, c;
        cin >> a >> b >> c;
        dis[a][b] = c;
    }
    rep(i,v) dis[i][i] = 0;
    warshall_floyd();
    bool ok = true;
    rep(i,v) if(dis[i][i] < 0) ok = false;
    if (!ok) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    rep(i,v) {
        rep(j,v) {
            if (dis[i][j] == inf) {
                cout << "INF";
            }
            else cout << dis[i][j];
            if (j != v-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3188
n, k = map(int, input().split())
a = [i-1 for i in map(int, input().split())]
left, right = 1, 10**9
while left < right:
    middle = (left + right)//2
    count = sum(i//middle for i in a)
    if count <= k:
        right = middle
    else:
        left = middle + 1
print(left)

Measured memory_bytes: 30944
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, a, b) for (int i = (a); i <= (b); i++)
#define repi(i, n) REPI(i, 0, n)
#define ALL(vs) (vs).begin(), (vs).end()
typedef long long ll;
typedef pair<int, int> pii;

#define MAX 52

void pop_front(vector<int> vs)
{
    reverse(ALL(vs));
    vs.pop_back();
    reverse(ALL(vs));
}

int main()
{
    int n, r;
    while (cin >> n >> r, n|r) {
        int arr[MAX];
        rep(i, n) arr[i] = i;
        reverse(arr, arr+n);

        rep(t, r) {
            int p, c;
            cin >> p >> c;

            int buf[MAX];
            rep(i, p-1) buf[i] = arr[i];
            rep(i, c)   arr[i] = arr[p-1+i];
            rep(i, p-1) arr[c+i] = buf[i];
        }

        printf("%d\n", arr[0]+1);
    }
    return 0;
}

Measured memory_bytes: 1144
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26244
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = list(map(int, sys.stdin.buffer.readline().split()))
    print(A if A <= B else A-1)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int n,a,b;
    cin>>n>>a>>b;
    {
        if(abs(a-b)%2){
            cout<<"Borys"<<endl;
        }else{
            cout<<"Alice"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

const int N=100001;

int n;
vector<int> G[N];
int color[N];

void dfs(int x,int y){
  stack<int> S;
  
  S.push(x);
  color[x]=y;
  
  while(!S.empty()){
    int u=S.top();
    S.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      if(color[v]==-1){
	color[v]=y;
	S.push(v);
      }
    }
  }
}

void assignColor(){
  int id=1;
  for(int i=0;i<n;i++) color[i]=-1;
  for(int i=0;i<n;i++){
    if(color[i]==-1) dfs(i,id++);
  }
}

int main(){
  int m,q,s,t;

  cin>>n>>m;

  for(int i=0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin>>q;

  for(int i=0;i<q;i++){
    cin>>s>>t;
    if(color[s]==color[t]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 7060
#include <algorithm>
#include <cassert>
#include <iostream>
using namespace std;

bool cmp (const pair<int, int> &lhs, const pair<int, int> &rhs) {
    if (lhs.second >= 0) {
        if (rhs.second >= 0) return lhs.first > rhs.first;
        else return true;
    } else {
        if (rhs.second >= 0) return false;
        else return lhs.second - lhs.first > rhs.second - rhs.first;
    }
}

int main() {
    int n; cin >> n;
    pair<int, int> a[n];
    int sum = 0;
    int sum_len = 0;
    for (int i = 0; i < n; i++) {
        string str; cin >> str;
        int s = 0;
        a[i] = {0, 0};
        for (char c : str) {
            if (c == '(') s++;
            else s--;
            a[i].first = min(a[i].first, s);
        }
        a[i].second = s;
        sum += s;
        sum_len += str.size();
    }
    if (sum != 0) { cout << "No\n"; return 0; }
    sort(a, a+n, cmp);
    sum = 0;
    for (auto &p : a) {
        if (sum + p.first < 0) { cout << "No\n"; return 0; }
        else sum += p.second;
    }
    cout << "Yes\n";
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);

	int k, t;
	vector<pair<int, int> > cake;
	cin >> k >> t;

	for(int i=0; i<t; i++){
		int a;
		cin >> a;
		cake.push_back(make_pair(a, i));
	}

	int bef = -1;
	int ans = 0;
	for(int i=0; i<k; i++){
		sort(cake.begin(), cake.end(), greater<pair<int, int> >());

		bool f = false;
		for(int j=0; j<t; j++){
			if(cake[j].first > 0 && cake[j].second != bef){
				cake[j].first--;
				f = true;
				bef = cake[j].second;
				break;
			}
		}
		if(f == false) {
			cake[0].first--;
			bef = cake[0].second;
			ans++;
		}

		/*
		for(int j=0; j<t; j++){
			printf("%d %d\n", cake[j].second, cake[j].first);
		}
		puts("");
		*/
	}

	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i,k) for(int i =0; i<k; i++)
#define ll long long int

using namespace std;



int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b && b!=c){
        cout << "Yes";
    }else{
        if(b==c && c!=a){
            cout << "Yes";
        }else{
            if(c==a && a!=b){
                cout << "Yes";
            }else{
                cout << "No";
            }
        }
    }
}


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()
{
    int N;
    cin >> N;
    vector<int> A(N + 1, 0);

    rep(i, N)
    {
        cin >> A.at(i);
    }
    int Alice = 0;
    int Bob = 0;
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    rep(i, N)
    {
        Alice += A.at(i);
        Bob += A.at(i + 1);
        i++;
    }
    cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#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 <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const  long long INF = 1LL << 60;
typedef unsigned long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}



int main(){
int N; cin >> N;
vector<int> a(N);
rep(i,N) cin >> a[i];
vector<int> b(N);
b = a;
sort(all(b));
int x = b[0];
int y = b[N-1];
int ans = 10000007;
int m = 0;

for(int i = x; i <= y;i++){
    for(int j = 0; j < N; j++){
        m += (a[j] - i) * (a[j] - i);
    }
    ans = min(ans,m);
    m = 0;
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
    using ll = long long;
     
    int main() {
      ios::sync_with_stdio(false);
      cin.tie(0);
      ll K, A, B;
      cin >> K >> A >> B;
      if (B - A > 2 && A < K)
        cout << A + (B - A) * max(1LL * 0, (K - (A - 1)) / 2) + ((K - (A - 1)) % 2)
             << '\n';
      else
        cout << K + 1 << '\n';
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include <algorithm>


using namespace std;


int main() {
    int i,j,n,x,ans,temp;
    ans=0;
   // temp=0;
    cin >> n >> x;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    /*for(i=0;i<n;i++){
        for(j=0;j<n;j++){
        if(a[i]<a[j]){
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }}*/
    sort(a.begin(), a.end());
    for(i=0;i<n;i++){
        x-=a[i];
        ans++;
        if(x==0){
            break;
        }else if(x<0){
            ans--;
            break;
        }
       // cout << a[i] <<endl;
    }
    if(x>0){ans--;}
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
w = []
for i in range(N):
  w.append(input())

v = True
z = list(set(w))
if len(z) != len(w):
  print("No")
else:
  for j in range(N - 1):
    if w[j][-1] != w[j+1][0]:
      v = False
  print("Yes") if v else print("No")


Measured memory_bytes: 9124
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;


int cnt[100];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i< M; ++i) {
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }
    for (int i = 1; i <= N; ++i) {
        cout << cnt[i] << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int s;
long long dp[2005];
int main() {
	scanf("%d",&s);dp[0]=1;
	for(int i=3;i<=s;++i) {
		for(int j=0;j<=i-3;++j) {
			dp[i]=(dp[i]+dp[j])%1000000007;
		}
	}
	printf("%lld",dp[s]);
	return 0;
}

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

#define int long long
#define w cout
#define e '\n'
#define sz(x) (int)x.size()
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.first >> p.second; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 + 10 , mod = 998244353;

signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n , k; cin >> n >> k;
	vector<int>v(n);
	cin >> v;
	sort(begin(v) ,end(v));
	int x = n - k;
	int ans =0 ;
	for(int i = 0; i < x; i ++ ){
		ans += v[i];
	}
	w << ans;
}	



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

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	
	int s = 0;
	for(int i=0;i<m;i++) {
		int x;
		scanf("%d", &x);
		
		s+=x;
	}
	printf("%d\n", max(-1, n-s));
	
	return 0;
}

Measured memory_bytes: 3824
def sums(num)
  return num*(num+1)/2
end

n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)

px = Array.new(n)
for i in 0..(n-1)
  px[i] = sums(p[i])*1.0/p[i]
end
pxs = Array.new(n+1)
pxs[0] = 0.0
for i in 0..(n-1)
  pxs[i+1] = px[i]+pxs[i]
end

ans = 0.0
for i in k..n
  val = pxs[i]-pxs[i-k]
  ans = [ans, val].max
end
puts ans

Measured memory_bytes: 21900
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int x;
    cin>>x;
    int a = x/500;
    x = x%500;
    int b = x/5;
    long long ans = a*1000;
    ans += b*5;
    cout<<ans;
    return 0;
}

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

#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int INF = 100500;
const int MAXN = 1e5 + 9;
const int MOD = 1e9 + 7;

int n, m;
ll aa[MAXN];
ll bb[MAXN];
ll ans = 0;

void input() {                  
	cin >> n;
	for(int i = 0; i < n; i++) cin >> aa[i] >> bb[i];
}

void solve() {          
	for(int i = n - 1; i >= 0; i--) {
		ll cur = (aa[i] + ans + bb[i] - 1) / bb[i];
		ans += cur * bb[i] - aa[i] - ans;
	}
	cout << ans << endl;
}

int main() {     
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen("xxx.in", "r", stdin);
	//freopen("xxx.out", "w", stdout);
#endif	
	input();
	solve();
	return 0;
}


Measured memory_bytes: 1792
import math
a,b,h,m=map(int,input().split())
sa=h*30+m/2
sb=6*m
s=max(sa,sb)-min(sa,sb)
if s>180:
  s=360-s
cos=math.cos(math.radians(s))
ans=(a**2+b**2-2*a*b*cos)**(1/2)
print(ans)

Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int P[100000];
LL A[100000];
LL B[100000];
LL C[100000];
LL sum[100000];
int main() {
    int N,M;
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++) {
        scanf("%d",&P[i]);P[i]--;
    }
    for(int i=0;i<N-1;i++) {
        scanf("%lld %lld %lld",&A[i],&B[i],&C[i]);
    }
    for(int i=0;i+1<M;i++) {
        int from=P[i],to=P[i+1];
        if(from>to) swap(from,to);
        sum[from]++;
        sum[to]--;
    }
    for(int i=1;i<N;i++) {
        sum[i]+=sum[i-1];
    }
    LL ans=0;
    for(int i=0;i<N-1;i++) {
        ans+=min(A[i]*sum[i],C[i]+sum[i]*B[i]);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 4704
#include <vector>
#include <iostream>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

char g[10];
void gDfs(int i, int n, int mxChar) {
  if (i == n) {
    cout << g << endl;
    return;
  }
  rep(j, mxChar + 1) {
    g[i] = (char)('a' + j);
    gDfs(i + 1, n, j == mxChar ? (mxChar + 1) : mxChar);
  }
}

void dfs(int i, int n, int mxChar, const string& s) {
  if (i == n) {
    cout << s << endl;
    return;
  }
  rep(j, mxChar + 1) {    
    string ss(s);
    ss.push_back((char)('a' + j));
    dfs(i + 1, n, j == mxChar ? (mxChar + 1) : mxChar, ss);
  }
}

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

  int n;
  cin >> n;
  // dfs(0, n, 0, "");
  gDfs(0, n, 0);
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<math.h>
double dist(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
    double x1,x2,y1,y2,d;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    d =dist(x1,y1,x2,y2);
    printf("%.6lf\n",d);
    return 0;
}


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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int i;
    vector<int> a(n);
    for(i = 0; i < n; i++){
        cin >> a.at(i);
    }
    vector<int> b(n);
    for(i = 0; i < n; i++){
        cin >> b.at(i);
    }
    vector<int> c(n-1);
    for(i = 0; i < n-1; i++){
        cin >> c.at(i);
    }
    int ans = 0;
    int flag = 100000;
    for(i = 0; i < n; i++){
        ans += b.at(a.at(i)-1);
        if(a.at(i) == flag + 1){
            ans += c.at(flag-1);
        }
        flag = a.at(i);
    }
    cout << ans << endl;
    return 0;
}


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

char c;

int main(){

    cin >> c;

    if(c == 'a'||c == 'i'||c == 'e'||c == 'u'||c == 'o'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n,a,b; cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
}


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

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

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

void Main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  map<int, int> M;
  rep(i, n) M[A[i]]++;
  ll tot = 0;
  for(auto itr = M.begin(); itr != M.end(); ++itr) {
    ll x = itr->second;
    tot += x*(x-1)/2;
  }
  for(int a : A) {
    cout << tot - (M[a] - 1) << endl;
  }
}

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



Measured memory_bytes: 9984
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

/*--------switch header--------*/
#define ALGORITHM   1
#define CASSERT     0
#define CMATH       0
#define DEQUE       0
#define FUNCTIONAL  1
#define IOMANIP     1
#define IOSTREAM    1
#define LIST        0
#define MAP         0
#define QUEUE       0
#define SET         0
#define STRING      1
#define UTILITY     1
#define VECTOR      1
#define VEC_DEBUG   1

using namespace std;

#pragma region headers
#if VEC_DEBUG
#define _GLIBCXX_DEBUG
#endif
#if ALGORITHM
#include <algorithm>
#endif
#if CASSERT
#include <cassert>
#endif
#if CMATH
#include <cmath>
#endif
#if DEQUE
#include <deque>
#endif
#if FUNCTIONAL
#include <functional>
#endif
#if IOMANIP
#include <iomanip>
#endif
#if IOSTREAM
#include <iostream>
#endif
#if LIST
#include <list>
#endif
#if MAP
#include <map>
#endif
#if QUEUE
#include <queue>
#endif
#if SET
#include <set>
#endif
#if STRING
#include <string>
#endif
#if UTILITY
#include <utility>
#endif
#if VECTOR
#include <vector>
#endif
#pragma endregion


/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define ALL(x)          (x).begin(), (x).end()
#define rALL(x)         (x).rbegin(), (x).rend()
#define REP(i, n)       for(int i = 0; (i) < (n); (i)++)
#define rREP(i, n)      for(int i = n - 1; (i) >= 0 ; (i)--)
#define FOR(i, a, b)    for(int i = (a); (i) < (b) ; (i)++)
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int x; cin >> x;
    int a = x/500;
    int b = x%500 / 5;

    cout << a * 1000 + b * 5 << endl;

return 0;
}

Measured memory_bytes: 3584