akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = list(input())
text = ""


def incre(n, i):
    if n > 26:
        n - 26 * (n // 26)

    d = ord(i) + n
    if d > 90:
        d -= 26

    return chr(d)


for i in S:
    text += incre(N, i)

print(text)

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    static int n,m;
    static long mod = 1000000000+7;
    // static ArrayList<Integer>[] graph,tree;
    public static void main(String[] args)throws IOException {
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        Scanner sc = new Scanner(System.in);
        //String[] buf = reader.readLine().split(" ");
        n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[] cnt = new int[26];
        for(char w:s){
            cnt[w-'a']++;
        }
        long ans = 1;
        for(int i=0;i<26;i++){
            ans = ans*(cnt[i]+1)%mod;
        }
        ans = (ans-1+mod)%mod;
        System.out.println(ans);
    }
    static long pow(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
}

Measured memory_bytes: 25940
import java.util.*

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	var bBef = scanner.nextInt()
	var ans = bBef;
	for (i in 2..n-1){
		val bi = scanner.nextInt()
		ans += Math.min(bBef, bi)
		bBef = bi
	}
	ans += bBef
	println(ans)
}

Measured memory_bytes: 31400
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  char X, Y;
  cin >> X >> Y;

  if (X > Y)
    printf(">\n");
  else if (X == Y)
    printf("=\n");
  else
    printf("<");

  return 0;
}


Measured memory_bytes: 256
from functools import reduce

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

def lcm(x, y):
  return (x * y) // gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm, numbers, 1)

n = [int(input()) for _ in range(int(input()))]
print(lcm_list(n))

Measured memory_bytes: 3572
n , x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
cou = 0
for i in range(n):
    cou += a[i]
    if cou > x:
        print(i)
        exit()
if cou == x:
    print(n)
else:
    print(n-1)

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

using namespace std;

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

	long long sum = 0;
	for (int i = 1; i <= N; i++)
	{
		/* code */
		if(i % 3 != 0 && i % 5 != 0){
			sum += i;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string sr;
  cin>>sr;
  vector<int>vc;
   int a,b;
  for(int i=0;i<=sr.length()-3;i++)
  {


    a=(sr[i]-'0')*100+(sr[i+1]-'0')*10+(sr[i+2]-'0');
     vc.push_back(abs(753-a));
  }
sort(vc.begin(),vc.end());
cout<<vc[0]<<endl;


}


Measured memory_bytes: 256
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] S = sc.next().split("");
    long total = 0;
    for (int i = 0; i < Math.pow(2,S.length-1); i++) {
      StringBuilder s = new StringBuilder();
      for (int j = 0; j < S.length; j++) {
        s.append(S[j]);
        if ((1 & i>>j) == 1) {
          total += Long.parseLong(s.toString());
          s.setLength(0);
        }
      }
      if (s.length() != 0) {
        total += Long.parseLong(s.toString());
      }
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 21972
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    a = list(map(int, input().split()))

    c = Counter(a)
    ans = 0
    for k, v in c.items():
        if k < v:
            ans += (v - k)
        elif v < k:
            ans += v

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18340
<?php
fscanf(STDIN, "%d %d", $h, $w);
for ($i = 0; $i < $h; $i++) {
	fscanf(STDIN, "%s", $s[]);
}
$a = array_fill(0, $h, array_fill(0, $w, 0));
$x = 1;
for ($i = 0; $i < $h; $i++) {
	for ($j = 0; $j < $w; $j++) {
		if ($s[$i][$j] == '#') continue;
		for ($k = $j + 1; $k <= $w; $k++) {
			if (!isset($s[$i][$k]) || $s[$i][$k] == '#') {
				$r = $k - $j;
				for ($p = $j; $p < $k; $p++) {
					$a[$i][$p] = $r;
				}
				$j = $k;
				break;
			}
		}
	}
}
for ($j = 0; $j < $w; $j++) {
	for ($i = 0; $i < $h; $i++) {
		if ($s[$i][$j] == '#') continue;
		for ($k = $i + 1; $k <= $h; $k++) {
			if (!isset($s[$k][$j]) || $s[$k][$j] == '#') {
				$r = $k - $i;
				for ($p = $i; $p < $k; $p++) {
					$y = $a[$p][$j] + $r - 1;
					if ($y > $x) $x = $y;
				}
				$i = $k;
				break;
			}
		}
	}
}
echo $x;

Measured memory_bytes: 145912
h, w = [int(x) for x in input().split()]
if h == 1 or w == 1:
    res = 1
else:
    if w%2 == 0:
        res = h * w // 2
    else:
        res = h * (w//2) + (h + 2 - 1)//2
print(res)


Measured memory_bytes: 2940
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        mut tt: [usize; n]
    };
    tt.sort();
    tt.dedup();
    if tt.len() == 1 {
        println!("{}", tt[0]);
        return;
    }
    let ans = tt.iter().fold(1usize, |acc, &t| lcm(acc, t));
    println!("{}", ans);
}

