akhauriyash/Code-Regression huggingface dataset:
// Problem : D - Teleporter
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){
	int n,k;cin>>n>>k;
	int a[n];
	inputarr(a,n);
	rep0(n) a[i]--;
	int dp[n][100];
	for(int i=0;i<n;i++) dp[i][0]=a[i];
	for(int l=1;l<70;l++){
		for(int i=0;i<n;i++){
			dp[i][l]=dp[dp[i][l-1]][l-1];
		}
	}
	// for(int l=0;l<3;l++){
		// trace(l,dp[0][l]);
		// cout<<dp[0][l]<<endl;
	// }
	int cur=0;
	for(int bit=0;bit<62;bit++){
		if(k&(1ll<<bit)){
			cur=dp[cur][bit];
			// trace(bit,cur);
		}
	}
	cout<<cur+1;



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 161508
def main():
    # 100円に毎年1%利子(複利・小数点切り捨て)->x円以上は何年後でしょうか
    x = int(input())

    i = 0
    n = 100
    while x>n:
        n = int(n*1.01)
        i += 1
    print(i)

main()


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

int n,b=0,a[100005],m=1000000001;
long long ans=0;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<0) b++;
        ans+=abs(a[i]);
        m=min(m,abs(a[i]));
    }
    if(b%2) ans-=(m*2);
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin>>S;long long K=0;
  for(int X=0;X<S.size();X++){
    K+=(S[X]-'0');
  }
  if(K%9==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3720
while True:
    Input = raw_input().split()

    a  = int(Input[0])
    op = Input[1]
    b  = int(Input[2])

    if   op == "+":
        ans = a + b
        print ans
    elif op == "-":
        ans = a - b
        print ans
    elif op == "/":
        ans = a / b
        print ans
    elif op == "*":
        ans = a * b
        print ans
    elif op == "?":
        break

Measured memory_bytes: 6436
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int z = sc.nextInt();
    int ans = 0;

    ans = (x-2*z) / (y+z);
    if((x-2*z) % (y+z) >= y){ans++;}

    System.out.println(ans);

  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


Measured memory_bytes: 22740
import itertools
import numpy as np
h, w, k = map(int, input().split())

grid = []
row_l = []
column_l = [0 for _ in range(w)]
for i in range(h):
    tmp = list(input())
    grid.append(tmp)
    row_l.append(tmp.count("#"))
    for j in range(w):
        if tmp[j] == "#": column_l[j]+=1

#print(row_l)
#print(column_l)
row_l = np.array(row_l)
column_l = np.array(column_l)
def dup(il,jl):
    sum = 0
    for i in il:
        for j in jl:
            if grid[i][j] == "#": sum+=1
    return sum

to_remove = sum(row_l)-k
ans = 0

for i_n in range(0, h+1):
    for j_n in range(0, w+1):
        for i in itertools.combinations(range(h), i_n):
            for j in itertools.combinations(range(w),j_n):
                if to_remove == sum(row_l[list(i)])+sum(column_l[list(j)])-dup(i,j):
                    ans += 1

print(ans)


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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	unordered_set<int> st;
	
	rep(i,n){
		int a;
		cin >>a;
		if(st.count(a)) st.erase(a);
		else st.insert(a);
	
	}
	
	cout << sz(st) <<"\n";
	return 0;
}


Measured memory_bytes: 4388
S = input()
S = S[::-1]
kws = ['dream','dreamer','erase','eraser']
kws = [kw[::-1] for kw in kws]

i = 0
while i < len(S):
    for kw in kws:
        if S[i:i+len(kw)] == kw:
            i += len(kw)
            break
    else:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    cout << (m*1900+(n-m)*100)*(1<<m) << endl;
}

Measured memory_bytes: 3632
// In the name of Allah
// #Isart

#include<bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double

using namespace std;

