akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;
using ll = long long;

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

int main()
{
    int n;
    int b[100];
    ll ans = 0;
    
    cin >> n;
    rep(i,n-1){
        cin >> b[i];
    }
    ans += b[0];
    ans += b[n-2];
    rep(i,n-2){
        ans += min(b[i],b[i+1]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(20000)
def solve(a, b, c, k):
    if(a < b and b < c and k>=0):
        return "Yes"
    elif(k < 0):
        return "No"
    s1 = solve(a, 2*b, c, k-1)
    s2 = solve(a, b, 2*c, k-1)
    if(s1 == "Yes" or s2 == "Yes"):
        return "Yes"
    else:
        return "No"

a, b, c = map(int, input().split())
k = int(input())
print(solve(a, b, c, k))

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    long long n,W,i,j,k,temp,ans,a,b;
    cin>>n>>W;
    long long v[n+1],w[n+1],dp[n+1][W+1]={};
    for(i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=W;j++)
        {
            if(w[i]<=j)
            {
                temp=v[i];
                if(j-w[i]>=0)
                    temp+=dp[i-1][j-w[i]];

                dp[i][j]=max(temp,dp[i-1][j]);
            }
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
    }
    cout<<dp[n][W];
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, Y;

int main(void){
    
    scanf("%d %d", &N, &Y);
    
    for(int i = 0; i * 10000 <= Y; ++i){
        int a = i * 10000;
        for(int j = 0; a + j * 5000 <= Y; ++j){
            int b = j * 5000, c = Y - a - b, k = c / 1000;
            if(c % 1000 == 0 && i + j + k == N){ printf("%d %d %d\n", i, j, k); return 0; }
        }
    }
	printf("-1 -1 -1\n");
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
ll comp[20][20], sum[(1 << 16)], dp[(1 << 16)];
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> comp[i][j];

    for(int i = 0; i < (1 << n); i++)
        for(int a = 0; a < n; a++)
            if(i >> a & 1) for(int b = a + 1; b < n; b++)
                    if(i >> b & 1) sum[i] += comp[a][b];

    for(int i = 1; i < (1 << n); i++)
        for(int j = i; j > 0; j = (j - 1) & i)
            dp[i] = max(dp[i], dp[i ^ j] + sum[j]);

    cout << dp[(1 << n) - 1] << "\n";
    return 0;
}


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

const int mxn = 1e6+10;
int prime[mxn];

void sieve(){
	for(int i=2;i<mxn;i++) prime[i] = i;

	for(int i=4;i<mxn;i+=2) prime[i] = 2;

	for(int i=3;i*i<mxn;i+=2){
		if(prime[i]==i){
			for(int j=2*i;j<mxn;j+=i) prime[j]=i;
		}
	}
}

bool vis[mxn];
int a[mxn];

int main(){

	sieve();
	int n; cin >> n;
	
	for(int i=0;i<n;i++) cin >> a[i];
	
	bool ok = 1;
	for(int i=0;i<n;i++){
		set<int> st;
		int x = a[i];
		while(x!=1){
			st.insert(x);
			x/=prime[x];
		}
		for(int each : st){
			if(vis[each]){
				ok=0;
				break;
			}
			vis[each]=1;
		}
		if(!ok) break;
	}
	if(ok){
		cout << "pairwise coprime" << endl;
		return 0;
	}

	int g=a[0];
	for(int i=1;i<n;i++) g=__gcd(g,a[i]);

	if(g==1){
		cout << "setwise coprime" << endl;
		return 0;
	}

	cout << "not coprime" << endl;
}


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

//Compiler version g++ 6.3.0

int main()
{
    int a;
    cin>>a;
    int b;
    if(a%2==0)
    {
      
    
    b=a/2;
    cout<<b;
    }
    else
    {
      b=a/2+1;
      cout<<b;
      
    }
    
}

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

int main(){
  int n;
  cin>>n;
  ll a[n],b[n];
  rep(i,n) cin>>a[i]>>b[i];
  ll ans=0;
  for(int i=n-1;i>=0;i--){
    if((ans+a[i])%b[i]==0) continue;
    ans+=b[i]-(ans+a[i])%b[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
import sys

N, K = map(int, input().split())

if K > (N-1)*(N-2)//2:
    print(-1)
    sys.exit()

edges = [(1, v) for v in range(2, N+1)]

num = (N-1)*(N-2)//2
for u in range(2, N+1):
    for v in range(u+1, N+1):
        if num == K:
            break
        edges.append((u, v))
        num -= 1
    else:
        continue
    break

print(len(edges))
print('\n'.join(map(lambda x: str(x[0])+' '+str(x[1]), edges)))


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){

  ll r, D, x0;
  IN(r,D,x0);
  REP(i, 10){
    x0 = r*x0-D;
    OUT(x0);
  }

  return 0;
}

Measured memory_bytes: 256
import heapq
N , M = map(int , input().split())
jobs = [list(map(int , input().split())) for _ in range(N)]
jobs.sort()

q = []
index = 0
ans = 0
for limit in range(1 , M + 1):
    while index < N:
        time =jobs[index][0]
        reward = jobs[index][1]
        if limit >= time:
            heapq.heappush(q , -reward)
            index += 1
        else:
            break
    #print(q)
    if len(q) != 0:
        tmp = heapq.heappop(q)
        ans -= tmp

print(ans)


Measured memory_bytes: 31596
import java.util.Scanner;

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

        int N = Integer.parseInt(sc.next());
        String S = sc.next();
        int K = Integer.parseInt(sc.next());
        char c = S.charAt(K-1);
        char tmp;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < S.length(); i++) {
            tmp = S.charAt(i);
            if (tmp == c) {
                sb.append(tmp);
            } else {
                sb.append('*');
            }
        }

        System.out.print(sb);
    }
}

Measured memory_bytes: 21588
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');
var temp = [];
var line;
while (line = lines.shift()) {
    temp.push(line.split(',')[0]);
}
 
var tm = [];
while (line = lines.shift()) {
    tm.push(line.split(',')[0]);
}
 
temp.sort(function(a,b){return a-b;});
 
temp.filter(function(e,i,a){return a.indexOf(e) == i}).forEach(function(c) {
    var cnt = tm.filter(function(n){return n == c;}).length;
    if (cnt > 0) {
        var tcnt = temp.filter(function(n){return n == c}).length;
        console.log(c, cnt + tcnt);
    }
});

Measured memory_bytes: 15480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll a[200005];
ll dp[200005];
ll ans[200005];
vector<ll> vec[200005];
void dfs(ll in,ll nm,ll noINF){
 	ll x=upper_bound(dp,dp+N+1,a[nm])-dp;
 	ll be=dp[x];
    if(dp[x-1]<a[nm]) dp[x]=a[nm];
    if(dp[x]!=INF) noINF=max(noINF,x);
    if(dp[in]!=INF) noINF=in;
    ans[nm]=noINF; 
    for(auto &i:vec[nm]){
    	if(ans[i]==INF) dfs(in+1,i,noINF);
    }
    dp[x]=be;
	return;
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
rep1(i,N+1) cin>>a[i];
rep(i,N-1){
    ll u,v; 
    cin>>u>>v;
    vec[u].pb(v);
    vec[v].pb(u);
}
fill(ans,ans+N+1,INF);
fill(dp,dp+N+1,INF);
dp[0]=-1;
dfs(1,1,0);
rep1(i,N+1) cout<<ans[i]<<endl;

}
    


Measured memory_bytes: 33516
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000
using ll = long long;
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);

}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0, m = 0, count = 0, sum = 0;
	llint k, a, b, c, x;
	bool check = false;
	string ss, sss;
	vector<llint> array, sarray;
	vector<bool> bo;
	cin >> a >> b >> c >> k;
	x = a + b;
	if (a >= k)cout << k << endl;
	else if (x >= k)cout << a << endl;
	else cout << a - (k - x) << endl;
	please AC;
}


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

