akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long 


int main(){
    int N,M;
    int a[52],b[52];
    int bu[52]={};
    cin >> N >> M;
    REP(i,M){
        cin >> a[i] >> b[i];
        bu[a[i]-1]++;bu[b[i]-1]++;
    }
    REP(i,N){
        cout << bu[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

A,B = LI()
if abs(A-B) % 2 == 0:
    print(abs(A-B)//2 + min(A,B))
else:
    print("IMPOSSIBLE")


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

int main(){

	int n, len, cnt, set;
	char sb[7][5];
	string str;
	
	set = 0;	

	while(cin >> str){
		set++;
		if(set != 1) cout << endl;
		cnt = 0;
		len = str.length();
		for(int i=0; i<5; i++){
			if(len+i >= 5){
				n = str[cnt] - '0';
				cnt++;
			}
			else n = 0;
			if(n >= 5){
				sb[0][i] = ' ';
				sb[1][i] = '*';
			}
			else {
				sb[0][i] = '*';
				sb[1][i] = ' ';
			}
			for(int j=2; j<7; j++){
				sb[j][i] = '*';
			}
			sb[n%5+2][i] = ' ';
		}
		
		for(int i=0; i<7; i++){
			for(int j=0; j<5; j++){
				cout << sb[i][j];
			}
			cout << endl;
			if(i == 1) cout << "=====" << endl;
		}
	}

	return 0;

}

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

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if (e-a<=k){
    cout << "Yay!" << endl;
  }
  else cout << ":(" << endl;
}


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

using ll = long long;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

int main() {
  int n, l[100];
  cin >> n;
  repi(n) cin >> l[i];
  auto mp = maxptr(l, l + n);
  int sum = 0;
  repi(n) if (l + i != mp) sum += l[i];
  cout << (*mp < sum ? "Yes" : "No") << endl;
}


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


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

    int max = 0;

    rep(i, 1, s.length() + 1) {
        rep(j, s.length() + 1 - i) {
            bool f = true;
            rep(k, j, j + i) {
                if (string("ACGT").find(s[k]) == string::npos) {
                    f = false;
                    break;
                }
            }
            if (f) {
                max = i;
                break;
            }
        }
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> A;
    for (int i = 0; i < N; ++i) {
        int t; cin >> t;
        A.push_back(t);
    }

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

    ll ans = 1;
    int cnt = 0;
    for (int i = N-1; i > 0; --i) {
        if(A[i-1] == A[i]){
            ans *= A[i];
            cnt++;
            i--;
        }
        if (cnt == 2){
            cout << ans << "\n";
            return 0;
        }
    }


    cout << 0 << "\n";

    return 0;
}



Measured memory_bytes: 892
!!! reference : submission #12221385
program main
    implicit none
    integer n, m, a(10005), t, i
    t = 0
    read(*, *) n, m
    read(*, *) (a(i), i = 1, m)
    do i = 1, m
        t = t + a(i)
    enddo
    if (n >= t) then
        print *, n - t
    else
        print *, -1
    end if
end program main

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

int main(){
	int a;
	int b;
	cin >> a ;
	cin >> b ;
	if (a != b){
		if (a < b){
			cout << "a < b" << endl;
		}
		else {
			cout << "a > b" << endl;
		}
	}
	else {
		cout << "a == b" << endl;
	}
	return 0;
}



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

int main() {
    int A, B, X;
    cin >> A >> B >> X;
    
    if (X - A <= B && X - A >= 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)

N=l()[0]
F=10**10

for i in range(1,int(N**0.5)+2):
    if N%i==0:
        F=min(F,max(len(str(i)),len(str(N//i))))
print(F)


Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n;
	sd(n);
	int a[n][3];
	fi(0,n,1){
		sd(a[i][0]);sd(a[i][1]);sd(a[i][2]);
	}
	ll dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	fi(1,n,1){
		dp[i][0]=max(dp[i-1][1], dp[i-1][2])+a[i][0];
		dp[i][1]=max(dp[i-1][0], dp[i-1][2])+a[i][1];
		dp[i][2]=max(dp[i-1][0], dp[i-1][1])+a[i][2];
	}
	plld(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]));
	
}

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


int main(){
  int A,B,C,D,P;
  int ansX, ansY;

  cin >> A >> B >> C >> D >> P;

  ansX = P * A;

  if(P <= C){
    ansY = B;
  }else{
    ansY = B;
    ansY += (P - C) * D;
  }

  if(ansX > ansY){
    cout << ansY << endl;
  }else{
    cout << ansX << endl;
  }
  return 0;
}



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

const int N = 1e6 + 100;

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++) {
        cin >> A[i];
        A[i]--;
    }
    vector<int> res;
    for(int i = n-1; i >= 0; i--) {
        int idx = -1;
        for(int k = 0; k < A.size(); k++) {
            if(A[k] == k) {
                idx = k;
            }
        }
        if(idx == -1) {
            cout << -1 << endl;
            return 0;
        }
        res.push_back(idx+1);
        A.erase(A.begin()+idx);
    }
    reverse(res.begin(), res.end());
    for(int x : res) cout << x << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

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

    cout << ( ( A >= 9 || B >= 9 ) ? ":(" : "Yay!" ) << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        string S = ReadLine();
        int K = int.Parse(ReadLine());

        int N = S.Length;
        var dp = new long[N + 1, K + 1, 2];
        dp[0, 0, 0] = 1;

        for (int i = 0; i < N; i++)
        {
            int n = S[i] - '0';
            for (int j = 0; j < K+1; j++)
            {
                for (int k = 0; k < 2; k++)
                {
                    var v = dp[i, j, k];
                    for (int l = 0; l < 10; l++)
                    {
                        int nk = k;
                        if (k == 0)
                        {
                            if (l < n) nk = 1;
                            else if (l == n) nk = 0;
                            else break;
                        }
                        int nj = j;
                        if (l > 0) nj++;
                        if (nj > K) break;
                        dp[i + 1, nj, nk] += v;
                    }
                }
            }
        }
        long ans = 0;

            ans += dp[N, K, 0] + dp[N, K, 1];
        
        WriteLine(ans);
    }
}


Measured memory_bytes: 27464
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define EPS (1e-10)
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<int>a(n); rep(i, n)cin >> a[i];
	int ans = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] > a[j]) {
				ans += k * (k + 1) / 2;
				ans %= MOD;
			}
			else if(a[i]<a[j]){
				ans += k * (k - 1) / 2; ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	
	
	return 0;
}

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

