akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 

signed main(){
	IOS;
	int n , w ; 
	cin >> n >> w ;
	vector<int>dp(w+1,0);
	for(int i=0;i<n;i++){
		int value , weight;
		cin >> weight >> value ;
		for(int j = w - weight ; j >= 0 ;j--){
			dp[j+weight] = max(dp[j+weight],dp[j]+value);
		}
	}
	cout << dp.back() << endl; 
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 666666
int arr[N];
int n,m;
map<int,int> mp;
vector<int> v[N];
int f(int a,int b){
	int s=1;
	while(b){
		if(b%2) s*=a;
		b/=2;a*=a;
	}
	return s;
}

signed main(){
	for(int i=-250;i<=250;i++) mp[i]=f(i,5);
	int n;
	cin>>n;
	
	for(int i=-250;i<=250;i++){
		for(int j=-250;j<=250;j++){
			if(mp[i]-mp[j]==n){
				cout<<i<<" "<<j;return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 19248
# BFS
from collections import deque

N=int(input())

dp = [-1] * 200005;
q = deque()

g = [1]
a = 6
while a <= 100000:
  g.append(a)
  a *= 6
a = 9
while a <= 100000:
  g.append(a)
  a *= 9
g.sort(reverse=True)

dp[0] = 0
q.append(0)

while len(q) > 0:
  v = q.popleft()
  if v == N: break
  for j in g:
    if dp[v+j] != -1: continue
    if v+j > N: continue
    dp[v+j] = dp[v] + 1
    q.append(v+j)

print(dp[N])


Measured memory_bytes: 5580
use itertools::Itertools;
fn main() {
    proconio::input! {
        n:String,
    }
    let mut a=n.chars().collect_vec();
    let mut b=a.len();
    for i in 0..a.len() {
        if a[i]=='A' {b-=i;break}
    }
    a.reverse();
    for i in 0..a.len() {
        if a[i]=='Z' {b-=i;break}
    }
    println!("{}",b)
}

Measured memory_bytes: 3256
#include<stdio.h>

int main()
{
    int i, j, n, k, l,  m;
    int g[100][100] = {0};
    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%d", &m);
        scanf("%d", &k);
        for(j = 0; j < k; j++){
            scanf("%d", &l);
            g[m - 1][l - 1] = 1;
        }
    }

    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(j == n - 1){
                printf("%d", g[i][j]);
            }
            else{
                printf("%d ", g[i][j]);
            }
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2140
from collections import defaultdict


def main():
    counter = defaultdict(int)
    H, W = list(map(int, input().split(' ')))
    for _ in range(H):
        A = input()
        for a in A:
            counter[a] += 1
    if H % 2 == W % 2 == 0:
        # 全ての個数が4の倍数ならOK
        for cnt in counter.values():
            if cnt % 4 != 0:
                print('No')
                return
        print('Yes')
    elif H % 2 == 0 and W % 2 == 1:
        non_quad_chars = 0
        for cnt in counter.values():
            if cnt % 4 == 1 or cnt % 4 == 3:
                print('No')
                return
            elif cnt % 4 == 2:
                non_quad_chars += 1
        if 2 * non_quad_chars <= H and (H - 2 * non_quad_chars) % 4 == 0:
            print('Yes')
        else:
            print('No')
    elif H % 2 == 1 and W % 2 == 0:
        non_quad_chars = 0
        for cnt in counter.values():
            if cnt % 4 == 1 or cnt % 4 == 3:
                print('No')
                return
            elif cnt % 4 == 2:
                non_quad_chars += 1
        if 2 * non_quad_chars <= W and (W - 2 * non_quad_chars) % 4 == 0:
            print('Yes')
        else:
            print('No')
    else:
        center_filled = False
        non_quad_chars = 0
        for cnt in counter.values():
            if cnt % 4 == 1 or cnt % 4 == 3:
                if center_filled:
                    print('No')
                    return
                center_filled = True
                if (cnt - 1) % 4 == 2:
                    non_quad_chars += 1
            elif cnt % 4 == 2:
                non_quad_chars += 1
        if 2 * non_quad_chars <= H + W - 2 and (H + W - 2 - 2 * non_quad_chars) % 4 == 0:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9440
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 200000
typedef long long ll;
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	ll ren[SIZE];
	vector<int>ko[SIZE];
	bool isact[SIZE];
	int st[SIZE];
	void init()
	{
		for (int i = 0; i < SIZE; i++)
		{
			par[i] = i;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return find(par[a]);
	}
	int actfind(int a)
	{
		if (a == par[a] || !isact[a])return a;
		else return actfind(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
			ko[a].push_back(b);
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
			ko[b].push_back(a);
		}
		if (ran[a] == ran[b])ran[b]++;
	}
	void activate(int a)
	{
		for (int i = st[a]; i < ko[a].size(); i++)
		{
			if (isact[ko[a][i]])continue;
			activate(ko[a][i]);
			isact[ko[a][i]] = true;
		}
		st[a] = ko[a].size();
	}
};
unionfind uf;
typedef pair<ll, ll>pii;
typedef pair<ll, pii>pi3;
ll wei[202020];
int dat[202020];
ll sum[202020];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	uf.init();
	for (int i = 0; i < num; i++)scanf("%lld", &uf.ren[i]), wei[i] = uf.ren[i];
	vector<pi3>v;
	for (int i = 0; i < way; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--;
		v.push_back(make_pair(zc, make_pair(za, zb)));
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		int s = v[i].second.first, t = v[i].second.second;
		ll d = v[i].first;
		if (uf.find(s) == uf.find(t))continue;
		uf.unite(s, t);
		if (uf.ren[uf.find(s)] >= d)uf.activate(uf.find(s));
	}
	for (int i = 0; i < num; i++)dat[i] = uf.actfind(i), sum[uf.actfind(i)] += wei[i];
	int r = 0;
	for (int i = 0; i < v.size(); i++)
	{
		int s = v[i].second.first, t = v[i].second.second;
		ll d = v[i].first;
		if (dat[s] != dat[t] || sum[dat[s]] < d)r++;
	}
	printf("%d\n", r);
}

Measured memory_bytes: 15984
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N+1];
        for(int i = 1;i <= N;i++){
            a[i] = sc.nextInt();
        }
        int count = 1;
        int x = a[1];
        for(int i = 1;i <= N;i++){
            if(x == 2){
                System.out.println(count);
                return;
            }
            count++;
            x = a[x];
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 51348
def main()->None:
    # http://drken1215.hatenablog.com/entry/2019/03/28/014100
    N = int(input())
    A = list(map(int, input().split()))

    res = 0
    i = 0
    while i < N  :
        # sameを抜ける
        while (i+1 < N) and (A[i] == A[i+1]):
            i += 1 
        # up
        if (i+1 < N) and (A[i] < A[i+1]):
            while (i+1 < N) and (A[i] <= A[i+1]):
                i += 1
        # down
        elif (i+1 < N) and A[i] > A[i+1]:
            while (i+1 < N) and (A[i] >= A[i+1]):
                i += 1
        res += 1
        i += 1
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14436
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        map<int, bool> mp;
        bool f = false;
        rep (i, m) {
                int a = i + 1, b = n - i;
                int c = b - a - 1, d = (n - 2) - (b - a - 1);

                if (c == d || mp[c] || mp[d]) f = true;
                cout << a << " " << b - f << endl;
                mp[c - f] = mp[d + f] = true;
        }

        return 0;
}


Measured memory_bytes: 11880
/* ex 9_2
   nnasy */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//スタックに格納するデータの最大数
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    int count = 0;
    char input[SIZE];
    scanf("%s", input);
    //最初のノードの指す先
    node *first = NULL;

    for (int i=0; i<strlen(input); i++){
        if (first==NULL){
            push(&first, input[i]);
        }else{
            if (input[i]==first->elem){
                push(&first, input[i]);
            }else{
                pop(&first);
                count += 2;
            }
        }
    }

    printf("%d\n", count);
    return 0;
}

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

set<int> f[100005];
int memo[100005],ans[100005],bro[100005];

int dfs(int now,int cnt)
{
	int as=1;
	for (auto i = f[now].begin(); i != f[now].end(); ++i)
	{
		int a=*i;
		if (memo[a]==-1)
		{
			memo[a]=cnt;
			as+=dfs(a,cnt);
		}
	}
	return as;
}

int main(int argc, char const *argv[])
{
	int n,m,k;
	cin>>n>>m>>k;
	int a,b;
	for (int i = 0; i < m; ++i)
	{
		cin>>a>>b;
		--a;
		--b;
		f[a].insert(b);
		f[b].insert(a);
		--bro[a];
		--bro[b];
	}
	int c[k],d[k];
	for (int i = 0; i < k; ++i)
	{
		cin>>c[i]>>d[i];
		--c[i];
		--d[i];
	}
	for (int i = 0; i < n; ++i)
	{
		memo[i]=-1;
	}
	int cnt=0;
	for (int i = 0; i < n; ++i)
	{
		if (memo[i]==-1)
		{
			memo[i]=cnt;
			ans[cnt]=dfs(i,cnt);
			++cnt;
		}
	}
	for (int i = 0; i < k; ++i)
	{
		if (memo[c[i]]==memo[d[i]])
		{
			--bro[c[i]];
			--bro[d[i]];
		}
	}
	cout<<ans[memo[0]]+bro[0]-1;
	for (int i = 1; i < n; ++i)
	{
		cout<<" "<<ans[memo[i]]+bro[i]-1;
	}
	cout<<endl;
	return 0;
}


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

X.sort()

def solve(X, P):
    ans = 0
    for x in X:
        ans += (P - x)**2
    return ans

ans = 100 * 100**2
for i in range(1, X[-1] + 1):
    ans = min(solve(X, i), ans)
print(ans)


Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int N,K;cin>>N>>K;
    ll ans=0;
    while(N){
        N/=K;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 200200;
const int Mod = 1e9 + 7;

int Inv[N];
int Fact[N];
int iFact[N];

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

void sub_self(int& x, int y)
{
    if((x -= y) < 0)    x += Mod;
}

int add(int x, int y)
{
    return add_self(x, y), x;
}

int sub(int x, int y)
{
    return sub_self(x, y), x;
}

int mul(int x, int y)
{
    return (ll) x * y % Mod;
}

int fp(int x, ll y)
{
    int Res = 1;
    for(; y > 0; y >>= 1, x = mul(x, x))
        if(y & 1)
            Res = mul(Res, x);
    return Res;
}

int C(int n, int m)
{
    if(n < 0)   return 0;
    if(m < 0)   return 0;
    if(n < m)   return 0;
    return mul(Fact[n], mul(iFact[m], iFact[n - m]));
}

void PreCalcMod()
{
    Inv[1] = 1;
    for(int i = 2; i < N; i++)  Inv[i] = (Mod - mul(Mod / i, Inv[Mod % i])) % Mod;

    Fact[0] = iFact[0] = 1;
    for(int i = 1; i < N; i++)  Fact[i] = mul(i, Fact[i - 1]);
    for(int i = 1; i < N; i++)  iFact[i] = mul(Inv[i], iFact[i - 1]);
}

struct SubTree
{
    int Size, Ways;

    SubTree(int Size = 0, int Ways = 1) : Size(Size), Ways(Ways) {}
    SubTree(const SubTree& Other) : SubTree(Other.Size, Other.Ways) {}
};

SubTree Merge(const SubTree& x, const SubTree& y)
{
    return SubTree(x.Size + y.Size, mul(mul(x.Ways, y.Ways), C(x.Size + y.Size, x.Size)));
}

int n;
int Ans[N];
SubTree Dp1[N];
SubTree Dp2[N];
vector <int> Adj[N];

void DFS1(int x = 1, int p = 0)
{
    for(int& y : Adj[x])
    {
        if(y == p)
        {
            swap(y, Adj[x].back());
            Adj[x].pop_back();
            break;
        }
    }

    Dp1[x] = Dp2[x] = SubTree();

    for(int y : Adj[x])
    {
        DFS1(y, x);
        Dp1[x] = Merge(Dp1[x], Dp1[y]);
    }

    Dp1[x].Size++;
}

void DFS2(int x = 1)
{
    int m = Adj[x].size();

    vector <SubTree> Prefix(m + 2, SubTree());
    vector <SubTree> Suffix(m + 2, SubTree());

    for(int i = 0; i < m; i++)  Prefix[i + 1] = Merge(Prefix[i], Dp1[Adj[x][i]]);
    for(int i = m - 1; ~i; --i) Suffix[i + 1] = Merge(Suffix[i + 2], Dp1[Adj[x][i]]);

    for(int i = 0; i < m; i++)
    {
        int y = Adj[x][i];

        Dp2[y] = Merge(Dp2[x], Merge(Prefix[i], Suffix[i + 2]));
    }

    for(int y : Adj[x]) Dp2[y].Size++, DFS2(y);
}

int main()
{
    PreCalcMod();

    cin >> n;

    for(int i = 1; i < n; i++)
    {
        int x, y;   scanf("%d%d", &x, &y);

        Adj[x].push_back(y);
        Adj[y].push_back(x);
    }

    DFS1();
    DFS2();

    for(int x = 1; x <= n; x++) Ans[x] = Merge(SubTree(Dp1[x].Size - 1, Dp1[x].Ways), Dp2[x]).Ways;

    for(int x = 1; x <= n; x++) printf("%d\n", Ans[x]);
}


Measured memory_bytes: 22656
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#define MAX 1000
#define INFTY 1<<30 // 2^30
using namespace std;
typedef long long llong;
 
static const int VMAX = 10000;
int n, A[MAX+10], s;
int B[MAX+10], T[VMAX+10];
 
int solve()
{
  int ans = 0;
  bool V[MAX+10];
  for(int i = 0; i < n; i++)
  {
    B[i] = A[i];
    V[i] = false;
  }
  sort(B,B+n);
  for(int i = 0; i < n; i++) T[B[i]] = i; // ????????????????????????????????????????????????
  for(int i = 0; i < n; i++)
  {
    if(V[i]) continue;
    int cur = i; // current point
    int S = 0; // sum of mass
    int m = VMAX; // min of the cycle
    int an = 0; // the number of material the cycle have
    while(1)
    {
      V[cur] = true; //already visited
      an++;
      int v = A[cur];
      m = min(m, v);
      S += v;
      cur = T[v];
      if(V[cur]) break;
    }
    ans += min(S+(an-2)*m, S+(an+1)*s+m);
  }
  return ans;
}
 
int main()
{
  cin >> n;
  s = VMAX;
  for(int i = 0; i < n; i++)
  {
    cin >> A[i];
    s = min(s,A[i]);
  }
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	sort(ALL(a));
	unordered_map<ll, ll> ma;
	REP(i, n) ma[a[i]]++;
	ll ans = 0;
	for(ll i = n - 1; i >= 0; i--) {
		if(ma[a[i]] == 0) continue;
		ma[a[i]]--;
		for(ll j = 2; j <= 2000000020; j *= 2) {
			if(j > a[i]) {
				if(ma[j - a[i]] > 0) {
					ma[j - a[i]]--;
					ans++;
				}
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 18420
// AGC039_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <cstring>  // std::memset 初期化
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

int main() {
    // input(sunippets: inpv, inpn, inps)
    string S;
    cin >> S;
    ll K;
    cin >> K;
    char s = S[0];
    ll check_all = 1;
    for (ll i = 1; i < S.size(); ++i) if (s == S[i]) check_all++;
    
    // calculation
    if (check_all == (ll)S.size()) {
        // 全部同じ文字のとき
        if (check_all%2 == 0) {
            cout << (check_all*K)/2 << "\n";
        } else {
            // 文字数が奇数のとき
            if (K%2 == 0) {
                // 最終的な文字数が偶数
                cout << (check_all*K)/2 + 1 << "\n";
            } else {
                // 最終的な文字数が奇数
                cout << (check_all*K)/2 << "\n";
            }
        }
    } else {
        vl vec;
        char ch = S[0];
        ll cnt = 1;
        for (ll i = 1; i < S.size(); ++i) {
            if (ch == S[i]) {
                cnt++;
            } else {
                vec.push_back(cnt);
                cnt = 1;
                ch = S[i];
            }
        }
        vec.push_back(cnt);
        
        if (S.front() != S.back()) {
            ll ans = 0;
            REP(i, vec.size()) {
                ans += vec[i]/2;
            }
            ans *= K;
            cout << ans << "\n";
        } else {
            // 内側を計算
            ll inner = 0;
            for (ll i = 1; i < (ll)vec.size()-1; ++i) {
                inner += vec[i]/2;
            }
            inner *= K;
            
            // 外側を計算
            // aaaeeaaa
            ll outer = 0;
            outer += vec.front()/2 + vec.back()/2;
            outer += ((vec.front()+vec.back())/2)*(K-1);
        
            cout << inner + outer << "\n";
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int n, per[200005];
bool rv[200005], alo[200005];

bool check(int num) 
{
	rep(i, n) rv[i] = per[i] > num;
	rep(i, n) alo[i] = (i == 0 || rv[i] != rv[i - 1]) && (i == n - 1 || rv[i] != rv[i + 1]);
	
	vector<int> vec;
	vec.push_back(1);
	for(int i = 1; i < n; i ++) if(alo[i] == alo[i - 1]) vec.back() ++;
	else {
		vec.back() *= alo[i - 1] ? -1 : 1;
		vec.push_back(1);
	}
	vec.back() *= alo[n - 1] ? -1 : 1;
	
	if(vec.size() == 1) {
		if(vec[0] < 0 && (n >> 1) & 1)
		rep(i, n) rv[i] ^= 1;
	} else {
		int pos = 0;
		rep(i, vec.size()) {
			if(vec[i] < 0) {
				bool ll = i == 0 ? rv[pos - vec[i]] : rv[pos - 1];
				bool rl = i == vec.size() - 1 ? rv[pos - 1] : rv[pos - vec[i]];
				rep(j, -vec[i]) rv[pos ++] = j < ((-vec[i]) >> 1) ? ll : rl;
			} else pos += vec[i];
		}
	}
	return rv[n >> 1];
}

int main()
{
	scanf("%d", &n);
	n = (n << 1) - 1;
	rep(i, n) scanf("%d", &per[i]);
	int l = 0, r = n;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(check(mid)) l = mid + 1;
		else r = mid;
	}
	printf("%d\n", r);
	return 0;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char s[100][100];
    for(int y=0;y<h;y++){
        for(int x=0;x<w;x++){
            cin >> s[y][x];
        }
    }
    for(int y=0;y<=h+1;y++){
        for(int x=0;x<=w+1;x++){
            if(y>0&&y<h+1&&x>0&&x<w+1)
            cout << s[y-1][x-1];
            else
            cout << '#';
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define maxn 200010
using namespace std;
ll dp[maxn][14];
void solve(string s)
{
	memset(dp,0,sizeof dp);
	int len=s.length();
	s="#"+s;
	dp[0][0]=1;
	for(int i=1;i<=len;i++)
	{
		int k=s[i]-'0';
		if(s[i]!='?')
		{
			for(int j=0;j<13;j++)
			{
				dp[i][(j*10+k)%13]+=dp[i-1][j];
				dp[i][(j*10+k)%13]%=mod;
			}
		}
		else
		{
			for(int k=0;k<=9;k++)
			{
				for(int j=0;j<13;j++)
				{
					dp[i][(j*10+k)%13]+=dp[i-1][j];
					dp[i][(j*10+k)%13]%=mod;
				}
			}
		}
	}
}
int main()
{
    string s;cin>>s;
    int len=s.length();
    solve(s);
    cout<<dp[len][5]%mod<<endl;
    return 0;
}

Measured memory_bytes: 22400
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,A,B;
  cin>>N>>A>>B;
  vector<int> C(N);
  for(int &i:C)cin>>i;
  int ok=1000000000,ng=0;
  while(ok-ng>1){
    int n=(ok+ng)/2,cnt=0;
    for(int i=0;i<N;i++)cnt+=(max(C[i]-n*B,0LL)+A-B-1)/(A-B);
    if(n>=cnt)ok=n;
    else ng=n;
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 3936
#include<bits/stdc++.h>
using namespace std;
void pre(){}
long long int mod = 1e9+7;
void solve(){
    long long int n,m;cin>>n>>m;
    bool arr[n+1][m+1];
    long long int dp[n+1][m+1];
    char c;
    for(long long int i=0;i<=n;i++){
        dp[i][0]=0;
        arr[i][0]=0;
    }
    for(long long int i=0;i<=m;i++){
        dp[0][i]=0;
        arr[0][i]=0;
    }
    for(long long int i=1;i<=n;i++){
        for(long long int j=1;j<=m;j++){
            cin>>c;
            if(c=='.'){
                arr[i][j]=1;
            }else{
                arr[i][j]=0;
            }
            dp[i][j]=0;
        }
    }
    for(long long int i=1;i<=n;i++){
        for(long long int j=1;j<=m;j++){
            if(i==1 && j==1){
                dp[1][1]=1;
                continue;
            }
            if(!arr[i][j]){
                continue;
            }
            dp[i][j]=dp[i-1][j]+dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][m]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  bool can = true;
  if(n%2 == 1) can = false;
  for(int i = 0;i < (n - 1);){
  	if(!(s[i] == 'h' && s[i+1] == 'i')){
  		can = false;
  	}
  	i = i + 2;
  }
  	if(can) cout << "Yes" << endl;
  	else cout << "No" << endl;
  return 0;
}


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

const int NMAX = 110;

int a[NMAX], n = 0;
long res = 0;

int main(){
	int tmp;
	while (cin >> tmp){
		++n;
		a[n] = tmp;
	}
	sort(a+1, a+n+1);
	for (int i=2; i<=n; ++i) res+=abs(a[i]-a[i-1]);
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

ll cul(ll p,ll q,ll n,vector<pll> &A){
    vector<bool> used(n,false);
    ll ret=n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(A[j].F-A[i].F==p && A[j].S-A[i].S==q){ret--;}
        }
    }
    return ret;
}


int main(){
    ll n;
    cin>>n;
    vector<pll> A(n);
    cin>>A;
    ll ans=n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j){
                ans=min(ans,cul(A[i].F-A[j].F,A[i].S-A[j].S,n,A));
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
a = input()

result = n+1
change_sum_w = [0]*n
change_sum_e = [0]*n

change_sum_w[0] = 0
change_sum_e[0] = a[1:n].count("E")

for i in range(n):
    tmp_count = change_sum_e[i] + change_sum_w[i]
    if i < n-1:
        change_sum_w[i+1] = change_sum_w[i] + 1 if a[i] == "W" else change_sum_w[i]
        change_sum_e[i+1] = change_sum_e[i] - 1 if a[i+1] == "E" else change_sum_e[i]

    if result > tmp_count:
        result = tmp_count

print(result)


Measured memory_bytes: 17808
#include<bits/stdc++.h>
using namespace std;
int n,A,B,h[111111];
int main(){
	scanf("%d%d%d",&n,&A,&B);
	A -= B;
	for(int i=0; i<n; i++)
		scanf("%d",&h[i]);
	int lo = 1, hi = 1000000000;
	while(lo!=hi){
		int mi = (lo + hi)/2;
		long long int todo = 0;
		for(int i=0; i<n; i++)
			if((long long int)B * mi < h[i]){
				todo += ((h[i] - B * mi -1) / A) + 1;
			}
		if(todo <= mi)
			hi = mi;
		else
			lo = mi+1;
	}
	printf("%d\n",lo);
	return 0;
}


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

int main() {

  ll a,ans;
  cin >> a;
  
  ll x = 100;
  ans = 1;
  
  while(ans < 1000000000000000) {
    x = x*1.01;
    if(x >= a) break;
    ans++;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 3624
//#define FILE_INPUT
#define _CRT_SECURE_NO_WARNINGS
//                 _                      
//                (_)                     
// _ __ ___   __ _ _  ___  _ __ _ __ ___  
//| '_ ` _ \ / _` | |/ _ \| '__| '__/ _ \ 
//| | | | | | (_| | | (_) | |  | | | (_) |
//|_| |_| |_|\__,_| |\___/|_|  |_|  \___/ 
//               _/ |                     
//              |__/                      
#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 unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vbl;
typedef tree<
    pll,
    null_type,
    less<pll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;

#define majorro cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define readvec(vector, n) {ll temp_vec_val;forn(inc, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size();\
                                    forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define printarr(arr, length, delimeter) {forn(elementarr, length){cout << arr[elementarr] << delimeter;}}
#define all(vector) (vector).begin(), (vector).end()
#define rall(vector) (vector).rbegin(), (vector).rend()
#define endl "\n"
  
struct pair_hash
{
    template <class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& pair) const
    {
        return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
    }
};
 
const ldbl EPS = 1e-6;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const ll MOD = 3037000499;
// const ull MOD = 1000000000000000003;
const ll INF = 1e18;
const ldbl pi = 2 * acos(0.0);
ll n, m, k, p, q, t, sum = 0, cnt= 0;
ll mx = -INF;
ll mn = INF;
bool flag = 0;
vll v;
str s = "", s1, s2;
 
void bad_solve(){}

void solve() //set.merge() -> c++17
//DELET DEBUG OUTPUT!11!1
//"YES"/"NO" OUTPUT!!!!
//__builtin_popcountll() -> __popcnt64() from <intrin.h>
{
    cin >> s;
    n = s.back()-'0';
    if(n == 3) cout << "bon";
    else if(!n || n == 1 || n == 6 || n == 8) cout << "pon";
    else cout << "hon";
}

int main()
{
#ifdef FILE_INPUT
    freopen("F:\\repos\\projects\\contests_vsc\\in.txt", "r", stdin);
    freopen("F:\\repos\\projects\\contests_vsc\\out.txt", "w", stdout);
#endif
    majorro
    
    solve();
  
    // freopen("test.txt", "w", stdout);
    // bad_solve();
  
//  memset(v, INT_MAX, 1000*2000*sizeof(int));
  
    return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

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

  ll ans=0;

  //bfs <digit,number,357exists>
  queue<pair<ll,tuple<bool,bool,bool>>> que;

  //initialize que with 3,5,7
  que.push(make_pair(3,make_tuple(true,false,false)));
  que.push(make_pair(5,make_tuple(false,true,false)));
  que.push(make_pair(7,make_tuple(false,false,true)));


  while(!que.empty()){
    pair<ll,tuple<bool,bool,bool>> p= que.front();
    que.pop();
    for(int i=3;i<=7;i+=2){
      ll x= p.first*10+i;
      // bigger than N to get out
      if(x>N)continue;
      //copy 357existance status
      tuple<bool,bool,bool> bools
        =make_tuple(get<0>(p.second),get<1>(p.second),get<2>(p.second));

      //analyze only if  any of 357 is missing
      if(!(get<0>(p.second) && get<1>(p.second) && get<2>(p.second))){
        if(i==3) get<0>(bools)=true;
        if(i==5) get<1>(bools)=true;
        if(i==7) get<2>(bools)=true;
      }
      if(get<0>(bools)&&get<1>(bools)&&get<2>(bools)) ans++;
      que.push(make_pair(x,bools));
    }
  }
  cout << ans;
}


Measured memory_bytes: 512
import itertools
 
N = int(input())
 
 
As = []
xys = []
for i in range(N):
    tmp = []
    As.append(int(input()))
    for i in range(As[-1]):
        tmp.append(list(map(int, input().split())))
    
    xys.append(tmp)
 
#bit演算の準備
bit_list = list(itertools.product(range(2), repeat = N))
 
#loop
ans = 0 #ansの初期設定
for bit in bit_list:
    unkind_count = 0
    for Aindex, A in enumerate(As):
        if(bit[Aindex] == 0):
            continue #Unkindの意見は参考にしない
        for xy in xys[Aindex]:
#            print(xy)
            #真偽値を値化
            honest_to_unkind = (xy[1] == 0 and bit[xy[0]-1] == 1)
            unkind_to_honest = (xy[1] == 1 and bit[xy[0]-1] == 0)
 
            if(honest_to_unkind or unkind_to_honest):
                unkind_count +=1
    
    if(unkind_count == 0):
#       print("yatta")
        ans = max(ans, sum(bit))
 
print(ans)

Measured memory_bytes: 8948
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	k := getNextInt(scanner)

	ba := make(BigArrays, n)
	for i := 0; i < n; i++ {
		ba[i].a = getNextInt(scanner)
		ba[i].b = getNextInt(scanner)
	}
	sort.Sort(ba)
	ans := 0

	for i := 0; i < n && k > 0; i++ {
		k -= ba[i].b
		ans = ba[i].a
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}

type BigArray struct {
	a, b int
}

type BigArrays []BigArray

func (a BigArrays) Len() int           { return len(a) }
func (a BigArrays) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a BigArrays) Less(i, j int) bool { return a[i].a < a[j].a }


Measured memory_bytes: 4352
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().strip().split()))
C = Counter(A)
ans = 0
for k, v in C.items():
    ans += v*(v-1)//2

for a in A:
    count = C[a]
    if count < 2:
        print(ans)
    else:
        print(ans-count+1)


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

int main() {
    
    int K;
    cin >> K;
    int ans = 0;
    for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
    for(int c = 1; c <= K; c++){
        ans += gcd(gcd(a,b),c);
    }
    }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>

int main(){
	int a,b,c,n,i;

	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%d%d%d",&a,&b,&c);
		if(a*a+b*b==c*c|c*c+b*b==a*a|a*a+c*c==b*b){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
package main

import "fmt"

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	ans := 10000
	ans = min(ans, abs((a+b)-(c+d)))
	ans = min(ans, abs((a+c)-(b+d)))
	ans = min(ans, abs((a+d)-(b+c)))
	fmt.Println(ans)
}



Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  int* dp = new int[n];
  dp[0]=arr[0];
  dp[1]=abs(arr[1]-arr[0]);
  dp[2]=min(dp[1]+abs(arr[2]-arr[1]),abs(arr[2]-arr[0]));
  for(int i=3;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;

#define MOD 1000000007

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

    ll N, K;
    cin >> N >> K;

    vector<p> v(N);

    for(ll i = 0; i < N; i++) {
        ll t, d;
        cin >> t >> d;
        v[i] = make_pair(d, t);
    }

    sort(v.begin(), v.end(), greater<p>());

    ll c = 0;
    ll k = 0;

    vector<ll> b(N + 10);

    for(ll i = 0; i < K; i++) {
        ll t = v[i].second;
        ll d = v[i].first;
        if(!b[t]) {
            k++;
        }
        b[t]++;
        c += d;
    }

    ll ans = c + k * k;

    ll pos = K - 1LL;

    for(ll i = K; i < N; i++) {
        ll t = v[i].second;
        ll d = v[i].first;
        if(b[t]) continue;
        while(true) {
            ll pt = v[pos].second;
            ll pd = v[pos].first;
            if(b[pt] > 1) {
                b[pt]--;
                b[t]++;
                k++;
                c -= pd;
                c += d;
                ans = max(ans, c + k * k);
            }
            pos--;
            if(pos < 0) {
                cout << ans << endl;
                return 0;
            }
            if(b[t]) break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5568
import java.awt.geom.*;
import java.util.*;
public class Main{
	double EPS = 1.0e-08;
	int INF = 1 << 24;
	//1240 start
	//1333 cording end
	//2325 restart
	//0007 sample match
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			Circle [] clist = new Circle[n];
			for(int i = 0; i < n; i++){
				Point2D p = new Point2D.Double(sc.nextInt(), sc.nextInt());
				clist[i] = new Circle(p, sc.nextInt());
			}
			
			ArrayList<Point2D> cand = new ArrayList<Point2D>();
			cand.add(clist[0].p);
			for(int i = 0; i < n-1; i++){
				Point2D [] res = intersectPtCC(clist[i], clist[i+1]);
				cand.add(res[0]);
				cand.add(res[1]);
			}
			cand.add(clist[n-1].p);
			
			int len = cand.size();
			double [][] dp = new double[len][len];
			for(int i = 0 ; i < len; i++){
				Arrays.fill(dp[i], INF);
				dp[i][i] = 0.0;
			}
			for(int i = 0; i < len; i++){
				for(int j = i + 1; j < len; j++){
					boolean isOK = true;
					Line2D m = new Line2D.Double(cand.get(i), cand.get(j));
					for(int k = j - 2; k > i; k -= 2){
						Line2D l;
						if(k % 2 == 0){
							l = new Line2D.Double(cand.get(k-1), cand.get(k));
						}
						else{
							l = new Line2D.Double(cand.get(k), cand.get(k + 1));
						}
						if(! m.intersectsLine(l)){
							isOK = false;
							break;
						}
					}
					if(isOK){
						dp[i][j] = cand.get(i).distance(cand.get(j));
						dp[j][i] = cand.get(i).distance(cand.get(j));
					}
				}
			}
			
			for(int j = 0; j < len; j++){
				for(int i = 0; i < len; i++){
					for(int k = 0; k < len; k++){
						dp[i][k] = Math.min(dp[i][k], dp[i][j] + dp[j][k]);
					}
				}
			}
			System.out.printf("%.6f\n",dp[0][len-1]);
		}
	}
	
	public class Circle{
		Point2D p;
		double r;
		public Circle(Point2D p, double r) {
			this.p = p; this.r = r;
		}
	}
	
	//円と円の交点
	Point2D [] intersectPtCC(Circle a,Circle b) {
		double dis = a.p.distance(b.p);
		Point2D v = sub(b.p, a.p);
		double rc = (dis * dis + a.r * a.r - b.r * b.r) / (2 * dis);
		double rate = rc / dis;
		v = mul(v, rate);
		Point2D c = add(v, a.p);
		double disC2c = c.distance(b.p);
		double disqc = Math.sqrt(b.r * b.r - disC2c * disC2c);
		Point2D v2 = sub(b.p, c);
		v2 = mul(v2, disqc / disC2c);
		Point2D [] res = new Point2D[2];
		res[0] = add(normalV1(v2), c);
		res[1] = add(normalV2(v2), c);
		return res;
	}
	
	private Point2D normalV1(Point2D p) {
		return new Point2D.Double(-p.getY(), p.getX());
	}
	
	private Point2D normalV2(Point2D p) {
		return new Point2D.Double(p.getY(), -p.getX());
	}

	private Point2D add(Point2D p1, Point2D p2) {
		double x = p1.getX() + p2.getX();
		double y = p1.getY() + p2.getY();
		return new Point2D.Double(x,y);
	}

	private Point2D mul(Point2D v, double rate) {
		return new Point2D.Double(v.getX() * rate, v.getY() * rate);
	}

	private Point2D sub(Point2D p1, Point2D p2) {
		double x = p1.getX() - p2.getX();
		double y = p1.getY() - p2.getY();
		return new Point2D.Double(x,y);
	}
	
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 17000
N,M = map(int,input().split(' '))
X = list(map(int,input().split(' ')))

if M <= N:
	print(0)
	exit()

X.sort()

l = []
for i in range(M-1):
	l.append(X[i+1]-X[i])

l.sort()
l=l[:M-N]
print(sum(l))


Measured memory_bytes: 13960
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    char c,ans;
    cin >> c;
    ans = c+1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
S = input()
T = set(S)
if (len(T) == 4):
  print('Yes')
elif (len(T) == 1 or len(T) == 3):
  print('No')
else:
  if ('N' in T):
    if ('S' in T):
      print('Yes')
    else:
      print('No')
  elif ('S' in T):
    if ('N' in T):
      print('Yes')
    else:
      print('No')
  elif ('W' in T):
    if ('E' in T):
      print('Yes')
    else:
      print('No')
  else:
    if ('W' in T):
      print('Yes')
    else:
      print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)


int main() {

    const ll MOD = 1e9 + 7;
    ll H, W, K;
    cin >> H >> W >> K;
    vector<vector<ll>> v(H+1, vector<ll>(W, 0));
    v[0][0] = 1;

    vector<vector<ll>> a(W, vector<ll>(W, 0));
    vector<ll> tmp(W);
    bool is_suit;
    REP(i, 1<<(W-1)){
        is_suit = true;
        REP(j, W-1) tmp[j] = (i>>j) & 1;
        REP(j, W-2) if (tmp[j] == 1 && tmp[j+1] == 1) is_suit = false;
        if (!is_suit) continue;
        REP(j, W){
            if (j != W-1 && tmp[j] == 1) a[j][j+1]++;
            else if (j != 0 && tmp[j-1] == 1) a[j][j-1]++;
            else a[j][j]++;
        }
    }

    /*
    REP(i, W) {
        REP(j, W) cout << a[i][j];
        cout << endl;
    }
    
*/
   REP(i, H)REP(j, W){
       v[i+1][j] = (v[i+1][j] + (v[i][j] * a[j][j]) % MOD) % MOD;
       if (j != W-1) v[i+1][j+1] = (v[i+1][j+1] + (v[i][j] * a[j][j+1] % MOD)) % MOD;
       if (j != 0) v[i+1][j-1] = (v[i+1][j-1] + (v[i][j] * a[j][j-1] % MOD)) % MOD;
   }
   /*
    REP(i, H+1) {
        REP(j, W) cout << v[i][j];
        cout << endl;
    }
*/
   cout << v[H][K-1] << endl;

    return 0;
}

Measured memory_bytes: 256
fun main() {
    val n = readInt()

    var ans = 0L
    for (i in 1..n) {
        if (i % 3 != 0 && i % 5 != 0) ans += i
    }
    println(ans)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

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

int main() {
  int A, B,C,X;
  int ans = 0;
  cin >> A >> B >> C >> X;
  
  for(int i=0; i<A + 1; i++){
    for(int j=0; j<B+1; j++){
      for(int k=0; k<C+1; k++){
        if(500*i + 100*j + 50*k == X) ans++;
      }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int a,b;
  cin >> a >> b;
  if (a <= 8 && b <= 8) {
    cout << "Yay!" << "\n";
  } else {
    cout << ":(" << "\n";
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
static int count=0;
int isPrime(int x){
  int q;
  int i=3;
  if(x==2){
    count+=1;
    //return count;                                                             
  }
  if(x<2 || x%2==0)return 0;
  //  else {                                                                    
  q=sqrt(x);
  while(i<=q){
    if(x%i==0)return 0;
    i=i+2;
  }
    count+=1;
  return count;
}

int main(){
  int n,A,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A);
    isPrime(A);
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;

int main(){
	LL l, r, mid, prev, base; string res;
	for(prev = 0, base = 100000000000000000LL; ; base /= 10){
		l = (prev ? 0 : 1), r = 9;
		while(l < r){
			mid = (l + r) >> 1;
			cout << "? " << (prev * 10 + mid + 1) * base - 1 << endl << flush;
			cin >> res;
			if(res[0] == 'Y') r = mid;
			else l = mid + 1;
		} prev = prev * 10 + r;
		cout << "? " << prev * base << endl << flush;
		cin >> res;
		if(res[0] == 'Y'){
			if(prev == 1){
				for(base = 1; true; base *= 10){
					cout << "? " << base + 1 << endl << flush;
					cin >> res;
					if(res[0] == 'Y'){
						cout << "! " << base << endl << flush;
						return 0;
					}
				}
			}
			for(base = 1; true; base *= 10){
				cout << "? " << (prev - 1) * base << endl << flush;
				cin >> res;
				if(res[0] == 'N') break;
			} cout << "! " << prev * base / 10 << endl << flush;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 648
//-----------------------
// author : xyqkoala
// time : 2020-07-12
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

int pop_cnt(int x){
	int res = 0;
	while(x){
		if(x&1) res++;
		x=x/2;
	}
	return res;
}

int dfs(int x,vector<int> &dp){
	if(dp[x]!=-1) return dp[x];
	dp[x] = 1+dfs(x%pop_cnt(x),dp);
	return dp[x];
}


LL qp(LL m,int n,int mod){
	LL res = 1;
	while(n){
		if(n&1){
			res = (res*m)%mod;
		}
		m = (m*m)%mod;
		n>>=1;
	}
	return res%mod;
}

void solve(){
	int n;
	cin>>n;
	string str;
	cin>>str;
	int cnt = 0;
	for(auto &item:str){cnt+=item-'0';}
	// cout<<cnt<<endl;
	vector<int> table={-1,1};
	vector<int> dp(n+1,-1);
	dp[0] = 0;
	vector<int> rem(2,0);
	for(int i=0;i<2;i++){
		int mod = table[i]+cnt;
		if((mod)>n) continue;
		if((mod)<=0) continue;
		for(int j=(n-1);j>=0;j--){
			if(str[j]=='1') rem[i]=(rem[i]+qp(2,n-1-j,mod))%mod;
		}
	}
	vector<int> res(n,0);
	for(int i=0;i<n;i++){
		int temp = rem['1'-str[i]];
		int mod = cnt;
		if(str[i]=='1') mod--;
		else mod++;
		if(mod<=0) continue;
		int sign = 1;
		if(str[i]=='1') sign= -1;
		temp+= sign*qp(2,n-i-1,mod);
		temp = (temp+mod)%mod;
		res[i]=  1+dfs(temp,dp);
	}
	for(int i=0;i<n;i++){
		cout<<res[i]<<endl;
	}
}


Measured memory_bytes: 5108