akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
  if (i > j) swap(i, j);
  return id[i][j];
}

bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];  // max length of path from v
int dfs(int v) {
  if (visited[v]) {
    if (!calculated[v]) return -1;
    return dp[v];
  }
  visited[v] = true;
  dp[v] = 1;
  for (int u : to[v]) {
    int res = dfs(u);
    if (res == -1) return -1;
    dp[v] = max(dp[v], res + 1);
  }
  calculated[v] = true;
  return dp[v];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> a(N, vector<int>(N - 1));
  for (int i = 0; i < N; i++) {
    for (auto &v : a[i]) {
      cin >> v;
      v--;  // i -> i-1
    }
  }

  int V = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i < j) {
        id[i][j] = V++;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - 1; j++) {
      a[i][j] = toId(i, a[i][j]);
    }
    for (int j = 0; j < N - 2; j++) {
      to[a[i][j + 1]].push_back(a[i][j]);
    }
  }

  int ans = 0;
  for (int i = 0; i < V; i++) {
    int res = dfs(i);
    if (res == -1) {
      puts("-1");
      return 0;
    }
    ans = max(ans, dfs(i));
  }

  cout << ans << endl;

  return 0;

  // cin.tie(0);
  // ios::sync_with_stdio(false);
  // int N;
  // cin >> N;
  // vector<vector<int>> a(N, vector<int>(N - 1));
  // for (int i = 0; i < N; i++) {
  //   for (auto &v : a[i]) {
  //     cin >> v;
  //     v--;  // i -> i-1
  //   }
  //   reverse(a[i].begin(), a[i].end());
  // }

  // vector<pair<int, int>> que;
  // auto check = [&](int i) {
  //   if (a[i].size() == 0) return;
  //   int j = a[i].back();
  //   if (a[j].size() == 0) return;
  //   if (a[j].back() == i) {
  //     pair<int, int> p(i, j);
  //     if (p.second < p.first) swap(p.first, p.second);
  //     que.push_back(p);
  //   }
  // };

  // for (int i = 0; i < N; i++) {
  //   check(i);
  // }

  // int day = 0;
  // while (que.size() > 0) {
  //   day++;
  //   sort(que.begin(), que.end());
  //   que.erase(unique(que.begin(), que.end()), que.end());
  //   vector<pair<int, int>> prevQ;
  //   swap(prevQ, que);
  //   for (auto &p : prevQ) {
  //     int i = p.first, j = p.second;
  //     a[i].pop_back();
  //     a[j].pop_back();
  //   }
  //   for (auto &p : prevQ) {
  //     int i = p.first, j = p.second;
  //     check(i);
  //     check(j);
  //   }
  // }
  // for (int i = 0; i < N; i++) {
  //   if (a[i].size() != 0) {
  //     puts("-1");
  //     return 0;
  //   }
  // }
  // cout << day << endl;
  // return 0;
}


Measured memory_bytes: 38528
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if (B + C < A) {
      System.out.println(0);
    } else {
      System.out.println(C - (A - B)); 
    }
  }
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007



const int N=100001;
vector<int>g[N];
ll dp[N][2];


ll solve(ll src,ll par,ll tight)
{
	if(dp[src][tight]!=-1)
	{
		return(dp[src][tight]);
	}
	if(tight==1)
	{
		ll ans=1;
		ll f=0;
		for(auto x:g[src])
		{
			if(x!=par)
			{
				f=1;
				ll p=solve(x,src,0);
				ans=(ans*p)%mod;
			}
		}
		return(dp[src][tight]=ans);
	}
	else
	{
		ll ans1=1;
		ll f=0;
		for(auto x:g[src])
		{
			if(x!=par)
			{
				f=1;
				ll p=solve(x,src,1);
				ans1=(ans1*p)%mod;
			}
		}
		ll ans2=1;
		for(auto x:g[src])
		{
			if(x!=par)
			{
				ll p=solve(x,src,0);
				ans2=(ans2*p)%mod;
			}
		}
		ans1=(ans1+ans2)%mod;
		return(dp[src][tight]=(ans1)%mod);
	}
}

int main()
{
	ll n,i;
	cin>>n;
	ll x,y;
	memset(dp,-1,sizeof(dp));
	for(i=0;i<n-1;i++)
	{
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	ll ans1=solve(1,-1,0);
	cout<<ans1<<"\n";
}

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

#define deb(x) cout << #x << "=" << x << endl;
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fo1(i, n) for (ll i = 1; i <= n; i++)
#define sn(x) cin >> x;
#define pn(x) cout << x << "\n"
#define ps(x) cout << x << " ";
#define pb() cout << "\n";
#define sort(x) sort(x.rbegin(), x.rend());
// #define reverse_sort(x) sort(x.rbegin(), x.rend());
// #define reverse(x) reverse(x.rbegin(), x.rend());

typedef long long ll;

using namespace std;


void solve()
{

	string str;
	sn(str);
	
	ll sum = 0;

	fo(i,str.size())
		sum+=str[i]-'0';

		

	 sum%9 ? cout <<"No\n" : cout << "Yes\n";



}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("err.txt", "w", stderr);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// return 0;

	ll t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
		// cout << ans;
	}
	return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long int
#define FILEIO  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
#define maxn 1000000
 

using namespace std;

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

