akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 998244353//1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b,int m) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = powerwithoutmod(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int Q = 301;
const int logN = 16;

int st[N<<1];
int range_max(int l, int r) {
    int ret = 0;
    for (;l<r;l>>=1,r>>=1) {
        if (l&1) ret = max(ret,st[l++]);
        if (r&1) ret = max(ret,st[--r]);
    }
    return ret;
}
void update(int l, int val) {
    st[l]=val;
    for (l>>=1;l>0;l>>=1) {
        st[l] = max(st[l<<1],st[l<<1|1]);
    }
}
void solve() {
    int n;
    cin>>n;
    vector<pi> v(n);
    REP(i,0,n-1) {
        cin>>v[i].first>>v[i].second;
        v[i].second += v[i].first;
    }
    sort(all(v));

    vector<int> dp(n+1), nxt(n);
    dp[n] = 1;
    dp[n-1] = 2;
    nxt[n-1] = n;
    update(n-1+n,n);
    REPN(i,n-2,0) {
        int lo=i, hi=n-1, mi;
        while (lo<hi) {
            mi = 1+(lo+hi)/2;
            if (v[mi].first<v[i].second) {
                lo = mi;
            }
            else hi = mi-1;
        }
        if (lo==i) nxt[i] = i+1;
        else nxt[i] = range_max(i+n+1,lo+n+1);
        update(i+n,nxt[i]);
        dp[i] = (dp[nxt[i]] + dp[i+1])%mod;
    }
    cout<<dp[0];
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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 (a>b) { a=b; return 1; } return 0; }


int main() {
    int a,b,c; cin>>a>>b>>c;
    //string S; cin>>S;


    cout<<((a+b+c>=22)?"bust":"win")<<endl;
    //cout<<a<<endl;

    return 0;
}


Measured memory_bytes: 256
#from itertools import combinations 
import sys
import math as mt
input=sys.stdin.buffer.readline  
t=1


#t=int(input())
for _ in range(t):
    n=int(input())
      
    #n,m,k=map(int,input().split())
    l=list(map(int,input().split()))
    l.sort(reverse=True)
    ans=l[0]
    cnt=0
    ind=1
    for i in range(2,n):
        if cnt==2:
            cnt=0
            ind+=1
        ans+=l[ind]
        cnt+=1
    print(ans)    

Measured memory_bytes: 92812
def main():
  n=int(input())
  arr=[input() for _ in range(n)]
  dic={}
  for i in range(n): #各単語の出現回数を数える
    if arr[i] not in dic:
      dic[arr[i]]=1
    else:
      dic[arr[i]]+=1
  largest=max(dic.values()) #最大の出現回数を求める
  ans=[]
  for keys in dic.keys():
    if dic[keys]==largest: #出現回数が最も多い単語を集計する
      ans.append(keys)
  ans=sorted(ans) #単語を辞書順に並べ替えて出力する
  for words in ans:
    print(words)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 101200
#include <iostream>
#include <queue>
#define MAX_N 100000
#define MAX_M 100000
typedef long long ll;
using namespace std;

int n, m;
int a[MAX_N];

void solve()
{
    ll ans = 0;
    // 大きいほうから出てくる順位キュー
    priority_queue<int, vector<int>, less<int>> que;
    for (int i = 0; i < n; i++)
    {
        que.push(a[i]);
    }

    // 最も大きいものを取り出し
    // 2で割った商を切り捨てたものを追加
    for (int i = 0; i < m; i++)
    {
        int p;
        p = que.top();
        que.pop();

        // 割引券を使う
        p /= 2;
        que.push(p);
    }

    while (!que.empty())
    {
        int p;
        p = que.top();
        que.pop();
        ans += p;
    }

    cout << ans << endl;
}

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

    solve();
}

/* 入力例
3
8 5 8
*/


Measured memory_bytes: 1276
object Main extends App {
  import scala.io.StdIn._
  val Array(n, x) = readLine.trim.split(' ').map(_.toLong)
  val nums = readLine.trim.split(' ').map(_.toLong).sorted
  val sum = nums.sum
  if (sum < x){
    println(n - 1)
  }else if (sum == x){
    println(n)
  }else {
    var count = 0
    var rest = x
    for (a ← nums){
      if (rest - a >= 0) {
        count += 1
        rest -= a
      }
    }
    println(count)
  }
  implicit class ScopedFunc[T](val value: T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[A](func: T ⇒ A): A = {
      func(value)
    }
  }
}


Measured memory_bytes: 27324
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, K = read_ints()

