akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

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

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	A := nextInt()
	B := nextInt()
	M := nextInt()
	AS := make([]int, A)
	BS := make([]int, B)
	minA := 1000000
	minB := 1000000
	for i := 0; i < A; i++ {
		n := nextInt()
		AS[i] = n
		minA = min(minA, n)
	}
	for i := 0; i < B; i++ {
		n := nextInt()
		BS[i] = n
		minB = min(minB, n)
	}
	ANS := minA + minB
	for i := 0; i < M; i++ {
		x := nextInt()
		y := nextInt()
		c := nextInt()
		ANS = min(ANS, AS[x-1]+BS[y-1]-c)
	}
	fmt.Println(ANS)
}


Measured memory_bytes: 6140
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	string s, ans;

	cin >> s;

	for (int i = 0; i < s.size(); ++i) {
		if (s.at(i) == '0') { ans.push_back('0'); }
		else if (s.at(i) == '1') { ans.push_back('1'); }
		else if (s.at(i) == 'B' && ans.size() >0) { ans.pop_back(); }
	}

	cout << ans << endl;

}


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

int n, m, a[205], cnt = 0;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        a[i] = 2;
    for (int i = n; i < n + m; ++i)
        a[i] = 1;

    for (int i = 0; i < n + m; ++i)
        for (int j = i + 1; j < n + m; ++j)
        {
            if ((a[i] + a[j]) % 2 == 0)
                ++cnt;
        }
    cout << cnt << endl;
}


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

int main()
{
  string a, b;
  cin >> a >> b;
  
  int ab = stoi(a+b);
  int sq = (int)(sqrt(ab));
  if(sq*sq==ab)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

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

  return 0;
}
  
  


Measured memory_bytes: 256
#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;
}
vector<ll> primes(ll n){
  vector<ll> v(1,1);
  for (ll i = 2; n >= i * i; ++i) {
		if(!(n % i)){
      v.pb(i);
	  }
  }
  if(v.size()==1)v.pb(n);
  return v;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n,m;cin>>n>>m;
  if(n*500 >= m){
    print("Yes");
  }else{
    print("No");
  }

  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  int k, n;
  cin >> k >> n;
  
  int p1;
  cin >> p1;
  
  int p = p1, q, d = 0;
  for(int i = 1; i < n; i++){
    cin >> q;
    d = max(d, q - p);
    p = q;
  }
  
  d = max(d, k - p + p1);
  
  cout << k - d;
}

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

using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

ll dp[101010];
ll v[110], w[110];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll>c(m);
	rep(i, m) {
		cin >> c[i];
	}
	rep(i, n + 1) {
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(i, n+1) {
		rep(j, m) {
			if (i - c[j] < 0)dp[i] = dp[i];
			else {
				dp[i] = min(dp[i], dp[i - c[j]] + 1);
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}



Measured memory_bytes: 3496
let rec f n t a ans lst =
  match n with
  | 0 -> ans
  | _ ->
    let buf = float_of_int (t) -. float_of_int (List.nth lst n) *. 0.006 in
    let ansT = float_of_int (t) -. float_of_int (List.nth lst ans) *. 0.006 in
    if abs_float (float_of_int (a) -. buf) < abs_float (float_of_int (a) -. ansT)
    then f (n-1) t a n lst
    else f (n-1) t a ans lst
let () =
  Scanf.scanf "%d\n"
    (fun n -> Scanf.scanf "%d %d\n"
        (fun t a ->
           Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x))
           |> Array.to_list
           |> f (n-1) t a 0
           |> (+) 1))
  |> print_int

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

int main()
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  for (auto &one : s)
  {
    int tmp = (one - 'A' + n) % 26;
    one = 'A' + tmp;
  }
  cout << s << endl;
}

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

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

int main() {

	int n;
	cin >> n;

	double ans = 0;
	
	rep(i, n) {
		double d;
		cin >> d;

		ans += 1 / d;
	}

	printf("%.14f", 1 / ans);

	return 0;
}


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

