akhauriyash/Code-Regression huggingface dataset:
// AtCoder ABC138: B - Resistors in Parallel
// 2019.8.26 bal4u

#include <stdio.h>

int main()
{
	int a, N;
	double s;
	
	scanf("%d", &N);
	s = 0; while (N--) {
		scanf("%d", &a);
		s += 1.0/a;
	}
	printf("%.8lf\n", 1/s);
	return 0;
}

Measured memory_bytes: 128
def resolve():
  K, N = [int(i) for i in input().split()]
  A = tuple(int(i) for i in input().split())
  
  distance = [A[i+1] - A[i] for i in range(len(A)-1)]
  distance.append(K - A[-1] + A[0])
  print(K - max(distance))
resolve()

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}


void hawawa()
{
	int n;
	cin >> n;
	double t, a;
	cin >> t >> a;
	vector<double> h(n);
	for (auto&& i : h) {
		int high;
		cin >> high;
		i = t - high * 0.006;
	}
	double minabs = abs(h[0] - a);
	int p = 1;
	for (int i = 1; i < n; i++) {
		if (minabs > abs(h[i] - a)) {
			p = i + 1;
			minabs = abs(h[i] - a);
		}
	}
	cout << p << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

const Int MAX = 510000;
const Int MOD = 1000000007;

Int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (Int 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;
    }
}

// 二項係数計算
Int COM(Int n, Int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

Int f(Int a) {
    Int res = 1;
    Int n = mod - 2;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

Int n, k;
bool used[100005];
vector<Int> G[100005];
Int res = 1;

void dfs(Int x) {
    Int cnt = 0;
    Int al = 0;
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        Int to = G[x][i];
        if (!used[to]) {
            cnt++;
        }
        else {
            al++;
        }
        
    }
    if ((Int)G[x].size() + 1 > k) {
        res = 0;
    }
    else {
        Int x = k - (al + 1);
        Int mul = COM(x, cnt) * fac[cnt] % mod;
        res = (res * mul) % mod;
    }
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        Int to = G[x][i];
        if (!used[to]) {
            used[to] = true;
            dfs(to);
        }
    }
}

int main() {
    COMinit();
    cin >> n >> k;
    for (Int i = 0; i < n - 1; i++) {
        Int a, b;
        cin >> a >> b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    used[1] = true;
    res = k;
    dfs(1);
    dump(res);
    return 0;
}

Measured memory_bytes: 20096
h, w, k = [int(i) for i in input().split()]
ans = [[0] * w for _ in range(h)]
l = 1
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == "#":
            ans[i][j] = l
            l += 1


for i in range(h):
    for j in range(w-1):
        if ans[i][j+1] == 0:
            ans[i][j + 1] = ans[i][j]
for i in range(h):
    for j in reversed(range(w-1)):
        if ans[i][j] == 0:
            ans[i][j] = ans[i][j + 1]

for j in range(w):
    for i in range(h-1):
        if ans[i+1][j] == 0:
            ans[i+1][j] = ans[i][j]
for j in range(w):
    for i in reversed(range(h-1)):
        if ans[i][j] == 0:
            ans[i][j] = ans[i+1][j]
for i in ans:
    print(" ".join([str(j) for j in i]))


Measured memory_bytes: 47848
n,a,b = map(int,input().split())

mod = 10**9 + 7

def comb(n,k,mod):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%mod
    for i in range(2,k+1):
        inv[i]=mod-inv[mod%i]*(mod//i)%mod
        ans=ans*(n-k+i)*inv[i]%mod
    return ans

m = pow(2,n,mod) - 1

s = comb(n,a,mod)
t = comb(n,b,mod)

ans = m - s - t

print(ans%mod)

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

int n;
int main()
{
	int i, j;
	cin >> n;
	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= 9; j++) {
			if (i * j == n) {
				puts("Yes");
				return 0;
			}
		}
	}
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,m;
char s[maxn],t[maxn];
int gcd(int a,int b);
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s%s",s,t);
	if(s[0]!=t[0]){
		printf("-1\n");
		return 0;
	}
	else{
		int tt=gcd(n,m);
		int n1=n/tt,m1=m/tt;
		int flag=1;
		int f=1;
		int n2=n1,m2=m1;
		while(n2<=n-1&&m2<=m-1){
			if(s[n2]!=t[m2]) {
				flag=0;
				break;
			}
			f++;
			n2=n1*f,m2=m1*f;
		}
		if(flag){
			printf("%lld\n",(long long)(n/tt)*(long long)m);
		}
		else{
			printf("-1\n");
		}
	}
}
int gcd(int a,int b){
	int tmp; 
	while(b!=0){
		tmp=a%b;
		a=b;
		b=tmp;
	}
	return a;
}

