akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

double pi = 3.1415926535897932384;

int main() {
    int N;
    cin >> N;
    vector<double> X(N), Y(N);
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
    for (int i = 0; i < N; i++) {
        double a, b=-100, c;
        for (int j = 0; j < N; j++) {
            if (i==j) continue;
            double ang = atan2(Y[j]-Y[i], X[j]-X[i]);
            if (b < -10) {
                a = ang;
                b = ang;
                c = ang;
            }else{
                if (ang < b-pi) ang += 2.0*pi;
                else if (ang > b+pi) ang -= 2.0*pi; 
                a = min(a, ang);
                c = max(c, ang);
            }
        }
        if (c - a > pi) printf("0\n");
        else printf("%.10lf\n", (pi-c+a)/(2.0*pi));
    }
    return 0;
}


Measured memory_bytes: 384
import sys

N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        flag=1
        for k in range(M):
            for l in range(M):
                if B[k][l]!=A[i+k][j+l]:
                    flag=0
                    break

            if flag==0:
                break

        else:
            print("Yes")
            sys.exit()


else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n,a[102];
int main()
{
	int i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]%2==0&&(a[i]%3!=0&&a[i]%5!=0))
		{
			cout<<"DENIED";
			return 0;
		}
	}
	cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin >> arr[i];
  sort(arr,arr+n);
  int ans = arr[n-1]-arr[0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
	string s;
  cin >> s;
  vector<int> v(2,0);
  
  for(int i = 0; i < 3; i++){
    if(s[i] == 'A'){
      v[0]++;
    }
    else
      v[1]++;
  }
	if(v[0] == 3 || v[1] == 3)
      cout << "No" <<endl;
     else
       cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(d + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        last[t[i]] = i;

        for (int j = 1; j <= 26; j++)
        {
            ans -= c[j] * (i - last[j]);
        }
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

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

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    // printf("%lld\n", scoring(BestT));

    double BestScore = scoring(BestT);

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1);

    double T0 = 1e6;
    double T1 = 1e3;
    double TL = 1950;

    ll count = 0;

    while (1)
    {
        auto end = chrono::system_clock::now(); // 計測終了時刻を保存
        auto dur = end - start;                 // 要した時間を計算
        auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();

        if (msec >= TL)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        double score = scoring(t);

        if (exp((score - BestScore) / T) > 0.5)
        {
            BestT = t;
            BestScore = score;
        }
    }

    for (int i = 1; i <= d; i++)
    {
        printf("%d\n", BestT[i]);
    }

    // printf("%lld\n", scoring(BestT));
}


Measured memory_bytes: 4324
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    X, Y = map(int, readline().split())
    for x in range(X+1):
        for y in range(Y+1):
            if x*2 + y*4 == Y and x + y ==X:
                print('Yes')
                return
    print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
listS=list(input())
listT=list(input())
alphaL =  [chr(i) for i in range(97,97+26)]
listS.sort()
listT.sort()
listT.reverse()

if alphaL.index(listS[0]) < alphaL.index(listT[0]):
    print("Yes")
else:
    if len(listS) < len(listT):
        listS.reverse()
        index=0
        while index < len(listS):
            if listS[index]!=listT[index]:
                print("No")
                break
            else:
                index+=1
        if index == len(listS):
            print("Yes")
    else:
        print("No")

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

#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>

const ll mod=1e9+7;

void solve()
{
    int n;
    sfi(n)

    ll freq[100005];
    memset(freq,0,sizeof(freq));

    int arr[n];

    ll sum=0;

    f(i,0,n)
    {
    	sfi(arr[i])
    	freq[arr[i]]++;
    	sum+=arr[i];
    }

    int q;
    sfi(q)

    while(q--)
    {
    	int a,b;
    	sfi(a)
    	sfi(b)

    	ll temp1=a*freq[a];
    	ll temp2=b*freq[a];

    	freq[b]+=freq[a];

    	freq[a]=0;

    	sum=sum-temp1+temp2;

    	pfln(sum)
    }

    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    solve();
    
    return 0;
}

Measured memory_bytes: 4980
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          Array.Sort(a);
          
          Console.WriteLine(a[2]-a[0]);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
MAX_NUM = 2 * (10**5)+ 10
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

n, k = map(int, input().split())

