akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

// 非常時
fn read_line() -> String{ let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim().to_string() }

/*
 <url:https://beta.atcoder.jp/contests/abc114/tasks/abc114_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
fn main(){
    input!(X:i32);
    println!("{}",match X {
       7 | 5 | 3 => "YES",
        _ => "NO"
    });
}

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

int d[10]={0};
int haa(int n){
  int a;
  while(n>0){
    a=n%10;
    if(d[a]==1){
      return 0;
    }
    n/=10;
  }
  return 1;
}

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

  for(int i=0;i<k;i++){
    cin >> j;
    d[j]=1;
  }

  for(int i=n;;i++){
    if(haa(i)==1){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,X,i,j,k,cnt;
inline void solve(){
  IN4(A,B,C,X);
  UP(i,0,A){
    UP(j,0,B){
      UP(k,0,C){
        if(i*500+j*100+k*50==X)cnt++;
      }
    }
  }
  OUT(cnt);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    lint ans = 0;

    std::map<int, int> cnt;
    for (int i = 0; i < n; ++i) {
        ans += cnt[i - xs[i]];
        ++cnt[xs[i] + i];
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 21152
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        itr = bisect.bisect_left(l, l[i] + l[j])
        count += itr - 1 - j
print(count)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n),mina(n-k+1),maxa(n-k+1);
  vector<int> dec(n,0),srt(n-k+1,0);
  vector<bool> chg(n-k+1,false);
  for(auto &i:a)cin>>i;
  deque<int> dq;
  for(int i=0;i<n;++i){
    while(!dq.empty()&&a[dq.back()]>=a[i])dq.pop_back();
    dq.push_back(i);
    if(dq.front()==i-k)dq.pop_front();
    if(i>=k-1)mina[i-k+1]=a[dq.front()];
  }
  dq.clear();
  for(int i=0;i<n;++i){
    while(!dq.empty()&&a[dq.back()]<=a[i])dq.pop_back();
    dq.push_back(i);
    if(dq.front()==i-k)dq.pop_front();
    if(i>=k-1)maxa[i-k+1]=a[dq.front()];
  }
  for(int i=1;i<n;++i)dec[i]+=dec[i-1]+(a[i-1]>a[i]);
  for(int i=0;i<n-k+1;++i)srt[i]=dec[i+k-1]-dec[i];
  for(int i=1;i<n-k+1;++i){
    if(a[i-1]!=mina[i-1]||a[i+k-1]!=maxa[i])chg[i]=true;
  }
  int r=0,d=0;
  for(int i=0;i<n-k+1;++i){
    if(srt[i]&&(!i||chg[i]))r++;
    else if(!srt[i])d=1;
  }
  cout<<r+d;
}

Measured memory_bytes: 4224
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

def gcd(a, b):  # a >= b
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        d = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(d, c)

print(ans)


Measured memory_bytes: 70392
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
	int j,i;
	double n,a[3],k;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<3;j++){
			cin>>a[j];
		}
		sort(a,a+3);
		k=((a[0]*a[0])+(a[1]*a[1]));
		if(sqrt(k)==a[2]){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3212
#include <stdio.h>
int main (){
	char str [255];
	char ans [255];
	scanf("%s",str);
	for(int i = 0 , j = 0 ; str[i] != '\0';i++){
		if (str[i] == '1'){
			ans[j] = '1';
			j++;
			ans[j] = '\0';
		}else if (str[i]== '0'){
			ans[j] = '0';
			j++;
			ans[j] = '\0';
		}else{
			if (j>0){
				ans[--j] = '\0';
			
			}
		}
	}
	printf ("%s",ans);
	return 0;
}

Measured memory_bytes: 1692
//#define _GLIBCXX_DEBUG
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

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

Measured memory_bytes: 3648
import Control.Applicative
import Control.Monad
import Data.List
import Data.List.Split (splitOn)

eps :: Double
eps = 1e-9

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n f >>= print
    main
  where
    f = g <$> map read <$> splitOn "," <$> getLine
    g [x, y] = (x, y)

solve :: [(Double, Double)] -> Int
solve xs = foldl' f 1 iss
  where
    iss = concat $ do
      p0 <- xs
      p1 <- tail $ dropWhile (/= p0) xs
      guard $ inside 2.0 p0 p1
      return $ intersection p0 p1
    f mxc is = max mxc (foldl' g 0 xs)
      where
        g c p = if inside 1.0 is p then c + 1 else c 

inside :: Double -> (Double, Double) -> (Double, Double) -> Bool
inside sh (x0, y0) (x1, y1) = d < sh || eps >= abs (d - sh)
  where
    d = sqrt $ (x1 - x0) ^ 2 + (y1 - y0) ^ 2

intersection :: (Double, Double) -> (Double, Double) -> [(Double, Double)]
intersection (x0, y0) (x1, y1) = [(x0 + cos (t + a), y0 + sin (t + a)), (x0 + cos (t - a), y0 + sin (t - a))]
  where
    (v1x, v1y) = (x1 - x0, y1 - y0)
    d = sqrt $ v1x ^ 2 + v1y ^ 2
    a = acos (d / 2)
    t = atan2 v1y v1x



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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n;
    int p[100001];
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i];

    vector<int> v;
    for (int i = 1; i <= n; i++)
    {
        int tmp = 0;
        for (int j = i; j <= n; j++)
        {
            if (p[j] != j)
            {
                i = j;
                break;
            }
            else
            {
                // cout << "=" << j << endl;
                i = j;
                tmp++;
            }
        }
        if (tmp != 0)
            v.push_back(tmp);
    }

    int sum = 0;
    for (int i = 0; i < v.size(); i++)
    {
        // cout << v[i] << endl;
        sum += max(1LL, (v[i] + 1) / 2);
    }
    cout << sum << endl;
}

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

int main(){
  int N, M; cin >> N >> M;
  map<ll, ll> A;
  rep(i, N){
    ll a,b; cin >> a >> b;
    A[a] += b;
  }
  
  ll res = 0;
  ll count = 0;
  for (auto p : A){
    res += p.first * p.second;
    count += p.second;
    if (count > M) {
      res -= (count - M) * p.first;
      break;
    }
  }
  
  cout << res << endl;
}


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

typedef long long ll;

ll N, M;
vector<tuple<ll, ll, ll>> E;
typedef pair<ll, ll> P;

ll solve() {
  ll v = 0, d = 0, e = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  while (v != N - 1) {
    for (; e < E.size() && get<0>(E[e]) <= v; ++e) {
      ll l, r, c;
      tie(l, r, c) = E[e];
      que.push(make_pair(d + c, r));
    }
    if (que.empty()) return -1;
    ll dx, r;
    tie(dx, r) = que.top();
    que.pop();
    d = dx;
    v = r;
  }
  return d;
}
int main() {
  cin >> N >> M;
  for (ll i = 0; i < M; ++i) {
    ll l, r, c;
    cin >> l >> r >> c;
    --l;
    --r;
    E.push_back(make_tuple(l, r, c));
  }
  sort(E.begin(), E.end());
  cout << solve() << endl;
  return 0;
}


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

int main() {
    int x,y;
    cin >> x >> y;
    while(!(x == 0 && y == 0)) {
   
    if(x > y) 
    		cout << y << " " << x << endl;
    	else 
    		cout << x << " " << y << endl;
	cin >> x >> y;
	}
	return 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    bool is_rev = false;
    int Q;
    cin >> Q;
    deque<char> deq;
    for(int i=0;i<N;i++) deq.push_back(S[i]);
    while(Q--){
        int t;
        cin >> t;
        if(t==1){
            is_rev ^= true;
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(!is_rev){
                if(f==1) deq.push_front(c);
                else deq.push_back(c);
            }else{
                if(f==2) deq.push_front(c);
                else deq.push_back(c);
            }
        }
    }
    if(is_rev) reverse(deq.begin(),deq.end());
    for(auto& c:deq) cout << c << "";
    cout << "\n";
}

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

int main(){
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  int x = a*60 + b;
  int y = c*60 + d;
  int ans;
  ans = max(y-x-e,0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    s = S
    for j in range(len(S)-1):
        if (i>>j) & 1:
            s = s[:j-len(S)+1]+'+'+s[j-len(S)+1:]
    ans += eval(s)
print(ans)

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

using namespace std;

void solve(void)
{
	int n, d;
	cin >> n >> d;
	d = 2 * d + 1;
	cout << (n - 1) / d + 1 << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1;
        }
    }
    return 0;
}


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

using namespace std;
int max(int a, int b) { return a > b ? a : b; }

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

    vector<vector<int>> a (n, vector<int> (3, 0));
    for (int i = 0; i < n; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;

        a[i][0] = x;
        a[i][1] = y;
        a[i][2] = z;
    }

    // dp[i][j] is the amount of happiness on day i if he performs j activity
    vector<vector<int>> dp(n, vector<int> (3, 0));
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for (int i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2];
    }

    cout << *max_element(dp[n - 1].begin(), dp[n - 1].end());

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define mkpr make_pair
#define ft first
#define sd second

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>
inline void read(T &x) {
    x=0; int f=0; char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-') f=1; if(ch==EOF) return; ch=getchar();}
    while(isdigit(ch)) {x=x*10+(ch-'0'); ch=getchar();} if(f) x=-x;
}

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

const int MAXN=1000011;

vector<int> G[MAXN];
int deg[MAXN];
int n, m, root=-1;

inline int DFS(int x, int fa) {
    int chcnt=0, res=0;
    for(int to: G[x]) {
        if(to!=fa) {
            ++chcnt;
            int tmp=DFS(to, x);
            res+=tmp;
            if(tmp) --chcnt;
        }
    }
    // printf("%d : %d\n", x, chcnt);
    if(chcnt>=2) res+=chcnt-1;
    return res;
}

int main() {
    scanf("%d", &n);
    if(n==1) {
        puts("0");
        return 0;
    }
    for(int i=1, x, y;i<n;++i) {
        scanf("%d%d", &x, &y);
        ++x, ++y;
        G[x].push_back(y);
        G[y].push_back(x);
        ++deg[x]; ++deg[y];
        if(deg[x]>2) root=x;
        if(deg[y]>2) root=y;
    }
    if(root==-1) {
        puts("1");
        return 0;
    }
    printf("%d\n", DFS(root, 0));
    return 0;
}

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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n, k;
    in(n);
    in(k);
    ll h[n];
    floop(i, n) in(h[i]);
    ll dp[n + k];
    floop(i, n + k) dp[i] = inf;
    dp[0] = 0;
    floop(i, n)
    {
        floop1(j, k)
        {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    out(dp[n - 1]);
}

Measured memory_bytes: 1792
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while (sc.hasNext()) {
			String str=sc.next();
			int[] counts=new int[14];
			Arrays.fill(counts,0);
			for(int i=0;i<str.length();i++){
				counts[str.charAt(i)-'0']++;
			}
			ArrayList<Integer> res=new ArrayList<Integer>();
			for(int i=1;i<=9;i++){
				counts[i]++;
				if(counts[i]<=4){
				if(can(counts)){
					res.add(i);
				}
				}
				counts[i]--;
			}
			if(res.size()>0){
			ln(join(res," "));
			}else{
				ln("0");
			}
		}
	}
	public boolean check(int[] list,int rest){
		if(rest==0){
			return true;
		}
		for(int i=1;i<=9;i++){
			if(list[i]>=3){
				list[i]-=3;
				if(check(list,rest-3)){
					list[i]+=3;
					return true;
				}
				list[i]+=3;
			}
			if(i<=7 && list[i]>=1 && list[i+1]>=1 && list[i+2]>=1){
				list[i]-=1;list[i+1]-=1;list[i+2]-=1;
				if(check(list,rest-3)){
					list[i]+=1;list[i+1]+=1;list[i+2]+=1;
					return true;
				}
				list[i]+=1;list[i+1]+=1;list[i+2]+=1;
			}
		}
		return false;
	}
	public boolean can(int[] list){
		for(int i=1;i<=9;i++){
			if(list[i]>=2){
				list[i]-=2;
				if(check(list,12)){
					list[i]+=2;
					return true;
				}
				list[i]+=2;
			}
		}
		return false;
	}

	public static String join(Collection<?> array, String separator) {
		Iterator<?> it=array.iterator();
		StringBuilder str = new StringBuilder(it.next() + "");
		while(it.hasNext()) {
			str.append(separator).append(it.next() + "");
		}
		return str.toString();
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
const main = (arg) => {
  const lines = arg.trim().split('\n');
  const N = Number.parseInt(lines[0]);
  const btcToJpy = (n) => n * 380000;
  let ans = 0;
  [...Array(N).keys()].forEach((i) => {
    let [x, u] = lines[i + 1].split(' ');
    x = Number.parseFloat(x);
    if (u === 'JPY') {
      ans += x;
    } else {
      ans += btcToJpy(x);
    }
  });
  console.log(ans);
};
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29700
import java.util.Scanner;

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

            int A = sc.nextInt();
            int B = sc.nextInt();

            if(B % A == 0){
                System.out.println(A + B);
            }else{
                System.out.println(B - A);
            }
        }finally{
            sc.close();
        }
    }
}

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

int main()
{
  int A, B, K;
  std::cin >> A >> B >> K;
  for(int i=100; 1<=i; i--)
  {
    if( A%i==0 && B%i==0 )
    {
       K-=1;
       if(K==0) { std::cout << i; return 0; }
    }
  }
}



Measured memory_bytes: 256
use std::cmp::min;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const INF: i32 = std::i32::MAX;

fn main() {
    input! {
    v: usize,
    e: usize,
    std: [(usize, usize, i32); e]
    }
    let mut g = vec![vec![-1; v]; v];
    for i in 0..e {
        let (s, t, d) = (std[i].0, std[i].1, std[i].2);
        g[s][t] = d;
    }
    let mut dp = vec![vec![-1; v]; 1 << v];
    let ans = dfs((1 << v) - 1, 0, &mut dp, &g);
    println!("{}", if ans < INF {ans} else {-1});
}

fn dfs(b: usize, t: usize, dp: &mut Vec<Vec<i32>>, g: &Vec<Vec<i32>>) -> i32 {
    if dp[b][t] >= 0 { return dp[b][t]; }
    if b.count_ones() == 1 && g[0][t] >= 0 {return g[0][t]}
    let mut res = INF;
    let v = dp[0].len();
    for s in 0..v {
        if b & (1 << s) == 0 { continue; }
        if g[s][t] < 0 { continue; }
        let p = dfs(b ^ (1 << t), s, dp, g);
        if p == INF { continue; }
        res = min(res, p + g[s][t]);
    }
    dp[b][t] = res;
    res
}



Measured memory_bytes: 7068
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N-K):
    YesNo(A[i]<A[i+K])

Measured memory_bytes: 94108
#include<set>
#include<map>
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<math.h>
using namespace std;

int a, b;

int main()
{
	scanf("%d", &a);
	scanf("%d", &b);
	int c = b * (int)pow(100, a);
	if (b == 100)
	{
		printf("%d\n", c + (int)pow(100, a));
	}
	else
	{
		printf("%d\n", c);
	}
	
}

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

void solve(long long N, long long L)
{
    long long min = L;
    long long max = L + N - 1;
    int sum = 0;
    if (min <= 0 && max >= 0) {
        for (int i = min; i <= max; i++) {
            sum += i;
        }
    } else if (min <= 0 && max <= 0) {
        for (int i = min; i <= max - 1; i++) {
            sum += i;
        }
    } else {
        for (int i = min + 1; i <= max; i++) {
            sum += i;
        }
    }
    cout << sum << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long L;
    scanf("%lld", &L);
    solve(N, L);
    return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(auto& it:a) cin>>it;
	vector<int> sg(k+1);
	for(int i=0;i<=k;i++){
		vector<bool> flag(k+1);
		for(auto it:a){
			if(i-it>=0) flag[sg[i-it]]=1;
		}
		for(int j=0;j<=k;j++){
			if(flag[j]==0){
				sg[i]=j;
				break;
			}
		}
	}
	cout<<(sg[k]?"First":"Second");
    return 0;
}



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

const int maxn=1<<18;
int n,a[maxn],max1[maxn],max2[maxn];

void update(int p,int val){
	if(val>max1[p])
		max2[p]=max1[p],max1[p]=val;
	else if(val>max2[p])
		max2[p]=val;
}

int main(){
	cin>>n;
	for(int i=0;i<1<<n;++i){
		cin>>a[i];
		max1[i]=a[i];
	}
	for(int i=2;i<=1<<n;i<<=1)
		for(int j=0;j<i>>1;++j)
			for(int k=0;k<1<<n;k+=i){
				update(j+k+(i>>1),max1[j+k]);
				update(j+k+(i>>1),max2[j+k]);
			}
	for(int i=1,ans=0;i<1<<n;++i){
		ans=max(ans,max1[i]+max2[i]);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;


//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}

const ll mod = 1e9 + 7;
const ll N = 1e5 + 7;


ll n, x, y, z;


int main()
{
    MohamedMotaz;

    cin >> n;
    ll dp[n][3];
    f(i,0,n){

        cin >> x >> y >> z;
        if (i == 0) { dp[0][0] = x, dp[0][1] = y, dp[0][2] = z; continue;}

        dp[i][0] = x + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = y + max(dp[i - 1][2], dp[i - 1][0]);
        dp[i][2] = z + max(dp[i - 1][1], dp[i - 1][0]);

    }

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});




}



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

int n, m, dp[100002], ans=0;
vector<int>adjl[100002];

int dfs(int now){
	if (dp[now]!=-1) return dp[now];
	int ret=0;
	for (int next : adjl[now]) ret=max(ret,dfs(next)+1);
	return dp[now]=ret;
}

int main(){
	memset(dp,-1,sizeof dp);
	cin >> n >> m;
	for (int i=0;i<m;i++){
		int u, v;
		cin >> u >> v;
		adjl[v].push_back(u);
	}
	for (int i=1;i<=n;i++) ans=max(ans,dfs(i));
	cout << ans << "\n";
}

Measured memory_bytes: 10624
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
from heapq import *
N,M=map(int,input().split())
ABC=[list(map(int,input().split())) for i in range(M)]
data=[[] for i in range(N+1)]
for i,(a,b,c) in enumerate(ABC):
    data[a].append([b,c,i])
    data[b].append([a,c,i])


mlst=set()

for sp in range(1,N+1):
    visited={sp}
    dic={}
    stack=[]
    distance=[0 for i in range(N+1)]
    for p,c,i in data[sp]:
        if not c in dic:
            dic[c]=[[p,i]]
            stack.append(c)
        else:
            dic[c].append([p,i])
            stack.append(c)
    heapify(stack)
    while stack:
        m=heappop(stack)
        a,i=dic[m].pop()
        if a in visited:
            if distance[a]==m:
                mlst.add(i)
            continue
        visited.add(a)
        mlst.add(i)
        distance[a]=m
        for p,c,i in data[a]:
            if not p in visited:
                C=m+c
                heappush(stack,C)
                if C in dic:
                    dic[C].append([p,i])
                else:
                    dic[C]=[[p,i]]
print(M-len(mlst))


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

int main() {
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3, x4, y3, y4;
	x3 = x2 + y1 - y2;
	y3 = y2 + x2 - x1;
	x4 = x1 + y1 - y2;
	y4 = y1 + x2 - x1;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

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

int main(){
  int M=0,N; cin >> N; cin.ignore();
  int a[N+1],ball[N+1]={0};
  for(int i=1;i<=N;i++) cin >> a[i];
  for(int i=N;i>0;i--){
    int ballcnt=0;
    for(int j=2*i;j<=N;j+=i) ballcnt += ball[j];
    if(ballcnt%2 != a[i]) ball[i] = 1;
  }
  for(int i=1;i<=N;i++) M+=ball[i];
  cout << M << endl;
  for(int i=1;i<=N;i++) if(ball[i] == 1) cout << i << " ";
  return 0;
}


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

int main(){

	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if((0 <= x - r && x + r <= W) && (0 <= y - r && y + r <= H)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3100
s = input()
c = [s[0]]
for i in range(1,len(s)):
    if(len(c)==0 or (c[-1]=='1' and s[i]=='1') or (c[-1]=='0' and s[i]=='0')):
        c.append(s[i])
    else:
        del c[-1]
print(len(s)-len(c))


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

int main()
{
	long w, h, x, y;
    double area;

    cin >> w >> h >> x >> y;
    int flag = 0;

    if (w%2==0 && h%2==0) {
        if (w/2 == x && h/2 == y) {
            flag = 1;
        }
    }

    cout << (w*h)/2.0 << " " << flag << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        StringBuilder S = new StringBuilder(sc.next());
                        int N = sc.nextInt();
                        for (int i = 0; i < N; i++) {
                                String operator = sc.next();
                                        int a = sc.nextInt(), b = sc.nextInt() + 1;
                                if (operator.equals("print")) {
                                        System.out.println(S.substring(a, b));
                                } else if(operator.equals("reverse")) {
                                        S.replace(a, b, (new StringBuilder(S.substring(a, b))).reverse().toString());
                                } else {
                                        String x = sc.next();
                                        S.replace(a, b, x);
                                }
                        }
                }
        }
}

Measured memory_bytes: 29628
/*
 ID: swagchicken1
 PROG:
 LANG: C++11
 */