Measured memory_bytes: 384
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n   = Integer.parseInt(scanner.nextLine());
		int max = 0;
		Map<String, Integer> map = new TreeMap<>();

		for(int i = 0; i < n; i++) {

			String x = scanner.nextLine();
			int val  = map.containsKey(x) ? map.get(x) + 1 : 1;
			map.put(x, val);
			max = Math.max(max, val);

		}

		for (var entry : map.entrySet()) {
			 if (entry.getValue() == max) {
				 System.out.println(entry.getKey());
	            }
		}

	}
}

Measured memory_bytes: 79268
s=list(input())
mod=10**9+7
n=len(s)

dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    if s[i]=="?":
        for k in range(10):
            for j in range(13):
                p=(k+10*j)%13
                dp[i+1][p]+=dp[i][j]
                dp[i+1][p]%=mod

    else:

        for j in range(13):
            p=(int(s[i])+10*j)%13
            dp[i+1][p]+=dp[i][j]
            dp[i+1][p]%=mod


print(dp[n][5])


Measured memory_bytes: 64888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

int main()
{
    int s;
    std::cin >> s;
    std::set<int> sets;

    int m = 0;
    do
    {
        sets.insert(s);
        s = (s % 2 == 0) ? s / 2 : s * 3 + 1;
        m++;
    } while (sets.count(s) == 0);
    m++;
    std::cout << m << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


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

main () {
	cin >> n >> k;
	forn (i, 1, n)
		cin >> h[i];	
	forn (i, 2, n) {
		dp[i] = inf;
		forn (j, max(1, i - k), i - 1)
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));				
	}

	cout << dp[n];
} 

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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






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


    int x; cin >> x;

    int res = 0;

    for (int i = 1; i < 10 && i <= x; i++) res++;
    for (int i = 100; i < 1000 && i <= x; i++) res++;
    for (int i = 10000; i < 100000 && i <= x; i++) res++;
    cout << res;




    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>

using namespace std;

#define N 100005

int dsu[N],ret[N];
long long W[N];
vector<int> edgeS[N];
bool isGoodEdge[N];

int f(int x) {
  if(x==dsu[x]) {
    return x;
  }
  return dsu[x] = f(dsu[x]);
}
void merge(int x,int y,int id,int wei) {
  x = f(x),y = f(y);
  if(x!=y) {
    if(edgeS[x].size()<edgeS[y].size()) {
      swap(x,y);
    }
    dsu[y] = x;
    W[x] += W[y];
    while(edgeS[y].size()>0) {
      edgeS[x].push_back(edgeS[y].back());
      edgeS[y].pop_back();
    }
  }
  edgeS[x].push_back(id);
  if(W[x]>=wei) {
    while(edgeS[x].size()>0) {
      isGoodEdge[edgeS[x].back()] = true;
      edgeS[x].pop_back();
    }
  }
}
void solve() {
  int n,m;
  scanf("%d %d",&n,&m);
  pair<int,pair<int,int> > edgeS[N];
  for(int i=1;i<=n;++i) {
    dsu[i] = i;
    scanf("%lld",&W[i]);
  }
  for(int i=0;i<m;++i) {
    scanf("%d %d %d",&edgeS[i].second.first,&edgeS[i].second.second,&edgeS[i].first);
  }
  sort(edgeS,edgeS+m);
  int R = 0;
  for(int i=0;i<m;++i) {
    int w = edgeS[i].first;
    int a = edgeS[i].second.first, b = edgeS[i].second.second;
    merge(a,b,i,w);
  }
  for(int i=0;i<m;++i) {
    if(isGoodEdge[i]) {
      ++R;
    }
  }
  printf("%d\n",m - R);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 8576
import sys
input = sys.stdin.readline


def f(n, W):
    dp = [0] * (W + 1)
    for i in range(n):
        wi, vi = map(int, input().split())
        for w in range(W, wi - 1, -1):
            v_ = dp[w - wi] + vi
            if dp[w] < v_:
                dp[w] = v_
    return(dp[-1])


n, w = map(int, input().split())
print(f(n, w))


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    double L;
    cin >> L;
    
    put_double(L/3.0*L/3.0*L/3.0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}
 
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}

