akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  std::vector<int> a(n + 1), s(n + 1);
  map<int, int> mp;
  for(int i = 1; i <= n; ++i) {
  	cin >> a[i];	
  	s[i] = s[i - 1] + a[i];
  	mp[s[i]]++;
  }
  int res = 0;
  for(int i = 1; i <= n; ++i) {
  	res += mp[s[i - 1]];
  	// cout << s[i] << ' ' << mp[s[i]] << endl;
  	mp[s[i]]--;
  }
  cout << res << endl;
	return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 10000000000000000;


vector<tuple<int,int,int>> elist[100005];
ll dist[100005];


int main(){ 
  int n,m;
  cin >> n >> m;
  rep(i,n) dist[i] = BIG;
  rep(i,m){
    int l,r,c;
    cin >> l >> r >> c;
    elist[r].push_back(make_tuple(c,l,r));
  }

  int lnow = n;
  int rdone = n+1;
  priority_queue<tuple<int,int,int>,                
      std::vector<tuple<int,int,int>>,  
      std::greater<tuple<int,int,int>>
      > que;


    rdone = n;
  for(int _=n; _>1; _--){
    if(elist[_].empty()) continue;
    for(const auto& e:elist[_]){
      que.push(e);
    }
    
    int lnow = _;
    while(!que.empty()&&lnow != 1){
      tuple<int,int,int> tmp = que.top();
      que.pop();
      int ctmp,ltmp,rtmp;
      ctmp = get<0>(tmp);
      ltmp = get<1>(tmp);
      rtmp = get<2>(tmp);

      for(int i = ltmp; i < lnow; i++){
        if(dist[i] <= dist[rtmp] +ctmp) {break;}
        else{dist[i] = dist[rtmp]+ctmp;}
      }
      lnow = ltmp;
    }
    //prints(_);
  }


  if(dist[1] == BIG){
    cout << -1 << endl;
  }
  else{

    cout << dist[1] << endl;
  }








  return 0;

}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

const int N = 1005;

vector<int> graph[N];

int n, m, l[200005], r[200005], cnt[N][N], vis[N][N];

void dfs(int u, int p, int root, int mark) {
    if(u == root) return ;
    if(cnt[root][u] >= 2) return ;
    if(vis[root][u] == mark) return ;
    vis[root][u] = mark; cnt[root][u]++;
    for(int i = 0; i < graph[u].size(); i++) {
        int v = graph[u][i];
        if(v == p) continue;
        dfs(v, u, root, mark);
    }
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        cin >> l[i] >> r[i];
        graph[l[i]].pb(r[i]);
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < graph[i].size(); j++) {
            int v = graph[i][j];
            dfs(v, i, i, v);
        }
    }
    for(int i = 1; i <= m; i++) {
        if(cnt[l[i]][r[i]] >= 2) {
            if(cnt[r[i]][l[i]] == 0)
                cout << "diff\n";
            else
                cout << "same\n";
        }
        else {//1
            if(cnt[r[i]][l[i]] >= 1)
                cout << "diff\n";
            else
                cout << "same\n";
        }
    }
}


Measured memory_bytes: 12288
h,w = (int(i) for i in input().split())
a,b = [],["" for i in range(w)]
for _ in range(h):
	s = input()
	if s.count("#")!=0:
		a.append(s)
		for i in range(w): b[i]+=s[i]
num,ans = [True for i in range(w)],["" for i in range(len(a))]
for i in range(w):
	if b[i].count("#")==0: num[i] = False
for i in range(len(a)):
	for j in range(w):
		if num[j]: ans[i]+=a[i][j]
for i in ans: print(i)

Measured memory_bytes: 3064
x = int(input())
k = int(x/100)
h = x%100
h2 = 0
for i in range(k):
    if h-h2>=5:
        h2+=5
    elif h-h2>=4:
        h2+=4
    elif h-h2>=3:
        h2+=3
    elif h-h2>=2:
        h2+=2
    elif h-h2>=1:
        h2+=1
    else:
        pass
