akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 100005

ll inv[N], fac[N], finv[N];

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
#define N 100005
int n, k;
int h[N];
int dp[N];
int dpf(int i)
{
	if(i >= n)
		return 1e9;
	if(i == n - 1)
		return 0;
	if(dp[i] >= 0)
		return dp[i];
	dp[i] = 1e9;
	for (int j = 1; j <= k; ++j)
	{
		dp[i] = min(dp[i], abs(h[i + j] - h[i]) + dpf(i + j));
	}
	return dp[i];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> k;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
		dp[i] = -1;
	}
	// dp[1] = abs(h[1] - h[0]);
	// dp[0] = 0;
	// for(int i = 2; i < n; ++i)
	// {
	// 	dp[i] = 1e9 + 2;
	// 	for(int j = 1; j <= k; ++j)
	// 	{
	// 		dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
	// 	}
	// }
	int ans = dpf(0);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5760
import sys
from collections import deque
s=sys.stdin.readlines()
n,q=map(int,s[0].split())
d=deque(e.split()for e in s[1:])
t=0
while d:
 k,v=d.popleft()
 v=int(v)
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t)


Measured memory_bytes: 20984
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

########################################################################################################################################################################

show_flg=False
show_flg=True

ans=0


n=I()
a=LI()
p=a[0]

x=1000
t=0
s=0
for i in range(n):
    if p<a[i]:
        s=x//p
        #t+=s
        x+=s*(a[i]-p)
    #show(x,s,a[i],p)
    p=a[i]
    
print(x)

Measured memory_bytes: 78468
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var s = nextstr();
  return s.slice(0,3);
}

Measured memory_bytes: 29548
n = input().split()
W = int(n[0])
H = int(n[1])
x = int(n[2])
y = int(n[3])
r = int(n[4])

top = y + r
bottom = y - r
right = x + r
left = x - r

if top <= H and bottom >= 0 and right <= W and left >= 0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 7668
package main

import (
	"fmt"
)

func min(a ...int) int {
	r := a[0]
	for i := 1; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func max(a ...int) int {
	r := a[0]
	for i := 1; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func createMemo(s1, s2 string) []bool {
	n := len(s1)
	ret := make([]bool, n)
	for i := 0; i < n; i++ {
		ok := true
		for j := i; j < n; j++ {
			if j-i >= len(s2) {
				break
			}
			if s1[j] == '?' || s2[j-i] == '?' {
				continue
			}
			if s1[j] != s2[j-i] {
				ok = false
				break
			}
		}
		ret[i] = ok
	}
	return ret
}

func minStr(s ...string) int {
	const mx = 2001
	memo := [3][]bool{}
	memo[0] = createMemo(s[0], s[1])
	memo[1] = createMemo(s[1], s[2])
	memo[2] = createMemo(s[0], s[2])

	ret := mx * 3
	for i := 0; i <= mx; i++ {
		if i < len(s[0]) && !memo[0][i] {
			continue
		}
		for j := 0; j <= mx; j++ {
			if j < len(s[1]) && !memo[1][j] {
				continue
			}
			if i+j < len(s[0]) && !memo[2][i+j] {
				continue
			}
			l := max(len(s[0]), i+len(s[1]), i+j+len(s[2]))
			if ret > l {
				ret = l
			}
		}
	}
	return ret
}

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	fmt.Println(min(
		minStr(a, b, c),
		minStr(a, c, b),
		minStr(b, a, c),
		minStr(b, c, a),
		minStr(c, a, b),
		minStr(c, b, a)))
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main(){
int ans=0,k,s;
	cin >> k >> s;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
				if (0<=s-(i+j)&&s-(i+j)<=k)ans++;
			
		}
	}
	cout << ans << endl;
	return 0;
}

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

struct Node
{
	int key;
	Node* prev;
	Node* next;
};

Node* head;

void init()
{
	head = (Node*)malloc(sizeof(Node));
	head->next = head;
	head->prev = head;
}

void insert(int key)
{
	Node* x = (Node*)malloc(sizeof(Node));
	x->key = key;

	x->next = head->next;
	head->next->prev = x;

	x->prev = head;
	head->next = x;
}

Node* listSearch(int key)                
{
	Node *se = head->next;
	while (true)
	{
		if (se == head || se->key==key)
			break;
		se = se->next;
	}
	return se;
}

void deleteNode(Node* t)
{
	if (t == head)
		return;
	t->prev->next = t->next;
	t->next->prev = t->prev;

	free(t);
}

void deleteFirst()
{
	deleteNode(head->next);
}