sum = 1
t = 1
for i in range(min(n, k)):
  t = ((t * (n-i)) % MOD * (n-i-1)) % MOD
  t = ((t * inv[i+1]) % MOD * inv[i+1]) % MOD
  sum = (sum + t) % MOD

print(sum)


Measured memory_bytes: 56504
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int n,k,y,x;

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>k>>x>>y;
	if(n<k)cout<<n*x<<endl;
	else cout<<k*x+(n-k)*y<<endl;
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 5;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	vector<int> dp(n,INF);
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++){
		if(i-k<=0){
			dp[i]=abs(v[i]-v[0]);}
		else{
			for(int j=1;j<=k;j++){
				//if(j==2)  cout<<dp[i-j]+abs(v[i]-v[i-j])<<endl;
				dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
					//cout<<dp[i]<<"  "<<j<<endl;
					}
			}
		}
		//for(int x: dp)
			//cout<<x<<"\t";
		cout<<dp[n-1]<<endl;
		


}

Measured memory_bytes: 1024
//
// Created by watemus on 01.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    int n;
    cin >> n;
    unordered_set<string> st;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << '\n';
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

Measured memory_bytes: 17752
from math import gcd 
a, b, c, d = map(int, input().split())
n = b-a+1

def lcm(a, b):
    return a * b // gcd(a, b)

def cal(x, a, b):
    cnt = b//x - a//x
    if a%x == 0:
        cnt += 1
    return cnt

ans = cal(c, a, b)
ans += cal(d, a, b)
ans -= cal(lcm(c, d), a, b)
print(n - ans)


Measured memory_bytes: 8760
module Main where

import Data.Functor
import Data.Maybe

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { fs@[t,s,e,w,n,b] <- getInts
  ; [q] <- getInts
  ; let iftab = zip [1..] fs
  ; let fitab = zip fs [1..]
  ; loop q iftab fitab  
  }

loop :: Int -> [(Int,Int)] -> [(Int,Int)] -> IO ()
loop 0 _  _   = done
loop m iftab fitab = do
  { [t,s] <- getInts
  ; let x = maybe undefined id (lookup t fitab)
  ; let y = maybe undefined id (lookup s fitab)
  ; let z = maybe undefined id (lookup (east (x,y)) iftab)
  ; print z >> loop (m-1) iftab fitab
  }

done :: IO ()
done = return ()

east (1,2) = 3
east (1,3) = 5
east (1,4) = 2
east (1,5) = 4
east (2,1) = 4
east (2,3) = 1
east (2,4) = 6
east (2,6) = 3
east (3,1) = 2
east (3,2) = 6
east (3,5) = 1
east (3,6) = 5
east (4,1) = 5
east (4,2) = 1
east (4,5) = 6
east (4,6) = 2
east (5,1) = 3
east (5,3) = 6
east (5,4) = 1
east (5,6) = 4
east (6,2) = 4
east (6,3) = 2
east (6,4) = 5
east (6,5) = 3

Measured memory_bytes: 3960
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ull a,b,memo_a,memo,memo_b,ans_a = 1,ans_b = 1,n,x = 1;
	cin >> n;
	
	rep(i,0,n){
		cin >> a >> b;
		
			memo_a = (ans_a % a == 0)?ans_a/a:(ans_a/a)+1;
			memo_b = (ans_b%b == 0)?ans_b/b:(ans_b/b)+1;
			memo = max(memo_a,memo_b);
			
			ans_a = memo*a;
			ans_b = memo*b;
	}
	
	
	cout << ans_a+ans_b << endl;
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
"""
  1
4 2 3 5
  6
  
"""

class Dice:
    def __init__(self, top, front, right, left, rear, bottom):
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.rear = rear
        self.bottom = bottom

    def N(self):
        self.tmp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.rear
        self.rear = self.tmp

    def E(self):
        self.tmp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = self.tmp

    def S(self):
        self.tmp = self.top
        self.top = self.rear
        self.rear = self.bottom
        self.bottom = self.front
        self.front = self.tmp

    def W(self):
        self.tmp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = self.tmp

    def show_numbers(self):
        print("上：%d"% self.top)
        print("前：%d"% self.front)
        print("右：%d"% self.right)
        print("左：%d"% self.left)
        print("後：%d"% self.rear)
        print("底：%d"% self.bottom)

    def show_top(self):
        print("%d" % self.top)


# ここからプログラム
buf = input().split(" ")
dice1 = Dice(int(buf[0]), int(buf[1]), int(buf[2]), int(buf[3]), int(buf[4]), int(buf[5]))