fn lcm(a: usize, b: usize) -> usize {
    return a / gcd(a, b) * b;
}

fn gcd(m: usize, n: usize) -> usize {
    return if n == 0 { m } else { gcd(n, m % n) };
}


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

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

 typedef long long ll;
 const long long INF = 1LL << 60;



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

    for(int i = 0; i < s.size(); i++)
    {
        cout << 'x';
    }
    
    cout << endl;


    return 0;
 }

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();

		boolean gate[] = new boolean[n + 1];
		for(int i = 0; i < m; i++){
			gate[sc.nextInt()] = true;
		}

		int result = 0;
		int tmp = 0;
		for(int i = x; i >= 0; i--){
			if(gate[i]){
				tmp++;
			}
		}

		result = tmp;

		tmp = 0;
		for(int i = x; i <= n; i++){
			if(gate[i]){
				tmp++;
			}
		}

		result = Math.min(result, tmp);

		System.out.println(result);
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define nitro ios_base::sync_with_stdio(false);cin.tie(0);
#define l  long
#define ll  long long
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
int main()
{
     nitro
     int n,r;cin>>n>>r;
     if(n<10) cout<<r+((10-n)*100);
     else cout<<r;
     return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long dp[53][53][2501];
int main() {
    int n, k; cin >> n >> k;
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int pair = 0; pair <= n; pair++) {
            for (int c = 0; c < n*n; c++) {
                // dp[i][pair][c]
                if (i < pair) continue;
                dp[i+1][pair][c+(i-pair)*2] += dp[i][pair][c];
                dp[i+1][pair+1][c+(i-pair)*2] += dp[i][pair][c];
                dp[i+1][pair+1][c+(i-pair)*2] += dp[i][pair][c] * ((i-pair) * 1 * 2);
                dp[i+1][pair+2][c+(i-pair)*2] += dp[i][pair][c] * (i-pair) * (i-pair);
                dp[i+1][pair][c+(i-pair)*2] %= mod;
                dp[i+1][pair+1][c+(i-pair)*2] %= mod;
                dp[i+1][pair+2][c+(i-pair)*2] %= mod;
            }
        }
    }
    cout << dp[n][n][k] << endl;
}

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


