akhauriyash/Code-Regression huggingface dataset:
//cwystc <--> 陈威宇是天才  --by cwy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<48||ch>57)&&ch!=45)ch=getchar();
	if (ch==45)f=-1,ch=getchar();
	while (ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
	x*=f;
}

//-------------------------------------------------head-------------------------------------------------

ll n;
int getlen(ll x){
	int res=0;while (x)x/=10,res++;return res;
}
int getall(ll x){
	int res=0;while (x)res+=x%10,x/=10;return res;;
}
int getmax(ll x){
	int res=0;while (x>=10)x/=10;return x;
}
int main(){
	read(n);
	printf("%d\n",max(getall(n),getmax(n)-1+(getlen(n)-1)*9));
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    }
}


Measured memory_bytes: 52440
S = raw_input()

p = len(S)-1
while p>=0:
  if p<2:
    print "NO"
    exit(0)
  if S[p]=="m":
    c = "dream"
  elif S[p]=="e":
    c = "erase"
  elif S[p-2]=="m":
    c = "dreamer"
  else:
    c = "eraser"
  if p>=len(c)-1 and S[p-len(c)+1:p+1]==c:
    p -= len(c)
  else:
    print "NO"
    exit(0)
print "YES"


Measured memory_bytes: 2692
h,w,k=map(int,input().split())
dp=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)]
f=[[0]*(w+1) for _ in range(h+1)]
for _ in range(k):
  r,c,v=map(int,input().split())
  f[r][c]=v
for i in range(1,h+1):
  for j in range(1,w+1):
    for k in range(3,-1,-1):
      if k:dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+f[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
print(max(dp[k][h][w] for k in range(4)))

Measured memory_bytes: 430992
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String text = sc.nextLine();
		int time = sc.nextInt();
		char[] alphabet = text.toCharArray();
		for(int i = 0 ;i < text.length();i = i + time) {
			System.out.print(alphabet[i]);
		}	
	}
}

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s1, s2;
	cin >> s1 >> s2;

	reverse(s2.begin(), s2.end());
	cout << (s1 == s2 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 100005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  string s;
  cin>>n>>m>>s;
  vector<int>f=vector<int>(n,0);
  for(int i=1;i<n;i++){
    if(s[i]=='C'&&s[i-1]=='A')f[i]=1;
    f[i]+=f[i-1];
  }
  //cout<<f[3]<<endl;
  while(m--){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    cout<<f[y]-f[x]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;
int main(int argc, char const *argv[]){
    int n;
    int ans=-1;
    cin >> n;
    vector<vector<P> > x(n);
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            P p;
            cin >> p.first >> p.second;
            p.first--;
            x[i].push_back(p);
        }
    }
    for(int bit=0;bit<(1<<n);bit++){
        bool flg=true;
        vector<int> t(n, 0);
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                t[i]=1;
            }
        }
        for(int i=0;i<n;i++){
            if(!(bit&(1<<i)))continue;
            for(auto p:x[i]) {
                if (t[p.first] == (1 - p.second)) {
                    flg=false;
                    break;
                }
            }
            if(!flg) break;
        }
        if(flg){
            int sum=0;
            for(int i=0;i<n;i++){
                if(bit&(1<<i)){
                    sum++;
                }
            }
            chmax(ans,sum);
        }
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 5;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> list(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> list[i];
  }
  vector<ll> aup;
  ll start = list[0] + 1;
  for (int i = 1; i < n; i++) {
    aup.push_back(list[i]);
  }
  int uplen = aup.size();
  k--;

  ll mincost = LLONG_MAX;
  for (int bit = 0; bit < (1<<uplen); bit++) {
    vector<int> ss(uplen, 0);
    int cnt = 0;
    for (int i = 0; i < uplen; i++) {
      if (bit>>i&1) {
        ss[i] = 1;
        cnt++;
      }
    }

    if (cnt == k) {
      ll cstart = start;
      ll sum = 0;
      for (int j = 0; j < uplen; j++) {
        if (ss[j]) {
          if (cstart < aup[j]) {
            cstart = aup[j] + 1;
          } else {
            sum += (cstart - aup[j]);
            cstart++;
          }
        } else {
          if (cstart < aup[j]) {
            cstart = aup[j] + 1;
          }
        }
      }
      mincost = min(mincost, sum);
    }
  }
  cout << mincost << endl;
  return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> num(K);
	for (int i = 0; i < K; i++) {
		cin >> num[i];
	}
	if (N == K)
		cout << 1;
	else if ((N - K) % (K - 1) == 0)
		cout << 1 + (N - K) / (K - 1);
	else
		cout << 2 + (N - K) / (K - 1);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