const int MAXN = 1e5 + 10;
int a[MAXN];

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int j = 0; j < 4; j ++){
		a[0] = j / 2;
		a[1] = j % 2;
		for(int i = 2; i < n; i ++){
			if(s[i - 1] == 'x') a[i] = 1 - a[i - 2];
			else if(s[i - 1] == 'o') a[i] = a[i - 2];
			if(a[i - 1] == 1) a[i] = 1 - a[i];
		}	
		bool is = true;
		for(int i = 0; i < n; i ++){
			int b = (i - 1 + n) % n, f = (i + 1) % n;
			if(a[i] == 0){
				if(s[i] == 'x')
					is = is & (a[b] != a[f]);
				else
					is = is & (a[b] == a[f]);
			}
			if(a[i] == 1){
				if(s[i] == 'x')
					is = is & (a[b] == a[f]);
				else
					is = is & (a[b] != a[f]);
			}
		}
		if(is){
			for(int i = 0; i < n; i ++){
				if(a[i] == 0)
					cout << "S";
				else
					cout << "W";
			}
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;	
}

Measured memory_bytes: 976
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

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

int main() {
    stack<long> st;
    string s;
    while (cin >> s) {
        if (s == "+") {
            long a = st.top(); st.pop();
            long b = st.top(); st.pop();
            st.push(a+b);
        }else if (s == "-") {
            long a = st.top(); st.pop();
            long b = st.top(); st.pop();
            st.push(b-a);
        }else if (s == "*") {
            long a = st.top(); st.pop();
            long b = st.top(); st.pop();
            st.push(a*b);
        }else { // number
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;
    return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
#define SORT(s) sort((s).begin(),(s).end())

int main() {
	int n;
  	cin>>n;
  tuple<string,int,int> p[110];//tupleとかpairとかを使って複数の値をまとめて管理
  
  for(int i=0;i<n;i++){
    string s;
    int a;
    cin>>s>>a;
  	p[i]=make_tuple(s,-a,i);//make_tupleでtupleを生成
  }							//昇順出力で大きい順に出るように点数を-に変換			
  sort(p,p+n);//ソートする
  
 
  for(int j=0;j<n;j++){
    
    cout<<get<2>(p[j])+1<<endl;//三番目の値+１を出力する
  }
  
}

Measured memory_bytes: 3596
H, W, D = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for i in range(H)]
Q = int(input())
LR = [[int(_) for _ in input().split()] for i in range(Q)]

pos = {}
for i, row in enumerate(A):
    for j, x in enumerate(row):
        pos[x] = (i, j)

dt = [0] * (H * W + 1)
for x in range(D + 1, H * W + 1):
    y = x - D
    p1, p2 = pos[x], pos[y]
    dt[x] = dt[y] + abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

for l, r in LR:
    print(dt[r] - dt[l])


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  // (K * i + 1) * (K ^ j)

  int64_t n;
  std::cin >> n;
  if (n == 2) {
    std::cout << 1 << std::endl;
    return 0;
  }

  int64_t n2 = n;
  std::map<int64_t, int64_t> m;

  for (int64_t i = 2; i * i <= n2; i++) {
    if (n2 % i == 0) {
      int64_t j = 0;
      while (n2 % i == 0) {
        n2 /= i;
        j++;
      }
      m[i] = j;
    }
  }
  if (n2 != 1) {
    m[n2] = 1;
  }

  std::set<int64_t> y;
  y.insert(1);

  for (const auto itr : m) {
    std::set<int64_t> y2;

    int64_t r = 1;
    for (int64_t j = 0; j <= itr.second; j++) {
      for (const auto i : y) {
        y2.insert(i * r);
      }
      r *= itr.first;
    }
    std::swap(y, y2);
  }

  y.erase(1);

  int64_t ans = 0;

  for (const auto i : y) {
    int64_t n2 = n;
    while (n2 % i == 0) {
      n2 /= i;
    }
    if (n2 % i == 1) {
      ans++;
    }
  }

  {
    int64_t n2 = n - 1;
    std::map<int64_t, int64_t> m;

    for (int64_t i = 2; i * i <= n2; i++) {
      if (n2 % i == 0) {
        int64_t j = 0;
        while (n2 % i == 0) {
          n2 /= i;
          j++;
        }
        m[i] = j;
      }
    }
    if (n2 != 1) {
      m[n2] = 1;
    }

    std::set<int64_t> y;
    y.insert(1);

    for (const auto itr : m) {
      std::set<int64_t> y2;

      int64_t r = 1;
      for (int64_t j = 0; j <= itr.second; j++) {
        for (const auto i : y) {
          y2.insert(i * r);
        }
        r *= itr.first;
      }
      std::swap(y, y2);
    }

    y.erase(1);
    ans += y.size();
  }

  std::cout << ans << std::endl;

  return 0;
}

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

namespace ITP1_5A
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string[] inString = Console.ReadLine().Split(' ');
                int H = int.Parse(inString[0]);
                int W = int.Parse(inString[1]);
                if ((H == 0) && (W == 0)) break;

                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }
}

Measured memory_bytes: 8808
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;


int main(){
  
  int d,t,s; cin>>d>>t>>s;
  if(d>t*s) cout<<"No"<<endl;
  else cout <<"Yes"<<endl;
  
  
}


Measured memory_bytes: 3632
import re
while 1:
	n,m = map(int,raw_input().split())
	if n ==0: break
	prize = []
	for i in range(n):
		num,money = raw_input().replace("*","[0-9]").split()
		prize.append([re.compile(num),int(money)])
	ans = 0
	for i in range(m):
		lot = raw_input()
		for num,money in prize:
			if num.search(lot):
				ans += money
	print ans

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

using namespace std;
#define F first
#define S second
typedef long long lli;
const int MX = 100005 , infi =1000000 , mod = 1000000007;
typedef pair<int,int> pii;

