akhauriyash/Code-Regression huggingface dataset:
def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

Measured memory_bytes: 17712
//
// Created by watemus on 02.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    int k;
    int a, b;
    cin >> k >> a >> b;
    int c = 0;
    for (int i = 0; i < 10000; i++) {
        c += k;
        if (c >= a && c <= b) {
            puts("OK");
            return;
        }
    }
    puts("NG");
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

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

int main()
{
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	vector<string> ans(h);
	for(int i = 0;i<h;i++)
		for(int j = 0;j<w;j++)ans[i].push_back('0');

	swap(a,b);




	for(int i = 0;i<a;i++)
		for(int j = 0;j<b;j++)
			ans[i][j]++;
	
	
	for(int i = a;i<h;i++)
		for(int j = b;j<w;j++)
			ans[i][j]++;
	for(int i = 0;i<h;i++)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	if(x==y)
	{
		cin>>x;
		cout<<x;
		return 0;
	}
	int z;
    cin>>z;
    if(z==x)
    cout<<y;
    else
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (wrds toInt) >>= mapM_ putStrLn

solve :: [Int] -> [String]
solve [j,y] = sort . map reverse . game $ (j,y)

game :: (Int,Int) -> [String]
game (6,4) = map ('A':) (game (5,4))
game (4,6) = map ('B':) (game (4,5))
game (5,5) = map ('A':) (game (4,5)) ++ map ('B':) (game (5,4))
game (5,y) = map ('A':) (game (4,y))
game (j,5) = map ('B':) (game (j,4))
game (j,y) = (nub . permutations) (replicate j 'A' ++ replicate y 'B')

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 5460
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n; double x[100000], y[100000];
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        scanf("%lf", &x[i]);
        scanf("%lf", &y[i]);
    }
    
    pair<double, double> p1[100000], p2[100000];
    
    for(int i = 0; i < n; i++)
    {
        p1[i] = make_pair(x[i], y[i]);
    }
    
    for(int i = 0; i < n; i++)
    {
        p2[i] = make_pair(y[i], x[i]);
    }
    
    sort(p1, p1 + n);
    sort(p2, p2 + n);
    
    double sqr_ans = 100000000.0;
    
    const int loops = 111;
    
    int n_1 = n - 1;
    
    for(int i = 0; i < n_1; i++)
    {
        int r = min(loops, n_1 - i);
        
        for(char j = 1; j <= r; j++)
        {
            double distance_ = (p1[i + j].first - p1[i].first) * (p1[i + j].first - p1[i].first) + (p1[i + j].second - p1[i].second) * (p1[i + j].second - p1[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    for(int i = 0; i < n_1; i++)
    {
        int r = min(loops, n_1 - i);
        
        for(char j = 1; j <= r; j++)
        {
            double distance_ = (p2[i + j].first - p2[i].first) * (p2[i + j].first - p2[i].first) + (p2[i + j].second - p2[i].second) * (p2[i + j].second - p2[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    printf("%.9f\n", sqrt(sqr_ans));
    
    return 0;
}

Measured memory_bytes: 7392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n;vector<int> v[100005];int dis[2][100005],w,b;
void dfs(int x,int fa,int h){
    rap(i,0,v[x].size()){
        int to=v[x][i];
        if(to==fa) continue;
        dis[h][to]=dis[h][x]+1;
        dfs(to,x,h);
    }
}
int main()
{
    scanf("%d",&n);
    rap(i,1,n){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        v[t1].pb(t2);v[t2].pb(t1);
    }
    dfs(1,0,0);
    dfs(n,0,1);
    rep(i,1,n) if(dis[0][i]<=dis[1][i]) b++;else w++;
    if(b>w) puts("Fennec");
    else puts("Snuke");
    return 0;
}

Measured memory_bytes: 14336
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int w , a  , b;
int main()
{
	while(~scanf("%d" , &w )){
		int i = 1;
		while((1 + i) * i / 2 < w) i++;
		cout << i << endl;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Fastest Route
 */
public class Main {

	static final int INF = 1 << 29;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int N = parseInt(line);
			if (N == 0) break;

			int[][] items = new int[N][N + 1];

			for (int i = 0; i < N; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				for (int j = 0; j <= N; j++) {
					items[i][j] = parseInt(st.nextToken());
				}
			}

			//
			int[] dp = new int[1 << N];

			Arrays.fill(dp, 1, dp.length, INF);

			for (int i = 0; i < 1 << N; i++) {
				for (int j = 0; j < N; j++) {
					if ((i >> j & 1) == 0) {
						int fastest = items[j][0];
						for (int k = 1; k <= N; k++) {
							if (((i >> (k - 1)) & 1) == 1) {
								fastest = Math.min(fastest, items[j][k]);
							}
						}
						dp[i | 1 << j] = Math.min(dp[i | 1 << j], dp[i] + fastest);
					}
				}
			}

			System.out.println(dp[(1 << N) - 1]);
		}
	}
}

Measured memory_bytes: 33144
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 行列のDPを持つ　縦軸がa
N, Ma, Mb = lr()
INF = 5000
limit = N * 10 + 1
dp = [[INF] * limit for _ in range(limit)]
dp[0][0] = 0
for _ in range(N):
    a, b, c = lr()
    used = set()
    for i in range(limit):
        if i < a:
            continue
        for j in range(limit):
            if j < b:
                continue
            # 商品は１個しか買えない            
            if (i-a, j-b) not in used:
                if dp[i][j] > dp[i-a][j-b] + c:
                    used.add((i, j))
                    dp[i][j] = dp[i-a][j-b] + c

answer = INF
for i in range(1, limit):
    if i % Ma != 0:
        continue
    for j in range(1, limit):
        if j % Mb != 0:
            continue
        if i // Ma == j // Mb:
            if dp[i][j] < answer:
                answer = dp[i][j]

print(answer if answer != INF else -1)
# 10

Measured memory_bytes: 47196
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    string S;
    cin >> S;

    cout << "2018";
    FOR(i, 4, S.size()) {
        cout << S[i];
    }

    cout << endl;

}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<cstdlib>
using namespace std;

int main()
{
    int j, x, n, i, flag = -1;
    cin >> x >> n;
    int A[n], D[105]={0};
    for(i=0;i<n;i++)
    {
        cin >> A[i];
        D[A[i]] = 1;
    }

    if(D[x] == 0 || n == 0)
    {cout << x;
    return 0;}
    else
    {
        i = x-1;
        j = x+1;
        while(flag == -1)
        {
            if(D[i] == 0)
            {flag = 0;
            break;}
            else
            i--;
            if(D[j] == 0)
            {flag = 1;
            break;}
            else
            j++;
        }
    }
    if(flag == 0)
    cout << i;
    else
    cout << j;
    return 0;
}



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

using namespace std;

vector<long long> divisors(long long n) {

    vector<long long> res;

    for(long long i=1; i*i<=n; i++) {

        long long one=i;

        if(n%one==0) {

            res.push_back(one);

            if(one!=n/one)

                res.push_back(n/one);

        }

    }

    return res;

}

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    vector<long long> dp(n+10,0);

    for(long long i=1; i<n+5; i++) {

        dp[i]++;

        for(long long j=2*i; j<n+5; j+=i) {

            dp[j]++;

        }

    }

    long long res=0;

    for(long long i=1; i<n; i++) {

        res+=dp[i];

    }

    cout << res << '\n';

    return 0;

}



Measured memory_bytes: 11100
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        long L =M/N;
        long ans=1;
         for(long i=1;i<=Math.sqrt(M);i++){
             if(M%i==0){
                 if(i<=L){
                     ans =Math.max(i,ans);
                 }
                 if(M/i<=L){
                     ans =Math.max(M/i,ans);
                 }
             }
         }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22740
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[50];
  int sum = 0;
  for(int i = 0;i < n;i++)
  {
    scanf("%d",&a[i]);
  }
  for(int i=0;i<n-1;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      sum += a[i] * a[j];
    }
  }
  printf("%d\n",sum);
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <cmath>

using namespace std;

void solve()
{
	double a, l, x;
	while(cin >> a >> l >> x)
	{
		double s1 = a / 4 * sqrt((a + 2 * l) * (2 * l - a));
		double maxS2 = 0;
		for(double i = 0.00001; i < 1.0; i += 0.00001)
		{
			double len1 = i * (l + x);
			double len2 = (1.0 - i) * (l + x);
			double s = (l + len1 + len2) / 2.0;
			if(s * (s - l) * (s - len1) * (s - len2) < 0)
			{
				continue;
			}
			else
			{
				double s2 = sqrt(s * (s - l) * (s - len1) * (s - len2));
				if(maxS2 < s2)
				{
					maxS2 = s2;
				}
			}
		}
		printf("%6f\n", s1 + 2 * maxS2);
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int n,r;
	cin >> n >> r;
	if(n<10){
		cout << r+ (10-n)*100 << endl;
	} else {
		cout << r << endl;
	}


	return 0;
}


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

int main()
{
  int n,k,p;
  cin >> n >> k;
  int a[n];
  rep(i,n) a[i] = 0;
  int w;
  rep(i,k){
    cin >> w;
    rep(i,w){
      cin >> p;
      a[p - 1]++;
    }
  }
  int ans=0;
  rep(i,n){
    if(a[i] == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

main(){
	int x,y,s ;
	while( cin >> x >> y >> s , x ){
		int ans = 0 ;
		for( int i=1 ; i<s ; i++ ){
			for( int j=1 ; j+i<=s ; j++ ){
				double A = i*(100.0+x) / 100 ;
				double B = j*(100.0+x) / 100 ;
				int c = A , d = B ;
				if( c+d == s ){
					A = i*(100.0+y) / 100 ;
					B = j*(100.0+y) / 100 ;
					c = A ; d = B ;
					ans = max( ans , c+d ) ;
				}
			}
		}
		cout << ans << endl ;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

struct Pointer{
    int p;//親へのポインタ
    int left;
    int right;
};

struct Pointer P[25];

void Preorder_Tree_Wolk(int x){
    if(x != -1){
        cout << " " << x ;
        Preorder_Tree_Wolk(P[x].left);
        Preorder_Tree_Wolk(P[x].right);
    }
}

void Inorder_Tree_Wolk(int y){
    if(y != -1){
        Inorder_Tree_Wolk(P[y].left);
        cout << " " << y ;
        Inorder_Tree_Wolk(P[y].right);
    }
}

void Postorder_Tree_Wolk(int z){
    if(z != -1){
        Postorder_Tree_Wolk(P[z].left);
        Postorder_Tree_Wolk(P[z].right);
        cout << " " << z ;
    }
}


int main(){
    int n;
    cin >> n;
    int id;

    for(int i=0; i<n; i++){//p(parent)を初期化
        P[i].p = -1;
    }

    for(int i=0; i<n; i++){
        cin >> id;
        cin >> P[id].left;
        if(P[id].left != -1){
            P[P[id].left].p = id;
        }
        cin >> P[id].right;
        if(P[id].right != -1){
            P[P[id].right].p = id;
        }        
    }

    int Root;
    for(int i=0; i<n; i++){
        if(P[i].p == -1){
            Root = i;
        }
    }

    cout << "Preorder" << endl;
    Preorder_Tree_Wolk(Root);
    cout << endl << "Inorder" << endl;
    Inorder_Tree_Wolk(Root);
    cout << endl << "Postorder" << endl;
    Postorder_Tree_Wolk(Root);
    cout << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    const ll push = 0;
    const ll pop = 1;
    const ll get = 2;
    struct Data{
        ll key, qid, val;
        Data(): key(0), qid(0), val(0){}
        Data(ll k, ll q, ll v): key(k), qid(q), val(v){}
        bool operator<(const Data& e) const{
            if(key == e.key){
                if(qid == e.qid) return val < e.val;
                return qid < e.qid;
            }
            return key < e.key;
        }
    };

    int N, Q;
    cin >> N >> Q;
    vector<ll> S(N), T(N), X(N), D(Q), ans(Q);
    for(int i=0; i<N; i++) cin >> S[i] >> T[i] >> X[i];
    for(auto& x: D) cin >> x;

    multimap<ll, Pll> mp;
    vector<Data> ds(2*N+Q);
    for(int i=0; i<N; i++){
        ds[2*i] = Data(S[i]-X[i], push, X[i]);
        ds[2*i+1] = Data(T[i]-X[i], pop, X[i]);
    }
    for(int i=0; i<Q; i++) ds[2*N+i] = Data(D[i], get, i);
    sort(ds.begin(), ds.end());

    multiset<ll> Xs;
    for(auto& d: ds){
        ll qid = d.qid;
        ll val = d.val;
        // cout << d.key << " " << qid << " " << val << "\n";
        if(qid == push) Xs.insert(val);
        else if(qid == pop){
            auto itr = Xs.find(val);
            Xs.erase(itr);
        }else{
            if(Xs.empty()) ans[val] = -1;
            else ans[val] = *Xs.begin();
        }
    }

    for(auto& x: ans) cout << x << "\n";
}

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

int main()
{
	int a[3];

	for (int i = 0; i < 3; i++)
		cin >> a[i];

	sort(a, a + 3);

	int ans = 0;
	ans += a[2] - a[0];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
   
int main(){
  int S[100000];
  int T[50000];
  int n,i,q,j,count=0,left,right,mid;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
  }

  for(i = 0; i < q; i++){
    left = 0;
    right = n;
    while(left < right){
      mid = (left + right) / 2;
      if(T[i] == S[mid]){
	count++;
	break;
      }
      if(T[i] > S[mid]){
	left = mid + 1;
      }else if(T[i] < S[mid]){
	right = mid;
      }
    } 
  }
  
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
int N;
int x[10],y[10];
double distance(int i,int j){
  double tmp1=x[i]-x[j];
  double tmp2=y[i]-y[j];
  return sqrt(tmp1*tmp1+tmp2*tmp2);
}
void solve(){
  int N;
  cin>>N;
  for(int i=1;i<=N;i++)cin>>x[i]>>y[i];
  vector<int> dot(N);
  for(int i=0;i<N;i++) dot.at(i)=i+1;
  
  double ans=0;
  do{
    for(int i=0;i<N-1;i++){
      ans+=distance(dot[i],dot[i+1]);
    }
  }while(next_permutation(dot.begin(),dot.end()));
  int factorial=1;
  for(int i=2;i<=N;i++)factorial*=i;
  cout << fixed << setprecision(10) << ans / factorial << endl;
  return;

}
int main(){
  solve();
  return 0;

}

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

int main() {
  int n;
  cin >> n;
  vector<double> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  double ans = (vec[0]+vec[1])/2.0;
  for(int i=2;i<n;i++){
    ans = (ans + vec[i])/2.0;
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

set<ll> prime_factorize(long long n) {
    set<ll> se;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        while (n % p == 0) { n /= p; }
        se.insert(p);
    }
    if (n != 1) se.insert(n);
    return se;
}

void solve(){
    ll A, B;
    cin >> A >> B;
    set<ll> seA = prime_factorize(A);
    set<ll> seB = prime_factorize(B);

    seA.insert(1);
    seB.insert(1);

    ll ans = 0;
    for(auto it : seA){
        auto it2 = seB.find(it);
        if (it2 != seB.end()) {
            ++ans;
        }
    }
    cout << ans << '\n';

    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int d[500];
int x[10000];
int y[10000];
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,m,i;
	while(1){
	scanf("%d",&n);
	scanf("%d",&m);
	if(n==0)return 0;
	for(i=0;i<n;i++)d[i]=3;
	for(i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		if(a==1)d[b-1]=1;
		x[i]=a-1;
		y[i]=b-1;
	}
	for(i=0;i<m;i++){
		if(d[x[i]]==1)d[y[i]]=min(d[y[i]],2);
		if(d[y[i]]==1)d[x[i]]=min(d[x[i]],2);
	}
	int ans=0;
	for(i=1;i<n;i++)if(d[i]<=2)ans++;
	printf("%d\n",ans);
	}
}

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

int main(){
	long long x,ans=0;
	cin >>x;

	if(!(x%11))
		ans = (x/11)*2;
	else {
		if(x%11 <= 6)
			ans = (x/11)*2 + 1;
		else if(x%11 >6)
			ans = (x/11)*2 + 2;
	}

	cout <<ans <<endl;


	return 0;
}

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

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)

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

    int x;
    cin >> x;
    cout << x / 500 * 1000 + x % 500 / 5 * 5 << el;
}


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

const int INF = 1001001001;

int main(){
	int n, m, x;
	int c[12], a[12][12];
	int ans = INF;
	int i, j, k;

	//input
	std::cin >> n >> m >> x;
	for(i=0; i<n; i++){
		std::cin >> c[i];
		for(j=0; j<m; j++){
			std::cin >> a[i][j];
		}
	}

	//algoritym
	//参考書の選び方は、2^n通り。2^n = 1<<n
	int combi = 1<<n;
	for(k=0; k<combi; k++){//参考書の選び方
		int cost = 0;
		std::vector<int> total(m);
		bool ok = true;

		for(i=0; i<n; i++){//n冊の参考書に対応するビットが1か
			if(k>>i & 1){
				cost += c[i];
				for(j=0; j<m; j++){//mこのアルゴリズム
					total[j] += a[i][j];
				}
			}
		}
		
		for(j=0; j<m; j++){
			if(total[j] < x) ok = false;
		}
		if(ok) ans = std::min(ans, cost);
	}

	//output
	if(ans == INF){
		std::cout << -1 << std::endl;
	}else{
		std::cout << ans << std::endl;
	}

	return 0;

}

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  
    if (a == b + c) {
      cout << "Yes" << endl;
    }
    else if (b == a + c) {
      cout << "Yes" << endl;
    }
    else if (c == a + b) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, ans;
int main(){
	scanf("%d", &n);
	for(int x = 1; x <= n; x += 2){
		int y = x, cnt = 0;
		for(int i = 1; i * i <= y; ++i){
			if(y % i == 0){
				if(i == y / i) cnt++;
				else cnt += 2;
			}
		}
		ans += cnt == 8; 
	}
	printf("%d", ans);
	return 0;
}

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

typedef long long int llint;

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

  int cnt = 0;
  
  for(int i = 0; i < 4; i++) {
    if(s[i] == '+') cnt++;
    else cnt--;
  }

  cout<< cnt <<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[300000];
main()
{
   int n,k;
   cin>>n>>k;
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
   }
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
   for(int i=0;i<n;i++ )
   {
       for(int j=i+1;j<=i+k;j++)
       {
            if(j<n) dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
       }
   }
   cout<<dp[n-1];

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int mod=1e9+7;
const int MAX=3e5+5;
int fact[MAX];
int ans=0;
int fastpow(int a,int b)
{
	int wynik=1;
	while (b)
	{
		if (b&1)wynik=((ll)wynik*a)%mod;
		a=((ll)a*a)%mod;
		b>>=1;
	}
	return wynik;
}

int binom(int a,int b)
{
	int licznik=fact[a];
	int mianownik=((ll)fact[b]*fact[a-b])%mod;
	//cout<<"TERAZ "<<licznik<<" "<<mianownik<<"\n";
	return ((ll)licznik*fastpow(mianownik,mod-2))%mod;
}

int ways(int x1,int y1,int x2,int y2)
{
	return binom(x2-x1+y2-y1,x2-x1);
}
int32_t main()
{
  BOOST;
  fact[0]=1;
  for (int i=1;i<MAX;i++)fact[i]=((ll)fact[i-1]*i)%mod;
  int n,m,a,b;
  cin>>n>>m>>a>>b;
  ll prefiks=0;
  int licznik=0;
  for (int i=n-a;i>=1;i--)
  {
    int x=i,y=b+1+licznik;
    if (y>m)break;
    ans=((ll)ans+(ll)ways(1,1,x,y)*ways(x,y,n,m))%mod;
    licznik++;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

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

		long n = scan.nextLong();
		long m = scan.nextLong();

		if(m < 2){
			System.out.println(0);
		}
		else if(n >= m/2){
			System.out.println(m/2);
		}
		else{
			if(n != 0){
				m -= n*2;
			}
			System.out.println(n+(m/4));
		}
	}
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
	return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int> &vec)
{
	for (auto &e : vec)
	{
		cout << e << " ";
	}
	cout << endl;
}

int main()
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;

	cout << ((a1 + a2 + a3 >= 22) ? "bust" : "win") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

mat G(100010, vec(0));
vec lb(100010,-INF), ub(100010,INF);
vector<bool> visited(100010, false);
P C_toP(ll v){
    visited[v] = true;
    ll &L = lb[v], &U = ub[v];
    for(ll to : G[v]){
        if(!visited[to]){
            P p = C_toP(to);
            L = max(L, p.fi - 1);
            U = min(U, p.se + 1);
        }
    }
    return mp(lb[v], ub[v]);
}
void P_toC(ll v, ll low, ll high){
    //low, highはvでのlb,ub候補
    visited[v] = true;
    ll &L = lb[v], &U = ub[v];
    L = max(L, low);
    U = min(U, high);
    for(ll to : G[v]){
        if(!visited[to]) P_toC(to, L - 1, U + 1);
    }
    return;
}

bool check(ll v, ll last){
    visited[v] = true;
    if(abs(last - lb[v]) != 1 || ub[v] < lb[v]) return false;
    for(ll to : G[v]){
        if(!visited[to]) {
            if(!check(to, lb[v])) return false;
        }
    }
    return true;
}

int main(){
    cin>>N;
    rep(i,N - 1){
        cin>>A>>B;
        --A, --B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    cin>>K;
    rep(i,K){
        cin>>A>>B;
        --A;
        lb[A] = ub[A] = B;
    }
    //cout<<'a'<<endl;
    C_toP(0);
    rep(i,N) visited[i] = false;
    P_toC(0, lb[0], ub[0]);
    rep(i,N) visited[i] = false;
    bool yes = check(0, lb[0] + 1);
    cout<<(yes ? "Yes" : "No")<<endl;
    if(yes){
        rep(i,N) cout<<lb[i]<<endl;
    }
    //rep(i,N) cout<<lb[i]<<' '<<ub[i]<<endl;
}

Measured memory_bytes: 14208
#include <vector>
#include <iostream>
using namespace std;
int n, m, x[3], a, b, dist[55]; vector<int> G[55]; bool dp[55][55][109];
int main() {
	cin >> n >> m;
	for (int i = 0; i < 3; i++) cin >> x[i];
	for (int i = 0; i < m; i++) {
		cin >> a >> b; a--, b--;
		G[a].push_back(b);
	}
	for (int i = 0; i < n; i++) {
		dp[i][i][0] = true;
		for (int j = 0; j < 100; j++) {
			for (int k = 0; k < n; k++) {
				if (dp[i][k][j]) {
					for (int l : G[k]) dp[i][l][j + 1] = true;
				}
			}
		}
	}
	fill(dist, dist + n - 1, 999999999);
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < n; j++) {
			if (dist[j] != 999999999) continue;
			int cnt = 0;
			for (int k = 0; k < 3; k++) {
				for (int l = 0; l < n; l++) {
					if (dp[j][l][x[k]] && dist[l] <= i) {
						cnt++; break;
					}
				}
			}
			if (cnt == 3) dist[j] = i + 1;
		}
	}
	if (dist[0] == 999999999) cout << "IMPOSSIBLE" << endl;
	else cout << dist[0] << endl;
	return 0;
}

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

def main():
    N = int(input())
    cnt = [0, 0, 0, 0, 0]
    for _ in range(N):
        s = input()
        if s[0] == 'M':
            cnt[0] += 1
        elif s[0] == 'A':
            cnt[1] += 1
        elif s[0] == 'R':
            cnt[2] += 1
        elif s[0] == 'C':
            cnt[3] += 1
        elif s[0] == 'H':
            cnt[4] += 1
    
    ans = 0
    for i in range(5):
        for j in range(i+1, 5):
            for k in range(j+1, 5):
                ans += cnt[i] * cnt[j] * cnt[k]
    
    print(ans)


if __name__ == '__main__':
    main()

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

typedef long long ll;
int main(){
  vector<ll> v(3);
  for(int i = 0; i < 3; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  ll k;
  cin >> k;
  for(int i = 0; i < k; i++){
    v[v.size()-1] = v[v.size()-1] * 2;
  }
  ll ans = 0;
  for(auto x: v){
    ans += x;
  }
  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;

int main(){
	int a, b;
  	cin >> a >> b;
  
  	string ans = "";
	if(a < b){
    	rep(i, b) ans += to_string(a);
    } else {
    	rep(i, a) ans += to_string(b);
    }
  
  	cout << ans << endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()
#define Foreach(item,collection) for(auto item : collection)

using pii=pair<int,int>;
using vb=vector<bool>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vvc=vector<vector<char>>;
using ti3=tuple<int,int,int>;
using ulong=unsigned long;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
#define OCB(c) (c&1)|(c&2)<<2|(c&4)<<4|(c&8)<<6|(c&16)<<8|(c&32)<<10|(c&64)<<12|(c&128)<<14

int main(){
    string a,b;
    cin >> a>>b;
    a+=b;
    auto k=stoi(a);
    auto res=(int)sqrt(k);
    if(res*res==k){
        out("Yes");
    }else{
        out("No");
    }
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, k, q; cin >> n >> k >> q;
	vector<int> A(n, k - q);
	for (int i=0; i<q; i++) {
		int j; cin >> j; j--;
		A[j] += 1;
	}
	string ret;
	for (int i=0; i<n; i++) {
		if (A[i] <= 0) ret = "No";
		else ret = "Yes";
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3664
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int n,W;
    scanf("%d %d",&n,&W);
    vector<pair<ll,ll>>A(n+1);

    ll totV = 0;
    for(int i=0;i<n;i++){
        ll w,p;
        scanf("%lld %lld",&w,&p);
        A[i].first = w;
        A[i].second = p;
        totV = totV + p;
    }

    vector<ll>dp(totV + 5,1e9+5);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int v = totV - A[i].second;v>=0;v--){
            dp[v+A[i].second] = min(dp[v+A[i].second],dp[v]+A[i].first);
        }

    }
    ll res = 0;
    for(ll v = 0;v<=totV;v++){
        if(dp[v]<=W) res = max(res,v);
    }
    printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{

    int k,a,b;
    cin>>k>>a>>b;

    

    for(int i = a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }

        
    }

cout<<"NG"<<endl;

}

Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int dfs(vector<vector<int>>& t,int i, int j, int depth,int w, int h) {
  if(depth==0)return 100000;
  int di[] = {1,0,-1,0};
  int dj[] = {0,1,0,-1};
  int minn = 100000;
  REP(k,4){
    for(int l=1;l <= 20; ++l){
      int ni=i+di[k]*l;
      int nj=j+dj[k]*l;
      if(ni<0||nj<0||ni>=h||nj>=w){
        break;
      }else if(t[ni][nj]==1){
        if(l>1){
          t[ni][nj] = 0;
          int n =dfs(t,ni-di[k],nj-dj[k],depth-1,w,h)+1;
          minn=min(minn,n);
          t[ni][nj] = 1;
        }
        break;
      }else if(t[ni][nj]==3){
        return 1;
      }
    }
  }
  return minn;
}

int main() {
  while(1){
    int w,h;
    cin>>w>>h;
    if(!w)break;
    vector<vector<int>> t(h,vector<int>(w));
    REP(i,h)REP(j,w)cin>>t[i][j];
    int si=0,sj=0;
    REP(i,h)REP(j,w)if(t[i][j]==2){
      si=i;sj=j;
      t[i][j]=0;
    }
    int n = dfs(t,si,sj,10,w,h);
    if(n < 100)
      cout << n << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}

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

int n;
int A[200000];

inline void swap(int *a, int *b){
  int z;
  z = *a;
  *a = *b;
  *b = z;
}

int kth(int *A, int n, int k){
  int i, l, r, pivot;
/*
  if(A[n/2] > A[0])    swap(A+n/2, A);
  if(A[n/2] > A[n-1])  swap(A+n/2, A+n-1);
  if(A[0] > A[n-1])    swap(A, A+n-1);
*/
  swap(A, A+n/2);
  pivot = A[0];
  l = 0;
  r = n;
  i = 1;
  while(i < r){
    if(A[i] < pivot) swap(A+l++, A+i++);
    else if(A[i] > pivot) swap(A+--r, A+i);
    else i++;
  } 
  if(k < l) return kth(A, l, k);
  if(k >= r) return kth(A+r, n-r, k-r);
  return pivot;
}

int main(){
  int i, m;
  long long int r;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", A+i);
    A[i] -= i+1;
  }
  m = kth(A, n, n/2);
  r = 0;
  for(i=0;i<n;i++) r += abs(A[i] - m);
  printf("%lld\n", r);
  return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int main(void){
    int a,p,all=0,ans=0;
    scanf("%d %d",&a,&p);
    all = a*3 + p;
    if(all % 2 ==0){
        ans = all /2;
    }else{
        ans = (all -1) / 2;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};
use std::f64::consts::PI;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());
    let r:f64 = scan.next();
    writeln!(out, "{} {}", PI*r*r, 2.0*PI*r).ok();
}



Measured memory_bytes: 5056
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

mat G(100010, vec(0));
vec ans(0);
vector<bool> used(100010,false);
void dfs(ll v){
    used[v] = true;
    for(ll to : G[v]){
        if(!used[to]){
            ans.push_back(to);
            dfs(to);
            return;
        }
    }
    return;
}

int main() {
    cin>>N>>M;
    rep(i,M){
        cin>>A>>B;
        --A; --B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    dfs(0);
    reverse(ALL(ans));
    ans.push_back(0);
    dfs(0);
    cout<<ans.size()<<endl;
    rep(i, ans.size()) {
        cout<<ans[i] + 1;
        i == ans.size() - 1 ? cout<<endl : cout<<' ';
    }
}

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

int main(){

  while(1){
    int n, m; cin >> n >> m;
    if(!n) break;

    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    vector<int> b;
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
	b.push_back(a[i] + a[j]);
      }
    }


    int ans = -1;
    for(auto x : b){
      if(x <= m) ans = max(ans, x);
    }

    if(ans == -1) cout << "NONE" << endl;
    else cout << ans << endl;

  }

  return 0;
}



Measured memory_bytes: 6772
#include<stdio.h>
long int s[100005],z[100005];
long int max(long int a[],int j,int n)
{
	long int b,r,k,m;
		b=a[j];
 		for(k=j+1;k<=n;k++)       
  		{ 	
  		
	  	
   		m=a[k];
   		while(m%b!=0)
   		{
   			r=m%b;
			m=b;
			b=r;}}	

 	 	return b;
} 
int zdgys(int m,int n)
{
	int a;			
	while(m%n!=0)
	{
		a=m%n;
		m=n;
		n=a;
	}
	return n;
}
int main()
{
	long int a[100005],b=1;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	s[0]=a[0];
	for(int i=1;i<n;i++)
	{
		s[i]=zdgys(s[i-1],a[i]);
	}
	
	z[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--)
	{
		z[i]=zdgys(z[i+1],a[i]);
	}
	for(int j=1;j<n-1;j++)
	{
		if(zdgys(s[j-1],z[j+1])>b)
		b=zdgys(s[j-1],z[j+1]);
	}
	long int t=(s[n-2]>z[1])?s[n-2]:z[1];
	if(t>b) b=t;
	printf("%d",b);
	return 0;
}


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

n, m = [int(i) for i in input().split()]
sc = [[int(i) for i in input().split()] for _ in range(m)]

ans = -1

if n == 1:
    bottom = 0
else:
    bottom = 10 ** (n-1)
top = 10 ** n

for a in range(bottom, top):
    a = str(a)
    flag = True
    for v in sc:
        s = v[0] - 1
        c = str(v[1])
        if a[s] != c:
            flag = False
            break
    if flag:
        ans = a
        break

print(ans)


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

int n, k;
double x[60], y[60], c[60], r[60];
double EPS = 1e-9;

double dist(pair<double, double> p, pair<double, double> q) {
	double xx = (p.first - q.first)*(p.first - q.first);
	double yy = (p.second - q.second)*(p.second - q.second);

	return sqrt(xx + yy);
}

vector<pair<double, double>> circle_circle_intersection(double x1, double y1, double r2, double x2, double y2, double r1){
	x1 -= x2;
	y1 -= y2;
	double S = x1*x1 + y1*y1;
	double a = (S + r1*r1 - r2*r2) / 2;
	double D = S*r1*r1-a*a;
	if(D <= 0) return {};
 
	double A1 = a * x1;
	double B1 = y1 * sqrt(D);
	double A2 = a * y1;
	double B2 = x1 * sqrt(D);
	return {
		{(A1+B1)/S+x2, (A2-B2)/S+y2},
		{(A1-B1)/S+x2, (A2+B2)/S+y2}
	};
}

int check(double t) {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		r[i] = t/c[i];
	}

	for (int i = 0; i < n; i++) {
		pair<double, double> p(x[i], y[i]);
		int cnt = 0;
		for (int k = 0; k < n; k++) {
			if (dist(p, make_pair(x[k], y[k])) <= r[k]) cnt++;
		}
		ans = max(ans, cnt);
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			vector<pair<double, double>> pts = circle_circle_intersection(x[i], y[i], r[i], x[j], y[j], r[j]);
			for (auto p: pts) {
				int cnt = 0;
				//cout << i << ' ' << j << ' ' << p.first << ' ' << p.second << '\n';
				//cout << x[i] << ' ' << y[i] << ' ' << r[i] << '\n';
				//cout << x[j] << ' ' << y[j] << ' ' << r[j] << '\n';
				for (int k = 0; k < n; k++) {
					if (dist(p, make_pair(x[k], y[k])) <= r[k] + EPS) cnt++;
				}
				ans = max(ans, cnt);
			}
		}
	}

	return ans;
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	feenableexcept(29);

	cin >> n >> k;
	if (k == 1) {
		cout << "0\n"; exit(0);
	}
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> c[i];
	}

	double lo = 0, hi = 100000000;
	for (int ite = 0; ite < 100; ite++) {
		double mid = (lo + hi)/2;

		if (check(mid) >= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	//cout << check(hi) << '\n';
	cout << fixed << setprecision(9) << hi << '\n'; 

	return 0;
}


Measured memory_bytes: 384
a=list(map(int,input().split()))
n=a[0]
m=a[1]
touhyou=list(map(int,input().split()))
s=float(sum(touhyou)/4/m)
list=[]
for i in touhyou:
  if i>=s:
    list.append(i)
if len(list)>=m:
  print("Yes")
else:
  print("No" )


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    string S[H];
    string M[H];
    rep(i, H) {
        rep(j, W) {
            char s;
            cin >> s;
            S[i] += s;
        }
    }

    int ans = 0;
    rep(i, H){
        rep(j, W){
            rep(k, H) {
                rep(l, W) {
                    rep(v, H) {
                        M[v] = S[v];
                    }
                    int st_x = i;
                    int st_y = j;
                    int go_x = k;
                    int go_y = l;
                    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

                    if (S[st_x][st_y] == '#' || S[go_x][go_y] == '#') continue;

                    queue<pair<int, int>> que;
                    int d[H][W];
                    for (int a = 0; a < H; a++){
                        for (int b = 0; b < W; b++) {
                            d[a][b] = 500000;
                        }
                    }
                    que.push(make_pair(st_x, st_y));
                    d[st_x][st_y] = 0;
                    while (que.size()) {
                        pair<int, int> p = que.front(); que.pop();
                        if (p.first == go_x && p.second == go_y) break;

                        // 移動4方向をループ
                        for (int a = 0; a < 4; a++) {
// 移動した後の点を(nx, ny)とする
                            int nx = p.first + dx[a], ny = p.second + dy[a];
// 移動が可能かの判定とすでに訪れたことがあるかの判定(d[nx][ny] != INFなら訪れたことがある)
                            if (0 <= nx && nx < H && 0 <= ny && ny < W && M[nx][ny] != '#' && d[nx][ny] == 500000) {
// 移動できるならキューに入れ、その点の距離をpからの距離+1で確定する
                                que.push(make_pair(nx, ny));
                                d[nx][ny] = d[p.first][p.second] + 1;
                            }
                        }
                    }
                    chmax(ans, d[go_x][go_y]);

                }

            }



        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
int main()
{ 
    cool;
    double l,ans,k;
    cin>>l;
    k=l-((l/3)*2);
    //printf("%f\n",k);
    ans=(l/3)*(l/3);
    ans*=k;
    printf("%f",ans);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("03")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"

const int mod=100000007;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, x, t;
	cin >> n >> x >> t;
	cout << fixed << setprecision(0) << ceil(float(n)/float(x))*t;
}



Measured memory_bytes: 3776
#include <stdio.h>

int main(){
    int p,q,r,sum1,sum2,sum3;
    
    scanf("%d %d %d",&p,&q,&r);
    
    sum1=p+q;
    sum2=p+r;
    sum3=q+r;
    
    if(sum1<=sum2 && sum1<=sum3){
        printf("%d\n",sum1);
    }
    
    else if(sum2<=sum1 && sum2<=sum3){
        printf("%d\n",sum2);
    }
    
    else if(sum3<=sum1 && sum3<=sum2){
        printf("%d\n",sum3);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  ll si = s.size();
  ll res = 0;
  for(int i = 0;i < si / 2 - 1;i++){
    string a = s.substr(0,i + 1);
    string b = s.substr(i + 1,i + 1);
    //cout << a << " " << b << endl;
    if(a == b)res = max(res,(ll)i);
  }
  cout << (res + 1) * 2 << endl;
}

Measured memory_bytes: 3636
A = [0, 1, 4]
G = [0, 1, 4]
C = [0, 1, 4]
T = [0, 1, 4]
AG = [0, 0, 1]
GA = [0, 0, 1]
AC = [0, 0, 1]
AT = [0, 0, 1]
AGG = [0, 0, 0]
ATG = [0, 0, 0]
AGT = [0, 0, 0]
for i in range(2, 100):
	A.append(A[i]+G[i]+C[i]+T[i])
	G.append(A[i]+G[i]+C[i]+T[i]-AC[i])
	C.append(A[i]+G[i]+C[i]+T[i]-AG[i]-GA[i]-AGG[i]-ATG[i]-AGT[i])
	T.append(A[i]+G[i]+C[i]+T[i])
	AG.append(A[i])
	GA.append(G[i])
	AC.append(A[i]-GA[i])
	AT.append(A[i])
	AGG.append(AG[i])
	ATG.append(AT[i])
	AGT.append(AG[i])
N = int(input())
print((A[N]+G[N]+C[N]+T[N])%(10**9+7))

Measured memory_bytes: 38384