akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let K: usize = read();
    let mut n: usize = 1;

    for i in 0..N {
        if (n*2 <= n+K) {
            n = n*2;
        }
        else {
            n = n+K;
        }
    }
    println!("{}", n);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#include <vector>
std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}
int main()
{
    int N;
    cin >> N;
    for( const auto &x: Eratosthenes( 2*N ) )
    {
        if (x < N) continue;
        cout << x << " " << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.max
import kotlin.time.seconds

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (a, b) = readIntegerList()
    val ans = if (a + b >= 10) "error"  else a + b
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main() {
  int mod=1000000007;
  int n,m,k;
  cin >> n>>m>>k;
  
    bool ex=false;
    rep(i,n+1){
      rep(j,m+1){
        if(i*j+(n-i)*(m-j)==k){
          ex=true;
        }
      }
    }
    if(ex){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  
}

Measured memory_bytes: 256
package main

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

func main() {
	var N, M int
	fmt.Scanln(&N, &M)
	sc := bufio.NewScanner(os.Stdin)
	broken := make(map[int]bool, M)
	for i := 0; i < M; i++ {
		sc.Scan()
		stair, _ := strconv.Atoi(sc.Text())
		broken[stair] = true
	}

	dp := make([]int, N+1)
	dp[0] = 1
	if broken[1] {
		dp[1] = 0
	} else {
		dp[1] = 1
	}

	for i := 2; i <= N; i++ {
		if broken[i] == false {
			dp[i] = dp[i-1] + dp[i-2]
		}
		dp[i] %= 1000000007
	}
	fmt.Println(dp[N])
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n, m;
  int x[100000];
  ll sm = 0;
  priority_queue<int> q;
  cin >> n >> m;
  for(int i=0;i<m;i++) cin >> x[i];
  sort(x,x+m);
  for(int i=0;i<m-1;i++) q.push(x[i+1]-x[i]);
  for(int i=0;i<n-1 && !q.empty();i++) q.pop();
  while(!q.empty()){
    sm += q.top();q.pop();
  }
  cout << sm << endl;
}

Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aoj1
{
    class Program
    {
        static void Main()
        {
            int[] num = IntInput();
            int a = num[0];
            int b = num[1];
            Console.WriteLine("{0} {1} {2:f6}", a / b, a % b, (double)a / (double)b);
        }

        static int[] IntInput()
        {
            string[] strs = Console.ReadLine().Split(' ');
            int[] numbers = new int[strs.Length];
            for (int i = 0; i < strs.Length; i++)
            {
                numbers[i] = int.Parse(strs[i]);
            }
            return numbers;
        }
    }
}

Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int input, ans = 0;
    cin >> input ;
    
    vector<int> side(input);
    for(int i = 0; i < input; i++){
        cin >> side.at(i);
    }
    
    sort(side.begin(), side.end());
    reverse(side.begin(), side.end());

    for(int i = 0; i < input; i++){
        for(int j = i + 1; j < input; j++){
            for(int k = j + 1; k < input; k++){
                if(side.at(i) < side.at(j) + side.at(k) && side.at(j) < side.at(k) + side.at(i) && side.at(k) < side.at(i) + side.at(j) ){
                    ans++;
                } else {
                    break;
                }
            }

        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 3644
package main

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

func calc(arr []string)  {
	n, _ := strconv.Atoi(arr[0])
	d, _ := strconv.Atoi(arr[1])
	if n%(2*d+1) == 0 {
		fmt.Println(n/(2*d+1))
	}else {
		fmt.Println(n/(2*d+1) + 1)
	}
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)
	arr := strings.Split(readLine(reader), " ")
	calc(arr)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}


Measured memory_bytes: 640
# include<iostream>
# include<algorithm>
using namespace std;
int abs(int a, int b)
{
    if(a > b)
        return a-b;
    else
        return b-a;
}
int main(void)
{
    int n;
    int a[100003];
    while(cin >> n && n!=0)
    {
        int i;
        for(i = 0; i < n; ++i)
            cin >> a[i];
        sort(a, a+n);
        int q = 1000000000;
        int mid = a[n-1]/2;
        int z;
        for(i = 0; i < n-1; ++i)
        {
            if(abs(a[i], mid) <= q)
            {
                q = abs(a[i], mid);
                z = i;
            }
        }
        cout << a[n-1] << " " << a[z] << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>  
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
const double PI=acos(-1.0);

typedef long long Int;
typedef long long LL;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef pair <double, double> PDD;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 30007;
const int MAX2 = 507;
const int ADD = 250;
const int LEN = 21;
const int BASE = 1000000000;
const int MOD = 1000000007;

int a, b, c, d, e, f;
int tot, sug;
set<PII> S;

void dfs(int w, int s)
{
  if (s * (100+e) > (w+s) * e) return;
  if (S.find(MP(w, s)) != S.end()) return;

  S.insert(MP(w, s));

  if (s * tot >= (w+s) * sug)
  {
    sug = s;
    tot = s+w;
  }

  if (w+s+100*a <= f) dfs(w+100*a, s);
  if (w+s+100*b <= f) dfs(w+100*b, s);
  if (w+s+c <= f) dfs(w, s+c);
  if (w+s+d <= f) dfs(w, s+d);
}

int main()
{
  cin >> a >> b >> c >> d >> e >> f;

  tot = 1;
  sug = 0;

  dfs(0, 0);

  cout << tot << ' ' << sug << endl;



  return 0;
}




Measured memory_bytes: 640
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var a = o.a();
  var b = o.a();
  var x = 0;
  for(var i = 0; i < n; i++){
    var t = 1 << i;
    if(a & t)x++;
    if(b & t)x++;
  }
  if(x % 2 === 0)return "NO";
  var ans = [];
  f(a,b,0);
  console.log("YES");
  return ans.join(" ");

  function f(a,b,x){
    if(a === b){ans.push(a);return;}
    var c = a ^ b, y = a, z = a, u = 1, v = 1;
    for(var i = 0; i < n; i++){
      var t = 1 << i;
      if(t & x)continue;
      if((c & t) && v){
        v = 0, z ^= t, x |= t;
        continue;
      }
      if(u)u = 0, y ^= t, z ^= t;
    }
    f(a,y,x);
    f(z,b,x);
  }
}

Measured memory_bytes: 20408
from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm_list(nums):
    return reduce(lcm_base, nums, 1)

def main():
    n = int(input())
    t = [int(input()) for _ in range(n)]
    print(lcm_list(t))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<ll>t(n);
    for(int i =0;i<n;i++)cin>>t[i];
    ll ans=1;
    for(int i=0;i<n;i++)ans=LCM(ans,t[i]);
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 384
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <cstdio>
using namespace std;
int minl=1000000000;
int main()
{
	int n, k, res;
	scanf("%d%d", &n, &k);
	int a[n], h=k;
	a[0]=k;
	for(int i=1; i<n; i++) a[i]=1+a[i-1], h+=a[i];
	for(int i=0; i<n; i++) if(abs(a[i])<minl) minl=abs(a[i]), res=h-a[i];
	printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = ReadIntList();
            var S = Console.ReadLine();

            foreach (var item in S)
            {
                if(NK[1]-- == 1)
                {
                    Console.Write(Char.ToLower(item));
                }
                else
                    Console.Write(item);
            }
#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


Measured memory_bytes: 11220
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    h,w,a,b = LI()
    ans = [1]*a+[0]*(w-a)
    ans_ = [0]*a+[1]*(w-a)
    for i in range(h):
        if i < b:
            print(*ans,sep = "")
        else:
            print(*ans_,sep = "")
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 998244353

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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


int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int dx = tx - sx, dy = ty - sy;
    string ans;
    rep(i, dy) ans += "U";
    rep(i, dx) ans += "R";
    rep(i, dy) ans += "D";
    rep(i, dx) ans += "L";

    ans += "L";
    rep(i, dy+1) ans += "U";
    rep(i, dx+1) ans += "R";
    ans += "D";
    ans += "R";
    rep(i, dy+1) ans += "D";
    rep(i, dx+1) ans += "L";
    ans += "U";

    //string ans = ( flag ? "Yes" : "No" );
    //printf("%.8lf\n", ans);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]

s = 0
for i in range(2):
    if  A >= B:
        s += A
        A -= 1
    else:
        s += B
        B -= 1

print(s)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const size_t M = 1e9 + 7;

int main(int,char**) {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    string s;
    cin >> s;
    
    int n = s.size();
    
    // dp(x, y) = how many such numbers
    // where x is the prefix length, y is reminder by 13
    vector< vector<size_t> > dp(n+1, vector<size_t>(13, 0));
    dp[0][0] = 1;
    
    
    for (int i = 0; i < n; ++i) {
        if (s[i] != '?') {
            int curDigit = s[i] - '0';
            for (int prevRem = 0; prevRem < 13; ++prevRem) {
                int curRem = (10*prevRem + curDigit)%13;
                dp[i+1][curRem] = (dp[i+1][curRem] + dp[i][prevRem])%M;
            }
        } else {
            // curDigit may be any 0..9
            for (int curDigit = 0; curDigit < 10; ++curDigit) {
                for (int prevRem = 0; prevRem < 13; ++prevRem) {
                    int curRem = (10*prevRem + curDigit)%13;
                    dp[i+1][curRem] = (dp[i+1][curRem] + dp[i][prevRem])%M;
                }
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}



Measured memory_bytes: 13648
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int a,b,c,d;
int main(){
  cin>>a>>b>>c>>d;
  int res=max(0,min(b,d)-max(a,c));
  prin(res);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;






void solve()
{
	long long a, b, k;
	cin >> a >> b >> k;

	if (a >= k)
	{
		cout << a - k << " " << b;
		return;
	}

	k -= a;
	a = 0;
	

	if (b >= k)
	{
		cout << a << " " << b - k;
		return;
	}

	b = 0;

	cout << a << " " << b;
}




int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
Aoddsum = sum(A[1:N:2])
X1 = S - 2*Aoddsum
X = [X1]
for n in range(1, N):
    X.append(2*A[n-1] - X[n-1])
    
for x in X:
    print(x, end=" ")


Measured memory_bytes: 14028
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >>m;
map<int,int> mp;
for(int i=0; i<m; i++){
int l,r;
cin >> l >> r;
mp[l]++;
mp[r]++;
}
for(auto e:mp)if(e.second%2!=0){
cout << "NO";
return 0;
}
cout<<"YES";
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  string answer = "No";
  for (int i=0; i<N; i++) {
    string end = {S.at(N-1)};
    if (S != T) {
      S.insert(0, end);
      S.pop_back();
    }
    else {
      answer = "Yes";
      break;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP
N = int(input())
a = list(map(int, input().split()))
f = sum(a)/N
t = Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
c = 0
for i in range(N):
    c += (a[i]-t)**2
print(c)

                

Measured memory_bytes: 77556
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}


int main(){
  ll x,y;
  int cnt=0;
  scanf("%lld %lld",&x,&y);
  y /= x;
  while(y>0){
    y /= 2;
    cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i) = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,h;cin>>h>>n;
  vector<pair<int,int>> a(n);rep(i,n)cin>>a[i].fi>>a[i].se;
  vector<vector<int>> dp(n+1,vector<int>(h+1,INF));
  
  rep(i,n)dp[i][0] = 0;
  rep(i,n){
    rep(j,h+1){
      chmin(dp[i][j],dp[max(i-1,0)][j]);
      chmin(dp[i][j],dp[i][max(j-a[i].fi,0)] + a[i].se);
    }
  }
  print(dp[n-1][h]);
  return 0;
}


Measured memory_bytes: 39424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll a,b,c,k,ans;
int main(){
	a=read(),b=read(),c=read(),k=read();
	ans+=min(a,k),k-=min(a,k);
	if(k)k-=min(b,k);
	if(k)ans-=k;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
// ref: https://drken1215.hatenablog.com/entry/2018/09/30/002900

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

struct xy{
    int x;
    int y;
};

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    uint N; cin >> N;
    vector<struct xy> vXY(N);
    for(uint i=0; i<N; ++i){ cin >> vXY[i].x >> vXY[i].y; }
    
    int mod2 = (abs(vXY[0].x) + abs(vXY[0].y)) % 2;
    for(uint i=1; i<N; ++i){
        int mod2_tmp = (abs(vXY[i].x) + abs(vXY[i].y)) % 2;
        if(mod2!=mod2_tmp){ cout << -1 << endl; return 0; }
    }
    
    vector<int> vD; for(int i=30; i>=0; --i){ vD.push_back( 1<<i ); }
    if(mod2==0){ vD.push_back(1); }
    cout << vD.size() << endl; for(uint i=0; i<vD.size(); ++i){ cout << vD[i] << ' '; } cout << endl;
    
    for(uint i=0; i<N; ++i){
        int xt = vXY[i].x; // t: target
        int yt = vXY[i].y;
        int xs=0, ys=0; // s: sum
        for(uint di=0; di<vD.size(); ++di){
            if(abs(xt-xs) > abs(yt-ys)){
                if(xt-xs>=0){ xs+=vD[di]; cout << 'R';
                }    else   { xs-=vD[di]; cout << 'L'; }
            }else{
                if(yt-ys>=0){ ys+=vD[di]; cout << 'U';
                }    else   { ys-=vD[di]; cout << 'D'; }
            }
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=1e5+5;

int main()
{
    int target;
    cin>>target;
    int x=pow(target,0.2);
    LL l=2*x;
    for(LL i=-l; i<=l; i++)
    {
        LL x=i*i*i*i*i;
        for(LL j=-l; j<=l; j++)
        {
            LL y=j*j*j*j*j;
            if(x-y==target)return 0*printf("%lld %lld\n", i, j);
        }
    }
//    for(target=10000; target<=1000; target++)
//    for(long long i=-1000; i<=1000; i++)
//    {
//        long long x=i*i*i*i*i;
//        int flag=0;
//        for(long long j=-1000; j<=1000; j++)
//        {
//            long long y=j*j*j*j*j;
//            if(x-y==target) {
//                    printf("%d %lld %lld\n", target, i, j);
//                    flag=1;
//                    break;
//            }
//
//        }if(flag)break;
//    }
    return 0;
}
/*
1 0 -1
2 1 -1
31 -1 -2
32 0 -2
33 1 -2
64 2 -2
211 -2 -3
242 -1 -3
243 0 -3
244 1 -3
275 2 -3
486 3 -3
781 -3 -4
992 -2 -4
1023 -1 -4
1024 0 -4
1025 1 -4
1056 2 -4
1267 3 -4
2048 4 -4
2101 -4 -5
2882 -3 -5
3093 -2 -5
3124 -1 -5
3125 0 -5
3126 1 -5
3157 2 -5
3368 3 -5
4149 4 -5
4651 -5 -6
6250 5 -5
6752 -4 -6
7533 -3 -6
7744 -2 -6
7775 -1 -6
7776 0 -6
7777 1 -6
7808 2 -6
8019 3 -6
8800 4 -6
9031 -6 -7
*/


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

long long int N, A, x[55], dp[55][2521], a;

int main(){
    scanf("%lld%lld", &N, &A);
    for(int i = 0; i < N; ++i){
        scanf("%lld", x + i);
    }
    dp[0][0] = 1;
    for(int i = 0; i < N; ++i){
        for(int j = N; j; --j){
            for(long long int k = x[i]; k < 2520; ++k){
                dp[j][k] += dp[j - 1][k - x[i]];
            }
        }
    }
    for(int i = 1; i <= N; ++i){
        a += dp[i][A * i];
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	final static long limit = 1000000000000000000l;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long mul = 1l;
        boolean isOver = false;
        
        for(int i=0; i<N; i++) {
        	long a = sc.nextLong();
        	if(a==0) {
        		System.out.println(0);
        		return;
        	}
        	if (mul>limit/a) {
        		isOver = true;
        	}else {
            	mul *= a;
        	}
        }
        
        if(isOver) {
        	System.out.println(-1);
        }else {
        	System.out.println(mul);
        }
        
	}

}


Measured memory_bytes: 59936
def containOdd(x):
    for c in x:
        if c % 2 == 1:
            return True
    return False

l = int(input())
nl = list(map(int, input().split()))
i = 0
while not containOdd(nl):
    nl = list(map(lambda x: x/2, nl))
    i += 1
print(i)

Measured memory_bytes: 2940
while True:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    state=[raw_input().split() for i in range(r)]
    state=map(list,zip(*state))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            n=bin(i^j).count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print ans

Measured memory_bytes: 8724
#include <stdio.h>
#include <math.h>
int main(void) {
    double a, b, degree, s, L, h;
 
    scanf("%lf %lf %lf", &a, &b, &degree);
    h = b * sin(degree * M_PI / 180.0);
    s = a * h / 2.0;
    L = sqrt(a*a + b*b - 2.0*a*b*cos(degree * M_PI / 180.0)) + a + b;
    printf("%.4lf\n%.4lf\n%.4lf\n", s, L, h);
    return 0;
}


Measured memory_bytes: 2076
i = 0
while i < 50:
    m, f, r = [int(i) for i in input().split()]
    if m == f == r == -1: break
    
    p = m + f
    
    if m == -1 or f == -1 or p < 30:
        print('F')
    elif p >= 80:
        print('A')
    elif 65 <= p < 80:
        print('B')
    elif 50 <= p < 65 or (30 <= p < 50 and r >= 50):
        print('C')
    else:
        print('D')

    
    i += 1


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	int N;
	int lst, now, t = 0;
	int ans = 1;
	lst = 0;
	scanf("%d", &N);
	for(int i = 0; i < N; i++) {
		scanf("%d", &now);
		debug("%d -- %d %d\n", t, lst, now);
		if(lst == 0) lst = now;
		else if(t == 0) {
			if(now > lst) t = 1;
			else if(now < lst) t = -1;
		}
		else if((t == 1 && now < lst) || (t == -1 && now > lst)) {
			t = 0;
			ans++;
		}
		lst = now;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');

            int W = int.Parse(strs[0]);
            int H = int.Parse(strs[1]);
            int x = int.Parse(strs[2]);
            int y = int.Parse(strs[3]);

            double ans0 = (double)W * (double)H;
            ans0 /= 2;

            int ans1 = 0;
            if (x * 2 == W && y * 2 == H)
            {
                ans1 = 1;
            }


            Console.WriteLine("{0} {1}", ans0, ans1);
        }
    }
}

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

using namespace std;

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

	int k, x;
	cin >> k >> x;
	for (int i = max(-100000, x - k + 1); i <= min(100000, x + k - 1); ++i) {
		cout << i << ' ';
	}

	return 0;
}


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

int main() 
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,m;cin>>n>>m;
	int t[m+1];memset(t,0,sizeof(t));
	for (int i = 0; i < n; i++)
	{
		int k;cin>>k;
		while(k--)
		{
			int x;cin>>x;
			t[x]++;
		}
	}
	int s=0;
	for (int i = 1; i <= m; i++)
	{
		if(t[i]==n)s++;
	}
	cout<<s;
}

Measured memory_bytes: 3192
#include<stdio.h>
int main ()
{
	int x,y,i,j,flag;
	scanf("%d",&x);
    for(i=x;;i++)
	{
		flag=1;
		for(j=2;j<i;j++)
			if(i%j==0)
				flag=0;
		if(flag)
		{
			y=i;
			break;
		}
	}
	printf("%d",y);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {

	int a[4][3][10];
	int n,b,f,r,v,i,j,k;
	
	scanf("%d",&n);
	
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				a[i][j][k]=0;
			}
		}
	}

	for(i=0;i<n;i++){
		scanf("%d%d%d%d",&b,&f,&r,&v);
		a[b-1][f-1][r-1]=a[b-1][f-1][r-1]+v;
	}
	
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" %d",a[i][j][k]);
			}
			if(i<4){
				printf("\n");
			}
		}
		if(i<3){
			printf("####################\n");
		}
	}

	return 0;
}

Measured memory_bytes: 612
n, m = map(int, input().split())
light = [list(map(lambda x: int(x)-1, input().split()))[1::] for _ in range(m)]
p = list(map(int, input().split()))
for i in range(m):
    light[i].insert(0, p[i])

#print(light)

ans = 0
for i in range(2**n):
    pattern = ''
    for j in range(n):
        if (i >> j) & 1:
            pattern += '1'
        else:
            pattern += '0'
    # print(pattern)
    flag = True
    for k in range(m):
        counter = 0
        for switch in light[k][1::]:
            counter += int(pattern[switch])
        if counter % 2 != light[k][0]:
            flag = False
            break
    if flag: ans += 1

print(ans)


Measured memory_bytes: 41328
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define cps CLOCKS_PER_SEC
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash { int operator()(int x) const { return x ^ RANDOM; }};
// cc_hash_table<int, int, hash<int>> cnt;

const int MAXN = 2e5 + 10;
int p[MAXN];
map<int,int> positions;
bool visit[MAXN];

void solve(){
    int n; cin>>n;
    FOR(i,1,n) {
        cin>>p[i]; positions[p[i]] = i;
    }

    int siz = 0;
    FOR(i,1,n){
        if(visit[i]) continue;
        int idx = i;
        int pos = positions[idx];
        int t_siz = 1;
        visit[idx] = 1;
        while(positions[idx+1] > pos){
            pos = positions[idx+1];
            idx++; t_siz++;
            visit[idx] = 1;
        }
        
        siz = max(siz,t_siz);
    }

    cout<<n-siz<<endl;
}
 
signed main(){
 
    FastRead; 

 
    int t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<":\n";
        solve();
    }
}
 

Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    for(int i=0; i<N; i++) {
        cin >> X[i];
    }
    vector<int> Y(N);
    Y = X;
    sort(Y.begin(), Y.end());
    int min_n = Y[0];
    int max_n = Y[N-1];
    ll min_p = INF;

    for(int i=min_n; i<=max_n; i++) {
        ll p = 0;
        for(int j=0; j<N; j++) {
            p += pow(abs(i-Y[j]),2);
        }
        min_p = min(min_p, p);
    }
    cout << min_p << endl;
}

Measured memory_bytes: 3632
N, X = [int(x) for x in input().split()]
LN = [int(x) for x in input().split()]
p = 0
c = 1
while True:
  if p + LN[c-1] <= X:
    p += LN[c-1]
    c += 1
    if c > len(LN):
      break
  else:
    break
print(c)

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

    int i, cnt = 0;
    for( i = a; i <= b; ++i )
        if( c % i == 0 )
            ++cnt;

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

    return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;};
void qmod(ll &a,ll b){a=(a*b)%MOD;};
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,o;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  string s,t;cin>>s>>t;
  buf=INF;
  reverse(ALL(s));
  reverse(ALL(t));
  for(i=0;i<s.size()-t.size()+1;i++){
    if(s[i]=='?'||s[i]==t[0]){
      for(j=0;j<t.size();j++){
        if(s[i+j]!=t[j]&&s[i+j]!='?')break;
        if(j==t.size()-1)chmin(buf,i);
      }
    }
  }
  if(buf==INF){
    cout<<"UNRESTORABLE"<<endl;
  }
  else{
    for(i=0;i<t.size();i++)s[i+buf]=t[i];
    for(i=0;i<s.size();i++){
      if(s[i]=='?')s[i]='a';
    }
    reverse(ALL(s));
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}

use std::cmp;

fn main () {
    input! {
        n : usize,
        v : [i32; n],
    }
    let mut m = 32;
    for x in v {
        if x % 2 == 1 {
            println!("0");
            return ;
        }
        let mut cnt = 0;
        let mut y = x;
        while y > 0 && y % 2 == 0 {
            y /= 2;
            cnt += 1;
        }
        m = cmp::min(m, cnt);
    }
    println!("{}", m);
}


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

int main() {
	int N,ans = 0,tmp = 0;
	cin >> N;
	vector<int> H(N);
	cin >> H.at(0);
	for (int i = 1; i < N; i++) {
		cin >> H.at(i);
		if (H.at(i) <= H.at(i - 1)) {
			tmp++;
			if (ans < tmp) {
				ans = tmp;
			}
		}
		else {
			tmp = 0;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 764
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 15 20:49:02 2018
AGC027A
@author: maezawa
"""

n, x = list(map(int, input().split()))
a = list(map(int, input().split()))

a.sort()
b = []
b0 = 0
for i in range(n):
    b0 += a[i]
    b.append(b0)
#print(b)
if b[0] > x:
    ans = 0
elif b[-1] == x:
    ans = n
elif b[-1] < x:
    ans = n-1
else:
    i = 0
    while True:
        if x == b[i]:
            ans = i + 1
            break
        elif x < b[i]:
            ans = i
            break
        i += 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b);
ll r[100009],l[100009];

int main(){
  int n;
  ll a[100009];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  r[0]=a[0];
  for(int i=1;i<n;i++){
    r[i]=gcd(r[i-1],a[i]);
  }
  l[n-1]=a[n-1];
  for(int i=n-2;i>=0;i--){
    l[i]=gcd(l[i+1],a[i]);
  }
  
  ll ans=max(r[n-2],l[1]);
  for(int i=1;i<n-1;i++){
    ans=max(ans,gcd(r[i-1],l[i+1]));
  }

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

ll gcd(ll a,ll b){
  if(a<b)swap(a,b);
  if(b==0)return a;
  return gcd(b,a%b);
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int N;
  	cin >> N;
	int value=7;
	int count =1;
	for(long long int i=0;i<N;i++){
		if(value % N==0){
			cout << count << endl;
			return 0;
		}
		else{
			value=((value*10)+7)%N;
		}
		count +=1;
	}
	cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 3636
# C
import copy
import itertools

n, k = map(int, input().split())
a_list = [int(x) for x in input().split()]

for j in range(k):
    b_list = [0]*n
#     print("a:",*a_list)
    for i in range(n):
        l = max(0, i-a_list[i])
        r = min(n-1, i+a_list[i])
        b_list[l] += 1
        if r+1 < n:
            b_list[r+1] -= 1
#     print("b:",*b_list)
    cumsum = list(itertools.accumulate(b_list))
    if cumsum == [n]*n:
        break
    a_list = cumsum
print(*cumsum)

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

const ll INF = 1e+18;
// DIJKSTRA
// cf. arihon p.96
struct edge {int to, cost;};
vector<vector<edge>> graph(100010);
vector<ll> dist(100010, INF);
typedef pair<int,int> P; // <kyori, chouten>
void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push(P(0,s));
    dist[s] = 0;
    while(!Q.empty()){
        P p = Q.top(); Q.pop();  // p <kyori, chouten>
        int v = p.second;
        if(dist[v] < p.first) continue;
        for (edge e : graph[v]){
            if (dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                Q.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, a, b, c, Q, K, x, y;
    cin >> N;
    REP(i,N-1){
        cin >> a >> b >> c;
        a--; b--;
        graph[a].push_back({b,c});
        graph[b].push_back({a,c});
    }
    cin >> Q >> K;
    K--;
    dijkstra(K);
    ll ans[Q];
    REP(i,Q){
        cin >> x >> y;
        x--; y--;
        ans[i] = dist[x] + dist[y];
    }
    REP(i,Q){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9316
#include <iostream>

using namespace std;

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

  int i, j;
  int s[M], c[M];
  for(i=0; i<M; i++)
    cin >> s[i] >> c[i];

  int n, count;
  int num[3];
  for(i=0; i<1000; i++){
    count = 0;
    if(i == 0)
      count++;
    num[0] = 0; num[1] = 0; num[2] = 0;
    n = i;
    while(n != 0){
      num[2-count] = n%10;
      n /= 10;
      count++;
    }
    //cout << num[0] << num[1] << num[2] << " "<<count << endl;
    //N桁になるとき
    if(count == N){
      if(num[0] == 0){
	num[0] = num[1];
	num[1] = num[2];
	num[2] = -1;
      }
      if(num[0] == 0){
	num[0] = num[1];
        num[1] = num[2];
        num[2] = -1;
      }
      
      for(j=0; j<M; j++){
	if(num[s[j]-1] != c[j] )
	  break;
      }
      if(j == M){
	for(int k=0; k<3; k++)
	  if(num[k] != -1)
	    cout << num[k];
	cout << endl;
	return 0;
      }
    }
  }

  cout << "-1" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9 + 7;
int d[505][505];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0 ; i < n * m ; i++){
        for(int j = 0 ; j < n * m ; j++){
            if(i != j)
                d[i][j] = 74751;
            else
                d[i][j] = 0;
        }
    }
    string s[25];
    f(n){
        cin >> s[i];
    }
    int dx[] = {-1,1,0,0};
    int dy[] = {0,0,1,-1};
    f(n){
       fr(j,0,m){
            if(s[i][j] == '#'){
                d[i*m+j][i*m+j] = 74751;
            }
       } 
    }
    f(n){
        fr(j,0,m){
            if(s[i][j] == '#')continue;
            int idx1 = i * m + j;
            fr(k,0,4){
                int xx = i + dx[k];
                int yy = j + dy[k];
                if(xx < 0 || xx >= n)continue;
                if(yy < 0 || yy >= m)continue;
                if(s[xx][yy] == '#')continue;
                int idx2 = xx * m + yy;
                d[idx1][idx2] = d[idx2][idx1] = 1;
            }
        }
    }
    for(int k = 0 ; k < n * m ; k ++){
        for(int i = 0 ; i < n * m ; i ++){
            for(int j = 0 ; j < n * m ; j++){
                d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
            }
        }
    }
    int mx = 0;
    f(n*m){
        fr(j,0,n*m){
            if(d[i][j] < 74751){
                mx = max(mx,d[i][j]);
            }
        }
    }
    cout << mx << '\n';
}

Measured memory_bytes: 1024
def add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]

def check_overk(in1, k):
    return len([i for i in in1 if i>k]) > 0

def split(ar, k, w):
    a = 0
    for i in ar:
        if check_overk(i, k):
            return -1
    tm = ar[0]
    for i in range(1, w):
        tm = add(tm, ar[i])
        if check_overk(tm, k):
            a += 1
            tm = ar[i]
    return a
            

h, w, k = map(int, input().split())
s = [[int(i) for i in input()] for j in range(h)]
ans = h*w

for i in range(2**(h-1)):
    data = []
    temp = s[0]
    sp = bin(i+2**h)[4:]
    if ans < sp.count("1"):
        continue
    for j in range(1, h):
        if sp[j-1] == "0":
            temp = add(temp, s[j])
        else:
            data.append(temp)
            temp = s[j]
    data.append(temp)
    ans_ = split([list(x) for x in zip(*data)], k, w)
    if ans_ == -1:
        continue
    ans_ += sp.count("1")
    if ans > ans_:
        ans = ans_
print(ans)

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

int main(void)
{
    long long int a;
    double b;
    cin >> a >> b;

    long long int bb = b*100+0.5;   // 切り捨てで壊れないようにする
    long long int ans = bb * a;
    ans /= 100;
    cout << ans << endl;


    

    return 0;
}



Measured memory_bytes: 3676
n, m = map(int, input().split())
a = [0]*n
for i in range(n):
    a[i] = list(map(int, input().split()))

a.sort()  # key=lambda x: x[0]

ans = 0
for i in range(n):
    if m > a[i][1]:
        ans += a[i][0]*a[i][1]
        m -= a[i][1]
    else:
        ans += m*a[i][0]
        break

print(ans)

Measured memory_bytes: 27876