signed main() {
//FILEIO;
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int a;
cin>>a;
cout<<a+(a*a)+(a*a*a);










    return 0;
}


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

int main(){
  ll l;
  cin >> l;
  double a,b,c;
  double ans=-1;
  if(l%3==0){
    a=l/3;
    ans=a*a*a;
  }else if(l%3==1){
    a=(double)l/3;
    b=(double)l/3;
    c=(double)l/3;
    ans=a*b*c;
  }else{
    a=(double)l/3;
    b=(double)l/3;
    c=(double)l/3;
    ans=a*b*c;
  }
  printf("%.10lf\n",(double)ans);
  return 0;
}


Measured memory_bytes: 256
/**********************
 * Author: Cloud_     *
 * Date:   27.06.2020 * 
 * Time:   17.56.57   *
 *                    *
***********************/
#include <bits/stdc++.h>
using namespace std;

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

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

const int N=100009;
int ar[300],br[300];
int main()
{
  //fastio; 
  string s,t;
  int i,j,len,ans=0;

   cin>>s>>t;
   len=s.size();
   

   for(i=0; i<len; i++)
   {
   	 if(s[i]!=t[i]) ans++;
   }
   cout<<ans<<endl;
  return 0;
}

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

#define forn(i,n) for(int i = 0; i < n; i++)
vector<int> edges[200010];
long long ans[200010];
long long bucket[200010];

void dfs(int node, int prev, long long val = 0){
	val+= bucket[node];
	ans[node] = val;
	for(auto& x : edges[node]){
		if(prev-x){
			dfs(x, node, val);
		}
	}
}

int main(){
	int n, q;
	int a,b;
	cin >> n >> q;
	forn(i,n-1){
		cin >> a >> b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	forn(i,q){
		cin >> a >> b;
		bucket[a]+=b;
	}
	dfs(1, -1);
	
	forn(i,n){ cout << ans[i+1] << " "; }
	
	cout << endl;

  return 0;
}


Measured memory_bytes: 25600
from sys import stdin, stdout
import math
import bisect
import queue

k = int(stdin.readline().strip())
a, b = map(int, stdin.readline().strip().split())

flag = 0

for i in range(a, b + 1):
    if i % k == 0:
        flag = 1
        break

stdout.writelines('OK\n' if flag == 1 else 'NG\n')


Measured memory_bytes: 68776
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
    int n;
    cin >> n;
    double sum = 0;
    for(int i=0; i<n; i++) {
        double x;
        string s;
        cin >> x >> s;
        if(s == "JPY") {
            sum += x;
        } else {
            sum += x * 380000.0;
        }
    }
    cout << sum << endl;
}


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

int a, b;

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

    cin >> a >> b;
    cout << (a + b - 1) / b << el;

    return 0;
}

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

struct Road{
  vector<long long> par;

  Road(int n){
    par.assign(n,-1);
  }

  void unite(long long x, long long y){
    x=root(x);y=root(y);
    if(x==y) return;

    if(par[x]>par[y]){
      swap(x,y);
    }
    par[x]+=par[y];
    par[y]=x;
  }

  long long root(long long x){
    if(par[x]<0){
      return x;
    }else{
      return par[x]=root(par[x]);
    }
  }

};

struct Railway{
  vector<long long> par;

  Railway(int n){
    par.assign(n,-1);
  }

  void unite(long long x, long long y){
    x=root(x);y=root(y);
    if(x==y) return;

    if(par[x]>par[y]){
      swap(x,y);
    }
    par[x]+=par[y];
    par[y]=x;
  }

  long long root(long long x){
    if(par[x]<0){
      return x;
    }else{
      return par[x]=root(par[x]);
    }
  }

};

int main(){
  long long n,k,q,a,b;
  cin >> n >> k >> q;
  Road road(n);
  Railway railway(n);
  for(int i=0;i<k;i++){
    cin >> a >> b;
    a--;b--;
    road.unite(a,b);
  }
  for(int i=0;i<q;i++){
    cin >> a >> b;
    a--;b--;
    railway.unite(a,b);
  }

  pair<long long, pair<long long, long long> > p[n];
  long long cmp[n]={},ans[n]={},cnt=0,ro,ra;

  for(long long i=0;i<n;i++){
    p[i]=make_pair(road.root(i), make_pair(railway.root(i), i) );
  }
  sort(p,p+n);
  ro=p[0].first;
  ra=p[0].second.first;
  for(long long i=0;i<n;i++){
    if(ro==p[i].first and ra==p[i].second.first){
      cnt++;
    }else{
      cmp[i-1]=cnt;
      cnt=1;
      ro=p[i].first;
      ra=p[i].second.first;
    }
  }
  long long tmp=cmp[n-1]=cnt;
  long long cntt=0;
  for(long long i=n-1;i>=0;i--){
    if(cntt==tmp){
      cntt=0;
      tmp=cmp[i];
    }
    ans[p[i].second.second]=tmp;
    cntt++;
  }

  for(long long i=0;i<n;i++){
    cout << ans[i] << ((i==n-1)?"\n":" ");
  }
  return 0;
}