buf = input()
for ch in buf:
    if ch == "N":
        dice1.N()
    elif ch == "E":
        dice1.E()
    elif ch == "S":
        dice1.S()
    elif ch == "W":
        dice1.W()

dice1.show_top()



Measured memory_bytes: 5620
h, w = map(int, input().split())
a = list(str(input()) for i in range(h))
s =[]
for j in range(w+2):
    s.append("#")
print(*s, sep="")
p = []
for k in range(h):
    p.append("#")
    p.append(a[k])
    p.append("#")
    print(*p, sep="")
    del p[:]
print(*s, sep="")

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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  vector<int>x={A,B,C};
  for(int i=0;i<1000000;i++){
    if(x.at(0)%2==1||x.at(1)%2==1||x.at(2)%2==1){
      cout<<i<< endl;
      return 0;
    }
    int a=x.at(0);
    int b=x.at(1);
    int c=x.at(2);
    x.at(0)=b/2+c/2;
    x.at(1)=a/2+c/2;
    x.at(2)=a/2+b/2;
  }
  cout<<"-1"<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll c[30],s[400][30],las[30],t[400];

int main()
{
	int D;
	cin >> D;
	rep(i,26)
	{
		cin >> c[i];
	}
	rep(i,D)
	{
		rep(j,26)
		{
			cin >> s[i][j];
		}
	}
	rep(i,D)
	{
		t[i] = 26 - (i%26);
	}

	ll tmp = 0;
	rep(j,D)
	{
		tmp += s[j][t[j]];
		las[t[j]] = j+1;
		rep(k,26)
		{
			tmp -= c[k] * (j+1 - las[k]);
		}
	}

	rep(i,100000)
	{
		ll r = rand() % (D-1);
		swap(t[r],t[r+1]);
		ll tmp2 = 0;
		rep(j,30)
		{
			las[j] = 0;
		}
		rep(j,D)
		{
			tmp += s[j][t[j]];
			las[t[j]] = j+1;
			rep(k,26)
			{
				tmp2 -= c[k] * (j+1 - las[k]);
			}
		}
		if (tmp2 > tmp)
		{
			tmp = tmp2;
		}
		else swap(t[r],t[r+1]);
	}
	rep(i,D)
	{
		cout << t[i] << endl;
	}
	return 0;
}

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int a, b, ans = 0;
	cin >> a >> b;
	ans = a + b;
	if(ans%2==1)
		cout << "IMPOSSIBLE" << "\n";
	else 
		cout << ans/2 << "\n";
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string a,b,c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys


def solve(K: int, A: int, B: int):
    for i in range(K, B + 1, K):
        if A <= i <= B:
            return True
    return False


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int

    if solve(K, A, B):
        print('OK')
    else:
        print('NG')


if __name__ == '__main__':
    main()


Measured memory_bytes: 62044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,e)for(int i=0;i<e;i++)
using namespace std;

void partion(){
    rep(i,20) cout << "#";
    cout << endl;
}