# 選ぶ数kが異なれば絶対和は異なる
# k個選ぶときに何通りあるか？
# 和としてありえるものの個数
# k個選ぶときにありえる通りの数はsum(0..(k-1))からsum((N-1)..N)1づつ出てくる
ans = 0
for k in ra(K, N + 2):
    tmp = ((N + N - (k - 1)) * k // 2) - ((0 + k - 1) * k // 2) + 1
    # print(tmp)
    ans += tmp
    ans %= MOD
print(ans)


Measured memory_bytes: 67908
#include<stdio.h>

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

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int32 fib[10] = {1,1,2,3,5,8,13,21,34,55};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w,k;
    cin >> h >> w >> k;k--;
    int64 dp[h+1][w];
    REP(i,w)dp[0][i] = 0;
    dp[0][0] = 1;
    REP(i,h){
        REP(j,w){
            dp[i+1][j] = 0;
            if(j-1 >= 0)
                dp[i+1][j] += dp[i][j-1] * fib[j - 1] * (w-j-1>=0?fib[w - j - 1]:1);
            dp[i+1][j] += dp[i][j] * fib[j] * fib[w - j - 1];
            if(j+1 < w)
                dp[i+1][j] += dp[i][j+1] * fib[j] * (w-j-2>=0?fib[w - j-2]:1);
            dp[i+1][j] %= MOD;
        }
    }
    ANS(dp[h][k]);
    return 0;
}

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

int main(){
long long N;
cin >> N;
long long ans= 0;
  
for(long long i =1;i <= N;++i){
if(i % 3 == 0 || i % 5 == 0)
continue;
ans +=i;
}
  
cout << ans << endl;
}

Measured memory_bytes: 3608
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

l, r, d = map(int, input().split())
for i in range(l, r+1):
    if i%d == 0:
        count += 1
print(count)

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ll nn = n / i;
        ans += nn * (2 * i + (nn - 1) * i) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
N, K = map(int, input().split())
X = list(map(int, input().split()))

L = N-K+1
Y = [10**9]*(L)
for i in range(L):
    a = X[i]
    b = X[i+K-1]
    if a*b<0:
        Y[i] = 2*min(abs(a), abs(b)) + max(abs(a), abs(b))
    else:
        Y[i] = max(abs(a), abs(b))

print(min(Y))