int main(void)
{
	int N;
	cin >> N;

	vector<int> a(N);
	for(int i=0; i<N; i++)
		cin >> a[i];

	sort(a.begin(), a.end());

	cout << a.back() - a.front() << endl;

	return 0;
}


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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
  ll m;
  cin >> m;
  vector<ll> d(m), c(m);
  ll sumc = 0, sumdc = 0;
  rep(i, 0, m) {
    cin >> d[i] >> c[i];
    sumc += c[i];
    sumdc += d[i] * c[i];
  }
  cout << (sumc - 1) + (sumdc - 1) / 9 << endl;
}


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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N, K;
    string S;

    cin >> N >> K >> S;
    S[K - 1] += 32;
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int MAX = 2e5+10, MAXL = 20;
ll n, res, a, b, c, d;
ll arr[200];
ll f (ll a, ll b) {
	return a / __gcd(a, b) * b;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	res = 1;
	for (int i = 0; i < n; i++) {
		cin >> a;
		res = f (res, a);
	}
	 cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a=str(input())
b=str(input())

if a[0] == b[-1] and a[1] == b[-2] and a[2] == b[-3]:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = onem()

a = l()

su = 1
s = 0
for i in range(n):
    su *= a[i]

for i in range(n):
    s += su/a[i]

print(su/s)




Measured memory_bytes: 66028
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
from math import *
input = sys.stdin.readline

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def factorization(n):
    # 参考: https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8
    dic = defaultdict(int)
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            dic[i] = cnt
            
    if temp!=1:
        dic[temp] = 1
    if not dic:
        dic[n] = 1

    return dic

def main():
    mod = 10**9 +7
    n = int(input())
    facn = factorial(n)

    pf = defaultdict(int)
    for i in range(1, n+1):
        pfp = factorization(i)
        for j in pfp:
            pf[j] += pfp[j]

    ans = 1
    for i in pf:
        if i == 1:
            continue
        ans *= pf[i] + 1 
        ans %= mod
        
    print(ans)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 69076
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

bool comp(ll L, ll R){
	return abs(L) < abs(R);
}

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll count=0;
	REP(i,n){
		cin >> a[i];
		if(a[i] < 0) count++;
	}
	sort(a.begin(),a.end(),comp);
	
	ll ans=0;
	REP(i,n){
		if(i==0){
			if(count%2){
				chmin(a[i], -1*a[i]);
			}else{
				chmax(a[i], -1*a[i]);
			}
		}else{
			chmax(a[i], -1*a[i]);
		}
		
		ans += a[i];
	}
	
	cout << ans << "\n";
	
	
	return 0;
}

Measured memory_bytes: 4048
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int d,n;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	cin>>d>>n;
	if(n==100){
		++n;
		if(d==0)
		cout<<n<<"\n";
		else if(d==1)
			cout<<n*100<<"\n";
		else if(d==2)
			cout<<n*10000<<"\n";
	}
	else if(d==0)
		cout<<n<<"\n";
	else if(d==1){
		n*=100;
		cout<<n<<"\n";
	}
	else if(d==2){
		n*=10000;
		cout<<n<<"\n";
	}
	
	
	return 0;
}



Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main() {
    char a, b;
    cin >> a >> b;
    if (a == 'H')cout << (b == 'H' ? 'H' : 'D') << endl;
    if (a == 'D')cout << (b == 'H' ? 'D' : 'H') << endl;
}

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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using multi = mp::number<mp::cpp_dec_float<1024>>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  multi a, b;
  cin >> a >> b;
  multi c = a * b;
  cout << (long long)floor(c) << '\n';
  return 0;
}