#define ll long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;

int main() {	
	IO;
	
	int n, k;
	cin >> n >> k;
	
	int jumps[n];
	vector<int> dp(n, INF);
	for (int i = 0; i < n; ++i) {
		cin >> jumps[i];
	}
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j <= i+k; ++j) {
			if (j < n)
				dp[j] = min(dp[j], abs(jumps[i] - jumps[j])+ dp[i]);
		}
	}
	
	cout << dp[n-1];	
	
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define rREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define rFOR(i, a, b) for (int i = a; i >= b; --i)
#define aFOR(i, V) for (auto i : V)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
#define INF 1'000'000'007 // 10^9 + 7
#define MOD 1'000'000'007 // 10^9 + 7
#define lINF 1'000'000'000'000'000'007 // 10^18 + 7
// ------------------------------

vector<int> group;
int num = 0;

void bfs(vector<vector<int>> vec, int now) {
    ++num;
    group[now] = num;
    queue<int> q;
    q.push(now);
    while (!q.empty()) {
        now = q.front();
        q.pop();
        group[now] = num;
        aFOR(i, vec[now]) {
            if (!group[i]) {
                q.push(i);
                group[i] = num;
            }
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> vec(N, vector<int>(0));
    vector<int> tmp(N, 0);
    group = tmp;
    dsu d(N);
    REP(i, M) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        d.merge(A, B);
    }
    set<int> s;
    REP(i, N) {
        s.insert(d.leader(i));
    }
    cout << s.size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 10236
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long

void solve()
{
    string S;
    cin >> S;

    if (S == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3600
# 2019/06/23
# AtCoder Beginner Contest 073 - C

# Input
n = int(input())
adict = {}

for i in range(n):
    a = input()
    if adict.get(a) == None:
        adict[a] = 1
    else:
        adict[a] += 1

ans = 0
for k in adict.keys():
    if adict[k] % 2 == 1:
        ans += 1

# Output
print(ans)


Measured memory_bytes: 17884
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int t;
    while(cin >> t, t){
        vector<int> v(t);
        for (auto &&i : v) scanf("%d", &i);
        int n;
        cin >> n;
        int M = 101;
        vector<int> u(M, 24);
        for (int i = 0; i < n; ++i) {
            int d, m;
            cin >> d >> m;
            u[d-1] = min(u[d-1], m);
        }
        auto dp = make_v(M, t, INF<int>);
        dp[0][0] = 0;
        for (int i = 1; i < M; ++i) {
            for (int j = 0; j < t; ++j) {
                if(v[(j+1)%t] <= u[i]) chmin(dp[i][(j+1)%t], dp[i-1][j]);
                chmin(dp[i][0], dp[i-1][j]+1);
            }
        }
        cout << *min_element(dp.back().begin(),dp.back().end()) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3196
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()
  max := nextInt()
  min := max
  sum := max
  for i := 0; i < n - 1 ;i++ {
      num := nextInt()
      if max < num {
          max = num
      }

      if min > num {
          min = num
      }
      sum += num
  }
  fmt.Println(strconv.Itoa(min) + " " + strconv.Itoa(max) + " " + strconv.Itoa(sum))
}

func getStdin() (string) {
    sc.Scan()
    v := sc.Text()
    return v
}

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

func nextFloat() (float64) {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}



Measured memory_bytes: 1220
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = sorted(iil())
print(A[-1]-A[0])

Measured memory_bytes: 3060
#include <algorithm> // std::sort(begin,end), max, min
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;

struct cake {
  ll x;
  ll y;
  ll z;
  ll val(const ll &x_sign, const ll &y_sign, const ll &z_sign) const {
    return this->x * x_sign + this->y * y_sign + this->z * z_sign;
  };
};




auto my_greater(const ll &x_sign, const ll &y_sign, const ll &z_sign) {
  return [&](const cake &c1, const cake &c2) -> bool {
    return c1.val(x_sign, y_sign, z_sign) > c2.val(x_sign, y_sign, z_sign);
  };
}

int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<cake> cakes;
  for (int i = 0; i < n; i++) {
    cake tmp;
    cin >> tmp.x >> tmp.y >> tmp.z;
    cakes.push_back(tmp);
  }
  ll my_max = 0, tmp_max;

  for (ll x_sign : {1, -1}) {
    for (ll y_sign : {1, -1}) {
      for (ll z_sign : {1, -1}) {
        sort(cakes.begin(), cakes.end(), my_greater(x_sign, y_sign, z_sign));
        tmp_max = 0;
        for (int i = 0; i < m; i++) {
          tmp_max += cakes[i].val(x_sign, y_sign, z_sign);
        }
        my_max = max(my_max, tmp_max);
      }
    }
  }
  cout << my_max << endl;
  return 0;
}


Measured memory_bytes: 256
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]

x, y = map(int, input().split())

ans = 'No'
if x in A and y in A:
    ans = 'Yes'
if x in B and y in B:
    ans = 'Yes'
if x in C and y in C:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define hahahahahahahahahahahah ios_base::sync_with_stdio(0);
using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;

int main()
{

	hahahahahahahahahahahah;
	cin.tie(0);
	string a,b;
	cin>>a>>b;
	ll x,y;
	cin>>x>>y;
	string s;
	cin>>s;

	if(s == a) x--;
	else y--;
	cout<<x<<" "<<y<<"\n";


	
	return 0;
}

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

int gcd(int x, int y){
  return y ? gcd(y, x%y) : x;
}

main(){
  int x, y;
  cin >> x >> y;
  vector<int> v;
v.push_back(3);
  for ( int i = 0; i < 5000000; i++ ) v.push_back(v[i]);
  cout << (x+1) + (y+1) - (gcd(x, y) - 1) - 2 << endl;
  return 0;
}




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

#define endl "\n"
#define ll long long
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define read(v) for(auto &it:v) cin>>it;
#define out(v) for(auto &it:v) cout<<it<<" ";
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<ll> vll;

#define deb(x) cout << ">" << #x << '=' << x << endl;
#define setbits(n) __builtin_popcountll(n)
#define done {cout<<"-1"<<endl; return;}

#define inf INT_MAX
#define ninf INT_MIN
const ll N = 1e5 + 5;
#define MOD 1000000007
vector<int> dp(2005, -1);
long long solve() {
	int x;
	cin >> x;
	if (x == 1) return 0;
	return 1;

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("inputc.txt", "r", stdin);
	freopen("outputc.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	cout << solve();
	//for (int i = 0; i <= t; i++) cout << i << " " << dp[i] << endl;
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

vector<P> G[100001];
vector<bool> used(100001,false);
vector<int> eused(100001,false);
vector<int> cnt(100001,0);
vector<int> G2[100001];


void dfs(int u,int v){
    used[u]=true;
    for (int i = 0; i < G[u].size(); i++) {
        if(G[u][i].first==v) continue;
        if(used[G[u][i].first]) continue;
        dfs(G[u][i].first,u);
        G2[u].pb(G[u][i].first);
        eused[G[u][i].second]=true;
    }
}


bool dfs2(int u,int v){
    for (int i = 0; i < G2[u].size(); i++) {
        if(!dfs2(G2[u][i],u)){
            cnt[u]++;
            cout << u+1 << " " << G2[u][i]+1 << endl;
        }
    }
    if(cnt[u]%2){
        cout << u+1 << " " << v+1 << endl;
        return true;
    }
    return false;
}

int main(){
    int n,m;cin >> n >> m;
    if(m%2){
        puts("-1");
        return 0;
    }
    vector<P> ans(n);
    for (int i = 0; i < m; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].pb({b,i});
        G[b].pb({a,i});
    }
    dfs(0,-1);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < G[i].size(); j++) {
            if(!eused[G[i][j].second]){
                cout << i+1 << " " << G[i][j].first+1 << endl;
                cnt[i]++;
                eused[G[i][j].second]=true;
            }
        }
    }
    dfs2(0,-1);
    return 0;
}


Measured memory_bytes: 23296
a, b, c, x, y = list(map(int, input().split()))
c *= 2
qwe = 0
if a + b > c:
    qwe = c * min(x, y)
else:
    qwe  = a * min(x, y) + b *min(x,y) 
for i in range(max(x, y) - min(x, y)):
    if x > y:
        if a < c:
            qwe += a
        else:
            qwe += c
    else:
        if b < c:
            qwe += b
        else:
            qwe += c
print(qwe)


Measured memory_bytes: 3064
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

c = 0
for i in range(n):
	if a[i] - b[i] >= 0:
		c += b[i]
		a[i] -= b[i]
	else:
		c += a[i]
		b[i] -= a[i]
		if a[i+1] - b[i] >= 0:
			c += b[i]
			a[i+1] -= b[i]
		else:
			c += a[i+1]
			a[i+1] = 0
print(c)

Measured memory_bytes: 19648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  ll a[n];
  int ans=0;
  rep(i,0,n) cin>>a[i];
  rep(i,0,n){
    rep(j,i+1,n){
      rep(k,j+1,n){
        if(a[i]==a[j]) continue;
        if(a[j]==a[k]) continue;
        if(a[k]==a[i]) continue;
        if(a[i]+a[j]+a[k]>2*max(max(a[i],a[j]),a[k])) ans++;
      }
    }
  }
  cout<<ans<<endl;
}

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

