akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val next = Array(N) { mutableListOf<Int>() }

    for (i in 0 until N - 1) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() - 1 }
        next[a].add(b)
        next[b].add(a)
    }

    // 0: 未着色 1:Fennec 2:Snuke
    val color = IntArray(N)
    color[0] = 1
    color[N - 1] = 2

    var nextFennec = mutableListOf(0)
    var nextSnuke = mutableListOf(N - 1)

    var usedCnt = 2

    while (usedCnt != N) {
        val nf = mutableListOf<Int>()

        for (n in nextFennec) {
            for (nn in next[n]) {
                if (color[nn] == 0) {
                    color[nn] = 1
                    nf.add(nn)
                    usedCnt++
                }
            }
        }

        nextFennec = nf

        val ns = mutableListOf<Int>()

        for (n in nextSnuke) {
            for (nn in next[n]) {
                if (color[nn] == 0) {
                    color[nn] = 2
                    ns.add(nn)
                    usedCnt++
                }
            }
        }

        nextSnuke = ns
    }

    val fennecCnt = color.count { it == 1 }
    val snukeCnt = N - fennecCnt

    if (fennecCnt > snukeCnt) {
        println("Fennec")
    } else {
        println("Snuke")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 86240
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main() {

    int N;
    cin >> N;

    int A[110000];
    for (int ai = 1 ; ai <= N ; ai ++){
        cin >> A[ai];
    }
    A[0] = 0;
    A[N+1] = 0;

    int sum = 0;
    int now = 0;
    for(int j = 1 ; j <= N ; j++){
            sum += abs(A[j] - now);
            now = A[j];
    }
    sum += abs(0 - now);

    for(int i = 1 ; i <= N ; i++){

        int moto = abs(A[i] - A[i-1]) + abs(A[i+1] - A[i]);
        int sin = abs(A[i+1] - A[i-1]);
        int diff = moto - sin;
        cout << sum - diff << endl;

    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define db(x) cout<<x<<" "
#define db1(x) cout<<x<<'\n'
#define db2(x,y) cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pair(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ll  long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vpi vector<pair<ll,ll>>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define mod 1000000007
#define MAX_N 100000
using namespace std;
// int dx[4] = {1,-1,0,0};
// int dy[4] = {0,0,1,-1};
ll dp[401][401];
ll prefixSum[401];
ll get(vector<ll>&arr, ll i, ll j){
    if(i>=j)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll ans = LLONG_MAX; 
    for(int k=i+1;k<=j;k++){
        ll temp = get(arr,i,k-1)+get(arr,k,j);
        ll sum = prefixSum[j];
        if(i-1>=0)
            sum-=prefixSum[i-1];
        ans = min(ans,temp+sum);
    }
    return dp[i][j] = ans;
}

void preprocess(vector<ll>&arr, ll n){
    prefixSum[0]=arr[0];
    repA(i,1,n-1)
    prefixSum[i]=prefixSum[i-1]+arr[i];
}

void solve(){

    ll n;
    cin>>n;
    memset(dp,0,sizeof(dp));
    vector<ll>arr(n);

    rep(i,n)
    cin>>arr[i];
    preprocess(arr,n);
    ll result = LLONG_MAX;
    for(int len=2;len<=n;len++){
        for(int i=0;i<=n-len;i++){
            int j = i+len-1;
            ll ans = LLONG_MAX;
            for(int k=i+1;k<=j;k++){
                ll temp = dp[i][k-1]+dp[k][j];
                ll sum = prefixSum[j];
                if(i-1>=0)
                sum-=prefixSum[i-1];
                ans = min(ans,temp+sum);
            }
            dp[i][j] = ans;
            result=min(result,ans);
        }
    }
    db1(dp[0][n-1]);   

}
int main(){ 

int t=1;
//cin>>t;
while(t--){
 solve();
}
  return 0; 
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;
  string u="Yes";
  rep(i,0,s.size()){
    if(s[i]!=t[i]){
      u="No";
    }
  }
  cout<<u<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  vector<char> c;
  rep(i,0,s.size()){
    if(s[i]=='B'){
      if(c.size()){
        c.pop_back();
      }
    }
    else{
      c.push_back(s[i]);
    }
  }
  rep(i,0,c.size()){
    cout<<c[i];
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int m=0;
  string s;
  cin >> s;
  if(s=="RSR"){
    cout << 1 << endl;
    return 0;
  }
  for (int i=0;i<3;i++) {
    if(s[i]=='R'){
      m++;
    }
  }
  cout << m << endl;
}

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

using namespace std;

const int N = 123456;

int n, m, color[N];
vector<int> adj[N];
bool visit[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int a = 0, b = 0, c = 0, number;
  bool ok;
  for (int i = 1; i <= n; ++i) {
    if (!visit[i]) {
      function<void (int, int)> dfs = [&] (int x, int z) {
        ++number;
        visit[x] = true;
        color[x] = z;
        for (auto y : adj[x]) {
          if (!visit[y]) {
            dfs(y, !z);
          } else if (color[y] != (!z)) {
            ok = false;
          }
        }
      };
      number = 0;
      ok = true;
      dfs(i, 0);
      if (number == 1) {
        ++a;
      } else if (!ok) {
        ++b;
      } else {
        ++c;
      }
    }
  }
  long long answer = 0;
  answer += (long long) a * a;
  answer += (long long) a * (n - a) << 1;
  answer += (long long) b * b;
  answer += (long long) b * c << 1;
  answer += (long long) c * c << 1;
  cout << answer << '\n';
  return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#define INF 10000000000000
using namespace std;
using ll = long long;
int main() {
	ll n;
	vector<ll> a(100010);
	vector<ll> b(100010);
	vector<ll> c(100010);
	vector<ll> ha(100010);
	vector<ll> hb(100010);
	vector<ll> hc(100010);

	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	ha[0] = a[0];
	hb[0] = b[0];
	hc[0] = c[0];
	for (ll i = 1; i < n; i++) {
		ha[i] = max(a[i] + hb[i - 1], a[i] + hc[i - 1]);
		hb[i] = max(b[i] + ha[i - 1], b[i] + hc[i - 1]);
		hc[i] = max(c[i] + ha[i - 1], c[i] + hb[i - 1]);
	}
	cout << max(max(ha[n - 1], hb[n - 1]), hc[n - 1]) << endl;
}

Measured memory_bytes: 4992
package main

import (
	"fmt"
	"sort"
)

// 参考にした回答
// https://atcoder.jp/contests/keyence2020/submissions/9566190
type arms [][]int

func (a arms) Len() int      { return len(a) }
func (a arms) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

// 今回はx+lのほうでソートすればよいのでこうしている。
func (a arms) Less(i, j int) bool { return a[i][1] < a[j][1] }

func main() {
	var N int
	fmt.Scan(&N)
	robots := make(arms, N)
	max := -1000000009
	count := 0
	for i := 0; i < N; i++ {
		var x, l int
		fmt.Scan(&x, &l)
		robots[i] = []int{x - l, x + l}
	}
	sort.Sort(robots)
	for i := range robots {
		if robots[i][0] >= max {
			count++
			max = robots[i][1]
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 7424
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

static const int MAX = 200001;

int main(int argc, const char * argv[]) {
    // input from txt
    /////////
    //write//
    /////////
    
    int n;
    int *a;
    a = new int[MAX];
    
    cin >> n;
    vector<int> p;
    rep(i, n){
        cin >> a[i];
        p.push_back(a[i]);
    }
    sort(p.begin(), p.end());
    
    rep(i, n){
        if(p.back() == a[i])cout << p[n-2] << endl;
        else cout << p.back() << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define mp make_pair
#define ff first
#define ss second
using vi = vector<int>;
using vvi = vector<vi>;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl

int main(){
  cout<<fixed<<setprecision(10);
  int N,W;
  cin>>N>>W;
  vector<pii> things;
  int v,w;
  for(int i=0; i<N; i++){
    cin>>v>>w;
    things.pb(mp(v,w));
  }
  sort(all(things), [](pii a, pii b){
    return ((double)a.ff/a.ss) > ((double)b.ff/b.ss);
  });
  /*
  for(pii x: things){
    cout<<x.ff<<","<<x.ss<<endl;
  }
  */
  double ans = 0.0;
  for(int i=0; i<N; i++){
    if(things[i].ss > W){
      ans += (double)things[i].ff*W/things[i].ss;
      cout<<ans<<endl;
      return 0;
    }else{
      ans += things[i].ff;
      W -= things[i].ss;
      //debug(W);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
int n,ans=INF;
vector<int>l(600000,0),r(600000,0);
string s;
signed main(){
    cin>>n>>s;
    rep(i,n){
        if(s[i]=='W')l[i+1]=l[i]+1;
        else l[i+1]=l[i];
    }
    for(int i=n;i>=1;i--){
        if(s[i]=='E')r[i-1]=r[i]+1;
        else r[i-1]=r[i];
    }
    rep(i,n){
        ans=min(ans,l[i]+r[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10244
#include <math.h>
#include <string>
#include <iostream>
using namespace std;

int main(){
    int N;
    cin>>N;
    double n=N;
    
    bool hantei=0;
    int kaisuu=0;
    while (hantei==0) {
        if (n>=2.) {
            n=n/2;
            kaisuu++;
        }
        else{hantei=1;}
    }
    
    int ans=(int)pow(2, kaisuu);
    
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 256
[a,b,k]=map(int,input().split())
a_set=set([])
b_set=set([])
for i in range(1,101):
    if a%i == 0:
        a_set.add(i)
for i in range(1,101):
    if b%i ==0:
        b_set.add(i)
res=a_set&b_set
res=list(res)
res.sort(reverse=True)
print(res[k-1])

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



int main(){
    int N;
    cin >> N;
    std::vector<int> p(N);
    for(int i=0; i < N; i++){
        cin >> p[i];
    }
    int cnt = 0;
    // printf("hoge");
    for(int i=2; i < N; i++){
        int a = p[i-2] - p[i-1];
        int b = p[i] - p[i-1];
        if(a*b<0){
            cnt ++;
        }
    }
    cout << cnt << endl;
}


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

int main(){
  int n,d,k,chd,chk,o;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d>>k;
    chd=0;
    chk=0;
    if(d%100!=0)chd=1;
    if(k%30!=0)chk=1;
    o=0;
    o=d/100+(k/30*5);
    if(chd==0&&chk==0){
      cout<<o<<endl;
    }else if(chd==0&&chk==1){
      cout<<o<<" "<<o+5<<endl;
    }else if(chd==1&&chk==0){
      cout<<o<<" "<<o+1<<endl;
    }else if(chd==1&&chk==1){
      cout<<o<<" "<<o+1<<" "<<o+5<<" "<<o+6<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	string s;
	int n;
	cin >> n >> s ;
	bool f = false;
	for (int i = 0; i < n/2; i++) {
		if (n % 2 == 1) {
			break;
		}
		int h = n / 2;
		if (s[i] == s[h+i]) {
			if (i == n/2-1) {
				f = true;
			}
		}
		else {
			break;
		}
	}

	if (f == true) {
		ce("Yes")
	}
	else {
		ce("No")
	}
	

	
}



int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main(){
  int N;
  cin >> N;
  int p[N][3];
  int i, j;
  for(i = 0; i < N; i++){
    for(j = 0; j < 3; j++){
      cin >> p[i][j];
    }
  }
  set< set<int> > Q;
  for(int k = 0; k < N; k++){
    set<int> R;
    for(int l = 0; l < 3; l++){
      R.insert(p[k][l]);
    }
    Q.insert(R);
  }
  cout << (N - Q.size()) << endl;
  return 0;
}

Measured memory_bytes: 3344
#include<iostream>
#include<algorithm>
#include<vector>
int N;
std::vector<int> A;
std::vector<int> S;
int D[100010];
int g,k;
int main(){
    std::cin>>N;
    for(int i=0;i<N;i++){
        int tmp;
        std::cin>>tmp;
        A.emplace_back(tmp);
        S.emplace_back(tmp);
    }
    std::sort(S.begin(),S.end());
    for(int i=0;i<N;i++){
        auto it=lower_bound(S.begin(),S.end(),A[i]);
        int acc=it-S.begin();
        D[acc]=i;
    }
    for(int i=0;i<N;i++){
        if((D[i]-i)%2){
            if(i%2)g++;
            else k++;
        }
    }
    std::cout<<std::max(g,k)<<std::endl;
    return 0;
}

Measured memory_bytes: 1652
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include "math.h"
using namespace std;

int main() {
    
    int N, M, C;
    
    cin >> N >> M >> C;
    
    int B[M];
    for (int j = 0; j < M; j++) {
        cin >> B[j];
    }
    
    int count = 0;
    
    for (int i = 0; i < N; i++) {
        int res = 0;
        for (int j = 0; j < M; j++) {
            int a;
            cin >> a;
            res += a*B[j];
        }
        if (res + C > 0) {
            count += 1;
        }
    }

    cout << count << endl;
    
    
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <stdint.h>

using namespace std;
#define REP(I,SIZE) for(int64_t I = 0;I < (int64_t)SIZE;I++)

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

  bool f = false;
  REP(i,buf.length()){
    if(buf[i] == '9'){
      f = true;
      break;
    }
  }

  if(f){
    cout << "Yes";
  }else{
    cout << "No";
  }

}


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

using namespace std;



int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("err.txt","w",stderr);
  #endif
    string s,t;
    cin>>s>>t;int co=0;
    for(int i=0;i<s.length();i++)
    {
    	if(s[i]!=t[i])
    		co++;
    }
    cout<<co;
}

Measured memory_bytes: 3920
open Batteries

let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let s = Scanf.scanf "%s " (fun a -> a) in

  let char_arr = Array.of_list (String.to_list s) in
  let res = ref n in

  let left_w = Array.make n 0 in
  let right_e = Array.make n 0 in

  for i=1 to (n-1) do
    if char_arr.(i-1) = 'W' then 
      left_w.(i) <- left_w.(i-1) + 1
    else
      left_w.(i) <- left_w.(i-1)
  done;

  for i=1 to (n-1) do
    let i = n-1-i in
    if char_arr.(i+1) = 'E' then 
      right_e.(i) <- right_e.(i+1) + 1
    else
      right_e.(i) <- right_e.(i+1)
  done;

  for i=0 to (n-1) do
    let v = left_w.(i) + right_e.(i) in
    if v < !res then res := v
  done;

  print_endline (string_of_int (!res))


Measured memory_bytes: 22784
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, len(p)-1):
    if p[i-1] < p[i] and p[i] < p[i+1] or p[i-1] > p[i] and p[i] > p[i+1]:
        ans += 1

print(ans)

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

int	main()
{
    int N;
    cin >> N;
    vector<int> x_vec(N), y_vec(N);
    for (int i = 0; i < N; ++i)
        cin >> x_vec.at(i) >> y_vec.at(i);
    vector<int> route(N, 0);
    for (int i = 0; i < N; ++i)
        route.at(i) = i;
    double sum_dist = 0;
    int cnt = 0;
    do {
        ++cnt;
        double dist = 0;
        for (int i = 0; i < N - 1; ++i) {
            int j1 = route.at(i);
            int j2 = route.at(i + 1);
            int dx = x_vec.at(j2) - x_vec.at(j1);
            int dy = y_vec.at(j2) - y_vec.at(j1);
            dist += hypot(dx, dy);
        }
        sum_dist += dist;
    } while (next_permutation(route.begin(), route.end()));
    cout << setprecision(10) << sum_dist / cnt << endl;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
// #include <atcoder/all> // NOTE: AtCoderライブラリ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
// using namespace atcoder; // NOTE: AtCoderライブラリ
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int, int> pii;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int A, B; cin >> A >> B;

    int d = B - A;
    int sum = 0;
    for (int i = 1; i < d; i++) {
        sum += i;
    }

    cout << (sum - A) << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1e9+7;

int main(){
    ll x,y;
    cin >> x >> y;
    int ans = 0;
    while(x <= y){
        x *= 2;
        ans++;
    }    
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
        int h[] = new int[n];
        int i;
        int count = 0;
        for(i = 0;i < n;i++){
          h[i] = sc.nextInt();
          if(h[i] >= k){
            count += 1;
          }
        }
       System.out.println(count);  
  
    }
}

Measured memory_bytes: 59164
#include <stdio.h>
int main(void)
{
  int a[200000];
  int i,n;
  int max = 0;
  int max_2 = 0;
  int *p;

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

  for(i = 0; i < n; i++){
    if(max < a[i]){
      max = a[i];
      p = &a[i];
    }
  }

  for(i = 0; i < n; i++){
    if(p != &a[i] && max_2 < a[i]){
        max_2 = a[i];
      }
  }

  
  for(i = 0; i < n; i++){
    if(max != a[i]){
      printf("%d\n", max);
    }
    else {
      printf("%d\n", max_2);
    }
  }

  return(0);
}


Measured memory_bytes: 2304
A,V=list(map(int,input().split()))
B,W=list(map(int,input().split()))
T=int(input())
flag=0

dist=B-A
speed=V-W
if dist<0:
    dist=-dist

if speed<1:
    flag=0
elif dist-(speed*T)<=0:
    flag=1


if flag==1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9196
n = int(input())
L = [list(map(int, input().split())) for _ in range(n)]

flag = True

for i in range(n):
    if abs(L[i][1] + L[i][2])>L[i][0] or (L[i][1] + L[i][2])%2 != L[i][0]%2:
        flag=False
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27300
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var ans = 0;
            var f = 0;

            while(f == 0)
            {
                for(int i = 0; i < n; i++)
                {
                    if(a[i] % 2 == 0)
                    {
                        a[i] /= 2;
                    }
                    else
                    {
                        f = 1;
                        break;
                    }
                }

                if(f == 1)
                {
                    break;
                }

                ans++;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28300
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

double p, e, t;

double dfs(int k, double l, double r) {
    double h = (l + r) / 2.0;
    if (k == 0) {
        if (fabs(t - h) < e)
            return 1.0;
        else
            return 0.0;
    }
    if (t - e <= l && r <= t + e) return 1.0;
    if (r < t - e || t + e < l) return 0.0;
    if (h >= t)
        return p * dfs(k - 1, h, r) + (1.0 - p) * dfs(k - 1, l, h);
    else
        return p * dfs(k - 1, l, h) + (1.0 - p) * dfs(k - 1, h, r);
}

int main() {
    int k;
    double l, r;
    cin >> k >> l >> r;
    cin >> p >> e >> t;
    cout << fixed << setprecision(10) << dfs(k, l, r) << endl;
    return 0;
}


Measured memory_bytes: 3292
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int answer=-10000000000;
	int n,k;
	cin>>n>>k;
	int j,arr1[n+1],arr2[n+1];
	for(j=1;j<=n;j++)
	{
		cin>>arr1[j];
	}
	for(j=1;j<=n;j++)
	    cin>>arr2[j];
	int temp=k;
	for(j=1;j<=n;j++)
	{
		int heremax=-10000000000;
		int score=0;
		int src=j;
		k=temp;
		if(k<=5000)
		{
			while(k!=0)
			{
				src=arr1[src];
				k--;
				score+=arr2[src];
				heremax=max(heremax,score);
			}
			answer=max(answer,heremax);
			continue;
		}
		else
		{
			int cyclesum=0,cyclelength=0;
			bool visited[n+1]={false};
			while(!visited[src])
			{
				visited[src]=true;
				src=arr1[src];
				cyclesum+=arr2[src];
				score+=arr2[src];
				heremax=max(heremax,score);
				cyclelength++;
			}
			int total=k/cyclelength;
			k%=cyclelength;
			if(k==0)
			{
				int val=(total-1)*cyclesum;
				val+=heremax;
				int val2=0;
				val2+=heremax;
				int herevalue=max(val,val2);
				answer=max(answer,herevalue);
			}
			else
			{
				int val1=heremax;
				int val2=total*cyclesum;
				int val3=(total-1)*cyclesum+heremax;
				score=0;
				heremax=-10000000000;
				src=j;
				int prev=max(val1,max(val2,val3));
				while(k!=0)
				{
					src=arr1[src];
					k--;
					score+=arr2[src];
					heremax=max(heremax,score);
				}
				int val4=max(0LL,heremax);
				val2+=val4;
				prev=max(prev,val2);
				answer=max(answer,prev);
			}
		}
	}
	cout<<answer<<endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  int ans = 2e9;
  for (int i = 0; i <= s.size() - 3; i++) {
    ans = min(ans, (int) abs(stoi(s.substr(i, 3)) - 753));
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N;
  cin>>N;
  vector<int> B(N-1);
  rep(i,N-1)cin>>B[i];
  int ans=0;
  rep(i,N-2)ans+=min(B[i],B[i+1]);
  ans+=(B[0]+B[N-2]);
  cout<<ans<<endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define MAX 200000
#define MOD 1000000007
#define INF 4000000000000000000
#define EPS 0.0000000000001
int main()
{
    char s[3];
    scanf("%c%c%c",&s[0],&s[1],&s[2]);
    if(s[1]=='R') s[1]='B';
    else s[1]='R';
    printf("%c%c%c",s[0],s[1],s[2]);
    return 0;
}



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

using ll = long long;
using vint = vector<int>;
using vll = vector<ll>;
constexpr ll LLINF = numeric_limits<ll>::max();

string S;
vint v(3);
string c = "+-*";

ll merge(ll a, ll b, int f) {
	if (f == 0) return (a + b);
	if (f == 1) return (a - b);
	return (a * b);
}

//[a, b)
ll solve(int a, int b) {
	//char r; cin >> r;
	//cout << a << " " << b << endl;

	if (S[a] == '(' && S[b-1] == ')') {
		a++, b--;
		int cnt = 0;
		bool ff = false;
		for (int i = a; i < b; i++) {
			if (S[i] == '(') cnt++;
			if (S[i] == ')') cnt--;
			if (cnt < 0) ff = true;
		}
		if (!ff) return (solve(a, b));
		a--, b++;
	}

	int cnt = 0;
	vint li1;
	li1.push_back(a);
	for (int i = a; i < b; i++) {
		if (S[i] == '(') cnt++;
		if (S[i] == ')') cnt--;
		if (cnt == 0) {
			for (int k = 0; k < 3; k++) {
				if (S[i] == c[k] && v[k] == 1) li1.push_back(i);
			}
		}
	}
	li1.push_back(b);
	
	if (li1.size() > 2) {
		ll val = solve(li1[0], li1[1]);
		for (int i = 1; i < (int)li1.size()-1; i++) {
			int d1 = li1[i], d2 = li1[i+1];
			for (int k = 0; k < 3; k++) {
				if (S[d1] == c[k]) val = merge(val, solve(d1+1, d2), k);
			}
		}
		return (val);
	}

	cnt = 0;
	vint li2;
	li2.push_back(a);
	for (int i = a; i < b; i++) {
		if (S[i] == '(') cnt++;
		if (S[i] == ')') cnt--;
		if (cnt == 0) {
			for (int k = 0; k < 3; k++) {
				if (S[i] == c[k] && v[k] == 2) li2.push_back(i);
			}
		}
	}
	li2.push_back(b);
	
	if (li2.size() > 2) {
		ll val = solve(li2[0], li2[1]);
		for (int i = 1; i < (int)li2.size()-1; i++) {
			int d1 = li2[i], d2 = li2[i+1];
			for (int k = 0; k < 3; k++) {
				if (S[d1] == c[k]) val = merge(val, solve(d1+1, d2), k);
			}
		}
		return (val);
	}

	cnt = 0;
	vint li3;
	li3.push_back(a);
	for (int i = a; i < b; i++) {
		if (S[i] == '(') cnt++;
		if (S[i] == ')') cnt--;
		if (cnt == 0) {
			for (int k = 0; k < 3; k++) {
				if (S[i] == c[k] && v[k] == 3) li3.push_back(i);
			}
		}
	}
	li3.push_back(b);
	
	if (li3.size() > 2) {
		ll val = solve(li3[0], li3[1]);
		for (int i = 1; i < (int)li3.size()-1; i++) {
			int d1 = li3[i], d2 = li3[i+1];
			for (int k = 0; k < 3; k++) {
				if (S[d1] == c[k]) val = merge(val, solve(d1+1, d2), k);
			}
		}
		return (val);
	}

	ll ret = stol(S.substr(a, b-a));
	//cout << a << " " << b << " " << ret << endl;
	return (ret);
}

int main() {
	cin >> S;

	ll maxv = -LLINF;
	for (v[0] = 1; v[0] <= 3; v[0]++) {
		for (v[1] = 1; v[1] <= 3; v[1]++) {
			for (v[2] = 1; v[2] <= 3; v[2]++) {
				ll val = solve(0, S.size());
				maxv = max(maxv, val);
			}
		}
	}

	cout << maxv << endl;
	return (0);
}



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

int main(){
    int N,M;
    cin >> N >> M;

    int H[100010];
    int A,B;
    int C[100010]={0};
    int i;

    for(i=1; i<N+1; i++){
        cin >> H[i];
    }

    for(i=0; i<M; i++){
        cin >> A >> B;
        if(H[A]<H[B]){
            if(C[A]==0) C[A]=1;
        }
        else if(H[A]>H[B]){
            if(C[B]==0) C[B]=1;
        }
        else{
            if(C[A]==0) C[A]=1;
            if(C[B]==0) C[B]=1;
        }
    }
    
    int count=0;
    for(i=1; i<N+1; i++){
        if(C[i]==0) count++;
    }
/*
    for(i=1; i<N+1; i++){
        cout << C[i] << ' ';
    }
    cout << endl;*/
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int c[3][3];
    string ans="Yes";
    rep(i,3){
        rep(j,3){
            cin>>c[i][j];
        }
    }
    rep(i,2){
        rep(j,2){
            if(abs(c[i][j]-c[i][j+1])!=abs(c[i+1][j]-c[i+1][j+1])){
                ans="No";
            }
        }
    }
    rep(j,2){
        rep(i,2){
            if(abs(c[i][j]-c[i][j+1])!=abs(c[i+1][j]-c[i+1][j+1])){
                ans="No";
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	S := sc.next()
	a := S[0 : len(S)/2]
	var redi int
	if len(S)%2 == 1 {
		redi++
	}
	b := S[len(S)/2+redi : len(S)]

	var cnt int
	for i := 0; i < len(a); i++ {
		if a[i] != b[len(a)-1-i] {
			cnt++
		}
	}
	fmt.Println(cnt)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


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

using namespace std;

typedef long long ll;

int main(void) {

	int n;
	ll max[2];
	multiset<ll> s;

	cin >> n;

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

		ll num; cin >> num;

		s.insert(num);

	}

	int idx = 0;
	int cnt = 0;

	ll pre = 0;

	max[0] = max[1] = 0;

	for (auto itr = s.rbegin(); idx < 2 && itr != s.rend(); ++itr) {

		if (pre != *itr) {

			pre = *itr;

			cnt = 0;

		}
		else {

			++cnt;

		}

		if (cnt == 1) {

			max[idx] = *itr;

			++idx;

			cnt = pre = 0;

		}

	}

	if (max[0] == 0 || max[1] == 0) {

		cout << 0 << endl;

	}
	else {

		cout << max[0] * max[1] << endl;

	}

	return 0;

}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void){

 int a,b;

 scanf("%d %d",&a,&b);

 if(a<b){
 printf("a < b\n");
}

 if(a>b){
 printf("a > b\n");
}

 if(a==b){
 printf("a == b\n");
}

return 0;

}

Measured memory_bytes: 580
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)

	pos := []int{-1, -1, -1}
	for i := 0; i < m; i++ {
		var s, c int
		fmt.Scanf("%d %d", &s, &c)
		if pos[s-1] == -1 {
			pos[s-1] = c
		} else if pos[s-1] != c {
			pos[s-1] = -2
		}
	}

	if pos[0] == -2 || pos[1] == -2 || pos[2] == -2 {
		fmt.Println("-1")
	} else if n != 1 && pos[0] == 0 {
		fmt.Println("-1")
	} else {
		if n == 1 && pos[0] == -1 {
			fmt.Print("0")
		} else if pos[0] == -1 {
			fmt.Print("1")
		} else {
			fmt.Print(pos[0])
		}
		for i := 1; i < n; i++ {
			if pos[i] == -1 {
				fmt.Print("0")
			} else {
				fmt.Print(pos[i])
			}
		}
		fmt.Println("")
	}

}


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

int main() {
    long n, ans = 0;
    cin >> n;
    queue<long> que;
    que.push(0);
    while(que.size()) {
        long temp = que.front();
        que.pop();
        if(temp > n) continue;
        que.push(10 * temp + 3);
        que.push(10 * temp + 5);
        que.push(10 * temp + 7);
        bool flag3 = false, flag5 = false, flag7 = false;
        while(temp) {
            if(temp % 10 == 3) flag3 = true;
            if(temp % 10 == 5) flag5 = true;
            if(temp % 10 == 7) flag7 = true;
            temp /= 10;
        }
        if(flag3 && flag5 && flag7) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
// * Act locally, think globally.

#include <bits/stdc++.h>

using namespace std;

#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

const int N = 2e5 + 7;

signed main()
{
    vector<int> cnt(2019);
    string s;
    cin >> s;
    int sum = 0;
    cnt[0] = 1;
    for (int i = s.length() - 1, b = 1; i >= 0; --i)
    {
        sum = (sum + b * (s[i] - '0')) % 2019;
        ++cnt[sum];
        b = (10 * b) % 2019;
    }
    int ans = 0;
    for (int i = 0; i < 2019; ++i)
    {
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int main(void)
{
	int N,T,S;
	int A[3001],B[3001];
	int i,j;
	
	cin>>N>>T>>S;
	for(i=0;i<N;i++){
		cin>>A[i]>>B[i];
	}
	
	for(i=0;i<=N;i++){
		for(j=0;j<=T;j++){
			dp[i][j]=0;
		}
	}
	
	int TT;
	
	for(i=0;i<N;i++){
		for(j=0;j<=T;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j<S&&S<j+B[i]){
				TT=S+B[i];
			}
			else{
				TT=j+B[i];
			}
			if(TT<=T&&dp[i+1][TT]<dp[i][j]+A[i]){
				dp[i+1][TT]=dp[i][j]+A[i];
			}
		}
	}
	
	/*for(i=0;i<N;i++){
		for(j=0;j<=T;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	
	int MAX=-1;
	for(i=0;i<=T;i++){
		MAX=max(MAX,dp[N][i]);
	}
	
	cout<<MAX<<endl;
	return 0;
}

	
	


Measured memory_bytes: 38340
#include<cstdio>
using namespace std;
char s[110];
int l,f[110][110],num,num1,num2,i,j,k,len;
int min(int a,int b){return a<b?a:b;}
int main()
{
	scanf("%d",&l);
	scanf("%s",s);
	for (i=1;i<=l;i++) f[i][i]=1;
	for (len=2;len<=l;len++)//length first!
	  for (i=1;i<=l-len+1;i++)//starting point
	    {
	    	j=i+len-1;
	    	f[i][j]=1000;
	    	if (s[i-1]=='('&&s[j-1]==')') f[i][j]=f[i+1][j-1];
	    	for (k=i;k<j;k++)
	    	  f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);
		}
	num=(l+f[1][l])/2;
	for (i=0;i<l;i++)
	{
		if (s[i]=='(') num1++;
		else num2++;
	}
	for (i=1;i<=num-num1;i++) printf("(");
	printf("%s",s);
	for (i=1;i<=num-num2;i++) printf(")");
}
//valid iff number of ( and ) match ans sum1[i]>=sum2[i]
//find the shortest length
//((((((................))))))))))) is the lexicographically smallest string

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleTest
{
    class Program
    {

        static void Main(string[] args)
        {
            long[] p = Console.ReadLine().Split(' ')
                .Select(s => long.Parse(s)).ToArray();
            //Console.WriteLine(string.Join(',', p.Select(i => i.ToString())));

            long n = p[0] / (p[1] + p[2]);
            long mod = p[0] % (p[1] + p[2]);
            long result = n*p[1] +Math.Min(mod, p[1]);
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;



namespace CSharpSample01
{

    
      
    class Program
    {
        
        static void Main(string[] args)
        {
            //入力1(S)
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            int cnt = 0;
            int h = 1;

            while (h < B)
            {
                cnt++;
                h += (A - 1);
            }

            Console.WriteLine(cnt);
        }
    }

}

Measured memory_bytes: 13140
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  h,w,i,j,count,x,y,m,n,c,a,b,min:Integer;
  //a:array of string;
  s,s1,s2,s3:string;
  sw:char;
  tf:Boolean;
  nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(s);

    for i := 1 to Length(s) do begin
      min := i;
      for j := i+1 to Length(s) do begin
        if s[j] < s[min] then
        min := j;
      end;
      sw:=s[i];
      s[i]:=s[min];
      s[min]:=sw;
    end;

    for i := 1 to Length(s) - 1 do
      if s[i]=s[i+1] then begin
        Writeln('no');
        Readln;
        exit;
      end;

    Writeln('yes');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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

int main() {
	//freopen("data.txt", "r", stdin);
	int x, y;	cin >> x >> y;
	for (int i = 0; i < y + 2; ++i) {
		cout << "#";
	}
	cout << "\n";
	for (int i = 0; i < x; ++i) {
		cout << "#";
		for (int j = 0; j < y; ++j) {
			char c; cin >> c;
			cout << c;
		}
		cout << "#\n";
	}
	for (int i = 0; i < y + 2; ++i) {
		cout << "#";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
n=int(input())
abc="abcdefghijklmnopqrstuvwxyz"
ans=""
while True:
  if n % 26 == 0:
    ans += "z"
    n = (n-1)//26
  else:
    ans += abc[n%26-1]
    n //= 26
  if n == 0:
    print(ans[::-1])
    break

Measured memory_bytes: 9108
import numpy as np
from numba import jit
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
@jit
def imos(a):
    tmp = np.zeros(n+1, dtype=np.int64)
    for i in range(n):
        tmp[max(0, i - a[i])] += 1
        tmp[min(i + a[i] + 1, n)] -= 1
    tmp = np.cumsum(tmp)
    return tmp[:n]

for j in range(1, min(k+1, 50)):
    a = imos(a)
print(*a)

Measured memory_bytes: 123592
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a*n, b) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
const int maxn = 1001000;
int tab[maxn], zysk[maxn], n;

int main()
{
	boost;
	cin >> n;
	int wa = 0;
	FOR(i, 1, n) {
		cin >> tab[i];
		zysk[i] = zysk[i-1];
		if (tab[i] == i) ++wa;
		if (i > 1 && tab[i] == i && tab[i-1] == i-1) {
			//cout << "HERE";
			zysk[i] = max(zysk[i], zysk[i - 2] + 1);
		}
	}

	cout << wa - zysk[n];
}


Measured memory_bytes: 4736
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


g = Graph()
N, M = [int(i) for i in input().split()]
#N = int(input())

for i in range(M):
    u, v = [int(i) for i in input().split()]
    u -= 1
    v -= 1
    g.add_edge(3*u+0, 3*v+1, 1)
    g.add_edge(3*u+1, 3*v+2, 1)
    g.add_edge(3*u+2, 3*v+0, 1)

S, T = [int(i) for i in input().split()]
d1 = Dijkstra(g, (S-1)*3)
ans = 0
if d1.dist[(T-1)*3] != float("inf"):
    print(d1.dist[(T-1)*3]//3)
else:
    print(-1)



Measured memory_bytes: 150008
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  long T, A;
  cin >> T >> A;
  long t, a, count;
  for(int i = 0; i < N - 1; i++) {
    cin >> t >> a;
    count = max(T / t, A / a);
    while(1) {
      if(T <= (t * count) && A <= (a * count)) {
        T = t * count, A = a * count;
        break;
      } else count++;
    }
  }
  cout << T + A << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
 
int main(void)
{
    int n,x,cnt,i,j,k,sum;
	
	while(1){
		scanf("%d %d",&n,&x);
		if(n==0 && x==0){
			break;
		}
		cnt=0;
		for(i=1;i<=n-2;i++){
			sum=i;
			for(j=i+1;j<=n-1;j++){
				sum+=j;
				for(k=j+1;k<=n;k++){
					sum+=k;
					if(sum==x){
						cnt++;
					}
					sum-=k;
				}
				sum-=j;
			}
		}
		printf("%d\n",cnt);
	}
	
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)3e5+5;
const int M = (int)1e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

void solve() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans = -2*lim;
  if((a<=0 && b>=0) || (c<=0 && d>=0)) {
    ans = 0;
  }
  ans = max({ans, a*c, a*d, b*c, b*d});
  cout << ans;
}

int main() {
    //freopen("./sort/b2.in","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
const long long inf = 1e18;
const int MAXN = 105;
const int MAXV = 1e3 + 5;
long long DP[MAXN][MAXN * MAXV];
int N;
long long W;
long long V[MAXN];
long long wt[MAXN];
long long rec(int idx, int value)
{
    if(idx == N){
        if(value == 0)
            return 0;
        return inf;
    }
    if(DP[idx][value] != -1)
        return DP[idx][value];
    return DP[idx][value] = min(wt[idx] + rec(idx + 1, value - V[idx]), rec(idx + 1, value));
}

int main()
{
    cin >> N >> W;
    for(int i = 0; i < N; ++i)
        cin >> wt[i] >> V[i];
    for(int j = 0; j < MAXN; ++j)
        for(int i = 0; i < MAXN * MAXV; ++i)
            DP[j][i] = -1;
    for(int i = 1; i < MAXN * MAXV; ++i)
        rec(0, i);
    for(int i = (MAXN * MAXV) - 1; i >= 0; --i)
    {
        if(DP[0][i] <= W)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << "0\n";
    return 0;
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<pair<ll,ll>> v(n);
    vector<ll> p(n);
    for(i=0;i<n;i++){
        p[i]=i;
        cin >> v[i].first >> v[i].second;
    }
    double ret = 0;
    do{
        /*for(ll x : p) {
            cout << x << " ";
        }
        cout << endl;*/
        for(i = 1; i < n; i++) {
            ret += sqrt((double)(v[p[i]].first - v[p[i - 1]].first) * (v[p[i]].first - v[p[i - 1]].first) + (double)(v[p[i]].second - v[p[i - 1]].second) * (v[p[i]].second - v[p[i - 1]].second));
        }
    }
    while(next_permutation(p.begin(),p.end()));
    for(i=1;i<=n;i++){
        ret /= (double)i;
    }
    printf("%.10f\n",ret);
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
	int n;
	ll t;
	cin >> n >> t;
	ll ans = 0;
	ll yotei = 0;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		if (yotei <= x) {
			ans += t;
			yotei = x + t;
		}
		else {
			ans += x + t - yotei;
			yotei = x + t;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!(
    r: i32,
    );
    println!("{}", 3 * r * r);
}

Measured memory_bytes: 4352
import java.util.Scanner;
import java.util.Arrays;


public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int t = sc.nextInt();
        int answer = 0;
        if(n%x==0){
            answer = (n/x)*t; 
        }else{
            answer = (n/x+1)*t;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 35732
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val t = readLine()!!.split(' ').map { it.toInt() }
    val sum = t.sum()
    val m = readLine()!!.toInt()

    repeat(m) {
        val (p, x) = readLine()!!.split(' ').map { it.toInt() }
        val d = t[p-1] - x
        println(sum-d)
    }
}


Measured memory_bytes: 38080