Measured memory_bytes: 3884
#include <stdio.h>
int main()
{
    int i, j, k, n;
    while(scanf("%d", &n) == 1)
    {
        long long int fact=1;
        for(i=1;i<=n;i++)
        {
            fact=fact*i;
        }
        printf("%lld\n",fact);
    }
    return 0;
}

Measured memory_bytes: 588
def partition(p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    A[i + 1] = f"[{A[i + 1]}]"
    print(" ".join(map(str, A)))
    return i + 1


input()
A = list(map(int, input().split()))
partition(0, len(A) - 1)



Measured memory_bytes: 16400
from sys import stdin
N,M = map(int,input().split())
F = [list(map(int,stdin.readline().split())) for i in [0]*M]
G = [[] for i in [0]*(N+1)]
for i in F:
    G[i[0]].append(i[1])
    G[i[1]].append(i[0])

def main(n,m,g):
    visited = [False for i in [0]*(n+1)]
    ans = 1
    for i in range(n+1):
        if visited[i]:
            continue
        q = [i]
        temp = 1
        while q:
            #print(q)
            #print(temp)
            node = q.pop(0)
            visited[node] = True
            adj = g[node]
            for j in adj:
                if visited[j]:
                    continue
                visited[j] = True
                temp += 1
                q.append(j)
        ans = max(ans,temp)
    print(ans)

if __name__=="__main__":
    main(N,M,G)

Measured memory_bytes: 69200
S=input()
if S=='SUN':
    print(7)
elif S=='MON':
    print(6)
elif S=='TUE':
    print(5)
elif S=='WED':
    print(4)
elif S=='THU':
    print(3)
elif S=='FRI':
    print(2)
elif S=='SAT':
    print(1)

Measured memory_bytes: 8940
// finish date: 2018/08/04
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int D, G;
    cin >> D >> G;
    vi order(D);
    rep(i, D) order[i] = i;

    vi p(D), c(D);
    rep(i, D) cin >> p[i] >> c[i];

    int temp;
    int cnt;
    int addScore;
    int ans = INF;
    do {
        temp = 0;
        cnt = 0;
        rep(i, D) {
            addScore = p[order[i]] * 100 * (order[i] + 1) + c[order[i]];
            if (temp + addScore >= G) {
                rep(j, p[order[i]]) {
                    temp += 100 * (order[i] + 1);
                    cnt++;
                    if (j == p[order[i]] - 1) {
                        temp += c[order[i]];
                    }
                    if (temp >= G) {
                        ans = min(ans, cnt);
                        goto outer;
                    }
                }
            } else {
                temp += addScore;
                cnt += p[order[i]];
            }
        }
        outer:;
    } while (next_permutation(order.begin(), order.end()));

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



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A[500002];
int O[500002];
int n;
int c = 0;
void msort(int b, int e){
	if (e-b==1) return;
	
	if (e-b==2)
	{
		int & ab = A[b];
		int & ae = A[b+1];
		if (ab > ae)
		{
			int abb = ab;
			ab=ae;
			ae=abb;
		}
		c+=2;
		return;
	}
	
	int m=(b+e)/2;
	msort(b,m);
	msort(m,e);
	int j=0;
	for(int i=b;i<m;i++){
		O[j++]=A[i];
	}
	O[j++]=0x7fffffff;
	for(int i=m;i<e;i++){
		O[j++]=A[i];
	}
	O[j++]=0x7fffffff;
	int o1=0;
	int o2=m-b+1; /// <-- was the bug.
	for (int i=b;i<e;i++){
		if(O[o1]<O[o2]){
			A[i]=O[o1++];
		}else{
			A[i]=O[o2++];
		}
		c++;
	}
}
int main(){
	cin >> n;
	for(int i=0;i<n;i++)cin>>A[i];
	msort(0,n);
	for(int i=0;i<n;i++){
		if (i) cout <<' ';
		cout<<A[i];
	}
	cout << endl<<c<<endl;
}

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

void solve(long long N, vector<long double> x, vector<string> u){
	double res = 0;
	for (int i = 0; i < N; i++) {
		if (u[i] == "JPY") {
			res += x[i];
		} else {
			res += x[i]*380000.0;
		}
	}
	printf("%.16f\n",res);
}

int main(){
	long long N;
	scanf("%lld",&N);
	vector<string> u(N-1+1);
	vector<long double> x(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%Lf",&x[i]);
		cin >> u[i];
	}
	solve(N, x, u);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int c = __gcd(a, b);
  for (int i = c; c >= 1; i--) {
    if (c % i == 0) {
      k--;
      if (k == 0) {
        cout << i;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0] * (N + 1)
        self.b = 1 << N.bit_length() - 1

    # a - 1の場所にwを追加する
    def add(self, a, w):
        x = a
        while(x <= self.N):
            self.bit[x] += w
            x += x & -x

    def get(self, a):
        ret, x = 0, a - 1
        while(x > 0):
            ret += self.bit[x]
            x -= x & -x
        return ret

    # 区間[l, r - 2]についての合計を求める
    def cum(self, l, r):
        return self.get(r) - self.get(l)

    def lowerbound(self,w):
        if w <= 0:
            return 0
        x = 0
        k = self.b
        while k > 0:
            if x + k <= self.N and self.bit[x + k] < w:
                w -= self.bit[x + k]
                x += k
            k //= 2
        return x + 1

# BITは前から置いていく
# そのためのクエリソート
N, Q = getNM()
C = getList()
que = [getList() for i in range(Q)]

# que[r]に[l(始点), i(queでのインデックス)]をappend
que_d = defaultdict(list)
for i in range(Q):
    que_d[que[i][1]].append([que[i][0], i])
ans = [0] * Q
# 色iのうち最も右側にあるものはどこにあるか
dic = defaultdict(lambda: -float('inf'))
bit = BIT(N)

for i in range(N):
    # 既に場所が登録されているならそれを削除する
    if dic[C[i]] >= 1:
        bit.add(dic[C[i]], -1)
    # 新しい「良い球」の場所を登録
    # 1-indexで!!
    dic[C[i]] = i + 1
    bit.add(dic[C[i]], 1)

    # queryに答える
    if len(que_d[i + 1]) > 0:
        for l, j in que_d[i + 1]:
            # cum(l, r):区間[l, r - 2]についての合計を求める
            ans[j] = bit.cum(l, i + 2)

for i in ans:
    print(i)

Measured memory_bytes: 339940
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 123456789;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

Vi v[100001];
int col[100001];
int n,m;
void dfs(int N,int c)
{
	col[N]=c;
	for(int next:v[N])
	{
		if(col[next]==c)
		{
			printf("%lld",1LL*n*(n-1)/2-m);
			exit(0);
		}
		if(!col[next])
		{
			dfs(next,3-c);
		}
	}
}
int main() {
	scanf("%d%d",&n,&m);
	fup(i,1,m,1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1,1);
	int a[3]={0};
	fup(i,1,n,1)a[col[i]]++;
	printf("%lld",1LL*a[1]*a[2]-m);
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
multiset< string > S;
int main() {
	int x,y,z;
	scanf("%d%d%d",&x,&y,&z);
	while(x--) S.insert("a");
	while(y--) S.insert("b");
	while(z--) S.insert("c");
	while(S.size()>1) {
		string a=*S.begin(),b=*S.rbegin();
		S.erase(S.begin());
		S.erase(--S.end());
		S.insert(a+b);
	}
	cout << *S.begin() <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    double d;
    cin >> d;
    int d1 = d * 1000;
    double ans = sqrt(2) * d;
    ans = max<double>(ans, (int)(d) + 1);
    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;
ll a[N] , b[N] ;
vector<pair<ll , pll> > v ;
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll n ;
    cin >> n ;
    for (int i = 1 ; i <= n ; i ++) {
    	cin >> a[i] >> b[i] ;
    	v.pb({a[i] + b[i] , {a[i] , b[i]}}) ;
	}
	sort(all(v)) ;
	reverse(all(v)) ;
	ll ans = 0 ;
	for (int i =0 ; i < v.size() ; i ++) {
		if (i & 1) {
			ans -= v[i].S.S ;
		}
		else ans += v[i].S.F ;
	}
	cout << ans ;
    
    return (0) ;
}

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

int main(){
    string S;
    cin >> S;
    int a = 0;

    for(int i = 0; i < 4; i++){
        if(S.at(i) == '+'){
                a++;
        }else{
            a--;
        }
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,K = map(int, input().split())
    tmp = N%K
    print(min(tmp, (-1*tmp)%K))

if __name__ == '__main__':
    main()


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

	
int main(){
	int H, W;
	cin >> H >> W;
	vector<vector<char>> a(H, vector<char>(W));
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> a.at(i).at(j);
		}
	}
	
	vector<char> jdgLin(H);
	vector<char> jdgCul(W);
	for(int i = 0; i < H; i++){
		bool jdg = true;
		for(int j = 0; j < W; j++){
			if(a.at(i).at(j) != '.'){
				jdg = false;
			}
		}
		if(jdg) jdgLin.at(i) = 'a';
		else jdgLin.at(i) = 'b';
	}
		for(int i = 0; i < W; i++){
		bool jdg = true;
		for(int j = 0; j < H; j++){
			if(a.at(j).at(i) != '.'){
				jdg = false;
			}
		}
		if(jdg) jdgCul.at(i) = 'a';
		else jdgCul.at(i) = 'b';
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(jdgLin.at(i) == 'b' && jdgCul.at(j) == 'b'){
				cout << a.at(i).at(j);
			}
			if(j == (W - 1)){
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 1000005
lld v[N],x1[N],x2[N];
lld dp1[N],dp2[N];
lld pref1[N],pref2[N],suff1[N],suff2[N];
int main()
{
    //sync;
    lld n,c,ans = 0;
    cin>>n>>c;
    rep(i,1,n+1) {
        cin>>x1[i]>>v[i];
        x2[i] = c - x1[i];
    }
    lld maxm = 0;
    rep(i,1,n+1) {
        dp1[i] = maxm + v[i] - x1[i];
        maxm = max(maxm, dp1[i] + x1[i]);
        ans = max(ans, dp1[i]);
        pref1[i] = max(pref1[i-1], dp1[i] - x1[i]);
        pref2[i] = max(pref2[i-1], dp1[i]);
    }
    maxm = 0;
    repd(i,n,1) {
        dp2[i] = maxm + v[i] - x2[i];
        maxm = max(maxm, dp2[i] + x2[i]);
        ans = max(ans, dp2[i]);
        suff1[i] = max(suff1[i+1], dp2[i] - x2[i]);
        suff2[i] = max(suff2[i+1], dp2[i]);
    }
    rep(i,0,n+2) {
        ans = max(ans, pref1[i] + suff2[i+1]);
        ans = max(ans, pref2[i] + suff1[i+1]);
    }
    cout<<ans;
    return 0;
}

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

int main() {
  string x;
  cin >> x;
  char stack[200000];
  int n = 0;
  for (int i = 0; i < x.length(); i++) {
    stack[n++] = x[i];
    if (n >= 2 && stack[n - 2] == 'S' && stack[n - 1] == 'T') {
      n -= 2;
    }
  }
  cout << n << endl;
}


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

int main() {
    int N;
    cin >> N;
    int val[N][3];
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> val[i][j];
        }
    }
    long long int dp[N][3];
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            dp[i][j] = -100000;
        }
    }
    for(int i = 0; i < 3; i++) {
        dp[0][i] = val[0][i];
    }
    for(int i = 1; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            dp[i][j] = max(dp[i-1][(j+1)%3] + val[i][j], dp[i-1][(j+2)%3]+ val[i][j]);
        }
    }
    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;
    return 0;
}

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

struct cell{
  int w,e;
  cell(){w=e=0;}
  cell(int a,int b){w=a;e=b;}
};
bool operator<(cell a,cell b){return a.e!=b.e?a.e<b.e:a.w<b.w;}

int main(){
  int n,a,b,i,s;
  vector<cell> v;
  while(cin>>n,n){
    v.resize(n);
    for(i=0;i<n;i++){
      cin>>a>>b;
      v[i]=cell(a,b);
    }
    sort(v.begin(),v.end());
    s=0;
    for(i=0;i<n;i++){
      s+=v[i].w;
      if(s>v[i].e){s=-1;break;}
    }
    if(~s)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 0
N = int(input())
a = list(int(i) for i in input().split())  

sum = 0
for k in range(N):
  if k == 0:
    sum += abs(a[k])
  elif k == (N-1):
    sum += abs(a[k] - a[k-1]) + abs(a[k])
  else:
    sum += abs(a[k] - a[k-1])

for j in range(N):
  if j == 0:
    if (a[j+1] - a[j]) * (a[j] -0) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]),abs(a[j]-a[j+1])))
  elif j == N-1:  
    if (a[j] - a[j-1]) * (0 - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j])))
  else:
    if (a[j] - a[j-1] ) * (a[j+1] - a[j]) >= 0:
      print(sum)
    else:
      print(sum - 2 * min(abs(a[j]-a[j-1]),abs(a[j+1]-a[j])))
    

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