Measured memory_bytes: 11520
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    int a[200];
    for(int i=0;i<2*n;i++){
        cin>>a[i];
    }
    sort(a,a+2*n);
    for(int i=0;i<2*n;i++){
        if(i%2==0) ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int r,g,b,a[3],n;
    int ans=0;
    cin >>a[0]>>a[1]>>a[2]>>n;
    vector<int> vx(a,a+3);
    sort(vx.begin(),vx.end());

    for (int i = 0; i <= n/vx[2]; i++){
        for (int j = 0; j <= n/vx[1]; j++){
            if((n-(i*vx[2]+j*vx[1])) % vx[0] == 0 && (n>=(i*vx[2]+j*vx[1])) )ans++;
        }
    }
    
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
N,W=map(int,raw_input().split())
vw=[map(int,raw_input().split()) for i in xrange(N)]
dp=[[0]*(W+1) for _ in xrange(N+1)]
for i in xrange(N):
    for j in xrange(W+1):
        if vw[i][1]>j:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=max(dp[i][j],dp[i+1][j-vw[i][1]]+vw[i][0])
print(dp[N][W])

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

int main(){
  int a,b;scanf("%d%d",&a,&b);
  double ret=0;
  for(int i=1;i<=a;i++){
    double tmp=1.0/a;
    int now=i;
    while(now<b){
      now*=2;
      tmp/=2;
    }
    ret+=tmp;
  }
  printf("%.12f\n",ret);
}


Measured memory_bytes: 3764
import sys

def func(h, w):
  ans = sys.maxsize
  h3 = h // 3
  fragments = []
  fragments.append(h3*w)

  if w % 2 == 0:
    fragments.append((h-h3) * w//2)
  else:
    fragments.append((h-h3) * w//2)
    fragments.append((h-h3) * (w//2 + 1))
    
  ans = min(ans, max(fragments) - min(fragments)) 
  
  h3 += 1
  fragments = []
  fragments.append(h3*w)
  if w % 2 == 0:
    fragments.append((h-h3) * w//2)
  else:
    fragments.append((h-h3) * (w//2))
    fragments.append((h-h3) * (w//2 + 1))
    
  ans = min(ans, max(fragments) - min(fragments))
  
  return ans
  

h,w = map(int, input().split())

# hかwが3で割り切れる場合は0
if h % 3 == 0 or w % 3 == 0:
  print(0)
  sys.exit()

# 縦に2回割る場合はhが差分、横に2回割る場合はwが差分となるので小さい方が正解候補
ans = min(w, h)

# 横1回,縦1回で割る場合
ans = min(func(h,w), func(w,h), ans)

print(ans)

Measured memory_bytes: 61980
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

string alphabets = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int i;
    char c;
    cin >> c;
    if(c=='z'){
        cout<< 'a';
    }else{
        for(i = 0;;++i){
            if(c==alphabets[i])
               {

                cout << alphabets[i+1];
                break;
               }
        }
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		sc.close();
		int a = H * W;
		int b = h * W;
		int c = w * H;
		int d = h * w;
		System.out.println(a - b - c + d);
	}

}


Measured memory_bytes: 22996
local function lltonumber(str)
  local ret = 0LL
  local sign = str:sub(1, 1) ~= "-"
  local begin = sign and 1 or 2
  for i = begin, #str do
    ret = ret * 10LL
    ret = ret + tonumber(str:sub(i, i))
  end
  if not sign then ret = ret * -1LL end
  return ret
end

local function llprint(llnumber)
  local str = tostring(llnumber):gsub("LL", "")
  print(str)
end

local str = io.read()
local n, kstr = str:match("(%d+) (%d+)")
n = tonumber(n)
local k = lltonumber(kstr)
local a, f = {}, {}
local asum = 0LL
for i = 1, n do
  a[i] = 0LL + io.read("*n")
  asum = asum + a[i]
end
for i = 1, n do
  f[i] = 0LL + io.read("*n")
end
table.sort(a)
table.sort(f, function(x, y) return x > y end)
if asum <= k then
  print(0)
else
  local function solve(x)
    local cnt = 0LL
    for i = 1, n do
      local c = x / f[i]
      if c < a[i] then
        cnt = cnt + a[i] - c
      end
    end
    return cnt <= k
  end
  local min = 0LL
  local max = a[1] * f[1]
  for i = 2, n do
    if max < a[i] * f[i] then max = a[i] * f[i] end
  end
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  llprint(max)
end


Measured memory_bytes: 39668
h,w=map(int,input().split())
s=list(input()for _ in[0]*h)
a=[0]*h
b=[0]*w
for i in range(h):
    f=0
    for j in range(w):f+=s[i][j]=='#'
    a[i]=f>0
for j in range(w):
    f=0
    for i in range(h):f+=s[i][j]=='#'
    b[j]=f>0
for i in range(h):
    if not a[i]:continue
    for j in range(w):
        if b[j]:print(s[i][j],end='')
    print()


Measured memory_bytes: 4468
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define lca long long
using namespace std;

const int MX = 1005 ;

int h, n, a[MX], b[MX];
int f[MX][MX*20];


int main()
{
    scanf("%d%d", &h, &n);
    for(int i=0;i<=n;i++) 
        for(int j=1;j<=20000;j++) 
            f[i][j] = 1000000000;
    for(int i=0;i<=n;i++) f[i][0] = 0;
    for(int i=1;i<=n;i++)   scanf("%d%d", &a[i], &b[i]);
    for(int i=1;i<=n;i++) 
        for(int j=0;j<=20000;j++)
        {
            if(j>=a[i])
                f[i][j] = min(f[i-1][j], min(f[i][j-a[i]] + b[i], f[i-1][j-a[i]] + b[i]));
            else
                f[i][j] = f[i-1][j];
        }
            
    for(int i=h+1;i<=20000;i++)   f[n][h] = min(f[n][h], f[n][i]);
    cout<<f[n][h]<<endl;
}

Measured memory_bytes: 78848
N,K=map(int,input().split())
x=[int(i) for i in input().split()]
ans=10**9
A=[]
B=[]
for i in range(N):
    if x[i]>=0:
        A.append(x[i])
    else:
        B.append(-x[i])
B=B[::-1]
if len(A)>=K:
    ans=min([ans,A[K-1]])
if len(B)>=K:
    ans=min([ans,B[K-1]])
C=len(A)
D=len(B)
for i in range(1,K):
    if ((i-1)<C) and ((K-i-1)<D):
        tmp1=A[i-1]+2*B[K-i-1]
        tmp2=2*A[i-1]+B[K-i-1]
        ans=min([ans,tmp1,tmp2])
print(ans)


Measured memory_bytes: 14844
#include<iostream>

int main(){
    int A, B;
    std::cin >> A >> B;
    if(A == 1) A = 14;
    if(B == 1) B = 14;
    if(A < B) std::cout << "Bob" << std::endl;
    else if(A > B) std::cout << "Alice" << std::endl;
    else std::cout << "Draw" << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws ClassNotFoundException, IOException {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<Integer>();
		for(int i =0; i < N; i++) {
			W.add(sc.nextInt());
		}
		int sum = W.stream().mapToInt(x -> x).sum();
		int pre = 0;
		int post = 0;
		int answer = -1;
		boolean flag = true;
		for(int w : W) {
			pre += w;
			post = sum - pre;

			if(flag) {
				answer = Math.abs(post - pre);
				flag = false;
			}else {
				if(answer > Math.abs(post - pre)) {
					answer = Math.abs(post - pre);
				}
			}
		}

		System.out.println(answer);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 26580
#include<iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
int main()
{
	long long A, B, C, i, j, a, b, c;


	cin >> A;
	cin >> B;
	cin >> C;

	if (A > B) {
		i = A;
		A = B;
		B = i;
	}
	if (B > C) {
		i = B;
		B = C;
		C = i;
	}
	if (A > B) {
		i = A;
		A = B;
		B = i;
	}

	if ((B - A) % 2 == 0) {
		cout << (B - A) / 2 + (C - B);
	}
	else {
		cout << (B - A) / 2 + (C - B) + 2;
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int x,a,b;
	cin>>x>>a>>b;
	x -= a;
	x = x-(x/b)*b;
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ll x[4] = {1,0,-1,0};
ll y[4] = {0,1,0,-1};

int main(){
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i,H){
        cin >> S[i];
    }
    Pll p = Pll(-1,-1);
    vector<vector<ll>> memo(H, vector<ll>(W));
    ll ind = 0;
    map<ll,ll> mp;
    vector<ll> v;
    v.push_back(0);
    rep(i,H){
        rep(j,W){
            if(S[i][j] == '#'){
                if(memo[i][j] > 0){
                    mp[memo[i][j]]++;  
                    continue;
                }
                ll tot = 0;
                ind++;
                p = Pll(i,j);
                queue<Pll> que;
                que.push(p);
                while(!que.empty()){
                    auto t = que.front();
                    ll h = t.first;
                    ll w = t.second;
                    que.pop();
                    if(!(0 <= h && h <= H-1)) continue;
                    if(!(0 <= w && w <= W-1)) continue;
                    if(memo[h][w] != 0)continue;
                    if(S[h][w] == '.')tot++;
                    memo[h][w] = ind;
                    rep(k,4){
                        ll Y = h+y[k];
                        ll X = w+x[k];
                        if(!(0 <= Y && Y <= H-1)) continue;
                        if(!(0 <= X && X <= W-1)) continue;
                        if(memo[Y][X] != 0)continue;
                        if(S[h][w] == S[Y][X]) continue;
                        que.push(Pll(Y,X));
                    }
                }
                mp[memo[i][j]]++;
                v.push_back(tot);
            }
        }
    }
    ll ans = 0;
    for(auto& e:mp){
        ans += v[e.first]*e.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11764
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;

int main() {
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int idx;
    cin >> idx;
    cout << a[idx - 1];
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> S(M);
    vector<char> C(M);
    rep(i, 0, M) {
        cin >> S[i] >> C[i];
    }
    rep(val, 0, 1000) {
        string s = to_string(val);
        if ((int)s.size() != N) {
            continue;
        }
        bool is_ok = true;
        rep(i, 0, M) {
            if (s[S[i] - 1] != C[i]) {
                is_ok = false;
            }
        }
        if (is_ok) {
            cout << val << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

const string T = "keyence";
const uint64_t L = T.size();

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

  uint64_t N = S.size();
  auto substr_eq = [&] (uint64_t n) {
    uint64_t j = 0, m = N - (L - n);

    for (uint64_t i = 0; i < n && j < L; ++i, ++j) {
      if (S[i] != T[j]) { return false; }
    }

    for (uint64_t i = m; i < N && j < L; ++i, ++j) {
      if (S[i] != T[j]) { return false; }
    }

    return true;
  };

  bool flag = false;
  N_TIMES(n, L + 1) {
    flag |= substr_eq(n);
  }
  cout << (flag ? "YES" : "NO") << endl;

  return 0;
}

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

int main(void){

int N;

cin >> N;


int p[N];
int max=0;
int sum=0;

for (int n=0;n<N;n=n+1) {
    cin >> p[n];
    if (max<p[n]) max=p[n];
    sum=sum+p[n];
}

cout << sum-max/2<<endl;

}


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

const int N = 1000000;
int dp[2][N+1];

int main(){
  for(int i=0;i<=N;i++)dp[0][i] = dp[1][i] = N;
  dp[0][0] = dp[1][0] = 0;

  int val = 1;
  for(int i=2;val<=1000000;i++){
    for(int j=0;j+val<=1000000;j++){
      dp[0][j+val] = min(dp[0][j+val],dp[0][j] + 1);
      if(val&1)dp[1][j+val] = min(dp[1][j+val],dp[1][j] + 1);
    }
    val = i*(i+1)*(i+2)/6;
  }

  int n;
  while(cin >> n,n)cout << dp[0][n] << " " << dp[1][n] << endl;
}

Measured memory_bytes: 8968
#include<bits/stdc++.h>
using namespace std;
using LL = unsigned long long;
constexpr int maxn = 200;
LL A[maxn];
char S[maxn + 1];
LL B[60];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T;
    for(cin >> T; T; T -= 1){
        int N;
        cin >> N;
        for(int i = 0; i < N; i += 1) cin >> A[i];
        cin >> S;
        int ok = 0;
        for(int i = 0; i < N; i += 1)if(S[i] == '1'){
            for(int j = 0 ; j < 60; j += 1) B[j] = 0;
            for(int j = i + 1; j < N; j += 1) if(S[j] == '0'){
                LL x = A[j];
                int b = -1;
                for(int k = 59; k >= 0; k -= 1) if(x & (1ULL << k)){
                    if(B[k]) x ^= B[k];
                    else{
                        b = k;
                        break;
                    }
                }
                if(b == -1) continue;
                B[b] = x;
                for(int k = b + 1; k < 60; k += 1) if((B[k] ^ x) < B[k]) B[k] ^= x;
            }
            LL x = A[i];
            for(int j = 59; j >= 0; j -= 1) if((x ^ B[j]) < x) x ^= B[j];
            if(x){
                ok = 1;
                break;
            }
        }
        cout << ok << "\n";
    }
    return 0;
}


Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int a,b;
  cin >> a >> b;
  
  int r=0,f=0;
  for(r=0;r<1300;r++){
    if(a==r*8/100 && b==r*10/100){
      f=1;
      break;
    }
  }
  if(f==0) cout << -1 << endl;
  else cout << r << endl;

  return 0;
}


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

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

#define INF 1000000000000000000

typedef long long LL;


struct person{
  LL h;
  LL p;
  bool operator<(const struct person & right) const{
    return (h+p<right.h+right.p);
  }
};

int main(){
  int n;
  cin >> n;
  vector<struct person> san(n);
  vector<LL> dp(n+1,INF);
  dp[0]=0;
  for(int i=0;i<n;i++){
    cin >> san[i].h >> san[i].p;
  }
  sort(san.begin(),san.end());
  for(int i=0;i<n;i++){
    for(int j=n;j>0;j--){
      if(dp[j-1]<=san[i].h) dp[j]=min(dp[j],dp[j-1]+san[i].p);
    }
    // for(int j=0;j<=n;j++){
    //   cout << dp[j] << " ";
    // }
    // cout << endl;
  }
  for(int i=n;i>=0;i--){
    if(dp[i]!=INF){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 384
s = list(map(str,input()))
ans = ""
count = 0
for i in s:
    if i == "0":
        ans += "0"
        count += 1
    elif i == "1":
        ans += "1"
        count += 1
    else:
        if count == 0 :
            continue
        else:
            ans = ans[:-1]
            count+=1
print(ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> l;
    for(int i=0;i<n;i++){
        int ll;
        cin >> ll;
        l.push_back(-ll);
    }
    sort(l.begin(),l.end());
    for(int i=0;i<n;i++){
        l[i]=-l[i];
    }
    //----
    long long ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]<l[j]+l[k]){ans++;}
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long

int N;
double p[3333]; // コインの表が出る確率
double dp[3333][3333];

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }

  dp[0][0] = 1; // DPテーブルを初期化
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i + j > N) continue;
      // おもて
      dp[i+1][j] += dp[i][j] * p[i+j];
      // うら
      dp[i][j+1] += dp[i][j] * (1 - p[i+j]);
    }
  }

  double ans = 0;
  for (int i = N/2 +1; i <=N; i++) {
    int j = N - i;
    ans += dp[i][j];
  }

  printf("%.10f\n", ans);

  return 0;
}

Measured memory_bytes: 80128
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	memo := make(map[int]int)
	x := a
	for true {
		y := x % b
		if y == c {
			fmt.Println("YES")
			return
		}
		_, ok := memo[y]
		if ok {
			break
		}
		memo[y] = 1
		x += a
	}
	fmt.Println("NO")
}

Measured memory_bytes: 512
#include <stdio.h>
#define ll long long int
using namespace std;

const ll md=1000000007;

ll power(ll b, ll p, ll m)
{
    ll d;
    if(p==0)
        return 1;
    d=power(b, p/2, m);
    if(p%2==0)
        return (d%m*d%m)%m;
    else
        return (b%m*(d%m*d%m)%m)%m;
}

int main()
{
    ll a, b, d;
    scanf("%lld %lld", &a, &b);
    d=power(a, b, md);
    printf("%lld\n", d);
    return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main(){
  int N; cin >> N;
  
  double sum = 0;
  rep(i, N){
    double x;
    string u;
    cin >> x >> u;
    if(u == "JPY") sum += x;
    if(u == "BTC") sum += x * 380000;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cassert>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
int N;

struct P
{
  int x,y,type;
  P(int x = -1,int y = -1,int type = -1):x(x),y(y),type(type){}
};
int SMLx[3][12] = {{0,0,1,-1},{1,2,2,2,1,1,0,0},{0,0,0,0,1,1,1,2,-1,-1,-1,-2}};
int SMLy[3][12] = {{1,2,1,1},{0,0,1,2,1,2,1,2},{1,2,3,4,1,2,3,2,1,2,3,2}};
int SML[] = {4,8,12};
bool F;
int Cx[] = {0,1,0};
int Cy[] = {1,1,2};

void print(const VVI& G)
{
  cout << "print---" << endl;
  for(int i=0;i<10;i++)
    {
      for(int j=0;j<10;j++)
	{
	  cout << G[i][j] << " ";
	}
      cout << endl;
    }
  cout << endl;
}

bool check(VVI& G,int x,int y,int type)
{
  G[y][x]--;
  for(int i=0;i<SML[type];i++)
    {
      int nx = x + SMLx[type][i];
      int ny = y + SMLy[type][i];
      if(!(0 <= nx && nx < 10 && 0 <= ny && ny < 10) || G[ny][nx] <= 0)
	{
	  G[y][x]++;
	  for(int j=i-1;j>=0;j--)
	    {
	      nx = x + SMLx[type][j];
	      ny = y + SMLy[type][j];
	      G[ny][nx]++;
	    }
	  return false;
	}
      G[ny][nx]--;
    }
  return true;
}

void draw(VVI& G,int x,int y,int type)
{
  G[y][x]++;
  for(int i=0;i<SML[type];i++)
    {
      int nx = x + SMLx[type][i];
      int ny = y + SMLy[type][i];
      if(!(0 <= nx && nx < 10 && 0 <= ny && ny < 10))
	assert(false);	 	
      G[ny][nx]++;
    }
}


void dfs(VVI& G,int x,int y,int cnt,vector<P> perm)
{
  if(cnt > N)
    return;
    if(F)
    return;
      
  perm.push_back(P(-1,-1,-1));
  for(int i=y;i<10;i++)
    for(int j= (i == y?x:0);j<10;j++)
      if(G[i][j] >= 1)
	{
	  bool found = false;
	  for(int k=0;k<3;k++)
	    {
	      if(!check(G,j,i,k))
		continue;
	      perm[perm.size()-1] = P(j+Cx[k],i+Cy[k],k+1);
	      dfs(G,j,i,cnt+1,perm);
	      draw(G,j,i,k);
	    }
	  return;
	}


  if(cnt == N  && !F)
    {
      for(int i=0;i<N;i++)
	{
	  cout << perm[i].x << " " << perm[i].y << " " << perm[i].type << endl; 
	}      
      assert(!F);
      F = true;
    }
}

int main()
{
  F = false;
  cin >> N;
  assert(N <= 12);
  VVI G(10,VI(10));

  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      cin >> G[i][j];
  dfs(G,0,0,0,vector<P>());
  assert(F);
  return 0;
}

/*
-- output --
3 2 1
8 4 2
1 1 2
5 2 3
8 1 2
1 4 2
3 6 3
6 6 3
1 8 2

-- input --
9
1 1 1 0 0 1 0 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 2 2 2 1 1 2 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1 1
1 1 2 1 1 1 1 2 1 1
0 1 1 1 2 2 1 1 1 0
1 1 2 1 1 1 1 1 0 0
1 1 1 1 0 0 1 0 0 0
1 1 1 0 0 0 0 0 0 0

*/

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int L[100005];
int R[100005];
int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	ll N,M;
	cin >> N >> M;
	for (ll i = 0; i < M;i++)
	{
		cin >> L[i] >> R[i];
	}
	ll left = 1, right = N;
	for (ll i = 0; i < M; i++)
	{
		if (left < L[i])
		{
			left = L[i];
		}
		if (right > R[i])
		{
			right = R[i];
		}
	}
	ll sum;
	if (left > right)
	{
		sum = 0;
	}
	else
	{
		sum = right - left + 1;
	}
		cout << sum << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int m, d,t,t2,count=0;
	cin >> m >> d;
	for (int i = 1; i <= m; i++) {
		for (int j = 22; j <= d; j++) {
			t = j % 10;
			t2 = j /10;
			if (t*t2 == i&&t>=2&&t2>=2) {
				//cout << m <<" "<<t2<<" "<<t << endl;
				count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder_問題5_B2問目
{
    class Program
    {
        static void Main(string[] args)
        {
            //問題5
            //入力を受け取る
            string[] input = Console.ReadLine().Split(' ');
            int a = Convert.ToInt32(input[0]);
            int b = Convert.ToInt32(input[1]);
            int sum = 0;
            for (int c = a; c <= b; ++c)
            {
                string d = Convert.ToString(c);
                int num = c;
                int rev = 0;
                while (num > 0)
                {
                    rev = rev * 10 + num % 10;
                    num /= 10;
                }
                string revstr = rev.ToString();
                bool check = d.Contains(revstr);
                int ok = c - Convert.ToInt32(revstr);
                if (check)
                {
                    if (ok == 0)
                    {
                        sum = sum + 1;
                    }
                }
            }
            Console.WriteLine(sum);
            
        }
    }
}



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

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

    if ((a * b) % 2 == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }

    return 0;
}

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

int main(void) {
	int n;
	cin >> n;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}
	int ans = 1e9;
	for (int i = 0; i < n; i++) {
		int l = 0, r = 0;
		for (int j = 0; j < i; j++) l += w[j];
		for (int j = i; j < n; j++) r += w[j]; 
		ans = min(ans, abs(l - r));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
    int N,T;
    cin >> N >> T;
    int c,t;
    int ans = 1000000;
    bool flag = false;
    for(int i=0;i<N;i++){
        cin >> c >> t;
        if(t<=T){
            if(c<ans){
                ans = c;
                flag = true;
            }
        }
    }
    if(flag == true){
    cout << ans << endl;
    }else{
    cout << "TLE" << endl;    
    }
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int Left[200005], Right[200005], p[200005];
int main()
{
    int n, k;
    cin >> n >> k;
    int neg = 0, pos = 0, zero = 0, zeroposition;
    for ( int i = 0; i <= n-1; i++ )
    {
        cin >> p[i];
        if ( p[i] < 0 )
        {
            neg++;
        }
        if ( p[i] == 0 )
        {
            zero++;
            zeroposition = i;
        }
        if ( p[i] > 0 )
        {
            pos++;
        }
    }
    if ( k == 1 && zero == 1 )
    {
        cout << 0;
        return 0;
    }
    else if ( zero == 1 )
    {
        k--;
        n--;
        for ( int i = zeroposition; i <= n; i++ )
        {
            p[i] = p[i + 1];
        }
    }
    int leftmost, rightmost, leftleast, rightleast;
    if ( neg < k )
    {
        leftmost = 0;
        rightleast = k-1;
    }
    else
    {
        leftmost = neg-k;
        rightleast = neg;
    }
    if ( pos < k )
    {
        rightmost = n-1;
        leftleast = neg - ( k - pos );
    }
    else
    {
        rightmost = neg+k-1;
        leftleast = neg-1;
    }
    for ( int i = 0; i <= leftleast - leftmost; i++ )
    {
        if ( neg >= k && i == 0 )
        {
            Left[0] = 0 - p[neg - k];
        }
        else
        {
            Left[i] = p[neg + k - (neg - (leftmost + i)) - 1] - p[leftmost + i] * 2;
        }
    }
    for ( int i = 0; i <= rightmost - rightleast; i++ )
    {
        if ( pos >= k && i == 0 )
        {
            Right[0] = p[neg + k - 1];
        }
        else
        {
            Right[i] = p[rightmost - i] * 2 - p[rightmost - k - i + 1];
        }
    }
    int min = 1000000000;
    for ( int i = 0; i <= leftleast - leftmost; i++ )
    {
        if ( Left[i] <= min && Left[i] > 0 )
        {
            min = Left[i];
        }
    }
    for ( int i = 0; i <= rightmost - rightleast; i++ )
    {
        if ( Right[i] <= min && Right[i] > 0 )
        {
            min = Right[i];
        }
    }
    cout << min;
}

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

using namespace std;

int main(){
	long long int N;
	cin >> N;
	string S;
	cin >> S;
	vector<long long int>W(N + 2), E(N + 2);
	for( size_t i = 0; i < N; i++ ){
		E[i + 1] += E[i];
		if( S[i] == 'W' ){
			E[i + 1]++;
		}
	}
	for( int i = N - 1; i >= 0; i-- ){
		W[i + 1] += W[i + 2];
		if( S[i] == 'E' ){
			W[i + 1]++;
		}
	}
	long long int ans = 1LL << 60;
	for( size_t i = 1; i <= N; i++ ){
		ans = min(ans, W[i + 1] + E[i - 1]);
	}
	cout << ans << endl;
}


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

enum State {
    EQUAL, LOWER, STATE_NUM
};

int64_t K;
string N;

vector<vector<vector<int64_t>>> memo;

//左からi桁目まで見た時、0でない数字がj個であり、Nに対する大小関係がsである場合の数
int64_t solve(int64_t i, int64_t j, State s) {
    if (i == N.size()) {
        return j == K;
    }

    if (j > K) {
        return 0;
    }

    if (memo[i][j][s] != -1) {
        return memo[i][j][s];
    }

    if (s == EQUAL) {
        //この桁をNと等しくする
        int64_t eq = solve(i + 1, j + (N[i] != '0'), EQUAL);

        //この桁をNとは異なるようにする
        int64_t lo = 0;
        for (int64_t d = 0; d < N[i] - '0'; d++) {
            lo += solve(i + 1, j + (d != 0), LOWER);
        }

        return memo[i][j][s] = eq + lo;
    } else if (s == LOWER) {
        int64_t result = 0;
        for (int64_t d = 0; d < 10; d++) {
            result += solve(i + 1, j + (d != 0), LOWER);
        }

        return memo[i][j][s] = result;
    }
}

int main() {
    cin >> N >> K;
    memo.resize(N.size() + 1, vector<vector<int64_t>>(K + 1, vector<int64_t>(STATE_NUM, -1)));
    cout << solve(0, 0, EQUAL) << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = [S() for _ in range(3)]
    r = n * 3
    for i in range(n):
        t = collections.defaultdict(int)
        for j in range(3):
            t[a[j][i]] += 1
        r -= max(t.values())

    return r



print(main())




Measured memory_bytes: 7756
N,*A=$<.read.split
s,M=0,18
C=(0..M).map{[0]*19}
A.map{|a|a=(a.to_r*10**9).to_i
i=j=0
i+=1until a[i]>0
i>M&&i=M
(j+=1;a/=5)until 0<a%5
j>M&&j=M
s+=C[M-i,19].sum{_1[M-j,19].sum}
C[i][j]+=1}
p s

Measured memory_bytes: 38468
import math
N = int(input())
if N % 2 == 1:
    print(0)
else:
    div10 = N // 10
    sum_val = div10
    if sum_val > 0:
        count_5 = math.floor(math.log(div10, 5))
        for i in range(count_5):
            sum_val += div10 // pow(5, i + 1)
    print(sum_val)


Measured memory_bytes: 2940
n = gets.chomp.to_i
xx = gets.chomp.split(" ").map(&:to_i)
min = 1145141919
(0..100).each do |i|
	ngo = xx.inject(0){|prev, now| prev + (i-now) ** 2}
	#puts ngo
	min = ngo if min > ngo
end
puts min

Measured memory_bytes: 1788
suba (xz:yz:xm:ym:x:y:1:_) = if x > xz
	then [x, yz, xm, ym]
	else [xz, yz, xm, ym]

suba (xz:yz:xm:ym:x:y:2:_) = if x < xm
	then [xz, yz, x, ym]
	else [xz, yz, xm, ym]

suba (xz:yz:xm:ym:x:y:3:_) = if y > yz
	then [xz, y, xm, ym]
	else [xz, yz, xm, ym]

suba (xz:yz:xm:ym:x:y:4:_) = if y < ym
	then [xz, yz, xm, y]
	else [xz, yz, xm, ym]

isZero n = if n < 0
	then 0
	else n

solve' (xc:xs) = if null xs
	then isZero (xc !! 2 - xc !! 0) * (xc !! 3 - xc !! 1)
	else solve' $ [suba $ xc ++ head xs] ++ tail xs

solve (x1:xs) =	solve' $ [[0, 0] ++ init x1] ++ xs

main = print . solve . map (map read) . map words . lines =<< getContents


Measured memory_bytes: 1020
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1000000000.0

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<double, int> Pd;
typedef pair<Pd, P> PPd;

int main()
{
	while(1){
		int n, m;
		cin>>n>>m;
		if(n==0 && m==0) return 0;
		int s, g;
		cin>>s>>g;
		vector<P> v[31];
		double d[450];
		int c[450];
		for(int i=0; i<m; i++){
			int x, y;
			cin>>x>>y>>d[i]>>c[i];
			v[x].push_back(P(y, i));
			v[y].push_back(P(x, i));
		}
		double t[31][31][31];
		for(int i=0; i<=n; i++){
			for(int j=0; j<=n; j++){
				for(int k=0; k<=30; k++){
					t[i][j][k]=INF;
				}
			}
		}
		t[s][0][0]=0;
		priority_queue<PPd, vector<PPd>, greater<PPd> > que;
		que.push(PPd(Pd(0, s), P(0, 0)));
		while(!que.empty()){
			PPd p=que.top();
          	        que.pop();
			int x=p.first.second;
			int prev=p.second.first;
			int cp=p.second.second;
			if(t[x][prev][cp]<p.first.first) continue;
			for(auto p1:v[x]){
				int y=p1.first, e=p1.second;
				if(y==prev) continue;
				if(cp-1>=1 && cp-1<=c[e]){
					if(t[y][x][cp-1]>t[x][prev][cp]+d[e]/((double)(cp-1))){
						t[y][x][cp-1]=t[x][prev][cp]+d[e]/((double)(cp-1));
						que.push(PPd(Pd(t[y][x][cp-1], y), P(x, cp-1)));
					}
				}
				if(cp>=1 && cp<=c[e]){
					if(t[y][x][cp]>t[x][prev][cp]+d[e]/((double)(cp))){
						t[y][x][cp]=t[x][prev][cp]+d[e]/((double)(cp));
						que.push(PPd(Pd(t[y][x][cp], y), P(x, cp)));
					}
				}
				if(cp+1>=1 && cp+1<=c[e]){
					if(t[y][x][cp+1]>t[x][prev][cp]+d[e]/((double)(cp+1))){
						t[y][x][cp+1]=t[x][prev][cp]+d[e]/((double)(cp+1));
						que.push(PPd(Pd(t[y][x][cp+1], y), P(x, cp+1)));
					}
				}
			}
		}
		double ans=INF;
		for(int i=1; i<=n; i++){
			if(t[g][i][1]<ans) ans=t[g][i][1];
		}
		if(ans>=INF-0.1){
			cout<<"unreachable"<<endl;
		}else{
			printf("%.5lf\n", ans);
		}
	}
	return 0;
}


Measured memory_bytes: 3804