void deleteLast()
{
	deleteNode(head->prev);
}

void deleteKey(int key)
{
	deleteNode(listSearch(key));
}

void printList()
{
	Node* cur = head->next;
	int i = 0;
	while (true)
	{
		if (cur == head)
			break;
		if (i++ > 0)
			cout << " ";
		cout << cur->key;
		cur = cur->next;
	}
	cout << endl;
}

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

	int n, x;
	string operate;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> operate;

		if (operate == "insert")
		{
			cin >> x;
			insert(x);
		}
		else if (operate == "deleteFirst")
			deleteFirst();
		else if (operate == "deleteLast")
			deleteLast();
		else
		{
			cin >> x;
			deleteKey(x);
		}
	}

	printList();

	return 0;
}




Measured memory_bytes: 34420
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int main(){
        int A, B, C, X, Y;
        cin >> A >> B >> C >> X >> Y;
        int cost = 0;
        if(C * 2 <= A + B){
            while(X >= 1 && Y >= 1){
                cost += C * 2;
                X--;
                Y--;
            }
        }

                if(X > 1 && A > C * 2){
                  cost += X * (C * 2);
                  Y -= X;
                }else{
                    cost += X * A;
                }

                if(Y > 1 && B > C * 2){
                  cost += Y * (C * 2);
                }else{
                    cost += Y * B;
                }

        cout << cost << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
	char name[30][21];
	int wei[30],safe[30],perm[30];
	for(int n;scanf("%d",&n),n;){
		for(int i=0;i<n;i++){
			scanf("%s%d%d",name[i],&wei[i],&safe[i]);
			perm[i]=i;
		}

		int opt[30];
		double gopt=-1;
		do{
			bool b=true;

			int wsum=0,g=0;
			for(int i=0;i<n;i++){
				int now=perm[i];
				if(wsum>safe[now]){
					b=false;
					break;
				}
				wsum+=wei[now];
				g+=(i+1)*wei[now];
			}

			if(!b)	continue;

			if(gopt<(double)g/wsum){
				gopt=(double)g/wsum;
				for(int i=0;i<n;i++)	opt[i]=perm[i];
			}
		}while(next_permutation(perm,perm+n));

		for(int i=n-1;i>=0;i--)	puts(name[opt[i]]);
	}

	return 0;
}

Measured memory_bytes: 736
N=gets.to_i
V=(1..5e2).find{|i|i*~-i/2==N}
V ? (e=V.times.map{[V-1]}
V.times{|i|i.times{|j|e[i]<<$.
e[j]<<$.
$.+=1}}
puts:Yes,V,e.map{|a|a*" "}):$><<"No"

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

void solve(int n, vector<int>h, int k){
  vector<ll>dp(n, INF);
  dp[0] = 0;
  for (int i=0; i<n; i++){
    for (int j=i+1; j<=k+i; j++){
      if (j<n){  
        dp[j] = min(
          dp[j],
          dp[i] + abs( h[i] - h[j] )
        );
      }
    }
  }
  cout << dp[n-1];
}

int main(){
  int n,k; cin>>n>>k;
  vector<int>h(n); rep(i,n) cin>>h[i];
  solve(n,h,k);
}

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

int main() {
	int c, a, n, i, k, j, t = 0;
	cin >> k;
	for(i = 1; i <= k; i++) {
		cin >> c >> a >> n;
		for (j = c; j != 0; j--) {
			if (c != 0 && a != 0 && n != 0) {
				c--;
				a--;
				n--;
				t++;
			}else if (c >= 2 && a != 0) {
				c = c - 2;
				a--;
				t++;
			}else if (c >= 3) {
				c = c - 3;
				t++;
			}
		}
		cout << t << endl;
		t = 0;
	}
}


Measured memory_bytes: 3080
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1LL << 60;

double f(double v, double left, double right, double t) {
  return min(v, min(t + left, -t + right));
}

double calc(double v, double t0, double t1, double left, double right) {
  // cout << t0 << ":" << t1 << ":" << left << ":" << right << endl;
  set<double> tlist;
  tlist.insert(t0);
  tlist.insert(t1);
  tlist.insert(v - left);
  tlist.insert(right - v);
  tlist.insert((right - left) / 2.0);
  double pt = -1, py;
  bool start = false;
  double ans = 0;
  for (auto& t : tlist) {
    if (!start) {
      if (t == t0) {
        start = true;
        pt = t;
        py = f(v, left, right, t);
      }
    } else {
      if (t <= t1) {
        ans += (py + f(v, left, right, t)) * (t - pt) / 2.0;
        py = f(v, left, right, t);
        // cout << t << ":" << py << "," << ans << endl;
        pt = t;
      } else {
        break;
      }
    }
  }
  return ans;
}

