akhauriyash/Code-Regression huggingface dataset:
Module Module1
    Sub Main()
            Dim N As Integer = Integer.Parse(Console.ReadLine)
            Dim TA() As String = Console.ReadLine.Split(" ")
            Dim H() As String = Console.ReadLine.Split(" ")
            Dim minNo As Integer = 0
            Dim minAns As Double = Double.MaxValue
            Dim nowWork As Double
            For i As Integer = 0 To H.Length - 1
                nowWork = System.Math.Abs(TA(1) - (Integer.Parse(TA(0)) - (Integer.Parse(H(i)) * 0.006)))
                If nowWork < minAns Then
                    minNo = i
                    minAns = nowWork
                End If
            Next
            Console.WriteLine(minNo + 1)
    End Sub
End Module


Measured memory_bytes: 11164
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    for (auto &&i : a) {
        cin >> i;
    }
    vector<pair<int, int>> x(M);
    REP(i, M) cin >> x[i].second >> x[i].first;
    ll ans = 0;
    SORT(a);
    RSORT(x);
    int now = 0;
    for (auto &&i : a) {
        if (now < M && i < x[now].first) {
            ans += x[now].first;
            x[now].second--;
        } else {
            ans += i;
        }
        if (x[now].second == 0 && now != M)
            now++;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using ll = long long;
using namespace std;

int main(){
    ll n;
    char ed;
    bool flag = true;
    string str;
    cin >> n;
    set<string> moji;
    cin >> str;
    ed = str[str.size()-1];
    moji.insert(str);
    for(ll i=1;i<n;i++){
        cin >> str;
        if(str[0]!=ed) flag = false;
        ed = str[str.size()-1];
        if(moji.find(str)!=moji.end())  flag = false;
        moji.insert(str);
    }
    if(flag) cout << "Yes\n";
    else    cout << "No\n";
    return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	bool snuke[N];
	for (int i = 0; i < N; i++) snuke[i] = true;

	int d;
	for (int i = 0; i < K; i++) {
		cin >> d;
		for(int j = 0; j < d; j++) {
			int A;
			cin >> A;
			snuke[A - 1] = false;

		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if(snuke[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
#define ll long long

const int N = 10005;
int h,n,sum;
ll ans;
int main() {
  scanf("%d", &h);
  scanf("%d", &n);
  int a[n];
  sum = 0;
  for(int i = 0; i < n; ++i){
    scanf("%d", a + i);
    sum += a[i];
  }

  if(sum >= h) printf("Yes\n");
  else printf("No\n");

	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();

		int tmpt = 0;
		int tmpa = 0;
		int tmpb = 0;
		int tmpt2 = 0;
		int tmpa2 = 0;
		int tmpb2 = 0;
		int t;
		int a;
		int b;

		for(int i=0;i<N;i++){
			t = scanner.nextInt();
			a = scanner.nextInt();
			b = scanner.nextInt();
			tmpt = t;
			tmpa = a;
			tmpb = b;
			t = t - tmpt2;
			a = a - tmpa2;
			b = b - tmpb2;
			tmpt2 = tmpt;
			tmpa2 = tmpa;
			tmpb2 = tmpb;
			if(Math.abs(a)+Math.abs(b)>t){
				System.out.println("No");
				return;
			}
			if((Math.abs(a)+Math.abs(b))%2!=t%2){
				System.out.println("No");
				return;
			}
		}
      	System.out.println("Yes");
	}
}

Measured memory_bytes: 86404
n = int(input())
t=0
A=n//1000
B=(n-A*1000)//100
C=(n-A*1000-B*100)//10
D=n%10

for i in range(8):
    k=A
    if i%2==0:
        k+=B
        p="+"
    else:
        k-=B
        p="-"
    if (i//2)%2==0:
        k += C
        q="+"
    else:
        k -= C
        q="-"
    if (i//4)%2==0:
        k += D
        r="+"
    else:
        k -= D
        r="-"
    if k==7:
        a=p
        b=q
        c=r
        t=1
if t>0:
    x=str(A)+a+str(B)+b+str(C)+c+str(D)+"=7"
    print(x)


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

void solve()
{
    int N; cin >> N;
    int ans = 0;
    REP(i, N)
    {
        int l, r; cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

Measured memory_bytes: 256
n, a, b = list(map(int, input().split()))
p = (10 ** 9) + 7

def powmod(x, exp, mod):
    if(exp == 1):
        return x % mod

    if(exp % 2 == 1):
        return (x * powmod(x, exp - 1, mod)) % mod

    x = powmod(x, exp / 2, mod)

    return (x * x) % mod

# nCrを計算するが、nもrも巨大なためフェルマーの小定理を利用する
# x = nPr
# y = r!
# x / y ≡ x * y^-1
# p を法とした時、掛けるたびにmodをとった数同士の割り算はうまくいかない
# フェルマーの小定理から
# y^(p-1) ≡ 1
# y * y^(p-2) ≡ 1
# y^(p-2)がyの逆元と同じ振る舞いをするのでy^(p-2)を掛ける
def combination(n, r, mod):
    x = 1
    y = 1

    for i in range(r):
        x *= n - i # n * (n - 1) * (n - 2) * ... * (n - i + 1)
        x %= mod
        y *= i + 1 # r * (r - 1) * (r - 2) * ... * 2 * 1 を逆さまにかけていく
        y %= mod

    return x * powmod(y, mod - 2, mod) % mod


total = powmod(2, n, p) - 1 #1本も花を選ばないパターンは除外する
comb_a = combination(n, a, p)
comb_b = combination(n, b, p)


print((total - comb_a - comb_b) % p)


Measured memory_bytes: 3188
a,b,c = gets.split.map(&:to_i);
k = gets.to_i

if a >= b and a >= c
	k.times do
		a *= 2
	end
	puts "#{a + b + c}"
elsif b >= a and b >= c
	k.times do
		b *= 2
	end
	puts "#{a + b + c}"
else
	k.times do
		c *= 2
	end
	puts "#{a + b + c}"
end

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  std::vector<long long> B(N);
  map<ll, ll> m;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    B[i] = A[i];
    m[A[i]]++;
  }

  sort(all(B));
  ll max_num = *max_element(all(A));

  rep(i, 0, N) {
    if (max_num != A[i]) {
      cout << max_num << endl;
      continue;
    }

    if (m[A[i]] == 1) {
      cout << B[N - 2] << endl;
      continue;
    }

    cout << A[i] << endl;
  }
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 12160
import java.util.*;

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

        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n];
        int[] d = new int[n+1];
        d[0] = 0;
        for(int i = 0; i < n; i++){
            l[i] = sc.nextInt();
        }
        int count = 1;
        for(int i = 1; i < n+1; i++){
            d[i] = d[i-1] + l[i-1];
            if (d[i] <= x)
                count++;
        }
        System.out.println(count);
        sc.close();  
    }
}

Measured memory_bytes: 21588
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 3e4+5;
int n;
int main()
{
    n = read();
    if(n == 3) return puts("2 3 25"), 0;
    for(int i = 1, j = n-1; i <= n; ++i, --j)
        if(i%2 == 0&&j%3 != 1&&i <= 5000&&j <= 15000)
        {
            for(int k = 1; k <= i; ++k) printf("%d ", 6*k-3);
            for(int k = 1; k <= j; ++k) printf("%d ", 2*k);
            return puts(""), 0;
        }
    return 0;
}

Measured memory_bytes: 256
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[0] - b[0], a[1] - b[1]]
w = t[0] * d[0] + t[1] * d[1]
if w < 0:
    d[0] *= -1
    d[1] *= - 1
    w *= -1
if t[0] * d[0] + t[1] * d[1] == 0:
    print("infinity")
else:
    min, max = 0, 1000000000000000
    while max - min > 1:
        mid = (min + max) // 2
        dest = w * mid
        ok = False
        for i in range(2):
            dest += d[i] * t[i]
            if dest <= 0:
                ok = True
        if ok:
            min = mid
        else:
            max = mid
    now = w * (min - 10)
    ans = 2 * (min - 10) - 1
    if ans < 0:
        ans = 0
        now = 0
    i, last = 0, 0
    while True:
        new = now + d[i] * t[i]
        last += 1
        if (now < 0 and new > 0) or (now > 0 and new < 0) or new == 0:
            ans += 1
            last = 0
        now = new
        i = 1 - i
        if last > 2:
            break
    print(ans)


Measured memory_bytes: 3192
//16-2 ????????±????????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    int zekken[100];
    for(int i=0; i<N; i++){
        cin >> zekken[i];
    }
    for(int i=1; i-1<M; i++){
        for(int l=0; l<N-1; l++){
            if(zekken[l]%i > zekken[l+1]%i){
                int tmp = zekken[l];
                zekken[l] = zekken[l+1];
                zekken[l+1] = tmp;
            }
        }
    }
    for(int i=0; i<N; i++){
        cout << zekken[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(m)]
a.sort(key=lambda x:x[1])
bridge = [a[0][1]-1]
for i in range(1,m):
    if a[i][0] > bridge[-1]:
        bridge.append(a[i][1]-1)
print(len(bridge))

Measured memory_bytes: 29028
#include <stdio.h>


int main(){
	
	int N;
	int i,key[1000];
	scanf("%d",&N);
	for (i = 1; i <= N; i++)	{
		scanf("%d",&key[i]);
	}

	N++;

	for(i = 1; i < N; i++){
		printf("node %d: key = %d, ",i,key[i]);
		
		if(i != 1){
			printf("parent key = %d, ",key[i/2]);
		}
		if(2*i < N){
			printf("left key = %d, ",key[2*i]);
		}
		if(2*i + 1 < N) {
			printf("right key = %d, ",key[2*i+1]);
		}
		printf("\n");
	}
	return 0;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    string s = a + b + c;
    if(s=="110"||s=="001") P("Open");
    else P("Close");
    return 0;
}

Measured memory_bytes: 3180
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int n;
	while (cin >> n, n) {
		map<int, int>mp;
		map<int, bool>check;
		vector<int>id(n);
		bool f(false);
		rep(i, 0, n) {
			int p, q; cin >> id[i] >> p >> q;
			mp[id[i]] += p*q;
			check[id[i]] = false;
		}
		rep(i, 0, n) {
			if (check[id[i]] == false) {
				check[id[i]] = true;
				if (mp[id[i]] >= 1000000) {
					cout << id[i] << endl;
					f = true;
				}
			}
		}
		if (f == false)cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
	int n;
	cin >> n;
	str s;
	int a=0, b=0, c=0, d=0;
	REP(i, n) {
		cin >> s;
		if(s == "AC") a++;
		if(s == "WA") b++;
		if(s == "TLE") c++;
		if(s == "RE") d++;
	}
	cout << "AC x " << a << endl;
	cout << "WA x " << b << endl;
	cout << "TLE x " << c << endl;
	cout << "RE x " << d << endl;
}


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

using namespace std;

int main(void){
	int a,b,c,d,e,f;
	
	while(cin >> a >> b >> c >> d >> e >> f){
		if((a|b|c|d|e|f) == 0) break;
		int MD = a + d, GG = b + e, GO = c + f;
		int ret = 0;
		
		for(int i=0;i<=2;i++){
			if(MD >= i && GG >= i && GO >= i)
				ret = max(ret, (MD-i)/3 + (GG-i)/3 + (GO-i)/ 3 + i);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int>A(4);
  for(int i=0;i<4;i++)cin>>A[i];
  sort(A.begin(),A.end());
  cout<<(A[0]==1&&A[1]==4&&A[2]==7&&A[3]==9? "YES":"NO")<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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

int main(int argc, char* argv[]) {
	int n,x,y;
	cin >> n >> x >> y;
  
	vector<ll> ans(n+1);
	int k = y - x + 1;
	if ((y - x + 1) % 2) {
		rep1(i, n-1) {
		  int ans0 = 0;
			if (i < n - y + x + 1) ans0 += n - y + x + 1 - i;
			if (i <= k / 2) ans0 += k;
			if (i == 1) ans0--; //XY
			ans[i] += ans0;
		}

		for (int i = x+1; i <= x + k / 2; i++) {
		  rep1(j,x-1) 
			  if (i == x+1) ans[i-j]++;
			  else ans[i - j] += 2;
		}
		for (int i = y - 1; i >= y - k / 2; i--) {
			for(int j = y+ 1; j <= n; j++) 
			  if (i == y-1) ans[j-i]++;
			  else ans[j - i] += 2;
		}
	}
	else {
		rep1(i, n-1) {
			int ans0 = 0;
			if (i < n - y + x + 1) ans0 += n - y + x + 1 - i;
			if (i < k / 2) ans0 += k;
			if (i == k / 2) ans0 += k / 2;
			if (i == 1) ans0--; //XY
			ans[i] += ans0;
		}

		for (int i = x + 1; i <= x + k / 2; i++) {
			rep1(j, x - 1) 
			  if (i == x + k / 2 || i == x+1) ans[i-j]++; 
			  else ans[i - j] += 2;
		}
		for (int i = y - 1; i >= y - k / 2; i--) {
			for (int j = y + 1; j <= n; j++)
			  if (i == y - k/2 || i == y - 1) ans[j-i]++;
			  else ans[j - i] += 2;
		}
	}

	rep1(i,n-1) cout << ans[i] << endl;
	return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll s;
    cin >> s;
    set<ll> S; 
    S.insert(s);
    for(int i = 2;; i++) {
        if (s % 2 == 0) s = s / 2; else s = 3 * s + 1;
        if (S.find(s) != S.end()) {
            cout << i << endl;
            break;
        }
        S.insert(s);
    }
    
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();

    #ifdef LOCAL_ENV
    assert(cin.rdstate() & ios_base::eofbit);
    #endif
}

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

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.size();
  vector<char> a(s.size()), b(2*s.size());
  
  for(int i = 0; i < n; i++){
  	a.at(i) = t.at(i);
    b.at(i) = s.at(i);
    b.at(i+n) = s.at(i);
  }
  
  bool ans = false;
  
  for(int i = 0; i < n; i++){
  	int count = 0;
  	for(int j = 0; j < n; j++){
    	if(a.at(j) == b.at(j+i)){
        	count++;
        }
    }
  
  	if(count == n){
    	ans = true;
    }
  }
  if(ans){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MOD 1000000007

int main() {
	int n = ri();
	int k = ri();
	int a[n];
	for (auto &i : a) i = ri();
	int dp[n + 1][256];
	memset(dp, 0, sizeof(dp));
	
	auto add = [&] (int &a, int b) {
		a += b;
		if (a >= MOD) a -= MOD;
	};
	
	dp[0][0] = 1;
	for (auto i : a) for (int j = n; j--; ) for (int k = 0; k < 256; k++) if (dp[j][k]) add(dp[j + 1][k ^ i], dp[j][k]);
	int fact = 1;
	int res = 0;
	for (int i = 1; i <= n; i++) {
		fact = (int64_t) fact * i % MOD;
		res = (res + (int64_t) dp[i][k] * fact) % MOD;
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

ll powll(ll n,ll k){ ll ret=1; while(k){ if(k&1)ret=ret*n; n=n*n; k>>=1; } return ret; }

int main(){
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  int n=a+b+1;
  rep(i,n){
    if(0<=i && i<a){
      if('0'<=s[i] && s[i]<='9'){
        continue;
      } else {
        cout << "No" << endl; return 0;
      }
    }
    if(i==a){
      if('-'==s[i]){
        continue;
      } else {
        cout << "No" << endl; return 0;
      }
    }
    if(a+1<=i && i<n){
      if('0'<=s[i] && s[i]<='9'){
        continue;
      } else {
        cout << "No" << endl; return 0;
      }
    }
  }
  cout << "Yes" << endl;

//  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=0;
string s;
int n;
void insortPlus(int cnt,vector<bool> b){
    if(cnt==n){
        int j=0;
        for(int i = 0;i < b.size();i ++){
            if(b[i]) {ans += stoll(s.substr(j,i+1-j));j=i+1;}
        }
        ans += stoll(s.substr(j,s.size()-j));
        return;
    }
    insortPlus(cnt+1,b);
    b[cnt] = 1;
    insortPlus(cnt+1,b);
}

int main(){
    cin >> s;
    vector<bool> b(s.size()-1);
    n=s.size()-1;
    insortPlus(0,b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int k, x, y;
    cin >> k >> x >> y;
    int flagx = 0, flagy = 0;
    if(x < 0){
        flagx = 1;
        x *= -1;
    }
    if(y < 0){
        flagy = 1;
        y *= -1;
    }

    vector<P> ans;
    int nx = 0, ny = 0;
    if((x+y)%2==0){
        int loop = 0;
        while(x-nx+y-ny>=2*k){
            if(x-nx>=k){
                nx += k;
            }else{
                ny += k;
            }
            ans.push_back(P(nx,ny));
            loop++;
        }
        if(loop%2&&k%2){
            rep(i,k){
                if(nx < x) nx++;
                else ny++;
            }
            ans.push_back(P(nx,ny));
        }
        if(nx==x&&ny==y){
            ;
        }else if(x-nx+y-ny==k){
            ans.push_back(P(x,y));
        }else{
            int half = (x-nx+y-ny)/2;
            rep(i,half){
                if(nx < x){
                    nx++;
                }else{
                    ny++;
                }
            }
            rep(i,k-half){
                if(nx >= x) nx++;
                else ny--;
            }
            ans.push_back(P(nx,ny));
            ans.push_back(P(x,y));
        }
    }else{
        if(k % 2 == 0){
            cout << - 1 << endl;
            return 0;
        }
        while(x-nx+y-ny>=3*k){
            if(x-nx>=k){
                nx += k;
            }else{
                ny += k;
            }
            ans.push_back(P(nx,ny));
        }
        if(nx==x&&ny==y){
            ;
        }else if(x-nx+y-ny==k){
            ans.push_back(P(x,y));
        }else{
            if(x-nx>=k){
                nx += k;
            }else if(x-ny>=k){
                ny += k;
            }else{
                rep(i,k){
                    if(nx < x) nx++;
                    else ny++;
                }
            }
            ans.push_back(P(nx,ny));
            if(ny > y){
                int half = (ny-y)/2;
                rep(i,half) ny--;
                rep(i,k-half) nx++;
                ans.push_back(P(nx,ny));
            }else{
                int half = (x-nx+y-ny)/2;
                rep(i,half){
                    if(nx < x){
                        nx++;
                    }else{
                        ny++;
                    }
                }
                rep(i,k-half){
                    if(nx >= x) nx++;
                    else ny--;
                }
                ans.push_back(P(nx,ny));
            }
            ans.push_back(P(x,y));
        }
    }
    int n = ans.size();
    cout << n << endl;
    rep(i,n){
        if(flagx) ans[i].first *= -1;
        if(flagy) ans[i].second *= -1;
        cout << ans[i].first << ' ' << ans[i].second << endl;
    }
    return 0;
}




Measured memory_bytes: 5364
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

int main(){
  int r,g,b;
  cin>>r>>g>>b;
  cout<<(((100*r+10*g+b)%4==0)?"YES":"NO")<<endl;
  return 0;
}

  



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String ssa = sc.next();
    String ssb = sc.next();
    String ssc = sc.next();
    int la = ssa.length();
    int lb = ssb.length();
    int lc = ssc.length();
    int pa = 0;
    int pb = 0;
    int pc = 0;
    int h = 0;
    String ans = "A";
    for(int i = 0; i < (la + lb + lc); i++) {
      if(h == 0) {
        if(pa < la) {
          if(ssa.charAt(pa) == 'a') {
            h = 0;
          } else if(ssa.charAt(pa) == 'b') {
            h = 1;
          } else {
            h = 2;
          }
          pa++;
        } else {
          break;
        }
      } else if(h == 1) {
        if(pb < lb) {
          if(ssb.charAt(pb) == 'a') {
            h = 0;
          } else if(ssb.charAt(pb) == 'b') {
            h = 1;
          } else {
            h = 2;
          }
          pb++;
        } else {
          ans = "B";
          break;
        }
      } else {
        if(pc < lc) {
          if(ssc.charAt(pc) == 'a') {
            h = 0;
          } else if(ssc.charAt(pc) == 'b') {
            h = 1;
          } else {
            h = 2;
          }
          pc++;
        } else {
          ans = "C";
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23636
#include <stdio.h>
#include <string.h>
#define MAX 200
char S[MAX];
char T[MAX];
int main(void){
     int n;scanf("%d", &n);
     scanf("%s%s", S,T);
    for (int i = 0; i <n ; ++i) {
        printf("%c%c", S[i], T[i]);
    }
}

Measured memory_bytes: 128
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<string>
#include <stdlib.h>
using namespace std;

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         vcl            vector<ll>
#define         pb             push_back
#define         prl            pair< ll , ll >
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         Faysal         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){Faysal

    lli ans,sum,tot,cnt,mx,mn,idx,chk,rem,ret,tmp,mid,lft,rgt,pos;

    lli tc,n,m,a,b,c,d,g,h,l,r,x,y,i,j,k;

    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])yes;
    else
        no;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int W, H,x,y,r;

	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	W -= r, H -= r;
	if (r <= x && x <= W && r <= y && y <= H) printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MAXN = 3e5 + 123;
const ld EPS = 1e-12;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

ll n, ans, dp[MAXN], l[MAXN], r[MAXN], z[MAXN];
pair<ll, ll> a[MAXN];

void solve(){
	cin >> n;

	for(ll i = 1, x, y; i <= n; ++i){
		cin >> x >> y;
		a[i].fr = x - y;
		a[i].sc = x + y;
	}

	sort(a + 1, a + n + 1);

	for(int i = 1; i <= n; ++i){
		l[i] = a[i].fr;
		r[i] = a[i].sc;
	}

	for(int i = 1; i <= n; ++i){
		dp[i] = max(dp[i], z[i]);
		dp[i]++;
		ll x = lower_bound(l + 1, l + n + 1, r[i]) - l;
		z[x] = max(z[x], dp[i]);
		z[i + 1] = max(z[i], z[i + 1]);
		ans = max(ans, dp[i]);
	}

	cout << ans;
}

int main(){

	faster();
 
	int T = 1;
	// cin >> T;
	
	while(T--){
		solve();
	}
 
	return 0;
}

Measured memory_bytes: 10240
# include<stdio.h>
int main(void)
{
	int a,b,tem;
    scanf("%d %d",&a,&b);
  	if(a<b){tem = a; a = b; b = tem;}//a>=b
  	if(a>=b+1){printf("%d",2*a-1);return 0 ;}
  	printf("%d",a+b);

}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

#define INF (ll)(1e9+7)

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n;
    cin >> n;
    vll nums(n);
    FOR(i, n) cin >> nums[i];
    vll dp(n, INF);
    dp[0] = 0;
    FORN(i, 1, n)
    {
        dp[i] = abs(nums[i] - nums[i - 1]) + dp[i - 1];
        if (i >= 2) dp[i] = min(dp[i], abs(nums[i] - nums[i - 2]) + dp[i - 2]);
    }
    cout << dp[n - 1] << '\n';
}



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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(long long i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


std::string replace_all(std::string &replacedStr, std::string from, std::string to) {
    unsigned int pos = replacedStr.find(from);
    int toLen = to.length();
 
    if (from.empty()) {
        return replacedStr;
    }
 
    while ((pos = replacedStr.find(from, pos)) != std::string::npos) {
        replacedStr.replace(pos, from.length(), to);
        pos += toLen;
    }
    return replacedStr;
}
int main() {
int A, B, C, D;
cin >> A >> B >> C >> D;

int L = A + B;
int R = C + D;

if(L > R) print("Left");
if(L == R) print("Balanced");
if(L < R) print("Right");
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
//change null_type here for map/set
typedef tree<int,null_type,less<int>,rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;
typedef long long int  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define F first
#define S second

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    x*=sgn; return ~c;
}
///START HERE
///indexed_set pbd;
//pbd.insert()
//auto x = pbd.find_by_order(2);
//int od=pbd.order_of_key(7)
///rope<int> rp;
//rp.push_back()
//RandomAccess like vector
//mutable_begin, mutable_end()

int main(){
    ///read()+printf
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //fast;
    int c=0,l,r,d;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++){
        if(i%d==0){
            c++;
        }
    }
    cout<<c;


    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int div(int n){
    int c=1,temp=7;
    while(temp%n!=0){
        temp=(temp%n)*10+7;
        c++;
    }
    return c;
}
int main()
{
    int n;
    cin>>n;
    if(n%2==0 || n%5==0){
        cout<<-1;
        return 0;
    }
    cout<<div(n);
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
/*#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)

////////////////////////////////////////

ll inf= 1000000005;

int main(){
    int n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    rep(i,0,n-1)a[i]=a[i]-i-1;
    ll l=-inf ,r=inf;
    while(l+1<r){
        ll m1=(2*l+r+3*inf)/3-inf,m2=(l+2*r+3*inf)/3-inf;
        ll ansm1=0,ansm2=0;
        rep(i,0,n-1){
            ansm1+=abs(m1-a[i]);
            ansm2+=abs(m2-a[i]);
        }
        if(ansm1<=ansm2)r=m2;
        else l=m1+1;
    }
   // cout<<l<<endl;
    ll ans=0;
    rep(i,0,n-1){
        ans+=abs(l-a[i]);
    }
    cout<<ans<<endl;
    
    return 0;
}





Measured memory_bytes: 1792
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n, x[100001], y[100001];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	set < pair<int, int> >toA, toB;
	for (int i = 0; i < n; i++)toA.emplace(x[i], i);
	for (int i = 0; i < n; i++)toB.emplace(y[i], i);

	typedef pair<int, int> P;
	priority_queue<P, vector<P>, greater<P>>que;
	long long ret = 0;
	que.emplace(0, 0);
	bool used[100001] = {};
	while (!que.empty()) {
		int aa = que.top().first;
		int bb = que.top().second;
		que.pop();
		if (used[bb]++)continue;
		ret += aa;

		pair< int, int > qq(x[bb], bb);
		auto s = toA.lower_bound(qq);
		if (s != toA.begin()) que.emplace(x[bb] - prev(s)->first, prev(s)->second);
		++s;
		if (s != toA.end()) que.emplace(s->first - x[bb], s->second);

		qq.first = y[bb];
		auto s2 = toB.lower_bound(qq);
		if (s2 != toB.begin()) que.emplace(y[bb] - prev(s2)->first, prev(s2)->second);
		++s2;
		if (s2 != toB.end()) que.emplace(s2->first - y[bb], s2->second);
	}
	cout << ret << endl;
}

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

int main() {
    int time;
    int h;
    int m;
    int s;
    cin >> time;
    h = time / 3600;
    m = (time % 3600) / 60;
    s = time % 60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct R {
	int idx;
	int p;
};

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

	int n; cin >> n;

	map<string, vector<R>> restrants;
	FOR_LE(i, 1, n) {
		string s; cin >> s;
		int p; cin >> p;
		restrants[s].push_back(R{ i,p });
	}

	for (auto& elem : restrants) {
		vector<R> rs = elem.second;
		sort(rs.begin(), rs.end(), [](const auto& lhs, const auto& rhs) {
			return lhs.p > rhs.p;
			});
		for (auto& i : rs) {
			cout << i.idx << endl;
		}
	}

	return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;



int main() {
    string s, t; cin >> s >> t;
    int n = s.size();
    vector<vector<ll>> vec(30);
    for(ll i = 0ll; i < n; i++){
        int m = s[i] - 'a';
        vec.at(m).emplace_back(i);
    }
    ll res = 0ll;
    ll pointer = -1ll;
    rp(j, 0, int(t.size())) {
        int now_char = int(t[j] - 'a');
        if(int(vec.at(now_char).size()) == 0) {
            cout << -1 << endl;
            return 0;
        }
        else if(*(vec.at(now_char).end()-1) <= pointer) {
            res += n;
            pointer = *vec.at(now_char).begin();
        }
        else pointer = *upper_bound(vec.at(now_char).begin(), vec.at(now_char).end(), pointer);
    }
    res += pointer + 1;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4648
#include <iostream>
#include <cstdio>

using namespace std;

int n, k;
int h[100001];
int dp[100001];

int main(){
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++){
        scanf("%d", &h[i]);
        dp[i] = 999999999;
    }
    dp[1] = 0;
    for (int i = 2; i <= n; i++){
        for (int j = max(1, i-k); j <= i-1; j++){
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n;
int i;
int x;

struct Node {
  int k;
  struct Node *r;
  struct Node *l;
  struct Node *p;
};

struct Node *root;
struct Node *NIL;

void insert(int key){

  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));

  z->k = key;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->k < x->k) x = x->l;
    else x = x->r;
  }
  z->p = y;
  if(y == NIL) root = z;
  else{
    if(z->k < y->k) y->l = z;
    else y->r = z;
  }
}




void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d", u->k);
  preorder(u->l);
  preorder(u->r);
}

void inorder(struct Node *u){
  if(u == NIL) return;
  inorder(u->l);
  printf(" %d", u->k);
  inorder(u->r);
}


char *comin = "insert"; //insert
char *compr = "print"; //print

int main(){

  char *com;

  com = (char*)malloc(10*sizeof(char));  
  
  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%s", com);



    
    if(strncmp(com,comin,6)==0){
      scanf("%d",&x);
      insert(x);
    }



    
    else if(strncmp(com,compr,5)==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }




  
  return 0;
}



Measured memory_bytes: 25196
from collections import deque

h, w = map(int, input().split())
sx, sy = map(int, input().split())
gx, gy = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1

moves = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ts = [(x, y) for x in range(-2, 3)
      for y in range(-2, 3) if not (x, y) in moves and (x, y) != (0, 0)]

grid = [list(map(str, input().rstrip())) for _ in range(h)]

q = deque([(sx, sy)])
qq = deque([(sx, sy)])

grid[sx][sy] = 0

while len(q) > 0 or len(qq) > 0:
    while q:
        (cx, cy) = q.popleft()
        for m in moves:
            nx, ny = cx + m[0], cy + m[1]
            if 0 <= nx < h and 0 <= ny < w:
                if grid[nx][ny] == ".":
                    grid[nx][ny] = grid[cx][cy]
                    q.append((nx, ny))
                elif grid[nx][ny] == "#":
                    qq.append((cx, cy))
    while qq:
        (cx, cy) = qq.popleft()
        for t in ts:
            nx, ny = cx + t[0], cy + t[1]
            if 0 <= nx < h and 0 <= ny < w:
                if grid[nx][ny] == ".":
                    grid[nx][ny] = grid[cx][cy] + 1
                    q.append((nx, ny))

print(grid[gx][gy] if grid[gx][gy] != "." else -1)

Measured memory_bytes: 164704
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=3005;
int h[N],ne[N<<1],to[N<<1],sg[N],a[N];
int n,tot;
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
void dfs(int x,int las) {
	sg[x]=0;
	for(RI i=h[x];i;i=ne[i]) {
		if(to[i]==las) continue;
		dfs(to[i],x);
		if(a[to[i]]<a[x]&&!sg[to[i]]) sg[x]=1;
	}
}
int main()
{
	int x,y;
	n=read();
	for(RI i=1;i<=n;++i) a[i]=read();
	for(RI i=1;i<n;++i) x=read(),y=read(),add(x,y),add(y,x);
	for(RI i=1;i<=n;++i) {dfs(i,0);if(sg[i]) printf("%d ",i);}
	return 0;
}

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

int N,K,i,sum;

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn = 555;
int M(){
    int h, w;
    if(!(cin >> h >> w)) return 0;
    map<char, int> qtd;
    for(int e = 0; e < h; e++)
        for(int f = 0; f < w; f++){
            char v;
            cin >> v;
            qtd[v]++;
        }
    int qtd_border = h * w;
    if((h%2) && (w%2)) qtd_border -= w + h - 1;
    else if(h%2) qtd_border -= w;
    else if(w%2) qtd_border -= h;
    int used_border = 0;
    //if(h >= 2 && w >= 2){
        for(auto & v : qtd) {
            int take = min((qtd_border - used_border)/4, v.second / 4);
            used_border += take * 4;
            v.second -= take * 4;
        }
    //}
    if(qtd_border != used_border){
        printf("No\n");
        return 1;
    }
    if((h%2) || (w%2)){
        for(auto & v : qtd) v.second %= 2;
        int oo = 0;
        for(auto & v : qtd) oo += v.second == 1;
        if(oo == (min(h%2, w%2))) printf("Yes\n");
        else printf("No\n");
    } else {
        for(auto & v : qtd) if(v.second != 0){
            printf("No\n");
            return 1;
        }
        printf("Yes\n");
    }
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,i,a[100000],b,c;
int main(){
  cin>>n;
  for(;i<n;a[i]=c-1,i++)cin>>c;
  for(i=0;i<n;i++){
    if(b==1)return cout<<i,0;
    b=a[b];
  }
  cout<<-1;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  if(S.size()>3&&S.at(0)=='Y'&&S.at(1)=='A'&&S.at(2)=='K'&&S.at(3)=='I')cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256