int main()
{
	string s;
	getline(cin,s);
	
	int ans = 0;
	vector<int> a;
	for(int i=0;i<3;i++)
	{
		if(s[i] == 'R')
		{
			ans++;
		}
		else
		{
			a.push_back(ans);
			ans = 0;
		}
		
	}
	a.push_back(ans);
	cout<<*max_element(a.begin(),a.end())<<endl;
	
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void solve() {
    int n, x, t;
    cin >> n >> x >> t;
    ll res=((n+x-1)/x)*t;
    cout << res << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		char color = s.charAt(0);
		int ans = 1;
		for(int i = 0; i < s.length(); i++) {
			if(color != s.charAt(i)) {
				ans++;
				color = s.charAt(i);
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 25684
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static object Solve() {
        return Console.ReadLine().Replace("eraser", "").Replace("erase", "").Replace("dreamer", "").Replace("dream", "") == "" ? "YES" : "NO";
    }
}

Measured memory_bytes: 26824
#include<iostream>
#include<vector>
#include<map>
//mapを使うことにより配列の通し番号ではなくキーとして数字を処理するので
//上限を設ける必要がない。今回のポイントは初期値が0であることを利用する、だ。
using namespace std;

int func(int n){
    if(n%2){
        return 3*n+ 1;
    }else{
        return n/2;
    }
}

int main(){
    int s;
    cin >> s;
    map<int,int> mp;
    
    //mp[s]の初期値は０だった。
    //一度登場するとインクリメントが行われる。
    mp[s]++;
    //最短で一致するとa2となるので。
    int count = 2;

    while(1){
        //この時点でｓは別物のｓとなる。
        s = func(s);

        //なるほど、同じ数字が出てくると同じ配列？の通し番号
        //にアクセスすることを利用しているのか。
        if(mp[s]){
            cout << count << endl;
            return 0;
        }
        //一度登場するとインクリメントが行われる。
        mp[s]++;
        count++;
        
    }
    


    

}


Measured memory_bytes: 256
n=int(input())
dp=[i for i in range(n+1)]
for i in range(n):
    for j in range(7):
        if i+6**j>n:
            continue
        dp[i+6**j]=min(dp[i+6**j],dp[i]+1)
        if i+9**j<=n:
            dp[i+9**j]=min(dp[i+9**j],dp[i]+1)
print(dp[n])

Measured memory_bytes: 7064
#include <iostream>
#include <vector>
using ll = long long int;

const int MAXB = 45;
ll N, K, A[1010];
std::vector<ll> sum;

ll dfs(int B, ll val) {
    if(B < 0) return val;
    
    ll target = val | (1LL << B), cnt = 0;
    for(size_t i=0; i<sum.size(); i++) {
        if((target & sum[i]) == target) cnt++;
    }
    if(cnt >= K) return dfs(B-1, val | (1LL << B));
    else return dfs(B-1, val);
}

int main() {
    std::cin >> N >> K;
    for(int i=0; i<N; i++) {
        std::cin >> A[i+1];
        A[i+1] += A[i];
    }
    for(int l=0; l<N; l++) {
        for(int r=l+1; r<=N; r++) {
            sum.push_back(A[r] - A[l]);
        }
    }
    std::cout << dfs(MAXB, 0LL) << std::endl;
    return 0;
}


Measured memory_bytes: 6256
// finish date: 2018/07/22
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, M;
    cin >> N >> M;
    vvi ab(M, vi(2));
    rep(i, M) cin >> ab[i][0] >> ab[i][1];

    sort(ab.begin(), ab.end(),
         [](vi a, vi b) {
             return (a[1] < b[1]);
         });

    int temp = 0;
    int cnt = 0;
    rep(i, M) {
        if (temp < ab[i][0]) {
            temp = ab[i][1]-1;
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 5760
#include<bits/stdc++.h>
#include<iostream>
#include <cstdio>
#include<cmath>
#define endl '\n'
#define sz 1000001
using namespace std;
typedef long long ll;
ll siv[sz],cnt;
std::vector<ll>prime(sz,0);
 
int main()
{
	ll limit = sqrt(sz+1);
	for(ll i = 3; i<=limit; i++)
		if(!siv[i])
			for(ll j = i*i; j<sz; j+=i+i)
				if(!siv[j])siv[j]=1;
	prime[cnt++]=2;
	for(ll i = 3; i<sz; i+=2)
		if(!siv[i])prime[cnt++]=i;
	ll x;
	cin>>x;
	vector<ll>::iterator it;
	sort(prime.begin(),prime.end());
	it = lower_bound(prime.begin(),prime.end(),x);
	cout<<*it;
	return 0;
}

Measured memory_bytes: 16000
'use strict'

const main = (input) => {
    const S = input.split('\n')[0]
    let ans = 1000
    for(let i = 0; i < S.length - 2; i++){
        let s = parseInt(S.slice(i, i + 3))
        let diff = Math.abs(753 - s)
        if(diff < ans){
            ans = diff
        }
    }
    console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

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

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}
	
int add(int x, int y, int mod = MOD998) {
	return x + y >= mod ? x + y - mod : x + y;
}

int sub(int x, int y, int mod = MOD998) {
	return x - y < 0 ? x - y + mod : x - y;
}

int mul(int x, int y, int mod = MOD998) {
	return 1LL * x * y % mod;
}

int pw(int a, int n, int mod = MOD998) {
	int res = 1;
	while (n) {
		if (n & 1) {
			res = mul(res, a, mod);
		}
		a = mul(a, a, mod);
		n >>= 1;
	}
	return res;
}

int inv(int x, int mod = MOD998) {
	return pw(x, mod - 2, mod);
}

vector<int> get_invs(int upto, int mod = MOD998) {
	vector<int> res(upto + 1);
	res[1] = 1;
	for (int i = 2; i <= upto; i++) {
		res[i] = mod - mul(mod / i, res[mod % i], mod);
	}
	return res;
}

void run() {
	int n;
	cin >> n;
	vector<vector<int>> graph(n);
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	vector<vector<int>> dp(n, vector<int>(2));
	function<int(int, int)> dfs = [&](int u, int p) {
		dp[u][0] = dp[u][1] = 1;
		for (int v : graph[u]) if (v != p) {
			dp[u][0] = mul(dp[u][0], dfs(v, u), MOD);
			dp[u][1] = mul(dp[u][1], dp[v][0], MOD);
		}
		return add(dp[u][0], dp[u][1], MOD);
	};
	cout << dfs(0, -1) << "\n";
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


Measured memory_bytes: 19584
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#include<ctype.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b
void check(int*,int);
int main() {
	int n,i,
		a[200],
		b[200],
		c[200];
	S(d, n);
	for (i = 0; i < n; i++) fscanf(stdin, "%d%d%d", a + i, b + i, c + i);
	check(a,n), check(b, n), check(c, n);
	for (i = 0; i < n; i++)P(d, a[i] + b[i] + c[i]);
	return 0;
}

void check(int *a,int n){
	int i,t,j;
	for (i = 0; i < n - 1; i++) {
		if (!a[i]) continue;
		for (j = i + 1, t = a[i]; j < n; j++)
			if (t == a[j]) a[i] = a[j] = 0;
	}
	return;
}

Measured memory_bytes: 604
import heapq

N,M = map(int, input().split())
A = [-int(n) for n in input().split()]

heapq.heapify(A)
for x in range(M):
	heapq.heappush(A, heapq.heappop(A)/2)
A_int = map(int, A)
print(-sum(A_int))


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

int main() {
	int N;
	cin >> N;
	double ans = 0;
	if (N % 2 == 0) {
		ans = 0.5;
	}
	else {
		ans = ((N + 1) / 2.0) / N;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(ll i=0;i<n;++i)
#define FOR(i,j,n) for(ll i=j;i<n;++i)
#define MOD (1e9 + 7)

int main(void){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll turn = 0;
    while(a>0 && c >0){
        if(turn==1){
            a-=d;
            turn = 0;
        }
        else{
            c-=b;
            turn = 1;
        }
    }
    if(a<=0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a;
        a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        for(int i = n-1; i > 0; i--){
            System.out.print(a[i]+" ");
        }
        System.out.println(a[0]);
    }    
}


Measured memory_bytes: 26244
import java.util.Scanner

import scala.io.StdIn._

object Main extends App {

  val Array(h,w,k) = readLine().split(" ").map(_.toInt)
  val C = Array.fill(h)(readLine().split(""))

  def solve() = {
    val hPlusW = h+w
    (0 until 1 << hPlusW).foldLeft(0) { (acc, i) =>
      var hRedMap = Map.empty[Int, Boolean]
      var wRedMap = Map.empty[Int, Boolean]
      for(j <- 0 until hPlusW) {
        if(isBitOn(i,j)) {
          if(j < h) hRedMap = hRedMap.updated(j, true)
          else wRedMap = wRedMap.updated(j-h, true)
        }
      }
      var cnt = 0
      for {
        l <- 0 until h
        c <- 0 until w
      } yield {
        if(!hRedMap.getOrElse(l, false) && !wRedMap.getOrElse(c, false) && C(l)(c) == "#") cnt += 1
      }
      if(cnt == k) acc + 1 else acc
    }
  }

  def isBitOn(num: Int, digit: Int): Boolean =
    (num & (1 << digit)) != 0


  println(solve())

}



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

int main() {
  const int MOD = 1000000007;
  int n; cin >> n;
  
  vector<int> alphabet(26);
  for (int i = 0; i < n; i++) {
    char c; cin >> c;
    alphabet.at(c - 'a')++;
  }
  
  long long answer = 1;
  for (int i = 0; i < 26; i++) {
    answer *= alphabet.at(i) + 1;
    answer %= MOD;
  }
  
  cout << answer - 1 << endl;
}

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

using namespace std;


#define PI 3.14159265
#define int long long

const int mod = 1e9 + 7;
const int N = 1e5;

int t[2 * N];


int n;

void build() {
  for (int i = n - 1; i > 0; --i) t[i] = __gcd(t[i<<1], t[i<<1|1]);
}

void modify(int p, int value) {
  for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = __gcd(t[p], t[p^1]);
}

int q(int l, int r) {
  int res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = __gcd(res, t[l++]);
    if (r&1) res = __gcd(res, t[--r]);
  }
  return res;
}


main(){


	cin >> n;

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

	build();

	int ans = 1;

	for(int i = 0; i < n; i++){
		ans = max(ans, __gcd(q(0, i), q(i + 1, n)));

		// cout << q(0, i) << " " << q(i + 1, n) << endl;
	}


	cout << ans << endl;




	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int d[10];
    rep(i, k) cin >> d[i];
    REP(i, n, 1000000) {
        string S = to_string(i);
        bool ok = true;
        rep(i, k) {
            rep(j, S.length()) {
                if(S[j] - '0' == d[i]) ok = false;
            }
        }
        if(ok) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    string in;  
 
    while (getline(cin, in), in != "0") {
	stringstream s(in);
	int sum = 0, n;
	bool flg = false;
 
	while (s >> n) {
	    if (2 <= n && n <= 9) {
		sum += n;
	    } else if (n >= 10) {
		sum += 10;
	    } else {
		sum++;
		flg = true;
	    }
	}
 
	if (sum <= 11 && flg) {
	    sum += 10;
	} 
	if (sum > 21) {
	    cout << 0 << endl;
	} else {
	    cout << sum << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	int x, n;
	int N = 100;
	cin >> x >> n;
	vecb p(N + 1, true);
	rep(i, n)
	{
		int tmp;
		cin >> tmp;
		p[tmp] = false;
	}
	int max_ = INT_MAX;
	int ans = 0;
	for (int i = -201; i <= N + 100; i++)
	{
		if (i >= 0)
			if (!p[i])
				continue;
		if (max_ > abs(x - i))
		{
			max_ = abs(x - i);
			ans = i;
		}
		if (max_ > abs(i - x))
		{
			max_ = abs(i - x);
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        p: [(isize, isize); n],
    }
    let mut s = 0_f64;
    for i in 0..n - 1 {
        for j in i + 1..n {
            let t = ((p[i].0 - p[j].0).pow(2) + (p[i].1 - p[j].1).pow(2)) as f64;
            s += t.sqrt();
        }
    }

    let ans: f64 = s * 2_f64 / (n as f64);
    println!("{}", ans);
}


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

int main(){
  int n, x, t;
  cin >> n >> x >> t;
  cout << ((n + x - 1) / x) * t << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


int main(){
    LL n;
    cin >> n;
    string s;
    cin >> s;
    LL q;
    cin >> q;
    for(LL i = 0; i < q; ++i){
        LL k;
        cin >> k;
        LL d_cnt = 0, m_cnt = 0;
        LL dm_cnt = 0;
        LL ans = 0;
        for(LL j = 0; j < n; ++j){
            if(j >= k){
                if(s[j-k] == 'D'){
                    d_cnt -= 1;
                    dm_cnt -= m_cnt;
                }else if(s[j-k] == 'M'){
                    m_cnt -= 1;
                }
            }
            if(s[j] == 'D'){
                d_cnt += 1;
            }else if(s[j] == 'M'){
                m_cnt += 1;
                dm_cnt += d_cnt;
            }else if(s[j] == 'C'){
                ans += dm_cnt;
            }
        }
        cout << ans << endl;
        cerr << "d=" << d_cnt << ", m=" << m_cnt << endl;
    }
    return 0;
}



Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, i, j, k, m, x;
	cin >> n >> k >> m;
	vector<int> c(n + 1, 0);
	for (i = 0; i < m; i++) {
		cin >> x;
		c[x]++;
	}

	for (i = 1; i <= n; i++) {
		if (k > (m - c[i])) cout << "Yes\n";
		else cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int h,w,a,b;cin>>h>>w>>a>>b;
    REP(i,b){REP(j,a)cout<<1;REP(j,w-a)cout<<0;cout<<endl;}
    REP(i,h-b){REP(j,a)cout<<0;REP(j,w-a)cout<<1;cout<<endl;}
}

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


Measured memory_bytes: 1280
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int H=sc.nextInt();
    int N=sc.nextInt();
    int Ans=0;
    
    for(int i=0;i<N;i++){
      Ans+=sc.nextInt();
    }
    if(Ans>=H){
      System.out.print("Yes");
    }else{
      System.out.print("No");
    }
  }
}

Measured memory_bytes: 46644
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 24/07/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n = ii1()
arr = iia()
dp = [0] * n
dp[1] = abs(arr[1] - arr[0])
for i in range(2, n):
    t1 = abs(arr[i] - arr[i - 2]) + dp[i - 2]
    t2 = abs(arr[i] - arr[i - 1]) + dp[i - 1]
    dp[i] = min(t1, t2)
print(dp[-1])


Measured memory_bytes: 20744
import java.util.Scanner;
public class Main{
    public static void main(String argv[])
    {
	Scanner scan = new Scanner(System.in);

	int num = scan.nextInt();
	int num1 = scan.nextInt();
	int num2 = scan.nextInt();


	if( num < num1 && num1 < num2)

	    System.out.println("Yes");
else
	System.out.println("No");
    }

}

Measured memory_bytes: 26172
//https://atcoder.jp/contests/abc049/tasks/arc065_b
//D - 連結 / Connectivity
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,K,L; cin>>N>>K>>L;
    uf_tree ut_k(N+1), ut_l(N+1);
    REP(i,K){
        int p,q; cin>>p>>q;
        ut_k.unite(p,q);
    }
    REP(i,L){
        int r,s; cin>>r>>s;
        ut_l.unite(r,s);
    }
    map<pair<int,int>,int> tbl; //rootが一致している
    FOR(i,1,N+1){
        int a=ut_k.find(i);
        int b=ut_l.find(i);
        tbl[{a,b}]++;
    }
    FOR(i,1,N+1){
        auto a=ut_k.find(i);
        auto b=ut_l.find(i);
        cout<<tbl[{a,b}]<<endl;
    }
    // FOR(i,1,N+1){ //全探索?
    //     ll ans=0;
    //     FOR(j,1,N+1){
    //         if (ut_k.is_same(i,j) && ut_l.is_same(i,j)){
    //             ++ans;
    //         }
    //     }
    //     cout<<ans<<endl;
    // }

    return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 a[100];
i64 f(i64 x) {
  if (a[x] > 0) return a[x];
  if (x == 0) return 2;
  if (x == 1) return 1;
  return a[x] = f(x - 1) + f(x - 2);
}

int main() {
  i64 x; cin >> x; cout << f(x) << '\n';
  return 0;
}


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

int compare_int(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;
}

int main(){
  int N;
  scanf("%d",&N);
  long long int A[N];
  int i;
  for(i=0;i<N;i++){
    scanf("%lld",&A[i]);
  }
  qsort(A, N, sizeof(long long int), compare_int);
  long long int ans=0;
  if(N%2==0){
    for(i=0;i<N/2-1;i++){
      ans=ans-2*A[i]+2*A[N/2+i+1];
    }
    ans=ans-A[N/2-1];
    ans=ans+A[N/2];
    printf("%lld",ans);
  }else{
    for(i=0;i<(N-3)/2;i++){
      ans=ans-2*A[i]+2*A[i+(N+3)/2];
    }
    if(2*A[(N+1)/2]-A[(N-3)/2]-A[(N-1)/2]>A[(N+1)/2]-2*A[(N-3)/2]+A[(N-1)/2]){
      ans=ans+2*A[(N+1)/2]-A[(N-3)/2]-A[(N-1)/2];
    }else{
      ans=ans+A[(N+1)/2]-2*A[(N-3)/2]+A[(N-1)/2];
    }
    printf("%lld",ans);
  }
  return 0;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

void solve()
{
    ll n,cnt=0;
    cin>>n;
    for(ll i=1;i<=1000000;i++)
    {
        for(ll j=1;j<=1000000;j++)
        {
            if(i*j>n) break;
            else if(i*j<n) cnt++; 
        }
    }
    cout<<cnt;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++) solve();
    return 0;
}

Measured memory_bytes: 3648
a,b = map(int,input().split())
if a == 0 or b == 0:
    print("Zero")
else:
    if 0<a<=b:
        print("Positive")
    elif a<=0<b:
        print("Zero")
    elif a<=b<0:
        if abs(a+b)%2 == 0:
            print("Negative")
        else:
            print("Positive")

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

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n;

	while(cin>>n){
		if(n%1000==0)cout<<0<<endl;
		else{
			cout<<(n / 1000 + 1) * 1000 - n<<endl;
		}
	}
	return 0;
}

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

int main()
{
  int n, m, cnt = 0;
  cin >> n >> m;
  
  vector<bool> res(m);
  for(int i=0; i<m; i++) res[i] = true;
  
  for(int i=0; i<n; i++)
  {
    vector<bool> res_tmp(m);
    for(int j=0; j<m; j++) res_tmp[j] = false;
    
    int k;
    cin >> k;
    
    for(int j=0; j<k; j++)
    {
      int a;
      cin >> a;
      res_tmp[a-1] = true;
    }
    
    for(int j=0; j<m; j++)
    {
      if(res_tmp[j] == false)
        res[j] = false;
    }
  }
  
  for(int i=0; i<m; i++)
  {
    if(res[i] == true)
      cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}

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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj(n);
  vector<int> deg(n);
  for (int i = 0; i < m; ++i) {
    int from, to;
    cin >> from >> to;
    --from;
    --to;
    ++deg[from];
    ++deg[to];
    adj[from].push_back(to);
    adj[to].push_back(from);
  }
  for (int i = 0; i < n; ++i) {
    if (deg[i] & 1) {
      cout << "No" << "\n";
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (deg[i] >= 6) {
      cout << "Yes" << "\n";
      return 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (deg[i] == 4) {
      ++cnt;
    }
  }
  if (cnt >= 3) {
    cout << "Yes" << "\n";
    return 0;
  }
  if (cnt == 2) {
    for (int i = 0; i < n; ++i) {
      if (deg[i] == 2) {
        int x = adj[i][0], y = adj[i][1];
        if (x == y) {
          cout << "Yes" << "\n";
          return 0;
        }
        for (int j = 0; j < (int) adj[x].size(); ++j) {
          if (adj[x][j] == i) {
            adj[x][j] = y;
            break;
          }
        }
        for (int j = 0; j < (int) adj[y].size(); ++j) {
          if (adj[y][j] == i) {
            adj[y][j] = x;
            break;
          }
        }
      }
    }
  }
  cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[10000][10000];
long long u[1111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e=1,f=0;
  string s="CODEFESTIVAL2016",w;
  cin >>w;
  for(int n=0;n<16;n++){
    if(w[n]!=s[n]) d++;
  }
  cout <<d<<'\n';
  return (0);
}


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

using namespace std;

int main () {
  ios::sync_with_stdio(0);
  int a, b;
  cin >> a >> b;
  if (a < 6) cout << "0\n";
  else if (a < 13) cout << b/2 << endl;
  else cout << b << endl;
}

Measured memory_bytes: 256
max_W1 = 0
max_W2 = 0
max_W3 = 0
sum_W = 0
max_K1 = 0
max_K2 = 0
max_K3 = 0
sum_K = 0

for i in range(10):
    W = int(input())
    if max_W1 < W:
        max_W3 = max_W2
        max_W2 = max_W1
        max_W1 = W
    elif max_W2 < W:
        max_W3 = max_W2
        max_W2 = W
    elif max_W3 < W:
        max_W3 = W
        
for j in range(10):
    K = int(input())
    if max_K1 < K:
        max_K3 = max_K2
        max_K2 = max_K1
        max_K1 = K
    elif max_K2 < K:
        max_K3 = max_K2
        max_K2 = K
    elif max_K3 < K:
        max_K3 = K
        
sum_W = max_W1 + max_W2 + max_W3
sum_K = max_K1 + max_K2 + max_K3
print(sum_W, sum_K)


Measured memory_bytes: 5592
import sys
N = int(input())
a = [int(input()) for _ in range(N)]
flag = [0]*N
k = 0
i = 0
flag[0] = 1
while k <N:
  k += 1
  i = a[i] - 1
  if flag[i] == 0:
    flag[i] = 1
  elif flag[i] == 1:
    print(-1)
    sys.exit()
  if i == 1:
    print(k)
    sys.exit()

Measured memory_bytes: 13768
/**
 *    author:  math2do
 *    created: 18.01.2020 02:59:16
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL
    freopen("C_vacation.in", "rt", stdin);
  #endif
  int n;
  cin >> n;
  vector <vector <int>> in(n, vector <int>(3));
  for(int i = 0; i < n; i++) {
    cin >> in[i][0] >> in[i][1] >> in[i][2];
  }

  vector <vector <vector <int>>> dp(n, vector <vector <int>>(3, vector <int>(3, 0)));
  dp[0][0][1] = in[0][0];
  dp[0][1][1] = in[0][1];
  dp[0][2][1] = in[0][2];

  int a, b, c;

  for (int i = 1; i < n; i++) {
    a = max(dp[i - 1][0][0], dp[i - 1][0][1]);
    b = max(dp[i - 1][1][0], dp[i - 1][1][1]);
    c = max(dp[i - 1][2][0], dp[i - 1][2][1]);
    dp[i][0][0] = max(a, max(b, c));
    dp[i][0][1] = in[i][0] + max(dp[i - 1][0][0], max(b, c));


    a = max(dp[i - 1][0][0], dp[i - 1][0][1]);
    b = max(dp[i - 1][1][0], dp[i - 1][1][1]);
    c = max(dp[i - 1][2][0], dp[i - 1][2][1]);
    dp[i][1][0] = max(a, max(b, c));
    dp[i][1][1] = in[i][1] + max(dp[i - 1][1][0], max(c, a));


    a = max(dp[i - 1][0][0], dp[i - 1][0][1]);
    b = max(dp[i - 1][1][0], dp[i - 1][1][1]);
    c = max(dp[i - 1][2][0], dp[i - 1][2][1]);
    dp[i][2][0] = max(a, max(b, c));
    dp[i][2][1] = in[i][2] + max(dp[i - 1][2][0], max(b, a));

  }
  
  a = max(dp[n - 1][0][0], dp[n - 1][0][1]);
  b = max(dp[n - 1][1][0], dp[n - 1][1][1]);
  c = max(dp[n - 1][2][0], dp[n - 1][2][1]);

  cout << max(a, max(b, c)) << endl;

  return 0;
}


Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
const double EPS = 1e-8;

int main(){
    while(1){
        int n,l;
        cin >> n >> l;
        if(n == 0) break;

        vector<int> cp(2*n +2), u(2*n +2, 0);
        cp[0] = 0;
        for(int i=0; i<n; i++){
            cin >> cp[2*i+1] >> cp[2*i+2] >> u[2*i+1];
        }
        cp[2*n+1] = 86400;

        double lb=0, ub=1e6;
        for(int rep=0; rep<50; rep++){
            double mid = (lb+ub) /2;
            double curr = l;
            bool ok = true;
            for(int i=0; i<(int)cp.size()-1; i++){
                curr += (mid -u[i]) * (cp[i+1] -cp[i]);
                curr = min(curr, (double)l);
                if(curr < 0){
                    ok = false;
                    break;
                }
            }
            if(ok){
                double sp = curr;
                for(int i=0; i<(int)cp.size()-1; i++){
                    curr += (mid -u[i]) * (cp[i+1] -cp[i]);
                    curr = min(curr, (double)l);
                    if(curr < 0){
                        ok = false;
                        break;
                    }
                }
                if(sp-curr > EPS) ok=false;
            }
            if(ok){
                ub = mid;
            }else{
                lb = mid;
            }
        }
        cout << fixed << setprecision(10);
        cout << lb << endl;
    } 
    return 0;
}


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

using namespace std;

int main()
{
    int a[3], result = 0;
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    result += a[2] - a[1];
    a[0] += result;
    while(a[0] < a[2]) {
        a[0] += 2;
        result++;
    }
    if(a[0] != a[2]) result++;
    cout << result << endl;

    return 0;
} 


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

#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vll vector<ll>
#define vvll vector<vll>
#define pb push_back
template<typename T, typename U>
static inline void amin(T &x, U y){
    if(x>y)
        x = y;
}
template<typename T, typename U>
static inline void amax(T &x, U y){
    if(x<y)
        x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

const ll mod = 1e9+7;

int main(){
    int n;
    string s;
    cin>> n;
    cin>> s;
    int ans = 0;
    for(int i = 0; i < n-2; ++i){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int P,Q,R;
  std::cin >> P >> Q >> R;

  cout << min(P+Q,min(Q+R,R+P)) << endl;

  return 0;
}

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

using namespace std; 

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}

int64_t
inner_product(vector<int64_t> a, vector<int64_t> b, uint64_t n) {
    int64_t ret = 0;
    for (uint64_t i = 0; i < n; i ++) {
        ret += a[i] * b[i];
    }
    return ret;
}

int
main(int argc, char const *argv[])
{
    uint64_t n, m;
    int64_t c;
    cin >> n >> m >> c;
    vector<int64_t> b(m);
    cin >> b;
    vector<vector<int64_t>> a(n);
    for (int i = 0; i < n; i++) {
        a[i].resize(m);
        cin >> a[i];
    }

    uint64_t ans = 0;
    for (int i = 0; i < n; i++) {
        int64_t res = inner_product(b, a[i], m) + c;
        if (res > 0) {
            ans ++;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void dfs(list<int> *adj,int s,int dp[],bool visited[])
{
	visited[s]=true;
	for(auto it=adj[s].begin();it!=adj[s].end();it++)
	{
		if(!visited[*it])
		{
			dfs(adj,*it,dp,visited);
		}
		dp[s]=max(dp[s],1+dp[*it]);
	}
}
int findLongestPath(list<int> *adj,int n)
{
	bool *visited;
	visited=new bool[n+1];
	for(int i=1;i<=n;i++)
		visited[i]=false;
	int dp[n+1];
	for(int i=1;i<=n;i++)
		dp[i]=0;
	for(int i=1;i<=n;i++)
	{
		if(!visited[i])
			dfs(adj,i,dp,visited);
	}
	int max_path=0;
	for(int i=1;i<=n;i++)
	{
		max_path=max(max_path,dp[i]);
	}
	return max_path;
}
int main()
{
	int n,m;
	cin>>n>>m;
	list<int> *adj;
	adj=new list<int>[n+1];
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
	}
	cout<<findLongestPath(adj,n);
	return 0;
}

Measured memory_bytes: 8192
fn solve(r: usize) -> usize {
    r * r
}

#[test]
fn solve_test() {
    assert_eq!(solve(2), 4);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let r = parse_line!(usize);
    println!("{}", solve(r));
}


Measured memory_bytes: 4352
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> as(h); cin >> as;
    vector<pair<int, int>> poss;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(as[i][j] == '#'){
                poss.emplace_back(i, j);
            }
        }
    }
    if((int)poss.size() == h * w){
        cout << 0 << '\n';
        return 0;
    }
    int ans = 0;
    while(poss.size()){
        vector<pair<int, int>> nexts;
        auto f = [&](int y, int x){ 
            if(0 <= y && y < h && 0 <= x && x < w && as[y][x] == '.'){
                as[y][x] = '#';
                nexts.emplace_back(y, x);
            }
        };
        for(auto& pos : poss){
            f(pos.first + 1, pos.second);
            f(pos.first, pos.second + 1);
            f(pos.first - 1, pos.second);
            f(pos.first, pos.second - 1);
        }
        nexts.swap(poss);
        ans += !poss.empty();
    }
    cout << ans << '\n';
}


Measured memory_bytes: 15208
fun main() {
    val (_, _, k) = readInts().map { it.toLong() }
    val a = readInts().map { it.toLong() }.toMutableList()
    val b = readInts().map { it.toLong() }.toMutableList()

    a.forEachIndexed { index, _ -> if (index > 0) a[index] += a[index - 1] }
    b.forEachIndexed { index, _ -> if (index > 0) b[index] += b[index - 1] }

    fun lowerBound(element: Long, list: List<Long>): Int {
        val index = list.binarySearch(element)
        if (index >= 0) return index
        return -(index + 1) - 1
    }

    var maxRead = lowerBound(k, b) + 1

    a.forEachIndexed { index, i ->
        maxRead = if (i <= k) {
//            println("a curr: $i search: ${k - i} b insertion: ${lowerBound(k - i, b)}")
            maxOf(maxRead, index + 1 + lowerBound(k - i, b) + 1)
        } else maxOf(0, maxRead)
    }

    println(maxRead)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
//private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 95244
import sys

sys.setrecursionlimit(10 ** 9)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = int(input())

    x3 = (-s) % (10 ** 9)
    y3 = (s + x3) // (10 ** 9)

    print(0, 0, 10 ** 9, 1, x3, y3)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38384