int main(){
    int n, i, j, k;
    int b, f, r, v;
    int F[4][3][10];
    rep(i,4){
        rep(j,3){
            rep(k,10) F[i][j][k]=0;
        }
    }
    cin >> n;
    rep(i,n){
        cin >> b >> f >> r >> v;
        F[b-1][f-1][r-1]+=v;
    }
    rep(i,4){
        rep(j,3){
            rep(k,10) cout << " " << F[i][j][k];
            cout << endl;
        }
        if(i!=3) partion();
    }
    return 0;
}


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Comparing Strings
            var line = ReadLine();
            int a = line[0];
            int b = line[1];

            var words = new List<string>();
            words.Add(GetWord(a, b));
            words.Add(GetWord(b, a));

            var ans = words.OrderBy(x => x).First();
            Console.WriteLine(ans);
        }

        static string GetWord(int a, int b)
        {
            var s = "";

            for(int i = 0; i < b; i++)
            {
                s += a;
            }

            return s;
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPre
{
    class Program
    {
        static void Main(string[] args)
        {
            var H = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            if((H[0]+H[1])%2 == 1)
            {
                Console.WriteLine("IMPOSSIBLE");
            }
            else
            {
                Console.WriteLine((H[0] + H[1])/2);
            }

        }

    }
}



Measured memory_bytes: 13140
import sys
readline = sys.stdin.readline

S = list(map(ord, readline().strip()))
N = len(S)
S = [None] + S + [None]
K = int(readline())

if N == 1:
    ans = 1
elif N == 2:
    ans = 1
    if S[1] == S[2]:
        ans = 2
    if K:
        ans = 2
else:
    dp1 = [[0]*(K+1) for _ in range(N+2)]
    dp2 = [[0]*(K+1) for _ in range(N+2)]
    for i in range(1, N+1):
        dp1[i][0] = 1
    for i in range(1, N):
        dp2[i][0] = 1
        if S[i] == S[i+1]:
            dp2[i][0] = 2    
        elif K:    
            dp2[i][1] = 2
    for s in range(3, N+1):
        dp3 = [[0]*(K+1) for _ in range(N+2)]
        for i in range(1, N-s+2):
            j = i+s-1    
            if S[i] == S[j]:
                for k in range(K+1):
                    dp3[i][k] = max(dp2[i+1][k], dp2[i][k], 2+dp1[i+1][k])
            else:
                dp3[i][0] = max(dp2[i+1][0], dp2[i][0], dp2[i+1][0])
                for k in range(1, K+1):
                    dp3[i][k] = max(dp2[i+1][k], dp2[i][k], dp1[i+1][k], 2+dp1[i+1][k-1])
        '''
        dp1 = [k[:] for k in dp2]
        dp2 = [k[:] for k in dp3]
        '''
        dp1 = dp2[:]
        dp2 = dp3[:]
    ans = max(dp3[1][k] for k in range(K+1))
print(ans)
'''
MLEした
dp = [[[0]*(K+1) for _ in range(N+2)] for _ in range(N+2)]
for i in range(1, N+1):
    dp[i][i][0] = 1
for i in range(1, N):
    dp[i][i+1][0] = 1
    if S[i] == S[i+1]:
        dp[i][i+1][0] = 2    
    elif K:    
        dp[i][i+1][1] = 2
for s in range(3, N+1):
    for i in range(1, N-s+2):
        j = i+s-1
        if S[i] == S[j]:
            for k in range(K+1):
                dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], 2+dp[i+1][j-1][k])
        else:
            dp[i][j][0] = max(dp[i+1][j][0], dp[i][j-1][0], dp[i+1][j-1][0])
            for k in range(1, K+1):
                dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], dp[i+1][j-1][k], 2+dp[i+1][j-1][k-1], dp[i+1][j-1][k])
print(max(dp[1][N][k] for k in range(K+1)))
'''   

Measured memory_bytes: 125404
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    string str,str1;
    cin>>str;
    ll q,x,y,z,val,val1,cnt=0;
    cin>>q;
    vector<char>v,v1;
    while(q--)
    {
        char ch;
        cin>>x;
        if(x==1)
        {
            cnt++;
        }
        if(x==2)
        {
            cin>>y>>ch;
            if(y==1)
            {
                if(cnt%2==0)
                {
                    v.pb(ch);
                }
                else
                {
                    v1.pb(ch);
                }
            }
            else
            {
                if(cnt%2==0)
                {
                    v1.pb(ch);
                }
                else
                {
                    v.pb(ch);
                }
            }
        }
    }
   // debug()<<v;
   // debug()<<v1;
    for(int i=0;i<v.size();i++)
    {
        str1+=v[i];   
    }
    for(int i=0;i<v1.size();i++)
    {
        str+=v1[i];
    }
    reverse(str1.begin(),str1.end());
    str1+=str;
    if(cnt%2==1)
    {
        reverse(str1.begin(),str1.end());
    }
    cout<<str1<<endl;
}

Measured memory_bytes: 1488
#include <iostream>
#include <string>
using namespace std;
int main(){
   int A,B,C,K;
   cin >> A >> B >> C >> K;
   for(int i=0; i<K; i++){
       if(A >= B && A >= C){
           A = A*2;
       }if(B >= A && B >= C){
           B = B*2;
       }if(C >=A && C >= B){
           C = C*2;
       }
   }cout << A+B+C << endl;
}


Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <ctime>

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //srand(time(NULL));
    ll x, k, d;
    cin >> x >> k >> d;
    int m = 1;
    if (x < 0) {
        m *= -1;
        x *= -1;
    }
    if (x > d) {
        ll z = min(k, (x / d));
        x -=  z* d;
        k -= z;
    }
    if (k == 0) {
        cout << abs(x) << endl;
        return 0;
    }
    if (k % 2 == 0 && abs(x) <= abs(x - 2 * d)) {
        cout << abs( x )<< endl;
        return 0;
    }
    if (k % 2 == 0 && abs(x) > abs(x - 2 * d)) {
        cout << abs(x - 2 * d) << endl;
        return 0;
    }
    if (k % 2 == 1 && abs(x+d) <= abs(x - d)) {
        cout <<  abs(x+d) << endl;
        return 0;
    }
    if (k % 2 == 1 && abs(x+d) > abs(x - d)) {
        cout <<  abs(x -  d) << endl;
        return 0;
    }



}