#define int long long 

const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	priority_queue<int> pq;
	
	for(int i = 0; i < n; ++i) 
	{	
		cin >> a[i];
		pq.push(a[i]);
	}
	
	for(int i = 0; i < n; ++i)
	{
		if(a[i] == pq.top())
		{
			int x = pq.top();
			pq.pop();
			cout << pq.top() << '\n';
			pq.push(x);
		}
		else cout << pq.top() << '\n';
	}
}



Measured memory_bytes: 4848
n, m = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [int(x) for x in range(n)]
        self.tree_size = [1 for _ in range(n)]

    def unite(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if self.same(x_root, y_root):
            return

        if self.size(x_root) >= self.size(y_root):
            self.parent[y_root] = x_root
            self.tree_size[x_root] += self.tree_size[y_root]
        else:
            self.parent[x_root] = y_root
            self.tree_size[y_root] += self.tree_size[x_root]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def size(self, x):
        return self.tree_size[self.find(x)]

    def same(self, x, y):
        if x == y:
            return True
        else:
            return False


uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    uf.unite(a-1, b-1)

# print([uf.size(i) for i in range(n)])
print(max([uf.size(i) for i in range(n)]))


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

int main(){
	int n;
	cin >> n;
	//string s;
	vector<string> s(n);
	//vector<string> check;
	rep(i,n){
		cin >> s[i];
	}
	sort(s.begin(),s.end());
	// rep(i,n){
	// 	cout << s[i];
	// }

	int count = 1;

	for(int i = 1; i< n; i++){
		if(s[i] != s[i-1]){
			count++;
			//cout << i << endl;
		} 
		else continue;
	}

	cout << count << endl;

	return 0;
}

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

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

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int result = (a==b ? a*2 : Math.max(a, b)*2-1);
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(auto& i : a) {
        cin >> i;
    }
    sort(a.rbegin(), a.rend());
    ll res = 0, i = 0;
    for(; i < k; i++);
    for(; i < n; i++) res += a[i];
    cout << res << "\n";
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
char str[100005];
int main()
{
	int ans=0;
	stack<char > sta;
	scanf("%s",str);
	int num;
	num = strlen(str);
	for(int i=0;i<num;i++)
	 sta.push(str[i]);
	char top;
	top=sta.top();
	sta.pop();
	while(!sta.empty())
	{
		if(top==sta.top())
       {
		sta.pop();
	  }
	  else
	  {
	   ans++;
	   top=sta.top();	
	  }
		
	}
	
	 
	cout<<ans<<endl;
  return 0; 
	
	
}

Measured memory_bytes: 384
// Vol02_0296
// A_Fat_Wallet

#include <cstdio>

int main()
{
	int c1, c2, c3, c4, c5, c6;
	int sum = 0;

	scanf("%d %d %d %d %d %d", &c1, &c2, &c3, &c4, &c5, &c6);
	sum = (c1 + (c2 * 5) + (c3 * 10) + (c4 * 50) + (c5 * 100) + (c6 * 500));

	printf("%d\n", (sum >= 1000));

	return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int[] cnt = new int[26];
        while(sc.hasNext()){

            String str = sc.nextLine();
            str = str.toLowerCase();

            for(int i=0;i<str.length();i++){
                if(str.charAt(i) >= 'a' && str.charAt(i) <= 'z'){
                    cnt[str.charAt(i)-'a']++;
                }
            }
        }
        for(int i=0;i<26;i++){
            System.out.printf("%c : %d\n", i+'a',cnt[i]);
        }
        sc.close();
    }
}


