akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int SQ(int x){
	return sqrt(x+1e-9);
}
char prime(){
	int p,q;
	cin>>p>>q;
	int t=p*p+q*q;
	for(int x=-SQ(t);x<=SQ(t);x++){
		for(int y=-SQ(t-x*x);y<=SQ(t-x*x);y++){
			if(x*x+y*y<=1) continue;
			int f=x*x+y*y;
			if(t%f) continue;
			int g=t/f;
			for(int a=-SQ(g);a<=SQ(g);a++){
				for(int b=-SQ(g-a*a);b<=SQ(g-a*a);b++){
					if(a*a+b*b<=1) continue;
					if(a*x-b*y==p&&a*y+b*x==q){
						return 'C';
					}
				}
			}
		}
	}
	return 'P';
}
int main(){
	int n;
	cin>>n;
	rep(tt,n) cout<<prime()<<endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,k,x=0;
string s;
cin>>n;
cin>>s;
vector<int> v;
v.push_back(0);
for(i=0;i<n;i++)
{ if(s[i]=='I')
{ x++;
v.push_back(x);
}
else if(s[i]=='D')
{ x--;
v.push_back(x);
}
}
sort(v.begin(),v.end());
cout<<v[v.size()-1];
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll dist2(ll x, ll y){
  return x*x+y*y;
}

int main(){

  ios_base::sync_with_stdio (false);
  cin.tie(NULL);
  ll N, D; cin >> N >> D;
  D = D*D;
  ll count = 0;
  FOR(i, 0, N){
    ll x, y; cin >> x >> y;
    if(dist2(x, y) <= D) count++;
  }

  cout << count << endl;
}


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

int n;

int main(){
    int i;
    string s;
    int c[4];
    for(i=0;i<4;i++){
        c[i]=0;
    }

    cin >> n;

    for(i=0;i<n;i++){
        cin>>s;
        if(s=="AC")c[0]++;
        else if(s=="WA")c[1]++;
        else if(s=="TLE")c[2]++;
        else c[3]++;
    }

    cout<<"AC x "<<c[0]<<endl;
    cout<<"WA x "<<c[1]<<endl;
    cout<<"TLE x "<<c[2]<<endl;
    cout<<"RE x "<<c[3];

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> b(n);
    rep(i,n) b[i] = a[i];
    sort(b.rbegin(), b.rend());
    rep(i,n){
        if(a[i] == b[0]) {
            cout << b[1] << endl;
        }else{
            cout << b[0] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
  tuple<int,int,char,long long,string> a[100000];
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int s1,s2;
    char s3;
    long long s4;
    string s5;
    cin>>s1>>s2>>s3>>s4>>s5;
    a[i]=make_tuple(s1,s2,s3,s4,s5);
  }
  sort(a,a+n);
  for (int i=0;i<n;i++){
    int s1,s2;
    char s3;
    long long s4;
    string s5;
    s1=get<0>(a[i]);
    s2=get<1>(a[i]);
    s3=get<2>(a[i]);
    s4=get<3>(a[i]);
    s5=get<4>(a[i]);
    cout<<s1<<" "<<s2<<" "<<s3<<" "<<s4<<" "<<s5<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 12384
import itertools
n = int(input())

l = list(itertools.permutations(range(1, n+1)))
dict = {}

index = 1
for i in l:
    dict[i] = index
    index += 1

p = map(int, input().split())
q = map(int, input().split())

print(abs(dict[tuple(p)] - dict[tuple(q)]))

Measured memory_bytes: 11052
def prime(n):
  if n==1:
    return False
  elif n==2 or n==3:
    return True
  else:
    for i in range(2,int(n**0.5)+1):
      if n%i==0:
        return False
    else:
      return True

n=int(input())
cnt=[0]*(n+1)
for i in range(1,n+1):
  tmp=i
  for j in range(1,i+1):
    if prime(j):
      if tmp%j==0:
        cnt[j]+=1
        tmp=tmp//j
        while tmp%j==0:
          cnt[j]+=1
          tmp=tmp//j
c74=0
c24=0
c14=0
c4=0
c2=0
for i in range(n+1):
  if cnt[i]>=74:
    c74+=1
  elif cnt[i]>=24:
    c24+=1
  elif cnt[i]>=14:
    c14+=1
  elif cnt[i]>=4:
    c4+=1
  elif cnt[i]>=2:
    c2+=1
ans=0
ans+=c74
ans+=(c74+c24)*(c74+c24+c14+c4+c2-1)
ans+=(c74+c24+c14)*(c74+c24+c14+c4-1)
ans+=(((c74+c24+c14+c4)*(c74+c24+c14+c4-1))//2)*(c74+c24+c14+c4+c2-2)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <ctime>
#include <math.h> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <utility>
#include <functional>
#include <set>
using namespace std;

int main(){
	int x;
  	cin >> x;
  	if (x == 0){
      cout << 1;
    }
  	else{
      cout << 0;
    }

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
# define ll long long
vector<int> v[100005];
int ans[100005];
int dfs(int curr)
{
    int cnt=0;
    if(ans[curr]!=0)
        return ans[curr];
    for(int i=0;i<v[curr].size();i++)
    {
        int y=v[curr][i];
        int z=dfs(y);
        cnt=max(cnt,z);
    }

    if(v[curr].size()==0)
    {
        ans[curr]=max(ans[curr],cnt);
        return 0;
    }

    ans[curr]=max(ans[curr],cnt+1);
    return cnt+1;

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    int n,m,x,y;
    memset(ans,0,sizeof(ans));
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
    }
    x=-1;
    for(int i=1;i<=n;i++)
        if(v[i].size())
            x=max(x,dfs(i));
    cout<<x;
    //code goes here
	return 0;
}



Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1e9+7;
struct mint {
  typedef long long ll;
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  bool operator>(const mint a) const {
    mint res(*this);
    return res.x > a.x;
  }
  bool operator<(const mint a) const {
    mint res(*this);
    return res.x < a.x;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

constexpr int premax = 200020; 
std::array<mint, premax> f, rf; 
bool mymodflag = false;
mint nCk (int n, int k) {
  if ( n == k ) return mint(1);
  if ( n < k  ) return mint(0);
  if ( !mymodflag ) {
    f[0] = 1; for(int i=1; i<premax; i++) f[i] = f[i-1]*i;
    rf[premax-1] = f[premax-1].pow(mod-2); for(int i=premax-2; i>=0; i--) rf[i] = rf[i+1]*(i+1);
    mymodflag = true;
  }
  return f[n]*rf[n-k]*rf[k];
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, M; std::cin >> N >> M;
  std::cout << nCk(N,2).x + nCk(M,2).x << std::endl;
  return 0;
}


Measured memory_bytes: 3328
n,m = map(int,input().split())
mod = 10 ** 9 + 7

def combo(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    else:
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod



N = n + 100
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#print(combo(2,1))

#print(m)
fac = {}
mm = m
#print(mm)
count = 0
while mm % 2 == 0:
    count += 1
    mm //= 2
if count > 0:
    fac[2] = count
f = 3
count = 0
while f ** 2 <= mm:
    while mm % f == 0:
        count += 1
        mm //= f
        #print(f,count)
    if count > 0:
        fac[f] = count
        count = 0
    f += 2
    #print(fac)
if mm != 1:
    if mm in fac:
        fac[mm] += 1
    else:
        fac[mm] = 1
#print(fac)

count = 1

for i in fac:
    if fac[i] >= 1:
        count = (count * combo(fac[i]+n-1,fac[i],mod)) % mod
    #print(count)
    
print(count)

Measured memory_bytes: 15048
n = int(input())
t_lst = [int(x) for x in input().split()]
m = int(input())
px_lst = [tuple(int(x) for x in input().split()) for _ in range(m)]

total_time = sum(t_lst)

for i in range(m):
    p, x = px_lst[i]
    print(total_time - t_lst[p - 1] + x)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	return scanInt(sc)
}

func resolve(x int) int {
	result := make([]int, x+1)
	result[0] = 1
	for i := 1; i <= x; i++ {
		for _, v := range []int{100, 101, 102, 103, 104, 105} {
			if i-v < 0 {
				continue
			}
			if result[i-v] == 1 {
				result[i] = 1
				break
			}
		}
	}
	return result[x]
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2572
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;
using ll = long long;

int main() {
        int c[3][3];
        for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                        cin >> c[i][j];
                }
        }

        for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                        if (c[i][j] - c[i][j+1] != c[i+1][j] - c[i+1][j+1]) {
                                cout << "No" << endl;
                                return 0;
                        }
                }
        }

        cout << "Yes" << endl;
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct UnionFind {
    vector<int> par;
	vector<int> cnt;

    UnionFind(int N) : par(N), cnt(N) {
        for (int i = 0; i < N; i++) {par[i] = i; cnt[i] = 1;}
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
		cnt[ry] = cnt[rx] + cnt[ry];
    }

	int count(int x) {
		return cnt[root(x)];
	}
};

void solve() {
    ll n, k, l;
    cin >> n >> k >> l;
    UnionFind uf1(n), uf2(n);
    for(ll i = 0; i < k; i++) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        uf1.merge(a, b);
    }
    for(ll i = 0; i < l; i++) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        uf2.merge(a, b);
    }
    map<ll, vll> m1;
    for(ll i = 0; i < n; i++) {
        m1[uf1.root(i)].push_back(i);
    }
    vll ans(n);
    for(auto i = m1.begin(); i != m1.end(); i++) {
        map<ll, ll> m2;
        for(auto j : i->second) {
            m2[uf2.root(j)]++;
        }
        for(auto j : i->second) {
            ans[j] = m2[uf2.root(j)];
        }
    }
    for(ll i = 0; i < n; i++) {
        if(i < n - 1) cout << ans[i] << ' ';
        else cout << ans[i] << endl;
    }
    return;
}

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

Measured memory_bytes: 25216
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main(void){
  int N;
  cin >> N;
  switch(N){
    case 1: cout << "Hello World" << endl;
      break;
    case 2:
      int A, B;
      cin >> A >> B;
      cout << A + B << endl;
      break;
  }
  return 0;
}


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

#define MOD 1000000007
typedef unsigned long long ull;

int main() {
    int n;
    int a;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a;
        if (a % 2 == 0) {
            if (!(a % 3 == 0 || a % 5 == 0)) {
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
}


Measured memory_bytes: 256
# instead of AVLTree

INF = 10**14

class BIT():
    def __init__(self, max):
        self.max = max
        self.data = [INF]*(self.max+1)
    
    def update(self, i, x):
        while i > 0:
            self.data[i] = min(self.data[i], x)
            i -= i & -i

    def read(self, i):
        m = INF
        while i <= self.max:
            m = min(self.data[i], m)
            i += i & -i
        return m

import sys
input = sys.stdin.readline
from operator import itemgetter

N, M = map(int, input().split())
LRC = [list(map(int, input().split())) for _ in range(M)]
LRC.sort(key=itemgetter(0))

bit = BIT(N)
bit.update(1, 0)

for l, r, c in LRC:
    m = bit.read(l)
    bit.update(r, m+c)

ans = bit.data[N]
if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 34176
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <utility>
#include <set>
#include <cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
using namespace std;
typedef pair<int,int> point;
typedef complex<double> P;
typedef long long ll;

const double eps = 1e-8;
const double INF = 1e12;


double dot(P a,P b){
	return a.real()*b.real()+a.imag()*b.imag();
}
double cross(P a,P b){
	return a.real()*b.imag()-a.imag()*b.real();
}

bool is_orthogonal(P a1,P a2,P b1,P b2){
	return EQ(dot(a1-a2,b1-b2),0.0);
}
bool is_parallel(P a1,P a2,P b1,P b2){
	return EQ(cross(a1-a2,b1-b2),0.0);
}

bool is_point_on_line(P a,P b,P c){
	return EQ(cross(b-a,c-a),0.0);
}

bool is_point_on_linesegment3(P a,P b,P c){
	//|a-c| + |c-b|<=|a-b| ???????????????
	return (abs(a-c)+abs(c-b)<abs(a-b)+EPS);
}

double distance_l_p(P a,P b,P c){
	return abs(cross(b-a,c-a))/abs(b-a);
}


double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a)<EPS)return abs(c-a);
	if(dot(a-b,c-b)<EPS)return abs(c-b);
	return abs(cross(b-a,c-a))/abs(b-a);
}

int ai[1000];
const int infi = 1<<29;
int n,m;

int solve(){
	int ans=-1;
	int min=infi,key=infi;
	bool h=false;
	for(int i=0;i<n;i++){
		vector<int> AI;
		AI.reserve(m+1);
		for(int j=0;j<=m;j+=ai[i])AI.push_back(j);
		vector<int> es;
		es.reserve(AI.size());
		for(int j=0,T=AI.size();j<T;j++){
			int t=AI[j];
			if(t>min || (t==min && ai[i]>=key))es.push_back(t);
		}
		if(!es.empty()){
			int t=es[0];
			if(t==min && ai[i]==key){
				h=true;
			}
		}else{
			h=false;
			min=AI.back();
			key=ai[i];
			ans=i;
		}
	}
	return h ? n:ans+1;
}

int main(){
	while(cin>>n>>m,n){
		for(int i=0;i<n;i++) cin>>ai[i];
			cout<<solve()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
using System;

namespace AtCoder0727
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            int notAscending = 0;
            int[] p= new int[str.Length];
            int[] q = new int[str.Length];
            for (int i = 0; i < str.Length; i++)
            {
                p[i] = Int32.Parse(str[i]);
                q[i] = Int32.Parse(str[i]);
            }
            Array.Sort(p);
            for (int i = 0; i < p.Length - 1; i++)
            {
                if (p[i] != q[i])
                {
                    notAscending += 1;
                }
                
            }
            if (notAscending <= 2)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
inline void solve(){
	int n;cin>>n;
	int h[n];for(int i=0;i<n;i++)cin>>h[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	dp[2]=abs(h[2]-h[0]);
	for(int i=3;i<n;i++){
		dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
	}
	cout<<dp[n-1]<<"\n";
	return;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    l = LIR(n)
    s = 0
    for a,b in l[::-1]:
        s += (-a-s)%b
    print(s)
    return
#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 57564
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
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;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 入出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

// 初期時読み込み
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

const int INF = 2002002002;

void solve(std::string S){
    set<char> str;
    REP(i, S.size())
        str.insert(S[i]);

    set<char> alpha;
    for (char i = 'a'; i <= 'z'; i++)
        alpha.insert(i);

    set<char> diff;
    std::set_difference(alpha.begin(), alpha.end(),
            str.begin(), str.end(),
            std::inserter(diff, diff.end()));

    if (diff.size() == 0) cout << "None" << '\n';
    else {
        auto itr = diff.begin();
        print(*itr);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int a, b; 
  cin >> a >> b;
  if ((a*b) % 2) cout << "Odd\n";
  else cout << "Even\n";
}

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

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> v(n);
    for(int i = 0; i < n; i++){
        std::cin >> v[i];
    }
    std::sort(v.begin(), v.end());
    double ans = v[0];
    for(int i = 1; i < n; i++){
        ans = (ans + v[i]) / 2;
    }
    std::cout << std::fixed << std::setprecision(15) << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3796
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<ll> A(n); 
    ll allxor = 0;
    rep(i, n){
        cin >> A[i];
        allxor = allxor ^ A[i];
    }
    vector<ll> ANS;
    rep(i, n){
        ll res = allxor ^ A[i];
        ANS.push_back(res);
    }
    for(auto a: ANS)cout << a << " ";
    cout << ln;
}
    


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<string> a(n);
  for ( int i=0; i<n; i++ ) cin >> a[i];
  sort(a.begin(),a.end());
  string ans="";
  for ( int i=0; i<n; i++ ) ans+=a[i];
  cout << ans;
  return 0;
}


Measured memory_bytes: 3576
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	M := nextInt()
	var a, b, c []int
	for i := 0; i < M; i++ {
		a = append(a, nextInt()-1)
		b = append(b, nextInt()-1)
		c = append(c, -nextInt())
	}

	dist := make([]int, N)
	for i := 1; i < N; i++ {
		dist[i] = math.MaxInt64
	}

	for loop := 0; loop < N-1; loop++ {
		for i := 0; i < M; i++ {
			if dist[a[i]] == math.MaxInt64 {
				continue
			} else if dist[b[i]] > dist[a[i]]+c[i] {
				dist[b[i]] = dist[a[i]] + c[i]
			}
		}
	}

	ans := -dist[N-1]

	negative := make([]bool, N)
	for loop := 0; loop < N; loop++ {
		for i := 0; i < M; i++ {
			if dist[a[i]] == math.MaxInt64 {
				continue
			}
			if dist[b[i]] > dist[a[i]]+c[i] {
				dist[b[i]] = dist[a[i]] + c[i]
				negative[b[i]] = true
			}
			if negative[a[i]] {
				negative[b[i]] = true
			}
		}
	}

	if negative[N-1] {
		fmt.Println("inf")
	} else {
		fmt.Println(ans)
	}
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 896
program tenquestionten
 integer,allocatable,dimension(:) :: X
 integer,allocatable,dimension(:) :: Y
 integer,allocatable,dimension(:) :: T
 integer N, i, j, sum, Xl, Yl, Tl, Z
 read(*,*) N
 allocate(X(N+1))
 allocate(Y(N+1))
 allocate(T(N+1))
 sum=0
 X(1) = 0
 Y(1) = 0
 T(1) = 0
  do i=2,N+1
  read(*,*) T(i), X(i), Y(i)
  end do
  do i=1,N
  Xl=abs(X(i+1)-X(i))
  Yl=abs(Y(i+1)-Y(i))
  Tl=abs(T(i+1)-T(i))
  Z=Xl+Yl
   if (Tl.ge.Z) then
    if ((mod(Z,2)).eq.(mod(Tl,2))) then
    sum = sum + 1
    end if
   end if
  end do
 if (sum.eq.N) then
 write(*,'(A)') "Yes"
 else if (sum.ne.N) then
 write(*,'(A)') "No"
 end if
end program

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string> 
#include <cstring> 
using namespace std;
int main()
{
	int n;
	int head,dis,sum=0;
	char str[110],board[100];
	cin>>n;
	cin>>board;
	for(int i=0;i<=n-1;i++){
		cin>>str;
	  for(head=0;head<=strlen(str)-1;head++){
		 	for(dis=0;head+(strlen(board)-1)*dis<=strlen(str);dis++){
		 	  	    for(int k=0;k<=strlen(board)-1;k++){
		 	  	    if(str[head+dis*k]!=board[k]) {goto p1;}
		 	  	 }
		 	  	 sum++;
		 	  	 goto p2;
		 	  	 p1:;
		 	  }	 	 
	  }
	  p2:;	
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
int main(){
    int K, A, B;
    scanf("%d", &K);
    scanf("%d %d", &A, &B);
    int L = B - A;
    int count = 0;
    for(int i = 0; i <= L ; i++){
        int total = A % K;
        A++;
        if(total == 0){
            count++;
        }
        else{
            count = count + 0;
    	}
	}
    
	if(count > 0){
        printf("OK\n");
    }
    else{
        printf("NG\n");
    }
	
 return 0;
}

Measured memory_bytes: 1660
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 9 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 


    ivv(a);
    ivv(b);

    if(b%a==0){
        cout<<a+b<<endl;
    }el {
        cout<<b-a<<endl;
    }


    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> even;
  vector<int> odd;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    if(i%2==0){
      even.push_back(tmp);
    }else{
      odd.push_back(tmp);
    }
  }
  sort(even.begin(),even.end());
  even.push_back(0);
  sort(odd.begin(),odd.end());
  odd.push_back(0);
  int mxev=0;
  int mxevp;
  int mxod=0;
  int mxodp;
  int nw = 1;
  vector<int> evnum;
  vector<int> odnum;
  for(int i = 1; even.size() > i; i++){
    if(even[i] == even[i-1])nw++;
    else{
      if(mxev < nw){
        mxev = nw;
        mxevp = even[i-1];
      }
      evnum.push_back(nw);
      nw = 1;
    }
  }
  for(int i = 1; odd.size() > i; i++){
    if(odd[i] == odd[i-1])nw++;
    else{
      if(mxod < nw){
        mxod = nw;
        mxodp = odd[i-1];
      }
      odnum.push_back(nw);
      nw = 1;
    }
  }
  sort(odnum.begin(),odnum.end(),greater<int>());
  sort(evnum.begin(),evnum.end(),greater<int>());
  odnum.push_back(0);
  evnum.push_back(0);
  if(mxodp == mxevp){
    cout << n - max(odnum[1]+evnum[0],odnum[0]+evnum[1]) << endl;
  }else{
    cout << n - (mxod+mxev) << endl;
  }
}
      
      
      
      
    
    

Measured memory_bytes: 1276
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

ll solve(int N, vi &D){
	ll ans = 0;
	rp(i,0,N-1){
		int x = D[i];
		rp(j,i+1,N){
			int y = D[j];
			ans += x*y;
		}
	}
	return ans;
}

int main(){
	int N; cin>>N;
	vi D(N);
	rp(i,0,N)cin>>D[i];
	ote(solve(N, D));

}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scanln(&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanln(&a[i])
	}

	fmt.Println(logic(a))
}

func logic(nums []int) int {
	sort.Ints(nums)
	sum := 0
	for _, num := range nums {
		sum += num
	}

	if sum%10 != 0 {
		return sum
	}

	for _, num := range nums {
		if num%10 != 0 {
			sum -= num
			if sum%10 != 0 {
				return sum
			}
		}
	}

	return 0
}


Measured memory_bytes: 512
import qualified Control.Monad as Monad
import qualified Data.Vector.Unboxed as UV

main :: IO ()
main = do
  _ <- getLine
  ts <- UV.fromList . fmap (read :: String -> Int) . words <$> getLine
  m <- readLn :: IO Int
  Monad.replicateM_ m $ do
    [p,x] <- map (read :: String -> Int) . words <$> getLine
    print . UV.sum $ ts UV.// [(p-1,x)]

Measured memory_bytes: 1020
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        ll aa;
        cin >> aa;
        a[i] = aa;
    }

    int ans = 0;
    sort(all(a));
    vi used(n);
    for(int i = n-1; i>=0; --i) {
        if(used[i]) continue;
        ll num = (1LL << (64-__builtin_clzll(a[i]))) - a[i];
        used[i] = 1;
        int aa = 0;
        int c = i+1;
        while(c-aa != 1) {
            int b = (aa+c)/2;
            if(a[b] > num or (a[b] == num and used[b] == 1)) {
                c = b;
            } else {
                aa = b;
            }
        }

        if(a[aa] == num and used[aa] == 0) {
            ans++;
            used[aa] = 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3328
import sys
def main():
  S = input()
  T = input()
  lenS = len(S)
  if S == T:
    print("Yes")
    sys.exit()
  for _ in range(lenS):
    tempS = S[-(lenS-1):] + S[0]
    if tempS == T:
      print("Yes")
      sys.exit()
    # print(tempS)
    S = tempS
  print("No")

main()

Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<cmath>
using namespace std;

int main(){
	int N;
	cin>>N;
	map<int,int>num;
	int tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		num[tmp]++;
	}
	long ans=0;
	if(N%2==0){
		bool judge=true;
		for(int i=1;i<N;i+=2){
			if(num[i]!=2)judge=false;
		}
		if(judge==true){
			ans=1;
			for(int i=0;i<N/2;++i){
				ans*=2;
				ans%=(long)pow(10,9)+7;
			}
		}
	}
	else{
		bool judge=true;
		if(num[0]!=1)judge=false;
		for(int i=2;i<N;i+=2){
			if(num[i]!=2)judge=false;
		}
		if(judge==true){
			ans=1;
			for(int i=0;i<(N-1)/2;++i){
				ans*=2;
				ans%=(long)pow(10,9)+7;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <map>
using namespace std;
int main(void){
    int n,M; cin >> n >> M;
    map<int, int> m;
    int i = 0;
    while (i < n) {
        int tmp;
        cin >> tmp;
        int j = 0;
        while (j < tmp) {
            int value;
            cin >> value;
            if (m.count(value)) {
                m[value] += 1;
            } else {
                m[value] = 1;
            }
            j++;
        }
        i++;
    }
    int count = 0;
    for (auto itr = m.begin(); itr != m.end(); itr++) {
        if (itr->second == n) count++;
    }
    cout << count << endl;
}

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

using namespace std;

string s;

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

    cin >> s;
    int ans = 0;
    for (auto x : s) {
        if (x == '2') ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
    int n,x,i,a,b,c;
    cin>>n>>x;
    int p[n];
    for(i=0,a=x,b=10000; i<n; i++)
    {
        cin>>p[i];
        a-=p[i];
        if(p[i]<b)
            b=p[i];
    }
    c=a/b;
    cout<<c+n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

bool vtd[200010];
ll t[200010];
int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[200000];
    for (ll i = 1; i <= n;i++){
        cin >> a[i];
        vtd[i] = false;
    }
    ll now = 1, ct = 0;
    
    t[1] = 1;
    while (vtd[now] == false){
        vtd[now] = true;

        t[now] = ct;
        ct++;
        now = a[now];
        
        if(k == ct){
            cout << now << endl;
            return 0;
        }
    }
    ll tekazu = ct - t[now];
    ll amari = t[now];
    ll tmp = k - amari;
    tmp %= tekazu;
    for (ll i = 0; i < tmp;i++){
        now = a[now];
    }
    cout << now;
}

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

int main() {
  int k,n;
  cin >> k >> n ;
  int t,s;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
  cin >> vec.at(i);
  }
  int min = k + vec.at(0)- vec.at(n-1);
  for ( int t = 0 ; t < n-1 ; t++){
    s = vec.at(t+1)- vec.at(t);
    if (min < s){
      min = s ;
    }
  }
  cout << k - min <<endl ;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define N 100000
using namespace std;
int n,a[N+5],ans;
struct node { int i,cnt; } b[2][N+5];
bool cmp(node p,node q) { return p.cnt>q.cnt; }
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=N;i++) b[0][i].i=b[1][i].i=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i%2][a[i]].cnt++;
	}
	sort(b[0]+1,b[0]+N+1,cmp);
	sort(b[1]+1,b[1]+N+1,cmp);
	if(b[0][1].i==b[1][1].i) ans=min(n-b[0][2].cnt-b[1][1].cnt,n-b[0][1].cnt-b[1][2].cnt);
	else ans=n-b[0][1].cnt-b[1][1].cnt;
	printf("%d\n",ans);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const ll inf = 1001001001;
ll dp[100010];

int main() {
  rep(i,100010) dp[i] = inf;
  int n;
  cin >> n;
  vl w;
  w.push_back(1);
  rep(i,6)w.push_back(pow(6,i+1));
  rep(i,5)w.push_back(pow(9,i+1));
  dp[0]=0;
  dp[1] = 1;
  int m = (int)w.size();
    rrep(i,n){
      rep(j,m)
        if(i-w[j] >=0) dp[i] = min(dp[i],dp[i-w[j]]+1);
  }
  cout<< dp[n] <<endl;
  return 0;
}

Measured memory_bytes: 1280
from sys import stdin
n, m = [int(i) for i in stdin.readline().split()]
h_ls = [int(i) for i in stdin.readline().split()]
ls = set(range(n))
for i in range(m):
    a, b = [int(i) for i in stdin.readline().split()]
    a -= 1
    b -= 1
    if h_ls[a] <= h_ls[b] and a in ls:
        ls.remove(a)
    if h_ls[b] <= h_ls[a] and b in ls:
        ls.remove(b)
print(len(ls))

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

int main() {
    int a,b,c; cin >> a >> b >> c;
    if(abs(b-a) > abs(c-a))
    cout << "B" << endl;
    else cout << "A" << endl;


    return 0;
}

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

int main(){
    std::string S;
    std::cin >> S;
    
    int index = S.size() - 1;
    while(index >= 0){
        if(index >= 5 && S[index - 5] == 'e' && S[index - 4] == 'r' && S[index - 3] == 'a' && S[index - 2] == 's' && S[index - 1] == 'e' && S[index] == 'r'){
            index -= 6;
        }else if(index >= 4 && S[index - 4] == 'e' && S[index - 3] == 'r' && S[index - 2] == 'a' && S[index - 1] == 's' && S[index] == 'e'){
            index -= 5;
        }else if(index >= 6 && S[index - 6] == 'd' && S[index - 5] == 'r' && S[index - 4] == 'e' && S[index - 3] == 'a' && S[index - 2] == 'm' && S[index - 1] == 'e' && S[index] == 'r'){
            index -= 7;
        }else if(index >= 4 && S[index - 4] == 'd' && S[index - 3] == 'r' && S[index - 2] == 'e' && S[index - 1] == 'a' && S[index] == 'm'){
            index -= 5;
        }else{
            break;
        }
    }
    if(index == -1){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 512
const main = (input) => {
  input = input.trim().split('\n')

  const [x,] = input[0].split(' ').map(Number)
  const arr = input[1] ? input[1].split(' ').map(Number).sort((a, b) => a - b) : []

  for (let abs = 0; 'infinite'; abs++) {
    if (!arr.includes(x - abs)) return console.log(x - abs)
    if (!arr.includes(x + abs)) return console.log(x + abs)
  }
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 30548
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		string c;
		cin >> c;
		int sum = 26, MAX = 0,MIN=1<<29;
		char train[52];
		for (int d = 0; d < c.length()/3+1; d++) {
			train[sum] = c[d*3];
			MAX = max(MAX, sum);
			MIN = min(MIN, sum);
			if (d<c.length()/3) {
				if (c[d*3+2] == '>')sum++;
				else sum--;
			}
		}
		for (int i = MIN; i <= MAX; i++) {
			cout << train[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 2976
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
  ll K,S,C=0;cin >> K >> S;
  rep(i,K+1){
    rep(j,K+1){
      if(S-i-j>=0 && S-i-j<=K){
        C++;
      }
    }
  }
  cout << C << endl;
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    if(n==0) {
        cout<<x<<endl;
        return 0;
    }
    sort(p.begin(),p.end());
    int pmin=*p.begin();
    int pmax=*(p.end()-1);
    if(x<pmin || x>pmax){ 
        cout<<x<<endl;
        return 0;
        }
    vector<int> v;
    int ii=0;
    for(int i=pmin-1;i<=pmax;i++){
        if(i==*(p.begin()+ii)) ii++;
        else v.push_back(i);
    }
    v.push_back(pmax+1);
//    for(int vv : v) cout<<vv<<" ";
//    cout<<endl;
    auto itr=lower_bound(v.begin(),v.end(),x);
    if(*itr==x){ 
        cout<<x<<endl;
        return 0;
        }
    if(x-*(itr-1)>*itr-x) cout<<*itr<<endl;
    else cout<<*(itr-1)<<endl;
    return 0;
}

Measured memory_bytes: 3648
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		String SS = keyboard.next();	
		int K = keyboard.nextInt();
		
		String[] moji = SS.split("");
			
		int nokosu = K - 1;
		String hana = moji[nokosu];
		
		for(int j=0; j < SS.length() ; j++) {
			if (moji[j].equals(hana)) {	
			}else {
				moji[j] = "*";
			}
		}
		for(int k=0; k < N; k++) {
			System.out.print(moji[k]);
		}
		keyboard.close();	

	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<ctype.h>
#include<string>
using namespace std;

string str;
int q;

int main(){
    cin>>str;
    cin>>q;
    for(int i=0;i<q;++i){
        string order;
        cin>>order;
        if(order=="print"){
            int a,b;
            cin>>a>>b;
            cout<<str.substr(a,b-a+1)<<endl;
        }
        else if(order=="reverse"){
            int a,b;
            cin>>a>>b;
            string text;
            for(int j=b;j>=a;--j){
                text+=str[j];
            }
            str.replace(a,b-a+1,text);
        }
        else if(order=="replace"){
            int a,b;
            string p;
            cin>>a>>b>>p;
            str.replace(a,b-a+1,p);
        }
    }
    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    string s;
    cin >> s;
    vector<int> ans;
    int sum = 0;
    for(int i = 0; i < s.size(); ++i){
    	if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
    		sum++;
    	else{
    		ans.pb(sum);
    		sum = 0;
    	}
    }
    ans.pb(sum);
    sort(ans.begin(), ans.end());
    cout << ans[ans.size() - 1] << endl;
	return 0;
} 	

Measured memory_bytes: 256