#include <iostream>
#include <tuple>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cctype>
#include <climits>
#include <chrono>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;

#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)

//#define endl '\n';

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1000000007;

long double PI = 4*atan(1);
long double eps = 1e-12;


ll dp[2010][2010] = {};
int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    //ofstream cout("output.txt");
    //ifstream cin("input.txt");
    int sh,wo; cin >> sh >> wo;
    cout << ((wo >= sh) ? "unsafe" : "safe") << endl;
    //auto stop = chrono::high_resolution_clock::now();
    //auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    //cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}


Measured memory_bytes: 3604
/*
 * @Date         : 2020-08-09 00:34:04
 * @Author       : ssyze
 * @Description  :
 */
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> r, w;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W')
            w.push_back(i);
        else
            r.push_back(i);
    }
    reverse(r.begin(), r.end());
    int ans = 0;
    for (int i = 0; i < min(w.size(), r.size()); i++) {
        if (r[i] > w[i]) {
            swap(s[r[i]], s[w[i]]);
            ans++;
        }
    }
    bool flag = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W') flag = 1;
        if (flag && s[i] == 'R') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

struct point {
    double x, y;

    point operator + (point a) {
        return {x + a.x, y + a.y};
    }
    point operator - (point a) {
        return {x - a.x, y - a.y};
    }
    point operator * (double d) {
        return {x * d, y * d};
    }
    double dist() {
        return sqrt(x*x+y*y);
    }
};