Measured memory_bytes: 3168
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int N = sc.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		for(int i=0; i<N; i++) {
			list.add(sc.nextInt());
		}
		
		Collections.sort(list);
		
		System.out.println(list.get(N-1) - list.get(0));
	}

	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21204
use proconio::*;
use proconio::marker::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        q: usize,
        c: [Usize1; n],
        ask: [(Usize1, usize); q],
    }
    let batch = 1024;
    let mut query = vec![vec![]; n / batch + 1];
    for (i, (l, r)) in ask.into_iter().enumerate() {
        query[l / batch].push((r, l, i));
    }
    let mut cnt = vec![0; n];
    let mut ans = vec![0; q];
    let mut sum = 0;
    let mut x = 0;
    let mut y = 0;
    for (i, mut query) in query.into_iter().enumerate() {
        query.sort_unstable_by_key(|p| p.0);
        if i & 1 == 1 {
            query.reverse();
        }
        for (r, l, k) in query {
            while l < x {
                x -= 1;
                let c = &mut cnt[c[x]];
                if *c == 0 {
                    sum += 1;
                }
                *c += 1;
            }
            while y < r {
                let c = &mut cnt[c[y]];
                y += 1;
                if *c == 0 {
                    sum += 1;
                }
                *c += 1;
            }
            while x < l {
                let c = &mut cnt[c[x]];
                x += 1;
                if *c == 1 {
                    sum -= 1;
                }
                *c -= 1;
            }
            while r < y {
                y -= 1;
                let c = &mut cnt[c[y]];
                if *c == 1 {
                    sum -= 1;
                }
                *c -= 1;
            }
            ans[k] = sum;
        }
    }
    for a in ans {
        println!("{}", a);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 40100
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    ll N, ans = 0;
    cin >> N;
    vector<ll> A(N), B(N + 1);
    map<ll, ll> p;
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++){
        B.at(i + 1) = B.at(i) + A.at(i);
        p[B.at(i + 1)]++;
    }
    p[0]++;
    for(auto t : p){
        ans += t.second * (t.second - 1) / 2;
    }
    cout << ans << endl;

}


