akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
struct res{
	int id;
	string na;
	int score;
}r[105];

bool cmp(res a,res b){
	if(a.na!=b.na)return a.na<b.na;
	else return a.score>b.score;
}
int n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		r[i].id=i+1;
		cin>>r[i].na>>r[i].score;
	}
	sort(r,r+n,cmp);
	for(int i=0;i<n;i++)cout<<r[i].id<<endl;
	return 0;
} 

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(max(a, b) > c && min(a, b) < c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	// your code goes here
	return 0;
}


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

int main() {
    int64_t K;
    cin >> K;
    int64_t mod = 0;
    for (int64_t i = 0; i < 1e7; i++) {
        mod *= 10;
        mod += 7;
        mod %= K;
        if (mod == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, k, ans = 0;
    cin >> n >> k;
    map<ll, ll>mp;
    for(int i = 0;i < n;++i)
    {
        ll x;
        cin >> x;
        ++mp[x];
    }
    set<pair<ll, ll>>st;
    for(auto &it : mp)
        st.insert({it.S, it.F});
    while(st.size() > k)
    {
        auto it = st.begin();
        ans += it->F;
        st.erase(it);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 25216
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

char s[11];
int n;
ll dp[11];

ll solve(int idx)
{
	if (idx==n) return 0;
	if (dp[idx]!=-1) return dp[idx];
	ll ans=0,curr=0;
	REPP(i,idx,n)
	{
		curr=10*curr+s[i]-'0';
		ans+=(1<<(max(n-2-i,0)))*curr+solve(i+1);
	}
	dp[idx]=ans;
	return ans;
}

int main()
{
	scanf("%s",s);
	n=strlen(s);
	FILL(dp,-1);
	printf("%lld\n",solve(0));
return 0;
}


Measured memory_bytes: 256
c1,c2,c3 = map(int, input().split())
c4,c5,c6 = map(int, input().split())
c7,c8,c9 = map(int, input().split())
card = [c1,c2,c3,c4,c5,c6,c7,c8,c9]
N = int(input())

b = []
for _ in range(N):
  b.append(int(input()))

for _ in b:
  for j in range(9):
    if card[j] == _:
      card[j] = "o"  
  
bingo = [
  [card[0],card[1],card[2]],
  [card[3],card[4],card[5]],
  [card[6],card[7],card[8]],
  [card[0],card[3],card[6]],
  [card[1],card[4],card[7]],
  [card[2],card[5],card[8]],
  [card[0],card[4],card[8]],
  [card[2],card[4],card[6]]
]

for i in bingo:
  if i == ["o","o","o"]:
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 9296
N = int(input())
A = [int(n) for n in input().split()]

cnt = 0


# bubbleSort

flag = 1
while flag:
    flag = 0
    for j in range(1,N)[::-1]:
        if A[j] < A[j-1]:
            cnt += 1
            A[j],A[j-1] = A[j-1],A[j]
            flag = 1

print(" ".join([str(a) for a in A]))
print(cnt)


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (auto &e: d) cin >> e;
    sort(d.begin(), d.end());

    int a = d[n/2-1];
    int b = d[n/2];
    int ans = b-a;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for(int i = 0;i < N; i++){
    int A;
    cin >> A;
    vec.at(i) = A;
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int Alice = 0;
  for(int i = 0;i < N;i += 2){
    Alice += vec.at(i);
  }
  int Bob = 0;
  for(int i = 1;i < N;i += 2){
    Bob += vec.at(i);
  }
  cout << Alice - Bob << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,s,e) for(register int i=s;i<=e;i++)
#define ll long long
char s[1000000];
ll ans;
int n;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	cin>>s;
	fo(i,0,n-1){
		if(s[i]!=s[i-1])ans++;	
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
// D - XOR World

// 任意の偶数 n について n ⊕ (n + 1) = 1 を利用した解法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll g(ll k) {
	if (k == 0) {
		return 0;
	} else if (k % 2 == 0) {
		return 1 ^ (((k - 2) / 2) % 2) ^ k;
	} else {
		return 1 ^ (((k - 1) / 2) % 2);
	}
}

ll f(ll A, ll B) {
	return g(B) ^ g(max(0LL, A-1));
}

int main() {
	ll A, B;
	cin >> A >> B;

	ll ans = f(A, B);

	cout << ans << endl;

	return 0;
}

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

int main(){
    //入力
    int N, A, B;
    cin >> N >> A >> B;

    //探索
    int exist = 0;
    while (exist == 0){
        //Alice
        if (B-A > 1)
            A++;
        else
            A--;

        if (A<=-1) {
            exist = 1;
            break;
        }

        //Borys
        if (A-B < -1)
            B--;
        else
            B++;

        if (B>=N+1) {
            exist = 2;
            break;
        }
    }

    if (exist == 1)
        cout << "Borys" << endl;
    else
        cout << "Alice" << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> ans;
  while (A.size()) {
    bool b = 0;
    for (int i = A.size() - 1; i >= 0; i--) {
      if (A.at(i) == i + 1) {
        ans.push_back(A.at(i));
        A.erase(A.begin() + i);
        b = 1;
        break;
      }
    }
    if (!b) return cout << -1 << "\n", 0;
  }
  reverse(ans.begin(), ans.end());
  for (auto a : ans) cout << a << "\n";
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d %d %d", $W, $H, $x, $y, $r);

if (in_line(array(0, $W), to_line($x, $r)) &&
    in_line(array(0, $H), to_line($y, $r))) {
    echo "Yes\n";
}
else {
    echo "No\n";
}

function to_line($c, $r)
{
    return array($c - $r, $c + $r);
}

function in_line($l1, $l2)
{
    return $l1[0] <= $l2[0] && $l2[1] <= $l1[1];
}

Measured memory_bytes: 6592
import numpy as np

n = int(input())
s_list = [input() for i in range(n)]

new_dict = {}
for s in s_list:
    if s not in new_dict.keys():
        new_dict[s] = 1
    else:
        new_dict[s] += 1
    
values = []
keys = []    
for key in new_dict.keys():
    values.append(new_dict[key])
    keys.append(key)
    
values = np.array(values)
keys = np.array(keys)

max_index = values == np.max(values)
keys = keys[max_index].tolist()
keys = sorted(keys)

for key in keys:
    print(key)

Measured memory_bytes: 79364
import sys

input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    for i in range(1, n+1):
        if i == n:
            print(str(a[n-i]))
        else:
            print(str(a[n-i]), end=" ")
            
if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, M;
    cin >> N >> M;
    vec A(N);
    REP(i,0,N) cin >> A[i];

    ll sum = 0;
    REP(i,0,N) sum += A[i];
    ll cnt = 0;
    REP(i,0,N) if(4*M*A[i] >= sum) ++cnt;
    if(cnt >= M) _PR("Yes");
    else _PR("No");

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main () {
  string S, T;
  cin >> S >> T;
  int n = (int)S.size();
  int ans = 0;
  for (int i = 0; i < n; i ++) {
    if (S[i] != T[i]) ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3452
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 110000
int n,q;
string s;
vector<pair<char,char>> p;
int check(int x){
    int now=x;
    rep(i,q){
        if(s[now]==p[i].first){
            if(p[i].second=='L')now--;
            else now++;
        }
        if(now==-1){
            return 1;
        }
        else if(now==n)return 2;
    }
    return 0;
}
main(){
    n=in(),q=in();
    cin>>s;
    rep(i,q){
        char s1,t;
        cin>>s1>>t;
        p.pb({s1,t});
    }
    int l=0,r=n+1;
    while(r-1>l){
        int mid=(l+r)/2;
        int a=check(mid-1);
        if(a==1)l=mid;
        else r=mid;
    }
    int ans=l;
    l=0,r=n+1;
    while(r-1>l){
        int mid=(l+r)/2;
        int a=check(n-mid);
        if(a==2)l=mid;
        else r=mid;
    }
    ans+=l;
    if(ans>=n){
        cout<<0;
    }
    else cout<<n-ans;
}


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

int main() {
    string t, s;
    cin >> t >> s;
    vector<int> vec(t.size()-s.size()+1);
    
    for (int i=0; i <= t.size() - s.size(); i++) {
        int cnt = 0;
        int j = 0;
        for (char c: s) {
            if (c != t[i+j]) cnt++;
            j++;
        }
        vec.at(i) = cnt;
    }
    sort(vec.begin(), vec.end());
    cout << vec.at(0) << endl; 
    return 0;
}



Measured memory_bytes: 3632
// Aizu Vol-1 0128: Abacus 
// 2017.8.1

#include <stdio.h>
#include <stdlib.h>

char *gets(char *);

char p[8][10] = {
	{ '*', '*', '*', '*', '*', ' ', ' ', ' ', ' ', ' ' },
	{ ' ', ' ', ' ', ' ', ' ', '*', '*', '*', '*', '*' },
	{ '=', '=', '=', '=', '=', '=', '=', '=', '=', '=' },
	{ ' ', '*', '*', '*', '*', ' ', '*', '*', '*', '*' },
	{ '*', ' ', '*', '*', '*', '*', ' ', '*', '*', '*' },
	{ '*', '*', ' ', '*', '*', '*', '*', ' ', '*', '*' },
	{ '*', '*', '*', ' ', '*', '*', '*', '*', ' ', '*' },
	{ '*', '*', '*', '*', ' ', '*', '*', '*', '*', ' ' },
};

char buf[100];
char ans[8][10];

int main()
{
	int i, j, k, n, r, f = 1;

	while (gets(buf) != NULL) {
		n = atoi(buf);
		for (i = 0, k = 10000; i < 5; i++, n %= k, k /= 10) {
			j = n / k;
			for (r = 0; r < 8; r++) ans[r][i] = p[r][j];
		}
		if (f) f = 0;
		else putchar('\n');
		for (r = 0; r < 8; r++) puts(ans[r]);
	}
	return 0;
}

Measured memory_bytes: 520
//https://atcoder.jp/contests/arc087/tasks/arc087_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};

vector<int> d[2]={{0},{0}};
int g[2];
bool solve(vector<int> &dx,int x){
    bitset<16001> dp;
    dp[8000]=true;
    for(int it:dx){
        dp=(dp<<it)|(dp>>it);
    }
    return dp[8000+x];
}
int main(){
    string s;
    cin>>s>>g[0]>>g[1];
    int n=s.size();
    int id=0;
    while(id<n&&s[id]=='F'){
        g[0]--;
        id++;
    }
    int t=0;
    for(int i:range(id,n)){
        if(s[i]=='T'){
            d[t].push_back(0);
            t=1-t;
        }
        else d[t].back()++;
    }
    g[0]=abs(g[0]);
    g[1]=abs(g[1]);
    if(solve(d[0],g[0])&&solve(d[1],g[1]))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,t;cin >> n >> t;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans=0;
	rep(i,n-1){
		ans+=min(a.at(i+1)-a.at(i),t);
	}
	ans+=t;
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int X;
	int A;

	do{
	scanf("%d %d",&X,&A);
	}while(0 > X || A  > 9); 
        if(X < A){
			printf("0");
        }
		else{
			printf("10");
		}
		
		return 0;
}
		

Measured memory_bytes: 128
import numpy as np

H, W = map(int,input().split())
G = [list(input()) for i in range(H)]

A = []
for i in G:
    if not '#' in i:
        continue
    A.append(i)

B = np.array(A)
B = B.T

X = []
for i in B:
    if not '#' in i:
        continue
    X.append(i)

ans = np.array(X)
ans = ans.T

for i in ans:
    print(''.join(i))


Measured memory_bytes: 27432
#include<stdio.h>
int main(void)
{
	int hi[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	int i,t,n,ni;
	while(1){
		ni=0;
		scanf("%d %d",&t,&n);
		if(t==0)break;
		for(i=2;i<=t;i++){
			ni+=hi[i-1];
		}
		ni=ni+n+3;
		if(ni%7==0){
			printf("Sunday\n");
		}
		if(ni%7==1){
			printf("Monday\n");
		}
		if(ni%7==2){
			printf("Tuesday\n");
		}
		if(ni%7==3){
			printf("Wednesday\n");
		}
		if(ni%7==4){
			printf("Thursday\n");
		}
		if(ni%7==5){
			printf("Friday\n");
		}
		if(ni%7==6){
			printf("Saturday\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
#include<stdlib.h>

int n, A, B, C;
int l[8];
int max = 3840;

int MIN(int a, int b){return a<b?a:b;};

int dfs(int cur, int a, int b, int c, int ta, int tb, int tc){
    if(cur == n){
        if(a * b * c == 0){return max;}
        return abs(A-a) + abs(B-b) + abs(C-c) + 10*((ta-1) + (tb-1) + (tc-1));
    }
    int ret0 = dfs(cur+1, a, b, c, ta, tb, tc);
    int ret1 = dfs(cur+1, a+l[cur], b, c, ta+1, tb, tc);
    int ret2 = dfs(cur+1, a, b+l[cur], c, ta, tb+1, tc);
    int ret3 = dfs(cur+1, a, b, c+l[cur], ta, tb, tc+1);
    
    return MIN(ret3,MIN(ret2,MIN(ret0, ret1)));
}

int main(void){
    scanf("%d%d%d%d", &n, &A, &B, &C);
    for(int i = 0; i < n; i++){scanf("%d", &l[i]);}
    printf("%d\n", dfs(0, 0, 0, 0, 0, 0, 0));
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int zoro = 0;
        boolean ok = false;
        
        int N = sc.nextInt();
        
        for(int i = 0 ; i < N ; i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(x == y){
                zoro++;
                if(zoro >= 3){
                    ok = true;
                }
            }else{
                zoro = 0;
            }
        }

        System.out.println(ok? "Yes" : "No");
    }
}


Measured memory_bytes: 36032
from itertools import product

N = int(input())

_357 = {'3', '5', '7'}

ans = 0
for r in range(3, len(str(N)) + 1):
    for numbers in product(('3', '5', '7'), repeat=r):
        if set(numbers) == _357 and int(''.join(numbers)) <= N:
            ans += 1

print(ans)


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


int main(){
    long long n;
    cin>>n;
    long long a[n-1];
    for(long long i=0;i<n-1;i++){
        cin>>a[i];
    }
    long long ans[n+1]={0};
    for(long long i=0;i<n-1;i++){
        ans[a[i]]++;
    }
    for(long long i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 6724
N, M = map(int,input().split())
array = sorted(list(map(int,input().split())))
convert = [list(map(int,input().split())) for _ in range(M)]
convert.sort(key=lambda x: x[1])
convert.reverse()
i = 0
for j in range(M):
  #array.sort()
  start = 0
  while (array[i] < convert[j][1]) & (start < convert[j][0]):
    array[i] = convert[j][1]
    #print(array)
    i += 1
    start += 1
    if i == N:
      break
  if i == N:
    break

print(sum(array))



Measured memory_bytes: 32836
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S,T;
    int count=0;
    cin>>S;
    cin>>T;
    for(int i=0;i<T.size();i++)
    {
        if(S[i]!=T[i])
        {
        count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    vl G = {1};
    while (3 * G.back() + 1 < N) G.eb(3 * G.back() + 1);
    ll M = G.size();
    reverse(all(G));

    ll cnt = 0;
    rep(gi, M){
        repe(i, G[gi], N){
            ll v = A[i];
            ll ai = i - G[gi];
            while(ai>=0 and A[ai]>v){
                A[ai + G[gi]] = A[ai];
                cnt++, ai -= G[gi];
            }
            A[ai + G[gi]] = v;
        }
    }

    cout << M << endl;
    rep(i, M) cout << G[i] << (i == M - 1 ? '\n' : ' ');
    cout << cnt << endl;

    rep(i, N) cout << A[i] << endl;
}


Measured memory_bytes: 10680
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	vector<int>x(n);
	vector<int>res(n);
	rep(i,n){
		cin>>x[i];
		res[i]=x[i];
	}
	sort(all(res));
	pair<int,int>p=mp(res[n/2 -1],res[n/2]);
	rep(i,n){
		cout<<((x[i] <p.S)?p.S:p.F)<<endl;
	}
}

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


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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, i, j;
int main() {
    cin >> n;
    for (i=11; n; i+=10) {
        for (j=2; j*j<=i && i%j>0; j++);
        if (j*j>i) cout << i << ' ', n--;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
#define v(T) vector<T>
#define vv(T) vector<v(T)>
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main()
{
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0, tmp = 0;
    for (int x : a){
        if (x==0) {
            ans += tmp/2;
            tmp = 0;
            continue;
        }
        tmp += x;
        
    }
    ans += tmp/2;
    cout << ans << endl;

}

Measured memory_bytes: 3728
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint w(n);
    int sum = 0;
    REP(i,n){
        cin >> w[i];
        sum += w[i];
    }
    int ans = sum;
    int now = 0;
    REP(i,n-1){
        now+=w[i];
        ans = min(ans, abs(now-(sum-now)));
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

N = n()


pos = {}

A = []
for i in xrange(N):
    a = n()
    A.append(a)
    pos[a] = i

A.sort()

c = 0
ok = True
for i in xrange(N):
    if pos[A[i]] % 2 != i % 2:
        c += 1

print c / 2


Measured memory_bytes: 18992
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b,int &x,int &y)
{
	if(b==0)
	{
		x=1; y=0;
		return a;
	}
	int g=gcd(b,a%b,x,y);
	int t1=y;
	int t2=x-(a/b)*y;
	x=t1;
	y=t2;
	return g;
}
int main() {
	// your code goes here
   int n,m; cin>>n>>m;
   int a[n];
   int flag=0;
   for(int i=0;i<n;++i)a[i]=-1;
   while(m--)
   {
   	int x,y; cin>>x>>y;
   	x--;
   	if(a[x]==-1)a[x]=y;
   	else if(a[x]!=y){
   		flag=1;
   		break;
   	}
   }
   if(flag)
   {
   	cout<<"-1";
   	return 0;
   }
   
   if(n==1)
   {
   	if(a[0]==-1||a[0]==0)
   	{
   		cout<<"0";
   		return 0;
   	}
   }
   for(int i=0;i<n;++i)
   {
   	if(a[i]==-1)
   	{
   		if(flag)a[i]=0;
   		else a[i]=1;
   		flag=1; 
   	}
    if(a[i]>0)
   	flag=1;
   else if(a[i]==0&&flag==0)
   {
   	cout<<"-1";
   	return 0;
   }
   flag=1;
   }
   for(int i=0;i<n;++i)cout<<a[i];
   return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int n = s.nextInt();
		int l = s.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < array.length; i++) {
			array[i] = l + i ;
		}
		int sum = Arrays.stream(array).sum();
		int res = calcNextSum(array,0);
		int diffMin = Math.abs(sum-calcNextSum(array,0));
		for(int i=1;i<array.length;i++) {
			int nextSum = calcNextSum(array,i);
			int diff=Math.abs(sum-nextSum);
			if(diffMin>diff) {
				diffMin = diff;
				res = nextSum;
			}
		}
		System.out.println(res);
	}
	public static int calcNextSum(int[] array, int eat) {
		int nextSum=0;
		for(int i=0;i<array.length;i++) {
			if(i!=eat) {
				nextSum+=array[i];
			}
		}
		return nextSum;
	}
}

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

 int main(){
  string A, B, C;
  string Aend, Bstart, Bend, Cstart;
  int An, Bn;

  cin >> A >> B >> C;
 
  An = A.size() -1;
  Bn = B.size() -1;

  Aend = A.substr(An);
  Bstart = B[0];

  Bend = B.substr(Bn);
  Cstart = C[0];

  if(Aend == Bstart && Bend == Cstart) cout << "YES" << endl;
   else cout << "NO" << endl; 

 
 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a[100], N, D, X, i;
    scanf("%d %d %d", &N, &D, &X);
    for(i=0;i<N;i++)scanf("%d", &(a[i]));
    for(i=0;i<N;i++){
        X += (D-1)/a[i] + 1;
    }
    printf("%d", X);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, x;
    cin >> n;
    vll p(n + 1, 0);
    for(i = 1; i <= n; i++)
        cin >> x, p[x] = i;
    for(i = 1; i <= n; i++)
        cout << p[i] << ' ';
    cout << endl; 
    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll A, B, C, K;
  while (cin >> A >> B >> C >> K) {
    ll res = 0;
    for (int a = 0; a <= K; a++) {
      for (int b = 0; a + b <= K; b++) {
        int c = K - a - b;
        ll sum = (A << a) + (B << b) + (C << c);
        res = max(res, sum);
      }
    }
    cout << res << endl;
  }
  return 0;
}


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

using namespace std;

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

const int N = 3000, mod = 2019;

int n;

int main()
{
    int l, r;
    cin >> l >> r;

    if(r - l > 2020)
    {
        puts("0");
        return 0;
    }

    LL res = 0x3f3f3f3f;
    for(int i = l; i <= r; i++)
        for(int j = i + 1; j <= r; j++)
            res = min(1LL * res, (LL)i * j % mod);

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    
public static void main (String[]args){
  Scanner input = new Scanner (System.in);
  int a = input.nextInt();
  int b = input.nextInt();
  int c = input.nextInt();
  int count5=0;
  int count7=0;
  if (a==5){     
      count5++;
  }
  else if (a==7){
      count7++;
  }
  if (b==5){     
      count5++;
  }
  else if (b==7){
      count7++;
  }
  if (c==5){     
      count5++;
  }
  else if (c==7){
      count7++;
  }
  if (count5==2 && count7==1){
      System.out.println("YES");
  }
  else{
      System.out.println("NO");
  }

}
}

Measured memory_bytes: 27000
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		String x = sc.next();
		String y = sc.next();
		String g1[] = {"1","3","5","7","8","10","12"};
		String g2[] = {"4","6","9","11"};
		String g3[] = {"2"};
		String cx = "";
		String cy = "";
		if(Arrays.asList(g1).contains(x)){
			cx = "g1";
		}else if(Arrays.asList(g2).contains(x)){
			cx = "g2";
		}else if(Arrays.asList(g3).contains(x)){
			cx = "g3";
		}
		if(Arrays.asList(g1).contains(y)){
			cy = "g1";
		}else if(Arrays.asList(g2).contains(y)){
			cy = "g2";
		}else if(Arrays.asList(g3).contains(y)){
			cy = "g3";
		}
		if(cx.equals(cy)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21460
n, q = map(int, input().split())

queue = []

for i in range(n):
    name, time = map(str, input().split())
    queue.append([name, int(time)])

time = 0

while len(queue) != 0:
    p = queue.pop(0)
    if p[1] <= q:
        time += p[1]
        print(p[0], time)
    else:
        time += q
        p[1] -= q
        queue.append(p)



Measured memory_bytes: 13016
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    ll n;
    cin >> n;
    vector<double> x(n);
    vector<double> y(n);
    rep(i, n) cin >> x.at(i) >> y.at(i);
    vector<double> ptn(n);
    rep(i, n) ptn.at(i) = i;
    double res = 0;
    double cnt = 0;

    do {
        cnt++;
        for(size_t i = 0; i < n - 1; i++) {

            res += sqrt(pow(x.at(ptn.at(i)) - x.at(ptn.at(i + 1)), 2) +
                        pow(y.at(ptn.at(i)) - y.at(ptn.at(i + 1)), 2));
        }
    } while(next_permutation(all(ptn)));
    cout << fixed << setprecision(15) << res / cnt;
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

	var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long X = inputArray[0];
			long Y = inputArray[1];


			var moshiSubeteTsuru = X * 2;
			var moshiSubeteKame = X * 4;

			if (Y < moshiSubeteTsuru | moshiSubeteKame < Y) {
				Console.WriteLine("No");
				return;
			}

			var sabun = Y - moshiSubeteTsuru;

			

			//答えの出力
			var ans = sabun %2 ==0 ? "Yes":"No";
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	vector<ll> dp(n);
	dp[0] = 1000;
	for(int i = 1; i < n; i++){
		dp[i] = dp[i - 1];
		for(int j = 0; j < i; j++){
			ll count = dp[j] / a[j];
			dp[i] = max(dp[i], dp[j] + (a[i] - a[j]) * count);
		}
	}
	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 307;
const int mod = 1e9 + 7;

inline int pls(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int mns(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline void Add(int &x, int y) { x = pls(x, y); }
inline void Minus(int &x, int y) { x = mns(x, y); }
inline void Mul(int &x, int y) { x = mul(x, y); }

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
struct Rec {
	int l, r, c;
	inline bool operator < (const Rec &v) const { return r < v.r; }
}b[maxN];
int f[maxN][maxN][maxN];

int main() {

	n = ri(), m = ri();
	rep (i, 1, m) b[i].l = ri(), b[i].r = ri(), b[i].c = ri();
	sort(b+1, b+m+1);

	int cur = 1;
	f[0][0][0] = 1;
	rep (i, 1, n) {
		For (k, 0, i) rep (j, 0, k) {
			Add(f[j][k][i], f[j][k][i-1]);
			Add(f[j][i-1][i], f[j][k][i-1]);
			Add(f[k][i-1][i], f[j][k][i-1]);
		}
		for (; cur <= m && b[cur].r == i; ++ cur) {
			For (k, 0, i) rep (j, 0, k) if (b[cur].c != 1 + (k >= b[cur].l) + (j >= b[cur].l))
				f[j][k][i] = 0;
		}
	}

	int res = 0;
	For (k, 0, n) rep (j, 0, k) Add(res, f[j][k][n]);

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

	return 0;
}

Measured memory_bytes: 110720
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
vector<H>e;
int pa[50];
int root(int x) {
	if (pa[x] == x) 
		return x;
	return pa[x] = root(pa[x]);
}
void unite(int x, int y) {
	x = root(x); y = root(y);
	pa[x] = y;
}
signed main() {
	int n, m, sum = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u1, u2;
		cin >> u1 >> u2;
		e.push_back(H{ --u1,--u2 });
	}
	for (int z = 0; z < m; z++) {
		for (int i = 0; i < n; i++)
			pa[i] = i;
		for (int i = 0; i < m; i++) {
			if (i != z) {
				unite(e[i].x, e[i].y);
			}
		}
		bool l = 0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (root(i) != root(j))
					l = 1;
		if (l) sum++;
	}
	cout << sum << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] x=new int[n];
        int[] y=new int[n];
        for(int i=0;i<n;i++){
            x[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            y[i]=sc.nextInt();
        }
        double D1=0,D2=0,D3=0,D=0;
        for(int i=0;i<n;i++){
            int d=Math.abs(x[i]-y[i]);
            D1+=d;
            D2+=d*d;
            D3+=d*d*d;
            if(D<d){
                D=d;
            }
        }
        System.out.printf("%.6f\n", D1);
        System.out.printf("%.6f\n", Math.sqrt(D2));
        System.out.printf("%.6f\n", Math.cbrt(D3));
        System.out.printf("%.6f\n", D);
    }
}


Measured memory_bytes: 26640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
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; }
const ll INF = 1LL << 60;


int main(){
    string n; cin >> n;
    ll ans = 0;
    int nd = n.size();
    int nx = int(n[0]-'0');
    int ny = int(n[nd-1]-'0');
    for(int ad=1; ad<=nd; ad++){
        for(int x=1; x<=9; x++){
            for(int y=1; y<=9; y++){
                for(int bd=1; bd<=ad; bd++){
                    if((ad==1 || bd==1) && (x!=y)) continue;
                    ll afr = pow(10.0,max(0,ad-2))+0.5;
                    ll bfr = pow(10.0,max(0,bd-2))+0.5;
                    if(nx==x &&  ad==nd && ad>2){
                        string tmp = n.substr(1,nd-2);
                        afr = stoi(tmp)+1;
                        if(ny<y && afr>0) afr--;
                    }
                    if(x>nx&&ad==nd) break;
                    if(ad==bd){
                        if(x<y) continue;
                        if(x==y && afr>0 ) ans += afr*afr;
                        else if(x>y) ans += afr*bfr*2;                      
                    }
                    else if(ad>bd){
                        ans+=afr*bfr*2;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<pair<double,double>> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i).first >> data.at(i).second;
  }
  double ans = 0, sub = 1;
  for(int i = 0; i < N - 1; i++)sub *=(i + 1);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      ans += sqrt(pow(data.at(i).first - data.at(j).first, 2) + pow(data.at(i).second - data.at(j).second, 2)) * sub;
    }
  }
  cout << setprecision(100) << ans / (sub * N) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

char buf[1000+10];

int main(void) {
  int w;
  cin >> buf >> w;
  for(int i = 0; buf[i]; i += w) {
    putchar(buf[i]);
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, S: str):
    print(YES if S[:N//2] == S[N//2:] else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <iomanip>
#include <vector>
//#include <boost/integer/common_factor_rt.hpp> // gcd, lcm
//#include <bits/stdc++.h>

using namespace std;

int main()
{
	long a, b, c, k;
	long sum=0;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> k;
	while (a > 0 && k > 0)
	{
		k--;
		sum++;
		a--;
	}
	while (b > 0 && k > 0)
	{
		k--;
		b--;
	}
	while (c > 0 && k > 0)
	{
		k--;
		sum--;
		c--;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#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 all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct Combination {
    vector<ll> kaijou;
    Combination() : kaijou(1001001, 1) {
        rep(i, 1001000) kaijou[i + 1] = (kaijou[i] * (i + 1)) % MOD;
    }
    ll modinv(ll a, ll m) {
        ll b = m, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
    ll c(int x, int y) {
        if (x < y || y < 0) return 0;
        return kaijou[x] * modinv(kaijou[x - y] * kaijou[y], MOD) % MOD;
    }
    ll h(int x, int y) {
        return c(x + y - 1, y);
    }
};

int main() {
    Combination comb;
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));

    ll ans = 0;
    rep(i, n) {
        ans += (comb.c(i, k - 1) * a[i]) % MOD;
        ans %= MOD;
        ans -= (comb.c(n - i - 1, k - 1) * a[i]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8832
n = int(input())
w = list(map(int, input().split()))

kei = sum(w)

absvalue = []

for t in range(1, n):
    subsum = sum(w[i] for i in range(t))
    nokori = kei - subsum
    absvalue.append(abs(subsum-nokori))

print(min(absvalue))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;
int N;
vector<long> list;
long long v;
long long kekka=0;
long long tuika;

int main()
{
	cin >> N;
	int A[N];
	for (int i=0; i < N; i++){
		 cin >> A[i];
		 v = v + A[i];
		 if (A[i]==0){
			 list.push_back(v);
			 v=0;
		 }
	}
	list.push_back(v);
	for (int j=0; j<list.size(); j++){
		tuika=list[j]/2;
		kekka = kekka + tuika;
	}
	cout<<kekka<<endl;
	return 0;
}

Measured memory_bytes: 1656
N, M = list(map(int, input().split()))
a = [int(input()) for _ in range(M)]
MOD = 10 ** 9 + 7
D = [0] * (N + 1)
D[0] = 1

a.append(10 ** 15)
c = 0
for i in range(1, N + 1):
  if a[c] == i:
    c += 1
    continue
  D[i] = D[i - 1]
  if i - 2 >= 0:
    D[i] = (D[i] + D[i - 2]) % MOD

print(D[-1])




Measured memory_bytes: 80960
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
	int x,a;
	cin>>x>>a;
	if(x<a)cout<<0<<endl;
	else cout<<10<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

string s, t;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> s >> t;
	ll ans = 0;
	for(ll i = 0; i < s.size(); i++){
		if(s[i] != t[i]){
			ans++;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
string s="";
while(n>0){
    s+=n/k;
    n/=k;
}
cout<<s.size()<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256