akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second>b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    string s;
    IN s;
    if(s=="ABC")
    {
        OUT "ARC";
    }
    else
    {
        OUT "ABC";
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>

int main()
{
	std::string weather {};
	std::cin >> weather;
	
	if (weather == "Sunny")
		std::cout << "Cloudy";
	else if (weather == "Cloudy")
		std::cout << "Rainy";
	else
		std::cout << "Sunny";
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAX INT_MAX
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define MOD 998244353
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
ll fastPowMod(ll a, ll p,ll mod){ if(p==0) return 1; ll z = fastPowMod(a,p/2,mod); z = (z*z)%mod; if(p%2) z = (z*a)%mod; return z; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}


void solve()
{
    int n,k;
    cin>>n>>k;
    vi h(n+1,0);
    srep(i,1,n) cin>>h[i];

    vi dp(n+1,INT_MAX);
    dp[0]=dp[1]=0;

    srep(i,2,n)
    {
        for(int j=i-1;j>=max(1,i-k);j--)
        {
            dp[i] = min(dp[i],dp[j]+abs(h[j]-h[i]));
        }
    }

    cout<<dp[n];

    
}

int main()
{
    fastio
    /*int t;
    cin>>t;
    
    rep(i,t)
    {*/
        solve();
        cout<<"\n";
    //}
    return 0;
}

Measured memory_bytes: 3924
<?php
fscanf(STDIN, "%d %d", $N, $K);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$cursor = 1;
$line = ['1'];
$visited = ['1' => 1];
$next = null;
$ans = null;
while(true) {
    $next = $A[$cursor - 1];
    if (isset($visited[$next])) {
        $pos = array_search($next, $line);
        $K -= $pos;
        $loop = count($line) - $pos;
        $ans = $line[$pos + $K % $loop];
        break;
    } else {
        $line[] = $next;
		$visited[$next] = 1;
    }
    if (count($line) === $K + 1) {
        $ans = $next;
        break;
    }
    $cursor = $next;
}
printf("%d", $ans);


Measured memory_bytes: 43008
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<LL,LL>
const int N=2e5+5;

LL n,d,p,ans;
pii a[N];
LL too[N];

int main()
{
	ios_base::sync_with_stdio(0);
	scanf("%lld%lld%lld",&n,&d,&p);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&a[i].first,&a[i].second);
	d<<=1;
	sort(a+1,a+n+1);
	for(int i=1,j=1;i<=n;i++)
	{
		too[i]+=too[i-1];
		a[i].second-=too[i];
		if(a[i].second<=0) continue;
		LL tt=(a[i].second+p-1)/p*p;
		ans+=(a[i].second+p-1)/p;
		while(a[i].first+d>=a[j].first && j<=n) j++;
		j--;
		too[i+1]+=tt;
		too[j+1]-=tt;
	}
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int len = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        
        sc.close();
        if(len%2!=0){
            System.out.println("No");
            return;
        }else{
            int half = len/2;
            for(int i=0;i+half<len;i++){
                if(s[i]!=s[i+half]){
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23124
#include<stdio.h>

long long int gcm(long long a,long long b){
	long long r,tmp;
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}


int main(){
	int N;
	scanf("%d",&N);
	long long T;
	long long ans=1;
	for(int i=0;i<N;i++){
		scanf("%lld",&T);
		ans=(ans/gcm(ans,T))*T;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>                                                                                                                                                      
int main (void){                                                                                                                                                        
    char s;                                                                                                                                                             
    scanf("%c",&s);                                                                                                                                                     
    if(s=='A'){                                                                                                                                                         
        printf("T\n");                                                                                                                                                  
    }else if(s=='T'){                                                                                                                                                   
        printf("A\n");                                                                                                                                                  
    }else if(s=='C'){                                                                                                                                                   
        printf("G\n");                                                                                                                                                  
    }else if(s=='G'){                                                                                                                                                   
        printf("C\n");                                                                                                                                                  
    }                                                                                                                                                                   
    return 0;                                                                                                                                                           
}        

Measured memory_bytes: 128
def main():
    H, W = map(int, input().split())
    state = [list(input()) for _ in range(H)]
    checked = [[False]*W for _ in range(H)]

    ans = 0
    for h in range(H):
        for w in range(W):
            if checked[h][w]:   continue
            q = [(h, w)]
            score = [0, 0]
            checked[h][w] = True
            c = 0
            while q:
                score[c%2] += len(q)
                qq = []
                for ph, pw in q:
                    nexts = []
                    if ph != 0: nexts.append((ph-1, pw))
                    if ph != H-1: nexts.append((ph+1, pw))
                    if pw != 0: nexts.append((ph, pw-1))
                    if pw != W-1: nexts.append((ph, pw+1))
                    for nh, nw in nexts:
                        if state[nh][nw] != state[ph][pw] and not checked[nh][nw]:
                            checked[nh][nw] = True
                            qq.append((nh, nw))
                c += 1
                q = qq
            ans += score[0]*score[1]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5748
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <sstream>

#define ll long long
#define Int ll
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

//     0 1 2 3 4 5
// ---------------
// 0 | 1 0 0 0 0 0
// 1 | 0 0 1 0 0 0
// 2 | 0 1 0 0 1 0
// 3 | 0 0 0 2 0 0
// 4 | 1 0 1 0 0 2
// 5 | 0 0 0 0 2 0
// 6 | 0 2 0 1 2 0

#define MAX_X 1000001
#define MOD 1000000007

Int X_, Y_;

void input() {
  cin >> X_ >> Y_;
}

// start = (0, 0) goal = (G.x, G.y)
// G.x + G.y = 0 mod 3
//
// (+1, +2) , (+2, +1)の移動回数をそれぞれn, mとすると、
// n +2m = X
// 2n + m = Y
// 2(X -2m) + m = Y, 2X - 3m = Y, m = (2X - Y)/3, n = (Y - m)/2
//
// m の範囲 0 <= m <= MAX_X/3

#define MAX_M MAX_X
Int fac[MAX_M], finv[MAX_M], inv[MAX_M];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_M; 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;
    }
}

Int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void solve() {
  COMinit();
  if ((X_ + Y_) % 3 != 0) {
    cout << 0 << endl;
    return;
  }

  Int m = (2 * X_ - Y_) / 3;
  Int n = (Y_ - m)/2;
  if (m < 0 || n < 0) {
    cout << 0 << endl;
    return;
  }

  cout << COM(m + n, n) << endl;
}

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


Measured memory_bytes: 23680
from collections import defaultdict
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
s = [0]*(n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]
dct = defaultdict(int)
for i in range(n+1):
    dct[s[i]%m] += 1
ans = 0
for v in dct.values():
    ans += v*(v-1)//2
print(ans)

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

void dfs(vector <int> adj[],bool vis[],int s,int &c)
{
    vis[s]=true;
    c++;
    for(int i=0;i<adj[s].size();i++)
    {
        if(not vis[adj[s][i]])
        {
            dfs(adj,vis,adj[s][i],c);
        }
    }
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n,m;
    cin>>n>>m;

    vector <int> adj[n+1];

    while(m--)
    {
        int a,b;
        cin>>a>>b;

        adj[a].pb(b);
        adj[b].pb(a);
    }

    int ans=0;
    bool vis[n+1]={false};
    loop(i,1,n+1)
    {
        if(not vis[i])
        {
            int c=0;
            dfs(adj,vis,i,c);

            ans=max(ans,c);
        }
    }

    cout<<ans;


    return 0;
}


Measured memory_bytes: 24184
h,w=map(int,input().split())
mod=10**9+7
G=[["#"]*(w+1) for i in range(h+1)]
for i in range(1,h+1):
  G[i]=["#"]+list(input())
A=[[0]*(w+1) for i in range(h+1)]
A[1][1]=1
for i in range(1,h+1):
  for j in range(1,w+1):
    if i==1 and j==1:
      continue
    if G[i][j]==".":
      A[i][j]=(A[i-1][j]+A[i][j-1])%mod
print(A[-1][-1])

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

int main(){
  int N;
  cin>>N;
  vector<int> W(N);
  for(int i=0; i<N; i++){
    cin>>W[i];
  }
  int ans=1e9;
  for(int i=0; i<N; i++){
    int sumb=0;
    int suma=0;
    for(int j=0; j<=i; j++){
      sumb+=W[j];
    }
    for(int k=i+1; k<N; k++){
      suma+=W[k];
    }
    ans=min(ans,abs(sumb-suma));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<iostream>

using namespace std;

int main()
{
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    while(A >= 0 || C >= 0){
        C -= B;
        if(C <= 0) break;
        A -= D; 
    }
    if(A <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void){
    int n, m, i, s[100], sum = 0, cnt = 0;
    scanf("%d %d", &n, &m);
    for( i = 0; i < n; i++){
        scanf("%d", &s[i]);
        sum = sum + s[i];
    }
    for( i = 0; i < n; i++){
       if( sum <= 4 * m * s[i] )
        cnt++;
    }
    if( cnt >= m )
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
first = 0;
second = 0;
third = 0;
for var in range(0,10):
	N = int(input())
	if (N>first):
		third = second
		second = first
		first = N
	elif (N>second):
		third = second
		second = N
	elif (N>third):
		third = N
print (first)
print (second)
print (third)


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
long long n,m,a[100005],b,c,sum;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>b;
		a[b]++;
		sum+=b;
	}
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>b>>c;
		sum=sum+a[b]*(c-b);
		a[c]+=a[b];
		a[b]=0;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 4372
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    if a[0] == 0:
        t = 2
        for i in range(2, n, 2):
            if a[i] != a[i-1] or a[i] != t:
                print(0)
                exit()
            t += 2
        print((2 ** ((len(a) - 1) // 2)) % (10 ** 9 + 7))
    else:
        t = 1
        for i in range(1, n, 2):
            if a[i] != a[i-1]:
                print(0)
                exit()
            t += 2
        print((2 ** (len(a) // 2)) % (10 ** 9 + 7))


if __name__ == '__main__':
    slove()


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

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

	int ans1 = 0,ans2=0;
	for(int i = 0; i < x; i++){
		ans1 += a[i];
	}
	for(int i = x+1; i <= n; i++){
		ans2 += a[i];
	}
	cout << (ans1 < ans2 ? ans1 : ans2) << "\n";

	return 0;
}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<usize>()[0];

    println!("{}", n*(n-1)/2);
}


Measured memory_bytes: 4352
while True:
    H,W = map(int, input().split())
    
    if H == 0 and W == 0:
        break
    
    for h in range(H):
        hmod = h % 2
        for w in range(W):
            wmod = w % 2
            hw = hmod + wmod
            if hw == 0 or hw == 2 :
                print("#",end="")
            else:
                print(".",end="")
        print("")
    print("")


Measured memory_bytes: 7016
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define NEWMAT(N, M, ini) MAT(N, vector<lint>(M, ini))
#define MOD 1000000007

typedef long long lint;
typedef pair<lint, lint> P;
typedef vector<lint> V;
typedef vector<vector<lint>> MAT;
bool lessPair(const P& l, const P& r){return l.second < r.second;}

lint getgcd(lint n, lint m)
{
  lint r;
  if (n > m) {
    lint t = m;
    m = n;
    n = t;
  }
  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }
  return n;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;

    V X(N);
    REP(i, N) {
      lint x; cin >> x; X[i] = x;
    }

    lint l = getgcd(X[0], X[1]);
    FOR(i, 2, N) {
      l = getgcd(l, X[i]);
    }

    cout << l << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> e(n+1);

    for(int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    vector<int> d(n+1);
    using P = pair<int, int>;

    queue<P> que;
    // black Fennec -1, white Snuke 1
    que.push(P(1, -1));
    que.push(P(n, 1));

    while(!que.empty())
    {
        P p = que.front();
        que.pop();
        int a = p.first;
        int b = p.second;
        for(int i = 0; i < e[a].size(); i++)
        {
            int next = e[a][i];
            if(d[next] == 0)
            {
                d[next] = b;
                que.push(P(next, b));
            }
        }
    }
    int f = 0, s = 0;
    for(int i = 1; i <= n; i++)
    {
        if(d[i] == -1) f++;
        else s++;
    }
    if(f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    ll ans=1e9;
    if(b-a>2020){
        cout << 0<<endl;
        return 0;
    }
    ll c=b-a;

    a%=2019;
    b=c+a;
    for(ll i=a;i<=b;i++){
        for(ll j=i+1;j<=b;j++){
            ans=min(ans,(i*j)%2019);
        }
    }
    cout << ans<<endl;


    return 0;
}




Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var r, c uint8
	fmt.Scanln(&r, &c)
	sheet := make([][]uint32, r+1)
	for i := uint8(0); i < r+1; i++ {
		sheet[i] = make([]uint32, c+1)
	}
	for i := uint8(0); i < r; i++ {
		for j := uint8(0); j < c; j++ {
			fmt.Scan(&sheet[i][j])
		}
	}
	var rttl, cttl uint32
	for i := uint8(0); i < r; i++ {
		for j := uint8(0); j < c; j++ {
			sheet[i][c] += sheet[i][j]
		}
		rttl += sheet[i][c]
	}
	for i := uint8(0); i < c; i++ {
		for j := uint8(0); j < r; j++ {
			sheet[r][i] += sheet[j][i]
		}
		cttl += sheet[r][i]
	}
	sheet[r][c] = (cttl + rttl) / 2
	for i := uint8(0); i <= r; i++ {
		for j := uint8(0); j <= c; j++ {
			if j == c {
				fmt.Printf("%d", sheet[i][j])
			} else {
				fmt.Printf("%d ", sheet[i][j])
			}
		}
		fmt.Printf("\n")
	}
	return
}



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

int main() {
	int n,max=0,map[101]={0};
	while (scanf("%d",&n) != EOF)
	{
		map[n]++;
		if (max < map[n])max=map[n];
	}
	for (int i=1; i<101; i++)
	{
		if (map[i]==max)cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 0
def main():
    N = int(input())
    S = []
    for i in range(N):
        line = [a for a in input().split()]
        line[1] = int(line[1])
        S.append([i+1] + line)
    tmp = sorted(S, key=lambda x:x[2], reverse=True)
    ans = sorted(tmp, key=lambda x:x[1])
    for i in range(len(ans)):
        print(ans[i][0])

main()


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  ll n;cin>>n;
  ll a[n+10];
  ll n4=0,n2=0;
  rep(i,0,n){
    cin>>a[i];
    if(a[i]%4==0)n4++;
    else if(a[i]%2==0)n2++;
  }

  if(n-(n4+n2)<=n4)out("Yes");
  else if(n-(n4+n2)==n4+1){
    if(n2==0)out("Yes");
    else out("No");
  }
  else out("No");

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] line = scanner.nextLine().split("");
    
    int curr = Integer.parseInt(line[0]);
    int change = 0;
    for(int i = 1; i < line.length; i++) {
      if (curr == Integer.parseInt(line[i])) {
        curr = Integer.parseInt(line[i]) == 0 ? 1 : 0;
        change++;
      }
      else {
        curr = Integer.parseInt(line[i]);
      }
    }
    System.out.println(change);
  }
}

Measured memory_bytes: 32716
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  vector<int> vec={a,b,c,d,e};
  int n=0;
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      if(abs(vec.at(i)-vec.at(j))>k){
        break;
      }else{
        n++;
      }
    }
  }
  if(n==25){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
typedef long int li;

int main(){
  int n,g,lim; cin >>n >>g;
  lim=1<<n;
  int ans=0;
  vector<int> p(n),c(n),full(n);
  rep(i,n){
    cin >>p[i] >>c[i];
    ans+=p[i];
    full[i]=(i+1)*p[i]*100+c[i];
  }
  if(df){
    for(auto x:full) cout << x << " ";
    cout << "\n";
  }
  
  auto f=
    [&](int a,int bs){
      if(df)printf("(%d,%d)\n",a,bs);
      li gain=0;
      int cnt=0;
      rep(i,n){
        if(bs%2 and a!=i){
          gain+=full[i];
          cnt+=p[i];
          if(df)printf("%d ",i+1);
        } 
        bs/=2;
      }
      if(df)printf("\n");
      if(gain>=g)return cnt;
      if(gain+full[a]<g) {
        if(df)printf("impossible\n");
        return ans;
      }
      if(gain+(a+1)*p[a]*100<=g){
        if(df)printf("all\n");
        return cnt+p[a];
      } 
      if(df)printf("[%d]",(g-gain+(a+1)*100-1)/((a+1)*100));
      return cnt+(int)(g-gain+(a+1)*100-1)/((a+1)*100);
    };

  rep(i,n)
    rep(bs,lim){
    int ret=f(i,bs);
    if(ans>ret) ans=ret;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
double ans;
double func(double d, int n){
	//printf("%f\n", d);
	ans += d;
	if(n == 11)return d;
	if(n % 2)return func(d/3.0, n+1);
	return func(2.0*d, n+1);
}

int main(){
	double d;
	while(scanf("%lf", &d) != EOF){
		ans = 0;func(d, 2);
		printf("%f\n", ans);
	}
	return 0;
}

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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

int main() {
	int x = read(), a = read();
	if (x < a) puts("0");
	else puts("10");
	return 0;
}

Measured memory_bytes: 384
N,*A=map(int,open(0).read().split());M=max(A);m=min(A);s=range(1,N+1);p=print;p(2*N-1);v,d=-m<M and(M,1)or(m,-1);r=s[::d]
for i in s:p(A.index(v)+1,i)
for z in zip(r,r[1:]):p(*z)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int num = 1;
    int N,K;
    cin >> N >> K;
    rep(i,N){
        if (num >= K){
            num += K;
        }
        else{
            num *= 2;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	unsigned long int s[300000];
	unsigned long long int n,x=0,max=0;
	cin>>n;
	cin>>s[0];
	max=s[0];
	for(int i=1;i<n;i++)
	{
		cin>>s[i];
		if(max>s[i])
			x+=max-s[i];
		else
			max=s[i];
	}
	cout<<x;
	return 0;
}

Measured memory_bytes: 5108
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    string S; cin >> S;
    vector<int>A(26);
    rep(i, S.size()) {
        A[S.at(i) - 97]++;
    }
    if (S.size() != 26) {
        cout << S;
        rep(i, 26) {
            if (A[i] == 0) {
                cout << char(i + 97) << endl; return 0;
            }
        }
    }
    REV(i,26) {
        if (S.at(i) < S.at(i - 1)){A[S.at(i)-97]--;continue;}
        for(int j=i;j>=0;j--){
          A[S.at(j)-97]--;
          for(int k=S.at(j)+1;k<123;k++){
            if(A[k-97]==0){
              for(int l=0;l<j;l++)cout<<S.at(l);
              cout << char(k) << endl;
              return 0;
            }
          }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3580
fun main(args: Array<String>) {
    val N = nextInt()
    val D = listOfInt()
    var ans = 0
    for (i in 0 until N-1) {
        for (j in i+1 until N) {
            ans += D[i] * D[j]
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 37872
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#define eps 1e-10
using namespace std;
const int maxn = 2e5 + 10;

struct Point{
    double x,y;
    Point(double x = 0, double y = 0) : x(x),y(y){}

};

typedef Point Vector;

Vector operator + (Vector A, Vector B){return Vector(A.x + B.x, A.y + B.y);}
Vector operator - (Vector A, Vector B){return Vector(A.x - B.x, A.y - B.y);}
Vector operator * (Vector A, double p){return Vector(A.x*p, A.y*p);}
Vector operator / (Vector A, double p){return Vector(A.x/p, A.y/p);}
bool operator < (const Point& A, const Point& B){return A.x < B.x || (A.x == B.x && A.y < B.y);}

int dcmp(double x){
    if(fabs(x) < eps) return 0;
    return x < 0 ? -1 : 1;
}

bool operator == (const Point& A, const Point& B){return dcmp(A.x-B.x) == 0 && dcmp(A.y-B.y) == 0;}

double Dot(Vector A, Vector B){return A.x*B.x + A.y*B.y;}
double Length(Vector A){return sqrt(Dot(A,A));}
double Angle(Vector A, Vector B){return acos(Dot(A,B)) / Length(A) / Length(B);}
double Cross(Vector A, Vector B){return A.x*B.y - A.y*B.x;}
double Area2(Point A, Point B, Point C){return Cross(B-A,C-A);}
// 向量所在象限(点积符号,叉积符号)
Vector Rotate(Vector A, double rad){return Vector(A.x * cos(rad) - A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));}

Point ps[maxn];

vector<Point> convex_hull(Point * ps, int n)
{
   vector<Point> hull(n * 2);
   int tp = 0;
   for(int i = 0;i < n;++i){
      while(tp > 1 && dcmp(Cross(hull[tp-1] - hull[tp-2],ps[i] - hull[tp-1])) <= 0)tp--;
      hull[tp++] = ps[i];
   }
   for(int i = n-2,t = tp;i >= 0;--i){
      while(tp > t && dcmp(Cross(hull[tp-1] - hull[tp-2],ps[i] - hull[tp-1])) <= 0) tp--;
      hull[tp++] = ps[i];
   }
   hull.resize(tp-1);
   return hull;
}

long long dist(Point p)
{
   return abs(p.x) + abs(p.y);
}

int main()
{
   int n;
   cin>>n;
   for(int i = 0;i < n;++i){
      cin>>ps[i].x>>ps[i].y;
   }
   sort(ps,ps+n);
   
   vector<Point> H = convex_hull(ps,n);
   int cnt = H.size();
   if(cnt == 2){
      printf("%lld\n",dist(H[0] - H[1]));
      return 0;
   }
   int i = 0,j = 0;
   for(int k = 0;k < cnt;++k){
      if(dcmp(H[i].x - H[k].x) > 0) i = k;
      if(dcmp(H[j].x - H[k].x) < 0) j = k; 
   }
   long long res = 0;
   int si = i,sj = j;
   while(i != sj && j != si){
      res = max(res,dist(H[j] - H[i]));
      if(dcmp(Cross(H[(i+1) % cnt] - H[i], H[(j+1) % cnt] - H[j]) < 0)){
         i = (i + 1) % cnt;
      }
      else j = (j + 1) % cnt;
   }
   printf("%lld\n",res);
   return 0;
}

Measured memory_bytes: 12808
(* 素集合データ構造 *)
module UnionFind : sig
  type t

  module Class : sig
    type t
    val to_int : t -> int
    val compare : t -> t -> int
  end

  (* n要素の素集合データ構造を作る *)
  val make : int -> t
  (* 要素がどの集合に属するか調べる *)
  (* 要素は0からn-1の整数である必要がある *)
  val find : t -> int -> Class.t
  (* 与えられた要素が属する集合同士を合併する *)
  val unite : t -> int -> int -> unit
end = struct
  type t = { rank : int array; parent : int array }

  module Class = struct
    type t = int
    let to_int c = c
    let compare = compare
  end

  let make n =
    { rank = Array.make n 0;
      parent = Array.init n @@ fun c -> c }

  let rec find uf x =
    if x = uf.parent.(x) then x
    else begin
      let y = find uf uf.parent.(x) in
      uf.parent.(x) <- y; y
    end

  let unite uf i j =
    let x = find uf i in
    let y = find uf j in
    if x <> y then begin
      if uf.rank.(x) < uf.rank.(y) then uf.parent.(x) <- y
      else begin
        uf.parent.(y) <- x;
        if uf.rank.(x) = uf.rank.(y) then
          uf.rank.(x) <- 1 + uf.rank.(x)
      end
    end
end


let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let abs = Array.init m @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun a b -> a, b in
  let uf = UnionFind.make n in
  let cnt = Array.make n 1 in
  let ans = Array.make (m + 1) 0 in
  for i = m - 1 downto 0 do
    let ca = UnionFind.find uf (fst abs.(i) - 1) in
    let cb = UnionFind.find uf (snd abs.(i) - 1) in
    if UnionFind.Class.compare ca cb = 0
    then ans.(i) <- ans.(i + 1)
    else begin
      let cnta = cnt.(UnionFind.Class.to_int ca) in
      let cntb = cnt.(UnionFind.Class.to_int cb) in
      ans.(i) <- ans.(i + 1) + cnta * cntb;
      cnt.(UnionFind.Class.to_int ca) <- cnta + cntb;
      cnt.(UnionFind.Class.to_int cb) <- cnta + cntb;
      UnionFind.unite uf (fst abs.(i) - 1) (snd abs.(i) - 1)
    end
  done;
  for i = 1 to m do
    Printf.printf "%d\n" @@ n * (n - 1) / 2 - ans.(i)
  done



Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

int n, a, b;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> a >> b;
    cout << min(b, n*a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

vector<int> inv, fac, finv;

inline ll binomial(int a, int b) {
    return ((ll)fac[a] * finv[b] % MOD) * finv[a - b] % MOD;
}

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

    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    int siz = r2 + c2 + 10;
    inv.resize(siz), fac.resize(siz), finv.resize(siz);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < siz; ++i) {
        inv[i] = MOD - (ll)(MOD / i) * inv[MOD % i] % MOD;
        fac[i] = (ll)fac[i - 1] * i % MOD;
        finv[i] = (ll)finv[i - 1] * inv[i] % MOD;
    }

    int ans = (binomial(r2 + c2 + 2, r2 + 1) - binomial(r2 + c1 + 1, c1) - binomial(r1 + c2 + 1, r1) + binomial(r1 + c1, r1)) % MOD;
    cout << (ans < 0 ? MOD + ans : ans) << endl;

    return 0;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int A, B, H; cin >> A >> B >> H;
  auto ans = (A+B) * H / 2;
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main(){
	int x, y;
	cin >> x >> y;
	for (int i = 2 * x; i <= 4 * x; i += 2){
		if(i == y){
			puts("Yes");
			return 0;
		}
	}
	puts("No");

	return 0;
}

Measured memory_bytes: 3608
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] hList = new int[n];
    boolean[] jList = new boolean[n]; 
    
    for (int i = 0; i < n; i++){
      hList[i] = sc.nextInt();
    }
    
    int ans = 0;
    
    for (int i = 0; i < m; i++){
      int s = sc.nextInt();
      int g = sc.nextInt();
      if (hList[s-1]>hList[g-1]){
        jList[g-1] = true;
      } else if (hList[s-1]<hList[g-1]){
        jList[s-1] = true;
      } else {
        jList[g-1] = true;
        jList[s-1] = true;
      }
    }
    
    for (int i = 0; i < n; i++){
      if(!(jList[i])){
        ans++;
      }
    }
                 
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 59428
#20　AtCoder Beginner Contest 077 C - Snuke Festival
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
c.sort()
ans = 0
for i in b:
    ans+= (bisect.bisect_right(a, i-1))*(n-bisect.bisect_left(c, i+1))
print(ans)

Measured memory_bytes: 23232
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS
//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.flush();
 	int d;
    cin >> d;
    int ans;
    if(d%2!=0)
    {
      ans = (d+1)/2;
    }
    else
    {
      ans = d/2;
    }
  	cout<< (float)ans/d;    
    return 0;
    // Bye Bye 2019
}



Measured memory_bytes: 256
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    deque<ll> q;
    for(ll i = 0; i < n; i++){
        ll buf; cin >> buf;
        if(i % 2 == 0) q.push_back(buf);
        else q.push_front(buf);
    }
    if(n % 2 == 0){
        for(ll i = 0; i < n; i++) cout << q[i] << " ";
    }
    else{
        for(ll i = n - 1; i >= 0; i--) cout << q[i] << " ";
    }  
    cout << endl;
    return 0;
}


Measured memory_bytes: 3840
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

#include "bits/stdc++.h"
using namespace std;

#define ll long long
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[N];

void solve()
{    
    ll n, m ,W;
    cin >> n >> W ;
    vector<pair<int, int>> item(n) ;
    for(int i=0; i<n; i++) {
    	cin>>item[i].first >> item[i].second ;
    } 
    sort(item.begin(), item.end()) ;

    vector<vector<long long int>> dp(n,vector<long long int>(W+1,0)) ;
    for(int i=item[0].first; i<=W; i++){
    	dp[0][i] = item[0].second ;	
    }
    for(int i=1; i<n; i++) {
    	for(int j=1; j<=W; j++) {
    		dp[i][j] = max(dp[i][j-1] , dp[i-1][j] ) ;
    		if(j>=item[i].first){
    			dp[i][j] = max({ dp[i][j], dp[i-1][j-item[i].first]+item[i].second});
    			
    		//cout<<i<<j<<" " <<dp[i][j]<<"    "<<dp[i-1][j-item[i].first]<<"."<<item[i].second<<"..";
    		}

    		//cout<<i<<j<<" " <<dp[i][j]<<"\n";

    	}
    }
    cout<< dp[n-1][W] ;

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}


// Xorawar

Measured memory_bytes: 82364
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N, K = I()
a = []
for i in range(N):
    x = k()
    a.append(x)

a.sort()

print(min(a[i+K-1]-a[i] for i in range(N-K+1)))


Measured memory_bytes: 14256
#include <iostream>
using namespace std;
 
int main () {
  int A,B,K;
  cin>>A>>B>>K;
  
  int minNum = A > B ? B : A;
  
  int count = 1;
  for(int d= minNum; d > 0; d--) {
  	if(A%d==0 && B%d == 0) {
      if(count == K) {
      	cout << d;
        break;
      }
      count++;
    }
  }
  
  return 0;
}

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

const int INF = 10000;
int n, A, B, C;
vector<int> l(n);

int min_MP(int i, int a, int b, int c){// distributed l[0], ..., l[i-1]
    // terminal case
    if(i == n){
        if(a != 0 && b != 0 && c != 0) return abs(a-A) + abs(b-B) + abs(c-C);
        else return INF;
    }

    int rec = min_MP(i+1, a, b, c);
    if(rec > min_MP(i+1, a+l[i], b     , c     ) + (a != 0 ? 10 : 0)) rec = min_MP(i+1, a+l[i], b     , c     ) + (a != 0 ? 10 : 0);
    if(rec > min_MP(i+1, a     , b+l[i], c     ) + (b != 0 ? 10 : 0)) rec = min_MP(i+1, a     , b+l[i], c     ) + (b != 0 ? 10 : 0);
    if(rec > min_MP(i+1, a     , b     , c+l[i]) + (c != 0 ? 10 : 0)) rec = min_MP(i+1, a     , b     , c+l[i]) + (c != 0 ? 10 : 0);
    return rec;// minimum MP for distributing l[i]
}

int main(){
    cin >> n >> A >> B >> C;
    l.resize(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }

    cout << min_MP(0,0,0,0) << endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int k;
ll a[120000];

int main() {
	cin >> k;
	for (int i = 0; i < k; ++i)
		cin >> a[i];
	ll l = 2;
	ll r = 2;
	for (int i = k - 1; i >= 0; --i) {
		ll l2 = (l + a[i] - 1) / a[i];
		ll r2 = r / a[i];
		l2 *= a[i];
		r2 *= a[i];
		if (l2 > r2) {
			cout << -1 << "\n";
			return 0;
		}
		r2 += a[i] - 1;
		l = l2, r = r2;
	}
	cout << l << " " << r << "\n";
	return 0;
}




Measured memory_bytes: 1024
program test
implicit none

integer(8) :: n,k,a(200000),max_a,bits(50)=0,bits_max = 1,ans2(0:50),ruijyou(0:50),base,ans
integer :: i,j

read(*,*) n,k
read(*,*) (a(i),i=1,n)


!2の累乗を計算
ruijyou(0) = 1
do i=1,50
	ruijyou(i) = ruijyou(i-1) * 2
enddo

!bits(i)      下からi桁目のビットが1である数の個数
!(n-bits(i))  下からi桁目のビットが0である数の個数
do i=0,49
	do j=1,n
		if(BTEST(a(j),i)) then
			bits_max = i+1
			bits(i+1) = bits(i+1) + 1
		endif
	enddo
enddo

!K=0のときの値
base = 0
do i=1,50
	base = base + bits(i)*ruijyou(i-1)
enddo

!i桁までの数で、K=0との最大値の差分を計算
ans2(0) = 0
do i=1,50
	ans2(i)= ans2(i-1) + max(0,(n-bits(i))-bits(i))*ruijyou(i-1)
enddo

!まず、K=kのときの値を計算
ans = ans_fixed(k,1,50)

!次に、下から2桁目以上で、Kのi桁目が1の場合、
!(i-1桁目までの最大値) + (i+1以降の桁をfixした場合)を計算
do i=2,50
	if(BTEST(k,i-1))then
		ans = max(ans,ans_fixed(k,i+1,50)+ans2(i-1))
	endif
enddo

write(*,*) base+ans

contains

function ans_fixed(x,j_s,j_e) result(tmp)
	implicit none
	integer(8):: x,tmp
	integer :: j_s,j_e
	
	tmp = 0
	
	do j=j_s,j_e
		if(BTEST(x,j-1))then
			tmp = tmp + ((n-bits(j))-bits(j)) * ruijyou(j-1)
		else
			tmp = tmp
		endif
	enddo
	
	return
	
end function

end program


Measured memory_bytes: 1536