akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
n,m,v,p = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]


def number(res,w):
    ans = 0
    for i in res:
        ans += min(m,i)
    
    #print(ans)
    if ans < w*m: return False
    else: return True
    



def check(c):
    M = a[c]+m
    if a[n-p] > M: return False

    w = v-c-1-(p-1)
    if w <= 0: return True
    
    res = []
    for i in range(c+1, n-p+1):
        res.append(M-a[i])
    
    
    #print(res,"w",w,"m",m,"c",c)
    return number(res,w)


a.sort()

ok = n-p
ng = -1
while ok-ng > 1:
    mid = (ok+ng)//2
    if check(mid):
        ok = mid
    else:
        ng = mid

#print(ng,ok)    
print(n-ng-1)


    
    
    






























Measured memory_bytes: 114456
INF=1000000007;
def RepeatSquaring(N,P,M):
    if (P == 0):
      return 1;
    if (P % 2 == 0):
        t = RepeatSquaring(N, P / 2, M);
        return t * t % M;
    return N * RepeatSquaring(N, P - 1, M);
N=int(input())
A=RepeatSquaring(9,N,INF);
B=RepeatSquaring(8,N,INF);
C=RepeatSquaring(10,N,INF);
print((C+B-A*2)%INF)

Measured memory_bytes: 9188
#include <stdio.h>