print(1) if h2 == h else print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m;
ll card[101010];
int main() {
    cin>>n>>m;
    REP(i, 0, m){
        ll l, r;
        cin>>l>>r;
        l--;
        card[l]++;
        card[r]--;
    }

    ll mx=0, ans=0;
    REP(i, 0, n+1){
        card[i+1]+=card[i];
        mx=max(mx, card[i]);
    }

    REP(i, 0, n+1){
        if(card[i]==mx) ans++;
    }
    if(mx==m) cout<<ans<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main() {
    int a;
    int x[101];
    int y[101];

    for (int i = 0; i < 101; i++) {
        x[i] = -1;
        y[i] = -1;
    }

    bool bingo[3][3];
    for (int j = 0; j < 3; j++) {
        for (int i = 0; i < 3; i++) {
            std::cin >> a;
            x[a] = i;
            y[a] = j;
            bingo[j][i] = false;
        }
    }

    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        int b;
        std::cin >> b;

        if (x[b] > -1 && y[b] > -1) {
            bingo[y[b]][x[b]] = true;
        }
    }

    bool yes = false;
    for (int j = 0; j < 3; j++) {
        if (bingo[j][0] && bingo[j][1] && bingo[j][2])
            yes = true;
    }
    for (int i = 0; i < 3; i++) {
        if (bingo[0][i] && bingo[1][i] && bingo[2][i])
            yes = true;
    }
    if (bingo[0][0] && bingo[1][1] && bingo[2][2])
        yes = true;
    if (bingo[2][0] && bingo[1][1] && bingo[0][2])
        yes = true;

    if (yes)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
    
    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    a = [int(i) for i in input().split()]

    c = 0
    for i in a:
        if i == c + 1:
            c += 1

    print(n - c if c else -1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;

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

int F[400], P[400][20];

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

    int N;
    std::cin >> N;

    for(int i=0;i<N;++i){
        for(int j=0;j<10;++j){
            int x;
            std::cin >> x;

            F[i] |= x << j;
        }
    }

    for(int i=0;i<N;++i){
        for(int j=0;j<=10;++j){
            std::cin >> P[i][j];
        }
    }

    ll res = -1001001001001001001ll;
    for(int i=1;i<(1<<10);++i){
        ll x = 0ll;
        for(int j=0;j<N;++j){
            int both = F[j] & i;
            x += P[j][__builtin_popcount(both)];
        }

        res = max(res, x);
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 256
s = input()
s = list(s)
t = input()
t = list(t)

l = []
for i in range(len(s)-len(t)+1) :
    moji = s[i]
    for j in range(len(t)-1) :
        moji += s[i+j+1]
    l.append(moji)
    moji = ""
c = 0
ans = 1000
for i in range(len(l)):
    c = 0
    for j in range(len(t)):
        if l[i][j] != t[j] :
            c += 1
    if ans > c :
        ans = c
print(ans)


Measured memory_bytes: 9236
#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;}
 
int N;
int cnt[111];
 
signed main(){
    cin>>N;
    for(int i=1;i<=N;i++){
        int n=i;
        for(int j=2;j<=n;j++){
            while(n%j==0){
                cnt[j]++;
                n/=j;
            }
        }
    }
 
    vint dp(100);
    dp[1]=1;
    rep(i,111){
        vint dp2(100);
        rep(j,100){
            rep(k,cnt[i]+1){
                if(j*(k+1)>=100)continue;
                dp2[j*(k+1)]+=dp[j];
            }
        }
        dp=dp2;
    }
    cout<<dp[75]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl "\n"
#define int ll

signed main ()
{
 
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     //freopen("input.txt", "r", stdin); 
     //freopen("output.txt", "w", stdout);
 	
	int left, right, d;
	cin >> left >> right >> d;
	
	int ans = 0;
	for (int i=left; i<=right; i++){
		ans += (i%d == 0);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3536
(defun read-fixnum+ ()
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char *standard-input* nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte *standard-input* nil #.(char-code #\Nul) nil))))
    (let ((result (loop (let ((byte (%read-byte)))
                          (cond ((<= 48 byte)
                                 (return (- byte 48)))
                                ((zerop byte) ; #\Nul
                                 (return-from read-fixnum+ 0)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return result)))))))

(defun main ()
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (let ((n (read))
        (ptime 0)
        (px 0)
        (py 0))
    (declare ((unsigned-byte 32) n ptime px py))
    (dotimes (_ n (write-line "Yes"))
      (let ((time (read-fixnum+))
            (x (read-fixnum+))
            (y (read-fixnum+)))
        (declare ((unsigned-byte 32) time x y))
        (let ((l1 (+ (abs (- x px)) (abs (- y py))))
              (dt (- time ptime)))
          (unless (and (<= l1 dt) (evenp (+ l1 dt)))
            (write-line "No")
            (return-from main))
          (setq ptime time px x py y))))))

#-swank(main)


Measured memory_bytes: 16736
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int Search(vector <long long int>v8,long long int n,long long int x){
    int z;
    for(z=0;z<n&&v8[z]<=x;z++){
        if(v8[z]==x)
           return z;}
    return -1;
}
int main()
{
    long long int n,k,x,i,count=500,h,g,l,ish=500,r;
    string s;
    vector<string> v;
    vector<long long int> v2;
    vector<long long int> v3;
    vector<long long int> fv;
    cin>>s;
    while(s.find('B')<s.length())
    {if(s.find('B')>0){size_t found=s.find('B');
    s.erase(found-1,2);}
    if(s.find('B')==0){
      size_t found=s.find('B');
      s.erase(found,1);}
    }
    
   cout<<s;
    return 0;
}


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

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

using namespace std;

typedef long long int lli;

int bitcount(int num) {
    int cnt = 0;
    for (; num; num >>= 1) cnt += (num & 1);
    return cnt;
}

int main () {
    lli N, K;
    cin >> N >> K;
    vector<lli> A, B;
    lli sum = 0;
    lli fst = 0;
    REP (i, 0, N) {
        int a, b;
        cin >> a >> b;
        if (a <= K) {
            A.push_back(a);
            B.push_back(b);
            sum += b;
            if ((a | K) == K) {
                fst += b;
            }
        }
    }
    if (K == 0) {
        cout << sum << endl;
        return 0;
    }
    int pos = log2(K & (-K)) + 0.1;
    int cnt = 0;
    for (lli num = 1; num <= K; num *= 2) cnt++;
    lli ans = fst;
    for (int p = pos; p < cnt; p++) {
        if (((K >> p) & 1) == 0) continue;
        lli mask = (K - (1 << p)) | ((1LL << p) - 1);
        lli tmp = 0;
        REP (i, 0, A.size()) {
            if ((A[i] | mask) == mask) {
                tmp += B[i];
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2164
N = int(input())
As = list(map(int, input().split()))

Bs = []

for i in range(N):
    Bs.append(As[i]-i-1)

Bs.sort()
b = Bs[N//2]

ans = 0

for i in range(N):
    ans += abs(Bs[i]-b)

print(ans)


Measured memory_bytes: 99796
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
vector<int> ad[100001];
int p[100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    // vector<vector<int>> ad(n, vector<int>());
    // vector<int> d(n, 0x3f3f3f3f);
    memset(p, -1, sizeof(p));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        ad[a].push_back(b);
        ad[b].push_back(a);
    }
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        // int val = d[u] + 1;
        for (int v : ad[u]) {
            if (p[v] == -1) {
                p[v] = u;
                q.push(v);
            }
        }
    }
    bool ok = true;
    for (int i = 1; i < n; i++) {
        if (p[i] == -1) {
            ok = false;
            break;
        }
    }
    if (ok) {
        cout << "Yes\n";
        for (int i = 1; i < n; i++)
            cout << p[i] + 1 << '\n';
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 10432
#include <iostream>
 
using namespace std;
 
int main() {
 
 
  int n = 1;
  cin >> n;
 
  for ( int i = 111; i <= 999; i += 111 ) {
    if ( n <= i ) {
      cout << i << endl;
      return 0;
    }
  }
 
 
  return 0;
}
 

Measured memory_bytes: 256
n,m= map(int,input().split())
A_line =[]
row=[]

for i in range(n):
    line = [int(i) for i in input().split()]
    A_line.append(line)
for i in range(m):
    row += [int(i) for i in input().split()]
for i in range(n):
    c=0
    for j in range(m):
        c += A_line[i][j]*row[j]
    print(c)


Measured memory_bytes: 6008
n, m = map(int, input().strip().split())
hs = list(map(int, input().strip().split()))
edges = [list(map(int, input().strip().split())) for _ in range(m)]

matrix = [[] for _ in range(n)]
for a, b in edges:
    matrix[a - 1].append(b - 1)
    matrix[b - 1].append(a - 1)

good = 0
for a in range(n):
    bs = matrix[a]
    h = hs[a]
    highest = all([hs[b] < h for b in bs])
    if len(bs) == 0 or highest:
        good += 1

print(good)


Measured memory_bytes: 48264
import functools

MOD = 10 ** 9 + 7
N = int(input())

primes = [2]

for i in range(3, N + 1):
    if not [p for p in primes if i % p == 0]:
        primes.append(i)

count = {p: 0 for p in primes}
for i in range(1, N + 1):
    num = i
    for p in primes:
        while num % p == 0:
            count[p] += 1
            num //= p

print(functools.reduce(lambda s, c: s * (c + 1) % MOD, count.values(), 1))


Measured memory_bytes: 3572
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
void solve(){
    set<int>st;
    rep(i,3) {
        int a;
        cin>>a;
        st.insert(a);
    }
    if(sz(st)==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




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

#define pb push_back

using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;


const int MOD = 1e9 + 7;

inline void addstates(vi& nextdp, const vi& dp, int dig, int mul) {
    for (int i=0; i<13; ++i) {
        int newrem = (dig*mul + i)%13;
        nextdp[newrem] += dp[i];
        nextdp[newrem] %= MOD;
    }
}

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

    string s;
    cin >> s;
    vi dp(13);
    dp[0] = 1;
    int mul = 1;
    for (int i=s.size()-1; i>=0; --i) {
        vi nextdp(13);
        if (s[i] == '?') {
            for (int j=0; j<10; ++j)
                addstates(nextdp, dp, j, mul);
        }
        else
            addstates(nextdp, dp, s[i]-'0', mul);
        mul = (mul*10)%13;
        swap(nextdp, dp);
    }
    cout << dp[5] << "\n";
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, s[310000], a, b;
int main() {
	cin >> n;
	REP(i, n) {
		cin >> s[i];
	}
	a = 0, b = n - 1;
	REP(i, n) {
		if (a < i) {
			cout << "no" << endl;
			return 0;
		}
		a = max(a, i + s[i] / 10);
	}
	REPR(i, n - 1) {
		if (b > i) {
			cout << "no" << endl;
			return 0;
		}
		b = min(b, i - s[i] / 10);
	}
	cout << "yes" << endl;
}


Measured memory_bytes: 5432
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
const int nmax = 2e5 + 5 ;
vector < ll > seg_tree(4*nmax);
ll query( int node , int start , int end , int l , int r ){
    if( start > r || end < l || l > r ){
        return 0 ;
    }
    if( start >= l && end <= r){
        return seg_tree[node];
    }
    int mid = (start+end)/2;
    return max(query(node*2 , start , mid , l , r),query(2*node+1,mid+1,end,l,r));
}
void update( int node , int start , int end , int pos , ll val ){
    if(start==end && start == pos){
            seg_tree[node] = val ;
            return ;
    }
    int mid = (start+end)/2;
    if(pos<=mid){
        update(2*node , start , mid , pos , val);
    }
    else{
        update(2*node+1,mid+1,end,pos,val);
    }
    seg_tree[node] = max( seg_tree[node*2] , seg_tree[node*2+1]);
}
void solve( ){
    int n  ;
    cin >> n ;
    vector < pair < int , int > >  a(n);
    for( int i = 0 ; i < n ; i++) cin >> a[i].ff ;
    for( int i = 0 ; i < n ; i++) cin >> a[i].ss ;
    // brute force
    vector < ll > dp(n,0);
    for( int i = 0 ; i < n ; i++) dp[i] = a[i].ss ;
    for( int i = 0 ; i < n ; i++){
        ll best = query(1 ,0 , nmax-1 , 0 , a[i].ff - 1 );
        dp[i] = best+a[i].ss;
        update(1 , 0 , nmax-1 , a[i].ff , best+a[i].ss);
    }
    cout << *max_element(st(dp));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    for( int i = 0 ; i < q ; i++){
        solve();
    }
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  int num = 0;
  
  for(int i = 1;i < 10;++i){
    if(N % i == 0 && N / i <= 9){
      num++;
    }
  }
  
  if(num == 0){
  cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll L[2010];

int main() {
  std::cin >> N;

  rep( i, N )
    std::cin >> L[i];

  std::sort( L, L+N );

  ll ans = 0;

  rep( i, N ) rep( j, i ) {
    ll x = L[j]+L[i];

    ll ng = -1, ok = N;

    while( ok-ng > 1 ) {
      ll mid = (ng+ok)>>1;

      (L[mid]>=x?ok:ng) = mid;
    }

    ans += std::max( ok-1-i, 0ll );
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 

const int MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;

    multiset< double, greater<double> > p; //! current slimes
    for (int i = 0; i < N; ++i) {
        double a;
        cin >> a;
        p.insert(a);
    }

    for (int i = 0; i < M; ++i) {
        auto it = p.begin();
        int val = *it;
        p.erase(it);
        p.insert(val / 2);
    }

    LL ans = 0;
    for (auto v: p) {
        ans += (int) v;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
using System;

public class hello
{

    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var w = int.Parse(line[0]);
            var h = int.Parse(line[1]);
            if (w == 0 && h == 0) break;
            var map = new string[h, w];
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine().Trim();
                for (int j = 0; j < w; j++)
                {
                    int t;
                    map[i, j] = int.TryParse(s[j].ToString(), out t) ? s[j].ToString() : "#";
                }
            }
            var dp = new string[h, w];
            goDp(map, h, w, dp);
        }
    }
    static void goDp(string[,] map, int h, int w, string[,] dp)
    {
        var ans = "0";
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (map[i, j] != "#")
                {
                    string t;
                    if ((i - 1 < 0) || (map[i - 1, j] == "#")) t = map[i, j];
                    else t = dp[i - 1, j] + map[i, j];
                    if (t[0] == '0')  t  = delete0(t);
                    string t2;
                    if ((j - 1 < 0) || (map[i, j - 1] == "#")) t2 =  map[i, j];
                    else t2 = dp[i, j - 1] + map[i, j];
                    if (t2[0] == '0') t2 = delete0(t2);
                    dp[i, j] = checkAB(t, t2) ? t : t2;
                    if (((i + 1 >= h) || (map[i + 1, j] == "#")) &&( (j + 1 >= w) || map[i, j + 1] == "#"))
                        ans = checkAB(ans, dp[i, j]) ? ans : dp[i, j];
                }
            }
        }
        Console.WriteLine(ans);
    }
    static string delete0 (string s)
    {
        if (s.Replace("0", "").Length == 0) return "0";
        var p = 0;
        while (p < s.Length )
        {
            if (s[p] != '0') break;
            p++;
        }
        return s.Substring(p);
    }
    static bool checkAB(string s, string t)
    {
        if (s == "") s = "0";
        if (t == "") t = "0";
        if (s.Length > t.Length) return true;
        else if (s.Length < t.Length) return false;
        return s.CompareTo(t) > 0;
    }
}



Measured memory_bytes: 26288
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#define in(N) cin >> N
#define in2(N,M) in(N) >> M
#define in3(N,M,K) in2(N,M) >> K
#define in4(N,M,K,L) in3(N,M,K) >> L
#define out(ans) cout << ans << endl
#define outf(ans) cout << fixed << setprecision(6) << ans << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define inv(A,N) rep(i,N) in(A[i])
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int A,B,C,D;
	in4(A,B,C,D);
	int X=A/D;
	int Y=C/B;
	if(A%D != 0){
		X++;
	}
	if(C%B != 0){
		Y++;
	}
	if(X>=Y){
		out("Yes");
	}else{
		out("No");
	}
	return 0;
}

Measured memory_bytes: 3588
#include<cstdio>
#include<algorithm>
 
using namespace std;
 
int main(){
    int a[100][100];
    for(int n;scanf("%d",&n),n;){
        for(int i=0;i<n;i++)for(int j=0;j<n;j++)  scanf("%d",a[i]+j);
 
        int cnt[100][100]={};
        for(int i=0;i<n;i++){
            int hmin=1<<30;
            for(int j=0;j<n;j++) if(a[i][j]<hmin) hmin=a[i][j];
            for(int j=0;j<n;j++) if(a[i][j]==hmin)   cnt[i][j]++;
        }
        for(int j=0;j<n;j++){
            int hmax=-(1<<30);
            for(int i=0;i<n;i++) if(a[i][j]>hmax) hmax=a[i][j];
            for(int i=0;i<n;i++) if(a[i][j]==hmax)   cnt[i][j]++;
        }
 
        int ans=-1;
        for(int i=0;i<n;i++)for(int j=0;j<n;j++)  if(cnt[i][j]==2)    ans=a[i][j];
        printf("%d\n",~ans?ans:0);
    }
 
    return 0;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

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

int h, w, n;
vector<string> s;
vector< vector<int> >steps;

void bfs(vector<P> &starts){
    queue<P> q;
    for(auto s : starts){
        q.push(s);
        steps[s.first][s.second] = 0;
    }

    while(!q.empty()){
        int y, x;
        tie(y, x) = q.front(); q.pop();
        for(int k = 0; k < 4; k++){
            int ny = y + dy[k];
            int nx = x + dx[k];
            if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
            if(s[ny][nx] == '#') continue;
            s[ny][nx] = '#';
            steps[ny][nx] = min(steps[ny][nx], steps[y][x] + 1);
            q.emplace(ny, nx);
        }
    }
    return;
}

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> h >> w;
    s.resize(h);
    for(int i = 0;i < h; i++){
        cin>>s[i];
    }
    steps.resize(h);
    for(int i = 0;i < h; i++){
        steps[i].resize(w);
    }

    vector<P> starts;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            steps[i][j] = INF32;
            if(s[i][j] == '#'){
                starts.push_back(make_pair(i, j));
            }
        }
    }

    bfs(starts);

    int ans = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            ans = max(ans, steps[i][j]);
        }
    }

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



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

int main() {
	int n;
	double x;
	cin>>n;
	double ret = 0.0;
	while(n--){
		cin>>x;
		ret += 1.0/x;
	}
	cout<<fixed<<setprecision(10)<<1/ret;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#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 pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
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};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n,p,w; cin>>n>>p>>w;
cout << (n-p+1)*(n-w+1) << endl;}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

const int MXN = 1e5 + 5;
int n, k;
int h[MXN];
int dp[MXN];

int Dp(int idx) {
    if(idx == n - 1) return 0;
    if(dp[idx] != -1) return dp[idx];
    int ans = 1e9;
    for(int i = idx + 1; i <= min(n - 1, idx + k); i++) {
        ans = min(ans, Dp(i) + abs(h[idx] - h[i]));
    }
    return dp[idx] = ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    memset(dp, -1, sizeof dp);
    cout << Dp(0) << endl;
    return 0;
}

Measured memory_bytes: 9052
N ,a, b = map(int,input().split())
MOD = pow(10,9) + 7

A = 1  
for i in range(a):
  A = A*(N-i)*pow(i+1,MOD-2,MOD)%MOD

B = 1  
for i in range(b):
  B = B*(N-i)*pow(i+1,MOD-2,MOD)%MOD

alll = pow(2,N,MOD) -1
#nota = cmb(N,a,MOD)
#notb = cmb(N,b,MOD)
ans = alll - (A+B)
ans = ans%MOD
print(ans)

Measured memory_bytes: 40556
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define vi vector<ll>
#define vii vector<pair<ll,ll>>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<endl;
    cout<<endl;

}
template <typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x==1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
//vector <bool> prime(boolsize,1);
//void seive()
//{
//    ll n=boolsize;
//    prime[0]=prime[1]=0;
//    for(ll i=2;i<=sqrt(boolsize);i++)
//    {
//        if(prime[i]==1)
//        {
//            for(ll j=i*i;j<=n;j+=i)
//            {
//                prime[j]=0;
//            }
//        }
//    }
//}

void fun()
{

}
/// check for test case before submitting
void vfun()
{
    ll n,m,x,y;
    cin>>n>>m;
    vi v(n+1,0);
    fo(i,m)
    {
        cin>>x>>y;
        v[x]++;
        v[y]++;
    }
    showvector1(v);


}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {

        //fun();
        vfun();
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not



Measured memory_bytes: 3648
from itertools import product
MOD = 10**9 + 7
N = int(input())
# XAGC, XGAC, AXGC, AGXC, XACG: prohibited
A=0; C=1; G=2; T=3
cur = [[[1]*4 for j in range(4)] for k in range(4)]
for i in range(4):
    cur[A][G][C] = cur[G][A][C] = cur[A][C][G] = 0

for _ in range(3,N):
    prev = cur
    cur = [[[0]*4 for j in range(4)] for k in range(4)]
    for i, j, k in product(range(4),repeat=3):
        if (j==A and k==G) or (j==G and k==A) or (i==A and k==G) or (i==A and j==G):
            for l in [A,G,T]:
                cur[j][k][l] += prev[i][j][k]
        elif j==A and k==C:
            for l in [A,C,T]:
                cur[j][k][l] += prev[i][j][k]
        else:
            for l in range(4):
                cur[j][k][l] += prev[i][j][k]
    for i, j, k in product(range(4),repeat=3):
        cur[i][j][k] %= MOD

ans = sum(sum(sum(cur[i][j]) for j in range(4)) for i in range(4)) % MOD
print(ans)

Measured memory_bytes: 43504
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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

long long dfs(long long n, int A, int B, int C, int D,
                std::map<long long, long long> &mp){
    if(mp.find(n) != std::end(mp)){
        return mp[n];
    }
    long long res(2*LINF);
    if(n <= 2*INF/D) chmin(res, n * D);
    {//2 n1 <= n <= n2
        long long n1((n/2)*2), n2(((n+1)/2) * 2);
        chmin(res, dfs(n1/2, A, B, C, D, mp) + (n-n1)*D + A);
        chmin(res, dfs(n2/2, A, B, C, D, mp) + (n2-n)*D + A);
    }
    {//3 n1 <= n <= n2
        long long n1((n/3)*3), n2(((n+2)/3) * 3);
        chmin(res, dfs(n1/3, A, B, C, D, mp) + (n-n1)*D + B);
        chmin(res, dfs(n2/3, A, B, C, D, mp) + (n2-n)*D + B);
    }
    {//5 n1 <= n <= n2
        long long n1((n/5)*5), n2(((n+4)/5) * 5);
        chmin(res, dfs(n1/5, A, B, C, D, mp) + (n-n1)*D + C);
        chmin(res, dfs(n2/5, A, B, C, D, mp) + (n2-n)*D + C);
    }
    return mp[n] = res;
}



int main(){
    int T, A, B, C, D; std::cin >> T;
    long long N;
    for(int t(0); t < T; ++t){
        std::cin >> N >> A >> B >> C >> D;
        std::map<long long, long long> mp;
        mp[0] = 0;
        mp[1] = D;
        std::cout << dfs(N, A, B, C, D, mp) << "\n";
    }
    return 0;
}


Measured memory_bytes: 4476
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ManavJ07▒▀██████▄
░███▀▒▒▒▒BITS▒▒▒▒▒▒▀█████
░▐██▒▒▒.........▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define endl "\n"
#define MOD 998244353
#define nl cout<<"\n"
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i];nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
    ll N;
    cin>>N;
    ll ar[N];
    cn(ar,N);
    ll c=1;
    for(ll i=0;i<N;i++)
        if(ar[i]==c)
            c++;
    if(c==1)
        cout<<-1;
    else
        cout<<N-c+1;
}


Measured memory_bytes: 1792
#include<stdio.h>

int absc(int x,int y){
	if(x<y){return y-x;}
	return x-y;
}

int main(void){
	int n,m,a[64],b[64],c[64],d[64],i,j,ml,mn,x;
	scanf("%d%d",&n,&m);
	for(i = 1;i <= n;i++){scanf("%d%d",&a[i],&b[i]);}
	for(i = 1;i <= m;i++){scanf("%d%d",&c[i],&d[i]);}
	for(i = 1;i <= n;i++){
		ml = 1145141919;
		for(j = 1;j <= m;j++){
			x = absc(a[i],c[j])+absc(b[i],d[j]);
			if(ml > x){mn = j;ml = x;}
		}
		printf("%d\n",mn);
	}
	return 0;
}

Measured memory_bytes: 128
n,a,b=map(int,input().split())
u=sorted(list(map(int,input().split())))[::-1]
v=sum(u[:a])/a
print(v)
f=[1]
for i in range(50):f+=[f[-1]*(i+1)]
x=u.count(u[a-1])
if u[0]==u[a-1]:print(sum(f[x]//(f[x-i]*f[i])for i in range(a,b+1)))
else:y=u[:a].count(u[a-1]);print(f[x]//(f[x-y]*f[y]))

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    int n;
    cin >> n;
    rep(i, n) {
        int k, p;
        cin >> k >> p;
        if(k%p==0) P(p);
        else P(k%p);
    }
    return 0;
}

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

int main(){

  int N, a, b, x, r, tmp;

  cin >> N;

  a = 2;
  b = N;

  if(b == 1){
    tmp = a;
    a = b;
    b = tmp;
  }

  x = a * b;
  r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }

  cout << x/b << endl;

  return 0;
}


Measured memory_bytes: 256