Measured memory_bytes: 15872
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = s[0];
        int x = s[1];
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Array.Sort(a);
        int count = 0;
        for(int i = 0; i<n; i ++) {
            x -= a[i];
            if (x>=0) count ++;
            else break;
        }
        if (x>0) count --;
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> M(N);
    M[0]=INF;
    rep(i, N)
    {
        cin >> P[i];
        M[i] = min(M[max(0,i-1)],P[i]);
    }
    int ans = 0;
    rep(i,N){
        if(M[i]>=P[i])ans ++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,j;
    cin>>n>>k;
    if(k==1)
    {
        cout<<0<<endl;
        return 0;
    }
    if(n==k)
    {
        cout<<0<<endl;
        return 0;
    }
    i=n-k;
    cout<<i<<endl;




    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
//using namespace std;
 int num[31];
void swap(int a,int b){
  int c = num[a];
  num[a]=num[b];
  num[b]=c;
  

}


int main(){
  int w,n,a,b,i;
  //  int num[31]={0};
  // cin>>w>>n;
  scanf("%d",&w);
  scanf("%d",&n);
 
  for(i=1;i<=w;i++){
    num[i]=i;
  }
  for(i=1;i<=n;i++){
    scanf("%d,%d",&a,&b);
    swap(a,b);
  }
  for(i=1;i<=w;i++){
    //cout<<num[i]<<endl;
    printf("%d\n",num[i]);
  }
  return 0;
  // cout<<a<<b;
}

Measured memory_bytes: 592
#include<stdio.h>
#include<math.h>

int main(){
    int num, i;
    long int input[100000];
    long int ans = 0;
    long int min = 1000000000;
    int count = 0;

    scanf("%d", &num);
    for(i=0; i<num; i++){
        scanf("%ld", &input[i]);
        ans = ans + abs(input[i]);
        if(input[i] < 0){
            count += 1;
        }
        if(min > abs(input[i])){
            min = abs(input[i]);
        }
    }
    
    if((count%2)==0){
        printf("%ld", ans);
    } else{
        printf("%ld", (ans-min*2));
    }

    return 0;
}

Measured memory_bytes: 896
#include<stdio.h>

int main()
{
	int a, b,ans;

	scanf("%d%d", &a, &b);
	ans = a + b;
	if (ans < a - b)
		ans = a - b;
	if (ans < a*b)
		ans = a*b;

	printf("%d\n", ans);

	return 0;
}

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

int vis[101] = { 0 };
int main()
{
	int n;
	int cnt = 0;
	for (int i = 0; i < 3; ++i)
	{
		cin >> n;
		if (0 == vis[n])
		{
			++cnt;
			vis[n] = 1;
		}
	}
	cout << cnt << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;
int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int64_t n,k ;
    cin >> n >> k ;
    int64_t ans = n % k ;
    ans = min(ans, k-ans) ;
    cout << ans << endl ;
}

Measured memory_bytes: 256
n = int(input())
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
result = 0
for i in range(n):
  if a[i] > b[i]:
    result += b[i]
    a[i] -= b[i]
    b[i] = 0
  else:
    result += a[i]
    b[i] -= a[i]
    a[i] = 0
    if a[i + 1] > b[i]:
      result += b[i]
      a[i + 1] -= b[i]
      b[i] = 0
    else:
      result += a[i + 1]
      b[i] -= a[i + 1]
      a[i + 1] = 0
print(result)


Measured memory_bytes: 19648
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    result = 0
    
    for i in range(N):
        attack = min(A[i],B[i])
        B[i] -= attack
        A[i] -= attack
        result += attack
        if B[i] > 0:
            attack = min(A[i+1], B[i])
            B[i] -= attack
            A[i+1] -= attack
            result += attack
    
    print( result )
    
solve()

Measured memory_bytes: 18624
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int r;
	cin >> r;
	if(r < 1200) puts("ABC");
	else if(r>=1200 && r<2800) puts("ARC");
	else puts("AGC");
	return 0;
}

Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
    fastread();
    int a;
    cin>>a;
    ll ans = a+a*a+a*a*a;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  int i, tmp, min, ans;
  vector <int>p(102,0);
  int x, n; cin >> x >> n;
  rep(i,n){cin >> tmp; p[tmp]++;}
  ans = 0; min = 999;

  FOR(i,0,102){
      if(p[i]!=0){continue;}
      tmp = abs(x-i);
      if(tmp < min){min = tmp; ans = i;}
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N;
    cin >> N;
    vector<ld> A(N);
    for (auto &x : A) cin >> x;
    ld ans_inv = 0;
    for (auto x : A) ans_inv += (ld)1.0 / x;
    cout << (ld)1.0 / ans_inv << endl;
}

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