Measured memory_bytes: 62576
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m,q=map(int, input().split())
Num2D=[[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
    l,r=map(int,input().split())
    Num2D[l][r]+=1
for i in range(n):
    for j in range(n):
        Num2D[i+1][j+1]+=Num2D[i+1][j]
        Num2D[i+1][j+1]+=Num2D[i][j+1]
        Num2D[i+1][j+1]-=Num2D[i][j]
for _ in range(q):
    l,r=map(int,input().split())
    print(Num2D[r][r]+Num2D[l-1][l-1]-Num2D[l-1][r]-Num2D[r][l-1])

Measured memory_bytes: 13584
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-08-30 14:36:32 +0900
# LastModified: 2020-08-30 14:45:15 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, a, b = map(int, input().split())
    tmp = n - n // (a+b) * (a+b)
    ans = n//(a+b) * a
    if tmp <= a:
        print(ans+tmp)
    else:
        print(ans+a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    lst=[]
    for i in range(n):
        a,b=map(int,input().split())
        lst.append([a-b,a+b])
    lst=sorted(lst,key=lambda x:x[1])
    ans=0
    end=-float("inf")
    for i in lst:
        if i[0]>=end:
            ans+=1
            end=i[1]
    print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 89968
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


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

    vector<int> A(N);
    for(int i(0); i < N; ++i) cin >> A[i];

    long long ans = 0;
    for(int i = 1; i < N; ++i){
        const int MaxNum = max(A[i - 1],A[i]);
        ans += MaxNum - A[i];
        A[i] = MaxNum;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main() {
    //c_p_c();
//    string c;   cin>>c;
//    if(c.length()>4&&(c[2]==c[3]&&c[4]==c[5])){
//        cout<<"YES";
//    } else  cout<<"NO";
//    return 0;
    lli c;  cin>>c;
    lli hap=0;
    hap+=c/500;
    hap*=1000;
    c-=500*(c/500);
    hap+=5*(c/5);
    cout<<hap;
    return 0;
}

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

#define int             long long
#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

int dp[101][101];

signed main(){
    int N; cin >> N;
    vector<int> p( N + 1 );
    REP( i, N ){
        cin >> p[i] >> p[i + 1];
    }

    for( int l = 2; l <= N; l++ ){
        for( int i = 1; i <= N - l + 1; i++ ){
            int j = i + l - 1;
            dp[i][j] = INF;
            for( int k = i; k <= j - 1; k++ ){
                dp[i][j] = min( dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[j] * p[k] );
            }
        }
    }

    cout << dp[1][N] << endl;
}



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

using namespace std;

int n;

int a[30], b[30], c[30][30], ans;

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> a[i];
    }
    for (int i = 1;i <= n;i ++) {
        cin >> b[i];
    }
    for (int i = 1;i < n;i ++) {
        int x;
        cin >> x;
        c[i][i + 1] = x;
    }
    for (int i = 1;i <= n;i ++) {
        ans += b[i] + c[a[i - 1]][a[i]];
    }cout << ans;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

ll cnt[200015];

ll f(ll i){
	if(i == 0) return 0;
	if(cnt[i] > 0) return cnt[i];
	ll pc = 0;
	rep(j,30){
		if((i>>j) & 1) ++pc;
	}
	if(pc == 0) return 0;
	ll res = f(i%pc) + 1;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s;
	cin >> n >> s;
	for(ll i = 2; i <= n+5; ++i){
		cnt[i] = 0;
	}
	cnt[1] = 1;
	for(ll i = 2; i <= n+5; ++i){
		cnt[i] = f(i);
	}
	ll p = 0;
	rep(i,n){
		if(s[i] == '1') ++p;
	}
	ll ans1 = 0, ans2 = 0, p1 = p-1, p2 = p+1;
	if(p <= 1) p1 = 1;
	for(int i = 0; i < n; ++i){
		ans1 = (ans1 * 2) % p1;
		ans2 = (ans2 * 2) % p2;
		if(s[i] == '1'){
			ans1 = (ans1 + 1) % p1;
			ans2 = (ans2 + 1) % p2;
		}
	}
	vector<ll> ans(n);
	ll div1 = 1, div2 = 1;
	for(int i = n-1; i >= 0; --i){
		ll num = 0;
		if(s[i] == '0'){
			num = (ans2 + div2) % p2;
		}
		else{
			if(p == 1) num = 200014;
			else num = (ans1 + p1 - div1) % p1;
		}
		ans[i] = num;
		div1 = (div1 * 2) % p1;
		div2 = (div2 * 2) % p2;
	}
	cnt[200014] = -1;
	rep(i,n) cout << cnt[ans[i]] + 1 << endl;
	return 0;
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 998244353
 
int main() {
 
	ll n,k;
	cin>>n>>k;

	vector<ll> A(n,0);
	ll sum = 0;

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

	vector<ll> fact;

	for(ll i=1;i<=sqrt(sum);i++) {
		if(i*i==sum)
			fact.push_back(i);
		else if(sum%i==0){
			fact.push_back(i);
			fact.push_back(sum/i);
		}
	}

	sort(fact.begin(), fact.end());

	vector<pair<ll,ll> > diff(n);
	bool flag = 0;
	ll res = 1;
	for(ll i=fact.size()-1;i>=0;i--) {
		ll f = fact[i];

		for(ll j=0;j<n;j++) {
			ll a = A[j]%f;
			diff[j]={a,f-a};
		}

		sort(diff.begin(),diff.end());
		// for(ll i=0;i<n;i++)
		// 	cout<<diff[i].first<<" "<<diff[i].second<<endl;

		vector<ll> left(n,0);
		for(ll j=0;j<n;j++){
			left[j] = (j-1>=0?left[j-1]:0) + diff[j].first;
		}
		// for(ll j=0;j<n;j++)
		// 	cout<<left[j]<<" ";
		// cout<<endl;

		vector<ll> right(n,0);
		for(ll j=n-1;j>=0;j--){
			right[j] = (j+1<n ? right[j+1]:0) + diff[j].second;
		}
		// for(ll j=0;j<n;j++)
		// 	cout<<right[j]<<" ";
		// cout<<endl;

		for(ll j=0;j<n-1;j++) {
			if(left[j]==right[j+1]){
				if(left[j]<=k){
					res = f;
					flag=1;
					break;
				}
			}
		}
		if(flag) break;

	}

	cout<<res<<endl;

	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n;
ll a[200009];
ll s;

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

    cin >> n;
    rep(i, n) {
        cin >> a[i];
        s ^= a[i];
    }

    rep(i, n) cout << (s ^ a[i]) << " \n"[i == n - 1];

    return 0;
}

Measured memory_bytes: 5248
/*
 *  Created on: 22 / 8 / 2020
 *  Author:     Eslam Waheed
 */

#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO

#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

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

#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define endl    '\n'

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e9 + 7;
//const ld EPS = 1e-8;
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
	//stp(0)
	Eslam__Waheed;
	string s; cin >> s;
	ll ans = 0;
	for (int i = 0; i < s.size(); i++)
	{
		ans += (s[i] - '0');
	}
	cout << ((ans % 9 == 0) ? "Yes" : "No");
}

Measured memory_bytes: 3768
import math

while True:
	n=int(input())
	if ( n == 0):
		exit(0)
	intarr = list(map(int, input().split()))
	m = sum(intarr)/len(intarr)
	#print(m)
	aa = 0
	for i in intarr:
		aa = aa + (i-m)**2
	a = math.sqrt(aa/n)
	print(a)


Measured memory_bytes: 5692
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=200005;
int n,nx[maxn][26],tot,lnk[maxn],son[maxn],nxt[maxn],dep[maxn];char S[maxn];
inline void add_e(int x,int y){tot++;son[tot]=y;nxt[tot]=lnk[x];lnk[x]=tot;}
void DFS(int now)
{
	for(int i=lnk[now];i;i=nxt[i])
		{dep[son[i]]=dep[now]+1;DFS(son[i]);}
}
void Print(int now)
{
	if(now==n+1){putchar('\n');return;}
	for(int j=0;j<26;j++)
	{
		if(dep[nx[now][j]]==dep[now]-1)
		{
			putchar(j+'a');
			Print(nx[now][j]);
			return;
		}
	}
}
int main()
{
	scanf("%s",S+1);
	n=strlen(S+1);
	for(int i=0;i<26;i++) nx[n][i]=n+1;
	for(int i=n-1;i>=0;i--)
	{
		for(int j=0;j<26;j++)
		{
			if(S[i+1]==j+'a') nx[i][j]=i+1;
			else nx[i][j]=nx[i+1][j];
		}
	}
	for(int i=0;i<=n;i++)
	{
		int mx=0;
		for(int j=0;j<26;j++)
			mx=max(mx,nx[i][j]);
		add_e(mx,i);
	}
	DFS(n+1);
	Print(0);
	return 0;
}

Measured memory_bytes: 24064
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n,q = get_nums_l()
s = input()

ruiseki_ac = [0] * (n+1)

for i in range(n-1):
    x = 0
    if s[i] == "A" and s[i+1] == "C":
        x = 1
    ruiseki_ac[i+1] = ruiseki_ac[i] + x
ruiseki_ac[n] = ruiseki_ac[n-1]

log(ruiseki_ac)

for i in range(q):

    a,b = get_nums_l()
    print(ruiseki_ac[b-1] - ruiseki_ac[a-1])


Measured memory_bytes: 90968
N = gets.to_i
Ss = Array.new(N) { gets.chomp }

def safe_invert(orig_hash)
    orig_hash.each_key.group_by do |key|
        orig_hash[key]
    end
end

w_c = {}

Ss.each do |word|
    if w_c.has_key?(word)
        w_c[word] += 1
    else
        w_c[word] = 1
    end
end

max_c = w_c.values.max
w_c = safe_invert(w_c)
w_c[max_c].sort.map { |w| puts w }

Measured memory_bytes: 41448
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define int LL
#define upto(a, b, i) for(int i = (a), b_ = (b); i <= b_; ++i)
#define uptil(a, b, i) for(int i = (a), b_ = (b); i < b_; ++i)
#define downto(a, b, i) for(int i = (a), b_ = (b); i >= b_; --i)
#define downtil(a, b, i) for(int i = (a), b_ = (b); i > b_; --i)
#define times(n, i) uptil(0, n, i)
#define rtimes(n, i) downto((n)-1, 0, i)

#define sp <<" "
#define ln <<endl
#define size(x) ((int)x.size())
template<class T> using vec = vector<T>;
template<class T> using vvec = vec<vec<T>>;

void solve() {
  int L,R; cin>>L>>R;
  if(L == 0 || R/2019 != (L-1)/2019) {cout << 0 ln; return;}

  int ans = 2018;
  uptil(L, R, i) upto(i+1, R, j) ans = min(ans, i * j % 2019);
  cout << ans ln;
}

signed main() {
  cout << fixed << setprecision(20);
  cerr << fixed << setprecision(6);
  solve();
  return 0;
}


Measured memory_bytes: 256
//     THE ONLY WAY IS UP

#include<bits/stdc++.h>

#define ll              long long int
#define ld              long double
#define f1(i, a, b)     for(ll i = a; i < b; i++)
#define f2(a, b)        for(auto a : b)
#define ar(v, i)        v[i]
#define in_(x)          ll x; cin >> x;
#define ino_(type, x)   type x; cin >> x;
#define pb              push_back
#define nl              "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
    in_(n)
    ll sum=0;
    f1(i, 1, n+1){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    
    cout << sum << endl;
    
}
// ctrl n opens new window
// ctrl d deletes the current line
// ctrl shift m selects the current body
// ctrl k moves to the next selected phrase
// ctrl alt k selects all the similar phrases

Measured memory_bytes: 3648
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    
    N,M = LMIIS()
    edge = defaultdict(list)
    for i in range(M):
        a,b = LMIIS()
        edge[a].append(b)
        edge[b].append(a)



    #根が１の木を作る
    #根から子を辿って、ルートを確定させていく
    roots = deque()
    roots.append(1)
    visited = [False]*(N+1)
    visited[1] = True
    lights = [0]*(N+1)
    while len(roots) > 0:
        root = roots.popleft()
        length = visited[root]
        for v in edge[root]:
            if not visited[v]:
                visited[v] = True
                lights[v] = root
                roots.append(v)
    print('Yes')
    for i in range(2,N+1):
        print(lights[i])





main()

Measured memory_bytes: 103516
#include <bits/stdc++.h>
using namespace std;
int n,d;
int x[11][11];
int main(){
	cin>>n>>d;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=d;j++){
			cin>>x[i][j];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++){
			int sum=0;
			for(int k=1;k<=d;k++){
				sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			for(int i=1;i<=300;i++){
				if(i*i==sum){
					ans++;
					break;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
#define mp             make_pair
#define pb             push_back
#define pf             push_front
#define fi             first
#define se             second
#define sz(x)          (ll)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x--)
#define lp(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define lpr(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define ilp(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define ilpr(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef tuple<int, int> ii;
typedef tuple<int, int, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
const   ll            INF = INT64_MAX;

int gcd(int a, int b)
{
    if(b == 0)
        return a;
    return gcd(b, a % b);
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // sci(n);
    int n;
    cin >> n;
    int a[n+1];
    lp(i, 0, n - 1)
    {
        cin >> a[i];
    }
    // sort(a, a+n);
    int x = gcd(a[0], a[1]);
    lp(i, 2, n - 1)
    {
        x = gcd(x, a[i]);
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;
int n,a,b,c,d;

map<ll,ll> memo;

ll dfs(ll x)
{
	//cout<<x<<endl;
	if(x==0)
	{
		return 0;
	}
	if(x==1)
	{
		return d;
	}
	if(memo.count(x))return memo[x];
	ll ret = x*d;
	if(LLONG_MAX/x<d)ret = LLONG_MAX;

	ll A = x%2;
	ret = min(ret,dfs((x-A)/2)+A*d+a);
	A = 2-A;
	if(x%2)ret = min(ret,dfs((x+A)/2)+A*d+a);

	ll B = x%3;
	ret = min(ret,dfs((x-B)/3)+B*d+b);
	B = 3 - B;
	if(x%3)ret = min(ret,dfs((x+B)/3)+B*d+b);

	ll C = x%5;
	ret = min(ret,dfs((x-C)/5)+C*d+c);
	C = 5 - C;
	if(x%5)ret = min(ret,dfs((x+C)/5)+C*d+c);

	return memo[x] = ret;
}

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		ll x;
		cin >> x;
		cin >> a >> b >> c >> d;
		cout<<dfs(x)<<endl;
		memo.clear();
	}
}


Measured memory_bytes: 4272
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

int main(){

    pll s,t;
    cin>>s.first>>s.second>>t.first>>t.second;
    if(s.first>t.first)swap(s,t);

    int N;cin>>N;
    vector<pll> fountain;
    REP(i,N){
        LL x,y;cin>>x>>y;
        if(x<s.first||x>t.first||y<min(s.second,t.second)||y>max(s.second,t.second))continue;
        fountain.push_back({x,y});
    }
    sort(ALL(fountain));
    int founNum;
    if(t.second>s.second){
        vector<LL> inc(fountain.size(),INT_MAX);

        REP(i,fountain.size()){
            auto itr = lower_bound(ALL(inc),fountain[i].second);
            *itr = fountain[i].second;
        }
        founNum = lower_bound(ALL(inc),INT_MAX)-inc.begin();
    }else{
        vector<LL> dec(fountain.size(),INT_MIN);
        REP(i,fountain.size()){
            auto itr = upper_bound(ALL(dec),fountain[i].second);
            *--itr = fountain[i].second;
        }
        founNum = dec.end() - upper_bound(ALL(dec),INT_MIN);
    }

    double long ans = abs(t.second - s.second)*100+abs(t.first - s.first)*100;
    ans += (long double)founNum * (long double)(-20 + 5*M_PI);
    if(founNum > min(abs(t.second - s.second),abs(t.first - s.first))){
        ans += (long double)5*M_PI;
    }
    cout<<fixed<<setprecision(20)<<ans<<endl;

    return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<MAX; i++){
		fac[i] = fac[i-1]*i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		finv[i] = finv[i-1] * inv[i] % mod;
	}
}


ll com(ll n, ll k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
	ll n,m,k; cin >> n >> m >> k;
	comInit();
	ll sum = 0;
	REP(i,1,m){
		sum += n*n%mod*i%mod*(m-i)%mod;
		sum %= mod;
	}
	REP(i,1,n){
		sum += m*m%mod*i%mod*(n-i)%mod;
		sum %= mod;
	}
	ll t = 1;
	ll s = (n*m-2)%mod;
	rep(i,k-2){
		t *= s-i;
		t %= mod;
		t *= inv[i+1];
		t %= mod;
		if(s-i==0) break;
	}
	cout << sum*t%mod << endl;
	
}

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

const int INF = 1001001001;
vector<int> to[100005];

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i), a.at(i)--;
  
  map<int, int> m;
  m[0] = 1; // 町1
  int to = a.at(0);
  ll loop = 1, period = 0;
  vector<int> telp;
  telp.push_back(1);
  bool period_get = false;
  while(loop <= k) {
    telp.push_back(to+1);
    // cout << telp.at(loop-1) << endl;
    m[to]++;
    if (m.at(to) == 2) period++;
    else if (m.at(to) == 3) {
      period_get = true;
      break;
    }

    to = a.at(to);
    ++loop;
  }
  if (period_get) {
    ll branch = m.size() - period;
    ll index = (k-branch) % period;
    cout << telp.at(index + branch) << endl;	
  }
  else {
    cout << telp.at(telp.size()-1) << endl; 
  }
  return 0;
}

Measured memory_bytes: 14772
from fractions import gcd 
import sys

l, r, c, d = map(int, sys.stdin.readline().split())

count = 0

first = (l + c - 1)//c 
last = r//c 

count += last - first + 1

first = (l + d - 1)//d 
last = r//d 
count += last - first + 1

lcm = c*d//gcd(c, d)

first = (l + lcm - 1)//lcm 
last = r // lcm
count -= last - first + 1


print(r - l - count + 1)

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}


int main(){
    int N;
    cin >> N;
    int c[N+1] = {0};
    for(int x=1; x<=sqrt(N); x++){
        for(int y=1; y<=sqrt(N) && x*x+y*y+1+x+y+x*y<=N; y++){
            for(int z=1; z<=sqrt(N) && x*x+y*y+z*z+x*y+y*z+x*z <= N; z++){
                if(x*x+y*y+z*z+x*y+y*z+x*z <= N){
                    c[x*x+y*y+z*z+x*y+y*z+x*z]++;
                }
            }
        }
    }
    for(int i=1; i<=N; i++){
        cout << c[i] << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a, b;
    int t = 0;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        if(a==b){
            t++;
            if(t==3){
                cout << "Yes" << '\n';
                return 0;
            }
        }
        else{
            t = 0;
        }
        
    }
    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

ll gdb_exec(ll a, ll b) {
  if (b == 0) return a;
  return gdb_exec(b, a % b);
}

ll gdb(ll a, ll b) {
  if (a < b) std::swap(a, b);
  if (a == 0 || b == 0) return -999999999;
  return gdb_exec(a, b);
}

ll lcm(ll a, ll b) {
  ll gdb_val = gdb(a, b);
  if (a % gdb_val == 0) {
    return (a / gdb_val) * b;
  }
  return (b / gdb_val) * a;
}

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;
  std::vector< ll > va(n, 0);
  std::vector< ll >::iterator it;

  for (ll i = 0; i < n; i++) {
    std::cin >> va[i];
  }

  int ans = INF;
  for (it = va.begin(); it != va.end(); it++) {
    int cnt = 0;
    ll val = *it;
    while (val % 2 == 0) {
      val /= 2;
      cnt++;
    }
    ans = std::min(cnt, ans);
  }

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


Measured memory_bytes: 384
_, k = gets.split(" ").map(&:to_i)
p = gets.split(" ").map(&:to_i)

pp = p.map {|n| (n + 1) * 0.5 }
s = Array.new(p.size + 1)
s[0] = 0
(0..pp.size - 1).each do |i|
  s[i + 1] = s[i] + pp[i]
end

max = 0
(0..p.size - k).each do |i|
  n = s[i + k] - s[i]
  max = n if max < n
end

puts max

Measured memory_bytes: 18052
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

type Node struct {
	Value int
	Parent *Node
	Left *Node
	Right *Node
}

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr := bufio.NewWriter(os.Stdout)
	
	var root *Node
	
	for i := 0; i < n; i++ {
		sc.Scan()
		command := sc.Text()
		
		if command == "print" {
			printInorder(root, wr)
			wr.WriteString("\n")
			printPreorder(root, wr)
			wr.WriteString("\n")
		} else if command == "insert" {
			sc.Scan()
			k, _ := strconv.Atoi(sc.Text())
			root = insert(root, k)
		}
	}
	wr.Flush()
}

func printInorder(node *Node, wr *bufio.Writer) {
	if node == nil {
		return
	}
	printInorder(node.Left, wr)
	wr.WriteString(" ")
	wr.WriteString(strconv.Itoa(node.Value))
	printInorder(node.Right, wr)
}

func printPreorder(node *Node, wr *bufio.Writer) {
	if node == nil {
		return
	}
	wr.WriteString(" ")
	wr.WriteString(strconv.Itoa(node.Value))
	printPreorder(node.Left, wr)
	printPreorder(node.Right, wr)
}

func insert(root *Node, k int) *Node {
	z := &Node{k, nil, nil, nil}
	if root == nil {
		return z
	}
	
	var x, y *Node
	x = root
	for x != nil {
		y = x
		if z.Value < x.Value {
			x = x.Left
		} else {
			x = x.Right
		}
	}
	z.Parent = y

	if z.Value < y.Value {
		y.Left = z
	} else {
		y.Right = z
	}
	return root
}



Measured memory_bytes: 23428
#include<bits/stdc++.h>
using namespace std;
unsigned long long lie,hang;
int main(){
	
	cin>>hang>>lie;
	if(hang==1 || lie==1)cout<<1;
	else
	if(lie%2==0 && hang%2==0)
	cout<<hang*lie/2;
	else if(lie%2==1 && hang%2==1)cout<<lie*(hang/2)+(lie/2)+1;
	else if(hang%2==1 && lie%2==0)cout<<hang*(lie/2);
	
	else cout<<lie*(hang/2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n; cin >> n;
	int a, b, c, d;
	string ans = "No";
	a = n/1000;
	b = (n-a*1000)/100;
	c =  (n-a*1000-b*100)/10;
	d = n-a*1000-b*1000-c*10;
	if (a==b && b==c){
		ans = "Yes";
	}
	if(b==c && c==d){
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
program main
  implicit none

  integer :: n, i, j, k, s

  read *, n

  s = 0
  do i = 1, n
     do j = i, n
        do k = j, n
           if (i == j) then
              if (j == k) then
                 s = s + gcd(i,j,k)
              else
                 s = s + 3*gcd(i,j,k)
              end if
           else
              if (j == k) then
                 s = s + 3*gcd(i,j,k)
              else
                 s = s + 6*gcd(i,j,k)
              end if
           end if
        end do
     end do
  end do

  print *, s
  

  stop
contains

  integer function gcd(i,j,k)
    implicit none
    integer, intent(in) :: i, j, k
    integer :: a, b, c, d, e
    logical :: log

    a = i
    b = j
    c = k
    if (a < b) then
       d = a
       a = b
       b = d
    end if

    log = .true.
    do while(log .eqv. .true.)
       if (b == 0) then
          d = a
          log = .false.
          exit
       else
          d = mod(a,b)
          a = b
          b = d
       end if
    end do

    if (c < d) then
       e = c
       c = d
       d = e
    end if

    log = .true.
    do while(log .eqv. .true.)
       if (d == 0) then
          gcd = c
          log = .false.
          exit
       else
          e = mod(c,d)
          c = d
          d = e
       end if
    end do

    return
  end function gcd
    
end program main


Measured memory_bytes: 2852
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 200005;

ll a[MAX_N], b[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    bool ok = true;
    ll sm = 0, mn = INF;
    rep(i,n){
        cin >> a[i] >> b[i];
        if(a[i] != b[i]) ok = false;
        if(a[i] <= b[i]){
            ans += a[i];
        }else{
            sm += a[i];
            cmn(mn, b[i]);
        }
    }
    if(ok){
        cout << "0\n";
    }else{
        cout << ans+sm-mn << "\n";
    }
    return 0;
}


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

using namespace std;

int main() { 
  double x1, y1, x2, y2;
  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  printf("%f\n", sqrt(abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1 - y2)));
  return 0;
}



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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n;cin>>n;
    map<ll,ll> a;

    rep(i,n){
        ll p;cin>>p;
        if(a.find(p)==a.end()) a[p]=1;
        else a[p]++;
    }
    
    ll ans=1;
    priority_queue<ll> que;
    que.push(0);
    que.push(0);
    for(auto itr=a.begin();itr!=a.end();itr++){
        rep(i,itr->second/2) que.push(itr->first);
    }

    ans*=que.top();
    que.pop();
    ans*=que.top();

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

Measured memory_bytes: 9692
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline int rd()
{
	int x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=605;
int n,b[N*N];pii a[N];
inline void out(){puts("No");exit(0);}
int main()
{
	n=rd();
	rep(i,1,n)a[i].X=rd(),a[i].Y=i,b[a[i].X]=i;
	sort(a+1,a+n+1);
	rep(i,1,n)
	{
		int t=a[i].Y-1;
		rep(j,1,a[i].X-1)
		{
			if(!t)break;
			if(!b[j])b[j]=a[i].Y,t--;
		}
		if(t)out();
	}
	per(i,n,1)
	{
		int t=n-a[i].Y;
		per(j,n*n,a[i].X+1)
		{
			if(!t)break;
			if(!b[j])b[j]=a[i].Y,t--;
		}
		if(t)out();
	}
	puts("Yes");
	rep(i,1,n*n)printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 2176
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10**9)

def dfs(y,x):
    for dy,dx in (-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1),(1,-1),(1,1):
        ny,nx=y+dy,x+dx
        if 0<=ny<h and 0<=nx<w:
            if grid[ny][nx]==1:
                grid[ny][nx]=0
                dfs(ny,nx)

while True:
    readline=stdin.readline
    w,h=map(int,readline().split())
    if w==0 and h==0:
        break
    grid=[list(map(int,readline().split())) for _ in range(h)]

    cnt=0
    for y in range(h):
        for x in range(w):
            if grid[y][x]==1:
                dfs(y,x)
                cnt+=1

    print(cnt)


Measured memory_bytes: 7876
n=int(input())
array=[]
for i in range(n):
    a=int(input())
    array.append(a)
count=0 
a=1       
for i in range(n):
    a=array[a-1]
    count+=1    
    if a==2:
        print(count)
        exit()
print(-1)        
        


Measured memory_bytes: 7084
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    char ss[1003];
    cin >> ss;
    int len = strlen(ss);
    if (ss[strlen(ss) - 1] == 's') {
        ss[len] = 'e';
        ss[len + 1] = 's';
        ss[len + 2] = '\0';
    }
    else {
        ss[len] = 's';
        ss[len + 1] = '\0';
    }
    cout << ss << endl;
    return 0;
}

Measured memory_bytes: 3624
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).
 
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

main :-
  get_number(N),
  get_number(K),
  Ans is (N*(N+1)*(N+2)/6-K*(K-1)*(3*N-2*K+4)/6+(N-K+2)) mod 1000000007,
  writeln(Ans).

Measured memory_bytes: 8184
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    ll now1 = 0, sum = 0;
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            now1 += abs(1-(sum+a[i])) * (sum+a[i] <= 0);
            sum = max(1LL, sum+a[i]);
        }else{
            now1 += abs(-1-(sum+a[i])) * (sum+a[i] >= 0);
            sum = min(-1LL, sum+a[i]);
        }
    }
    ll now2 = 0; sum = 0;
    for(int i = 0; i < n; i++){
        if(i % 2 == 1){
            now2 += abs(1-(sum+a[i])) * (sum+a[i] <= 0);
            sum = max(1LL, sum+a[i]);
        }else{
            now2 += abs(-1-(sum+a[i])) * (sum+a[i] >= 0);
            sum = min(-1LL, sum+a[i]);
        }
    }
    cout << min(now1, now2) << endl;
}

Measured memory_bytes: 3976
# coding: utf-8
# Your code here!

N, K = map(int, input().rstrip().split(' '))
X = [0] + list(map(int, input().rstrip().split(' ')))

sorted_left_X = []
sorted_right_X = []
sorted_remove_X = []
for i in range(N+1):
    sorted_left_X.append(sorted([x for x in X[:i] if x < 0]))
    sorted_right_X.append(sorted([x for x in X[::-1][:i] if x < 0]))
    
    sorted_remove_X.append(sorted([x for x in X[:i] if x < 0] + [x for x in X[::-1][:i] if x < 0]))

cum_X = []
cum = 0
for x in X:
    cum += x
    cum_X.append(cum)

if K > N:
    temp = sorted([x for x in X if x < 0])
    print(cum_X[-1] - sum(temp[:min(len(temp), K)]))
else:
    max_count = 0
    for k in range(1,K+1):
        for i in range(k+1):
            temp = sorted(sorted_left_X[i] + sorted_right_X[k-i])
            temp2 = sum(temp[:min(len(temp), K-k)])
            max_count = max(cum_X[i] - cum_X[0] + cum_X[-1] - cum_X[i+N-k] - temp2, max_count)

    print(max_count)
    

Measured memory_bytes: 39152
n,m = map(int,input().split())
ai = [int(input()) for i in range(m)]

mod = 10**9+7

dp = [0] * (n+1)
dp[0] = 1
num = 0

for i in range(1,n+1):
    #print(i)
    if m == 0:
        if i == 1:
            dp[i] = dp[i-1] % mod
        else:
            dp[i] = (dp[i-1] + dp[i-2])%mod
    else:
        if i == ai[num]:
            dp[i] = 0
            num += 1
            num = min(num,m-1)
        else:
            if i == 1:
                dp[i] = dp[i-1] % mod
            else:
                dp[i] = (dp[i-1] + dp[i-2])%mod
    #    dp[i+1] = dp[i-1] + dp[i]
            
print(dp[n]%mod)

Measured memory_bytes: 50776