lli n,m , vals[MX][3] , dp[MX][3];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<MX;i++)
        dp[i][0]=dp[i][1]=dp[i][2]=-1;
    for(int i=0;i<n;i++)
        cin>>vals[i][0]>>vals[i][1]>>vals[i][2];
    dp[0][0]=vals[0][0];
    dp[0][1]=vals[0][1];
    dp[0][2]=vals[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0] = vals[i][0]+max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = vals[i][1]+max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = vals[i][2]+max(dp[i-1][1], dp[i-1][0]);
    }
    cout<<max( dp[n-1][0] ,max(dp[n-1][1] , dp[n-1][2]) );
    return 0;
}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int x;
    cin >> x;
    /*
    vector<int> sieve((int)1e5+101, 1);
    sieve[0] = sieve[1] = 0;
    int res = 0;
    for (int i = 4; i <= (int)1e5+100; i += 2) sieve[i] = 0;
    for (int i = 3; i*i <= (int)1e5+100; i += 2)
    	if (sieve[i]) 
    		for (int j = i*i; j <= (int)1e5+100; j += 2*i) {
    			sieve[j] = 0;
    		}
	for (int i = x; i <= 2*x; ++i)
		if (sieve[i]) {
			cout << i << '\n';
			break;
		}
		*/
    for (int i = x; i <= 2*x; ++i) {
    	bool works = 1;
    	for (int j = 2; j*j <= i; ++j) {
    		if (i % j == 0) {
    			works = 0;
    			break;
    		}
    	}
    	if (works) {
    		cout << i << '\n';
    		break;
    	}
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  char s[4][110];
  rep(i,3) cin >> s[i];
  cout << "A" << s[1][0] << "C" << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//
int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(c >= b){
        cout << floor((a * (b - 1)) / b) - a * floor((b - 1) / b);
    }else{
        cout << floor((a * c) / b) - a * floor(c / b);
    }
}

Measured memory_bytes: 3760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();

		if (a == b && a == c && b == c) {
			System.out.println(1);
		} else if (a == b && a != c || a == c && a != b || b == c && c != a) {
			System.out.println(2);
		} else {
			System.out.println(3);
		}
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int H, W, K;
vector<string> grid;
vector<vector<int>> d;

void bfs(int sx, int sy)
{
	queue<pair<int, int>> que;
	que.push({sx, sy});
	d[sx][sy] = 0;

	while (!que.empty())
	{
		auto v = que.front();
		que.pop();
		int vx = v.first, vy = v.second;

		for (int i = 0; i < 4; i++)
		{
			for (int j = 1; j <= K; j++)
			{
				int nx = vx + dx[i] * j, ny = vy + dy[i] * j;

				if (nx < 0 || nx >= H || ny < 0 || ny >= W) // grid の外
					break;

				if (grid[nx][ny] == '@') // 行き止まり
					break;

				if (d[nx][ny] != -1 && d[nx][ny] <= d[vx][vy]) // 行く意味なし
					break;

				if (d[nx][ny] != -1) // 最短ではない
					continue;

				d[nx][ny] = d[vx][vy] + 1;
				que.push({nx, ny});
			}
		}
	}
}

int main()
{
	fast();

	cin >> H >> W >> K;
	int sx, sy, gx, gy;

	cin >> sx >> sy >> gx >> gy;
	sx--, sy--, gx--, gy--;
	grid = vector<string>(H);
	d = vector<vector<int>>(H, vector<int>(W, -1));

	for (int i = 0; i < H; i++)
	{
		cin >> grid[i];
	}

	bfs(sx, sy);

	cout << d[gx][gy] << "\n";
}

Measured memory_bytes: 11112
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

using namespace std;

#define PI			3.14159265
#define OO			1e9
#define SS       	second
#define FF       	first
#define Trace(n)  	cout<< #n <<" = "<< n << endl; 
#define ll			long long
#define endl		"\n"
#define EPS		    1e-9
//#define MOD         1e9 + 7	    
//int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
//int dy[] = { -1, 1, 0, 0, 1, -1, 1, -1 };

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}