Measured memory_bytes: 26304
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

typedef long long lint;

using namespace std;

void test_case() {
    int n, k;
    vector<int> a;
    cin >> n >> k;
    a.resize(n);
    for(auto &i: a)
        cin >> i;
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < k; i++)
        ans+=a[i];
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int tests=1;
    //cin >> tests;
    for(int test = 0; test < tests; ++test) {
        test_case();
    }
    return 0;
}


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

int main(){
  	int n;cin>>n;
	string s;
  	cin>>s;
  	int red=0,blue=0;
  	for(int i=0;i<s.size();++i){
    	if(s[i]=='R')++red;
      	else ++blue;
    }if(red>blue)cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    rep(i,n-2){
        vector<int> q;
        rep(j,3) q.push_back(p[i+j]);
        sort(q.begin(), q.end());
        if(p[i+1] == q[1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// モジュール

// A -> B
ll solve(ll n, vector<ll> &va, vector<ll> &vb) {

    vector<ll> dv = vb;
    REP(i, vb.size()) dv[i] -= va[i];

    // dp[j] := 重みがj
    vector<ll> dp(n+1, 0);
    REP(i, vb.size()) {
        REP(j, n+1) if (j - va[i] >= 0) {
            chmax(dp[j], dp[j - va[i]] + dv[i]);
        }
    }

    return n + *max_element(ALL_OF(dp));

}

// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    ll ga, sa, ba;
    cin >> ga >> sa >> ba;
    ll gb, sb, bb;
    cin >> gb >> sb >> bb;

    vector<ll> va = {ga, sa, ba};
    vector<ll> vb = {gb, sb, bb};

    ll ans1 = solve(n, va, vb);
    ll ans = solve(ans1, vb, va);
    // DUMP(ans1);
    cout << ans << endl;
    
}

Measured memory_bytes: 195584
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int w,h,n;cin>>w>>h>>n;
  vector<vector<bool> > a(h,vector<bool>(w,0));
  int arx = w,ary = h;
  int alx = 0,aly = 0;
  rep(i,n){
    int x,y,o;cin>>x>>y>>o;
    --o;
    if(o == 0){
      alx = max(alx,x);
    }
    if(o == 1){
      arx = min(arx,x);
    }
    if(o == 2){
      aly = max(aly,y);
    }
    if(o == 3){
      ary = min(ary,y);
    }
  }
  int ans = max(arx - alx,0) * max(ary - aly,0);
  print(ans);
  return 0;
}

Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)

inf = 10**18
l = inf
r = inf
n.times{|i|
  l = i if x[i]<0
  k-=1 if x[i]==0
  if x[i]>0
    r = i
    break
  end
}

a = [inf]*n
b = [inf]*n

if l!=inf
  (l+1).times{|i|
    a[i] = -x[l-i]
  }
end

if r!=inf
  (n-r).times{|i|
    b[i] = x[r+i]
  }
end

if k==0
  p 0
  exit
end

min = inf
(l+1).times{|i|
  if i<k-1
    tmp = a[i]*2 + b[k-i-2]
    min = tmp if min > tmp
  else
    tmp = a[i]
    min = tmp if min > tmp
    break
  end
}
(n-r).times{|i|
  if i<k-1
    tmp = b[i]*2 + a[k-i-2]
    min = tmp if min > tmp
  else
    tmp = b[i]
    min = tmp if min > tmp
    break
  end
}

p min


Measured memory_bytes: 10004
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

// https://ei1333.github.io/luzhiled/snippets/math/divisor.html
vector< int > divisor(int n) {
	vector< int > ret;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			ret.push_back(i);
			if(i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}

int main()
{
	int N;
	int A[200000];
	static int Count[1000001];
	fill(Count, Count+1000001, 0);
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	set<int> nums;
	for(int i = 0; i < N; i++){
		nums.insert(A[i]);
		Count[A[i]]++;
	}
	
	int ans = 0;
	for(int i = 0; i < N; i++){
		vector<int> divs = divisor(A[i]);
		for(int j = 0; j < divs.size(); j++){
			if(j == divs.size() - 1){
				// cout << " ! " << Count[A[i]] << endl;
				if(Count[A[i]] == 1){
					ans++;
				}
				break;
			}
			
			// cout << divs[j] << " ";
			if(nums.find(divs[j]) == nums.end()){
				continue;
			}else{
				break;
			}
		}
		// cout << endl;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 17664
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ListBuffer

object Main {
  def isWinner(a:Array[(Int,String)]) = {
    def scan(a:List[(Int,String)]):Int = {
      a match {
        case Nil => 1
        case hd1::hd2::hd3::tail if hd1._2!=hd2._2 || hd2._2!=hd3._2 => 0
        case hd1::hd2::hd3::tail if(hd1._1==hd2._1 && hd2._1==hd3._1) => scan(tail)
        case hd::tail => {
          val buf = new ListBuffer[(Int,String)]
          var (x1,x2) = (false,false)
          for(i<-tail) {
            if(i._1==(hd._1+1) && !x1) { x1 = true }
            else if(i._1==(hd._1+2) && !x2) { x2 = true }
            else buf += i
          }
          if(x1 && x2) scan(buf.toList)
          else 0
        }
      }
    }
    scan(a.toList)
  }

  def main(args:Array[String]) = {
    val t = readInt
    for(i<-1 to t) {
      val a = (readLine.split(" ").map(_.toInt) zip readLine.split(" ")) .sortWith{ (x,y)=>
        if(x._2<y._2) true
        else if(x._2==y._2) {
          x._1<y._1
        } else false
      }
      println(isWinner(a))
    }
  }
}

Measured memory_bytes: 44212
A, B, C = map(int,input().split())
K = int(input())

flag = False
for i in range(K+1):
    TB = B * (2 ** i)
    TC = C * (2 ** (K-i))
    if TB > A and TC > TB:
        flag = True
        break

if flag:
    print("Yes")
else:
    print("No")


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

int main() {
  string k;

  cin >> k;

  int n = k.size();

      int target = (n-1)/2;
      int target2 = (n+3)/2;

      if (k.substr(0,target) == k.substr(target2-1,n)) {
          cout << "Yes" << endl;
      } else {
          cout << "No" << endl;
      }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxN 500005
#define inf (int) 1e9 + 50
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

int n, q;
int u[maxN], v[maxN];
int a[maxN], b[maxN], c[maxN], ans[maxN];
vector <int> g[maxN], gid[maxN];

void update(int u, int v) {
    while(u <= n) {
        b[u] += v;
        u += u & -u;
    }
}

int get(int u) {
    int ans = 0;
    while(u) {
        ans += b[u];
        u -= u & -u;
    }
    return ans;
}

int s(int u, int v) {
    return get(v) - get(u - 1);
}

void enter() {
    cin >> n >> q;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, q) {
        cin >> u[i] >> v[i];
        g[v[i]].push_back(u[i]);
        gid[v[i]].push_back(i);
    }
}

void solve() {
    FOR(i, 1, n) {
        if(c[a[i]]) update(c[a[i]], -1);
        update(i, 1);
        c[a[i]] = i;
        int siz = g[i].size() - 1;
        FOR(k, 0, siz) {
            int id = gid[i][k], u = g[i][k];
            ans[id] = s(u, i);
        }
    }
    FOR(i, 1, q) cout << ans[i] << endl;
}

int main() {
    //freopen("main.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    enter();
    solve();
}


Measured memory_bytes: 56904
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline ll read() {
    ll res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n;
char s[20];
bool flag = true;

int main() {
    scanf("%s", s);
    n = strlen(s);
    int ans = s[0] - '0' + 9 * (n - 1);
    for (int i = 1; i < n; i++) if (s[i] != '9') flag = false;
    if (!flag) ans--;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3632
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto dp = new long[][](n, n);
  foreach (i; 0..n)
    dp[i][i] = (n%2 == 1 ? 1 : -1) * a[i];

  foreach (j; 0..n)
    foreach_reverse (i; 0..j)
      if ((n-(j-i+1))%2 == 0)
        dp[i][j] = max(dp[i+1][j]+a[i], dp[i][j-1]+a[j]);
      else
        dp[i][j] = min(dp[i+1][j]-a[i], dp[i][j-1]-a[j]);

  writeln(dp[0][n-1]);
}


Measured memory_bytes: 74492
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin>>S;
    if(S[0]=='S')
    cout<<"Cloudy"<<endl;
    else if(S[0]=='C')
    cout<<"Rainy"<<endl;
    else
    cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)//rep(i,回数){処理}
using namespace std;
using ll = long long;
using P = pair<int, int>;




int main() {
    int n,ans;
    cin >> n;
    ans = 0;
    vector<ll> llist(n);
    rep(i,n) cin >> llist[i];
    rep(i,n) {
        rep(j,n) {
            rep(k,n) {
                if (i < j && j < k) {
                    if (llist[i] == llist[j]) continue;
                    if (llist[i] == llist[k]) continue;
                    if (llist[k] == llist[j]) continue;

                    if ((llist[i] + llist[j] > llist[k]) && (llist[j] + llist[k] > llist[i]) &&(llist[i] + llist[k] > llist[j])) {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    ll N, K; cin >> N >> K;
    vector<int> A(N); cin >> A;

    vector<int> done(N+1, -1);
    vector<int> dest(N+1, 0);

    dest[0] = 1;
    done[1] = 0;
    int l = -1, r = -1;
    for (int i = 1; i < N; i++) {
        int a = A[dest[i-1]-1];
        if (done[a] != -1) {
            l = done[a];
            r = i - 1;
            break;
        } else {
            dest[i] = a;
            done[a] = i;
        }
    }

    int ans;
    if (K <= r) {
        ans = dest[K];
    } else {
        ans = dest[l + (K-l) % (r-l+1)];
    }

    cout << ans << endl;
}


Measured memory_bytes: 5636
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <iomanip>
#include <map>
#include <climits>
#include <stack>
using namespace std;
#define ll long long int
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<double> vf;
typedef priority_queue<double,vf,greater<double>> minHeap;

void dfs(vii &adj,int x, stack<int> &topo,vb &vis){
	if(!vis[x]){
		vis[x] = true;
		
		for(int i = 0;i<adj[x].size();i++){
			int v = adj[x][i];
			if(!vis[v]){
				dfs(adj,v,topo,vis);
			}
		}
		topo.push(x);
	}
}
void getDP(vii &adj,int x,vi &dp){
	int ans = 0;
	for(int i = 0; i<adj[x].size();i++){
		int v = adj[x][i];
		ans = max(ans,dp[v] + 1);
	}
	dp[x] = ans;
}
int main(){
	fastio();
	int n,m;
	cin>>n>>m;
	vii adj(n);
	for(int i =0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x-1].push_back(y-1);
	}
	stack<int> st,topo;
	vi dp(n,INT_MIN);
	vb vis(n,false);
	for(int i = 0;i<n;i++){
		if(!vis[i]){
			dfs(adj,i,st,vis);
		}
	}
	while(!st.empty()){
		topo.push(st.top());
		st.pop();
	}
	while(!topo.empty()){
		int x = topo.top();
		topo.pop();
		getDP(adj,x,dp);
	}
	cout<<*max_element(dp.begin(),dp.end());
	return 0;
 
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  cout << (n + 999) / 1000 * 1000 - n << endl;
}


Measured memory_bytes: 3652
//https://atcoder.jp/contests/abc153/tasks/abc153_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll H, N;cin>>H>>N;
    vector<ll> an(N);
    ll sum=0;
    for(auto&& a:an){
        cin>>a;
        sum+=a;
    }
    bool ans=(sum>=H)?true:false;
    cout<<(ans?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 1024