int main(){
    dcl(n,k);
    vector<ll> a;
    int g=-1;
    rep(i,n){
        dcl(t);
        a.pb(t);
        if(!i){
            g=t;
        }
        g=gcd(g,t);
    }
    if(abs(k-a[0])%g==0 && k<=*max_element(all(a)) ){
        cout<<"POSSIBLE"<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }

}


Measured memory_bytes: 1400
#include <iostream>
#include<iomanip>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
using namespace std;

const int NN=5e6+10;

long long n;
long long a[100][100];


int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=50;i++){
        a[i][1]=50;
    }
    for(int i=1;i<=50;i++){
        for(int j=2;j<=50;j++){
            if(j>i){
                a[i][j]=a[i][i]-2;
            }
            else{
                a[i][j]=a[i][j-1]-1;
            }
        }
    }
    /*
    for(int i=1;i<=50;i++){
        for(int j=1;j<=50;j++){
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }*/
    printf("50\n");
    long long ans=n/50;
    if(n==50) {
        ans=0;
    }
    else if(n%50==0&&n>50){
        ans=ans-1;
    }
    int ans2=n%50;
    if(ans2==0) ans2=50;
    if(n==0) ans2=0;
    printf("%lld",a[ans2][1]+ans);
    for(int i=2;i<=50;i++){
        printf(" %lld",a[ans2][i]+ans);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int H, W;
    cin >> H >> W;

    vector<vector<int>> c(10, vector<int>(10, 0));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }

    vector<vector<int>> A(H, vector<int>(W));
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cin >> A[h][w];
        }
    }

    // dikstra
    // vector<int> dist(10, 1e9);
    // priority_queue<pair<int, int>, vector<pair<int, int>>,
    // greater<pair<int, int>>>
    // que;
    // que.emplace(0, 1);
    // dist[1] = 0;
    // while (!que.empty()) {
    // int index = que.top().second;
    // int cost = que.top().first;
    // que.pop();
    // if (dist[index] < cost) continue;
    // dist[index] = cost;
    // for (int i = 0; i < 10; i++) {
    // if (dist[i] == 1e9) {
    // que.emplace(cost + c[i][index], i);
    // }
    // }
    // }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    vector<int> dist(10);
    for (int i = 0; i < 10; i++) {
        dist[i] = c[i][1];
    }

    // for (int i = 0; i < 10; i++) {
    // cout << i << " " << dist[i] << endl;
    // }

    int output = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (A[h][w] != -1) {
                output += dist[A[h][w]];
            }
        }
    }
    cout << output << endl;

    return 0;
}


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