int main()
{
	fast();
	int n;
	double ans = 0;
	cin >> n;
	while (n--)
	{
		double N;
		cin >> N;
		ans += (1.0 / N);
	}
	cout << fixed << setprecision(7) << 1.0 / ans;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayDeque

val br = System.`in`.bufferedReader()
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val aArray = IntArray(n) { readInteger() }

    // linkedListのほうが良さそう
    val colorDequeue = mutableListOf<Int>() // 使用した色に対して最後に塗った数値
    var ans = 1
    colorDequeue += aArray.first()
    for (a in aArray.drop(1)) {
        var left = -1
        var right = colorDequeue.size
        while (right - left > 1) {
            val mid = (right + left) / 2
            if (colorDequeue[mid] < a) left = mid else right = mid
        }

        if (left == -1) {
            ans++
            colorDequeue.add(0, a)
        } else {
            colorDequeue[left] = a
        }
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 51712
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,K;
string S;
int main(){
    cin>>N>>K>>S;
    queue<ll> q;
    ll start=0;
    ll nowLength=0;
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(S[i]=='0'&&(S[i+1]=='1'||i+1==N)){
            q.push(i+1-start);
            nowLength+=i+1-start;
            start=i+1;
        }
        if((q.size()==K && (S[i]=='1'&&S[i+1]=='0') ) || i+1==N){
            ans=max(ans,i+1-start+nowLength);
            nowLength-=q.front();
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())

ans = []
if M%2 == 0:
    for i in range(1, M//2+1):
        ans.append([i, M+1-i])
        ans.append([M+i, 2*M+2-i])
else:
    for i in range(1, M//2+1):
        ans.append([i, M+1-i])
    for i in range(1, (M+1)//2+1):
        ans.append([M+i, 2*M+2-i])

for i in range(len(ans)):
    print(*ans[i])

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

using namespace std;

int calc(int n){
	int sum = 0;
	
	for(int x = 0; x < 600; x += n){
		sum += x*x*n;
	}

	return sum;
}

int main(){
	vector<int> ans;
	int n;

	while(cin >> n){
		if(cin.eof()){
			break;
		}

		ans.push_back(calc(n));
	}

	for(int& i: ans){
		cout << i << endl;
	}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/06/29  Problem: ABC 132 B / Link: http://abc132.contest.atcoder.jp/tasks/abc132_b  ----- */


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

	LL N; cin >> N;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	
	LL ans = 0LL;
	FOR(i, 1, N - 1) {
		VL b({ a[i - 1],a[i],a[i + 1] });
		auto it = minmax_element(ALL(b));
		if (a[i] != *it.first&&a[i] != *it.second)ans++;
	}
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
 int K;
 cin>>N;
 cin>>K;
 int x;
 int S=0;
 for(int i=0;i<N;i++)
 {
   cin>>x;
   if(x<(K-x))S+=2*x;else S+=2*(K-x);
 }
 cout<<S<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main() {
  char buf[262144];
  scanf("%s", buf);
  std::string s = buf;

  size_t n = s.length();
  std::vector<int> a(n);
  for (size_t i = 0; i < n; ++i) a[i] = s[i]-'0';
  a.push_back(0);
  std::vector<int> memo(2019, 0);
  memo[0] = 1;

  int t = 1;
  intmax_t res = 0;
  for (size_t i = n; i--;) {
    a[i] = (t*a[i] + a[i+1]) % 2019;
    res += memo[a[i]];
    ++memo[a[i]];
    (t *= 10) %= 2019;
  }

  printf("%jd\n", res);
}


Measured memory_bytes: 4640
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstring>

#define MOD 1000000007

using namespace std;

int main()
{
	long long n, k;

	scanf("%lld %lld", &n, &k);

	long long next[200001];

	for (long long i = 1; i <= n; i++)
	{
		scanf("%lld", &next[i]);
	}

	long long val[200001];

	memset(val, -1, sizeof(val));

	val[1] = 0;
	long long cur = 1;
	long long cnt = 1;
	long long path[200001];
	path[0] = 1;
	cur = next[cur];

	while (val[cur] == -1)
	{
		val[cur] = cnt;
		path[cnt] = cur;

		cnt++;
		cur = next[cur];
	}

	long long loop;

	loop = cnt - val[cur];

	if (k <= val[cur])
	{
		printf("%lld\n", path[k]);
	}

	else
	{
		long long r;

		r = (k - val[cur]) % loop;

		printf("%lld\n", path[val[cur]+r]);
	}

	return 0;
}

Measured memory_bytes: 6356
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b;


  rep(i, N){
    cin >> a[i];
    if(a[i] == i+1) b.push_back(a[i]);
  }

  int ans = b.size();
  for(int i = 1; i <b.size(); i++ ){
    if(b[i] == b[i-1]+1){
      ans--;
      i++;
    }
  }

  print(ans);

}


Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int TT = cin.nextint;
        for (int i = 0; i < TT; i++)
        {
            var A = cin.nextlong;
            var B = cin.nextlong;

            var C = A * B;

            BigInteger ng = (BigInteger)1 << 32; //不可能
            BigInteger ok = 0; //可能

            while (ng - ok > 1)
            {
                var mid = (ng + ok) / 2;
                if (mid % 2 == 1)
                {
                    var P = (mid + 1) / 2;
                    if (P >= A) P++;
                    var Q = (mid + 1) / 2;
                    if (Q >= B) Q++;

                    if (P * Q < C)
                    {
                        ok = mid;
                    }
                    else
                    {
                        ng = mid;
                    }
                }
                else
                {
                    var p1 = mid / 2;
                    var p2 = mid / 2 + 1;
                    if (p1 >= A) p1++;
                    if (p2 >= A) p2++;
                    var q1 = mid / 2;
                    var q2 = mid / 2 + 1;
                    if (q1 >= B) q1++;
                    if (q2 >= B) q2++;

                    if (p1 * q2 < C && p2 *q1 < C)
                    {
                        ok = mid;
                    }
                    else
                    {
                        ng = mid;
                    }
                }
            }
            WriteLine(ok);



        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13524
#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: 6796
#include<stdio.h>
#include<algorithm>
using namespace std;
int mod=1000003;
struct wolf{
    int l,r;
    wolf(){}
    wolf(int a,int b){
        l=a;r=b;
    }
};
inline bool operator<(const wolf&a,const wolf&b){
    if(a.l!=b.l)return a.l<b.l;
    return a.r>b.r;
}
wolf p[51000];
int in[51000];
int next[51000];
int dp[51000][2][2];
int solve(int a,int b,int c){
    if(~dp[a][b][c])return dp[a][b][c];
    if(in[a]==-1){
        int ret=0;
        if((p[a].r-p[a].l+b+c)%2==0)return dp[a][b][c]=0;
        if(b==0&&c==0)return dp[a][b][c]=2;
        return dp[a][b][c]=1;
    }
    long long ret=0;
    long long te=0;
    long long to=0;
    int at;
    if(b==0&&c==0&&(p[a].r-p[a].l)%2){
        to=1;
        at=p[a].l;
        for(int i=in[a];~i;i=next[i]){
            if(p[i].l>=p[a].r)break;
            long long tte;
            long long tto;
            if((p[i].l-at)%2){
                tte=te*solve(i,1,1)+to*solve(i,0,1);
                tto=te*solve(i,1,0)+to*solve(i,0,0);
            }else{
                tte=te*solve(i,0,1)+to*solve(i,1,1);
                tto=te*solve(i,0,0)+to*solve(i,1,0);
            }
            te=tte%mod;
            to=tto%mod;
            at=p[i].r;
        }
        if((p[a].r-at)%2==0)ret=te;
        else ret=to;
    }
    te=to=0;
    if(b)to=1;
    else te=1;
    at=p[a].l;
    for(int i=in[a];~i;i=next[i]){
        if(p[i].l>=p[a].r)break;
        long long tte;
        long long tto;
        if((p[i].l-at)%2){
            tte=te*solve(i,1,1)+to*solve(i,0,1);
            tto=te*solve(i,1,0)+to*solve(i,0,0);
        }else{
            tte=te*solve(i,0,1)+to*solve(i,1,1);
            tto=te*solve(i,0,0)+to*solve(i,1,0);
        }
        te=tte%mod;
        to=tto%mod;
        at=p[i].r;
    }
    if((p[a].r-at)%2==!c)ret=(ret+te)%mod;
    else ret=(ret+to)%mod;
    //printf("%d %d %d: %d\n",a,b,c,ret);
    return dp[a][b][c]=ret;
}
int main(){
    int a,b;
    while(scanf("%d%d",&a,&b),a){
        for(int i=0;i<b;i++){
            int s,t;scanf("%d%d",&s,&t);
            s--;t--;
            p[i]=wolf(min(s,t),max(s,t));
        }
        p[b++]=wolf(0,a-1);
        if(a%2){
            printf("0\n");continue;
        }
        std::sort(p,p+b);
        for(int i=0;i<b;i++){
            int nx=lower_bound(p,p+b,wolf(p[i].r,99999999))-p;
            if(nx>=b)next[i]=-1;
            else next[i]=nx;
            int ni=upper_bound(p,p+b,wolf(p[i].l,p[i].r))-p;
            if(ni>=b||p[ni].l>=p[i].r)in[i]=-1;
            else in[i]=ni;
        }
    //  for(int i=0;i<b;i++)printf("%d %d\n",in[i],next[i]);
        for(int i=0;i<b;i++)for(int j=0;j<2;j++)for(int k=0;k<2;k++)dp[i][j][k]=-1;
        printf("%d\n",solve(0,0,0));
    }
}

Measured memory_bytes: 7068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long L,R;
  cin >> L >> R;
  int result = 2019;
  if((L / 2019) < (R / 2019)){
   cout << 0 << endl; 
  }else{
    for(long long a = L;a < R;a++){
      for(long long b = a + 1;b <= R;b++){
        if(result > (a * b) % 2019)result = (a * b) % 2019;
        
      }


    }
    cout << result << endl; 
  }
  
}

Measured memory_bytes: 3572
#include <stdio.h>

int main(void) {
    int i, n, max, min, ans ,tmp;
    int array[101];
    scanf("%d",&n);
    while(n) {
        scanf("%d",&tmp);
        ans = 0;
        array[0] = tmp;
        max = tmp;
        min = tmp;
        for(i = 1; i < n; i++ ) {
            scanf("%d",&array[i]);
            if(min > array[i]) {
                min = array[i];
            }
            if(max < array[i]) {
                max = array[i];
            }
        }
        for(i = 0; i < n; i++ ) {
            ans += array[i];
        }
        ans -= (min + max);
        printf("%d\n",ans/(n-2));
        scanf("%d",&n);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
#define int long long

#define GG (puts("Impossible"), exit(0))

const int N = 2333;
int n, mn, mx, a[N];
vector <int> dis[N], rol;

signed main(void) {
	read(n);
	rep (i, n) read(a[i]), dis[a[i]].push_back(i), mx = max(mx, a[i]);
	mn = (mx + 1) / 2;
	rep (k, mn - 1) if (dis[k].size()) GG;
	for (int k = mx; k >= mn; k--) {
		// cout << k << "\n";
		if (!dis[k].size()) GG;
		rol.push_back(dis[k].back()); dis[k].pop_back();
	}

	for (int k = mn + (!(mx & 1)); k <= mx; k++) {
		// cout << k << "\n";
		if (!dis[k].size()) GG;
		rol.push_back(dis[k].back()); dis[k].pop_back();
	}
	if (dis[mn].size()) GG;
	puts("Possible");
}


Measured memory_bytes: 256
N = int(input())
ls1 = []
ls2 = []
ls3 = []
ans = []
for i in range(N):
    s = input()
    ls1.append(s)
    ls3.append(s)
M = int(input())
for j in range(M):
    t = input()
    ls2.append(t)
    ls3.append(t)
k = set(ls3)
p = list(k)
for i in range(len(p)):
    ans.append(ls1.count(p[i])-ls2.count(p[i]))
print(max(0,max(ans)))

Measured memory_bytes: 3064
# coding: utf-8

H = int(input())
W = int(input())
N = int(input())

if H > W:
    for i in range(1, W+1):
        if H * i >= N:
            print(i)
            break
else:
    for i in range(1, H+1):
        if W * i >= N:
            print(i)
            break


Measured memory_bytes: 2940
use std::io;

/// https://beta.atcoder.jp/contests/abc070/tasks/abc070_c
fn main() {
    let n = read_one::<u64>();
    let ans = (0..n).fold(1, |a, _| lcm(a, read_one::<u64>()));
    println!("{}", ans);
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn lcm(a: u64, b: u64) -> u64 {
    // avoid overflow
    (a / gcd(a, b)) * b
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

void solve() {
    ll N; cin >> N;
    ll m = 2 * 1e12; m++;
    for(ll i = 1; i * i <= N; i++) 
        if(N % i == 0) {
            if(i-1 + N/i-1 < m)
                m = i-1 + N/i-1;
        }
    cout << m << endl;
}

int main() {
    solve();
}


Measured memory_bytes: 256
#include<stdio.h>

/* ?§??????????struct?????£?¨? */
typedef struct{
	int d0;
	int d1;
	int d2;
	int d3;
	int d4;
	int d5;
}DICE;

/* DiseRoll??¢??°?????£?¨? */
int DiceRoll(DICE[], int);
/* Dise??¢??°?????£?¨? */
void Dice(char p, DICE[], int);
/* Count??¢??°?????£?¨? */
int Count(DICE[], int);

int main(void){

	DICE d[100];
	int i = 0, flg = 0, n;
	char str[2][4] = { "Yes" ,"No" };

	scanf("%d", &n);
		for(i = 0; i < n; i++)
			scanf("%d %d %d %d %d %d", &d[i].d0, &d[i].d1, &d[i].d2, &d[i].d3, &d[i].d4, &d[i].d5);
				for(i = 1; flg == 0&&i < n; i++) flg = DiceRoll(d, i);
					if(flg) { printf("No\n"); return 0;
			}
		printf("Yes\n");
	return 0;
}



/* DiseRoll??¢??°?????????????????????????????? */
int DiceRoll(DICE d[], int i){
	int j, l, iSum, jSum;

		for(j = 0; j < i; j++){
			iSum = d[i].d0 + d[i].d1 + d[i].d2 + d[i].d3 + d[i].d4 + d[i].d5;
			jSum = d[j].d0 + d[j].d1 + d[j].d2 + d[j].d3 + d[j].d4 + d[j].d5;
				if (jSum == iSum) {
				if (d[j].d5 == d[i].d0) Dice('N', d, j), Dice('N', d, j);
					else if(d[j].d1 == d[i].d0) Dice('N', d, j);
					else if(d[j].d4 == d[i].d0) Dice('S', d, j);
					else if(d[j].d2 == d[i].d0) Dice('W', d, j);
					else if(d[j].d3 == d[i].d0) Dice('E', d, j);
						if(d[j].d0 == d[i].d0) {
							for(l = 0; l < 4; l++) {
								if (d[j].d1 == d[i].d1)
								if (d[i].d2 == d[j].d2&&d[i].d3 == d[j].d3&&d[i].d4&&d[j].d4&&d[i].d5 == d[j].d5) 
							return 1;
						Dice('L', d, j);
					}
				}
			if(Count(d, i) >= 10 && Count(d, j) >= 10) return 1;
		}
	}
	return 0;
}



/* Dise??¢??°???????????????????????????????????? */
void Dice(char p, DICE d[], int n){
	int tmp;
		if(p == 'S') { tmp = d[n].d0; d[n].d0 = d[n].d4; d[n].d4 = d[n].d5; d[n].d5 = d[n].d1; d[n].d1 = tmp; }
		if(p == 'W') { tmp = d[n].d0; d[n].d0 = d[n].d2; d[n].d2 = d[n].d5; d[n].d5 = d[n].d3; d[n].d3 = tmp; }
		if(p == 'E') { tmp = d[n].d0; d[n].d0 = d[n].d3; d[n].d3 = d[n].d5; d[n].d5 = d[n].d2; d[n].d2 = tmp; }
		if(p == 'N') { tmp = d[n].d0; d[n].d0 = d[n].d1; d[n].d1 = d[n].d5; d[n].d5 = d[n].d4; d[n].d4 = tmp; }
		if(p == 'L') { tmp = d[n].d1; d[n].d1 = d[n].d3; d[n].d3 = d[n].d4; d[n].d4 = d[n].d2; d[n].d2 = tmp; }
}



/* Count??¢??°??????????????°???????????? */
int Count(DICE d[], int n){
	int cnt = 0;
		if(d[n].d0 == d[n].d1)++cnt;
		if(d[n].d0 == d[n].d2)++cnt;
		if(d[n].d0 == d[n].d3)++cnt;
		if(d[n].d0 == d[n].d4)++cnt;
		if(d[n].d0 == d[n].d5)++cnt;
		if(d[n].d1 == d[n].d2)++cnt;
		if(d[n].d1 == d[n].d3)++cnt;
		if(d[n].d1 == d[n].d4)++cnt;
		if(d[n].d1 == d[n].d5)++cnt;
		if(d[n].d2 == d[n].d3)++cnt;
		if(d[n].d2 == d[n].d4)++cnt;
		if(d[n].d2 == d[n].d5)++cnt;
		if(d[n].d3 == d[n].d4)++cnt;
		if(d[n].d3 == d[n].d5)++cnt;
		if(d[n].d4 == d[n].d5)++cnt;

	return cnt;
}

Measured memory_bytes: 584
#include <algorithm>
#include <iostream>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main(){
  int n, i, j=1;
  long long c=0;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++) cin >> a[i];

  sort(a, a + SIZE_OF_ARRAY(a), greater<>());

  c+=a[0];
  for(i=2;i<n;i++){
    c+=a[j];
    if (i%2 == 1) j++;
  }
  cout << c << endl;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define sf(n) scanf("%f",&n)
#define pf(n) printf("%.12f",n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 1e5 + 7; 
//const int md = 1e9 + 7;

int ok[maxn][2];
vector<int> G[maxn];

void dfs(int x) {
	for (int y : G[x]) {
		if (!ok[y][0] && !ok[y][1]) { ok[y][0] = ok[x][1]; ok[y][1] = ok[x][0]; dfs(y); }
		ok[x][0] |= ok[y][1]; ok[x][1] |= ok[y][0];
	}
}

int main() {
	int n,m; sd(n); sd(m);
	for (int i = 1; i <= n; i++) { ok[i][0] = ok[i][1] = false; }
	for (int i = 1; i <= m; i++) {
		int x,y; sd(x); sd(y);
		G[x].pb(y); G[y].pb(x);
	}
	ok[1][0] = true; dfs(1);
	ll a = 0, b = 0, c = 0;
	for (int i = 1; i <= n; i++) {
		if (ok[i][0]) a++;
		if (ok[i][1]) b++;
		if (ok[i][0] && ok[i][1]) c++;
	}
	ll N = n;
	pl(min(a*b - c,N*(N-1)/2) - m ); endc;
}

Measured memory_bytes: 7296
package main

import "fmt"

func main() {
	var M, N int
	fmt.Scan(&N, &M)

	as := make([]int, N)
	v := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&as[i])
		v += as[i]
	}

	l := float64(v) / float64(4*M)
	p := 0
	for i := 0; i < N; i++ {
		if l <= float64(as[i]) {
			p++
		}
		if p == M {
			fmt.Println("Yes")
			break
		}
	}
	if p < M {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(void){
    long long int a,b,k;
    scanf("%lld%lld%lld",&a,&b,&k);
    if(a+b-k<=0)
    printf("0 0");
    else if(a-k>=0)
    printf("%lld %lld",a-k,b);
    else if(a-k<0)
    printf("0 %lld",b+a-k);
    return 0;
}

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

int main() {
  vector<int> x(3);
  for (int i = 0; i < 3; i++)
  cin >> x.at(i);
  sort(x.begin(), x.end());
  cout << x.at(2) * 10 + x.at(0) + x.at(1) << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    pos = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    m, M = float("inf"), 0
    for x, y in pos:
        dist = x+y
        if m > dist:
            m = dist
        if M < dist:
            M = dist
    if ans < M-m:
        ans = M-m
    m, M = float("inf"), 0
    for x, y in pos:
        dist = (10**9 - x)+y
        if m > dist:
            m = dist
        if M < dist:
            M = dist
    if ans < M-m:
        ans = M-m
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 102460
N = gets.to_i
A = gets.split.map(&:to_i)
B = A.each_with_index.map{|v,i| v - (i + 1) }
B.sort!

def f(b)
  B.map{|v| (v - b).abs }.inject(&:+)
end

if N.even?
  b = (B[N/2] + B[N/2 - 1]) / 2
  puts [f(b), f(b + 1)].min
else
  b = B[N/2]
  puts f(b)
end


Measured memory_bytes: 21368
"use strict"
function main(arg) {
    arg = arg.trim().split("\n")[0].split('').sort()
    if (arg[0] == arg[1] && arg[2] == arg[3] && arg[0] != arg[3]) {
        console.log('Yes')
    } else {
        console.log('No')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
sa = input()
sb = input()
sc = input()
idx_a = idx_b = idx_c = 0
k = "a"
while True:
    if k == "a":
        if idx_a == len(sa):
            print("a".upper())
            exit()
        k = sa[idx_a]
        idx_a += 1
    elif k == "b":
        if idx_b == len(sb):
            print("b".upper())
            exit()
        k = sb[idx_b]
        idx_b += 1
    else:
        if idx_c == len(sc):
            print("c".upper())
            exit()
        k = sc[idx_c]
        idx_c += 1

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    double n,m;
    cin >> n>> m;
    vector<double>a(n);
    double sum =0;
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        sum+=a.at(i);
    }
    double che = sum/(4.00*m);
    for(int i=0;i<n;i++){
        if(a.at(i)>=che)m--;
      if(m==0){cout<<"Yes"<<endl; return 0;}
    }
cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  ll g ; cin >> g;
  REP(i,n-1){
      ll tmp ; cin >> tmp;
      g = gcd(g,tmp);
  }
  cout << g << endl;

}

Measured memory_bytes: 256
//
//

#include <bits/stdc++.h>

using namespace std;

#define llint long long int
#define REP(i,s,l) for(llint i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007


int main() {

    //AとBの公約数で上からK番目
    int numA,numB;
    int bigger;
    cin >> numA >> numB;
    int order;
    cin >> order;
    vector<int> kouyaku; //ベクトルの初期化。データ確保の場合はkouyaku(100)
    bool flug = false;

    for(int i=min(numA,numB);i >= 1; --i){
        if(numA%i == 0 && numB%i == 0){
            kouyaku.push_back(i);//末尾に追加する
        }
    }

    cout << kouyaku[ order-1 ] << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())

ans = 0
for a in range(1, N+1):
    cnt = 1
    while a*cnt<N:
        ans += 1
        cnt += 1

print(ans)

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

using namespace std;

#define MAX 110
#define INF (1<<29)
typedef pair<int, int> pii;

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

int main()
{
    int N, M, P;
    while (cin >> N >> M >> P, N) {
        int d[MAX][MAX];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = INF;
            }
            d[i][i] = 0;
        }
        
        vector<Edge> G[MAX];
        
        int a, b, c;
        for (int i = 0; i < M; i++) {
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            G[a].push_back(Edge(b, c));
            G[b].push_back(Edge(a, c));
        }

        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }

        priority_queue<pii> Q;
        Q.push(pii(d[0][N-1], N-1));
        
        vector<bool> visited(MAX, 0);
        visited[N-1] = 1;

        vector<double> cnt(MAX, 0);
        cnt[N-1] = 1;
        
        while (!Q.empty()) {
            pii p = Q.top(); Q.pop();
            int v = p.second;
            for (int i = 0; i < (int)G[v].size(); i++) {
                Edge &e = G[v][i];
                if (d[0][e.to] + e.cost == d[0][v]) {
                    cnt[e.to] += cnt[v];
                    if (!visited[e.to]) {
                        visited[e.to] = 1;
                        Q.push(pii(d[0][e.to], e.to));
                    }
                }
            }
        }

        priority_queue<pii, vector<pii>, greater<pii>> Q2;
        Q2.push(pii(0, 0));

        vector<bool> visited2(MAX, 0);
        visited2[0] = 1;

        double dp[MAX] = {};
        dp[0] = 1;
        
        while (!Q2.empty()) {
            pii p = Q2.top(); Q2.pop();
            int v = p.second;
            for (int i = 0; i < (int)G[v].size(); i++) {
                Edge &e = G[v][i];
                if (visited[e.to] && d[0][v] + e.cost == d[0][e.to]) {
                    dp[e.to] += dp[v] * cnt[e.to] / cnt[v];                    
                    if (!visited2[e.to]) {
                        visited2[e.to] = 1;
                        Q2.push(pii(d[0][e.to], e.to));
                    }
                }
            }
        }

        int child;
        for (int i = 0; i < P; i++) {
            cin >> child;
            printf("%.10f\n", dp[child]);            
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3304