int main(void){
	int n;
	scanf("%d",&n);
	int t[n],x[n],y[n];
	//(0,0)からt[0]秒後にx[0],y[0]にたどり着けるかどうか調べる
	int i,temp;
	for(i=0;i<n;i++){
		scanf("%d%d%d",&t[i],&x[i],&y[i]);
	}
	temp = t[0] - x[0] - y[0];
	if(temp%2==0 && temp >=0){
	}else{
		printf("No");
		return 0;
	}
	for(i=1;i<n;i++){
		temp = (t[i]-t[i-1])-(x[i]-x[i-1])-(y[i]-y[i-1]);
		if(temp%2==0 && temp >=0){
		}else{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=b-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	fast_io();
	string s;
	int n,k;
	cin >> n >> k >> s;
	vector<pii> v;
	char prior = 'a';
	int tp = -1;
	cu(i,0,s.length()){
		if(s[i] != prior){
			v.pb({s[i] == '1', 1});
			prior = s[i];
			++tp;
		}
		else{
			++v[tp].S;
		}
	}
	vector<int> rsum(n);
	rsum[0] = v[0].S;
	cu(i,1,v.size()){
		rsum[i] = rsum[i-1] + v[i].S;	
	}
	int ans = 0;
	cu(i,0,v.size()){
		int bot = max(0, i - 2*k + (v[i].F == 0));	
		if(bot == 0){
			ans = max(ans, rsum[i]);	
		}
		else{
			ans = max(ans, rsum[i] - rsum[bot - 1]);	
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1528
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for (int i = (a); i < (b); i++ )

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

	double n;
	double  ans;

	if (a % 2 == 0) {
		n = a / 2;
		ans = n / a;
		cout << ans << endl;
	}

	else {
		n = (a + 1) / 2;
		ans = n / a;
		cout << ans << endl;
	}

	}

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

int main() {
  int p = 2019;
  string s;
  cin >> s;

  int n = s.size();
  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4396
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(input())
T = list(map(int, input().split()))
M = int(input())
sum_  = sum(T)
for _ in range(M):
    P, X = map(int, input().split())
    ans = sum_ - T[P-1] + X
    print(ans)

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

int main(int argc, char *argv[])
{
    long long N;
    cin >> N;

    for(long long h = 1; h <= 3500; ++h)
    {
        for(long long n = 1; n <= 3500; ++n)
        {
            long long top = N*h*n;
            long long bottom = 4 * h * n - N * (n + h);

            if(bottom == 0) continue;

            long long w = top / bottom;
            if(w <= 0) continue;

            if(top % bottom == 0)
            {
                cout << h << ' ' << n << ' ' << w << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int arr[110][110];
int cnt[11000];
int dx[]={1, 0, -1, 0};
int dy[]={0, 1, 0, -1};
bool safe(int h, int w, int a, int b){
    return 1<=a&&a<=h&&1<=b&&b<=w;
}
int main()
{
    int n, h, w;
    scanf("%d %d %d", &h, &w, &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &cnt[i]);
    }
    int dir = 0;
    int x = 1, y = 1;
    int idx = 1;
    int left = h * w;
    int c = 0;
    while(left){
        arr[x][y] = idx; c++; left--;
        if(c == cnt[idx]){c=0;idx++;}
        if(left > 0) {
            if(dir == 0) y++;
            else y--;
            if(y == w + 1){
                y = w; x++; dir = 1;
            }
            else if(y == 0){
                y = 1; x++; dir = 0;
            }
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            printf("%d ", arr[i][j]);

        }
puts("");
    }
}


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

int main() {
  int K;
  cin >> K;
  
  string S;
  cin >> S;
  
  int x;
  x = S.size();
    
  if (x<=K) {
    cout << S << endl;
  }
  
  else if (x>K) {
    for (int i=0; i<x-K; i++) {
      S.pop_back();
    }
    cout << S << "..." << endl;
  }
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
typedef long long ll;

int
main(int argc, char *argv[])
{
  ll q, h, s, d, n;
  scanf("%lld %lld %lld %lld", &q, &h, &s, &d);
  scanf("%lld", &n);

  q *= 4; h *= 2;
  ll min1 = Min(s, Min(h, q));
  ll min2 = Min(d, 2 * min1);
  printf("%lld\n", (n / 2) * min2 + (n % 2) * min1);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++){
    int v = A.at(i);
    int j = i - 1;
    while(j >= 0 && A.at(j) > v){
      A.at(j+1) = A.at(j);
      j--;
    }
    A.at(j+1) = v;
    for(int i = 0; i < N; i++){
      cout << A.at(i);
      if(i != N-1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3112
import sys
readline = sys.stdin.readline

N = int(readline())
ans = []
import bisect
for i in range(N):
  a = -int(readline())
  ind = bisect.bisect_right(ans, a)
  if ind == len(ans):
    ans.append(a)
  else:
    ans[ind] = a
    
print(len(ans))


Measured memory_bytes: 12724
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s1,s2,s3;
  cin>>s1>>s2>>s3;
  int ans=0;
  if(s1=='1') ans++;
  if(s2=='1') ans++;
  if(s3=='1') ans++;
  cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int x, y;
	for (int i = 0; true; i++) {
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		if (x < y)cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
import sys

A1, A2, A3 = map(int, input().split())
A_LIST = [A1, A2, A3]

# Checking input is within constraints
try:
    CHECK_INT = [int(x) for x in A_LIST]
except ValueError:
    print('Input includes non-integer value(s).')
    sys.exit()

for i in A_LIST:
    if int(i) > 13 | int(i) < 1:
        print('Input includes value(s) not integers 1 through 13.')
        sys.exit()

# Output
if sum(A_LIST) >= 22:
    print('bust')
else:
    print('win')


Measured memory_bytes: 3060
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		for (int i = 1; i <= N; ++i) {
			if (String.valueOf(i).length() % 2 == 1)
				++ans;
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> a(h);
    deque<tuple<int, int, int>> q;
    vector<vector<bool>> b(h, vector<bool>(w, true));
    int x = 1000;
    REP(i, h) {
        cin >> a[i];
        int p;
        if ((p = a[i].find('S')) != string::npos)  {
            q.emplace_back(i, p, 0);
            b[i][p] = false;
            x = min({x, i, h - i - 1, p, w - p - 1});
        }
    }
    int r, c, n;
    while (!q.empty()) {
        tie(r, c, n) = q.front(); q.pop_front();
        if (n >= k) {
            continue;
        }
        if (r != 0 && b[r - 1][c] && a[r- 1][c] == '.') {
            q.emplace_back(r - 1, c, n + 1);
            b[r - 1][c] = false;
            x = min({x, r - 1, h - (r - 1) - 1, c, w - c - 1});
        }
        if (r != h - 1 && b[r + 1][c] && a[r + 1][c] == '.') {
            q.emplace_back(r + 1, c, n + 1);
            b[r + 1][c] = false;
            x = min({x, r + 1, h - (r + 1) - 1, c, w - c - 1});
        }
        if (c != 0 && b[r][c - 1] && a[r][c - 1] == '.') {
            q.emplace_back(r, c - 1, n + 1);
            b[r][c - 1] = false;
            x = min({x, r, h - r - 1, c - 1, w - (c - 1) - 1});
        }
        if (c != w - 1 && b[r][c + 1] && a[r][c + 1] == '.') {
            q.emplace_back(r, c + 1, n + 1);
            b[r][c + 1] = false;
            x = min({x, r, h - r - 1, c + 1, w - (c + 1) - 1});
        }
    }
    cout << (x + k - 1) / k + 1 << endl;
}


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

using namespace std;
#define ll long long
#define inf 998244353

char s[15][1005];

int main()
{
    int n, m, k;
    scanf("%d%d%d",&n,&m,&k);
    int jin=0, mi=inf;
    for(int i=0; i<n; i++)
    {
        scanf("%s",s[i]);
    }
    for(;;jin++)
    {
        //printf("jin=%d\n",jin);
        bitset<12> bit(jin);
        int p=bit.count();
        int pans=p+1;
        if(bit.test(n-1))
        {
            break;
        }
        for(int i=0; i<m;)
        {
            int sha=10007, le=0, lr=0;
            int pz=pans;
            while(pz--)
            {
                int pa=0, zi=0;
                le=lr;
                for(int j=i; j<m; j++)
                {
                    for(int o=le; o<n; o++)
                    {
                        if(s[o][j]=='1')
                        {
                            pa++;
                        }
                        if(bit.test(o))
                        {
                            lr=o+1;
                            break;
                        }
                    }
                    if(pa>k)
                    {
                        zi=j;
                        break;
                    }
                }
                if(pa>k)
                sha=min(zi-i,sha);
                else
                sha=min(m-i,sha);
            }
            //printf("%d\n",sha);
            if(sha<=0)
            {
                p=-1;
                break;
            }
            else
            {
                i=i+sha;
            }
            if(i<m)
            p++;
        }
        if(p==-1)
        {
            continue;
        }
        else
        {
            //printf("%d\n",p);
            mi=min(p,mi);
        }
    }
    printf("%d\n",mi);
    return 0;
}


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

using namespace std;

int n, ac, wa, tle, re;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
// 	freopen(".inp", "r", stdin);
//  	freopen(".out", "w", stdout);
 	cin >> n;
 	for (int i = 0; i < n; i++) {
 		string s;
 		cin >> s;
 		if (s == "AC") ac++;
 		if (s == "WA") wa++;
 		if (s == "TLE") tle++;
 		if (s == "RE") re++;
 	}
 	cout << "AC x " << ac << endl;
 	cout << "WA x " << wa << endl;
 	cout << "TLE x " << tle << endl;
 	cout << "RE x " << re << endl;
	
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

struct Edge
{
    int to, limit, cost;
    Edge(int to, int limit, int cost) : to(to), limit(limit), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct State
{
    int node, speed, pre;
    ld cost;
};

bool operator<(const State &e, const State &f)
{
    return e.cost > f.cost;
}

ld dp[40][40][40];

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

    int n, m, st, gt;
    while (cin >> n >> m, n || m)
    {
        cin >> st >> gt;
        st--;
        gt--;
        Graph g(n);
        for (int i = 0; i < m; i++)
        {
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--;
            y--;
            g[x].push_back(Edge{y, c, d});
            g[y].push_back(Edge{x, c, d});
        }
        for (int i = 0; i < n; i++)
            for (int j = 0; j <= 30; j++)
                for (int k = 0; k < n; k++)
                    dp[i][j][k] = INF;
        priority_queue<State> q;
        dp[st][0][st] = 0;
        q.push(State{st, 0, st, 0});
        while (!q.empty())
        {
            State s = q.top();
            q.pop();
            int node = s.node, speed = s.speed, pre = s.pre;
            ld cost = s.cost;
            for (auto e : g[node])
            {
                int to = e.to, limit = e.limit;
                if (to == pre)
                    continue;
                ld d = e.cost;
                if (limit >= speed + 1)
                {
                    if (dp[to][speed + 1][node] == INF)
                    {
                        dp[to][speed + 1][node] = cost + d / (speed + 1);
                        q.push(State{to, speed + 1, node, cost + d / (speed + 1)});
                    }
                }
                if (limit >= speed)
                {
                    if (dp[to][speed][node] == INF)
                    {
                        dp[to][speed][node] = cost + d / speed;
                        q.push(State{to, speed, node, cost + d / speed});
                    }
                }
                if (speed > 0 && limit >= speed - 1)
                {
                    if (dp[to][speed - 1][node] == INF)
                    {
                        dp[to][speed - 1][node] = cost + d / (speed - 1);
                        q.push(State{to, speed - 1, node, cost + d / (speed - 1)});
                    }
                }
            }
        }
        ld res = 1e15;
        for (int k = 0; k < n; k++)
        {
            res = min(res, dp[gt][1][k]);
        }
        if (res+EPS >= INF)
            cout << "unreachable" << endl;
        else
            cout << fixed << setprecision(10) << res << endl;
    }
}



Measured memory_bytes: 4448
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	cout << N * (N + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
const int md=1e9+7;
int n,ans,f[1000005],g[1000005];
int main(){
	scanf("%d",&n);
	ans=(n-1LL)*(n-1LL)%md;
	ans+=(n>2)+1;
	f[0]=g[0]=1;
	for(int i=1;i<n;++i){
		f[i]=(f[i-1]+((i>=3)?g[i-3]:0))%md,g[i]=(g[i-1]+f[i])%md;
		if(i<n-1)ans=(ans+((n-1LL)*(n-1)+i+1+(i!=n-2))%md*f[i])%md;else
		ans=(ans+1ll*n*f[i])%md;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B, C;
	cin >> A >> B >> C;

	co(min(C, A + B + 1) + B);

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - バイナリハックイージー / Unhappy Hacking (ABC Edit)
            string s = Console.ReadLine();
            string words = "";

            foreach(var c in s)
            {
                if (c == 'B')
                {
                    if (words.Length > 0)
                    {
                        words = words.Substring(0, words.Length - 1);
                    }
                }
                else
                {
                    words += c.ToString();
                }
            }

            Console.WriteLine(words);
        }
    }
}

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    for(int i=1;i<B;i++){
        if((A*i)%B==C){
            cout << "YES" << endl;
            return 0;
            
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]
xyh.sort(reverse = True, key = lambda x: x[2])

for cx in range(101):
  for cy in range(101):
    ## 全ての条件を満たすかどうかをみていく

    H = xyh[0][2]+abs(xyh[0][0]-cx)+abs(xyh[0][1]-cy)
            
    for xxyyhh in xyh[1:]:
      x = xxyyhh[0]
      y = xxyyhh[1]
      height = xxyyhh[2]
      
      if height == max(H -abs(x-cx) - abs(y-cy),0):
        continue
      else:
        break  
    else:
      print(cx,cy,H)
      sys.exit()
          


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
using namespace std;

int arr[101];
int main(){ int x, n;
    cin >> x >> n;
    for (int i=0; i<n; i++){ int x;
        cin >> x;
        arr[x]++;
    }
    int min = 2e9, ans;
    for (int i=0; i<=102; i++){
        if(arr[i] == 0){
            if(abs(x-i) < min){
                min = abs(x-i);
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define pb push_back
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

int N;
int A[110];
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  cin >> N;
  REP(i,N) cin >> A[i];

  cout << *max_element(A, A + N) - *min_element(A, A + N) << endl;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll T1, T2, A1, A2, B1, B2;

int main() {
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    if ((A1 > B1 && !(A2 < B2)) || (A1 < B1 && !(A2 > B2))) {
        cout << 0 << endl;
        return 0;
    }

    unsigned long long int x = T1 * abs(A1 - B1);
    unsigned long long int y = T2 * abs(A2 - B2);
    if (x > y) {
        cout << 0 << endl;
    } else if (x < y) {
        unsigned long long int z = y - x;
        if (x % z == 0)
            cout << (x / z) * 2 << endl;
        else
            cout << 1 + (x / z) * 2 << endl;
    } else {
        cout << "infinity" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{ 
  bool f=0;
  int l[10],r[10],i,j,n,k;
  long long int dp[200001],MOD=998244353;
  long long int ddp[10];
  cin>>n>>k;
  n--;
  for(i=0;i<k;i++)
  {
    cin>>l[i]>>r[i];
  }
  for(i=0;i<k;i++){ddp[i]=0;}
  
  for(i=0;i<200001;i++){dp[i]=0;}
  
  dp[0]=1;
  
  
  for(i=0;i<=n;i++)
  {
    
    for(j=0;j<k;j++)
    {
      if(i-l[j]>=0){ddp[j]+=dp[i-l[j]];}
      if(i-r[j]>0){ddp[j]-=dp[i-r[j]-1];}
      if(ddp[j]<0)ddp[j]+=MOD;
      ddp[j]=ddp[j]%MOD;
    }
    
    for(j=0;j<k;j++)
    {
      dp[i]+=ddp[j];
      dp[i]=dp[i]%MOD;
    }

  }

     cout<<dp[n]<<endl;
  
  
  return 0;
}

Measured memory_bytes: 5140
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>

using namespace std;

#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))

#define equal equalll
#define less lesss
typedef long double dbl;
typedef long long ll;
const int N = 1e5 + 10;
const ll INF = 1.01e9;
typedef vector<int> vi;

vector<int> e[N];
bool fail;

int dfs(int v, int p = -1) {

    int sum = 0;
    for (auto u: e[v]) {
        if (u != p) {
            sum += dfs(u, v);
        }
    }
    if (sum >= 2) {
        fail = 1;
        return 0;
    }
    return 1 -  sum;
}

int main(){
#ifdef HOME 
    assert(freopen("in", "r", stdin));
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        scanf("%d%d", &v, &u); v--; u--;
        e[v].pb(u);
        e[u].pb(v);
    }
    if (n % 2 == 1) {
        fail = 1;
    }

    dfs(0);
    if (fail) {
        puts("First");
    }
    else {
        puts("Second");
    }
    
    
#ifdef HOME 
    epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
    return 0;
}



Measured memory_bytes: 5888
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    cout << max(0LL, A + B * (N - 1) - A * (N - 1) - B + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char s[10];
  scanf("%s",s);
  int a=10*(s[5]-'0');
  int b=s[6]-'0';
  if(a+b>4) printf("TBD\n");
  else printf("Heisei\n");
  return 0;
}

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

int main()
{
	int A[100], N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];

	bool flag = true;
	int count = 0;
	int end = 0;
	while (flag) {
		flag = false;
		for (int i = N - 1; i > end; i--) {
			if (A[i-1] > A[i]) {
				swap(A[i - 1], A[i]);
				count++;
				flag = true;
			}
		}
		end++;
	}

	cout << A[0];
	for (int i = 1; i < N; i++) {
		cout << ' ' << A[i];
	}
	cout << endl << count << endl;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cs cout << "Case " << ++xx << ": "
#define cS printf("Case %lld:\n",++xx)
#define bitoff(val,pos) val & ~(1ll<<pos)
#define biton(val,pos) val | (1ll<<pos)
#define bittgl(val,pos) val ^ (1ll<<pos)
#define bitchk(val,pos) (bool)(val & (1ll<<pos))
#define odevn(val,pos) (bool)(val & (1ll<<pos))
#define bitcnt(val) __builtin_popcount(val)zz
#define pi acos(-1ll)
#define flot(ds) cout << setprecision(ds) << fixed;
ll drcx[] = {0, 0, -1, 1, 1, 1, -1, -1};
ll drcy[] = {1, -1, 0, 0, 1, -1, 1, -1};
ll xx,fr[300009];
struct strk{
    ll id1,id2;
}str[300009];
ll bgmod(ll v1, ll v2, ll md){
    ll res = 1;
    v1 = v1 % md;
    while (v2 > 0){
        if (v2 & 1)
            res = (res * v1) % md;
        v2 = v2 >> 1;
        v1 = (v1 * v1) % md;
    }
    return res;
}
int main()
{
        map<char,ll>mp;
        vector<ll>vec;
        ll n,a,b,c,f=0,gcd;
        pair<ll,pair<ll,ll> >pp;
        priority_queue< pair<ll, pair<ll,ll> > >qq;
        cin >> n >> c;
        for(ll i=1;i<=n;i++)
        {
            cin >> a;
            vec.push_back(a);
        }
        sort(vec.begin(),vec.end());
        for(ll i=0;i<c;i++)f+=vec[i];
        cout << f << endl;

    return 0;
}






Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin >>n >>l;
    int sum=0;
    int minabs=299;
    int min=0;

    for(int i=1;i<=n;i++){
        sum+=l+i-1;
        if(abs(l+i-1)<minabs){
            min=l+i-1;
            minabs=abs(l+i-1);
        }
    }
    cout<<sum-min<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n * 3];
			for(int i = 0; i < n * 3; i++){
				data[i] = sc.nextInt();
			}
			Arrays.sort(data);
			long sum = 0;
			for(int i = n; i < n * 3;i+=2){
				sum += data[i];
			}
			System.out.println(sum);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


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

typedef long long ll;

static const int MAX = 1e6;
static const int NIL = -1;
static const ll INF = 1<<21;
static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

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

    multiset<int> mset;

    int now;
    for(int i=0;i<N;i++) {
        now = A.at(i);
        auto itr = mset.lower_bound(now);
        if (itr!=mset.begin()) mset.erase(--itr);
        mset.insert(now);
    }

    cout << mset.size() << endl;
    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  string S,T;
  cin >> S >> T;
  for(int i=0; i<S.size(); i++){
    if(S.substr(i)+S.substr(0,i) == T){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
			Scanner scanner = new Scanner(System.in);

			// 数値入力
			int intx = scanner.nextInt();

			// intxの3乗を計算して出力
			System.out.println(intx * intx * intx);
	}
}



Measured memory_bytes: 26056
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

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

int main(){
    double r;
    cin >> r;
    printf("%.3lf\n", 2 * M_PI * r );
    return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	bool ok = false;
	int cnt = 0;
	while(n--)
	{
		int x,y;
		cin>>x>>y;
		if(x==y)
			cnt++;
		else
			cnt = 0;
		if(cnt==3)
			ok = true;
	}
	if(ok)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll x;
    cin >> x;
    ll ans=0;
    bool judge=true;
    while(judge){
        ans++;
        if(ans*x%360==0){
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
//#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

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

    if(k>=s.length()) cout<<s<<endl;
    else cout<<s.substr(0,k)<<"..."<<endl;
    return 0;
}


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

#define ll long long
#define pb push_back
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;

	if(n % 1000 == 0){
		cout<<0;
	}
	else{
	
		int count = n / 1000;
		cout<<(1000*(count+1))-n;
	}
	return 0;
}


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

bool judge(void);

int N;
int i,j;
int X[36],Y[36];
char x[36],y[36];


bool judge(){
  int i;
  for(i = 0 ; i < N ; i++){
    if(x[i] == y[i] && X[i] == Y[i]){
      continue;
    }else{
      return 0;
      break;
    }
  }
  return 1;
}
    

int main(){
  int tmp,min;
  char tmp_2;

  cin >> N;

  for(i = 0 ; i < N ; i++){
    cin >> x[i] >> X[i];
    Y[i]=X[i];
  }

  strcpy(y,x);

  for(i = 0 ; i < N ; i++){
    for(j = N - 1 ; j >= i+1 ; j--){
      if(X[j] < X[j-1]){
	swap(X[j],X[j-1]);
	swap(x[j],x[j-1]);
      }
    }
  }

  for(i = 0 ; i < N ; i++){
    min = i;
    for(j = i ; j < N ; j++){
      if(Y[j] < Y[min]){
	min=j;
      }
    }
    swap(Y[i],Y[min]);    
    swap(y[i],y[min]);
  }

  for(i = 0 ; i < N-1 ; i++){
    cout << x[i] << X[i] << ' ';
  }
  cout << x[N-1] << X[N-1] << endl;
  cout << "Stable" << endl;

  for(i = 0 ; i < N-1 ; i++){
    cout << y[i] << Y[i] << ' ';
  }
 
  cout << y[N-1] << Y[N-1] << endl;

  if(judge() == 0){
    cout << "Not stable" << endl;
  }else{
    cout << "Stable" << endl;
  }

  return 0;
}

Measured memory_bytes: 1172
while True :
  n = int(input())
  if(n == 0) :
    break
  else :
    A = [5, 7, 5, 7, 7]
    ans = 0
    w = [len(input()) for i in range(n)]
    for i in range(n) :
      k = 0
      s = 0
      for j in range(i, n) :
        s += w[j]
        if(s == A[k]) :
          s = 0
          k += 1
          if(k == 5) :
            ans = i + 1
            break
          elif(s > A[k]) :
            break
      if(ans != 0) :
        break
    print(ans)


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	
	vl dp(k+1);
	dp[0] = 1;
	
	while (n--) {
		vl ndp(k+1);
		ll a; cin >> a;
		
		ll sum = 0;
		FOR(i,0,k+1) {
			sum += dp[i];
			if (i > a) sum -= dp[i-a-1];
			sum %= MOD;
			ndp[i] = sum;
		}
		dp = ndp;
	}
	if (dp[k] < 0) dp[k] += MOD;
	cout << dp[k] << endl;
}



Measured memory_bytes: 1792
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = S()
print('ABC'+N)


Measured memory_bytes: 61844
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int n, m;
    cin >> n >> m;
    vi h(n);
    rep(i, n) cin >> h[i];
    vvi michi(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        michi[a].push_back(b);
        michi[b].push_back(a);
    }

    int ans = 0;
    rep(i, n) {
        bool ok = true;
        rep(j, michi[i].size()) {
            if(h[i] <= h[michi[i][j]]) ok = false;
        }
        if(ok) {
            ans++;
            //cout << i << endl;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8804
#include <stdio.h>

int main(){
int a, b, c;
    int tmp;
    scanf("%d %d %d", &a, &b, &c);
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2748
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

//#define READ_FROM_FILE

int main() {
	ios::sync_with_stdio(false);
	#ifdef READ_FROM_FILE
    freopen("input.in","r",stdin);
 	freopen("output.out","w",stdout);
	#endif

	vector<ll> cost(4);
	vector<pair<ll, ll>> A(4);

	ll N;
	rep(i, 4) {
		cin>>cost[i];
		A[i] = make_pair(cost[i]*(8/pow(2, i)), i);
	}
	cin>>N;

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

	int i = 0;
	if(A[i].second == 0) {
		cout<<4LL*N*cost[0]<<endl;
		return 0;
	}

	if(A[i].second == 1) {
		cout<<2LL*N*cost[1]<<endl;
		return 0;
	}

	if(A[i].second == 2) {
		cout<<N*cost[2]<<endl;
		return 0;
	}

	if(N%2 == 0) {
		cout<<(N/2)*cost[3]<<endl;
		return 0;
	}

	ll ans = (N/2)*cost[3];
	N = 1;

	i = 1;
	if(A[i].second == 0) {
		cout<<ans+4LL*N*cost[0]<<endl;
		return 0;
	}

	if(A[i].second == 1) {
		cout<<ans+2LL*N*cost[1]<<endl;
		return 0;
	}

	if(A[i].second == 2) {
		cout<<ans+N*cost[2]<<endl;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#define mp make_pair
#define pb push_back
#define int long long

const int INF = 1e+18;
using LL = long long;
using namespace std;

typedef pair<int, int> pii;

bool used[2010];
int n, k, s, x[2010], y[2010], z[2010];
vector<int> G[2010];

int kasane(int a, int b) {
	int ax = x[a], ay = y[a], az = z[a];
	int bx = x[b], by = y[b], bz = z[b];
	int ret = 0, cx, cy, cz;
	cx = max(0ll,min(x[a],x[b]) - max(x[a],x[b]) + s);
	cy = max(0ll,min(y[a],y[b]) - max(y[a],y[b]) + s);
	cz = max(0ll,min(z[a],z[b]) - max(z[a],z[b]) + s);
	if (!cx || !cy || !cz) return 0;
	return 2 * (cx * cy + cy * cz + cz * cx);
}

vector<vector<int>> sen;
vector<int> tmpvec;
vector<bool> isEn;

void dfs(int v, int par) {
	used[v] = true;
	tmpvec.pb(v);
	for (int to : G[v]) {
		if (to != par && !used[to]) {
			dfs(to, v);
		}
	}
}

int dp1[2010][2010][2][2];

signed main() {
	while (cin >> n >> k >> s, n) {
		isEn.clear();
		sen.clear();
		for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];
		for (int i = 0; i < n; i++) {
			G[i].clear();
			used[i] = false;
		}
		if (k == 1) {
			cout << 6 * s * s << endl;
			continue;
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (kasane(i, j)) {
					G[i].pb(j);
					G[j].pb(i);
				}
			}
		}
		for (int i = 0; i < n; i++) {
			if (!used[i] && G[i].size() == 1) {
				tmpvec.clear();
				dfs(i, -1);
				sen.pb(tmpvec);
				isEn.pb(false);
			}
		}
		for (int i = 0; i < n; i++) {
			if (!used[i]) {
				tmpvec.clear();
				dfs(i, -1);
				sen.pb(tmpvec);
				isEn.pb(true);
			}
		}
		int mi = INF;
		for (int i = 0; i < sen.size(); i++) {
			vector<int> vec = sen[i];
			int ans = s * s * 6 * k,_n = vec.size();
			if (_n < k) continue;
			if (_n == k && isEn[i]) {
				for (int j = 0; j < _n; j++) ans -= kasane(vec[j],vec[(j + 1) % _n]);
				mi = min(mi,ans);
				continue;
			}
			for(int j = 1;j < k;j++) ans -= kasane(vec[j],vec[j - 1]);
			for(int j = 0;j < (isEn[i] ? _n : (_n - k + 1));j++){
				mi = min(mi,ans);
				ans -= kasane(vec[(j + k) % _n],vec[(j + k - 1) % _n]);
				ans += kasane(vec[j],vec[(j + 1) % _n]);
			}
		}
		if (mi == INF) cout << -1 << endl;
		else cout << mi << endl;
	}
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int inf = INT_MAX / 2;
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; }


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

    int N;
    string S;
    cin >> N >> S;
    
    int a, b, c, ans;
    ans = 0;
    for (int i = 0; i < 1000; i++) {
        a = i / 100;
        c = i % 10;
        b = (i - 100 * a - c) / 10;
        for (int j = 0; j < N-2; j++) {
            if (a == (int)S[j]-'0') {
                for (int k = j+1; k < N-1; k++) {
                    if (b == (int)S[k]-'0') {
                        for (int l = k+1; l < N; l++) {
                            if (c == (int)S[l]-'0') {
                                ans++;
                                break;
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3676
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = -a[0] + a[n-1]
for i in range(1, n-1):
    ans += abs(a[i])
print(ans)
x = a[0]
y = a[n-1]
for i in range(1, n-1):
    if a[i] > 0:
        print(x, a[i])
        x -= a[i]
    else:
        print(y, a[i])
        y -= a[i]
print(y, x)


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

#define F first
#define S second
#define int long long
#define pb push_back
#define endl '\n'

using namespace std;

int32_t main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	char n;
	cin >> n;
	//cout << (int)('a') << endl;
	if ( (int)n < 97) cout << "A" ;
	else cout << "a";
	return 0;	
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int x;
    double p;
    cin >> x >> p;
    p/=100;
    cout << (x+1)/2/p << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 384
def bubbleSort(table):
    swap_count = 0
    for nAchieve in range(len(table) - 1):
        for index in range(len(table) - 1, nAchieve, -1):
            if table[index] < table[index - 1]:
                table[index], table[index - 1] = table[index - 1], table[index]
                swap_count += 1
    return swap_count


def conversion(table):
    return ' '.join(map(str, table))


element = int(input())
table = list(map(int, input().split()))
swap_count = bubbleSort(table)
table = conversion(table)

print('{}\n{}'.format(table, swap_count))


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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 2005;
int a[N], b[N];

int check(int i, int n, int k, int mx) {
	int last = 0;
	int ans = 0, cnt = 0;
	REPU(j, 0, n) {
		if (a[j] < b[i]) {
			ans += tmin(cnt, tmax(0, j - last - k + 1));
			last = j + 1;
			cnt = 0;
		}
		else if (a[j] <= mx) cnt++;
	}
	if (last < n) ans += tmin(cnt, tmax(0, n - last - k + 1));
	return ans;
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n, k, q; cin >> n >> k >> q;
	REPU(i, 0, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	int ans(INT_MAX);
	REPU(i, 0, n) {
		if (check(i, n, k, b[n - 1]) < q) break;
		int lb = i - 1, rb = n - 1;
		while (rb - lb > 1) {
			int mb = (lb + rb) >> 1;
			int tot = check(i, n, k, b[mb]);
			if (tot >= q) rb = mb;
			else lb = mb;
		}
		amin(ans, b[rb] - b[i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/python
# -*- coding: utf-8 -*-

n=int(input()) # 数列の長さ
A=list(map(int, input().split())) # 空白を区切文字として配列に格納

tmp = 0
cnt = 0
flag = 1

while flag:
    flag = 0
    for i in range(1, n):
        j = n - i
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1
print(*A)
print(cnt)


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

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  vector<tuple<int, int>> v;
  vector<tuple<int, int, int, int>> u;
  int h, w;
  cin >> h >> w;
  int x[500][500];
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> x[i][j];
    }
  }
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      v.emplace_back(i, j);
    }
    i++;
    if(i >= h) break;
    for(int j = w-1; j >= 0; j--) {
      v.emplace_back(i, j);
    }
  }
  for(int i = 0; i < v.size() - 1; i++) {
    int a,b,c,d;
    tie(a,b) = v[i];
    tie(c,d) = v[i+1];
    if(x[a][b]&1) {
      x[c][d]++;
      u.emplace_back(a,b,c,d);
    }
  }
  cout << u.size() << endl;
  for(int i = 0; i < u.size(); i++) {
    int a,b,c,d;
    tie(a,b, c,d) = u[i];
    cout << a+1 << " " << b+1 << " " << c+1 << " " << d+1 << endl; 
  }
  return 0;
}


Measured memory_bytes: 7152