int main(){
    int H, W;
    cin >> H >> W;
    while(H != 0 && W != 0){
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
}


Measured memory_bytes: 3088
n = int(input())

if n < 10:
  print(n)
elif n < 100:
  print(9)
elif n < 1000:
  print(9+(n-99))
elif n < 10000:
  print(9+900)
elif n < 100000:
  print(9+900+(n-9999))
else:
  print(90909)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	sort(l.begin(), l.end());
	ll ans = 0;
	for(int i = 0; i < n-2; ++i){
		for(int j = i+1; j < n-1; ++j){
			int a = l[i];
			int b = l[j];
			auto c = lower_bound(l.begin(), l.end(), a+b);
			c--;
			int cnt = (c - l.begin()) - j;
			ans += cnt;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(void){
  int n, x, last;
  
  cin >> n >> last;
  cout << last;
  for (int i=1; i<n; i++){
    cin >> x;
    if (x==last) continue;
    cout << " " << x;
    last = x;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int i;
  for(i=0;i<str.size();i++){
    if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
    else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
  }
    cout << str << endl;
  return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#include <math.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;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int H;
  int W;
  cin >>H>>W;
  
  vector<vector<char>> data(H,vector<char>(W));
  
  rep(i,H) {
    rep(j,W) {
      cin >>data.at(i).at(j);
    }
  }
  
  const int dx[8]={0,1,1,1,0,-1,-1,-1};
  const int dy[8]={1,1,0,-1,-1,-1,0,1};
  
  rep(i,H) {
rep(j,W) {
  if(data.at(i).at(j)=='#') {
    continue;
  }
int num=0;
  rep(d,8) {
  const int ni=i+dx[d];
  const int nj=j+dy[d];
  if((ni<0) ||( ni>=H) )   {
    continue;
  }
  
  if((nj<0) ||( nj>=W) )   {
    continue;
  }
  else if((data.at(ni).at(nj)=='#') &&(ni>=0) &&(ni<H) &&(nj>=0) &&(nj<=W)) {
    num++;
  }
  }
  data.at(i).at(j)=char(num+'0');
}
  }
    

  
  
  
  
  
  
  
  
  
  
  
  
  //出力
  rep(i,H) {
    rep(j,W) {
      cout<<data.at(i).at(j);
    }
    cout<< endl;
  }
}
 






Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int N,M,a;
  scanf("%d%d",&N,&M); 
  int cnt[N];
  for(int i = 0;i < N;i++) cnt[i] = 0;
  for(int i = 0;i < 2*M;i++){
    scanf("%d",&a);
    cnt[a-1]++;
  } 
  for(int i = 0;i < N;i++) printf("%d\n",cnt[i]); 
  return 0;
}

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

using namespace std;
const int N=3e5+5;
int a[N],b[N];
int n,k;
int ans=1;
void solve(int v)
{
    long long s = 0;
    for(int i=0;i<n;i++){
        b[i]=a[i]%v;
        s += b[i];
    }

    sort(b,b+n);
    long long now = 0;
    for(int i=n-1; i>=0; i--){
        if(s>now){
            now += v-b[i];
            s -= b[i];
        }
    }
    assert(now == s);

    if(s<=k)
        ans=max(ans,v);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(long long i=1;i*i<=sum;i++)
    {
        if(sum%i==0)
        {
            solve(i);
            solve(sum/i);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long ans;
int main(){
  long long n,m; cin >> n >> m;
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  vector<long long> a(m);
  vector<long long> sub(m-1);
  for(long long i=0;i<m;++i) cin >> a[i];
  sort(a.begin(), a.end());
  for(long long i=0;i<m-1;++i) sub[i] = a[i+1] - a[i];
  sort(sub.begin(), sub.end());
  for(long long i=0;i<m-n;i++) ans += sub[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
import           Control.Monad
import qualified Data.Sequence as Seq

main = do
  s <- Seq.fromList <$> getLine

  let solve s res | Seq.length s < 2 = res
                  | otherwise =
                    let l Seq.:< ss = Seq.viewl s
                        ss' Seq.:> r = Seq.viewr ss
                    in
                      if l == r
                      then solve ss' res
                      else case (l, r) of
                        ('x', _) -> solve (s Seq.|> 'x') (res+1)
                        (_, 'x') -> solve ('x' Seq.<| s) (res+1)
                        _        -> (-1)

  print $ solve s 0

Measured memory_bytes: 8188
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nl = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var apples = Enumerable.Range(nl[1], nl[0]).ToArray();
            var minIndex = 0;
            for (var i = 0; i < apples.Length; i++)
            {
                if (Math.Abs(apples[minIndex]) > Math.Abs(apples[i])) minIndex = i;
            }
            apples[minIndex] = 0;
            Console.WriteLine(apples.Sum());
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  ll N,D,ans=0; cin>>N>>D;
  D *= D;
  rep(i,N){
    ll x,y; cin>>x>>y;
    x *= x;
    y *= y;
    if (D >= x + y)
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif



int main() {
    ll N, K;
    cin >> N >> K;
    V<ll> A(N);
    for(auto &&ele : A) cin >> ele;
    ll cur_sum = 0;
    ll ans = 0;
    map<ll, ll> cnt;
    cnt[0]++;
    V<ll> history(N + 1);
    for(ll i = 0; i < N; i++) {
        cur_sum += A[i];
        cur_sum %= K;
        ll len = i + 1;
        if(K <= len) cnt[history[len - K]]--;
        for(ll j = 0; j <= 1; j++) {
            ll over = (cur_sum - len) % K;
            over += j * K;
            ll want = -over;
            ans += cnt[want];
        }
        ll key = (cur_sum - len) % K;
        key *= -1;
        cnt[key]++;
        history[i + 1] = key;
    }

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


Measured memory_bytes: 28416
n=int(input(""))
s=0
t=0
for i in range(n):
    d=input("").split(" ")
    if(int(d[0])==int(d[1])):
        s+=1
        if(s==3):
            t=1
            
    else:
        s=0
if(t==1):
    print("Yes")
else:
    print("No")
    
    

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
typedef long long lint;
typedef vector<int> vi;

const int mod = 1e9 + 7;

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

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

// ?????????????????????????????????????????????
lint extgcd(lint a, lint b, lint& x, lint& y) {
	lint d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}

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

// n????´???° ???????????????unsorted
vi divisor(lint n) {
	vi res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.pb(i);
			if (n / i != i) res.pb(n / i);
		}
	}

	return res;
}

// 2 * 2 * 3 * 5 * 5 * 5 = {2:2, 3:1,5:3} ???????????? map ????????£????????????
map<int, int> prime_factor(lint n) {
	map<int, int> res;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			++res[i];
			n /= i;
		}
	}

	if (n != 1) res[n] = 1;
	return res;
}

const int MAX_N = 202020;
int prime[MAX_N];
bool memo[MAX_N + 1];

// ?´???°?????¨?????? n??\???????´???°????????°?????????
int sieve(int n) {
	int p = 0;
	memset(memo, true, sizeof(memo));
	memo[0] = memo[1] = false;

	for (int i = 2; i <= n; ++i) {
		if (memo[i]) {
			prime[p++] = i;
			for (int j = i * 2; j <= n; j += i) {
				memo[j] = false;
			}
		}
	}

	return p;
}

const lint MAX_LEN = 1000000;
const lint MAX_SQRT_B = 1000000;
bool memo_all[MAX_LEN];         //i means i + a
bool memo_small[MAX_SQRT_B];

// [a, b)????´???°????????°???????????????
lint count_prime(lint a, lint b) {
	for (int i = 0; (lint)i * i < b; i++) memo_small[i] = true;
	for (int i = 0; i < b - a; i++)     memo_all[i] = true;

	for (int i = 2; (lint)i * i < b; i++) {
		if (memo_small[i]) {
			for (int j = 2; (lint)j * j < b; j += i) memo_small[j] = false;
			for (lint j = max(2LL, (a + i - 1) / i) * i; j < b; j += i) memo_all[j - a] = false;
		}
	}

	lint ret = 0;
	for (lint i = a; i < b; i++) {
		if (memo_all[i]) ret++;
	}
	return ret;
}

// k???????????§????????£??????????????°??????{a_0 : 0, a_1 : 1, a_2 : 1, ... }
lint Fib[101010];
int calcFib(int k) {
	Fib[0] = 0;
	Fib[1] = Fib[2] = 1;
	for (int i = 3; i <= k; ++i) {
		Fib[i] = Fib[i - 1] + Fib[i - 2];
		// Fib[i] %= mod;
	}

	return Fib[k];
}

int main() {
	lint a, b;

	cin >> a >> b;

	lint x, y;
	extgcd(a, b, x, y);
	cout << x << " " << y << endl;
}

Measured memory_bytes: 3104
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	HashMap<String, Integer> h = new HashMap<String, Integer>();



	void run(){

		for(;sc.hasNext();){

			String k = sc.next();

			if(h.containsKey(k)){

				h.put(k,h.get(k)+1);

			}else{

				h.put(k, 1);

			}

		}

		int maxch = 0;

		String maxlen = "";

		int maxcount = 0;

		String freq = "";

		for(String k :h.keySet()){

			if(k.length() > maxch){

				maxch = k.length();

				maxlen = k;

			}

			if(h.get(k) > maxcount){

				maxcount = h.get(k);

				freq = k;

			}

		}

		System.out.println(freq + " " + maxlen);

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

		

	}

}

Measured memory_bytes: 12000
from collections import Counter
N = int(input())
now_time = [0, 24]
D = list(map(int, input().split()))
c = Counter(D)
candidate = []
if N == 1:
    print(min(D[0], 24-D[0]))
    exit()

for num, amount in c.items():
    if num == 0:
        print(0)
        exit()
    if amount > 2:
        print(0)
        exit()
    if amount == 2:
        # 確定した時間
        now_time.append(num)
        now_time.append(24-num)
    if amount == 1:
        candidate.append((num, 24-num))  # 選択の余地がある時間
ans = 0
# 確定した時間に選択の余地がある組を追加していく
for mask in range(1 << len(candidate)):
    list_0_1 = []
    time_list = now_time.copy()  # 確定している時間
    for i in range(len(candidate)):
        list_0_1.append(int((mask >> i) & 1))
    # print(list_0_1)
    for i, num in enumerate(list_0_1):
        time_list.append(candidate[i][num])
    # exit()
    tmp = 100
    for i in range(len(time_list)):
        for j in range(i+1, len(time_list)):
            tmp = min(tmp, abs(time_list[i] - time_list[j]))
    ans = max(tmp, ans)


print(ans)


Measured memory_bytes: 3444
n = int(input())
D = list(map(int, input().split()))
D.sort()

# 二分割した左側
mid_left = len(D)//2 -1

if D[mid_left] == D[mid_left+1]:
    print(0)
else:
    print(D[mid_left+1] - D[mid_left])


Measured memory_bytes: 14008
#include <bits/stdc++.h>
// #include <math.h>
// #include <cmath>
// #include <vector>
// #include <utility> 
// #include <unordered_map>
// #include <map>
// #include <string>

using namespace std;
typedef long long int lli;

#define M_PI_H  3.14159265358979323846/2  /* pi by two*/
#define rep(i, start, end) for(int i = start; i < end; i++) 
#define repr(i, start, end) for(int i = start; i >= end; i--)   //INCLUSIVE



int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	
	int n, k;
	cin>>n>>k;
	int a[n];

	rep(i, 0, n){
		cin>>a[i];
	}

	sort(a, a+n);

	int sum=0;
	rep(i, 0, k){
		sum += a[i];
	}

	cout<<sum;
	
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){
  double pi = 6.28318530717958623200;
  ll R;
  cin >> R;

  cout << setprecision(15) << R * pi << endl;

  return 0;
}


Measured memory_bytes: 3784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int shojikin = scanner.nextInt();
		int cake_val = scanner.nextInt();
		int dounut_val = scanner.nextInt();
		int dounut_kosuu;
		shojikin -= cake_val;
		dounut_kosuu =shojikin / dounut_val;
		shojikin -= dounut_val * dounut_kosuu;
		System.out.println(shojikin);
	}
}

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

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

	int m, f, r;
	cin >> m >> f >> r;
	while (m != -1 || f != -1 || r != -1){
		if (m == -1 || f == -1)
			cout << "F\n";
		else if (m + f >= 80)
			cout << "A\n";
		else if (m + f >= 65)
			cout << "B\n";
		else if (m + f >= 50)
			cout << "C\n";
		else if (m + f >= 30){
			if (r >= 50)
				cout << "C\n";
			else
				cout << "D\n";
		}
		else
			cout << "F\n";
		cin >> m >> f >> r;
	}

	return 0;
}


Measured memory_bytes: 3180
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 110
using namespace std;
int n,a[3][maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	for(int i=2;i<=n;i++)a[1][i]+=a[1][i-1];
	a[2][1]+=a[1][1];
	for(int i=2;i<=n;i++){
		a[2][i]+=max(a[1][i],a[2][i-1]);
	}
	printf("%d",a[2][n]);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    
    //マスの数
    int n = sc.nextInt();
    int ans = 0;
    for(int i = 1; i <= n;i++){
      //マスの数字
      int a = sc.nextInt();
      if(i % 2 == 1 && a % 2 == 1){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35728
#include <iostream>
using namespace std;
int main(void){
    int n, a, b, c, d, x=0, y=0;
    bool f=true;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    for(int i=a;i<c;i++){
        if(s[i]=='#' && s[i-1]=='#')f=false;
    }
    for(int i=b;i<d;i++){
        if(s[i]=='#' && s[i-1]=='#')f=false;
    }
    if(!f){
        cout << "No" << endl;
        return 0;
    }else if(c<d){
        cout << "Yes" << endl;
        return 0;
    }
    for(int i=b-2;i<d+1;i++){
        if(s[i]=='.'){
            y=max(y, ++x);
        }else{
            x=0;
        }
    }
    if(y>=3){
        cout << "Yes" << endl;
        return 0;
    }else{
        cout << "No" << endl;
        return 0;
    }
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		String num = Long.toString(N);
		long t = 0;
		for(int i = 0; i < num.length(); i++) {
			t += Long.parseLong(num.substring(i, i + 1));
		}
		if(N % t == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

using namespace std;

int N, M, Q;
int dp[15][100005];
int color[100005];
vector<int> G[100005];

int main(void)
{
	cin >> N >> M;
	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	cin >> Q;
	int v, d, c;
	for(int q = 1; q <= Q; q++){
		cin >> v >> d >> c;
		dp[d][v] = q;
		color[q] = c;
	}
	
	for(int i = 10; i > 0; i--){
		for(int j = 1; j <= N; j++){
			if(dp[i][j] == 0) continue;
			dp[i-1][j] = max(dp[i-1][j], dp[i][j]);
			for(int k = 0; k < G[j].size(); k++){
				dp[i-1][G[j][k]] = max(dp[i-1][G[j][k]], dp[i][j]);
			}
		}
	}
	
	for(int i = 1; i <= N; i++){
		cout << color[dp[0][i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 12280
import sys
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
K = []
for i in range(N):
    for j in range(a[i]):
        K.append(i+1)
maze = [[0] * W for _ in range(H)]

def dfs(x, y, p, i):
    if y < 0 or y >= H:
        return
    if 0 <= x < W:
        maze[y][x] = K[i]

    if x < 0:
        p = 0
        dfs(x+1, y+1, p, i)
        return
    elif x >= W:
        p = 1
        dfs(x-1, y+1, p, i)
        return

    if p == 0:
        dfs(x+1, y, p, i+1)
    else:
        dfs(x-1, y, p, i+1)

    return

dfs(0, 0, 0, 0)

for i in range(H):
    print(*maze[i])


Measured memory_bytes: 12148
//////////////////////////
/*      _        ____   */
/*  U  /"\  u U /"___|  */
/*   \/ _ \/  \| | u    */
/*   / ___ \   | |/__   */
/*  /_/   \_\   \____|  */
/*   \\    >>  _// \\   */
/*  (__)  (__)(__)(__)  */
/*  Compro by NULL_CT©  */
//////////////////////////
/*STL Libs*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

/*Boost to boost compile time*/
#include <boost/multiprecision/cpp_int.hpp>

#define REP(I, LIM) for (long I = 0; I < LIM; I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using bint = boost::multiprecision::cpp_int;

static constexpr int MOD = 10000007;
static constexpr long INF = LONG_MAX;

vector<long> divisor(long n) {
  vector<long> head, tail;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

//--------------------------------

void execute() {
  int n,d;
  cin>>n>>d;
  
  int count=0;
  REP(i,n){
    long x,y;
    cin>>x>>y;
    if(d >= sqrt(x*x+y*y)){
      count++;
    }
  }
  cout<<count<<endl;
}

//--------------------------------

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // cout<<fixed<<setprecision(20);

  execute();

  return (0);
}


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

int main(){
ll a,b,c;
 cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0){
    cout<<'0'<<endl;
  }
 else{
  ll ans;
  ans=min(min(a*b,b*c),(c*a));
  cout<<ans<<endl;
 }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	nokori := c - (a - b)
	if nokori < 0 {
		fmt.Printf("%d\n", 0)
	} else {
		fmt.Printf("%d\n", nokori)
	}
}


Measured memory_bytes: 512
use proconio::input;
use proconio::marker::Usize1;
use std::collections::VecDeque;
use std::cmp::max;

struct Node {
    to: Vec<usize>,
    from: Vec<usize>,
    count: usize,
    dist: u32,
}

impl Node {
    fn new() -> Self {
        Node {
            to: Vec::new(),
            from: Vec::new(),
            count: 0,
            dist: 0,
        }
    }
}

fn main()
{
    input! {
    n:usize,
    m:usize,
    edge:[(Usize1,Usize1);m],
    }

    let mut v = (0..n).map(|_| Node::new()).collect::<Vec<Node>>();
    for &(a, b) in edge.iter() {
        v[a].to.push(b);
        v[b].from.push(a);
    }

    let mut q = VecDeque::new();
    for i in 0..n {
        if v[i].to.len() == 0 {
            q.push_back(i);
        }
    }

    while let Some(idx) = q.pop_front() {
        let dist = v[idx].dist + 1;
        for i in 0..v[idx].from.len() {
            let nxt = v[idx].from[i];
            v[nxt].dist = max(v[nxt].dist, dist);
            v[nxt].count += 1;

            if v[nxt].count == v[nxt].to.len() {
                q.push_back(nxt);
            }
        }
    }

    let ans = v.into_iter().map(|e| e.dist).max().unwrap();
    println!("{}", ans);
}

Measured memory_bytes: 17264
#include<stdio.h>
int main(void)
{
	int t,n,s,f,i,z;
	scanf("%d",&t);
	while(t!=0){
	z=0;
	scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			z+=f-s;
		}
			if(z>=t){
				printf("OK\n");
			}
			else{
				printf("%d\n",t-z);
			}
		scanf("%d",&t);
	}
	return 0;
}

Measured memory_bytes: 1040
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

ll max_i(vll v,ll not_this_iter){
    ll max_iter = -1;
    ll max_val = LLONG_MIN;
    rep(i,(ll)v.size()){
        if(i == not_this_iter) continue;
        if(v[i] > max_val){
            max_val = v[i];
            max_iter = i;
        }
    }

    return max_iter;
}


int main(void){
    FAST_IO
    ll n;
    cin >> n;

    vll v(n);
    rep(i,n) cin >> v[i];
    
    vll cnt0(100001);
    vll cnt1(100001);
    
    rep(i,n){
        if(i % 2 == 0){
            cnt0[v[i]]++;
        } else {
            cnt1[v[i]]++;
        }
    }

    ll iter0 = max_i(cnt0,-1);
    ll iter1 = max_i(cnt1,-1);
    if(iter0 != iter1){
        cout << n - cnt0[iter0] - cnt1[iter1] << endl;
    } else if(cnt0[iter0] > cnt1[iter1]){
        cout << n - cnt0[iter0] - cnt1[max_i(cnt1,iter1)] << endl;
    } else if(cnt0[iter0] < cnt1[iter1]){
        cout << n - cnt0[max_i(cnt0,iter0)] - cnt1[iter1] << endl;
    } else {
        ll i0 = max_i(cnt0,iter0);
        ll i1 = max_i(cnt1,iter1);
        cout << n - cnt0[iter0] - max(cnt0[i0],cnt1[i1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 5984
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(C+1)] for j in range(4)] for k in range(R+1)]
 
for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v
 
for i in range(R):
    for j in range(4):
        for k in range(C):
            DP[i+1][j][k+1] = max(DP[i][3][k+1], DP[i+1][j][k])
            if j == 0:
                continue
            v = MAP[i][k]
            if v == 0:
                continue
            DP[i+1][j][k+1] = max(DP[i+1][j][k+1], max(DP[i][3][k+1], DP[i+1][j-1][k]) + v)

print(DP[R][3][C])


Measured memory_bytes: 468956
import bisect


def bisect_search(f, val=0, l=0, r=10**6):

    #is_increase=(f(r)-f(l))>=0

    eps = 10**(-5)
    while True:

        c = (l+r)//2
        print(l, c, r)
        input()
        if f(c) == val and f(c-1) != val:
            return c
        #if f(c)-val < eps:
        #    return c

        if f(c) > val:
            r = c

        else:
            l = c

        if l == r:
            return False



def next(ch,k):
    global N,dcs
    k_=k%N
    #print(ch,ch_,k)
    #print(dcs[ch][ch_]+1)
    #print(dcs[ch])
    #print(dcs[ch][ch_]+1)
    #print(N)
    val = dcs[ch][k_-1]+1
    if k_==0:
        val=1

    A=bisect.bisect_left(dcs[ch],val,k_,min(k_+N,2*N-1))
    B = N*((k//N))
    #print(A,B,k//N,k,N)

    return A+B#+A//N


import numpy as np

s=input()
t=input()

td=list(set(t))

N=len(s)
d={}

import sys

R = set(list(s))
L = set(list(t))

if not(L <= R):
    print(-1)
    sys.exit()

for std in td:
    d[std] =[0]*(2*N)



for i in range(len(s)*2):
    #nd[s[i]]

    for std in td:            
        if s[i%N]==std:
            d[std][i]=1



dcs={}
for std in td:
    dcs[std]=np.cumsum(d[std])


last=-1
for ts in t:
    #print(last)
    last=next(ts,last+1)


print(last+1)


#print(dcs)


Measured memory_bytes: 97424
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> L(M);
  std::vector<int> R(M);
  for(int i=0;i<M;i++) std::cin >> L[i] >> R[i];
  int lnum=-1, rnum=N+1;
  for(int i=0;i<M;i++){
    lnum=max(lnum, L[i]);
    rnum=min(rnum, R[i]);
  }
  if(rnum < lnum ) std::cout << 0 << '\n';
  else std::cout << rnum - lnum + 1 << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, q, com, x, y;

struct range_minimum_query {
	// 管理したい元の配列のサイズ以上の2冪。
	int n;
	// セグメント木(完全二分木)を管理する一次元配列。
	vector<int> segtree;
	// minの単位元としてのINF。値は2^31-1。
	const int INF = INT_MAX;

	// @param sz 管理したい元の配列のサイズ
	// nをsz以上の2冪にし、セグメント木のサイズを2*n-1、値をINFに初期化する。
	range_minimum_query(int sz) {
		for (n = 1; n < sz;) n <<= 1;
		segtree.assign(2 * n - 1, INF);
	}

	int find(int l, int r) {
		return find(l, r, 0, n, 0);
	}
	int find(int l, int r, int a, int b, int k) {
		// [a,b)が[l,r)の外側なら、影響のない単位元INFを返す。
		if (b <= l || r <= a) return INF;

		// [a,b)が[l,r)の内側なら、その頂点は[l,r)内で最も大きい区間minを持つので、それを返す。
		else if (l <= a && b <= r) return segtree[k];

		// どちらでもなければ(解説スライドでの赤線を跨いでいる状態)、もっと細分されたものを確認する必要があるため、子を確認する。
		// 左側の子は[a,(a+b)/2)の区間minを持ち、indexは2*k+1
		// 右側の子は[(a+b)/2,b)の区間minを持ち、indexは2*k+2
		// この２つの[l,r)内の区間minのminを返してやれば良い。
		// 現在見ている頂点が葉に該当する場合は必ず上の２つの条件のどちらかで捕捉されるため考えなくて良い。
		else return min(find(l, r, a, (a + b) / 2, 2 * k + 1), find(l, r, (a + b) / 2, b, 2 * k + 2));
	}

	void update(int i, int x) {
		// 解説スライドの通り、元の配列を持つ最下段の長さをn(2冪)とすると、
		// その上のセグメント木の構造を持つ部分は n/2 + n/4 + n/8 + .. + 1 = n-1(等比級数の公式より)
		// よって、元の配列を最初に更新したいので、元の配列部分のindexに修正するため、n-1を加える。
		i += n - 1;

		// その頂点をxに更新する。
		segtree[i] = x;
		// 更新した最下段の情報の影響する範囲を更新する。
		// 具体的には更新した頂点の祖先全てが対象となる。
		while (i > 0) {
			// 親ノードへと移動
			i = (i - 1) / 2;
			// 自分の子２つを比較し、小さい方を得る。
			segtree[i] = min(segtree[2 * i + 1], segtree[2 * i + 2]);
		}
	}
};

int main() {
	cin >> n >> q;
	range_minimum_query rmq(n);
	rep(i, q) {
		cin >> com >> x >> y;
		if (com == 0) {
			rmq.update(x, y);
		}
		else {
			cout << rmq.find(x, y + 1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
long long a,b;
int main()
{
	scanf("%lld%lld",&a,&b);
	printf("%lld\n",a*(a-1)/2+b*(b-1)/2);
return 0;
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

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

    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
    return 0;
}


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

int main(void){ 
  string s;
  while(getline(cin,s)){
    vector<int> l;
    s+= ",";
    int n = 0 , lon = 0;;
    for(int i = 0 ; i < s.size() ; i ++){
      //cout<<n<<" ";
      if(s[i] ==','){
	l.push_back(n);
	lon += n;
        n = 0;
      }else{
	n = n * 10 + s[i] - '0';
      }
    }
    lon = lon - l[l.size() - 2] - l[l.size()-1];
    double per = l[l.size() - 2] + l[l.size()-1];
    per = l[l.size() - 2 ] / per * lon;
    /*
    cout<<"lon"<<lon<<endl;
    cout<<"per"<<per<<endl;
    //*/
    int nn=0;
    for(int i = 0 ; i < l.size() ; i ++){
      nn += l[i];
      //cout<<nn<<endl;
      if(nn>=per){
	//cout<<"res"<<++i<<endl;
	cout<<++i<<endl;
	break;
      }
    }
    //*/
  }
}

Measured memory_bytes: 1196
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	ar := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	sort.Ints(ar)
	sum := float64(ar[0])
	for i := 1; i < n; i++ {
		sum = (sum + float64(ar[i])) / float64(2)
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
(defun app ()
    (let* ((n (read))
        (a (read))
        (b (read))
        (c (floor (/ n (+ a b))))
        (d (rem n (+ a b)))
        (ans (* a c)))
        (if (>= d a)
        (incf ans a)
        (incf ans d))
        (format t "~D~%" ans)
    )
)
(app)

Measured memory_bytes: 24384