unsigned long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0, startp = 0, endp = 0, checker = 0;
std::vector<std::string> vec{}, vecsec{};
int iremono[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char cutcount[201];
int kakunou2[50][50] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{

	cin >> a>>b>>c;
	if (a + b >= c) {
		cout << b + c << endl;
	}
	else {
		cout << b * 2 + a + 1 << endl;
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
class Program {
    static void Main (string[] args) {
        var input = INP();
        var input2 = INP();
        var input3 = INP();
        long A = TOL(input[0]);
        long B = TOL(input2[0]);
        long V = TOL(input[1]);
        long W = TOL(input2[1]);
        long T = TOL(input3[0]);
 
        long dist = Math.Abs(B - A);
        long re = W - V;
        if(re >= 0) {
            CWL("NO");
            return;
        }
 
        decimal result = dist + re * T;
        if(result > 0) {
            CWL("NO");
            return;
        }
 
        CWL("YES");
    }
 
    static string[] INP () {
        return Console.ReadLine().Split(' ');
    }
 
    static void CWL (string value) {
        Console.WriteLine(value);
    }
 
    static void CWL (int value) {
        Console.WriteLine(value);
    }
 
    static void CWL (long value) {
        Console.WriteLine(value);
    }
 
    static void CWL (float value) {
        Console.WriteLine(value);
    }
 
    static void CWL (double value) {
        Console.WriteLine(value);
    }
 
    static int TOI (string str) {
        return int.Parse(str);
    }
 
    static long TOL (string str) {
        return long.Parse(str);
    }
 
    static float TOF (string str) {
        return float.Parse(str);
    }
 
    static double TOD (string str) {
        return double.Parse(str);
    }
 
    /*static void Main (string[] args) {
        var input = INP();
        var input2 = INP();
        var input3 = INP();
 
        CWL("dummy");
    }*/
}

Measured memory_bytes: 27536
import sys
import numpy as np
# from numba import njit#,i8

#@njit(cache=True)
# @jit(返り値の型(引数1の型,引数2の型,．．．,引数nの型))
#@jit(i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:]))
def main(N,Q,C,queries,orderByR,mostRightColorIndex,bitArray):

	def add(itemCount, items, i, value):
		while i <= itemCount:
			items[i] += value
			i += (i & (-i))

	def sumFromStart(items, end):
		summary = 0
		i = end
		while i > 0:
			summary += items[i]
			i -= (i & (-i))
		return summary

	def sum(items, start,end):
		summary = sumFromStart(items, end) - sumFromStart(items, start-1)
		return summary

	# 答え配列
	ans=np.zeros(Q, dtype=np.int64)
	#ans=[0]*Q
	# 左からBITと現在色の更新をしながら、クエリのrightに到達したときにBITにクエリ発行する
	qindex = 0

	for n in range(N):
		# 外側のループでは、全部の色をループ

		if Q <= qindex:
			break

		if 0 < mostRightColorIndex[C[n]]:
			# ループ中の場所の色のindexが既にある場合(=過去に、同じ色が登録されていた場合)
			# 今回で、同じ色の一番右側の要素はループ中の要素になる
			# 前登録したこの色の一番右のindexを一度BITから抜く(↓で再度登録される)
			add(N,bitArray,mostRightColorIndex[C[n]], -1 )

		# この要素の色の一番右のindexを、BITに登録
		mostRightColorIndex[C[n]] = n+1
		add(N,bitArray,n+1, 1)

		# while qindex < Q and n+1 == queries[qindex][2]:
		while qindex < Q and n+1 == queries[orderByR[qindex]][1]:
			# 今のBITが次のクエリ発行するための状態(n==query.right)だったら、クエリ発行
			tmpIndex = orderByR[qindex]
			start = queries[tmpIndex][0]
			end = queries[tmpIndex][1]
			ans[tmpIndex]=sum(bitArray,start,end)
			# print(tmpIndex,start,end,ans[tmpIndex])
			qindex += 1

	return ans

if sys.argv[-1]=='ONLINE_JUDGE':
	from numba.pycc import CC
	cc=CC('my_module')
	cc.export('main','i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])')(main)
	cc.compile()
	exit(0)
from my_module import main
#from numba import njit
#main=njit('i8[:](i8,i8,i8[:],i8[:,:],i8[:],i8[:],i8[:])', cache=True)(main)



def input(): return sys.stdin.readline()

N,Q = map(int,input().split())

C=np.array(input().split(), int)

# Query取得-rightでソート
# dtypeQuery = [("index", int), ("start", int), ("end", int)]
queries=np.empty((Q,2),int)
# #rights=[[] for _ in range(N+1)]

for q in range(Q):
	l,r=map(int,input().split())
	#queries[q] = (q,l,r)
	queries[q][0] = l
	queries[q][1] = r
	#queries=np.sort(queries,order="end")

#queries=np.array(sys.stdin.buffer.read().split(),int).reshape(Q,2)

orderByR=np.argsort(queries[:,1])

# 各色の現在の一番右のindex
mostRightColorIndex = np.zeros(N+1, int)
# bit indexed tree
bitArray=np.zeros(N+1,int)

for a in main(N,Q,C,queries,orderByR,mostRightColorIndex,bitArray):
	print(a)


Measured memory_bytes: 85636
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <map>
#include <string>

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

pair<bool,string> as[111];
int d[111][111];
int main(){
  
  int N;
  map<string,int> label;
  while(cin>>N){
    for(int i=0;i<N;i++){
      string s;
      cin>>s;
      if(s=="goto"){
        as[i].first=true;
        cin>>s;
        as[i].second=s.substr(0,(int)s.size()-1);
      }
      else{
        as[i].first=false;
        as[i].second=s.substr(0,(int)s.size()-1);
        label[as[i].second]=i;
      }
    }
    const int INF=1<<29;
    // 初期化
    for(int i=0;i<=N;i++)
      for(int j=0;j<=N;j++)
        if(i==j)d[i][j]=0;
        else d[i][j]=INF;
    for(int i=0;i<N;i++){
      if(as[i].first){
        d[i][label[as[i].second]]=min(d[i][label[as[i].second]],0);
        d[i][i+1]=min(d[i][i+1],1);
      }
      else{
        d[i][i+1]=min(d[i][i+1],0);
      }
    }
    // wfしてd[0][N]間最短経路を計算
    for(int k=0;k<=N;k++)
      for(int i=0;i<=N;i++)
        for(int j=0;j<=N;j++)
          d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    cout<<d[0][N]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1276
inp = input().split()
n, k = int(inp[0]), int(inp[1])
p = input().split()
p = list(map(int, p))
sum_ = 0
max_ = 0
for i in range(n):
    sum_ += p[i]
    if i >= k:
        sum_ -= p[i-k]
    if sum_ > max_:
        max_ = sum_
print((max_+k)/2)

Measured memory_bytes: 24548
# 過去の提出を見ながら解いた

def main():
    N, M = map(int, input().split())
    *a, = map(int, input().split())
    a.sort()

    def count(mid) -> int:
        cnt = 0  # (i,j)>=mid の個数
        j = N  # j: iと組んでペア和>=midを満たすjの下限, 初期値は範囲外=条件を満たすjはない
        for i in range(N):
            while j > 0 and a[i] + a[j - 1] >= mid:
                j -= 1
            # j==0 or a[i]+a[j]>=mid
            # j==0
            # 現在のiに対しすべてのaの要素が相方になる。
            # 一度そのようなiに達したら、それ以降のiはすべてこの条件を満たす。
            cnt += N - j  # iに対し[j,N)が相方になる
        return cnt

    def binary_search(*, ok: int, ng: int, is_ok: 'function') -> int:
        """あるペア和以上のみ採用する場合に
        M回以上握手できないようなペア和の上限"""
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    ma = binary_search(ok=2 * 10 ** 5 + 1, ng=0, is_ok=lambda mid: count(mid) < M)

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    *acc, = accumulate(a)

    ans = 0
    j = N  # j: iと組んでペア和>=midを満たすjの下限, 初期値は範囲外=条件を満たすjはない
    for i in range(N):
        while j > 0 and a[i] + a[j - 1] >= ma:
            j -= 1
        ans += a[i] * (N - j) + acc[N] - acc[j]  # i側の寄与=ペア数,j側の寄与=acc
    ans += (ma - 1) * (M - count(ma))  # ペア和maではMペア組めないが、ma-1で埋められる

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14268
<?php

//文字列の入力
$n = fgets(STDIN);
$h = explode(' ',trim(fgets(STDIN)));

$count[-1] = 0;
for ($i = 0; $i < $n-1; $i++){
    if ($h[$i] >= $h[$i+1]){
        $count[$i] = $count[$i -1] +1;
    }else{
        $count[$i] = 0;
    }
}

echo (max($count));


Measured memory_bytes: 35372
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

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

    string key = "keyence";

    int leftsum = 0;
    for (int i = 0; i < key.length(); i++)
    {
        if (key[i] == S[i])
        {
            leftsum++;
        }
        else
        {
            break;
        }
    }

    int rightsum = 0;
    for (int i = 0; i < key.length(); i++)
    {
        if (key[key.length() - 1 - i] == S[S.length() - 1 - i])
        {
            rightsum++;
        }
        else
        {
            break;
        }
    }

    if (leftsum + rightsum >= key.length())
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
int n, ans;
vector<ll> g;
vi power;
vi ss;

void solve(int i, int res, ll ok)
{
	if (i == n)
	{
		chmax(ans, res);
		return;
	}
	if (res + ss[n] - ss[i] <= ans) return;
	if (((ok >> i) & 1) == 0) solve(i + 1, res + power[i], ok | g[i]);
	solve(i + 1, res, ok);
}

int main()
{
	while (cin >> n, n)
	{
		ans = 0;
		g.resize(n);
		unordered_map<string, int> mp;
		vs name(n);
		power.resize(n);
		vector<vs> nei(n);
		REP(i, n)
		{
			int m;
			cin >> name[i] >> power[i] >> m;
			REP(j, m)
			{
				string s; cin >> s;
				nei[i].push_back(s);
			}
		}
		REP(i, n) mp[name[i]] = i;
		REP(i, n)
		{
			g[i] = 1ll << i;
			REP(j, nei[i].size())
			{
				g[i] |= 1ll << mp[nei[i][j]];
			}
		}

		ss.resize(n + 1);
		REP(i, n) ss[i + 1] = ss[i] + power[i];

		ll ok = g[0];
		solve(1, power[0], ok);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3248
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

#define ll long long int

int main(){
  int N;
  cin >> N;
  vector<int> X,Y,number;
  for(int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    X.push_back(x);
    Y.push_back(y);
    number.push_back(i);
  }
  double sum=0;
  int count=0;
  do{
    float total_dis=0;
    for(int i=0;i<N-1;i++){
      int now = number[i];
      int next = number[i+1];
      float dis = sqrt(pow(X[next]-X[now],2)+pow(Y[next]-Y[now],2));
      total_dis += dis;
    }
    sum+=total_dis;
    count++;
  }while(next_permutation(number.begin(),number.end()));
  cout << fixed << setprecision(15) << sum/count << endl;

  return 0;
}

Measured memory_bytes: 888
<?php

fscanf(STDIN, "%d", $N);

$array = array();
$rar = array();
$result = 0;
$temp = 0;
for ($i=1; $i <= $N; $i++) { 
	 array_push($array, trim(fgets(STDIN)));
}
sort($array, SORT_NUMERIC );
if ($N % 2 == 0) {
	for ($j=0; $j < $N / 2; $j++) { 
		$rar[$j*2+1]=$array[$j];
		$rar[$j*2]=$array[$j+$N/2];
	}

	for ($k=0; $k < $N-1 ; $k++) { 
		$result+=abs($rar[$k]-$rar[$k+1]);
	}
}else{
	$center = $N/2;
	$rar[$center]=$array[0];
	for ($m=1; $m <= $N / 2; $m++) { 
		if ($m % 2==1) {
			$rar[$center-$m]=$array[$N-$m];
			$rar[$center+$m]=$array[$N-$m-1];
		}else{
			$rar[$center-$m]=$array[$m-1];
			$rar[$center+$m]=$array[$m];
		}
		
	}
	for ($k=0; $k < $N-1 ; $k++) { 
		$result+=abs($rar[$k]-$rar[$k+1]);
	}
	$rar[$center]=$array[$N-1];
	for ($m=1; $m <= $N / 2; $m++) { 
		if ($m % 2==0) {
			$rar[$center-$m]=$array[$N-$m];
			$rar[$center+$m]=$array[$N-$m-1];
		}else{
			$rar[$center-$m]=$array[$m-1];
			$rar[$center+$m]=$array[$m];
		}
		
	}
	for ($k=0; $k < $N-1 ; $k++) { 
		$temp+=abs($rar[$k]-$rar[$k+1]);
	}
	$result = ($result<$temp)?$temp:$result;
}
echo $result;

Measured memory_bytes: 19444
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define M 1000000007

int32_t main()
{   fast

    int n;
    cin>>n;
    int l[n];

    for(int i=0;i<n;i++)
    {
        cin>>l[i];
    }
    sort(l,l+n);
    int ans=0;
    for(int i=0;i<n;i++)
    {   int k=i+2;
        for(int j=i+1;j<n;j++)
        {
           while(k<n&&l[i]+l[j]>l[k]) k++;
           if(k>j) ans+=k-j-1;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;
using ll=long long;
#define PRI(n) cout << n <<endl;
#define PRI2(n, m) cout << n << " " << m << endl;

#define PRI3(n, m, o) cout << n << " " << m<< " " << o << endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REP1(i, n)  for(int i = 1; i <= (int)n; ++i)
#define REPT(i, t, n)  for(int i = t; i <= (int)n; ++i)
const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;
typedef pair<int, int> Pi;

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll dp[100010][3];
ll ABC[100010][3];

int N, K;

int main() {
    cin >> N;
    int a, b, c;
    REP(i, N) {
        cin >> a >> b >> c;
        ABC[i][0] = a;
        ABC[i][1] = b;
        ABC[i][2] = c;
    }
    dp[0][0] = ABC[0][0];
    dp[0][1] = ABC[0][1];
    dp[0][2] = ABC[0][2];
    REP1(i, N) {
        REP(j, 3) {
            REP(k, 3) {
                if (k == j)continue;
                dp[i][k] = max(dp[i][k], dp[i-1][j] + ABC[i][k]);
            }
        }

    }
    cout << max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2])) << endl;
    return 0;
}


Measured memory_bytes: 4992
program AGC029A
    implicit none
    integer(8)::i,slen,ans,bcount
    character(200000)::S
    read*,S
    slen=len_trim(S)
    ans=0
    bcount=0
    do i=1,slen
        if(S(i:i)=="W")ans=ans+bcount
        if(S(i:i)=="B")bcount=bcount+1
    end do

    print'(i0)',ans
end program AGC029A

Measured memory_bytes: 1084
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int main()
{    
	string a;
	cin>>a;
	int ans=0;
	for(int i=0;i<a.size()-1;i++)
	{
		if(a[i]!=a[i+1])
			ans++;
	}
	cout<<ans;
	return 0;
}

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

void run(void){
  int n;
  scanf("%d",&n);
  double *dp=(double *)calloc(n+1,sizeof(double));
  dp[0]=1;
  int i;
  for(i=1;i<=n;i++){
    double p;
    scanf("%lf",&p);
    for(int j=i;j>0;j--){
      dp[j]=dp[j]*(1-p)+dp[j-1]*p;
    }
    dp[0]=dp[0]*(1-p);
  }
  double sum=0;
  for(i=n;i>n-i;i--) sum+=dp[i];
  printf("%.9f\n",sum);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
$n=<>;$h[$|--]{$_}--for glob<>;($u,$x,$v,$y)=map$h[$i++/2]{$_},@a=map{(sort{$$_{$a}-$$_{$b}}keys%$_)[0,1]}@h;print$n+("@a"-$a[2]?$u+$v:$u+$y-($-=$u+$y-$v-$x))

Measured memory_bytes: 30208
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>

using namespace std;


int main(){
  int N;
  while(scanf("%d",&N),N){
   set<int> men[50];
   set<int> days[30];
    for(int i=0;i<N;i++){
      int d;
      scanf("%d",&d);
      men[i].insert(i);
      for(int j=0;j<d;j++){
	int f;
	scanf("%d",&f);
	days[f-1].insert(i);
	
      }
    }
    int i=0;
    for(;i<31;i++){
      for(int j=0;j<N;j++) if((int)men[j].size() == N) goto F;
      set<int> sum;
      for(set<int>::iterator it=days[i].begin();it!=days[i].end();it++){
	for(set<int>::iterator itr=men[*it].begin();itr!=men[*it].end();itr++){
	  sum.insert(*itr);
	}
      }
      for(set<int>::iterator it=days[i].begin();it!=days[i].end();it++){
	men[*it]=sum;
      }
    }
  F:
    if(i == 31)
      printf("-1\n");
    else
      printf("%d\n",i);
    
  }
}

Measured memory_bytes: 1176
N , M = gets.split.map!{|i| i.to_i}

x = gets.split.map!{|i| i.to_i}
x.sort!

sum = 0
min = 0

if N >= M 
    puts 0
else
    l = Array.new(M-1,0)
    for i in 1..x.size-1
        l[i-1] = x[i] - x[i-1]
    end

    l.sort!{|a,b| -a <=> -b}

    for i in 0..N-2
        sum += l[i]
    end

    puts x[x.size-1] - x[0] - sum
end

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

int64_t gcd(int64_t a, int64_t b) {
    if(!b)
        return a;
    return gcd(b, a % b);
}

bool canMake(int64_t a, int64_t step, int64_t b, int64_t low, int64_t high) {
    if(high < low)
        return false;
    a %= b;
    if(a >= low and a <= high)
        return true;
    
    if(a > high) {
        int64_t times = (b - a + step - 1) / step;
        a += (times * step);
        a %= b;
    }

    if(a < low) {
        int64_t times = (low - a + step - 1) / step;
        a += times * step;
        if(a >= low and a <= high)
            return true;
        return false;
    } 

    return false;
}

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

    while(t--) {
        int64_t A = 0, B = 0, C = 0, D = 0;
        cin >> A >> B >> C >> D;
            
        //case1: B > A
        if(B > A) {
            cout << "No\n";
            continue;
        }
        
        //case2: D < B
        if(D < B) {
            cout << "No\n";
            continue;
        }
        
        //case 3: B <= C
        if(B <= C) {
            cout << "Yes\n";
            continue;
        }
        
        int64_t G= gcd(B, D);
        if(canMake(A, G, B, C + 1, B - 1))
            cout << "No\n";
        else
            cout << "Yes\n";
    }
}

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

public class Main {
    static final int         MAX = 200000;
    public static void main(String[] args) throws Exception {
        // 入力
        int             n = 0;
        int[]           A = new int[MAX];
        try (BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));) {
            n = Integer.parseInt(br.readLine());
            String[]        lines = br.readLine().split(" ");
            for (int i = 0; i < n; i++) {
                A[i] = Integer.parseInt(lines[i]);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        long        ans = mergeSort(A, n, 0, n);

        // 出力
/*        StringBuilder       sb = new StringBuilder();
        sb.append(A[0]);
        for (int i = 1; i < n; i++) {
            sb.append(" ");
            sb.append(A[i]);
        }
        System.out.println(sb);
*/
        System.out.println(ans);
    }

    static long mergeSort(int[] A, int n, int left, int right) {
        int         mid = 0;
        long        c1, c2, c3;
        if (left + 1 < right) {
            mid = (left + right) / 2;
            c1 = mergeSort(A, n, left, mid);
            c2 = mergeSort(A, n, mid, right);
            c3 = merge(A, n, left, mid, right);
            return c1 + c2 + c3;
        } else {
            return 0;
        }
    }

    static int[]       L = new int[MAX / 2 + 2];
    static int[]       R = new int[MAX / 2 + 2];
    static final int        SENTINEL = 2000000000;
    static long merge(int[] A, int n, int left, int mid, int right) {
        int         n1 = mid - left;
        int         n2 = right - mid;
        for (int i = 0; i < n1; i++) L[i] = A[left + i];
        for (int i = 0; i < n2; i++) R[i] = A[mid + i];
        L[n1] = SENTINEL;
        R[n2] = SENTINEL;

        long        c = 0;
        int     iteratorL = 0;
        int     iteratorR = 0;
        for (int i = left; i < right; i++) {
            if (L[iteratorL] <= R[iteratorR]) {
                A[i] = L[iteratorL];
                iteratorL++;
            } else {
                A[i] = R[iteratorR];
                iteratorR++;
                c += n1 - iteratorL;
            }
        }

        return c;
    }
}



Measured memory_bytes: 57700
#include <cstdio>
#include <algorithm>
#include <tr1/unordered_set>
using namespace std;

int n , v[20] , ans = 0;

tr1::unordered_set<int> memo[20];

int X[421] , Y[421] , top;
 
int main(){
	while(scanf("%d\n",&n)&& n){
		for(int i = 0 ; i < n ; i++) scanf("%d",&v[i]) , memo[i].clear() ;
		ans = 99999999;
		top = 0;
		X[top] = 0;
		Y[top] = 0;
		while(~top){
			int pos = X[top] , sum = Y[top]; top--;
			if(pos==n) ans = min(ans,sum);
			else{
				if(memo[pos].count(sum)) continue;
				else memo[pos].insert(sum);
				X[++top] = pos+1;
				Y[top]   = sum+v[pos];
				X[++top] = pos+1;
				Y[top]   = abs(sum-v[pos]);
			}
		}
		printf("%d\n",ans);
	}
}

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

using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    bool b=false;
    for(ll i=0;i<s.size()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            b=true;
        }
    }
    if(b)
    {
        cout<<"Bad\n";
    }
    else
        cout<<"Good\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

int main(void){
    string a;
    cin >> a;
    a[3] = '8';
    cout << a << endl;
}


Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

const int MAX_N=100010;
int par[MAX_N];
int myrank[MAX_N];

void init(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		myrank[i]=0;
	}
}

pii find(int x){
	if(par[x]==x){
		return make_pair(x,myrank[x]);
	}else{
		pii p=find(par[x]);
		myrank[x]+=p.second;
		par[x]=p.first;
		return make_pair(par[x],myrank[x]);
	}
}

void unite(int x,int y,int w){
	int px=find(x).first;
	int py=find(y).first;
	int w2=w-(myrank[y]-myrank[py])+(myrank[x]-myrank[px]);
	if(px==py)return;
	if(w2<0){
		w2=-w2;
		swap(px,py);
	}

	par[py]=px;
	myrank[py]=w2;
}

bool same(int x,int y){
	return find(x).first==find(y).first;
}

int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		init(n+1);
		REP(i,m){
			char q;
			int a,b,w;
			cin>>q>>a>>b;
			if(q=='!'){
				cin>>w;
				unite(a,b,w);
			}else{
				if(same(a,b)){
					cout<<myrank[b]-myrank[a]<<endl;
				}else{
					cout<<"UNKNOWN"<<endl;
				}
			}
		}
	}
}

Measured memory_bytes: 2980
#include<cstdio>
#include<iostream>
using namespace std;
#include<cmath>
long long int a,b,c;
int main() 
{
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0) {
        cout<<0;
        return 0;
    }
    cout<<min(min(a*b,a*c),b*c);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    final static Integer LEN = 105;
    public static void main(String args[]){
	Integer[][] graph = new Integer[LEN][LEN];
	Integer[] minCost = new Integer[LEN];
	int count=0;
	int v;
	Boolean[] used = new Boolean[LEN];

	Scanner in = new Scanner(System.in);

	//read
	int n = in.nextInt();
	for(int i=0; i<n; i++){
	    for(int j=0; j<n; j++){
		int k = in.nextInt();
		graph[i][j]=(k==-1? Integer.MAX_VALUE : k);
	    }
	}

	//make prim
	for(int i=0; i<n; i++){
	    minCost[i]=Integer.MAX_VALUE;
	    used[i]=false;
	}

	minCost[0]=0;

	while(true){
	    v = -1;
	    for(int i=0; i<n; i++){
		if(!used[i] && (v==-1 || minCost[i] < minCost[v]))v=i;
	    }

	    if(v==-1)break;
	    used[v]=true;
	    count+=minCost[v];

	    for(int i=0; i<n; i++){
		minCost[i]=Math.min(minCost[i], graph[v][i]);
	    }
	}

	//print
	System.out.println(count);
    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;
long long pow_mod(long long x, long long y, long long mod) {
	auto ret=1ll;
	while (y) {
			if (y % 2)
				ret = ret * x % mod;
			x =  x * x % mod;
			y /= 2;
		}
	return ret;
}

void solve()
{
	string s;
	cin >> s;

	long long ans = 0;
	auto one_cnt = 0;
	for(auto i = 0; i < s.size(); ++i)
	{
		if(s[i] == '1') {
			ans = (ans + pow_mod(2, one_cnt, MOD) * pow_mod(3, s.size() - i - 1, MOD) % MOD) % MOD;
			one_cnt++;
		}
	}

	ans = (ans + pow_mod(2, one_cnt, MOD)) % MOD;
	cout << ans << endl;
}

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
}

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

int main() {
	int n;
  	cin>>n;
  
	int ml=n+1,res=0;
  
  	for(int i=0;i<n;i++){
    	int p;cin>>p;
      	ml=min(ml,p);
      if(ml==p)++res;
           
    	
    }
  cout<<res<<endl;
    
}

Measured memory_bytes: 3516
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

ll A[5*1010];
ll B[5*1010][210];
ll mB[210];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D;cin>>D;
  cout << "Christmas";
  repeat(i,25-D){
    cout << " Eve";
  }
  cout << endl;
  return 0;
}


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

using namespace std;

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

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100010

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

ll DP[MAX];

//
int main(){
	int N,W;cin>>N>>W;
	V we(N),va(N);
	REP(i,N)cin>>we[i]>>va[i];

	fill(DP,DP+MAX,-1);
	DP[0]=0;
	REP(i,N){
		for(int j=W;j>=we[i];--j){
			if(DP[j-we[i]]==-1)continue;
			DP[j] = max(DP[j],DP[j-we[i]]+va[i]);
		}
	}

	ll ans = 0;
	REP(i,W+1){
		ans = max(ans,DP[i]);
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!

    var ans = 0
    var zero = if (s[0] == '0') 1 else 0

    var r = 0
    for (l in (0 until n)) {

        if (l > 0 && s[l - 1] == '0' && s[l] == '1') {
            zero--
        }

        while (r < n && zero <= k) {
            if (r > l && s[r - 1] == '1' && s[r] == '0') {
                zero++
            }
            r++
        }
        ans = Math.max(ans, r - l - if (zero > k) 1 else 0)
    }

    println(ans)
}


Measured memory_bytes: 38948
import math
import collections
from operator import mul
from functools import reduce

L,R=map(int,input().split())

if R-L>=2019:
    print(0)
    exit()

L%=2019
R%=2019

if L>=R:
    print(0)
    exit()


m=1000000000000000000;
for i in range(L,R):
    for j in range(i+1,R+1):
        m=min(m,(i*j)%2019)
print(m)


Measured memory_bytes: 40812
=begin
－－－－－－－－－－－－－－ 
A = 100*A 水
B = 100*B 水
C,D = １回の投入可能砂糖量
E = 100(g)あたりに溶かすことのできる砂糖量
F = ビーカー許容量(水 + 砂糖 = 総質量)
sugar = F 質量内でできる砂糖の質量を格納(Ci + Dj を組み合わせてできる質量の列挙)
water = F 質量内でできる水の質量を格納(100Ai + 100Bjの組み合わせでできる質量の列挙)
sum = water[i]とsugar[j]の総質量
pos = water[i] に溶かせる砂糖量
con = sugar[j]*100 / (sugar[j] + water[i])  の砂糖濃度(%)
ans = 答え
－－－－－－－－－－－－－－
=end

A,B,C,D,E,F = gets.split.map(&:to_i);

water = [];
(0..30).each{|i|
  (0..30).each{|j|
    x = (100*A*i) + (100*B*j);
    water << x if x <= F;
  }
}
water.sort!.uniq!;

sugar = []
(0..F).each{|i|
  (0..F).each{|j|
    y = C * i + D * j;
    sugar << y if y <= F;
  }
}
sugar.sort!.uniq!;

sum_ans = 0;
sugar_ans = 0;
dif = -1;
con = 0.0;

water.each{|w|
  pos = w / 100 * E;
  sugar.each{|s|
    sum = w + s;
    next if pos < s || F < sum
    con = (s*100) / (s + w).to_f;
    if dif < con
      sum_ans = sum;
      sugar_ans = s;
      dif = con;
    end
  }
}

puts "#{sum_ans} #{sugar_ans}"

Measured memory_bytes: 6008
fun main(args: Array<String>) {
    while (true) {
        var s = readLine()!!.toString() //最初の文字列
        if (s == "-") break
        val m = readLine()!!.toInt() //シャッフル回数
        val h = (0 until m).map { readLine()!!.toInt() }
        h.forEach { i ->
            s = s.slice(i until s.length) + s.slice(0 until i)
        }
        println(s)
    }
}


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

int main()
{
	string ans;
	long long n;

	cin >> n;

	if( n == 0 ) {
		ans = "0";
	}
	else {
		for( long long i = 0; abs(n) > 0; i++ ) {
			long long bit = 1LL << i;
			if( i % 2 ) {
				bit = -bit;
			}
			long long r = n % (1LL << (i + 1) );
			if( r ) {
				n -= bit;
				ans += "1";
			}
			else {
				ans += "0";
			}

		}
		reverse( ans.begin(), ans.end() );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
//chiragjn
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define gibe_de_fast_io_b0ss ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF/2;
int main(){
    gibe_de_fast_io_b0ss;
    ll k, a, b;
    cin>>k>>a>>b;
    ll c = b - a;
    ll ans = 0;
    if(c > 2 && k >= a + 1LL) {
        k -= (a + 1LL);
        ans = b;
        ans += c * (k / 2LL);
        ans += (k % 2);
        cout<<ans;
    }
    else {
        cout<<(k + 1);
    }
    return 0;
}

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

#define int long long
int N;
int A[200000], B[200000], C[200000];

signed main() {
  cin >> N;
  vector<int> xs, ys;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    xs.push_back(A[i]);
    ys.push_back(A[i]);
  }
  for (int i=0; i<=N; i++) {
    B[i] = N+1000;
  }
  B[0] = 0;
  xs.push_back(0);
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i=0; i<N; i++) {
    int h = lower_bound(xs.begin(), xs.end(), A[i]) - xs.begin();
    B[h] = min(B[h], i);
  }

  int l = N+1000;
  for (int i=xs.size()-2; i>=0; i--) {
    int a = xs[i+1], b = xs[i];
    int s = N - (upper_bound(ys.begin(), ys.end(), b) - ys.begin());
    l = min(l, B[i+1]);
    C[l] += (a-b)*s;
  }
  for (int i=0; i<N; i++) {
    cout << C[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 6124
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
pair<ll,ll> z[30];
map<ll,ll>p;
int main(){
    ll cnt,ans=1e11;
    string s,t;
    cin>>s;
    rep(i,0,26){
        char x=i+'a';
        t=s;
        cnt=0;
        while(cnt<s.length()){
            p.clear();
            ll tl=t.length();
            rep(j,0,tl)p[t[j]-'a']++;
            if(p.size()==1)break;
            rep(j,1,tl)if(t[j]==x)t[j-1]=x;
            t.erase(tl-1);
            cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{
  int p,l,r;
};

Node T[MAX];
int n, D[MAX];

void print( int s ){
  int i, c;
  cout << "node " << s << ": ";
  cout << "parent = " << T[s].p << ", ";
  cout << "depth = " << D[s] << ", ";

  if( T[s].p == NIL )cout << "root, ";
  else if( T[s].l == NIL )cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";
  for( i = 0, c = T[s].l ; c != NIL ; i++, c = T[c].r ){
    if( i )cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int rec( int s, int p ){
  D[s] = p;
  if( T[s].r != NIL )rec( T[s].r, p );
  if( T[s].l != NIL )rec( T[s].l, p + 1 );
}

int main( void ){
  int i,j,a,b,c,l,r;
  cin >> n;
  for( i = 0 ; i < n ; i++ ){
    T[i].p = T[i].l = T[i].r = NIL;
  }
  for( i = 0 ; i < n ; i++ ){
    cin >> b >> a;
    for( j = 0 ; j < a ; j++ ){
      cin >> c;
      if( j == 0 )T[b].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = b;
    }
  }
  for( i = 0 ; i < n ; i++ ){
    if( T[i].p == NIL )r = i;
  }

  rec( r, 0 );
  for( i = 0 ; i < n ; i++ )print(i);

  return 0;
}

Measured memory_bytes: 5844
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
#define DUMP1(A) do { for (auto &a : A) cout << a << ' '; cout << '\n'; } while (0)
#define DUMP2(A) do { for (auto &row : A) { DUMP1(row); } } while (0)
int main() {
    int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K;
    cout << H2 * 60 + M2 - (H1 * 60 + M1) - K << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <vector>
#include <climits>

class Graph{
public:
	std::vector< std::vector<int> > A;
	int n;

	Graph(int n);

	void SetEdge(int a, int b, int weight);
	void SortEdge();
	void SortEdge_Rec1(int left, int right);
	void SortEdge_Rec2(int left, int mid, int right);

	std::vector<int> Dijkstra();

};

Graph::Graph(int n){
	A.resize(n);
	for (int i = 0; i < n; i++) A[i].resize(n, -1);
	this->n = n;
}

void Graph::SetEdge(int a, int b, int weight){
	A[a][b] = weight;
	return;
}
/*
void Graph::SortEdge(){
	SortEdge_Rec1(0, A.size());
}

void Graph::SortEdge_Rec1(int left, int right){
	if (left + 1 < right){
		int mid = (left + right) / 2;
		SortEdge_Rec1(left, mid);
		SortEdge_Rec1(mid, right);
		SortEdge_Rec2(left, mid, right);
	}
}

void Graph::SortEdge_Rec2(int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	std::vector< std::vector<int> > L(n1 + 1);
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	std::vector< std::vector<int> > R(n2 + 1);
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	std::vector<int> x;
	x.push_back(0); x.push_back(0); x.push_back(INFTY);
	L[n1] = x;
	R[n2] = x;
	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++){
		if (L[i][2] <= R[j][2]){
			A[k] = L[i];
			i = i + 1;
		}
		else{
			A[k] = R[j];
			j = j + 1;
		}
	}
}
*/
std::vector<int> Graph::Dijkstra(){
	std::vector<int> d(n, INT_MAX), prev(n, -1), Q(n, 0);
	d[0] = 0;
	for (int i = 0; i < n; i++) Q[i] = i;

	while (!Q.empty()){
		int mini, minu;
		for (int i = 0; i < Q.size(); i++){
			if (i == 0 || d[Q[i]] < d[minu]){
				minu = Q[i];
				mini = i;
			}
		}
		Q.erase(Q.begin() + mini);
		for (int i = 0; i < n; i++){
			if (A[minu][i] != -1){
				if (d[i] > d[minu] + A[minu][i]){
					d[i] = d[minu] + A[minu][i];
					prev[i] = minu;
				}
			}
		}
	}
	return d;
}

int main(){
	int n, u, k, v, c;
	scanf("%d", &n);
	Graph G(n);
	for (int i = 0; i < n; i++){
		scanf("%d%d", &u, &k);
		for (int j = 0; j < k; j++){
			scanf("%d%d", &v, &c);
			G.SetEdge(u, v, c);
		}
	}
	std::vector<int> result = G.Dijkstra();
	for (int i = 0; i < n; i++) printf("%d %d\n", i, result[i]);

	return 0;
}


Measured memory_bytes: 3292
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void)
{
  int a, b, K, i, j, k, tmp, X[100001], ans;
  double S;
  scanf("%d %d", &a, &b);
  if (a < b)
  {
    tmp = a;
    a = b;
    b = tmp;
  }
  for (i = 0; i < a; i++)
  {
    printf("%d", b);
  }
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  string s;
  ll make = 0;

  cin >> s;
  for(ll i=0; i<s.length(); i++) {
    if(s[i] == 'x') {
      make++;
    }
  }

  if(make >= 8) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    double R;
    cin >> R;
    cout << fixed << setprecision(10) << 2 * PI * R << endl;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    int p = 3 * N + K;
    cout << (p / 2) << endl;
}

Measured memory_bytes: 3572
w,h,n=map(int,input().split())
x_min=0
x_max=w
y_min=0
y_max=h

for i in range(n):
  x,y,a=map(int,input().split())  
  if a==1:
    x_min=max(x_min,x)
  elif a==2:
    x_max=min(x_max,x)      
  elif a==3:
    y_min=max(y_min,y)
  else:
    y_max=min(y_max,y)
  #print(x_min,x_max,y_min,y_max)
print( max(0,x_max-x_min)*max(0,y_max-y_min) )

Measured memory_bytes: 38384