int main() {
  ll n;
  cin >> n;
  vl t(n), v(n), ts(n);
  rep(i, n) { cin >> t[i]; }
  ts[0] = t[0];
  REP(i, 1, n) { ts[i] = ts[i - 1] + t[i]; }
  rep(i, n) cin >> v[i];
  vl left(n), right(n);
  left[0] = 0;
  right[n - 1] = ts[n - 1];
  REP(i, 1, n) {
    if (v[i] >= v[i - 1]) {
      left[i] = min(left[i - 1], v[i - 1] - ts[i - 1]);
    } else {
      left[i] = left[i - 1];
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    if (v[i] >= v[i + 1]) {
      right[i] = min(right[i + 1], v[i + 1] + ts[i]);
    } else {
      right[i] = right[i + 1];
    }
  }
  double ans = 0;
  rep(i, n) {
    ll t0 = 0;
    if (i > 0) t0 = ts[i - 1];
    ll t1 = ts[i];
    ans += calc(v[i], t0, t1, left[i], right[i]);
  }
  cout << setprecision(5) << fixed << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(auto i=a;i<n;i+=x)
#define forD(i,a,n,x) for(auto i=n-1;i>=0;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define init(a,x) memset(a,x,sizeof(a))

ld c[3003]; 

void solve1(ll n)
{
	ld dp[n+1][n+1];
	forA(i,0,n+1,1)forA(j,0,n+1,1)dp[i][j]=0;
	forA(i,0,n+1,1)
	{
		ll tails = n-i; if(i>tails)dp[0][i]=1.0; else dp[0][i]=0.0;
	}

	forA(i,1,n+1,1)
	{
		forA(j,0,n-i+1,1)
		{
			ld hp = c[i-1];  ld tp = 1.0-hp; 
			dp[i][j]= hp*dp[i-1][j+1] + tp*dp[i-1][j];
		}
	}
 cout<<fixed<<setprecision(10)<<dp[n][0]<<"\n";
}

int main()
{
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	ll n; cin>>n; forA(i,0,n,1)cin>>c[i];
	solve1(n);
	return 0;
}

Measured memory_bytes: 74112
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var nums = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var result = 0;
        for(var i = 0; i < num; i++)
        {
            while (nums[i] % 2 == 0)
            {
                result++;
                nums[i] /= 2;
            }
        }
        WriteLine(result);
    }
}

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

#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

long long int maxv(long long int R[],long long int n){
    long long minv = pow(10,10);
    long long  maxv = -pow(10,10);
    REP(j,n){
        maxv = max(maxv,R[j]- minv);
        minv = min(minv,R[j]);
    } 
    return maxv;
}


int main(){
    long long int n;
    scanf("%lld",&n);
    long long int R[n];
    for (int i = 0; i < n; i++){
        scanf("%lld",&R[i]);
    }
    printf("%lld\n",maxv(R,n));
    return 0;
}


Measured memory_bytes: 4804
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int ll
#define For(a, b, c) for(int a = b; a <= c; ++a)
#define Ford(a, b, c) for(int a = b; a >= c; --a)
#define All(a, b) for(auto &a : b)
#define Rep(a, b, c) for(int a = b; a < c; ++a)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(a, b) memset(a, b, sizeof(a))
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define bitone(i) __builtin_popcountll(i)
#define bitl(i) __builtin_clz(i)
#define bitr(i) __builtin_ctz(i)
#define vll vector<ll>
/********************************************************

Digvijay Bahadur Singh
MNNIT

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


const int MOD=998244353;
const int N = 1e6+100;
/********************************************************************/
                 /* GRAPH*/