vi a,f,p;
int n;
ll k;

bool solve(ll v){
    ll kk=k;
    for(int i:p){
        ll x=(ll)a[i]*f[i];
        if (x<=v) return true;
        ll j = (x-v)/f[i];
        if (x - j*f[i]>v) ++j;
        if (j>kk) return false;
        kk -= j;
    }
    return true;
}

int main() {
    READ(0);
    cin>>n>>k;
    a.resize(n),f.resize(n),p.resize(n);
    FOR(i,n) cin>>a[i];
    FOR(i,n) cin>>f[i];
    FOR(i,n) p[i]=i;
    sort(a.begin(),a.end());
    sort(f.begin(),f.end(),greater<int>());
    sort(p.begin(),p.end(),[](int x,int y){return (ll)a[x]*f[x]>(ll)a[y]*f[y];});
    ll lo=0,hi=(ll)a[p[0]]*f[p[0]],mid;
    while(lo<hi) {
        mid = lo + (hi - lo) / 2;
        if (solve(mid)) hi=mid;
        else lo = mid + 1;
    }
    cout << lo;
    return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main() {
	long long n;
	cin >> n;
	vector<long long> a(n,0);
	map<long long,long long> b;
	
	for(long long i=0;i<n;i++){
		cin >> a[i];
		b[a[i]]++;
	} 
	
	long long sum=0;
	for(auto p : b){
		if(p.second<=1)continue;
		sum+=(p.second*(p.second-1))/(2);
	}
	
	for(long long i=0;i<n;i++){
		long long org=(b[a[i]]*(b[a[i]]-1))/2;
		if(org<0)org=0;
		
		long long now=((b[a[i]]-1)*(b[a[i]]-2))/2;
		if(now<0)now=0;
		
		long long ans=sum-org+now;
		cout << ans << endl;
	} 
	
	return 0;
}



Measured memory_bytes: 11008
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll N;

int main () {
  cin >> N;
  for (ll x = 1; x <= 3500; ++x) {
    for (ll y = 1; y <= 3500; ++y) {
      ll bunbo = 4 * x * y - N * y - N * x;
      if (bunbo <= 0) continue;
      ll z = (N * x * y) / (4 * x * y - N * y - N * x);
      if (4 * x * y * z == N * (x * y + y * z + z * x)) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 768
#include<vector>
#include<algorithm>
using namespace std;

// 辺を表す構造体
struct edge{
    int from, to;
    long long cost;
};

// v:=頂点数 es:=辺の集合 cost:=始点からの最短経路のコストを格納する配列
// s:=始点(指定しなければ頂点0) g:=終点(指定しなければ頂点v-1)
// 始点から到達可能で、かつ終点へ到達可能な負閉路が検出された場合falseを、それ以外の場合trueを返す
bool bellman_ford(int v, const vector<edge>& es, vector<long long>& cost, int s = 0, int g = -1){
    if(g == -1){
        g = v - 1;
    }

    constexpr long long INF = 1LL << 61;

    cost.resize(v);
    fill(cost.begin(), cost.end(), INF);
    cost[s] = 0;

    for(int i = 0 ; i < v * 2 ; ++i){
        for(auto& e : es){
            if(cost[e.from] < INF && cost[e.from] + e.cost < cost[e.to]){
                if(i >= v - 1 && e.to == g){
                    return false;
                }else if(i >= v - 1){
                    cost[e.to] = -INF;
                }else{
                    cost[e.to] = cost[e.from] + e.cost;
                }
            }
        }
    }

    return true;
}

#include<iostream>

int main(){
    int n, m;
    long long p;
    cin >> n >> m >> p;

    vector<edge> es;
    for(int i = 0 ; i < m ; ++i){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        es.push_back({a - 1, b - 1, p - c});
    }

    vector<long long> cost;
    if(bellman_ford(n, es, cost)){
        cout << max(-cost[n - 1], 0LL) << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define MAX 1e9+7
#define MIN -MAX
#define i(a) cin>>a
#define in(a,b) cin>>a>>b
#define o(a) cout<<a
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define v(a) vector<ll>a
#define mp(a,b) make_pair(a,b)
#define NO_OF_CHARS 256
using namespace std;
int countDivisors(int n)
{
    int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
int power(int x,int y)
{
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int lenOfLongIncSubArr(int arr[], int n)
{
    // 'max' to store the length of longest
    // increasing subarray
    // 'len' to store the lengths of longest
    // increasing subarray at diiferent
    // instants of time
    int max = 1, len = 1;

    // traverse the array from the 2nd element
    for (int i=1; i<n; i++)
    {
        // if current element if greater than previous
        // element, then this element helps in building
        // up the previous increasing subarray encountered
        // so far
        if (arr[i] <= arr[i-1])
            len++;
        else
        {
            // check if 'max' length is less than the length
            // of the current increasing subarray. If true,
            // then update 'max'
            if (max < len)
                max = len;

            // reset 'len' to 1 as from this element
            // again the length of the new increasing
            // subarray is being calculated
            len = 1;
        }
    }

    // comparing the length of the last
    // increasing subarray with 'max'
    if (max < len)
        max = len;

    // required maximum length
    return max;
}
//In one operation u can choose any element in an array
//and divide it by 2.The value of K is given and we can divide
//K times.We have to find the minm sum.
int main(){
    ll n,k;
    cin>>n;
    k = n-1;
    cout<<(k*(k+1))/2;
}


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

int main(){
int N;
cin >> N;
vector<int> vec(N);
for(int i=0;i<N;i++){
    cin >> vec.at(i);
}
sort(vec.begin(),vec.end());

int a =0;
for(int j=0;j<N-2;j++){
    for(int k=j+1;k<N-1;k++){
        for(int l=k+1;l<N;l++){
            if(vec.at(j)==vec.at(k) || vec.at(j)==vec.at(l)){
                continue;
            }
            if(vec.at(k)==vec.at(l)){
                continue;
            }
            if(vec.at(l) < (vec.at(j)+vec.at(k))){
                a++;
            }
        }
    }
}

cout << a << endl;
return 0;
}

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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const ll inf = 2e18;

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

	int n, w; cin >> n >> w;
	ll v[n], c[n], dp[w + 1];
	rep(i, 0, n) cin >> c[i] >> v[i];
	rep(x, 0, w + 1) dp[x] = 0;
	rep(i, 0, n)
		per(x, c[i], w + 1)
				ckmax(dp[x], dp[x - c[i]] + v[i]);
	cout << dp[w];
}

Measured memory_bytes: 1024
N, M = map(int, input().split())

X = list(map(int, input().split()))

X.sort(reverse=True)

d = [0]

for i in range(M-1):
    d.append(X[i] - X[i+1])

d.sort(reverse=True)
if N >= M:
    print(0)
else:
    print(sum(d)-sum(d[0:N-1]))




Measured memory_bytes: 13960
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> a(n+1, true);
	for (int i = 0; i < m; i++) {
		int temp;
		cin >> temp;
		a[temp] = false;
	}
	
	vector<ll> dp(n + 1);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= min(n, i + 2); j++) {
			if (a[j]) {
				dp[j] += dp[i];
				dp[j] %= 1000000007;
			}
		}
	}
	
	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1792
// Problem : D - Teleporter
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//look at my code
//my code is amazing
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define vc vector
#define pb push_back
#define ar array
#define all(a) (a).begin(), (a).end()
#define ms(v,n,x) fill(v,v+n,x);
#define init(c,a) memset(c,a,sizeof(c))
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define inf 9e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
// const int N=;

int32_t main()
{
    
	fast
	ll n,k;
	cin>>n>>k;
	ll p[n+1];
	for(ll i=1;i<=n;i++)
	cin>>p[i];
	vll vis(n+1);
	vll v;
	v.pb(1);
	vis[1]=1;
	ll i=1;
	
	while(!vis[p[i]]) {
		v.pb(p[i]);
		i=p[i];
		vis[i]=1;
		
	}
	// trace(p[i]);
	// for(auto i:v)
	// cout<<i<<" ";
	
	ll cs=p[i];
	vll cycle;
	ll f=0;
	
	ll b=0,c=0;
	
	for(auto i:v){
		if(i==cs){
			f=1;
			b=c;			
		}
		if(f==1)
		cycle.pb(i);
		
		c++;
	}
	
	if(k<=b){
		cout<<v[k];
		return 0;
	}
	
	k-=b;
	
	
	ll s=cycle.size();
	k%=s;
	cout<<cycle[k];
	

	



    

	return 0;
    
}

Measured memory_bytes: 10640
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m==-1&&f==-1&&r==-1) break;
            if(m==-1||f==-1||m+f<30){
                System.out.println("F");
            }else if(m+f<50){
                if(r<50){
                    System.out.println("D");
                }else{
                    System.out.println("C");
                }
            }else if(m+f<65){
                System.out.println("C");
            }else if(m+f<80){
                System.out.println("B");
            }else{
                System.out.println("A");
            }
        }
        sc.close();
    }
}


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

using namespace std;

int main() {
    int n;cin >>n;
    int p;
    for(int i;i<=n;++i){
        p = pow(2,i);
        if (p>n){
            cout << pow(2,i-1)<< endl;
            return 0;
        }
    }
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};

int main() {
    IOS;
    int l;
    cin >> l;
    int n = 20;
    int m = 0;
    vector<vector<edge>> path(n);
    for(int i=n-1;i>0;--i,l/=2){
        path[i-1].push_back(edge(i,0));
        m++;
        if(l>1){
            path[i-1].push_back(edge(i,l/2));
            m++;
            if(l%2==1){
                path[0].push_back(edge(i,l-1));
                m++;
            }
        }
        
    }
    put(n,m);
    REP(i,n){
        REP(j,path[i].size()){
            put(i+1,path[i][j].to+1,path[i][j].cost);
        }
    }
    return 0;
}


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


Measured memory_bytes: 2704