int main() {
  for(int i = 0; i < 9; ++i) {
    string name;
    int s, t;
    cin >> name >> s >> t;
    cout << name << " " << s + t << " " << s * 200 + t * 300 << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
from math import gcd
k = int(input())
うんち = 0
for デビ in range(1,k+1):
    for デビデ in range(1,k+1):
        for ビル in range(1,k+1):
            うんち += gcd(デビ,gcd(デビデ,ビル))
print(うんち)

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/07/20  Problem: ABC 134 E / Link: http://abc134.contest.atcoder.jp/tasks/abc134_e  ----- */

template<typename Monoid>
struct SegmentTreeFastAry {
	using nd = typename Monoid::type;
	const int ARY_SIZE;
	vector<nd> node;
public:
	SegmentTreeFastAry(int n) : ARY_SIZE(n), node(2 * ARY_SIZE, Monoid::id()) {}
	void set_val(int i, const nd val) {
		i += ARY_SIZE; node[i] = val;
		while (i > 1) { i >>= 1;	node[i] = Monoid::op(node[i << 1], node[(i << 1) + 1]); }
	}
	inline nd query(int l, int r) {
		if (l >= r) return Monoid::id(); nd vl = Monoid::id(), vr = Monoid::id();
		for (l += ARY_SIZE, r += ARY_SIZE; l != r; l >>= 1, r >>= 1) {
			if (l & 1) vl = Monoid::op(vl, node[l++]); if (r & 1) vr = Monoid::op(node[--r], vr);
		}	return Monoid::op(vl, vr);
	}
	nd operator[](int i) { return node[i + ARY_SIZE]; }
};

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

	LL N; cin >> N;
	struct TwoMin {
		using type = PLL;
		static type id() { return PLL(INF + 2, INF + 2); }
		static type op(const type&l, const type&r) {
			return min(l, r);
		}
	};

	SegmentTreeFastAry<TwoMin>seg(N);
	vector<LL> a(N);
	vector<PLL>ord;
	FOR(i, 0, N) {
		cin >> a[i];
		seg.set_val(i, PLL(a[i], -i));
		ord.emplace_back(a[i], -i);
	}

	SORT(ord);
	LL ans = 0;
	for (auto it : ord) {
		LL idx = -it.second;
		if (seg[idx].first > INF)continue;
		ans++;
		seg.set_val(idx, TwoMin::id());
		while (idx < N) {
			PLL ne = seg.query(idx + 1, N);
			LL nid = -ne.second;
			if (nid < 0)break;
			seg.set_val(nid, TwoMin::id());
			idx = nid;
		}
	}

	cout << (ans) << "\n";
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int par[100001],r[100001];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    r[i]=0;
  }
}

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

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

bool same(int x,int y){
  return find(x)==find(y);
}

int main() {
  int n;
  cin>>n;
  int h[n];
  for(int i=0;i<n;i++) cin>>h[i];
  int dp[n+1];
  dp[1]=0;
  dp[2]=abs(h[1]-h[0]);
  for(int i=3;i<=n;i++){
    dp[i]=min(dp[i-2]+abs(h[i-1]-h[i-3]),dp[i-1]+abs(h[i-1]-h[i-2]));
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 4356
import java.util.*;
 
import javax.xml.crypto.Data;
 
import java.math.*;
 
public class Main {
     
     
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] k = new int[n];
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            k[i] = sc.nextInt();
            p[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++) {
            int s = k[i];
            int now = 0;
            while(s != 0) {
                now %= p[i];
                now++;
                s--;
            }
            System.out.println(now);
        }
    }
     
}

Measured memory_bytes: 20656
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n, m;
  cin >> n >> m;
  int ans = n*(n-1)/2+m*(m-1)/2;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ll L, R;
  cin >> L >> R;

  ll ans = 2020;
  for (ll i = L; i <= L + 2017; i++) {
    for (ll j = i + 1; j <= L + 2018; j++) {
      ans = min(ans, (i * j) % 2019);
      if (j == R) break;
    }
    if (i + 1 == R) break;
  }

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

Measured memory_bytes: 256
s = input()
s_first = int(s[:2])
s_second = int(s[2:]) 

if 1 <= s_first <= 12 and 1 <= s_second <= 12:
	print("AMBIGUOUS")
elif (not 1 <= s_first <= 12 ) and 1 <= s_second <= 12:
	print("YYMM")
elif 1 <= s_first <= 12 and (not 1 <= s_second <= 12):
	print("MMYY")
elif (not 1 <= s_first <= 12) and (not 1 <= s_second <= 12):
	print("NA")

Measured memory_bytes: 3060
#include <iostream>

int main(void){
	int A,B;
	std::cin>>A>>B;

	if(A>=13){
		std::cout<<B<<std::endl;
		return 0;
	}else if(A>5){
		std::cout<<int(B/2)<<std::endl;
		return 0;
	}else{
		std::cout<<0<<std::endl;
		return 0;
	}
	return  0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, K; cin >> N >> K;
  vector<ll> a(N); rep(i, N) { cin >> a[i]; a[i] --;}
  vector<ll> b(N);
  ll ans = 0;
  for(ll i = 0; (K >> i) > 0; i++) {
    /*
    cerr << i << "] ";
    rep(j, N) {
      cerr << a[j] << " ";
    }
    cerr << endl;
    */
    if((K >> i) & 1) {
      ans = a[ans];
    }
    
    rep(j, N) b[j] = a[a[j]];
    rep(j, N) a[j] = b[j];
  }

  cout << ans + 1 << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 6416