akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

ll solve(ll N, ll X,
         const vector<ll>& a,
         const vector<ll>& p) {
    if(N == 0) {
        return (X <= 0) ? 0 : 1;
    }
    else if(X <= 1 + a[N - 1]) {
        return solve(N - 1, X - 1, a, p);
    }
    else {
        return p[N - 1] + 1 + solve(N - 1, X - 2 - a[N - 1], a, p);
    }
}

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

    ll N, X;
    std::cin >> N >> X;

    vector<ll> a(1, 1), p(1, 1);
    REP(i, N) {
        a.push_back(a[i] * 2 + 3);
        p.push_back(p[i] * 2 + 1);
    }

    std::cout << solve(N, X, a, p) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
using pi=pair<int,int>;
void solve()
{
	int n;
	cin>>n;
	vector<pi>xy(n);
	ll mins=2e9;
	ll maxs=-2e9;
	ll min2=2e9;
	ll max2=-2e9;
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		mins=min(mins,x+y);
		maxs=max(maxs,x+y);
		min2=min(min2,x-y);
		max2=max(max2,x-y);
	}
	ll ans=abs(mins-maxs);
	ans=max(ans,abs(min2-max2));
	cout<<ans<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 4772
#include <iostream>

using namespace std;

long long a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	while(a>0&&c>0){
        c=c-b;
        if(c<1){
            cout<<"Yes";
            return 0;
        }
        a=a-d;
        if(a<1){
            cout<<"No";
            return 0;
	    }
	}
}


Measured memory_bytes: 3596
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.buffer.readline()[:-1]
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

ans = 0
for i, x in enumerate(a):
    if (i+1)%2 and x%2:
        ans += 1
print(ans)


Measured memory_bytes: 10096
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a[3];
    rep(i,0,3){
        cin >> a[i];
    }
    sort(a,a+3);
    print(a[0] * a[1]/2);

}


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

using namespace std;

#define rep(i,j) for(int i=0;i<(j);i++)

vector<int>Nail[5005];
int N, M;

