akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    agc041a()
}

fun agc041a() {
    val (n, a, b) = readLine()!!.split(' ').map { it.toLong() }

    val answer = if ((b - a) % 2 == 0L) ((b - a) / 2) else {
        Math.min(
            a + ((b - a - 1) / 2),
            (n - b + 1) + ((b - a - 1) / 2)
        )
    }

    println(answer)
}


Measured memory_bytes: 36392
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* It does not matter how slowly you go as long as you do not stop.*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1005;



int32_t main(){
    FAST;

    int a , b;  cin >> a >> b;
    if(b % a == 0)
        cout << a + b << endl;
    else cout << b - a << endl;

    return 0;
}




Measured memory_bytes: 256
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#pragma GCC optimize ("Ofast,unroll-loops,-ffloat-store")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ll = int_fast64_t; using ld = long double;

// -----------------------------------------------------------------------------

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll s = a + b;
    ll q = n / s, r = n % s;
    cout << q * a + min(r, a) << '\n';
}

int main() {
    fast_io; cin_exception;
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let vs: Vec<u32> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();
    let mut a = vec![0, vs[0]];
    let mut lasta = vs[0];
    for i in 2..1_000_000 {
        let an = if lasta % 2 == 0 {
            lasta / 2
        } else {
            3 * lasta + 1
        };
        if a.iter().any(|ak| *ak == an) {
            print!("{}", i);
            return;
        } else {
            a.push(an);
            lasta = an;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long 
#define int long long //
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define LN outchar('\n')
#define endl '\n'
using namespace std;

template<typename T> void inpos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=0; if(c=='-')neg=1;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
template<typename T> void outpos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do{snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
inline void instr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while(c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}


int32_t main () {
	
	int n;
	cin >> n;
	
	double temp;
	vector <double> dp(n+1,0.0);
	
	dp[0] = 1.0; // Doubt
	for (int i =0 ; i<n;i++) {
		cin>>temp;
		for (int j = n; j>0 ; j--){
			dp[j] = dp[j-1] * temp + dp[j] * (1-temp);
		}
		dp[0] *= (1-temp);
	}
	double ans = 0;
	for (int i = (n+1)/2 ; i<n+1;i++) {
		ans+= dp[i];
	}
	cout << fixed <<setprecision(10) << ans<<endl;
	

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val PN = readLine()!!.split(" ").map(String::toInt)


    var min = Integer.MAX_VALUE
    var count = 0
    for (i in PN.indices) {
        if (PN[i] < min) {
            count++
            min = Math.min(PN[i], min)
        }
    }
    println(count)
}



Measured memory_bytes: 83116
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    n %= 10;
    if(n == 2 || n==4 || n == 5 || n == 7 || n == 9){
        cout << "hon" << endl;
    }else if(n == 0 || n == 1 || n == 6 || n ==8){
        cout << "pon" << endl;
    }else if(n == 3){
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
N = int(input())
t = [int(input()) for i in range(N)]
M = max(t)
div = [i for i in range(1, M + 1) if M % i == 0]
di = 0
for i in t:
    for j in div:
        if i <= j:
            di += j - i
            break
print(di)



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

#define pb push_back
#define mp make_pair
#define ub upper_bound
#define st first
#define nd second
#define ll long long
#define pii pair < ll , ll >

char x;
string s;

int main(){

	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++){
			cin >> x;
			if(i==j)
				s = s + x;
		}

	cout << s << endl;
}

Measured memory_bytes: 256
N = int(input())
lst = list(map(int, input().split()))
x = 0
cnt = 0
while lst[x] != 1:
    if x == N-1:
        print(-1)
        exit()
    else:
        x += 1
cnt += x
n = x
for i in range(x+1, N):
    if lst[n] + 1 != lst[i]:
        cnt += 1
    else:
        n = i
print(cnt)

Measured memory_bytes: 26012
a,b,c = map(int,input().split())

if a == 7:
  if b == 5 and c == 5:
    print("YES")
  else:
    print("NO")
elif b == 7:
  if a == 5 and c == 5:
    print("YES")
  else:
    print("NO")
elif c == 7:
  if a == 5 and b == 5:
    print("YES")
  else:
    print("NO")
else:
  print("NO")

Measured memory_bytes: 9044
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val (L,R,D) = rd.readIntArray()

    val ans = R/D - (L-1)/D

    println(ans)
}


//val rd = debug.Reader("abc", "168", "a", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 36592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MOD 1000000007
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
const int dx[3]={0,0,1},dy[3]={0,1,0};
ll dp[4020][4020];int N=2005;bool vis[4020][4020];
int n,xx[200010],yy[200010],qx[200010],qy[200010],head=0,tail=1,maxq=200000;
ll inv[8010],finv[8010],f[8010];
void init(){
	int i;inv[1]=finv[1]=1;
	for(i=2;i<=8000;i++){
		inv[i]=((MOD-MOD/i)*inv[MOD%i])%MOD;
	}
	f[1]=1;
	for(i=2;i<=8000;i++){
		f[i]=(f[i-1]*i)%MOD;
		finv[i]=(finv[i-1]*inv[i])%MOD;
	}
}
int main(){
	init();
	int i,maxx=0,maxy=0,x,y,tx,ty;ll X=0;
	n=read();
	for(i=1;i<=n;i++){
		xx[i]=read();yy[i]=read();
		dp[N-xx[i]][N-yy[i]]+=1;
		maxx=max(maxx,xx[i]);maxy=max(maxy,yy[i]);
	}
	qx[0]=N-maxx,qy[0]=N-maxy;vis[N-maxx][N-maxy]=1;
	while(head!=tail){
		x=qx[head];y=qy[head];head=(head+1)%maxq;
//		cout<<"dp "<<x<<ends<<y<<ends<<dp[x][y]<<endl;;
		for(i=1;i<=2;i++){
			tx=x+dx[i];ty=y+dy[i];
			if(tx>N+maxx||ty>N+maxy) continue;
			dp[tx][ty]=(dp[tx][ty]+dp[x][y])%MOD;
//			cout<<"	to "<<tx<<ends<<ty<<ends<<dp[tx][ty]<<endl;
			if(!vis[tx][ty]){
				vis[tx][ty]=1;
				qx[tail]=tx;qy[tail]=ty;tail=(tail+1)%maxq;
			}
		}
	}
	for(i=1;i<=n;i++){
		X=X+dp[N+xx[i]][N+yy[i]];X%=MOD;
		X=X-((f[xx[i]*2+yy[i]*2]*finv[xx[i]*2])%MOD*finv[yy[i]*2])%MOD+MOD;
		X%=MOD;
	}
	printf("%lld\n",(X*inv[2])%MOD);
}

Measured memory_bytes: 145152
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
ac, wa, tle, re = 0, 0, 0, 0

for _ in range(N):
    s = input()[:-1]
    
    if s=='AC':
        ac += 1
    elif s=='WA':
        wa += 1
    elif s=='TLE':
        tle += 1
    else:
        re += 1

print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)

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

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)

#define BUFSIZE 4

int main(int argc, char const *argv[]) {
    int A, B, i, outlet= 1, ans= 0;
    input_i(A);
    input_i(B);
    while(1) {
        if(outlet >= B) break;
        ans++;
        outlet= outlet - 1 + A;
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
object Main extends App {
  import scala.math.BigDecimal.RoundingMode
  import java.util.Scanner
  val sc = new Scanner(System.in)

  val x: BigInt = BigInt(sc.nextBigInteger())
  val max: BigInt = BigInt(10).pow(18)

  def interest(a: BigDecimal) =
    (a * BigDecimal("1.01")).setScale(0, RoundingMode.DOWN)
  var i = 0
  val base = BigDecimal(100)
  val found = 0
  val st = LazyList
    .from(1)
    .scanLeft((BigDecimal(100), 0)) { case ((b, _), i) => (interest(b), i) }
    .dropWhile { case (b, i) => b < BigDecimal(x) }
  println(st.head._2)

}


Measured memory_bytes: 55928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
	int n,a;
	cin>>n>>a;
	if(n>=10)cout<<a<<endl;
	else cout<<a+100*(10-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    rep(i, 0, N) {
        int cnt = 0;
        rep(j, 0, N + 1) {
            if(i + j == N) break;
            if(S[j] == S[i + j]) cnt++;
            else cnt = 0;
            if(j - i >= 0 && cnt >= i + 1) cnt -= S[j - i] == S[i + j - i];
            if(cnt < 0) cnt = 0;
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
while 1:
    n = int(input())
    if n == 0:
        break

    score_a = 0
    score_b = 0
    for _ in range(n):
        a, b = map(int, input().split())
        if a > b:
            score_a += a + b
        elif a < b:
            score_b += a + b
        else:
            score_a += a
            score_b += b

    print(score_a, score_b)



Measured memory_bytes: 5612
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<bitset>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

inline ll read()
{
    long long f=1,sum=0;
    char c=getchar();
    while (c<'0' || c>'9')
    {
        if (c=='-')	f=-1;
        c=getchar();
    }
    while (c>='0' && c<='9')
    {
        sum=sum*10+c-'0';
        c=getchar();
    }
    return sum*f;
}
const int MAXN=2010;
const int MAXLEN=10010;
string s[MAXN];
bitset <MAXLEN> f[MAXN];
pa pos[2][1000010];
int num[MAXN]; 
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++)
	{
		cin>>s[i];
		for (int j=0;j<(int)s[i].size();j++)
			num[s[i][j]-'a']++;
	}
	int t=0;
	char p;
	for (int i=0;i<26;i++)
		if (num[i])
			t++,p=i+'a';
	if (t==1)
	{
		cout<<string(k,p);
		return 0;
	}
	f[n][0]=1;
	for (int i=n;i>=1;i--)
		f[i-1]=f[i]|(f[i]<<s[i-1].length());
	string ans;
	int now=0,cnt=0;
	for (int i=0;i<n;i++)
		if (f[i+1][k-(int)s[i].size()])
			pos[now][cnt++]=mp(i,0);
	for (int i=0;i<k;i++)
	{
		char minn='z';
		cnt=min(cnt,10000);
		for (int j=0;j<cnt;j++)
		{
			int id=pos[now][j].fi;
			int ppos=pos[now][j].se;
			minn=min(minn,s[id][ppos]);
		}
		ans.push_back(minn);
		int ncnt=0,m=INF;
		for (int j=0;j<cnt;j++)
		{
			int id=pos[now][j].fi;
			int ppos=pos[now][j].se;
			if (s[id][ppos]!=minn) continue;
			if (ppos+1!=(int)s[id].size())
				pos[now^1][ncnt++]=mp(id,ppos+1);
			else
				m=min(m,id+1);
		}
		for (int j=m;j<n;j++)
			if (k-i-1-(int)s[j].size()>=0 && f[j+1][k-i-1-(int)s[j].size()])
				pos[now^1][ncnt++]=mp(j,0);
		cnt=ncnt;
		now^=1;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 7424
N, X = [int(_) for _ in input().split()]

def calc(n, x, cache = {}):
    if n == 1:
        return min(max(x - 1, 0), 3)
    else:
        plen = 2 * 2 ** n - 3
        if x == 1:
            return 0
        elif x >= 4 * 2 ** n - 3:
            return 2 * 2 ** n - 1
        elif x < 2 + plen:
            return calc(n - 1, x - 1)
        elif x == 2 + plen:
            return calc(n - 1, x - 1) + 1
        else:
            return 2 ** n + calc(n - 1, x - 2 - plen)

result = calc(N, X)

print(result)


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, r; cin >> n >> r;

    if (n >= 10) {
        cout << r << endl;
    } else {
        cout << r + 100 * (10 - n) << endl;
    }
}

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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector< pi >
#define ff first
#define ss second
const int N=300010;
int a[N],odd[N],even[N],ans[N];
int main()
{
	int n,res=0,x,y;
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",a+i),res=min(res+a[i],mod);
	y=0;
	for(int i=1;i<=n;i++)
		odd[i]=odd[i-1]+(a[i]%2==0);
	res=min(res,odd[n]);
	y=0;
	for(int i=n;i>=1;i--)
		y=min(y+a[i],mod),even[i]=min(y,even[i+1]+(a[i]>0?(a[i]%2):2));
	res=min(res,even[1]);
	for(int i=0;i<=n;i++)
		ans[i]=odd[i]+even[i+1];
	for(int i=n-1;i>=0;i--)
		ans[i]=min(ans[i+1],ans[i]);
	x=0;y=0;
	res=min(res,ans[1]);
	for(int i=1;i<=n;i++)
	{
		x+=(a[i]%2);
		if(a[i]==0) x+=2;
		y=min(y+a[i],mod);
		x=min(y,x);
		if(i==n)
		{
			res=min(res,x);
			break;
		}
		assert(ans[i+1]>=odd[i]);
		//cout<<ans[i+1]-odd[i]<<"\n";
		res=min(res,x+(ans[i+1]-odd[i]));
		res=min(res,x+ans[i]-odd[i]);
		//cout<<x<<" "<<ans[i]<<"\n";
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 4096
import sys
import math

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

x = INT()

tmp = x//11
y = x - (5*tmp + 6*tmp)
tmp *= 2
if y:
	if y >= 7:
		tmp += 2
	else:
		tmp += 1

print(tmp)

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

int dfs(int x,int y,int f[32][32]) {
	int n = 1;
	f[x][y] = 0;
	if (f[x + 1][y] == 1)
		n += dfs(x + 1, y, f);
	if (f[x - 1][y] == 1)
		n += dfs(x - 1, y, f);
	if (f[x][y + 1] == 1)
		n += dfs(x, y + 1, f);
	if (f[x][y - 1] == 1)
		n += dfs(x, y - 1, f);
	return n;
}


int main()
{
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0 && h == 0)break;
		int floor[32][32] = {};
		int startX = 0;
		int startY = 0;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				char c;
				cin >> c;
				if (c == '.' || c == '@') {
					floor[i][j] = 1;
					if (c == '@') {
						startX = i;
						startY = j;
					}
				}
				else if (c == '#')floor[i][j] = 0;
			}
		}
		int cnt = dfs(startX, startY, floor);
		cout << cnt << endl;
	}
    return 0;
}

Measured memory_bytes: 3020
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <deque>
#include <queue>
#include <assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    int sum=0;
    vector<int> p(n);
    for(int i=0;i<n;i++){
    	cin >> p[i];
    }
    sort(p.begin(), p.end());
    for(int i=0;i<k;i++){
    	sum+=p[i];
    }
    cout << sum << endl;
}




Measured memory_bytes: 3640
#include <stdio.h>

long max(long a, long b) {
  if (a >= b) {
    return a;
  } else {
    return b;
  }
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long dp0[n/2][2],dp1[n/2][2];
  dp0[0][0] = 0;
  dp0[0][1] = a[0];
  dp1[0][0] = -10000000000;
  dp1[0][1] = a[1];
  for (long i = 1; i < n/2; i++) {
    dp0[i][0] = dp0[i-1][0]+a[i*2];
    dp0[i][0] = max(dp0[i][0],max(dp0[i-1][1],dp1[i-1][1]));
    dp0[i][1] = dp0[i-1][1]+a[i*2];
    dp1[i][0] = max(dp0[i-1][0],dp1[i-1][0])+a[i*2+1];
    dp1[i][1] = max(dp0[i-1][1],dp1[i-1][1])+a[i*2+1];
  }
  long ans;
  if (n%2 == 0) {
    ans = max(dp0[n/2-1][1],dp1[n/2-1][1]);
  } else {
    ans = dp0[n/2-1][0]+a[n-1];
    ans = max(ans,max(dp0[n/2-1][1],dp1[n/2-1][1]));
  }
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 6416
Q, H, S, D = map(int, input().split())
N = int(input())

if 2 * Q < H:
    H = 2 * Q
if 2 * H < S:
    S = 2 * H
if 2 * S < D:
    D = 2 * S

print(N//2 * D + N%2 * S)


Measured memory_bytes: 2940
N = int(input())
Xs = []
Ys = []
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    X = []
    Y = []
    for j in range(a):
        x, y = map(int, input().split())
        X.append(x-1)
        Y.append(y)
    Xs.append(X)
    Ys.append(Y)
ans = 0

for i in range(2 ** N):
    flag = True
    l = 0
    for j in range(N):
        if i >> j & 1 == 1:
            l += 1
            for k in range(A[j]):
                if Ys[j][k] + (i >> Xs[j][k] & 1) == 1:
                    flag = False
    if flag:
        ans = max(ans, l)

print(ans)

Measured memory_bytes: 42604
import java.util.Scanner;

public class Main {

    private static int[] GROUP_1 = { 1, 3, 5, 7, 8, 10, 12 };
    private static int[] GROUP_2 = { 4, 6, 9, 11 };
//    private static int[] GROUP_3 = { 2 };

    public static void main(String[] args) throws Exception {
        try (
            Scanner sc = new Scanner(System.in);
        ) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            
            if (
                    (isBelonged(x, GROUP_1) && isBelonged(y, GROUP_1))
                        || (isBelonged(x, GROUP_2) && isBelonged(y, GROUP_2))
            ) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
    
    private static boolean isBelonged(int num, int[] group) {
        for (int g : group) {
            if (g == num) {
                return true;
            }
        }
        return false;
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ud(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, a, b) for (int i = a, i < b; ++i)
#define rep3(i, n) for (int i = n - 1; i >= 0; ++i)
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }

void solve(void) {
  int k;
  cin >> k;
  int x = 7 % k;
  int cta = 1;
  set<int> st;
  st.insert(x);
  bool f = true;
  while (x != 0) {
    x = (10 * x + 7) % k;
    if (st.find(x) != st.end()) break;
    st.insert(x);
    cta++;
  }
  if (x != 0)
    cout << -1 << endl;
  else
    cout << cta << endl;
}

int main(void) { solve(); }


Measured memory_bytes: 50496
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
int n;
int las[MAXN];
char s[MAXN];
int main(){
	SF("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++){
		if(las[s[i]-'a']!=0){
			if(i+1-las[s[i]-'a']+1<=3){
				PF("%d %d\n",las[s[i]-'a'],i+1);
				return 0;	
			}
		}	
		las[s[i]-'a']=i+1;	
	}
	PF("-1 -1");
}

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

long long n, m[1000004], h[1000004], ans;
int main()
{
	cin>>n;
	for(int i=0; i<=n; i++) cin>>m[i];
	for(int i=0; i<n; i++) cin>>h[i];
	for(int i =0; i<n; i++){
	if( (m[i]+ m[i+1]) <= h[i] ){
		ans += m[i] + m[i+1];
		m[i+1] = 0;
	}
	else if(m[i] < h[i]) {
			int r = m[i+1]  - (h[i]- m[i]);
			ans += h[i];
			m[i+1] = r;
		}
		else{
			ans += h[i];
		}

	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5120
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

AR=[0]
for i in range(N):
    AR.append(AR[-1]+A[i])
AR+=[10**10]
BR=[0]
for i in range(M):
    BR.append(BR[-1]+B[i])
BR+=[10**10]
#print(AR)
#print(BR)

import bisect

ans=0
for a in range(len(AR)):
    if AR[a]>K:
        break
    cnt=a
    cnt+=bisect.bisect_right(BR,K-AR[a])-1
    if ans<cnt:
        ans=cnt
    #print(a,K-AR[a],bisect.bisect_right(BR,K-AR[a]),cnt,ans)
print(ans)

Measured memory_bytes: 132360
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  std::sort(s.begin(), s.end());
  std::cout << (s[0] == s[1] && s[1] != s[2] && s[2] == s[3] ?
   "Yes" : "No")  << std::endl;
  return 0;
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void){
    ll N; cin>>N;
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ll tmp; cin>>tmp;
        while(tmp%2==0){
            tmp /= 2;
            ans++;
        }
    }
    cout<<ans<<endl;

}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll N;
  cin>>N;
  vector<ll> A(N);
  for(auto &I:A){cin>>I;}
  map<ll,ll> S;
  for(auto &I:A){
    ll num=I;
    for(ll i=2;i*i<=I;i++){
      if(I%i==0){
        S[i]+=num;
        while(I%i==0){I/=i;}
      }
    }
    if(I!=1){S[I]+=num;}
  }
  ll mx=0;
  for(auto &I:S){mx=max(mx,I.second);}
  cout<<mx<<endl;

  return 0;
}



Measured memory_bytes: 3208
class Dice:
  def __init__(self, list1):
    self.f = list1

  def spin1(self):  #(真上から見て反時計回り)
    f = self.f
    self.spin2()
    f[0], f[2], f[3], f[5] = f[3], f[0], f[5], f[2]
    f[0], f[1], f[4], f[5] = f[4], f[0], f[5], f[1]
    return f[:]

  def spin2(self):  #(方角Eから見て時計回り)
    f = self.f
    f[0], f[1], f[4], f[5] = f[1], f[5], f[0], f[4]
    return f[:]
    
  def spin3(self):  #(方角Sから見て半時計回り)
    f = self.f
    f[0], f[2], f[3], f[5] = f[2], f[5], f[0], f[3]
    return f[:]


data = list(map(int, input().split()))
dice_1 = Dice(data)

data_2 = [dice_1.spin2() for _ in range(4)]
for j in data_2[:]:
    dice_2 = Dice(j)
    data_2 += [dice_2.spin1() for _ in range(4)]

data_4 = []
for l in data_2:
    dice_3 = Dice(l)
    data_4 += [dice_3.spin3() for _ in range(4)]

data_1 = list(map(int, input().split()))
if data_1 in data_4:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5612
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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;
}

char alpha[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'};

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

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

Measured memory_bytes: 3596
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);


// ===

fn main() {
    let r: i32 = read();
    if r < 1200 {
        println!("ABC");
    } else if r < 2800 {
        println!("ARC");
    } else {
        println!("AGC");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<vector<int>> a(n,vector<int>(26));
	rep(i,n){
		string s;
		cin >> s;
		rep(j,s.size()){
			a[i][s[j]-'a']++;
		}
	}
	vector<int> ans(26,100000000);
	rep(i,26){
		rep(j,n){
			ans[i]=min(ans[i],a[j][i]);
		}
	}
	rep(i,26){
		char c='a'+i;
		rep(j,ans[i]){
			cout << c;
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
int main(void){
  char str[1000];
  int i,l;
  
  fgets(str,1000,stdin);
  l=strlen(str);
  for(i=0;i<l;i++){
    if(str[i]=='p' && str[i+1]=='e'&&str[i+2]=='a'&&str[i+3]=='c'&&str[i+4]=='h'){
      str[i]='a';
      str[i+1]='p';
      str[i+2]='p';
      str[i+3]='l';
      str[i+4]='e';
      i=i+4;
    }else if(str[i]=='a' && str[i+1]=='p'&&str[i+2]=='p'&&str[i+3]=='l'&&str[i+4]=='e'){
      str[i]='p';
      str[i+1]='e';
      str[i+2]='a';
      str[i+3]='c';
      str[i+4]='h';
    }
    
  }
    printf("%s",str);
    return 0;
}

Measured memory_bytes: 1860
#include <iostream>

using namespace std;

#define MOD 1000000007

int main(){
  long long int N, K, ans=0, min, max;
  cin >> N >> K;
  for(long long int i=K; i<=N+1; i++){
    min = i*(i-1)/2;
    max = i*(2*N-i+1)/2;
    ans = (ans + (max-min+1))%MOD;
  }
  cout << ans << endl;
  return 0;
}


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

long long memo[100];

long long fib(long long n) {
	if (memo[n] != 0)return memo[n];
	if (n == 0)return 2;
	if (n == 1)return 1;
	memo[n] = fib(n - 1) + fib(n - 2);
	return fib(n - 1) + fib(n - 2);
}

int main() {
	int n;
	cin >> n;
	cout << fib(n) << endl;
	return 0;
}

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

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

int main() {
  
  int n, s, t;
  cin >> n;
  
  rep(i,n) {
    cin >> s >> t;
    if(s <= 5) {
      if(s < t) {
	cout << s;
	for(int j=s+1; j<=t; j++) cout << " " << j;
	cout << endl;
      }
      if(s > t) {
	cout << s;
	for(int j=s-1; j>=t; j--) cout << " " << j;
	cout << endl;
      }
    }
    else {
      if(t <= 5) {
	for(int j=s; j<10; j++) cout << j << " ";
	s=5;
	cout << s;
	for(int j=s-1; j>=t; j--) cout << " " << j;
	cout << endl;
      } else if(s < t) {
	cout << s;
	for(int j=s+1; j<=t; j++) cout << " " << j;
	cout << endl;
      } else {
	for(int j=s; j<10; j++) cout << j << " ";
	cout << "5 4 3 2 1 0 1 2 3 4 5";
	for(int j=6; j<=t; j++) cout << " " << j;
	cout << endl;
      }
    }
  }
  
  return 0;
}

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

class UnionFind {
public:
    // parent node index if not root index
    // minus size of the tree if root index
    std::vector<int> data;
    UnionFind( int n ) {
        data.resize( n, -1 );
    }
    int find( int x ) {
        if ( data[x] < 0 ) {
            return x;
        } else {
            int r = find( data[x] );
            data[x] = r;
            return r;
        }
    }
    void unite( int x, int y ) {
        int r = find( x );
        int s = find( y );
        if ( r != s ) {
            data[r] += data[s];
            data[s] = r;
        }
    }
    int size( int x ) {
        int r = find(x);
        return -data[r];
    }
};


ll solve() {
    ll N, M, K;
    cin >> N >> M >> K;
    ll a, b, c, d;
    UnionFind uf(N);
    vector<ll> fr(N), bl(N);
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        uf.unite(a,b);
        fr[a]++;
        fr[b]++;
    }
    for ( int i = 0; i < K; i++ ) {
        cin >> c >> d;
        c--, d--;
        if ( uf.find(c) == uf.find(d) ) {
            bl[c]++;
            bl[d]++;
        }
    }
    
    vector<ll> ans(N);
    for ( int i = 0; i < N; i++ ) {
        ans[i] = uf.size(i) - 1 - fr[i] - bl[i];
    }
    for ( int i = 0; i < N; i++ ) {
        cout << (i != 0 ? " " : "") << ans[i];
    }
    cout << "\n";

    return 0;
}

int main() {
    solve();
    return 0;
}

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

int main()
{
  int n, k;
  int x[100+10];
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  int total = 0;
  int border = k/2;
  for(int i=0;i<n;i++){
    if(x[i] > border){
      total += ((k-x[i])*2);
    }else{
      total += (x[i]*2);
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> cnt(3,-1);
	ll ans=1;
	rep(i,n){
		cin>>a[i];
		ll now=0;
		rep(j,3){
			if(cnt[j]==a[i]-1){
				now++;
			}
		}
		ans*=now;
		ans%=mod;
		rep(j,3){
			if(cnt[j]==a[i]-1){
				cnt[j]++;
				break;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
 int dp[1000001];
int solve(int n, int k, int a[])
{   
    dp[0] = 0;
    
    for(int i=1;i<n;i++)
        dp[i] = INT_MAX;
   
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
                dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]));
        }                    
    }
    
    return dp[n-1];
    
}

int main()
{
  
        int n, k;
        cin >> n >> k;
        int a[n];
        for(int i=0;i<n;i++) cin >> a[i];
        cout << solve(n,k,a) << endl;
        
}

Measured memory_bytes: 4344
def solve(inp):
    S = inp.readline().strip()

    for i in range(0, len(S), 2):
        if S[i] == 'L':
            return 'No'
    for i in range(1, len(S), 2):
        if S[i] == 'R':
            return 'No'

    return 'Yes'


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    # test('')
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 505
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
struct edge{ int s,t,c; } in[M*100];
int n,m,fa[M];
vector<int> id;

int find(int x)
{
	return fa[x]==x ? x : fa[x] = find(fa[x]);
}
int work(int ban)
{
	int re=0;
	REP(i,1,n) fa[i]=i;
	
	REP(i,1,m) if(i != ban)
	{
		if( find(in[i].s) != find(in[i].t) )
		{
			if(ban==-1) id.PB(i);
			re += in[i].c;
			fa[find(in[i].s)] = find(in[i].t);
		}
	}
	return re;
}
int main()
{
	RI(n,m);
	REP(i,1,m) RI(in[i].s, in[i].t, in[i].c);
	sort(in+1, in+m+1, [](edge a, edge b) { return a.c < b.c; } );

	id.clear();
	int mst = work(-1);
	int a1=0, a2=0;
	FOR(i,id)
	{
		if( work(*i)!=mst )
		{
			a1 ++;
			a2 += in[*i].c;
		}
	}

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

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int LN = 17;
int n;
int arr[N];
int l;
int nxt[N];
int ptr;
int prv[N];
int dp1[LN][N];
int dp2[LN][N];
int q;
int a , b;
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , arr + i);
    }
    scanf("%d" , &l);
    ptr = n;
    for(int i = n ; i >= 1 ; --i){
        while(arr[ptr] - arr[i] > l){
            --ptr;
        }
        nxt[i] = ptr;
    }
    ptr = 1;
    for(int i = 1 ; i <= n ; ++i){
        while(arr[i] - arr[ptr] > l){
            ++ptr;
        }
        prv[i] = ptr;
    }
    for(int i = 1 ; i <= n ; ++i){
        dp1[0][i] = nxt[i];
        dp2[0][i] = prv[i];
    }
    for(int i = 1 ; i < LN ; ++i){
        for(int j = 1 ; j <= n ; ++j){
            dp1[i][j] = dp1[i - 1][j] > n ? n + 1 : dp1[i - 1][dp1[i - 1][j]];
            dp2[i][j] = dp2[i - 1][j] < 1 ? 0 : dp2[i - 1][dp2[i - 1][j]];
        }
    }
    scanf("%d" , &q);
    while(q--){
        scanf("%d %d" , &a , &b);
        int ans = 1;
        if(a < b){
            for(int i = LN - 1 ; i >= 0 ; --i){
                if(dp1[i][a] < b){
                    a = dp1[i][a];
                    ans += 1 << i;
                }
            }
        }
        else{
            for(int i = LN - 1 ; i >= 0 ; --i){
                if(dp2[i][a] > b){
                    a = dp2[i][a];
                    ans += 1 << i;
                }
            }
        }
        printf("%d\n" , ans);
    }
}

Measured memory_bytes: 15232
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)

	A, B, C, D := getInt(), getInt(), getInt(), getInt()

	out(min(A, B) + min(C, D))
}


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

using Bool = bool;
using Int = long long int;
template <class T>
using Vector = std::vector<T>;
template <class T>
using Matrix = Vector<Vector<T>>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

const Vector<Int> dx{1, 0, -1, 0}, dy{0, -1, 0, 1};
const Vector<Int> front{0, 1, 3, 4};
const Matrix<Int> trans{{0, 2, 3, 5},
                        {1, 2, 4, 5},
                        {3, 2, 0, 5},
                        {4, 2, 1, 5}};
const Matrix<Int> init{{0, 3, 5, 2, 4, 0},
                       {4, 0, 1, 6, 0, 3},
                       {2, 6, 0, 0, 1, 5},
                       {5, 1, 0, 0, 6, 2},
                       {3, 0, 6, 1, 0, 4},
                       {0, 4, 2, 5, 3, 0}};

struct Dice {
    Vector<Int> face;

    void roll(Int d) {
        Int tmp = face[trans[d][0]];
        for (Int i = 0; i < 3; ++i) {
            face[trans[d][i]] = face[trans[d][i + 1]];
        }
        face[trans[d][3]] = tmp;
    }

    Dice(Int t, Int f) : face(6) {
        Int r = init[f - 1][t - 1];
        face[0] = f, face[1] = r, face[2] = t;
        for (Int i = 0; i < 3; ++i) {
            face[i + 3] = 7 - face[i];
        }
    }
};

Bool solve() {
    Int n;
    std::cin >> n;
    if (n == 0) return false;

    Matrix<Int> h = genv<Int>(5, 5, 0LL);
    auto top = h;

    for (Int i = 0; i < n; ++i) {
        Int t, f;
        std::cin >> t >> f;
        Dice dice(t, f);

        Int x = 2, y = 2;
        while (true) {
            Int nd = -1;
            for (Int d = 0; d < 4; ++d) {
                Int nx = x + dx[d], ny = y + dy[d];
                if (dice.face[front[d]] >= 4 &&
                    h[nx][ny] < h[x][y] &&
                    (nd < 0 || dice.face[front[nd]] < dice.face[front[d]])) {
                    nd = d;
                }
            }

            if (nd < 0) break;
            dice.roll(nd);
            x += dx[nd], y += dy[nd];
        }

        ++h[x][y];
        top[x][y] = dice.face[2];
    }

    Vector<Int> ans(7, 0);
    for (Int x = 0; x < 5; ++x) {
        for (Int y = 0; y < 5; ++y) {
            ++ans[top[x][y]];
        }
    }

    for (Int i = 1; i <= 6; ++i) {
        std::cout << ans[i] << " \n"[i == 6];
    }
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#define rep(i, n) for (int64_t i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, Q;
  cin >> N >> Q;

  int64_t black = (N - 2) * (N - 2);
  vector<int> row(N + 1, N);
  vector<int> col(N + 1, N);
  int H = N;
  int W = N;
  rep(i, Q) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      if (x < W) {
        for (int j = x; j < W; ++j) {
          row[j] = H;
        }
        W = x;
      }
      black -= (row[x] - 2);
    } else {
      if (x < H) {
        for (int j = x; j < H; ++j) {
          col[j] = W;
        }
        H = x;
      }
      black -= (col[x] - 2);
    }
  }
  cout << black << endl;
  return 0;
}


Measured memory_bytes: 4848
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    double r1, r2;
    cin >> r1 >> r2;

    double r3 = 1.0 / (1.0 / r1 + 1.0 / r2);
    printf("%.10f\n", r3);

    return 0;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const ll INF = 1e18;

int n;
int a[maxn], pos[maxn];
ll ans;
ll dp[maxn][3];

inline int calc(int x, int y){
	if(y & 1) return -x;
	return x;
}

int main(){
	scanf("%d", &n);
	FOR(i, 0, n){
		if(!i) pos[i] = 1;
		else{
			char c;
			scanf("%*c%c", &c);
			if(c == '-') pos[i] = -1;
			else pos[i] = 1;
		}
		scanf("%d", a + i);
	}
//	FOR(i, 0, n) cout << pos[i] << " " << a[i] << endl;
	REP(i, 0, n) FOR(j, 0, 3) dp[i][j] = -INF;
	dp[0][0] = 0;
	FOR(i, 0, n) FOR(j, 0, 3) if(dp[i][j] != -INF){
//		cout << "i = " << i << " j = " << j << " " << dp[i][j] << " " << calc(pos[i] * a[i], j) << endl;
		if(pos[i] == 1){
			REP(nj, 0, j)
				dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + calc(a[i], j));
		}
		else{
			if(j + 1 < 3)
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + calc(-a[i], j));
			REP(nj, 0, j)
				dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + calc(-a[i], j));
		}
	}
	printf("%lld\n", dp[n][0]);
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr[100005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,sum=0,an=0;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    sum/=2;
    for(ll i=2;i<=n;i+=2)
    an+=arr[i];
    ll x=sum-an;
    cout<<2*x<<" ";
    for(ll i=1;i<n;i++){
        cout<<2*(arr[i]-x)<<" ";
        x=arr[i]-x;
    }
}

