akhauriyash/Code-Regression huggingface dataset:
open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module ARC083 =
    let private Mod = 1000000007L

    let private RestoringRoadNetwork () =
        let n = ReadNextInt ()
        let m = Array.init n (fun _ -> ReadListOf int64 n |> Seq.toArray)
        let g x y = m.[x].[y]
        let mutable fail = false
        let mutable total = m |> Seq.map Seq.sum |> Seq.sum
        total <- total / 2L
        //printfn "total = %d" total
        for i in [0..n-1] do
            for j in [i+1..n-1] do
                let mutable minD = System.Int64.MaxValue
                for k in [0..n-1] do
                    if i <> k && j <> k then
                        minD <- min minD (g i k + g k j)
                let c = g i j
                if minD < c then fail <- true
                elif minD = c then total <- total - c
        if fail then -1L else total
        |> printfn "%d"

    let Entry = RestoringRoadNetwork

ARC083.Entry ()

Measured memory_bytes: 26156
import java.util.*;

public class Main {
    static int MOD = 1000000007;
	static int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        while (is_prime(x) == false) {
            x++;
        }
        
        System.out.println(x);
    }

    public static boolean is_prime(int n) {
        for (int i = 2; i*i <= n; i++) {
            if (n % i == 0) return false;
        }
        return true;
    }
}

Measured memory_bytes: 21844
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
    int a[101][101];
	int n;
	int m;
	int b[101];
	int c;
    cin>>n>>m;

	for( int i=1; i<n+1; i++){
		for( int j=1; j<m+1; j++){
			cin>>a[i][j];
		}
	}
	for( int i=1; i<m+1; i++)cin>>b[i];
	for( int i=1; i<n+1; i++){
		c=0;
		for( int j=1; j<m+1; j++){
			c+=a[i][j]*b[j];
		}
		cout<<c<<endl;
	}

}

Measured memory_bytes: 3124
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N, C, K;
int A[MAXN];

void input()
{
    read(N); read(C); read(K);
    for (int i = 1; i <= N; ++i) {
        read(A[i]);
    }
}