int main(){
  scanf("%d%d", &N,&M);
  rep(i,5005) Nail[i].resize(i+3, 0);
  //  cout << 0 << endl;
  //  rep(i,N+1){ rep(j,Nail[i].size()) cout << Nail[i][j] << " "; cout << endl; }  
  rep(i,M){
    int A,B,X;
    scanf("%d%d%d", &A, &B, &X);
    Nail[A][B]++;
    Nail[A][B+1]--;
    Nail[A+X+1][B]--;
    Nail[A+X+2][B+1]++;
    Nail[A+X+1][B+X+2]++;
    Nail[A+X+2][B+X+2]--;
  }
  //  cout << 0 << endl;
  //  rep(i,N+3){ rep(j,Nail[i].size()) cout << Nail[i][j] << " "; cout << endl; }
  rep(i,N+3) rep(j,Nail[i].size()-1) Nail[i][j+1] += Nail[i][j];
  //  cout << 1 << endl;
  //  rep(i,N+3){ rep(j,Nail[i].size()) cout << Nail[i][j] << " "; cout << endl; }
  rep(i,N+3) for(int j=i;j<N+2;j++) Nail[j+1][i] += Nail[j][i];
  //  cout << 2 << endl;
  //  rep(i,N+3){ rep(j,Nail[i].size()) cout << Nail[i][j] << " "; cout << endl; }  
  rep(i,N+1) rep(j,Nail[i].size()-1) Nail[i+1][j+1] += Nail[i][j];
  //  cout << 3 << endl;
  //  rep(i,N+3){ rep(j,Nail[i].size()) cout << Nail[i][j] << " "; cout << endl; }
  int res = 0;
  rep(i,N+3) rep(j,Nail[i].size()) if(Nail[i][j]>0) res++;

  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 50320
n=int(input())
*h,=map(int, input().split())
import numpy as np
h=np.array(h)

def rec(hh):
    if len(hh)==0:
        return 0
    if len(hh)==1:
        return hh[0]
    i=np.argmin(hh)
    res=hh[i]
    l=rec(hh[:i]-hh[i])
    r=rec(hh[i+1:]-hh[i])
    return res+l+r
print(rec(h))

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

vector<bool> B(100005);
vector<int> ans(100005); 

int main() {
    int Q; cin >> Q;
    for (int i = 2; i <= 100000; i++){
        if(!B[i]){
            for (int j = i+i; j <= 100000; j+=i){
                B[j] = true;
            }
        }
    }

    for (int i = 3; i <= 100000; i+=2){
        if(!B[i] && !B[(i+1)/2]){
            ans[i]++;
        }
    }

    rep(i, 100000){
        ans[i+1] += ans[i];
    }

    rep(i, Q){
        int l,r; cin >> l >> r;
        int x = ans[r] - ans[l-1];
        cout << x << endl;
    }
    
    

}

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

int main()
{
    queue<int> Q;
    int n;
    int a, b, c;
    cin >> n;
    int D[100], in[100][100];
    for (int i = 0; i < n; i++)
    {
        D[i] = -1;
        for (int j = 0; j < n; j++)
            in[i][j] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        for (int j = 0; j < b; j++)
        {
            cin >> c;
            in[c - 1][a - 1] = 1;
        }
    }
    Q.push(0);
    D[0] = 0;
    while (!Q.empty())
    {
        int cur = Q.front();
        Q.pop();
        for (int i = 0; i < n; i++)
        {
            if (in[i][cur] == 1 && D[i] == -1) {
                D[i] = D[cur] + 1;
                Q.push(i);
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << i + 1 << " " << D[i] << endl;
    }
    return 0;
}

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

int main(){
  ll l,r;
  cin >> l >> r;
  int ml = l%2019;
  int mr = r%2019;
  if(r-l>=2019||ml>mr){
    cout << 0 << endl;
  }else{
    int ans = 10000000;
    for(int i = ml;i<mr;i++){
      for(int j=i+1;j<=mr;j++){
        int tmp = i*j;
        tmp %= 2019;
        ans = min(ans,tmp);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    int n, m;
    int[] ls, rs, ds;
    long[] xs;
    ArrayList<ArrayList<Edge>> es;
    boolean flg;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        ls = new int[m];
        rs = new int[m];
        ds = new int[m];
        es = new ArrayList<>(n);
        for (int i = 0; i < n; i++)
            es.add(new ArrayList<>());
        for (int i = 0; i < m; i++) {
            ls[i] = sc.nextInt();
            rs[i] = sc.nextInt();
            ds[i] = sc.nextInt();
            es.get(ls[i]- 1).add(new Edge(rs[i]- 1, ds[i]));
            es.get(rs[i]-1).add(new Edge(ls[i]-1, -ds[i]));
        }
    }

    private void solve() {
        xs = new long[n];
        Arrays.fill(xs, Long.MAX_VALUE);
        flg = true;
        for (int i = 0; i < n; i++) {
            if (xs[i] == Long.MAX_VALUE && flg) {
                xs[i] = 0;
                dfs(i);
            }
        }
        if (flg)
            System.out.println("Yes");
        else
            System.out.println("No");
    }

    private void dfs(int cur) {
        ArrayList<Edge> c_es = es.get(cur);
        for (Edge e: c_es) {
            if (xs[e.to] == Long.MAX_VALUE) {
                xs[e.to] = e.cost + xs[cur];
                dfs(e.to);
            }
            else {
                long check = e.cost + xs[cur];
                flg &= xs[e.to] == check;
            }
        }
    }

    private class Edge {
        int to, cost;
        Edge(int t, int c) {
            to = t;
            cost = c;
        }
    }
}


Measured memory_bytes: 187092
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main(){
  int N, M;
  cin>>N>>M;
  int H[100001], A[100001]={0};
  rep(i, N) cin>>H[i];
  rep(i, M){
    int a, b;
    cin>>a>>b;
    a--; b--;
    // printf("%d,%d, H = %d, %d\n", a,b,H[a], H[b]);
    if(H[a]<H[b]) A[a]++;
    else if (H[a]>H[b]) A[b]++;
    else {A[a]++; A[b]++;}
  }
  int ans=0;
  rep(i, N){
    // out(A[i]);
    if(A[i]==0) ans++;
  }
  out(ans);
}


Measured memory_bytes: 4404
/*input
6 1
6 5 2 5 3 2
*/
/**
    Author: Kristopher Paul
    Date Created: 04-05-2020
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

//Uncomment for File I/O
//ifstream fin("input.in")

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n,k;
    cin >> n >> k;
    int a[n+1];
    FOR(i,1,n+1){
        cin >> a[i];
    }
    int cv = 1;
    vector<int> vec;
    vec.pb(1);
    umap<int,int> pos;
    pos[1] = 1;
    FOR(i,1,k+1){
        cv = a[cv];
//        cout << " cv: " << cv << endl;
        if(pos[cv] != 0){
            int left = k-i;
            int st = pos[cv];
            int en = vec.size();
            int ind = left % (en-st+1);
            cout << vec[(st+ind)-1] << endl;
            return;
        }
        vec.pb(cv);
        pos[cv] = vec.size();
    }
    cout << vec[vec.size()-1] << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 12944
n=int(input())
a=list(map(int,input().split()))
d={}
for i in a:
  if i in d:
    d[i]+=1
  else:
    d[i]=1
ans=0
for i in list(set(a)):
  ans+=d[i]*(d[i]-1)//2
for i in a:
  kari=ans
  kari-=d[i]*(d[i]-1)//2
  kari+=(d[i]-1)*(d[i]-2)//2
  print(kari)

Measured memory_bytes: 26912
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(a,b,c) for(int a=b; a<(int)c; a++)
#define REPE(a,b,c) for(int a=b; a<=(int)c; a++)
#define REPD(a,b,c) for(int a=b; a>=(int)c; a--)
#define rep(a,b) REP(a,0,b)
#define repd(a,b) REPD(a,b,0)
typedef long long int ll;
using namespace std;
string str;
int idx;

int DFS(int n){
	int rtn = 0;
	vector<int> data;
	//cout << "n:" << n << " idx:" << idx << endl;
	while (true){
		if (str.at(idx) == '['){
			//cout << "[" << idx << " " << n << endl;
			idx++;
			int num = DFS(n + 1);
			if (n == 0)return num;
			data.push_back(num);
		}
		else if (str.at(idx) == ']'){
			//cout << "]" << idx << " " << n << endl;
			idx++;
			sort(data.begin(), data.end());
			rep(i, (data.size() + 1) / 2){
				rtn += data[i];
			}
			return rtn;
		}
		else{
			int num = 0;
			while (true){
				//cout << num << " " << "idx:" << idx << endl;
				if (str.at(idx) == ']'){
					//cout << idx << ":" << num << endl;
					data.push_back((num+1)/2);
					break;
				}
				num *= 10;
				num += str.at(idx) - '0';
				idx++;
			}
		}
	}
	//cout << "ERROR" << endl;
	return -1;
}


int main(){
	int N;
	cin >> N;
	//cout << N << endl;
	rep(i, N){
		std::cin >> str;
		//std::cout << str << endl;
		//std::cout << "i:" << i << endl;
		idx = 0;
		cout << DFS(0) << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
def solver (str)
        # 後ろに1文字付け足す
        alphabets = ('a'..'z').to_a
        str = str.delete("\n")
        for a in alphabets
                s = str + a
                if s.length == s.split("").uniq.length then
                        return s
                end
        end

        # 文字を入れ替える (26文字のとき)
        for i in 1..(str.length)
                s = str[0, str.length-i] # 後ろi文字を切り落とす
                last_i = str[-i, i].split("").sort! # 後ろi文字
                for c in last_i
                        if str < s+c then
                                return s + c
                        end
                end
                # for c in last_i
                #       if s[str.length-i-1] < c then
                #               return s[0, s.length-1] + c
                #       end
                # end
        end

        return -1
end

s = gets
puts solver(s)



Measured memory_bytes: 2044
while s = gets
   if s == nil
     break
   end
   s = s.split()
   a = s[0].to_i
   b = s[1].to_i
   i = 1
   while i <= a
     if a % i == 0 && b % (a/i) == 0
       break
     end
     i+=1
   end
   puts a/i
end

Measured memory_bytes: 6100
#include <cstdio>
#include <vector>
using namespace std;
int n, m, a, b, cnt, col[100009]; vector<int> g[100009];
bool dfs(int pos) {
	bool ret = true; cnt++;
	for (int i : g[pos]) {
		if (col[i] == col[pos]) ret = false;
		if (col[i] == 0) {
			col[i] = 3 - col[pos];
			if (!dfs(i)) ret = false;
		}
	}
	return ret;
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a, &b); a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int c0 = 0, c1 = 0, c2 = 0;
	for (int i = 0; i < n; i++) {
		if (col[i] == 0) {
			col[i] = 1; cnt = 0;
			bool res = dfs(i);
			if (cnt == 1) c0++;
			else if (!res) c1++;
			else c2++;
		}
	}
	printf("%lld\n", 1LL * (c1 + c2) * (c1 + c2) + 1LL * c2 * c2 + 1LL * n * n - 1LL * (n - c0) * (n - c0));
	return 0;
}

Measured memory_bytes: 9984
str = gets.chop

/^([^\/]*)\/([^\/]*)\/([^\/]*)$/ =~ str

year = $1.to_i
month = $2.to_i
data = $3.to_i

if (year <= 2019) && (month <= 4) && (data <= 30) then
	print 'Heisei'
else
	print 'TBD'
end


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

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

using namespace std;

vector<int> p;
vector<bool> er;
void sieve(int n){
	er.assign(n+1,true);
	er[0]=er[1]=false;
	for(int i=2;i*i<=n;i++) if(er[i]) for(int j=i*i;j<=n;j+=i) er[j]=false;
	rep(i,n+1) if(er[i]) p.emplace_back(i);
}

int main(){
	sieve(55555);

	int n; cin>>n;
	for(int q:p) if(q%10==1 && n>0) cout<<q<<' ', n--;

	return 0;
}


Measured memory_bytes: 256
inf = 10**9 + 7


def merge(L, R):
    cnt = 0
    l, r = len(L), len(R)
    L.append(inf)
    R.append(inf)
    lst = []
    i, j = 0, 0
    for k in range(l + r):
        if L[i] < R[j]:
            lst.append(L[i])
            i += 1
        else:
            lst.append(R[j])
            j += 1
            # まだ追加されていないLの要素数
            cnt += l - i
    return lst, cnt


def merge_sort(A):
    l = len(A)
    if l == 1:
        return A, 0
    L, cntL = merge_sort(A[:l // 2])
    R, cntR = merge_sort(A[l // 2:])
    A, cnt = merge(L, R)
    return A, cntL + cntR + cnt


n = int(input())
*A, = map(int, input().split())
A, cnt = merge_sort(A)
print(cnt)



Measured memory_bytes: 27476
n = int(input())
seq = sorted((int(x) for x in input().split()), reverse=True)
val1 = None
val2 = None
cur_val = seq[0]
for val in seq[1:]:
    if val == cur_val:
        if val1 is None:
            val1 = val
            cur_val = None
        elif val2 is None:
            val2 = val
            break
    else:
        cur_val = val
if val1 is None or val2 is None:
    print(0)
else:
    print(val1 * val2)


Measured memory_bytes: 62832
import sys

def dijkstra(v_count: int, edges: list, start: int,
             *, adj_matrix: bool = False, unreachable=float("inf")) -> list:
    """ ダイクストラ法
    :param v_count: 頂点数
    :param edges: 辺のリスト(隣接リストor隣接行列)
    :param start: スタートする頂点
    :param adj_matrix: edgesに渡したリストが隣接行列ならTrue
    :param unreachable: 到達不能を表すコスト値
                        隣接行列の辺の有無の判定および返すリストの初期値に使用
    """
    from heapq import heappush, heappop

    vertices = [unreachable] * v_count
    vertices[start] = 0
    q, rem = [(0, start)], v_count - 1

    while q and rem:
        cost, v = heappop(q)
        if vertices[v] < cost:
            continue
        rem -= 1

        dests = (filter(lambda x: x[1] != unreachable, enumerate(edges[v]))
                 if adj_matrix else edges[v])

        for dest, _cost in dests:
            newcost = cost + _cost
            if vertices[dest] > newcost:
                vertices[dest] = newcost
                heappush(q, (newcost, dest))

    return vertices

n = int(input())
edges = [[] for _ in [0]*n]
for a in (tuple(map(int, l.split())) for l in sys.stdin):
    edges[a[0]] = tuple(zip(a[2::2], a[3::2]))
vertices = dijkstra(n, edges, 0)
for i, n in enumerate(vertices):
    print(i, n)


Measured memory_bytes: 6264
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=100005,INF=0x7f7f7f7f;
int n,k;
int a[MAXN];
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int ans=INF;
	for(int i=k;i<=n;i++)
	{
		int j=i-k+1;
		ans=min(ans,max(0-a[j],a[j]-0)+a[i]-a[j]);
		ans=min(ans,max(0-a[i],a[i]-0)+a[i]-a[j]);
	}
	printf("%d\n",ans);
}

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

using namespace std;

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

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n,m;cin>>n>>m;
    vector<vector<int>> g(n);
    vector<int> live(n,1), acnt(n,0), bcnt(n,0);
    string s;
    cin>>s;
    for(int i=0;i<m;i++)
    {
        int a,b;cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
        if(s[a]=='A')
        {
            acnt[b]++;
        }
        else
        {
            bcnt[b]++;
        }
        if(s[b]=='A')
        {
            acnt[a]++;
        }
        else
        {
            bcnt[a]++;
        }
    }
    queue<int> que;
    for(int i=0;i<n;i++)
    {
        if(acnt[i]==0 || bcnt[i]==0)
        {
            que.push(i);
            live[i] = 0;
        }
    }
    while(!que.empty())
    {
        int cur = que.front();
        que.pop();
        for(auto v:g[cur])
        {
            if(live[v]==0) continue;
            if(s[cur]=='A')
            {
                acnt[v]--;
            }
            else
            {
                bcnt[v]--;
            }
            if(acnt[v] && bcnt[v]) continue;
            que.push(v);
            live[v] = 0;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(live[i])
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 12880
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream& operator>>(istream& is, vector<T>& v);
template<class T> ostream& operator<<(ostream& os, vector<T> const& v);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream&, const tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream& os, const tuple<T...>& t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream& operator<<(ostream& os, const tuple<T...>& t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream&, tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream& is, tuple<T...>& t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream& operator>>(istream& is, tuple<T...>& t){ _it<0>(is, t); return is; }
template<class T> istream& operator>>(istream& is, vector<T>& v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif


string ans[1<<20];
char s[32];
char t[32];

int main(){
#ifdef LOCAL
    freopen("in","r",stdin);
#endif
    while(cin >> s && s[0]!='#'){
        int sz = 0;
        int n = strlen(s);
        rep(i,n) t[i] = s[i];
        t[n] = 0;
        int change[32];
        rep(mask,1<<n){
            bool ok = true;
            rep(i,n){
                ok &= s[i]!='z' || ~mask>>i&1;
            }
            if(!ok) continue;
            rep(i,n){
                t[i] = s[i] + (mask>>i & 1);
            }
            rep(i,26){
                change[i] = 30;
            }
            rep(i,n){
                change[t[n-i-1]-'a'] = n-i-1;
            }
            loop(i,1,26) t[change[i]]--;
            if(strcmp(t,s)==0){
                rep(i,n){
                    t[i] = s[i] + (mask>>i&1);
                }
                ans[sz++] = t;
            }
        }
        sort(ans, ans + sz);
        printf("%d\n",sz);
        if(sz > 10){
            rep(i,5) printf("%s\n", ans[i].c_str());
            rep(i,5) printf("%s\n", ans[sz-5+i].c_str());
        } else {
            rep(i,sz){
                printf("%s\n",ans[i].c_str());
            }
        }
    }
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  int k=0;
  for(int j=0;j<N;j++){
    if(P.at(j)!=j+1) k++;
  }
  if (k<=2) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
 
}

Measured memory_bytes: 3632
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var A = Number.parseInt(inputStr[0]);
  var B = Number.parseInt(inputStr[1]);
  var C = Number.parseInt(inputStr[2]);
  var ANS = 0;
  
  if (A > B) { 
	ANS = 0;
  } else if ( A*C <= B) {
    ANS = C;
  } else {
    ANS = Math.floor(B/A);
  }
  console.log(ANS);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

typedef long long ll;

void solve(){
	int x;
	cin>>x;
	cout<<8-(x-400)/200;	
}

int main(){
	Red;
	int T=1;
	//cin>>T;
	while(T--)solve();
}

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;



int main() {
  int k, a, b; cin >> k >> a >> b;
  string ans = "NG";
  for(int i = a; i <= b; i ++){
    if(i % k == 0){
      ans = "OK";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a*b%2!=0 || a*b*3%2!=0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;

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

    sort(a, a + n, greater<int>());

    bool isApproved = false;
    for(int i = 0; i < n; i++) {
        if(a[i] % 2 == 0) {
            if(a[i] % 3 == 0 || a[i] % 5 == 0) {
                // isApproved = true;
            } else {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
int main()
{
    int n,x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        if(i%3==0){
            printf(" %d",i);}

    else
    {
        x=i;
        do
        {
            if(x%10==3)
            {
                printf(" %d",i);
                break;
            }
            x/=10;
    }while(x);
    }
    }
    printf("\n");
}



Measured memory_bytes: 2720
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans = 0;
    if(k>=2*n){
        rep(i,n) if(v[i]>=0) ans += v[i];
        cout << ans << endl;
        return 0;
    }
    vector<int> a;
    rep(i,min(n,k)+1){
        rep(l,i+1){
            a.clear();
            rep(j,l) a.emplace_back(v[j]);
            rep(j,i-l) a.emplace_back(v[n-1-j]);
            sort(all(a));
            int m = k-i;
            int flag = 0;
            int sum = 0;
            rep(j,a.size()){
                if(flag<m && a[j]<0){
                    flag++;
                }
                else{
                    sum += a[j];
                }
            }
            chmax(ans,sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left
import heapq
n, q = map(int, input().split())
stx = [tuple(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

events = []
for s, t, x in stx:
    events.append((s-x, 1, x))
    events.append((t-x, -1, x))
events.sort(key=lambda x: x[0])

hp = []
st = set()
res = [-1] * q
now = 0
for t, b, x in events:
    while now < q and d[now] < t:
        if len(st) > 0:
            while hp[0] not in st:
                heapq.heappop(hp)
            res[now] = hp[0]
        now += 1
    if b == 1:
        heapq.heappush(hp, x)
        st.add(x)
    else:
        st.discard(x)
print(*res)

Measured memory_bytes: 107076
#include <iostream>
#include <set>
#include <list>
using namespace std;


int main() {
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        list<int> fs[n+1];
        for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
            fs[a].push_back(b);
            fs[b].push_back(a);
        }
        int count = 0;
        set<int> inv;
        for (list<int>::iterator f = fs[1].begin(); f != fs[1].end(); f++) {
            for (list<int>::iterator ff = fs[*f].begin(); ff != fs[*f].end(); ff++) {
                if (*ff == 1) continue;
                inv.insert(*ff);
            }
            inv.insert(*f);
        }
        cout << inv.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<algorithm>

using namespace std;

pair<int,int>P[100000];

int main(){

  int n;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    P[i]=make_pair(a,i+1);
  }

  sort(P,P+n);

  for(int i=0;i<n;i++){
    printf("%d ",P[i].second);
  }

  return 0;

}

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

using namespace std;

constexpr char endl('\n');


int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    size_t n;
    cin >> n;

    vector<vector<pair<size_t, size_t>>> a(n);

    for (auto &v : a) {
        size_t l;
        cin >> l;
        for (auto i = 0; i < l; ++i) {
            size_t x, y;
            cin >> x >> y;
            v.push_back(make_pair(x - 1, y));
        }
    }

    vector<pair<size_t, size_t>> b;
    for (auto v : a) {
        bitset<15> x(0);
        bitset<15> y((1ULL << n) - 1);
        for (auto w : v) {
            if (w.second == 0) {
                y.set(w.first, false);
            }
            else {
                x.set(w.first, true);
            }
        }
        b.emplace_back(make_pair(x.to_ullong(), y.to_ullong()));
    }

    size_t ret = 0;
    for (size_t i = (1ULL << n) - 1; i > 0; --i) {
        bitset<15> p(i);
        bool ok = true;
        for (auto j = 0; j < n; ++j) {
            if (p.test(j)) {
                //cout << b.at(j).first << ", " << b.at(j).second << ::endl;
                if ((p.to_ullong() & b.at(j).first) != b.at(j).first) {
                    ok = false;
                    break;
                }
                if ((p.to_ullong() | b.at(j).second) != b.at(j).second) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) {
            bitset<15> ret2(i);
            ret = max(ret, ret2.count());
        }
    }
    cout << ret << ::endl;

    return 0;
}


Measured memory_bytes: 256
def main():
	D, G = map(int, input().split())
	p = [0]*(D+1)
	c = [0]*(D+1)
	ans = 10**9
	for i in range(D):
		p[i], c[i] = map(int, input().split())

	for mask in range(1 << D):
		s, num, rest_max = 0, 0, -1
		for i in range(D):
			if ((mask >> i) & 1) == 1:
				s += 100 * (i+1) * p[i] + c[i]
				num += p[i]
			else:
				rest_max = i
		if s < G:
			s1 = 100 * (rest_max+1)
			need = (G - s + s1 - 1) // s1
			if need >= p[rest_max]:
				continue
			num += need
		ans = min(ans, num)

	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
using Yorukatsu029.Questions;
using Yorukatsu029.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu029.Questions
{
    /// <summary>
    /// ABC135 C
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var monsterCounts = inputStream.ReadLongArray();
            var bravePower = inputStream.ReadLongArray();

            long totalCount = 0;
            for (int i = 0; i < n; i++)
            {
                long count1 = Math.Min(monsterCounts[i], bravePower[i]);
                bravePower[i] -= count1;
                long count2 = Math.Min(monsterCounts[i + 1], bravePower[i]);
                monsterCounts[i + 1] -= count2;
                totalCount += count1 + count2;
            }

            yield return totalCount;
        }
    }
}


namespace Yorukatsu029
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu029.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu029.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 30152
N = int(input())
n = list(map(int,input().split()))
b = 0
ans = 0
while True:
  for j in range(N):
    if n[j] % 2 == 1:
      b += 1
    n[j] /= 2
  if b != 0:
    break
  ans += 1
print(ans)


Measured memory_bytes: 3064
data=[]
N, M = map(int,input().split())
for i in range (M):
    data.append(list(map(int, input().split())))

ans=[]
for i in range (N):
    count=0
    for j in range (M):
        if i+1 == data[j][0] or i+1== data[j][1]:
            count+=1
    ans.append(count)

for k in range (N):
    print(ans[k])

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n, m;
string str;

int main() {
    while (cin >> n >> m) {
        if (n == 0) break;
        map<string,int> ma;
        for (int i = 0; i < n; ++i) {
            cin >> str;
            while (str[0] == '*') str = str.substr(1);
            int num; cin >> num;
            ma[str] = num;
        }
        int res = 0;
        for (int i = 0; i < m; ++i) {
            cin >> str;
            for (int j = 0; j < str.size(); ++j) {
                string sub = str.substr(j);
                if (ma.count(sub)) res += ma[sub];
            }
        }
        cout << res << endl;
    }
    return 0;
}


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

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

  int n, m;
  cin >> n >> m;
  priority_queue<int> pq;

  while(n--) {
    int x;
    cin >> x;
    pq.push(x);
  }

  while(m--) {
    int x = pq.top();
    pq.pop();
    x >>= 1;
    pq.push(x);
  }

  ll sum = 0;
  while(!pq.empty()) {
    sum += pq.top();
    pq.pop();
  }

  cout << sum;

  return 0;
}


Measured memory_bytes: 892
#include <iostream>

using namespace std;

int main( void )
{
  for( int i = 0; ; i++ ){
    int x, y;

    cin >> x >> y;

    if( x == 0 && y == 0 ){
      break;
    }

    if( x <= y ){
      cout << x << " " << y << endl;
    }else{
      cout << y << " " << x << endl;
    }
  }

  return( 0 );
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    sc.close();

    String[] days = {
      "SUN","MON","TUE","WED","THU","FRI","SAT"
    };
    
    long ans = 0;
    for (int i = 0; i < days.length; i++) {
      if (days[i].equals(S)) ans = 7 - i;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    ll a;
    string b;
    cin >> a >> b;
    int i = b[0] - '0';
    int j = b[2] - '0';
    int k = b[3] - '0';
    ll c = 100 * i + 10 * j + k;
    cout << a * c / 100 << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, d, x;
  cin >> n >> d >> x;

  int ans = 0;
  while (n--) {
    int a;
    cin >> a;
    int v = 1;
    while (v <= d) {
      ans++;
      v += a;
    }
  }
  cout << ans + x << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
    int i;

    int n;
    scanf("%d", &n);
    int x[n], y[n];
    for( i = 0; i < n; ++i )
        scanf("%d", &x[i]);
    for( i = 0; i < n; ++i )
        scanf("%d", &y[i]);

    int p;
    double D;
    for( p = 1; p < 4; ++p ){
        D = 0;
        for( i = 0; i < n; ++i )
            D += (double)(pow(fabs(x[i] - y[i]), p));
        D = (double)pow(D, 1.0/p);
        printf("%lf\n", D);
    }

    D = 0;
    for( i = 0; i < n; ++i ){
        double tmp = (double)(fabs(x[i] - y[i]));
        D = D < tmp ? tmp : D;
    }
    printf("%lf\n", D);

    return 0;
}



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll h,w;
    cin >> h >> w;
    vector<string> a(h);
    vector<vector<ll>> kyori(h,vector<ll>(w,-1));
    queue<pair<ll,ll>> que;
    ll ans = 0;
    for(i = 0;i < h;++i){
        cin >> a.at(i);
    }
    for(i = 0;i < h;++i){
        rep(j,w){
            if(a.at(i).at(j) == '#'){
                que.emplace(i,j);
                kyori.at(i).at(j) = 0;
            }
        }
    }
    ll di[4] = {0,-1,1,0};
    ll dj[4] = {-1,0,0,1};
    while(!que.empty()){
        auto x = que.front();
        que.pop();
        ll d = kyori.at(x.first).at(x.second);
        for(i = 0;i < 4;++i){
            ll ni = x.first + di[i];
            ll nj = x.second + dj[i];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(kyori.at(ni).at(nj) == -1){
                kyori.at(ni).at(nj) = d+1;
                que.emplace(ni,nj);
                ans = max(ans, d+1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25524
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define MAXN 100
int K,N;
char str[MAXN+5],tstr[MAXN+5];

int main(){
    scanf("%s%d",str+1,&K);
    N=strlen(str+1);
    bool flag=0;
    for(int i=1;i<N;i++)
        if(str[i]!=str[i+1]){
            flag=1;
            break;
        }
    if(!flag){
        printf("%lld",(long long)K*N/2);
        return 0;
    }
    //BBBCBCCAACBACBABCCACCBBAACCABBACBCAABCCCBAABCCAACCBACCCBCBBABAAAABBCBABAAAAB
    //BBBAB
    memcpy(tstr,str,sizeof str);
    int cnt=0,tmp=0;
    for(int i=1;i<=N;i++)
        if(str[i]==str[i-1])
            cnt++,str[i]='$';
    tmp=cnt;
    cnt+=str[N]==str[1];
    long long Ans1=(long long)cnt*(K-1)+tmp;
    cnt=1,tmp=0;
    tstr[1]='$';
    for(int i=2;i<=N;i++)
        if(tstr[i]==tstr[i-1])
            cnt++,tstr[i]='$';
    tmp=cnt;
    cnt+=tstr[N]==tstr[1];
    long long Ans2=(long long)cnt*(K-1)+tmp;
    printf("%lld",min(Ans1,Ans2));
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long a, b;
char c;
int main() {
  cin >> a >> c >> b;
  if (c == '+') cout << a+b << endl;
  else cout << a-b << endl;
}


Measured memory_bytes: 256