int main(){
	int n; cin>>n;
  	long a=0,b=0,c=0; long x,y,z; long  ta,tb,tc;
  	for(int i=0; i<n; i++){
      cin>>x>>y>>z;
      ta=x+max(b,c); tb=y+max(a,c); tc=z+max(a,b);
      a=ta; b=tb; c=tc;
    }
  	cout<<max(a,max(b,c))<<endl;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n, k = i_map()
    num_list = i_list()

    if n == k:
        print(1)
        exit()

    one_index = 0

    for i in range(n):
        if num_list[i] == 1:
            one_index = i
            break

    left_num = one_index
    right_num = n - one_index - 1

    count = 0

    left = left_num // (k-1)
    right = right_num // (k-1)

    count += left + right

    amari = n - 1 - (k-1) * (left+right)

    if amari > k - 1:
        count += 2
    elif amari == 0:
        pass
    else:
        count += 1
        
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 56304
#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 rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

void Main() {
  //自動整形防止用コメント
  int k, x;
  std::cin >> k >> x;
  repf(i, x - (k - 1), x + k) { std::cout << i << ' '; }

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  uint64_t K;
  std::cin >> K;
  uint64_t q = K / 50ull + 1;
  uint64_t r = 50ull - K % 50ull;
  if (K % 50ull == 0) {
    r = 0;
    --q;
  }
  if (q == 0) {
    if (r == 0) {
      std::cout << 2 << std::endl;
      std::cout << 1 << " " << 1 << std::endl;
    } else if (r == 1) {
      std::cout << 2 << std::endl;
      std::cout << 0 << " " << 2 << std::endl;
    } else {
      std::cout << r << std::endl;
      for (unsigned i = 0; i < r; ++i) {
        std::cout << i + 1 << " ";
      }
    }
  } else {
    std::cout << 50 << std::endl;
    for (unsigned i = 0; i < 50; ++i) {
      std::cout << (i < r ? q - 1 : q) << " ";
      ++q;
    }
  }
  std::cout << std::endl;
  return 0;
}

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

long long ans;
int A[101000];
int n;

int main() {
	scanf("%d",&n);
	n *= 2;
	for (int i = 1; i <= n; i++) scanf("%d",&A[i]);
	sort(A + 1, A + n + 1);
	for (int i = 1; i <= n; i += 2) ans += (long long)A[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int main()
{
    int n;
    int d;
    cin >> n >> d;
    
    cout << ceil(n/(2.0*d + 1.0));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> d(2*pow(10, 5));
    for (int i = 0; i<N; i++) {
        cin >> d[i];
    }

    sort(d.begin(), d.begin()+N);

    int hind = N / 2;
    
    if (d[hind-1] < d[hind]) {
        cout << (d[hind]-d[hind-1]);
    } else {
        cout << 0;
        // for (int i = 1; i < hind; i++) {
            
        //     if ((d[hind] == d[hind-i]) & (d[hind-i] == d[hind+1+i])) {
        //         continue;
        //     } else if ((d[hind-i] != d[hind+1+i]) & ((d[hind] != d[hind-i]) | (d[hind] != d[hind+1+i]))) {
        //         cout << 0;
        //         break;
        //     } else {

        //     }
        // }
    }



    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int a,b;
  int c;
  c = 0;
  scanf("%d%d",&a,&b);
  if(a >= 13){
    printf("%d\n",b);
  }else if ((6 <= a)&(a <= 12)){
    b = b / 2;
    printf("%d\n",b);
  }else{
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<int>sta,cyc;
int a[200005],vis[200005];
int main()
{
	int n;
	long long k;
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	} 
	int j=1;
	while (1)
	{
		vis[j]=1;
		sta.push_back(j); 
		j=a[j];
		if (vis[j])
		{
			while (1)
			{
				cyc.push_back(sta.back());
				int t=sta.back();
				sta.pop_back() ;
				if (t==j)   break;
			}
			break;
		}
	}
	reverse(cyc.begin(),cyc.end());
	if (k<sta.size() )
	{
		cout<<sta[k];
	}
	else
	{
		k-=sta.size();
		k%=cyc.size(); 
		cout<<cyc[k];
	}
	return 0;
} 

Measured memory_bytes: 7120
A, B = map(int, input().split())
if A % 2 == 0:
    num = B - A
    result = 0
else:
    num = (B - (A + 1))
    result = A
if num // 2 % 2 == 0:
    result ^= 0
else:
    result ^= 1
if num % 2 == 1:
    result ^= (B-1)
result ^= B
print(result)

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

ll Pow(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

bool cmp(const int &a, const int &b){
    return a < b;
}

ll gcd(ll x, ll y){
    return x % y == 0 ? y : gcd(y, x % y);
}

ll lcm(ll x, ll y){
    return x / gcd(x, y) * y;
}

const int MAXN = 2000 + 5;
const int mod = 1e9 + 7;
ll comb[MAXN][MAXN];

void init(){
	for (int i = 0; i < MAXN; i++){
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; j++){
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
			comb[i][j] %= mod;
		}
	}
}

const int MAXM = 1e6;
int primes[MAXM], cnt;
bool st[MAXN];

void get_prime(int n){
	for (int i = 2; i <= n; i++){
		if (!st[i]) primes[cnt++] = i;
		for (int j = 0; j < cnt && i * primes[j] <= n; j++){
			st[i * primes[j]] = true;
			if (i % primes[j] == 0) break;
		}
	}
}

int main(){
    int n, d;
    scanf("%d%d", &n, &d);
    int x[15][15] = {0};
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= d; j++)
            scanf("%d", &x[i][j]);
    int cnt = 0;
    for (int i = 1; i <= n; i++){
        for (int j = i + 1; j <= n; j++){
            int tmp = 0;
            for (int k = 1; k <= d; k++)
                tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            if ((int)sqrt(tmp) * (int)sqrt(tmp) == tmp) cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,MA,MB;
    cin >> N >> MA >> MB;
    vector<pair<P,ll>> K(N);
    vector<P> p(N);
    rep(i,N){
        cin >> K[i].first.first >> K[i].first.second >> K[i].second;
        K[i].first.first*=3628800;
        K[i].first.second*=3628800;
        K[i].first.first/=MA;
        K[i].first.second/=MB;
        p[i].second=K[i].second;
        p[i].first=K[i].first.first-K[i].first.second;
    }
    //ぜんはーん
    ll H=(N+1)/2;
    N-=H;
    vector<P> fi(1<<H);
    rep(i,1<<H){
        ll rescost=0,resd=0;
        rep(j,H){
            if((i>>j)&1){
                rescost+=p[j].second;
                resd+=p[j].first;
            }
        }
        fi[i]={resd,rescost};
    }
    sort(fi.begin(),fi.end());
    fi.pb({INF,INF});
    P x=*lower_bound(fi.begin(),fi.end(),make_pair(0LL,1LL));
    ll ans=INF;
    if(x.first==0){
        ans=x.second;
    }
    rep(i,1<<N){
        ll rescost=0,resd=0;
        rep(j,N){
            if((i>>j)&1){
                rescost+=p[H+j].second;
                resd+=p[H+j].first;
            }
        }
        //cout << resd << ' ' << rescost << '\n';
        P A=*lower_bound(fi.begin(),fi.end(),make_pair(-resd,-INF));
        if(A.first+resd==0){
            if(rescost+A.second!=0)
            chmin(ans,rescost+A.second);
        }
    }
    cout << (ans==INF?-1:ans) << '\n';
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 35896
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int n, a[MAXN], f[MAXN];
ll m;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) cin >> a[i];
    ll lcmNow = 1;
    m *= 2;
    FOR(i,1,n) {
        lcmNow = lcm(lcmNow, a[i]);
        if (lcmNow > m) {
            cout << 0;
            return 0;
        }
    }
    FOR(i,1,n) {
        ll x = lcmNow / a[i];
        f[i] = x % 2;
    }
    int sum = 0;
    FOR(i,1,n) sum += f[i];
    if (sum == 0) {
        ll p = m / lcmNow;
        cout << p / 2;
    }
    else if (sum == n) {
        ll p = m / lcmNow;
        cout << p / 2 + p % 2;
    }
    else cout << 0;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    int n;
    cin >> n;    

    vector<int> a(n), b(n-1);

    for(int i= 0; i < n-1; ++i){
        cin >> b[i];
    }

    a[0] = b[0];
    for(int i = 0; i < n-2; ++i){
        a[i+1] = min(b[i], b[i+1]);
    }
    a[n-1] = b[n-2];

    int ans = 0;

    for(int i = 0; i < n; ++i){
        ans += a[i];
    }
    cout  << ans << endl;
}

Measured memory_bytes: 256
a = gets.chop.to_i
b = gets.chop.to_i
c = gets.chop.to_i
d = gets.chop.to_i
e = gets.chop.to_i

times = [a,b,c,d,e]
ftimes = []

times.each_with_index do |t,i|
  s = t%10
  if s != 0
    ftimes.push(s)
  else
    ftimes.push(9)
  end
end

result = times[ftimes.index(ftimes.min)]
times.delete_at(ftimes.index(ftimes.min))


times.each_with_index do |t,i|
  s = t%10
  if s != 0
    result += (t-s+10)
  else
    result += t
  end
end

puts result


Measured memory_bytes: 1788
//organize and stay in moment - Abhinav IIIT-A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,x,n) for(int i=x;i<n;++i)
#define ar array
#define MAXN (int)2e5+5
#define pb push_back
int mod= 1e9+7;
int mod2=998244353;
int arr[MAXN];
int as;
void input(){
  cin>>as;
  f(i,0,as) cin>>arr[i];
}
void solve(){
	int h,w; cin>>h>>w;
	string s[h];
	f(i,0,h)
	cin>>s[i];
	int ans[h][w];
	f(i,0,h)
	f(j,0,w){
		if(i==0 && j==0){
			if(s[i][j]=='#')
				ans[i][j]=1;
			else ans[i][j]=0;
		}else if(i==0){
			if(s[i][j]=='.')
				ans[i][j]=ans[i][j-1];
			else if(s[i][j-1]=='#')
				ans[i][j]=ans[i][j-1];
			else ans[i][j]=ans[i][j-1]+1;
		}else if(j==0){
			if(s[i][j]=='.')
				ans[i][j]=ans[i-1][j];
			else if(s[i-1][j]=='#')
				ans[i][j]=ans[i-1][j];
			else ans[i][j]=ans[i-1][j]+1;
		}else{
			int top,left;
			if(s[i][j]=='.'){
				top=ans[i-1][j];
				left=ans[i][j-1];
			}else{
				if(s[i-1][j]=='#')
					top=ans[i-1][j];
				else top=ans[i-1][j]+1;
				if(s[i][j-1]=='#')
					left=ans[i][j-1];
				else left=ans[i][j-1]+1;
			}
			ans[i][j]=min(top,left);
		}
	}
  cout<<ans[h-1][w-1]<<"\n";
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t; t=1; //cin>>t;
  while(t--) solve();
  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>

int main(){
    int d;
    std::cin >> d;
    std::vector<int> c(26);
    for(int i = 0; i < 26; i++){
        std::cin >> c[i];
    }
    std::vector<std::vector<int>> s(d, std::vector<int>(26));
    for(int j = 0; j < d; j++){
        for(int i = 0; i < 26; i++){
            std::cin >> s[j][i];
        }
    }
    std::vector<int> t(d);
    for(int j = 0; j < d; j++){
        std::cin >> t[j];
    }


    std::vector<int> l(26);
    for(int i = 0; i < 26; i++){
        l[i] = 0;
    }

    int v = 0;
    for(int j = 0; j < d; j++){
        for(int i = 0; i < 26; i++){
            if(i == t[j] - 1){
                v = v + s[j][i];
                l[i] = j + 1;
            }
            else{
                v = v - c[i]*(j + 1 - l[i]);
            }
        }
        std::cout << v << std::endl;
    }
}

Measured memory_bytes: 3596
from operator import attrgetter


class Damage:
    def __init__(self, a, b):
        self.a = a
        self.b = b


N, H = map(int, input().split())
damages = []
for _ in range(N):
    a, b = map(int, input().split())
    damages.append(Damage(a, b))
damages = sorted(damages, key=attrgetter("b"), reverse=True)

max_a_damage = (max(damages, key=lambda damage: damage.a)).a
cnt = 0
sum = 0
for damage in damages:
    if damage.b <= max_a_damage:
        cnt += int((H-sum) / max_a_damage)
        if (H-sum) % max_a_damage > 0:
            cnt += 1
        sum = H
        break
    else:
        cnt += 1
        sum += damage.b
        if H <= sum:
            break
if H-sum > 0:
    cnt += int((H-sum) / max_a_damage)
    if (H-sum) % max_a_damage > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 29096
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll dp[310][310][310];
int main() {
    int N, K; cin >> N >> K;
    vector<ll> H(N);
    for(int i=0; i<N; i++) cin >> H[i];

    vector<ll> M = H;
    M.emplace_back(0);
    sort(M.begin(), M.end());
    M.erase(unique(M.begin(), M.end()), M.end());

    fill(dp[0][0], dp[N+1][0], LONGINF);
    dp[0][0][0] = 0;
    for(int i=0; i<N; i++) {
        for(int j=0; j<=K; j++) {            
            ll opt_less = LONGINF;
            for(int k=0; k<(int)M.size(); k++) {
                chmin(opt_less, dp[i][j][k]);
                chmin(dp[i+1][j+(M[k]!=H[i])][k], opt_less);
                if(k+1<(int)M.size()) opt_less += M[k+1] - M[k];
            }

            ll opt_more = LONGINF;
            for(int k=(int)M.size()-1; k>=0; k--) {
                chmin(opt_more, dp[i][j][k]);
                chmin(dp[i+1][j+(M[k]!=H[i])][k], opt_more);                
            }
        }
    }

    ll ans = LONGINF;
    for(int j=0; j<=K; j++) {
        for(int k=0; k<(int)M.size(); k++) {
            chmin(ans, dp[N][j][k]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 227712
#include <iostream>
using namespace std;
using ll = long long int;

#define MAX_N 1000000000000

ll N;
ll X;

ll gcd(ll a, ll b){
    ll r;
    r = a % b;
    if(r == 0)  return b;
    else   return gcd(b, r);
}

void solve(){
    cout << 3 * (N - gcd(N - X, X)) << endl;
}


int main(){
    cin >> N >> X;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int m,f,r;

	for(i = 0; 1; i++)
	{
		scanf("%d %d %d", &m,&f,&r);

		if(m == -1 && f == -1 && r == -1)
		{
			break;
		}

		if(m == -1 || f == -1)
		{
			printf("F\n");

		}else if (m + f >= 80) 
		{
			printf("A\n");

		}else if (m + f < 80 && m + f >= 65) 
		{
			printf("B\n");

		}else if (m + f < 65 && m + f >= 50) 
		{
			printf("C\n");
		
		}else if (m + f < 50 && m + f >= 30) 
		{
			if(r >= 50)
			{
				printf("C\n");
			}else 
			{
				printf("D\n");
			}
		}else if (m + f < 30) 
		{
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
V<int> dx={1,0,-1,0},dy={0,-1,0,1};
map<P,P> mp;
int main(){
  int n;
  cin>>n;
  V<int> s(n);
  for(int i=0;i<n;i++)cin>>s[i];
  int cnt=1,ans=0;
  for(int i=0;i<n;i++){
    if(s[i]==cnt){cnt++;}
    else ans++;
  }
  if(cnt==1)cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;

	int dup = 0;
	for (int i = 0; i < n; i++) {
		int tmp = 0;
		for (int j = 0; j <= n; j++) {
			if (j == n || s[i + j] != t[j]) {
				dup = max(dup, tmp);
				break;
			}
			tmp++;
		}
	}
	cout << 2 * n - dup << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i < (int)n; i++)

using namespace std;
typedef long long int ll;

int n, k;
vector<int> w(100000);

bool judge(int p) {
	bool ret = true;
	int s = 1, t = 0;
	Loop(i, n) {
		if (t + w[i] > p) {
			s++;
			if (s > k) {
				ret = false;
				break;
			}
			t = 0;
		}
		t += w[i];
	}
	return ret;
}

int main() {
	cin >> n >> k;
	int wmax = 0, sumw = 0;
	Loop(i, n) {
		cin >> w[i];
		if (w[i] > wmax) wmax = w[i];
		sumw += w[i];
	}
	int left = wmax, right = sumw;
	int p = (left + right) / 2;
	while (left < right) {
		if (judge(p)) right = p;
		else left = p + 1;
		p = (left + right) / 2;
	}
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 3116
#include<iostream>

using namespace std;

int main() {
	int a,b,c,d,l,r;
	cin >> a >> b >> c >> d;
	l = a + b;
	r = c + d;
	if (l > r) cout << "Left" << endl;
	else if (l == r)cout << "Balanced" << endl;
	else cout << "Right"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
cnt = [0,0]
s = [0,0]

def is_pos(x,i):
    if not x >= 1:
        cnt[i] += 1-x
        s[i] = 1
    return

def is_neg(x,i):
    if not x <= -1:
        cnt[i] += 1+x
        s[i] = -1
    return
    
for i in range(n):
    s[0] += a[i]
    s[1] += a[i]
    x = i%2
    y = (i+1)%2
    is_pos(s[x],x)
    is_neg(s[y],y)

ans = min(cnt)
print(ans)

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(b[0]==a[a.length()-1] && b[b.length()-1]==c[0]) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	string str;
	cin >> str;

	stack<int> s0;
	stack<pair<int, int>> s1;

	int sum = 0;
	for (int i = 0; i < str.length(); i++)
	{
		if (str.substr(i, 1) == "\\")
		{
			s0.push(i);
		}
		else if(str.substr(i, 1) == "/" && s0.size() > 0)
		{
			int j = s0.top();
			s0.pop();
			int a = i - j;
			sum += a;

			for (;s1.size() > 0 && s1.top().first > j;)
			{
				a += s1.top().second;
				s1.pop();
			}

			s1.push(make_pair(j, a));
		}
	}

	vector<int> ans;
	for (; s1.size();)
	{
		ans.push_back(s1.top().second);
		s1.pop();
	}

	reverse(ans.begin(), ans.end());
	cout << sum << endl;

	cout << ans.size();

	for (int i = 0; i < ans.size(); i++)
	{
		cout << " " << ans.at(i);
	}

	cout << endl;
}


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

int main(){
    string str, p, command;
    int q, a, b;
    cin >> str >> q;
    for (int i=0; i<q; i++) {
        cin >> command >> a >> b;
        if (command == "print") {
            cout << str.substr(a, b-a+1) << endl;
        } else if (command == "replace") {
            cin >> p;
            str = str.replace(a, b-a+1, p);
        } else {
            string tmp = str.substr(a, b-a+1);
            int n = tmp.size();
            for(int j = 0; j<n; j++) {
                str[j+a]=tmp[n-j-1];
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int primeCnt = 0;
		for (int i = 0; i < n; i++) {
			if (checkPrimeNumber(Integer.parseInt(br.readLine()))) primeCnt++;
		}
		System.out.println(primeCnt);
	}

	public static boolean checkPrimeNumber(int target) {
		if (target < 2) return false;
		if (target == 2) return true;
		if (target % 2 == 0) return false;

		for (int i = 3; i <= Math.sqrt(target); i += 2) {
			if (target % i == 0) return false;
		}
		return true;
	}
}

Measured memory_bytes: 30268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = str[0];
            var M = str[1];
            var X = str[2];
            var ryo = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var costunder = 0;
            var costupper = 0;
            
            for(var i=0;i<M;i++)
            {
                if (ryo[i] < X)
                    costunder++;
                else if (ryo[i] > X)
                    costupper++;
            }
            Console.WriteLine(Math.Min(costunder, costupper));
        }
    }
}



Measured memory_bytes: 11092
import std.stdio, std.functional, std.algorithm;

real calcImpl(int n, int m, int target){
	if(n == 0) return target == 0? 1: 0;
	real result = 0;
	foreach(i; 1..m+1) result += calc(n-1, m, target-i);
	return result;
}
alias memoize!calcImpl calc;

void main(){
	while(true){
		int n, m, k;
		readf("%d %d %d", &n, &m, &k);readln();
		if(n == 0 || m == 0) break;
		real eval = 0;
		foreach(i; n..m*n+1){
			eval += max(1.0, i-k)*calc(n, m, i);
		}
		writefln("%.8f",eval/(m^^n));
	}
}

Measured memory_bytes: 4452
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter
    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    A = list(map(int, input().split()))

    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    l = [0]
    for i in range(N-1):
        l.append(gcd(l[-1], A[i]))
    r = [0]
    for i in range(N-1, 0, -1):
        r.append(gcd(r[-1], A[i]))
    
    res = 0
    for i in range(N):
        res = max(res, gcd(l[i], r[-(i+1)]))
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14520
#include<bits/stdc++.h>
using namespace std;
const int MAX=10000;
const int INF=123456789;
vector<pair<int,int> > G[MAX];
list<int> out;
int indeg[MAX];
bool V[MAX];
int n;
void bfs(int s){
  queue<int> q;
  q.push(s);
  V[s]=true;
  while(!q.empty()){
    int u=q.front();q.pop();
    out.push_back(u);
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i].first;
      indeg[v]--;
      if(indeg[v]==0&&!V[v]){
        V[v]=true;
        q.push(v);
      }
    }
  }
}

void toposort(){
  for(int i=0;i<n;i++){
      indeg[i]=0;
  }
  for(int u=0;u<n;u++){
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i].first;
      indeg[v]++;
    }
  }

  for(int u=0;u<n;u++){
    if(indeg[u]==0&&!V[u]){
       bfs(u);
    }
  }
}

int main(){
  int e;
  cin>>n>>e;
  for(int i=0;i<n;i++){
    V[i]=false;
  }

  for(int i=0;i<e;i++){
    int s,t;
    cin>>s>>t;
    G[s].push_back(make_pair(t,1));
  }

  toposort();

  for(list<int>::iterator p=out.begin();p!=out.end();p++){
    cout<<*p<<endl;
  }
return 0;
}

Measured memory_bytes: 4228
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int K, T;
    cin >> K >> T;
    vint a(T);
    rep(i, T) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int now = a[0];
    ll ans = 0;
    if (T == 1) {
        cout << now - 1 << endl;
        return 0;
    }
    REP(i, 1, T - 1) {
        if (now - a[i] >= 0) {
            now -= a[i];
        }
        else {
            now = a[i] - now;
        }
    }
    if (now > a[T - 1]) {
        ans = max(0, now - a[T - 1] - 1);
    }
    else {
        ans = max(0, a[T - 1] - now - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256