//vector<vector<ll>> g;
//vector<bool> vis1,vis2;
/*******************************************************************/
ll power(ll a,ll b)
{
   ll ans =1;
   while(b>0){
   if(b&1) ans = (ans%MOD * a%MOD)%MOD;
   a = (a%MOD * a%MOD)%MOD;
   b=b>>1;
   }
   return ans%MOD;
}
struct triple
{
  int f,s,t;
};
bool comp(triple x,triple y)
{
  if(x.f==y.f)
  {
    return x.s>y.s;
  }
  return x.f<y.f;
}
bool isPalindrome(string s)
{
  int n=s.length();
  int l=0,r=n-1;
  while(s[l]==s[r]&&l<r)
  {
    l++;
    r--;
  }
  if(n&1)
  return l==r;
  else
  {
    return r<l;
  }
  

}
signed main(){
  ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
  
  
  ll T=1;
 //cin>>T;
  
   // T=1;
    
    while(T--)
  {
     long double n;
     cin>>n;
     long double temp = 1.0*n/3;
     long double ans = temp*temp*temp;
     printf("%Lf\n",ans);
    
       
   
  

   
 


      

  }

  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s;

	cin>>s;

	if(s[5]>'0'||s[6]>'4'){
		cout<<"TBD"<<endl;
	} else{
		cout<<"Heisei"<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b == 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cout << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cout << v[i][j] << " ";} br;}}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, k; cin >> n >> k;
    ll ans = 0;
    ll tmp = 1;
    while(true){
        if(tmp > n){
            break;
        }else{
            tmp = tmp * k;
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3620
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<unordered_map>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int n, m,x; 
int arr[14][14];
int cost[14];

bool check(vector<int> v) {
	for (int i = 1; i <= m; i++)
		if (v[i] < x)
			return 0;
	return 1;
}

int fun(int ind,vector<int> v) {
	if (ind == n + 1)
		if (check(v))
			return 0;
		else
			return 1e9;
	if (check(v))
		return 0;
	int mn = fun(ind + 1, v);
	for (int i = 1; i <= m; i++)
		v[i] += arr[ind][i];
	return min(mn,cost[ind]+fun(ind + 1, v));
}

int main()
{
	cin >> n >> m >> x;
	for (int i = 1; i <= n; i++)
	{
		cin >> cost[i];
		for (int j = 1; j <= m; j++)
			cin >> arr[i][j];
	}
	vector<int>v(m+1, 0);
	ll z = fun(1, v);
	if (z >= 1e9)
		cout << -1;
	else
		cout << z;
	return 0;
}

Measured memory_bytes: 3636
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
for i in range(a-1,-1,-2):
    br.append(ar[i])
if a % 2 == 0:
    n = 0
else:
    n = 1
for i in range(n,a-1,2):
    br.append(ar[i])
for i in range(a-1):
    print(br[i],end=" ")
print(br[a-1])

Measured memory_bytes: 30984
s = input()
n = len(s)
ans = 'Yes'
for i in range(n):
    if i%2 == 0:
        if s[i] == 'R' or s[i] == 'U' or s[i] == 'D':
            ans = 'Yes'
        else:
            print('No')
            exit()

    else:
        if s[i] == 'L' or s[i] == 'U' or s[i] == 'D':
            ans = 'Yes'
        else:
            print('No')
            exit()

print(ans)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
int a[620][620], n, d1, d2, z;
void gao(int d) {
	int b = 0;
	while (d % 4 == 0) {
		d /= 4;
		b++;
	}
	if (d & 1) {
		for (int i = 0; i < 2 * n; i++) {
			for (int j = 0; j < 2 * n; j++) {
				if (((i >> b) + (j >> b)) & 1) {
					a[i][j] = 1;
				}
			}
		}
	} else {
		for (int i = 0; i < 2 * n; i++) {
			for (int j = 0; j < 2 * n; j++) {
				if ((i >> b) & 1) {
					a[i][j] = 1;
				}
			}
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &d1, &d2);
	gao(d1);
	gao(d2);
	for (int i = 0; i < 2 * n; i++) {
		for (int j = 0; j < 2 * n; j++) {
			if (z < n * n && !a[i][j]) {
				printf("%d %d\n", i, j);
				z++;
			}
		}
	}
	return 0;
}

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

vector<vector<int>> Graph;  //有向グラフ
vector<int> dp; //深さ(最大距離)
int N, M;
int x, y;
int MAX = 0;

int dsf(int n){
  if(Graph[n].size() == 0) return 0;
  if(dp[n] > 0) return dp[n];

  for(int j = 0; j < Graph[n].size(); j++){
    //cout << "n : " << n << " Graph[n][j] : " << Graph[n][j] << endl;
    dp[n] = max(dp[n], dsf(Graph[n][j])+1);
  }
  return dp[n];
  }
 
   
int main(){
  cin >> N >> M;
  Graph.resize(N+1, vector<int>()); 
  dp.resize(N+1, 0);

  for(int i = 0; i < M; i++){ cin >> x >> y; Graph[x].push_back(y); }
  for(int i = 1; i <= N; i++){ MAX = max(MAX, dsf(i)); }
  cout << MAX << endl;
  return 0;
}
  







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


void solve(long long X){
  for(long long a = -120; a <= 120; a++) {
    long long pow_a = pow(a, 5);

    for(long long b = -120; b <= 120; b++) {
      if(pow_a - pow(b, 5) == X) {
        cout << a << " " << b << endl;
        return;
      }
    }
  }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
  scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 4144
N = int(input())
h = list(map(int, input().split()))

INF = 10**18
dp = [INF] * 10**5
dp[0] = 0
dp[1] = dp[0] + abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])

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

int main()
{
	int N;
	string S;
	int W[300010]={};
	int w=0;
	int ans=3e5;
	
	cin >> N >> S;
	
	S="_"+S;
	for(int i=1;i<=N;i++)
	{
		if(S[i]=='W')
		{
			w++;
			W[i]++;
		}
		W[i]+=W[i-1];
	}
	
	for(int i=1;i<=N;i++)
		ans=min(ans,W[i-1]+(N-w)-(i-W[i]));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2180
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
template<class T> // [pair<Num, Num>]
vector<int> convex_hull(const T& ps) {
    vector<int> res;
    int i = min_element(begin(ps), end(ps)) - begin(ps);
    do {
        cerr << i << endl;
        res.push_back(i);
        int j = (i + 1) % ps.size();
        for (int k = 0; k < ps.size(); ++k) {
            if (k == i) continue;
            auto xi = ps[i].first, yi = ps[i].second,
                xj = ps[j].first - xi, yj = ps[j].second - yi,
                xk = ps[k].first - xi, yk = ps[k].second - yi;
            auto prod = xk * yj - xj * yk;
            
            // without points on lines
            if (prod > 0 || 
                (prod == 0 && xj * xj + yj * yj < xk * xk + yk * yk)) {
                j = k;
            }
        }
        i = j;
    } while (i != res.front());
    return res;
}
i64 n;
vector<pair<i64, i64>> ps;
int main() {
    cin >> n;
    ps.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> ps[i].first >> ps[i].second;
    }
    auto ch = convex_hull(ps);
    int m = ch.size();
    vector<double> res(n);
    double PI = acos(-1);
    for (int i = 0; i < m; ++i) {
        int pi = ch[i], ci = ch[(i - 1 + m) % m], ai = ch[(i + 1) % m];
        auto p = ps[pi], q = ps[ci], r = ps[ai];
        double f = atan2(double(q.second - p.second), double(q.first - p.first)),
               g = atan2(double(r.second - p.second), double(r.first - p.first));
        
        if (f > g) g += 2 * PI;
        // cerr << (f / PI * 180) << '\t' << (g / PI * 180) << endl;
        double a = g - f - PI;
        res[pi] = abs(a / (2.0 * PI));
    }
    for (int i = 0; i < n; ++i) {
        printf("%.10f\n", res[i]);
    }
    return 0;
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    string s;
    cin >> s;

    sort(ALL(s));

    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#define N 1002
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
int n, m;
bool prime[N];
int main() {
	cin>>n;
	memset(prime, false, sizeof(prime));
	vector<int>ps;
	ps.clear();
	for (int i = 2; i <= n; ++i) {
		if (!prime[i]) {
			ps.push_back(i);
			for (int j = i*i; j <= n; j+=i) {
				prime[j] = true;
			}
		}
	}
	ll ans=1LL;
	for (int i = 0; i < ps.size(); ++i) {
		int p = ps[i];
		int cnt=0;
		while(n / p) {
			cnt += n/p;
			p *= ps[i];
		}
		ans = ans*(ll)(cnt+1)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
ans = [1] * M
li = [i for i in range(1,M+1)]
for i in range(N):
    a = [int(i) for i in input().split()[1::]]
    for i in set(li) - set(a):
        ans[i-1] = 0

print(sum(ans))


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0)
    cout<<1;
  else if(b==0)
    cout<<2;
  else if(c==0)
    cout<<3;
  else if(d==0)
    cout<<4;
  else
    cout<<5;
}

Measured memory_bytes: 3520
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>

using namespace std;
const int INF=11;

int w,h;

int field[22][22];
int sx,sy;
int gx,gy;
int ans=INF;
int hx[4]={1,-1,0,0,},hy[4]={0,0,1,-1,};

void dfs(int field2[22][22],int x,int y,int mx,int my,int c){
	int a;
	if(c>10)return;
	if(c>ans)return;
	if(x>0 && x<=w && y>0 && y<=h);else return; 
	if(field2[x][y]==3){
		if(ans>c)ans=c;
		return;
	}
	if(field2[x+mx][y+my]==1){
		field2[x+mx][y+my]=0;
		for(a=0;a<4;a++){
			if(field2[x+hx[a]][y+hy[a]]!=1)dfs(field2,x,y,hx[a],hy[a],c+1);
		}
		field2[x+mx][y+my]=1;
	}else dfs(field2,x+mx,y+my,mx,my,c);
	return;
}

int main(void){
	int a,b;
	while(1){
		for(b=0;b<21;b++){
			for(a=0;a<21;a++){
				field[a][b]=0;
			}
		}
		ans=INF;
		sx=0;
		sy=0;
		gx=0;
		gy=0;
		cin >> w >> h;
		if(w==0 && h==0)break;
		for(b=1;b<=h;b++){
			for(a=1;a<=w;a++){
				cin >> field[a][b];
				if(field[a][b]==2)sx=a,sy=b,field[a][b]=0;
				if(field[a][b]==3)gx=a,gy=b;
				
			}
		}
		for(a=0;a<4;a++){
			if(field[sx+hx[a]][sy+hy[a]]!=1)dfs(field,sx,sy,hx[a],hy[a],1);
		}
		printf("%d\n",ans<=10?ans:-1);
	}
	return 0;
}

Measured memory_bytes: 868
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), m = inp.nextInt();
            LinkedList<Integer>[] graph = new LinkedList[n];
            LinkedList<Integer>[] parents = new LinkedList[n];
            for (int i = 0; i < n; i++) {
                graph[i] = new LinkedList<>();
                parents[i] = new LinkedList<>();
            }
            for (int i = 0; i < m; i++) {
                int x = inp.nextInt() - 1, y = inp.nextInt() - 1;
                graph[x].add(y);
                parents[y].add(x);
            }
            int[] dp = new int[n];
            int[] t = topologicalSort(graph);
            for (int node: t) {
                for (int parent: parents[node]) {
                    dp[node] = Math.max(dp[node], dp[parent] + 1);
                }
            }
            int res = 0;
            for (int i: dp) res = Math.max(res, i);
            out.print(res);
        }

        private static int[] topologicalSort(LinkedList<Integer>[] graph) {
            int n = graph.length;
            int[] in_degree = new int[n];
            for (int i = 0; i < n; i++) {
                for (int to: graph[i]) in_degree[to]++;
            }
            int[] res = new int[n];
            int j = 0;
            for (int i = 0; i < n; i++) {
                if (in_degree[i] == 0) res[j++] = i;
            }
            for (int i = 0; i < j; i++) {
                for (int to: graph[res[i]]) {
                    if (--in_degree[to] == 0) res[j++] = to;
                }
            }
            return res;
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}




Measured memory_bytes: 57848
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = long long;

int N, X[1000];

struct R {
    int a, b;
    R() {} R(int c, int d): a(c), b(d) {}
};

vector<int> children[1000];

int dp[5050];

R dfs(int v) {
    vector<R> cr;
    for (int w : children[v]) {
        R r = dfs(w);
        if (r.a == -1 && r.b == -1) {
            return R(-1, -1);
        }
        if (r.a > r.b) {
            swap(r.a, r.b);
        }
        cr.push_back(r);
    }
    int base = 0, ss = 0;
    vector<int> ds;
    for (R& r : cr) {
        base += r.a; ss += r.a + r.b;
        ds.push_back(r.b - r.a);
    }
    if (base > X[v]) {
        return R(-1, -1);
    }

    int L = X[v]-base;
    fill(dp, dp+L+1, 0);
    dp[0] = 1;
    for (const int& x: ds) {
        for (int k = L; k >= x; --k) {
            if (dp[k-x]) {
                dp[k] = 1;
            }
        }
    }
    int z = -1;
    for (int j = L; j >= 0; --j) {
        if (dp[j]) {
            z = j;
            break;
        }
    }
    if (z == -1) {
        return R(-1, -1);
    }
    return R(X[v], ss - (z+base));
}

int main() {
    cin >> N;
    for (int j = 0; j < N-1; ++j) {
        int p; cin >> p;
        children[--p].push_back(j+1);
    }
    for (int j = 0; j < N; ++j) {
        cin >> X[j];
    }

    R result = dfs(0);
    cout << (result.a == -1 || result.b == -1 ? "IMPOSSIBLE" : "POSSIBLE") << endl;
    return 0;
}


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

int main(){
  int a[5],k;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
      if(a[j] - a[i] > k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

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

   V<P<int,int>> p(n);
   for (int i = 0; i < n; i++) {
      p[i] = make_pair(a[i], i);
   }
   sort(p.begin(), p.end());

   int ans = 0;
   set<int> st{-1, n};
   for (int i = 0; i < n; i++) {
      int id = p[i].second;
      int l = *(--st.upper_bound(id));
      int r = *st.upper_bound(id);
      ans += (id - l) * (r - id) * a[id];
      st.insert(id);
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 14336
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int C = sc.nextInt();

        int TIME = 100001;
        int[][] acc = new int[TIME][C + 1];
        for (int i = 0; i < N; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            int c = sc.nextInt();

            acc[s][c] += 1;
            acc[t][c] -= 1;
        }

        for (int t = 1; t < TIME; t++) {
            for (int c = 1; c <= C; c++) {
                acc[t][c] = acc[t][c] + acc[t - 1][c];
            }
        }

        // 0.5秒分確保
        for (int t = 1; t < TIME; t++) {
            for (int c = 1; c <= C; c++) {
                if (acc[t][c] > 0 && acc[t - 1][c] != acc[t][c]) {
                    acc[t - 1][c] += acc[t][c];
                }
            }
        }

        int needMaxCnt = 0;
        for (int t = 1; t < TIME; t++) {
            int tmpMaxCnt = 0;
            for (int c = 1; c <= C; c++) {
                tmpMaxCnt += acc[t][c];
            }
            needMaxCnt = Math.max(needMaxCnt, tmpMaxCnt);
        }

        out.println(needMaxCnt);
    }
}

Measured memory_bytes: 113496
PROGRAM CitySavers
      IMPLICIT NONE
      integer(16) :: n
      integer(16),allocatable :: a(:),b(:),remB1(:),remB2(:)
      integer(16) :: i,ans=0
      
      
      read*,n
      allocate( a(n+1),b(n),remB1(n),remB2(n) )
      read*,a(1:n+1)
      read*,b(1:n)
      
      
      do i = n,1,-1
        remB1(i) = max( b(i)-a(i+1),0 )
        a(i+1) = a(i+1) - (b(i)-remB1(i))
        
        remB2(i) = max( remB1(i)-a(i),0 )
        a(i) = a(i) - (remB1(i) - remB2(i))
      end do
      
      !print*,a(1:n+1)
      !print*,remB2
      
      print*,sum( b(:) - remB2(:) )
      
      END PROGRAM

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
#define int long
#define fill(a) for(auto &i:a)cin>>i
#define all(a) (a).begin(),(a).end()
signed main(){
  int a,b,q;
  cin>>a>>b>>q;
  vector<int> sl(a),tl(b),sg,tg;
  fill(sl); fill(tl);
  sg=sl; tg=tl;
  sort(all(sg),greater<>());
  sort(all(tg),greater<>());
  while(q--){
    int x,inf=1e12;
    cin>>x;
    int s[2],t[2];
    auto snl=lower_bound(all(sl),x);
    auto sng=lower_bound(all(sg),x,greater<>());
    auto tnl=lower_bound(all(tl),x);
    auto tng=lower_bound(all(tg),x,greater<>());
    s[1]=(snl!=sl.end()?*snl:inf);
    s[0]=(sng!=sg.end()?*sng:inf);
    t[1]=(tnl!=tl.end()?*tnl:inf);
    t[0]=(tng!=tg.end()?*tng:inf);
    s[0]=abs(s[0]-x); s[1]=abs(s[1]-x); t[0]=abs(t[0]-x); t[1]=abs(t[1]-x);
    cout<<min({max(s[0],t[0]),max(s[1],t[1]),s[0]*2+t[1],t[0]*2+s[1],s[1]*2+t[0],t[1]*2+s[0]})<<"\n";
  }
}

Measured memory_bytes: 4480
import Control.Applicative
import Control.Monad
import System.IO.Unsafe
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

f n = if odd n then 0 else 1 + f (div n 2)

main = getInt >> getInts >>= print . minimum . map f

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  rep(i,N){
    cin >> A[i];
    sum += abs(A[i]);
  }
  sort(A.begin(),A.end());
  if(A[N-1] <= 0){
    cout << sum+A[N-1]*2 << endl;
    ll now = A[N-1];
    rep(i,N-1){
      cout << now << " " << A[i] << endl;
      now -= A[i];
    }
  }else if(A[0] >= 0){
    cout << sum-A[0]*2 << endl;
    ll now = A[0];
    for(int i=1; i<N-1; i++){
      cout << now << " " << A[i] << endl;
      now -= A[i];
    }
    cout << A[N-1] << " " << now << endl;
  }else{
    cout << sum << endl;
    int pos = lower_bound(A.begin(),A.end(),0) - A.begin();
    for(int i=pos; i<N-1; i++){
      cout << A[0] << " " << A[i] << endl;
      A[0] -= A[i];
    }
    for(int i=0; i<pos; i++){
      cout << A[N-1] << " " << A[i] << endl;
      A[N-1] -= A[i];
    }
  }
  return 0;
}


Measured memory_bytes: 2688
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

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

int main(){
  int N,M;
  scanf("%d%d",&N,&M);
  
  scc_graph g(N);
  rep(i,M){
    int a,b;
    scanf("%d%d",&a,&b);
    g.add_edge(a,b);
  }
  
  auto scc=g.scc();
  printf("%d\n",scc.size());
  for(auto v:scc){
    printf("%d ",v.size());
    for(int x:v){
      printf("%d ",x);
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 40592
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n = 10000+2;
long long cnt[111];
long long m,n,a=0,b,W;
const int INF = 1e9+1;
const int mod = 1e9 + 7;
string s1,s2;
long dist[max_n],s[max_n],w[max_n],v[max_n];
long long dp[max_n][max_n];
vector<vector<int> > G;
bool isprime(long long xx){
    if(xx == 2) return true;
    if(xx % 2==0 || xx<2)    return false;
    long long ii = 3;
    while(ii*ii <= xx){
        if(xx %ii == 0) return false;
        ii += 2;
    }
    return true;
}
long long gcd(long long xx, long long yy){
    if(yy == 0) return xx;
    long long k = xx/yy;
    long long c = xx - k*yy;
    return gcd(yy, c);
}
void solve(){
    for(int i=1 ; i<=s1.size() ; i++){
        dp[i][0] = i;
    }
    for(int j=1 ; j<=s2.size() ; j++){
        dp[0][j] = j;
    }
    for(int i=1 ; i<=s1.size() ; i++){
        for(int j=1 ; j<=s2.size() ; j++){
            long long x = min(dp[i-1][j]+1, dp[i][j-1]+1);
            if(s1[i-1] == s2[j-1]){
                x = min(x,dp[i-1][j-1]);
                dp[i][j] = x;
            }else{
                x = min(x, dp[i-1][j-1]+1);
                dp[i][j] = x;
            }
        }
    }
    cout << dp[s1.size()][s2.size()] << endl;
}
int main(){
    cin >> s1 >> s2;
    solve();
    return 0;
}


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

const int INF = 100000; 

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

    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
s = input()
l = len(s)
#print(s[:(l-1)//2])
#print(s[(l+3)//2-1:])
def pal(t):
    c = 1
    for i in range((len(t)-1)//2):
        if t[i] != t[-i-1]:
            c = 0
    return c
"""
if pal(s) and pal(s[:(l-1)//2]) and pal(s[(l+3)//2-1:]):
    print("Yes")
else:
    print("No")

"""
if s[:(l-1)//2] == s[(l+3)//2-1:] and pal(s):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,d=0,e=0;
	cin>>x>>y;
	int c[y+1];
	for(int i=1;i<=y;i++)
	cin>>c[i];
	for(int i=0;i<=y;i++)
	{
		d=0;
		e=0;
		for(int k=1;k<=y;k++)
		{
			if(x+i==c[k])
			{
				d++;
 			}
			if(x-i==c[k])
			{
				e++;
			}
		}
		if(e==0)
		{ 
			cout<<x-i<<endl;
			return 0; 
		} 
		if(d==0)
		{
			cout<<x+i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3604
#include <stdio.h>
int actg_flag(char);
 
int main(void) {
  char d[10];
  scanf("%s", d);
  int i;
  int max=0;
  int count=0;
  
  for(i=0;i<10;i++){
    if (d[i]=="\0") {
      printf("%d", max);
      return 0;
    }
    if (actg_flag(d[i]) == 1){
      count++;
      if (max < count){max = count;}
    }
    else{
      count=0;
    }
  }
  printf("%d", max);
}

int actg_flag(char d){
  if(d == 'A'){
  return 1;
  }
  else if (d == 'T'){
  return 1;
  }
  else if (d == 'C'){
  return 1;
  }
  else if (d == 'G'){
  return 1;
  }
  return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(M)]
one_to_other = set([b for a, b in ab if a == 1])
other_to_n = set([a for a, b in ab if b == N])

way = one_to_other & other_to_n
if len(way) >= 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 38504
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    ll bn = 0;
    for (int i = s.size() - 1; i >= 0; --i) {
        if (s[i] == 'B')
            ans += (s.size() - bn++ - 1) - i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 644