akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int A[200001];

int main() {
  int N, result;
  int max1, max2, max1i, max2i;
  int i;
  scanf ("%d", &N);
  
  for (i=0;i<N;i++) {
      scanf("%d", &A[i]);
  }
  
  max1 = 0;
  for (i=0;i<N;i++) {
      if (A[i]>max1) {
          max1 = A[i];
          max1i = i;
      }
  }
  
  max2 = 0;
  for (i=0;i<N;i++) {
      if (i!=max1i) {
          if (A[i]>max2) {
              max2 = A[i];
              max2i = i;
          }
      }
  }
  
  for (i=0;i<N;i++) {
      if (i==max1i) printf("%d\n", max2);
      else          printf("%d\n", max1);
  }
  return 0;
}




Measured memory_bytes: 2304
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b;
    sum+=a/b;
    if(a%b) sum++;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3644
#ran time eerror
from collections import Counter 

d = int(input())
l = []
for k in range(d):
  r = input()
   
  l.append(Counter(r))

oi = l[0]

for g in range(1,d):
    oi = oi & l[g]
    
    
print("".join(sorted(oi.elements())))



Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	ll x; cin >> x;
	while (true)
	{
		bool is_prime = true;
		for (ll i = 2; i*i <= x; i++)
		{
			if (x % i == 0)
			{
				is_prime = false;
				break;
			}
		}
		if (is_prime)
		{
			co(x);
			return 0;
		}
		x++;
	}
	return 0;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repe(i, n) for (ll i = 0; i <= (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

ll ans = 0;
bool check = 0;
bool boo = 0;
string s, t;
int N = 3;
vector<int> v(N);
long long a, b, c, d, n, m;
int x = 0, y = 0;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    // 36
    int left = 0, right = 0;
    cin >> n >> m >> x;
    rep(i, m)
    {
        cin >> a;
        if (a < x)
            left++;
        else
            right++;
    }
    pr(min(left, right));

    return 0;
}


Measured memory_bytes: 3580
#include<cstdio>
int main()
{
	long long int a,b,i,ss=10000,s,j;
	scanf("%lld%lld",&a,&b);
	 if(b/2019>a/2019)
	printf("0\n");
	else
	{
	for(i=a;i<b;i++)
	for(j=i+1;j<=b;j++)
	{
		s=(i*j)%2019;
		if(s<ss)
		ss=s;
	}
	printf("%lld",ss);
}
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	vi sikaku;
	vi sikaku2;
	int cnt = 1;
	while (cnt*(cnt + 1)*(cnt + 2) / 6 <= 1000000) {
		sikaku.push_back(cnt*(cnt + 1)*(cnt + 2) / 6);
		if (cnt*(cnt + 1)*(cnt + 2) / 6 % 2 == 1)
			sikaku2.push_back(cnt*(cnt + 1)*(cnt + 2) / 6);
		cnt++;
	}
	int n;

	while (cin >> n, n) {
		vi memo(n + 1, 1e9);
		vi memo2(n + 1, 1e9);
		memo[n] = 0;
		memo2[n] = 0;
		queue<int> Q;
		Q.push(n);
		while (!Q.empty()) {
			int q = Q.front(); Q.pop();
			if (q == 0)
				break;
			REP(i, sikaku.size()) {
				if (q >= sikaku[i]) {
					if (memo[q - sikaku[i]] > memo[q] + 1) {
						memo[q - sikaku[i]] = memo[q] + 1;
						Q.push(q - sikaku[i]);
					}
				}
				else
					break;
			}
		}
		queue<int> Q2;
		Q2.push(n);
		while (!Q2.empty()) {
			int q = Q2.front(); Q2.pop();
			if (q == 0)
				break;
			REP(i,sikaku2.size()) {
				if (q >= sikaku2[i]) {
					if (memo2[q - sikaku2[i]] > memo2[q] + 1) {
						memo2[q - sikaku2[i]] = memo2[q] + 1;
						Q2.push(q - sikaku2[i]);
					}
				}
				else
					break;
			}
		}
		cout << memo[0] << " " << memo2[0] << endl;

	}
	return 0;
}

Measured memory_bytes: 15204
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10
 
 
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    ans = []
    for i in range(1, len(a_list), 2):
        ans.append(a_list[i])
    ans = ans[::-1]
    for i in range(0, len(a_list), 2):
        ans.append(a_list[i])
 
    if n % 2 != 0:
        ans = ans[::-1]
    print(*ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 25540
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const int MAX= 1e6+100;


ll a[MAX];
int main(){
	fastio;
	ll tc,n,x,k,q,l,r,m;
	cin>>n>>k;
	cout<<min(n%k,k-n%k)<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}
signed main() {
	int n = input();
	int ans = 0;
	for1(i, n)if (i % 3 > 0 && i % 5 > 0)ans += i;
	cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int N, K;
	cin >> N >> K;
	vector<ll>num(K, 0);
	for (int i = 1; i <= N; ++i) {
		num[i%K]++;//num[x]=Kで割ってx余る数が1以上N以下に何個あるか
	}
	ll res = 0;
	for (int a = 0; a < K; ++a) {
		int b = (K - a) % K;
		int c = (K - a) % K;
		if ((b + c) % K != 0)continue;
		res += num[a] * num[b] * num[c];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    string s; cin >> s;
    bool q = false;
    for(int i = 0 ;i < 3; i++)
        if(s[i] == s[i+1])
            q = true;
    if(q)
        cout << "Bad" << endl;
    else
        cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    S = input()
    L = len(S)
    """
    dpなんですか、そうですか。。。（眼中になかった）
    '?'を総当たりで埋めてから考えるのではなく、
    i文字目までの問題の解を考えるのがミソ。具体的には
        dp[i][""]    = (i文字目まで見たときにまだどの文字も選んでいない方法)
        dp[i]["A"]   = (i文字目まで見たときに"A  "の１文字まで選んでいる方法)
        dp[i]["AB"]  = (i文字目まで見たときに"AB "の２文字まで選んでいる方法)
        dp[i]["ABC"] = (i文字目まで見たときに"ABC"の３文字まで選んでいる方法)
    をキーとする遷移を考える。

    （注意）この遷移を例えば
        dp[i]["A"] = (i文字目まで見たときに"A"の１文字を選ぶ方法)
    のようにすると、それまでにどの文字を選んできたかの情報が抜け落ちるのでダメ。
    """
    dp = [1, 0, 0, 0]
    if S[0] == "A": dp = [1, 1, 0, 0]
    if S[0] == '?': dp = [3, 1, 0, 0]
    #print("S[0]={}, dp[0]={}".format(S[0], dp))
    for i in range(1, L):
        if S[i] == 'A':
            dp = [dp[0], dp[1] + dp[0], dp[2], dp[3]]
        elif S[i] == 'B':
            dp = [dp[0], dp[1], dp[2] + dp[1], dp[3]]
        elif S[i] == 'C':
            dp = [dp[0], dp[1], dp[2], dp[3] + dp[2]]
        else: 
            # ここがミソ！！！'?'には３通り入る余地があって、
            # この文字を選ばなくても今までの取り方はすべて３倍カウントになる！
            dp = [dp[0] * 3, dp[1] * 3 + dp[0], dp[2] * 3 + dp[1], dp[3] * 3 + dp[2]]
        dp = [dp[0] % mod, dp[1] % mod, dp[2] % mod, dp[3] % mod]
        #print("S[{}]={}, dp[{}]={}".format(i, S[i], i, dp))
    print(dp[3])


if __name__ == "__main__":
    main()


Measured memory_bytes: 40048
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] h = new int[N + 1];
    for (int i = 1; i <= N; i++) {
      h[i] = sc.nextInt();
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
      int d = h[i] - h[i - 1];
      if (d > 0) {
        ans += d;
      }
    }
    System.out.println(ans);
  }
}


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

int n;
long long ans=0,pa=0,pb=0,l[100010],r[100010];
priority_queue<long long>a;
priority_queue<long long,vector<long long>,greater<long long> >b;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld%lld",&l[i],&r[i]),l[i]=r[i]-l[i];
	a.push(r[1]);b.push(r[1]);
	for(int i=2;i<=n;i++){
		pa-=l[i-1];pb+=l[i];
		if(r[i]<a.top()+pa){
			ans+=a.top()+pa-r[i];b.push(a.top()+pa-pb);
			a.pop();a.push(r[i]-pa);a.push(r[i]-pa);
		}
		else if(r[i]>b.top()+pb){
			ans+=r[i]-(b.top()+pb);a.push(b.top()+pb-pa);
			b.pop();b.push(r[i]-pb);b.push(r[i]-pb);
		}
		else a.push(r[i]-pa),b.push(r[i]-pb);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3572
/*input
2019 4037
*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int arr[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int l,r;
    cin>>l>>r;
    if(r-l+1>=2019){
        cout<<0;
        return 0;
    }
    ll ans=INT_MAX;
    for(ll k=l;k<=r;k++){
        for(ll i=k+1;i<=r;i++){
            ans=min(ans,(i*k)%2019);
        }
    }
    cout<<ans;
}

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

namespace TYC
{
	typedef long long ll;
	typedef pair<int, int> pii;
	const int N = 6e5 + 5, INF = 0x3f3f3f3f;

	int W, H, n, size, ans, real[N], val[N << 2], tag[N << 2];
	pii P[N >> 1], L[N], R[N];

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

#define ls o << 1
#define rs o << 1 | 1
	
	inline void pushdown(const int o)
	{
		int t = tag[o];
		if (t)
		{
			val[ls] += t, tag[ls] += t;
			val[rs] += t, tag[rs] += t;
			tag[o] = 0;
		}
	}

	void build(const int o = 1, const int l = 1, const int r = size)
	{
		tag[o] = 0;
		if (l == r)
			return void(val[o] = H - real[l]);
		int mid = (l + r) >> 1;
		build(ls, l, mid), build(rs, mid + 1, r);
		val[o] = max(val[ls], val[rs]);
	}

	void add(const int s, const int e, const int v, const int o = 1, const int l = 1, const int r = size)
	{
		if (e <= 0 || s > e)
			return;
		if (s <= l && r <= e)
			return void((val[o] += v, tag[o] += v));
		pushdown(o);
		int mid = (l + r) >> 1;
		if (s <= mid)
			add(s, e, v, ls, l, mid);
		if (e > mid)
			add(s, e, v, rs, mid + 1, r);
		val[o] = max(val[ls], val[rs]);
	}	

	int query(const int s, const int e, const int o = 1, const int l = 1, const int r = size)
	{
		if (e <= 0 || s > e)
			return -INF;
		if (s <= l && r <= e)
			return val[o];
		pushdown(o);
		int mid = (l + r) >> 1, ans = 0;
		if (s <= mid)
			ans = max(ans, query(s, e, ls, l, mid));
		if (e > mid)
			ans = max(ans, query(s, e, rs, mid + 1, r));
		return ans;
	}

#undef ls
#undef rs
	
	void solve()
	{
		sort(P + 1, P + 1 + n);
		build();
		int ltop = 0, rtop = 0;
		for (int i = 1, v; i <= n; i++)
		{
			if (P[i].first != P[i + 1].first)
			{
				v = real[P[i].first];
				ans = max(ans, v + query(1, P[i].first - 1));
			}
			v = P[i].second;
			if (real[v] <= (H >> 1))
			{
				add(L[ltop].first, P[i].first - 1, -real[v]);
				while (ltop && v >= L[ltop].second)
				{
					add(L[ltop - 1].first, L[ltop].first, -real[v] + real[L[ltop].second]);
					--ltop;
				}
				L[++ltop] = P[i];
			}
			else
			{
				add(R[rtop].first, P[i].first - 1, real[v] - H);
				while (rtop && v <= R[rtop].second)
				{
					add(R[rtop - 1].first, R[rtop].first, real[v] - real[R[rtop].second]);
					--rtop;
				}
				R[++rtop] = P[i];
			}
		}
		ans = max(ans, max(real[P[1].first], W - real[P[n].first]) + H);
		ans = max(ans, W + query(1, H - 1));
	}

	void work()
	{
		W = read(), H = read(), n = read();
		for (int i = 1; i <= n; i++)
		{
			real[++size] = P[i].first = read();
			real[++size] = P[i].second = read();
		}
		sort(real + 1, real + 1 + size);
		size = unique(real + 1, real + 1 + size) - real - 1;
		for (int i = 1; i <= n; i++)
		{
			P[i].first = lower_bound(real + 1, real + 1 + size, P[i].first) - real;
			P[i].second = lower_bound(real + 1, real + 1 + size, P[i].second) - real;
		}
		solve();
		swap(W, H);
		for (int i = 1; i <= n; i++)
			swap(P[i].first, P[i].second);
		solve();
		printf("%d\n", ans << 1);
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,D; cin>>N>>D;
    int count=0;
    vector<vector<int>> X(N,vector<int> (D));
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin>>X[i][j];
        }
    }

    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            double kyo1=0;
            for(int k=0;k<D;k++) {
                kyo1 = kyo1 + pow(X[j][k] - X[i][k], 2);
            }
            double kyo=0;
            kyo = sqrt(kyo1);
            if (floor(kyo) == kyo) {
                count++;
            }
        }
    }
    cout<<count;
    return 0;
}


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

using namespace std;

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

    for (int i = 0; i < n; i++) {
        char s;
        cin >> s;
        if (s == 'Y') return cout << "Four\n", 0;
    }
    cout << "Three\n";

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = 10**(n-1)

for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

for i in range(0, dig*10):
    flag = False
    if len(str(i)) < n:
        continue
    for j,s in enumerate(s_len):
        if str(i)[s-1] != str(c_len[j]) and flag == False:
            flag = True
            break
    if flag==False:
        print(i)
        exit()

print("-1")

Measured memory_bytes: 3064
# C - Green Bin
def main():
    count = 0
    dictCount = {}
    for i in [input() for i in range(int(input()))]:
        strInput = ''.join(sorted(i))
        if strInput in dictCount:
            count += dictCount[strInput]
            dictCount[strInput] += 1
        else:
            dictCount[strInput] = 1
    print(count)

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 24976
S = list(input())
ans = 0
if S[0] == "1":
	for i in range(len(S)):
		if i % 2 == 0 and S[i] == "0":
			ans += 1
		if i % 2 == 1 and S[i] == "1":
			ans += 1
else:
	for i in range(len(S)):
		if i % 2 == 0 and S[i] == "1":
			ans += 1
		if i % 2 == 1 and S[i] == "0":
			ans += 1
print(ans)

Measured memory_bytes: 4008
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int A,B,C;
	cin>>A>>B>>C;
	if(B+C>A){
		cout<<C-(A-B)<<endl;
	}
	else{
		cout<<0<<endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5;

ll n, k, a[N], fact[N];

ll fpow(ll a, ll b) {
    a %= MOD;
    if (b == 0)
        return 1;
    ll ret = fpow(a * a, b / 2);
    if (b & 1)
        ret *= a;
    return ret % MOD;
}

ll modinv(ll a) {
    return fpow(a, MOD - 2);
}

ll nCr(ll n, ll r) {
    if (n < r)
        return 0;
    return fact[n] * modinv(fact[r] * fact[n - r]) % MOD;
}

void init() {
    fact[0] = 1;
    for (int i = 1; i < N; ++i)
        fact[i] = (fact[i - 1] * i) % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    init();

    cin >> n >> k;

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

    sort(a, a + n);

    ll ans = 0;
    for (int i = 0; i < n; ++i) 
        (ans += nCr(i, k - 1) * a[i]) %= MOD;

    reverse(a, a + n);
    for (int i = 0; i < n; ++i) 
        (ans -= nCr(i, k - 1) * a[i]) %= MOD;

    cout << (ans + MOD) % MOD << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
    int m,f,r;
    char lank;
    while ( 1 ) {
        scanf("%d %d %d", &m, &f, &r);
        if ( m == -1 && f == -1 && r == -1 ) break;
        if ( m == -1 || f == -1 ){
            lank = 'F';
        } else if ( m + f >= 80 ) {
            lank = 'A';
        } else if ( m + f >= 65 ) {
            lank = 'B';
        } else if ( m + f >= 50 ) {
            lank = 'C';
        } else if ( m + f >= 30 ) {
            if ( r >= 50 ) {
                lank = 'C';
            } else {
                lank = 'D';
            }
        } else {
            lank = 'F';
        }
        printf("%c\n", lank);
    }
    return 0;
}


Measured memory_bytes: 2076
import java.util.*;

public class Main {
    static boolean[] isPrime;
    static List<Integer> primes = new ArrayList<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if( n != 1 ) {
            // prime sieve, n+1??
            isPrime = new boolean[n+1];
            sieve(n+1);
            // get prime factors of n
            int[] primeFacts = new int[n+1];
            for( int j = 1; j <= n; j++ ) {
                for( int i = 0; i < primes.size(); i++ ) {
                    int temp = j;
                    int pri = primes.get(i);
                    while(temp%pri==0) {
                        primeFacts[pri]++;
                        temp /= pri;
                    }
                }
            }
            int gt2 = 0;
            int gt4 = 0;
            int gt14 = 0;
            int gt24 = 0;
            int gt74 = 0;
    
            for( int i : primeFacts ) {
                if( i >= 2 ) gt2++;
                if( i >= 4 ) gt4++;
                if( i >= 14 ) gt14++;
                if( i >= 24 ) gt24++;
                if( i >= 74 ) gt74++;
            }
    
            int[] ans = new int[4];
            ans[0] = (gt4 * (gt4-1) * (gt2-2))/2; // 5 5 3
            ans[1] = gt24 * (gt2-1); // 3 25
            ans[2] = gt14 * (gt4-1); // 5 15
            ans[3] = gt74; // 75
    
            int sum = 0;
            for( int i : ans ) sum += i;
            System.out.println(sum);
            
            // System.out.println(Arrays.toString(primeFacts));
        } else {
            System.out.println(0);
        }
        
    }

    static void sieve( int N ) {
        isPrime[2] = true; primes.add(2);
        for( int i = 3; i < N; i+=2 ) isPrime[i] = true;
        for( int i = 3; i < N; i+=2 ) {
            if( isPrime[i] ) {
                primes.add(i);
                if((long)(i)*i>=N) continue;
                for( int j=i*i; j<N; j+=i ) isPrime[j] = false;
            }
        }
    }
}

// for 100
// 15 <= 3
// 9 <= 5
// 4 <= 15
// 3 <= 25
// 1 <= 75

// 5 5 3
// (9 * 9-1 * 15-2) / 2 = 468

// 5 15
// 4 * 9-1 = 32

// 3 25
// 3 * 15-1 = 42

// 75
// 1

// total = 543

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N,K;
  cin>>N>>K;
  vector<int>x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
  }
 
  int64_t ans=999999999999999;
  for(int i=0;i<N;i++){
    if(N-K>=i){
    int64_t sum=0;
    int start=min(abs(x[i]),abs(x[i+K-1]));
    sum=start+x[i+K-1]-x[i];
    ans=min(ans,sum);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3748
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
int a[123], b[123];

int main() {
    int N;
    while (~scanf("%d", &N)) {
          for (int i = 1; i <= N; i++) {
              int tmp;
              scanf("%d", &tmp);
              a[i] = a[i - 1] + tmp;
          }
          for (int i = 1; i <= N; i++) {
              int tmp;
              scanf("%d", &tmp);
              b[i] = b[i - 1] + tmp;
          }
          int ans = 0;
          for (int i = 1; i <= N; i++) {
              int sum = a[i] + b[N] - b[i - 1];
              ans = max(sum, ans);
          }
          printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int binary_search(vector<int> v,int key){
  int right=0,left=v.size()-1;
  if(v.empty() || v[left]>=key)return -1;
  if(v[0]<key)return 0;
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<key)left=mid;
    else right=mid;
  }
  while(left!=0 && v[left]==v[left-1])left--;
  return left;
}

vector<int> ver;
void dfs(const graph &g,int v){
  ver[v]=1;
  for(auto i:g[v]){
    if(ver[i]!=1)continue;
    dfs(g,i);
  }
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int mi=a[0];
  vector<int> v;
  v.push_back(a[0]);
  for(i=1;i<n;i++){
    if(v[v.size()-1]>=a[i]){
      v.push_back(a[i]);
    }else{
      int p=binary_search(v,a[i]);
      if(p==-1)return 1;
      if(p!=0){
        if(!(v[p-1]>=a[i] && a[i]>v[p]))return 1;
      }
      swap(v[p],a[i]);
    }
  }
  cout<<v.size()<<endl;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

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

    vector<int> ans(n);
    rep(i, n){
        if(i < k) {
           ans[i] = s;
        }
        else {
            if(s + 1 > 1000000000) ans[i] = 1;
            else ans[i] = s + 1;
        }
    }
    for(auto x : ans) cout << x << endl;
    return 0;
}

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

int main() {
	string S;
    cin >> S;
    int cnt1 = 0;
    int cnt2 = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '0') {
            cnt1++;
        }
        else {
            cnt2++;
        }
    }
    cout << min(cnt1,cnt2)*2 << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;

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

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(ll H, ll W, vector <string> a) {
	string uesita(W + 2, '#');
	cout << uesita << endl;
	rep(i, H) {
		cout <<  '#' << a[i] << '#' << endl;
	}
	cout << uesita << endl;
}

int main() {
	ll W;
	ll H;
	scanf("%lld", &H);
	vector <string> a(H - 1 + 1);
	scanf("%lld", &W);
	for(int i = 0; i <= H - 1; i++) {
		cin >> a[i];
	}
	solve(H, W, a);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}
void print(double n){cout << n << endl;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}

//main-----------------------------------------------------------------------------


signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int n = input();

    vector<int> arr; rep(i,0,n) arr.push_back(input());

    vector<pair<int, int>> a;
    vector<pair<int, int>> b;

    rep(i,0,100001){
        a.push_back(make_pair(0, i));
        b.push_back(make_pair(0, i));
    }

    rep(i,0,n){
        if(i % 2 == 0) a[arr[i]].first++;
        else{ b[arr[i]].first++;}
    }

    sort(a.begin(), a.end(), greater<pair<int, int>>());
    sort(b.begin(), b.end(), greater<pair<int, int>>());

    if(a[0].second == b[0].second){
        print(min(n - a[0].first - b[1].first, n - a[1].first - b[0].first));

    }else{
        print(n - a[0].first - b[0].first);
    }





}

Measured memory_bytes: 4252
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        double ans = ((double)((n+1)/2)) / (double)n;
        System.out.println(ans);

    }


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

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            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() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21204
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

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

	int N, K;
	cin >> N >> K;

	int h[N];
	for(int i = 0; i < N; i++) {
		cin >> h[i];
	}

	sort(h, h + N);
	int mini = 2e9+5;
	for(int i = 0; i <= N - K; i++) {
		mini = min(mini, h[i+K-1] - h[i]);
	}
	cout << mini << endl;
	return 0;
}

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

int main()
{
  int A,B;cin>>A>>B;
  int count=0;
  int consent=1;
  
  while (consent < B)
  {
    consent += A;
    count++;
    consent--;
  }
  
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	double v,t,y,n1;
	int n;
	while(scanf(" %lf",&v)!=EOF){
		t=v/9.8;
		y=4.9*t*t;
		n=0;
		n1=(5+y)/5;
		while(n<n1){
			n=n+1;
		}
	printf("%d\n",n);
	}
	return 0;
}

Measured memory_bytes: 628
import heapq

def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
way = [0]
hq = [0]
heapq.heapify(hq)
posi = 0
cycle = 0
while True:
    if binary_search(hq, a[posi]) != -1:
        rest = way.index(a[posi])
        cycle -= (rest - 1)
        break
    way.append(a[posi])
    heapq.heappush(hq, a[posi])
    posi = a[posi]
    cycle += 1
# print(way)
# print(cycle)
if k < len(way):
    print(way[k] + 1)
else:
    print(way[(k-rest) % cycle + rest] + 1)

Measured memory_bytes: 110196
#include <iostream>

using namespace std;

int main() {
  char N[4] = {};
  for (int i = 0; i < 3; ++i) {
    cin >> N[i];
  }
  for (int i = 0; i < 3; ++i) {
    if (N[i] == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3028
import java.io.*;
import java.util.*;

public class Main {
    BufferedReader br;
    String[] map = {"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};
    Main() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    int n;
    String[] ss;
    void init() {
        try {
            n = Integer.parseInt(br.readLine());
            ss = new String[n];
            for (int i = 0; i < n; i++) {
                ss[i] = br.readLine();
                for (int j = 0; j < map.length; j++) {
                    ss[i] = ss[i].replaceAll(map[j], Character.toString((char)('A'+j)));
                }
            }
        } catch (IOException e) {}
    }
    public static void main(String[] args) {
        new Main().run();
    }
    void run() {
        init();
        int[][] count = new int[300][300];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < ss[i].length()-1; j++) {
                if (ss[i].charAt(j+1) != ' ') {
                    count[ss[i].charAt(j)][ss[i].charAt(j+1)]++;
                }
            }
        }
        for (char c = 'a'; c <= 'z'; c++) {
            int max = 0;
            char max_char = 'a';
            for (char d = 'a'; d <= 'z'; d++) {
                if (count[c][d] > max) {
                    max_char = d;
                    max = count[c][d];
                }
            }
            for (char d = 'A'; d <= 'L'; d++) {
                if (count[c][d] > max) {
                    max_char = d;
                    max = count[c][d];
                }
            }
            String max_kan_char = Character.toString(max_char);
            if (Character.isUpperCase(max_char)) max_kan_char = map[max_char-'A'];
            System.out.println(c + " " + max_kan_char + " " + max);
        }
        for (char c = 'A'; c <= 'L'; c++) {
            int max = 0;
            char max_char = 'a';
            for (char d = 'a'; d <= 'z'; d++) {
                if (count[c][d] > max) {
                    max_char = d;
                    max = count[c][d];
                }
            }
            for (char d = 'A'; d <= 'L'; d++) {
                if (count[c][d] > max) {
                    max_char = d;
                    max = count[c][d];
                }
            }
            String max_kan_char = Character.toString(max_char);
            if (Character.isUpperCase(max_char)) max_kan_char = map[max_char-'A'];
            System.out.println(map[c-'A'] + " " + max_kan_char + " " + max);
        }
    }
}

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

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

    vector<int> a(n);
    int count = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i] < 0){
            a[i] *= -1;
            count += 1;
        }
    }

    sort(a.begin(),a.end());
    
    long long int sum = 0;
    for(int i=0; i<n; i++){
        sum += a[i];
    }
    if(count % 2 == 1) sum -= 2 * a[0];
    cout << sum << endl;
    return 0;
}

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

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

int main() {
  int n; cin>>n;
  vector<int> v(n);
  rep(j,n){cin>>v.at(j);}
  int i=0,k=1,count=0;
  while(i<n){   
    if(v.at(i)==k){
      k++;count++;
    }
    i++;
  }
  if(count==0)cout<<-1;
  else{cout<<n-count;}
}

Measured memory_bytes: 1024
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
h = intl()

dp = [0]*n
for i in range(1,n):
    if i == 1:
        dp[i] = abs(h[i] - h[0])
    else:
        dp[i] = min( abs(h[i]-h[i-1]) + dp[i-1], abs(h[i]-h[i-2]) + dp[i-2] )
print(dp[-1])

Measured memory_bytes: 14484
#include<bits/stdc++.h>
using namespace std;
int a[2][101];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=2;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=2;i++){
		for(int j=1;j<=n;j++){
			a[i][j]+=max(a[i-1][j],a[i][j-1]);
		}
	}
	cout<<a[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007
 
using namespace std;

bool cmp(const pair<lli, lli> left, const pair<lli, lli> right) {
    if(left.first==right.first)return left.second < right.second;
  	return left.first< right.first;
}

int main(){
    int n;
    cin >> n;
    vector<pair<lli,lli>> vec;
    rep0(i,n){
        int x,l;
        cin >> x >> l;
        vec.emplace_back(x-l,x+l);
    }
    sort(all(vec), cmp);

    deque<int> dq;
    dq.push_back(0);

    rep1(i,n-1){
        int x=dq.front();
        dq.pop_front();
        if(vec[i].second <= vec[x].second){
            dq.push_front(i);
        }else if(vec[i].first>= vec[x].second){
            dq.push_front(x);
            dq.push_front(i);
        }else {
            dq.push_front(x);
        }
    }

    cout << dq.size();

}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int LMS(int n, int k) 
{ 
if (n == 1) 
	return 1; 
else
	/* The position returned by josephus(n - 1, k) is adjusted because the 
	recursive call josephus(n - 1, k) considers the original position 
	k%n + 1 as position 1 */
	return (LMS(n - 1, k) + k-1) % n + 1; 
} 
int main(){
	
	int t = 1;
	//cin >> t;
	while(t--){
		string a, b;
		cin >> a >> b;
		int p, q;
		cin >> p >> q;
		string s;
		cin >> s;
		if(s == a) p--;
		else q--;
		cout << p << ' ' << q;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        for(int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        Arrays.sort(c);
        long count = 0;
        for(int i = 0; i < n; i++) {
            int num = b[i];
            long numsA = lowerBound(a, num);
            long numsC = n - upperBound(c, num);
            count += numsA * numsC;
        }
        System.out.println(count);
    }

    static long lowerBound(int[] a, int x) {
        int l = -1, r = a.length;
        while(r - l > 1) {
            int mid = (l + r) / 2;
            if(a[mid] >= x) r = mid;
            else l = mid;
        }
        return r;
    }

    static long upperBound(int[] a, int x) {
        int l = -1, r = a.length;
        while(r - l > 1) {
            int mid = (l + r) / 2;
            if(a[mid] <= x) l = mid;
            else r = mid;
        }
        return r;
    }
}


Measured memory_bytes: 94440
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<deque>
#include<string>
#include<map>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>

using namespace std;


int main(void) {
	int n; cin >> n;
	int a[n]; int i, sum = 0;

	for (i = 0; i < n; i++) { cin >> a[i]; }

	for (i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) {
			sum++;
			i++;
		}
	}
  
  cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256