const double EPS = 1e-9;

struct line {
    double a, b, c;
};

line ser_per(point a, point b) {
    line res;
    point d = a - b;
    res.a = d.x;
    res.b = d.y;
    point o = (a + b) * 0.5;
    res.c = res.a * o.x + res.b * o.y;
    return res;
}

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

    int n;
    cin >> n;
    vector<point> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y;
    }

    double res = 1e100;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point o = (a[j] + a[i]) * 0.5;
            double r = (a[i] - o).dist();
            bool ok = true;
            for (int k = 0; k < n; k++) {
                if ((a[k] - o).dist() > r + EPS) {
                    ok = false;
                }
            }
            if (ok) {
                res = min(res, r);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                line q = ser_per(a[i], a[j]);
                line w = ser_per(a[i], a[k]);

                // q.a * x + q.b * y = q.c
                // w.a * x + w.b * y = w.c

                double d = q.a * w.b - q.b * w.a;
                if (abs(d) < EPS) {
                    continue;
                }
                double dx = q.c * w.b - q.b * w.c;
                double dy = q.a * w.c - q.c * w.a;

                point o = {dx / d, dy / d};
                double r = (a[i] - o).dist();
                bool ok = true;
                for (int t = 0; t < n; t++) {
                    if ((a[t] - o).dist() > r + EPS) {
                        ok = false;
                    }
                }
                if (ok) {
                    res = min(res, r);
                }
            }
        }
    }
    cout << setprecision(20) << res << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  if(N%2!=0){
    cout << "No" << endl;
  }else{
    rep(i,N/2){
      if(S[i] != S[i+N/2]){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e9+5;
int main()
{
	int n,k; cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	vector<int> dp(n,MAX);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<i+k+1;j++)
		{
			if(j<n)
			{
				int t=h[i]-h[j];
				if(t<0)
				{
					t=t*(-1);
				}
				if(dp[j]>(dp[i]+t))
				{
					dp[j]=dp[i]+t;
				}
			}
		}
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char p[100010];
long long S[100010],P[100010],n;
int main(){
	cin>>n;
	scanf("%s",p);
	long long i,j;
	for(i=0;p[i];i++){
		if(p[i]=='o')P[i+1]=0;
		else P[i+1]=1;
	}
	P[n+1]=P[1];
	for(i=0;i<8;i++){
		S[0]=i&1;
		S[1]=(i>>1)&1;
		S[2]=(i>>2)&1;
		for(j=2;j<=n+1;j++)S[j+1]=S[j-2]^P[j];
		if(S[0]^S[n]^S[1]^S[n+1]||S[1]^S[n+1]^S[2]^S[n+2])continue;
		for(j=1;j<=n;j++)cout<<(S[j]^S[j-1]?'W':'S');
		return 0;
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const int maxn = 2e5 + 5;
int mx[maxn];
int n, a[maxn];

void upd(int x, int v) {
	for (; x < maxn; x += x & -x) mx[x] = max(mx[x], v);
}

int qry(int x) {
	int ans = 0;
	for (; x; x -= x & -x) ans = max(ans, mx[x]);
	return ans;
}

struct T {
	int val, fix;
	T *ls, *rs;
	T(int v) {val = v, fix = rand(), ls = rs = NULL;}
};

void split(T *x, int v, T *&a, T *&b) {
	if (!x) {a = b = NULL; return ;}
	if (x->val <= v) a = x, split(x->rs, v, a->rs, b);
	else b = x, split(x->ls, v, a, b->ls);
}

T *merge(T *a, T *b) {
	if (!a || !b) return a ? a : b;
	if (a->fix < b->fix) {a->rs = merge(a->rs, b); return a;}
	else {b->ls = merge(a, b->ls); return b;}
}

int mxv(T *x) {while (x && x->rs) x = x->rs; return x ? x->val : 0;}
void prt(T *x) {if (x) prt(x->ls), printf("%d ", x->val), prt(x->rs);}

T *rt[maxn * 2];
vector <int> lst;
int f[maxn];

int main() {
//	freopen("in", "r", stdin);
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) scanf("%d", &a[i]);
	for (int i = 0; i < n; ++ i) {
		int v = qry(n - a[i] + 1);
		rt[v] = merge(rt[v], new T(a[i]));
		f[a[i]] = v;
		upd(n - a[i] + 1, v + 1);
	}
	lst.resize(qry(n));
	for (int i = 0; i < lst.size(); ++ i) lst[i] = mxv(rt[i]);
	for (int i = 0; i < lst.size() - 1; ++ i) {
		while (rt[i]) {
			int x = mxv(rt[i]);
			int lb = i + 1, rb = lst.size();
			while (lb < rb) {
				int md = (lb + rb) >> 1;
				if (lst[md] > x) lb = md + 1;
				else rb = md;
			}
			if (lb == lst.size()) lst.pb(0);
			T *a, *b;
			split(rt[i], lst[lb], a, b);
			rt[i] = a; rt[lb] = merge(rt[lb], b);
			lst[i] = mxv(a); lst[lb] = mxv(rt[lb]);
		}
	}
	printf("%d\n", int(lst.size()) - 1);
//	printf("%.3f\n", clock() * 1.0 / CLOCKS_PER_SEC);
	return 0;
}


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

int solve() {
	int n, k;
	cin >> n >> k;
	int pre;
	priority_queue<int, vector<int>, greater<int> > que;
	cin >> pre;
	for (int i = 1; i < n; i++) {
		int x;
		cin >> x;
		que.push(x - pre);
		pre = x;
	}
	int sum = 0;
	while (que.size() >= k) {
		sum += que.top();
		que.pop();
	}
	return sum;
}

int main () {
	int t;
	cin >> t;
	for (; t; t--) {
		cout << solve() << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<char> s(N);
    for (int i=0; i<N; ++i) cin >> s[i];

    for (char c : s) {
        if (c == 'Y') {
            cout << "Four" << endl;
            return;
        }
    }
    cout << "Three" << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)


int main() {
  int l,r;
  cin >> r;
  cout << pow(r,2.0)*3.0 << endl;
}

Measured memory_bytes: 3788
n = input()
a = input().split()
a = [int(s) for s in a]
a.sort(reverse=True)

if a[-1] == 0:
  print(0)
else :
  sum = 1
  for i in a:
    sum *= i
    if sum > 10**18:
      sum = -1
      break
  print(sum)

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

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

	int a,b;
	cin>>a>>b;
	if(a==0&&b==0)
		cout<<0<<endl;
	cout<<(a-1)*(b-1)<<endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

f=bfs(0)
s=bfs(n-1)
ctf=0
cts=0
for i in range(n):
  if f[i]<=s[i]:
    ctf+=1
  else:
    cts+=1
if ctf>cts:
  print('Fennec')
else:
  print('Snuke')

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

int main(){
  int S;
  cin >> S;
  
  if(S/100 ==0){
    if( S%100 >= 13){
      cout << "NA"<<endl;
    }
    else if ( S%100 == 0){
      cout << "NA" << endl;
    }
    else if ( S%100 < 13){
      cout << "YYMM" <<endl;
    }
  }
  
  else if ( S/100 < 13){
    if( S%100 >= 13){
      cout << "MMYY" <<endl;
    }
    else if ( S%100 == 0){
      cout << "MMYY" << endl;
    }
    else if ( S%100 < 13){
      cout << "AMBIGUOUS" <<endl;
    }
  }
  
  else if (S/100 >= 13){
    if( S%100 >= 13){
      cout << "NA" <<endl;
    }
    else if ( S%100 == 0){
      cout << "NA" << endl;
    }
    else if ( S%100 < 13){
      cout << "YYMM" <<endl;
    }
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int H = int.Parse(str[0]);
		int W = int.Parse(str[1]);
		int[,]C = new int[H,W];
		for(var i=0;i<H;i++){
			string str2 = Console.ReadLine();
			for(var j=0;j<W;j++){
				if(str2.Substring(j,1)=="#"){
					C[i,j]=1;
				}
			}
		}
		var uf = new UnionFind(H*W);
		for(var i=0;i<H;i++){
			for(var j=0;j<W;j++){
				if(i<H-1 && C[i+1,j]!=C[i,j]){
					uf.Unite(i*W+j,(i+1)*W+j);
				}
				if(j<W-1 && C[i,j+1]!=C[i,j]){
					uf.Unite(i*W+j,i*W+(j+1));
				}
			}
		}
		long[,]A1 = new long[H,W];
		long[,]A2 = new long[H,W];
		for(var i=0;i<H;i++){
			for(var j=0;j<W;j++){
				int r = uf.Root(i*W+j);
				if(C[i,j]==1){
					A1[r/W,r%W]++;
				} else {
					A2[r/W,r%W]++;
				}
			}
		}
		long ans = 0;
		for(var i=0;i<H;i++){
			for(var j=0;j<W;j++){
				ans += A1[i,j]*A2[i,j];
			}
		}
		Console.WriteLine(ans);
	}
}

public class UnionFind
{
    private int[] data;
	public UnionFind(int size){
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y){
        x = Root(x);
        y = Root(y);
        if (x != y){
            if (data[y] < data[x]){
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
	public bool IsSameGroup(int x, int y){
        return Root(x) == Root(y);
    }
    public int Root(int x){
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }
}

Measured memory_bytes: 18780
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void){
    int a, b;
    scanf("%d %d", &a,&b);
    
   int d = a / b;
   int r = a % b;
   double f = (double)a / b;
   
   printf("%d %d %f\n", d, r, f);

   return 0;
}



Measured memory_bytes: 2736
def main():
    import sys
    input = sys.stdin.readline
    A, B = input().rstrip().split()
    A = int(A)
    ans = 0
    ans += A*int(B[0])*100
    ans += A*int(B[2])*10
    ans += A*int(B[3])
    print(ans//100)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define ET cout << "\n"
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef bbq
#define debug(...) {\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}
#define DB(a,s,e) {for(int _i=s;_i<e;++_i) cerr << a[_i] << " ";cerr << "\n";}
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T,typename ...S> void _do(T &&x,S &&...t){cerr<<x<<", ";_do(t...);}
template<typename a,typename b> ostream& operator << (ostream &s,const pair<a,b> &p){return s<<"("<<p.X<<","<<p.Y<<")";}
#else
#define debug(...)
#define DB(a,s,e)
#endif

int arr[100005];
deque<pii> dq;// 0: 0101... 1:11....

int main()
{
    IOS();
    int n;
    cin >> n;
    for(int i=0;i<n;++i)
        cin >> arr[i];
    sort(arr,arr+n),dq.pb(pii(0,arr[0]));
    for(int i=1;i<n;++i)
    {
        if(arr[i]==arr[i-1])
            dq.pb(pii(dq.back().X^1,1));
        else
            dq.pb(pii(((arr[i]-arr[i-1])|~dq.back().X)&1,1)),dq.pb(pii(0,arr[i]-arr[i-1]));
        if(dq[0].Y>1)
            --dq[0].Y;
        else
            dq.pop_front();
    }
    if(~dq[0].X&dq[0].Y&1)
        cout << "Second\n";
    else
        cout << "First\n";
}

Measured memory_bytes: 1408