Measured memory_bytes: 2176
x, k, d = map(int, input().split())
x = abs(x)
a = x // d
a = min(k, a)
k -= a
x -= (d*a)
if k == 0:
    print(x)
else:
    y = abs(x - d)
    if k &1 == 0:
        print(x)
    else:
        print(y)


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

ll N;
ll F[100][10];
ll P[100][11];


int main() {
    cin >> N;
    rep(i, N)rep(j, 10) cin >> F[i][j];
    rep(i, N)rep(j, 11) cin >> P[i][j];

    ll ans = -1e9;
    rep(i, 1 << 10) {
    // rep(i, 1 << 4) {
        if (i == 0) continue;

        // ショップ数分
        ll shop_ans = 0; 
        rep(k, N) {
            ll cnt = 0;
            rep(j, 10) {
                // i のビットが立っている場合
                if ((i >> j) & 1 && F[k][j] == 1) {
                    cnt++;
                }
            }
            shop_ans += P[k][cnt]; 
            // printf("i: %d cnt: %d\n", i, cnt);
        }

        ans = max(shop_ans, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=[0]*m
b=[0]*m
c=[0]*m
for i in range(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
INF=10**18#float('inf')
dist=[ [INF]*n for _ in range(n)]
for i in range(n):
  dist[i][i]=0
for i in range(m):
  dist[a[i]][b[i]]=c[i]
  dist[b[i]][a[i]]=c[i]
#floyd warshall
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
ans=m
for i in range(m):
  shortest=False
  for j in range(n):
    if dist[j][a[i]]+c[i]==dist[j][b[i]]:
      shortest=True
      break
  if shortest:
    ans-=1
print(ans)





Measured memory_bytes: 3408
import sys
input = sys.stdin.readline


def read():
    x1, y1, x2, y2 = map(int, input().strip().split())
    return x1, y1, x2, y2


def solve(x1, y1, x2, y2):
    v12 = (x2-x1, y2-y1)
    v34 = (-x2+x1, -y2+y1)
    v23 = (-y2+y1, x2-x1)
    x3, y3 = x2 + v23[0], y2 + v23[1]
    x4, y4 = x3 + v34[0], y3 + v34[1]
    return "%d %d %d %d" % (x3, y3, x4, y4)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 3064
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
using namespace std;

int main() {
  int s,ans;
  cin >>s;
  ans=0;
  while(s!=4&&s!=2&&s!=1){
    if(s%2==0){
      s=s/2;
      ans++;
    }
    else if(s%2!=0){
      s=s*3+1;
      ans++;
    }
  }
  if(s==4){
    cout << ans+4 << endl;
  }
  else if(s==2){
    cout << ans+4 << endl;
  }
  else if( s==1){
    cout << ans+4 << endl;
  }
}

Measured memory_bytes: 256