void solve()
{
    std::sort(A + 1, A + N + 1);

    int p = 1;
    int ans = 0;
    for (int i = 2; i <= N; ++i) {
        if (i - p == C || A[i] - A[p] > K) {
            ++ans;
            p = i;
        }
    }
    ++ans;

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

int main()
{
#ifdef __DEBUG
    freopen("A.in", "r", stdin);
    freopen("A.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 踏破铁鞋无觅雪，得来全不费功夫。


Measured memory_bytes: 640
#include <stdio.h>
int main(){
    char p[101],s[101];
    int i=0,j=0,k=0,l=0,m=0;
    int ans=0;
    for(i=0;i<101;i++){
        scanf("%c",&s[i]);
        if(s[i]=='\n')break;
    }
    for(j=0;j<101;j++){
    scanf("%c",&p[j]);
    if(p[j]=='\n')break;
    }   
    for(k=0;k<i;k++){
        if(s[k]==p[0]){
            for(l=0;l<j;l++){
                m=k+l;
                if(m>=i)m-=i;
                if(s[m]!=p[l])break;
                if(l==j-1)ans=1;
            }
        }
    }
    if(ans)printf("Yes\n");
    else printf("No\n");
    return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include<vector>
#include<tuple>

using namespace std;
int main(){
  int n,m,dif=0;
  int lmax = 0,rmin = 122222;
  cin >> n >> m;
  int l[122222],r[122222];
  for(int i=0;i<m;i++){
    cin >> l[i] >> r[i];
    rmin = min(rmin,r[i]);
    lmax = max(lmax,l[i]);
  }
  // rの最大値,lの最小値
  if(m==1){
    dif = r[0] - l[0] + 1;
  }else{
    dif = rmin - lmax + 1;
  }
  if(dif<0) dif = 0;
  cout << dif << endl;

}


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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b;
    scanf("%d %d", &a, &b);
    if (a > b) swap(a, b);
    for (int i = 0; i < b; i++) {
		printf("%d", a);
	}
    return 0;
}


Measured memory_bytes: 3712
x1,y1,x2,y2 = list(map(int,input().split()))
x3 = x2 - y2 + y1
y3 = y2 + x2 - x1
x4 = x1 - y2 + y1
y4 = y1 + x2 - x1
print('{} {} {} {}'.format(x3,y3,x4,y4))

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

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

int main(){
    int n, k; cin >> n >> k;
    string ans_st = "";
    int r = 0;
    int q = n;
    int count = 0;
    while(q > 0){
        // r = q % k;
        // ans_st += to_string(r);
        q = q / k;
        count++;
    }
    // reverse(ans_st.begin(), ans_st.end());
    // cout << stoi(ans_st) << endl;
    cout << count << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d %d', $n, $m);
$s = array_fill(1, $m, NULL);
for ($i  = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d', $a, $b);
    $s[$a][] = $b;
}

$cnt = 0;
$q = new SplPriorityQueue();
for ($i = 1; $i <= $m; $i++) {
    foreach ($s[$i] as $v) {
        $q->insert($v, $v);
    }
    if (!$q->isEmpty()) $cnt += $q->extract();
}
echo $cnt.PHP_EOL;

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

int main()
{
	int N;
	int A[100005], B[100005], C[100005];
	int64_t sum = 0;	
	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	for ( int i = 0; i < N; i++ ) {
		cin >> B[i];
	}
	for ( int i = 0; i < N; i++ ) {
		cin >> C[i];
	}
	sort(A, A + N);
	sort(C, C + N);
	for ( int i = 0; i < N; i++ ) {
		int64_t vl = lower_bound(A, A + N, B[i]) - A;
		int64_t vr = N - (upper_bound(C, C + N, B[i]) - C);
		sum += vl * vr;
	}
	cout << sum << endl;
	return ( 0 );
}


Measured memory_bytes: 1408
#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;

int main(){
  int n,m;
  cin >> n >> m;
  ll ans = n*(n-1)/2 + m*(m-1)/2;
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)1e5 + 100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n, was[maxn];
vi ans;
void solve(){
	cin >> n;
	if(n == 3){
		puts("2 5 63");
		return;
	}
	int s = 0;
	forn(i, 1, maxn){
		if(i % 2 == 0 || i % 3 == 0){
			ans.pb(i);
			was[i] = 1;
			s = (s + i) % 6;
			if(sz(ans) == n) break;
		}
	}
	int add = (6 - s) % 6;
	if(add){
		for(auto &x : ans){
			if(was[x + add]) continue;
			if((x + add) % 2 == 0 || (x + add) % 3 == 0){
				x += add;
				break;
			}
		}
	}
	for(auto x : ans) cout << x << " ";
}

int main () {
  solve();
}





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

using namespace std;
using ll = long long int;

constexpr ll Mod = 1000000000 + 7;

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

    ll ans = 0;
    for (ll i = k; i <= n + 1; i++)
    {
        ll min = (0 + i - 1) * (i) / 2;
        ll max = (n + n - i + 1) * (i) / 2;
        //cout << min << " " << max << endl;
        ans += (max - min + 1);
        ans %= Mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,m;
    cin>>n>>m;
    char a[n][m];
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<m;j++)
      {
        cin>>a[i][j];
      }
    }
    for(int i=0;i<=m+1;i++)
      cout<<"#";
    cout<<endl;
    for(int i=0;i<n;i++)
    {
      cout<<"#";
      for(int j=0;j<m;j++)
      {
        cout<<a[i][j];
      }
      cout<<"#"<<endl;
    }
    for(int i=0;i<=m+1;i++)
      cout<<"#";
    //cout<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <iomanip>
#include <functional>



using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  vector<double> a(n);
  double sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  
  double base=sum/(4*m);
  int count=0;
  for(int i=0;i<n;i++){
    if(a[i]<base){
      continue;
    }else{
      count++;
    }
  }
  
  if(count<m) cout<<"No";
  else cout<<"Yes";
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int N;
    string S;
    cin >>N;
    cin >>S;

    int total = 0;
    int flag = 0;
    rep(i,N){
        if(flag==0){
            if(S.at(i)=='A'){
                flag=1;
            }
        }else if(flag==1){
            if(S.at(i)=='B'){
                flag=2;
            }else{
                flag=0;

            if(S.at(i)=='A'){
                flag=1;
            }
            }
        }else if(flag==2){
             if(S.at(i)=='C'){
                 total++;
            }
                flag=0;

            if(S.at(i)=='A'){
                flag=1;
            }
        }
    }
    cout<<total<<endl;

    return 0;
}

Measured memory_bytes: 256
n = raw_input()
S = map(int, raw_input().split())
q = raw_input()
T = map(int, raw_input().split())

def BinarySearch(list, num):
	left = 0
	right = len(list) - 1
	while left <= right:
		mid = (left + right) / 2
		#print("left = {:}".format(left))
		#print("mid = {:}".format(mid))
		#print("right = {:}".format(right))
		#print("")
		if list[mid] == num:
			return 1
		elif list[mid] < num:
			left = mid + 1
			#print("left = {:}".format(left))
			#print("mid = {:}".format(mid))
			#print("right = {:}".format(right))
			#print("")
		else:
			right = mid - 1
			#print("left = {:}".format(left))
			#print("mid = {:}".format(mid))
			#print("right = {:}".format(right))
			#print("")
	return 0

cnt = 0
for i in T:
	cnt += BinarySearch(S, i)

print cnt

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

using namespace std;

string t;
int n , e , w , s , l;
int main()
{
	cin >> t;
	l = (int) t.size();
	for (int i = 0; i < l; i++)
	{
		if (t[i] == 'N')
		{
			n += 1;
		}
		else if (t[i] == 'S')
		{
			s += 1;
		}
		else if (t[i] == 'E')
		{
			e += 1;
		}
		else if (t[i] == 'W')
		{
			w += 1;
		}
	}
	if (w == 0 && e > 0)
	{
		cout << "No";
		return 0;
	}
	if (e == 0 && w > 0)
	{
		cout << "No";
		return 0;
	}
	if (n == 0 && s > 0)
	{
		cout << "No";
		return 0;
	}
	if (n > 0 && s == 0)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 256
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
ll a[10000];
int main() {
	int n;
	while (cin >> n, n) {
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			sum += a[i];
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] * n <= sum) {
				ans++;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3164
#!/usr/bin/env python3

def solve(K: int, A: int, B: int) -> bool:
    for x in range(A, B + 1):
        if x % K == 0:
            return True
    return False

# generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
def main():
    K = int(input())
    A, B = map(int, input().split())
    ans = solve(K, A, B)
    print(ans and 'OK' or 'NG')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll modpow(ll x, ll y, ll mod) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}*/
/*ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

signed main() {
	string s;
	ll n, m, k, a, b, c, cnt = 0, ans = 0;
	cin >> s;
	rep(i, s.size()) {
		cnt += (ll)(s[i] - '0');
	}
	if (cnt % 9 == 0) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    IO;
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = n - 1; i >= 1; i--)
    {
        if(arr[i - 1] > arr[i])
            --arr[i - 1];
    }
    bool ok = true;
    for(int i = 0; i < n - 1; i++)
    {
        if(arr[i] > arr[i + 1])
        {
            ok = false;
            break;
        }
    }
    if(ok)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 640
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
A=abs
c=sum(A(j-i)for i,j in zip(a,a[1:]))
for i,j,k in zip(a,a[1:],a[2:]):print(c-A(j-i)-A(k-j)+A(k-i))

Measured memory_bytes: 67288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    ll a[n];
    ll x[n];
    ll sum = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        sum += a[i];
    }
    sum /= 2;
    for(int i = 1;i < n;i += 2)sum -= a[i];
    x[0] = sum;
    for(int i = 1;i < n;i++)x[i] = a[i-1]-x[i-1];
    for(int i = 0;i < n;i++)cout << 2*x[i] << " ";
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
 
int a[100000][3], dp[100000][3];
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int n;
	cin >> n;
	for(int i=0; i<n; ++i)
		for(int j=0; j<3; ++j)
			cin >> a[i][j];
	for(int j=0; j<3; ++j)
		dp[0][j]=a[0][j];
	for(int i=1; i<n; ++i) {
		for(int j=0; j<3; ++j) {
			int mx=0;
			for(int k=0; k<3; ++k)
				if(k!=j)
					mx=max(dp[i-1][k], mx);
			dp[i][j]=mx+a[i][j];
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

Measured memory_bytes: 2560
#include <cstdio>
#include <utility>

int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    if(x < y) std::swap(x,y);

    while(x % y != 0){
        x = x % y;
        std::swap(x,y);
    }    
    printf("%d\n",y);

}


Measured memory_bytes: 2744
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (ll i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (ll i=0; i<n; ++i) in2(a[i].first, a[i].second);
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n-1; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto i : a)
const int mod = (int)(1e9) + 7;
//endregion

int n, m, k, total, maxi, t;
string a;

int main() {
    io();
    in2(n, k);
    vii arr;
    in(a);
    fori (i, n) {
        if (arr.empty() or arr.back().first != (a[i] - '0')) arr.pp(a[i] - '0', 1);
        else arr.back().second++;
    }
    t = 0;
    m = arr.size();
    forr (i, arr) {
        total += i.second;
        if (t == k) break;
        if (!i.first) t++;
    }
    maxi = total;
    for (int i=arr[0].first + 2*k; i<m; i+=2) {
        total += (arr[i].second - arr[i-2*k].second);
        if (i > 2*k) total -= arr[i-2*k-1].second;
        if (i<m-1) total += arr[i+1].second;
        maxi = max(total, maxi);
    }
    out(maxi);
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vint A(n);
  rep(i,n) cin >> A[i];
  vint ans(n);
  rep(i,n-1){
    ans[A[i]-1]++;
  }
  rep(i,n) cout << ans[i] << endl;
}

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

int main() {
  ll n;
  ll mod=1e9;
  cin >> n;
  cout << "0 0 1 1000000000 ";
  cout << (n+mod-1)/mod << " " << (mod-n%mod)%mod << endl;
}

Measured memory_bytes: 256
l=list(map(int,input().split()))
l = sorted(l, reverse=True)
count = 0
while True:
  if l[0] == l[1] == l[2]:
    break
  elif l[0] > l[1]:
    l[1] += 1
    l[2] += 1
  else:
    l[2] += 2
    
  l = sorted(l, reverse=True)
  count += 1
print(count)


Measured memory_bytes: 3064
/*
      author : Nishikawa
      created: 07.08.2020 23:45:32
*/

//ABC168D

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

const int INF = 1001001001;
vector<int> to[100005];//ある頂点から繋がっている頂点を記録


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

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

    queue<int> q;//queue構造によりBFSを行う
    vector<int> dist(n,INF);//目標の頂点までの最短距離
    vector<int> pre(n,-1);//直前の頂点を記録
    dist[0]=0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front(); q.pop();
       /* for(int i=0; to[v].size(); i++){
            if(dist[to[v][i]] != INF) continue;
            dist[to[v][i]] = dist[v]+1;
            pre[to[v][i]] = v;
            q.push(to[v][i]);
        }*/
        for(int u : to[v]){
            if(dist[u] != INF) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    for(int i=0;  i<n; i++){
        if(i == 0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;

/*
1~100000までの数それぞれについて、
・1以上i以下の数で、2017に似ている数の個数
を保持するs[i]を定義し、各クエリでs[r]-s[l-1]を計算する
*/

bool isprime(int x){
    int threshold = sqrt(x)+1;
    if(x==2) return true;
    for(int i=2; i<=threshold; i++){
        if(x%i==0) {
            return false;
        }
    }
    return true;
}

int s[100010];

void solve(){
    int q;
    cin >> q;
    rep(i,100001){
        if(i==0) s[i]=0;
        else if(i==1) s[i]=0;
        else if(i==2) s[i]=0;
        else{
            if(isprime(i)&&isprime((i+1)/2)) s[i]=s[i-1]+1;
            else s[i]=s[i-1];
        }
    }
    /*
    rep(i,100){
        cout << 2*i+3 << ":" << s[2*i+3] << endl;
    }
    cout << endl;
    */
    vector<int> ans;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        ans.emplace_back(s[r]-s[l-1]);
    }
    rep(i,q){
        cout << ans[i] << endl;
    }
}

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



Measured memory_bytes: 1528
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String args[]) throws IOException {
        FastReader s = new FastReader();
        int n = s.nextInt(), a = s.nextInt(), b = s.nextInt();
        if(Math.abs(a-b)%2==0){
            System.out.println("Alice");
        }else{
            System.out.println("Borys");
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23252
//04
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  bool cmp[30001]={};
  vector<int> prm;
  for(int i=2;i<=30000;i++){
    if(!cmp[i]){
      prm.push_back(i);
      for(int j=2;j*i<=30000;j++){
	cmp[i*j]=true;
      }
    }
  }
  for(int t;cin>>t,t;){
    int cn=0;
    for(int i=0;i<prm.size();i++){
      for(int j=i;j<prm.size();j++){
	int l=t-prm[i]-prm[j];
	cn+=prm[j]<=l&&l<prm[i]+prm[j]&&binary_search(prm.begin(),prm.end(),l);
      }
    }
    cout<<cn<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    vector<ll> a(n + 1); vin(a);
    vector<ll> b(n); vin(b);
    ll ans = 0;
    for(int i = n - 1; i >= 0; --i) {
        ans += min(a[i] + a[i + 1], b[i]);
        int d = max(b[i] - a[i + 1], 0LL);
        a[i] = max(a[i] - d, 0LL);
    }
    print(ans);

    return 0;
}


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

long int euc(long int x,long int y);

int main(void){
  long int n,x,ans;
  cin >> n >> x;
  if (n>x*2) ans=euc(n-x,x);
  else ans=euc(x,n-x);
  cout << ans*3 << endl;
  return 0;
}

long int euc(long int x,long int y){
  if (x%y==0) return x;
  long int nx,ny;
  nx=y;
  ny=x%y;
  return x-ny+euc(nx,ny);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N;
    cin >> N;
    V cnt(13, 0);
    cnt[0] = 1;
    rep(i, N){
        ll a;
        cin >> a;
        cnt[a]++;
    }
    ll flg = 0;
    if(cnt[0] >= 2 || cnt[12] >= 2)flg = 1;
    rep(i, 13)if(cnt[i] >= 3)flg = 1;
    if(flg){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    rep(i, 1 << 13){
        V v(25, 0);
        rep(j, 13){
            ll a = j, b = 24 - j;
            if(cnt[j] == 0)continue;
            if(cnt[j] == 2){
                v[a] = 1;
                v[b] = 1;
                continue;
            }
            if(i & (1 << j))v[a] = 1;
            else v[b] = 1;
        }
        ll tmp = 999;
        rep(j, 25)rep(k, 25)if(v[j] && v[k] && j != k)chmin(tmp, min(abs(j - k), 24 - abs(j - k)));
        chmax(ans, tmp);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char s[1010];
char t[1010];
int snum[1010],tnum[1010];
int ans[1000010];
int main(){
	scanf("%s %s",s,t);
	int sm=(s[0]=='-'),tm=(t[0]=='-');
	int sn=strlen(s+sm),tn=strlen(t+tm);
	for(int i=0;i<sn;i++)snum[i]=s[sn+sm-1-i]-'0';
	for(int i=0;i<tn;i++)tnum[i]+=t[tn+tm-1-i]-'0';
	for(int i=0;i<=1000;i++)for(int j=0;j<=1000;j++){
		ans[i+j]+=snum[i]*tnum[j];
	}
	for(int i=0;i<1000010;i++){
		ans[i+1]+=ans[i]/10;
		ans[i]%=10;
	}
	int digit=0;
	for(int i=0;i<1000010;i++)if(ans[i])digit=i;
	if((sm^tm)&&(digit>0||ans[0]!=0))printf("-");
	for(int i=digit;i>=0;i--)printf("%d",ans[i]);
	puts("");
}


Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;

int main(){
    int N; cin >> N;
    ll SUM=0, X=0, ans = 1e18;
    vector<int> A(N); for(int i = 0; i < N; i++) {cin >> A[i]; SUM += A[i];}
    for(int i = 0; i < N-1; i++){
        X += A[i];
        ll Y = SUM-X; 
        ans = min(ans, abs(X-Y));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
n=int(input())
w=[]
w.append(input())
for i in range(n-1):
    s=input()
    if  s[0]!=w[-1][-1]:
        pass
    else:
        w.append(s)

l=len(list(set(w)))

if l!=n:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long int n,ans=0,i,j,k;
    cin>>n;
    long long int a[n+1][n+1];
    bool p[n+1][n+1];
    memset(p,0,sizeof(p));
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cin>>a[i][j];
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++){
            if(i!=j)
                for(k=1;k<=n;k++){
                    if(a[i][j]==a[i][k]+a[k][j]&&k!=j&&k!=i)
                        p[i][j]=1;
                    if(a[i][j]>a[i][k]+a[k][j]){
                        cout<<"-1"<<endl;
                        return 0;
                    }
                }
        }
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(p[i][j]==0)
                ans+=a[i][j];
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
#define int long long
#define All(v) (v.begin(),v.end())
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {
	return a / gcd(a, b)*b;
}
int modpow(int a,int b){
    if(!b)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int fac(int a){
    int Ans=1;
    for(int i=1;i<=a;i++){
        Ans*=i;
        Ans%=MOD;
    }
    return Ans;
}//kaijo
int comb(int a,int b){
    return fac(a)*modpow(fac(a-b),MOD-2)%MOD*modpow(fac(b),MOD-2)%MOD;
}
signed main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((a*b)%2&&(c+d)%2)puts("No");
	else puts("Yes");
	return 0;
}





Measured memory_bytes: 3064
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

itta=[0]*(n+1)
now=1
cnt=1
while itta[now]==0:
    itta[now]=cnt
    now=a[now-1]
    if cnt==k:
        print(now)
        quit()
    cnt+=1

# print(itta)
# print(now)
# print(cnt)

k-=itta[now]-1
k%=cnt-itta[now]

while k>0:
    k-=1
    now=a[now-1]

print(now)

Measured memory_bytes: 103904
n = int(input())
s = []
t = []
for i in range(n):
    s1, t1 = map(str,input().split())
    s.append(s1)
    t.append(int(t1))
x = input()
for i in range(n):
    if s[i] == x:
        print(sum(t[i+1:]))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional> // for less 
    using namespace __gnu_pbds; 
    using namespace std;
    //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;    
    #define ll            long long
    #define pb            push_back
    #define ppb           pop_back
    #define si            set <ll>
    #define endl          '\n'
    #define fr            first
    #define sc            second
    #define mii           map<ll,ll>
    #define msi           map<string,ll>
    #define mis           map<ll,string>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define all(v)        v.begin(),v.end()
    #define sort(v)       sort(all(v))
    #define pii           pair<ll ,ll >
    #define vi            vector<ll >
    #define vii           vector<pair<ll,ll>>
    #define vs            vector<string>
    #define sz(x)         (ll)x.size()
    #define M             1000000007
    #define bs            binary_search
    #define rev(a)        reverse(all(a));
    #define sp(n)         setprecision(n)
    #define spl           " "
    #define arr(a,n)      rep(i,0,n) cin>>a[i]
    #define mod           998244353
    #define print_vector(a)  for(auto t:a) cout<<t<<" ";cout<<endl;
    #define print_arr(a,n)   rep(i,0,n) cout<<a[i]<<" "; cout<<endl;        
    #define show(a,n)     for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    #define N             100000000
    #define debug(x)      cout << #x << " is " << x << endl;
    #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    #define INF           1ll<<31
    #define hi            cout<<"hi"<<endl;
    const ll maxn=200005;
    void solve()
    {
      ll n,k;
      cin>>n>>k;
      ll t=n%k;
      cout<<min(t,abs(k-t))<<endl;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        //#endif
        ll t=1;
        //cin>>t;
        while(t--) solve();
    }
    
  

Measured memory_bytes: 256
a,b,c=map(int,input().split())
k=int(input())
import itertools
l=[0,1,2]
A=a
B=b
C=c
for V in itertools.combinations_with_replacement(l, k):
    v=list(V)
    A=a
    B=b
    C=c
    for i in range(k):
        if v[i]==0:
            A*=2
        elif v[i]==1:
            B*=2
        else:
            C*=2
    if A<B<C:
        print("Yes")
        quit()
print("No")

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define fore(i,a,b) for(int i = a; i < b; i++)
#define fst first
#define snd second
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define piii pair<int, pii>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

const int N_MAX = 1e6+15;

int main(){
    ll A;
    cin>>A;
    string B;
    cin>>B;
    int n=sz(B);
    int b=(int)(B[0]-'0');
    int c=(int)(B[2]-'0')*10+(int)(B[3]-'0');
    ll X=A*b;
    ll Y=A*c/100LL;
    cout<<X+Y<<endl;
    return 0;
}

Measured memory_bytes: 3628
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define S second
#define F first
#define PB push_back

ll stree[1000000],a[200000];

void update(ll left,ll right,ll node,ll val,ll pos)
{
    if(left==right) {
        a[pos]=val;
        stree[node]=val;
        return;
    }
    ll mid=(left+right)/2;
    if(left<=pos && pos<=mid)
        update(left,mid,2*node+1,val,pos);
    else
        update(mid+1,right,2*node+2,val,pos);
    stree[node]=max(stree[2*node+1],stree[2*node+2]);
}

ll query(ll left,ll right,ll node,ll st,ll end)
{
    if(right<st||left>end)
        return 0;
    if(left>=st&&end>=right)
        return stree[node];
    ll mid=(left+right)/2;
    return stree[node]=max(query(left,mid,2*node+1,st,end),query(mid+1,right,2*node+2,st,end));
}


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

    
    ll i,n;
    cin>>n;
    ll val[n],h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    for(ll i=0;i<n;i++){
        cin>>val[i];
    }
    ll maxi=0;
    for(ll i=0;i<n;i++)
    {
        ll sm=query(0,n-1,0,0,h[i]-1);
        sm+=val[i];
        //cout << sm << " ";
        update(0,n-1,0,sm,h[i]-1);
        if(sm>maxi)
            maxi=sm;

    }
    cout << maxi;
   
    return 0;
}


Measured memory_bytes: 9472
#include <iostream>

using namespace std;

int main()
{
    char a;
    int n,c=0;
    cin>>n;
    char arr[n-1];
    for(int i=0;i<n;i++){
    cin>>arr[i];}
    for(int i=0;i<n;i++){
        if (arr[i]=='A'&&arr[i+1]=='B'&&arr[i+2]=='C')
          c=c+1;}
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define inf 1e18
#define pre(x,y) fixed<<setprecision(y)<<x
#define pq priority_queue<int>
#define mpq priority_queue<int,vector<int>,greater<int>>
#define gcd(x,y) __gcd(x,y)
#define mp make_pair



int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,i;
    cin>>n>>k;
    vector<vector<int>> dp(n+1,vector<int>(k+1));
    vector<int> v(n+1);
    for(i=1;i<=n;i++) cin>>v[i];
    for(i=0;i<=k;i++)
    {
    	dp[1][i]=(i<=v[1])?1:0;
    }

    for(i=2;i<=n;i++)
    {
    	dp[i][0]=1;
    	for(int j=1;j<=k;j++)
    	{
    		dp[i][j]=(dp[i][j-1]+dp[i-1][j]-((j-v[i]-1>=0)?dp[i-1][j-v[i]-1]:0)+mod)%mod;
    	}
    }
    cout<<dp[n][k]<<endl;
	return 0;
}


Measured memory_bytes: 83044
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue> 
using namespace std;
#define INF 0x3f3f3f3f
int in[55];
int n,m,k;
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		memset(in,0,sizeof(in));
		int u,v;
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			in[u]++;
			in[v]++;
		}
		for(int i=1;i<=n;i++)
		{
			cout<<in[i]<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,K;
bool ans[110];
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    memset(ans,false,sizeof(ans));
    cin >> N >> K;
    for (int i = 0; i < K; i++)
    {
        int d; cin >> d;
        for (int i = 0; i < d; i++)
        {
            int a; cin >> a;
            ans[a] = true;
        }
        
    }
    
}

int solve(){
    vector<int> a;
    for (int i = 1; i <= N; i++)
    {
        if(ans[i]) a.push_back(i);
    }
    cout << N-a.size() << endl;
    
    return 0;
}   

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


Measured memory_bytes: 3652
from collections import defaultdict

n = int(input())
test_dict = defaultdict(list)
count = 1
for i in range(n):
    s,p = map(str,input().split())
    test_dict[s].append([int(p),count])
    #test_dict_order[s] +=count
    count += 1

for key,val in sorted(test_dict.items(), key=lambda x: x[0]):
    for j in sorted(val, key=lambda x:x[0], reverse=True):
        print(j[1])

Measured memory_bytes: 38384