akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    string slimes;
    cin >> slimes;
    int result = 0;
    char last = ' ';
    for (int m = 0; m < n; ++m) {
        if (last == slimes[m]) {
            continue;
        }
        ++result;
        last = slimes[m];
    }
    cout << result;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;


int main(){
    ll K;
    string s;cin>>s>>K;
    rep(i,0,s.size()){
        if(s.at(i)!='a'&&'{'-s.at(i)<=K){
            K=K-('{'-s.at(i));
            s.at(i)='a';
        }
    }
    if(K!=0){
    K=K%26;
    s.at(s.size()-1)=(s.at(s.size()-1)-'a'+K)%26+'a';
    }
    cout<<s<<endl;
    
}







Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main(){
	int n, answer = 0;
	string key;
	cin >> key >> n;
	while(n--){
		string line;
		cin >> line;
		line += line;
		if(strstr(line.c_str(), key.c_str()) != NULL){ ++answer; }
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 0
A, B = gets.split.map(&:to_i)

# 0^1^...^number
def calc(number)
  return 0 if number <= 0

  number += 1

  res = 0
  0.upto(50) do |i|
    base = 2 ** (i + 1)
    number_of_1 = (number / base) * base / 2
    number_of_1 += [0, number % base - (base / 2)].max

    if number_of_1 % 2 == 1
      res += 2 ** i
    end
  end

  res
end

puts calc(B) ^ calc(A-1)


Measured memory_bytes: 1916
n=int(input())
clist = list(map(int, input().split()))
clist=sorted(clist)
answer=0
kihon=(2**(n-1))%(10**9+7)
tas=(2**(n-2))%(10**9+7)
for i in range(n):
    answer+=clist[-i-1]*(kihon)
    answer=answer%(10**9+7)
    kihon+=tas

answer=(answer*(2**n))%(10**9+7)
print(answer)

Measured memory_bytes: 89036
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Control.Monad.ST
import           Data.Array.IArray
import           Data.Array.MArray
import           Data.Array.ST
import           Data.Array.Unboxed

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

makeArray :: Int -> [(Int, Int, Int)] -> ST s (STUArray s (Int, Int) Int)
makeArray v xs = do
    a <- newArray ((0, 0), (v-1, v-1)) maxBound
    forM_ [0 .. v-1] $ \i -> writeArray a (i, i) 0
    forM_ xs $ \(s, t, d) -> writeArray a (s, t) d
    return a

updateArray :: STUArray s (Int, Int) Int -> ST s ()
updateArray a = do
    (_, (n, _)) <- getBounds a
    forM_ [0 .. n] $ \k -> do
        forM_ [0 .. n] $ \i -> do
            forM_ [0 .. n] $ \j -> do
                ij <- readArray a (i, j)
                ik <- readArray a (i, k)
                kj <- readArray a (k, j)
                if ik == maxBound || kj == maxBound
                    then return ()
                    else writeArray a (i, j) $ min ij (ik + kj)

hasNegativeCycle :: UArray (Int, Int) Int -> Bool
hasNegativeCycle a = any (< 0) $ fmap (a !) [(i, i) | i <- [0 .. n]]
  where
    (_, (n, _)) = bounds a

main :: IO ()
main = do
    [v, e] <- fmap readi . B.words <$> B.getLine
    xs <- replicateM e $ do
        [a, b, c] <- fmap readi . B.words <$> B.getLine
        return (a, b, c)

    let ary = runSTUArray $ do
            a <- makeArray v xs
            updateArray a
            return a

    let show_ x = if x == maxBound then "INF" else show x
    if hasNegativeCycle ary
        then putStrLn "NEGATIVE CYCLE"
        else do
            forM_ [0 .. v-1] $ \i -> do
                let ds = fmap (ary !) [(i, j) | j <- [0 .. v-1]]
                putStrLn . unwords $ fmap show_ ds



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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    int x; cin >> x;
    for(int i = x;; ++i){
        bool ok = 1;
        for(int j = 2; j*j <= i; ++j){
            if(i % j == 0){
                ok &= 0;
                break;
            }
        }   
        if(ok){
            return cout << i << '\n', 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
function main(input: string) {
  const lines = input.trim().split('\n')

  const [n, k] = lines[0].split(' ').map(Number)
  const a = lines[1].split(' ').map(Number)
  const s = a.reduce((p, c) => p + c)
  const divs = divisor(s)
  let res = 1
  divs.some(d => {
    const r = a.map(ai => ai % d).sort((a, b) => a - b)
    let mx = 0
    let sum = 0
    let y = n
    for (var j = 0; j < y && mx <= k; j++) {
      sum += r[j]
      mx += r[j]
      while (sum > 0) {
        sum -= d - r[--y]
      }
    }
    if (mx <= k) {
      res = d
      return true
    }
    return false
  })
  console.log(res)
}
// 10 1 2 22
// 3 1 2 1
// 3 1 2 1

//|6 6 5 4
//|21
// 1|6 5 4
// 1|15
// 1 1|5 4
//   2|9
// 1 1 2|4
//     4|4
// 1 1 2 3|

function divisor(n) {
  const rs: number[] = [n]
  const m = Math.sqrt(n)
  if ((m | 0) * (m | 0) === n) {
    rs.push(m | 0)
  }
  for (var i = 2; i < m; i++) {
    if (n % i === 0) {
      rs.push(i, n / i)
    }
  }
  return rs.sort((a, b) => b - a)
}

const lineNums = text => text.split(' ').map(Number)

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 10608
n = int(input())
dic = {}

A = list(map(int, input().split()))

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = 0

for key in dic:
    if dic[key] != key:
        if dic[key] > key:
            ans += dic[key] - key
        else:
            ans += dic[key]

print(ans)

Measured memory_bytes: 21848
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n:usize,
        sn:[usize;n],
    }
    let sum: usize = sn.iter().fold(0, |y, x| y + x);
    let ans = if sum % 10 == 0 {
        sum - sn.iter().filter(|&x| x % 10 != 0).min().unwrap_or(&0)
    } else {
        sum
    };
    println!("{}", if ans % 10 == 0 { 0 } else { ans });
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> v;
    int n; cin >> n;
    rep(i, n) {int a; cin >> a; v.push_back(a);}
    rep(i, n) {if (i) cout << " "; cout << v[i];}
    cout << endl;
    rrep(i, 1, n) {
        int key = v[i];
        v.erase(v.begin() + i);
        //rep(j, v.size()) cout << v[j] << " "; cout << endl;
        int j = i - 1;
        while (v[j] > key && j >= 0) j--;
        v.insert(v.begin() + j + 1, key);
        rep(j, n) {if (j) cout << " "; cout << v[j];}
        cout << endl;
    }
    
    
}



Measured memory_bytes: 3136
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	int n;
	cin>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	vi l(n),r(n);
	int lc=arr[0],rc=arr[n-1];
	REP(i,0,n-1) {
		lc=__gcd(lc,arr[i]);
		l[i]=lc;
	}
	for(int i=n-1;i>=0;i--) {
		rc= __gcd(rc,arr[i]);
		r[i]=rc;
	}
	int mx = max(r[1],l[n-2]);
	REP(i,1,n-2) {
		int gc = __gcd(l[i-1],r[i+1]);
		mx=max(mx,gc);
	}
	cout<<mx;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 4496
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}



int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int n;
  cin >> n;
  int a = 1;
  int b = 1;
  int c = 1;
  vector<int> ans(n,0);
  while(1){
	  reps(i,a){
		  reps(j,i){
			  if(a*a+i*i+j*j+i*j+i*a+j*a <= n){
				  if(i==j&&j==a)
					  ans[a*a+i*i+j*j+i*j+i*a+j*a-1]++;
				  else if((i==j && i!=a)||(i==a && i!=j)||(j==a && i!=j)){
					  ans[a*a+i*i+j*j+i*j+i*a+j*a-1] += 3;
				  }else{
					  ans[a*a+i*i+j*j+i*j+i*a+j*a-1] += 6;
				  }
			  }else{
				  break;
			  }
		  }
	  }
	  a++;
	  if(a*a+1+1+1+a+a > n) break;
  }
  rep(i,n){
	  cout << ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<cassert>

using namespace std;

#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
////////////////////

ll x, y;
int ans;

void solve(){
	ans = 1;
	while(x * 2 <= y){
		x *= 2;
		++ans;
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%lld %lld",&x,&y);

	solve();

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

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main()
{
  int N;
  cin>>N;
  cout<<N*(N+1)/2<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N+1];
        int[] B = new int[N+1];
        for(int i = 0;i < M;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a == 1)  A[b]++;
            else if(b == N) B[a]++;
        }
        for(int i = 0;i < N+1;i++){
            if(A[i]+B[i] == 2){
                System.out.println("POSSIBLE");
                return;
            }
            if(i == N)  System.out.println("IMPOSSIBLE");
        }
    }
}

Measured memory_bytes: 98356
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
//
//
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define ll long long
#define ld long double
#define gap ' '
#define endl '\n'
int dp[101][100001];
int W[101],v[101];
int f(int n,int w) {
	if(n==0 or w==0) return 0;
	if(dp[n][w]!=-1) return dp[n][w];
	int a=0;
	if(w-W[n]>=0) a=max(a,f(n-1,w-W[n])+v[n]);
	a=max(a,f(n-1,w));
	return dp[n][w]=a;
}
void solve() {
	int n,w;
	cin>>n>>w;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	cin>>W[i]>>v[i];
	cout<<f(n,w)<<endl;
}
void solve(bool testcase) {
	int t;cin>>t;while(t--)solve();
}
int32_t main() {
	fio
	solve();
	return 0;
}


Measured memory_bytes: 79232
a = input()
if len(a)%2 == 0:
    a = a[:-2]
    for i in range(int(len(a)/2)):
        if a[:int(len(a)/2)] ==a[int(len(a)/2):]:
            print(len(a))
            break
        else:
            a = a[:-2]
else:
    a = a[:-3]
    for i in range(int(len(a)/2)):
        if a[:int(len(a)/2)] ==a[int(len(a)/2):]:
            print(len(a))
            break
        else:
            a = a[:-2]

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

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

int n;
int v[100100];
int count1[100100];
int count2[100100];

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

    fill(count1, count1+100010, 0);
    fill(count2, count2+100010, 0);
    for(int i = 0; i < n; i+=2){
        count1[v[i]]++;
    }
    for(int i = 1; i < n; i+=2){
        count2[v[i]]++;
    }

    int ma1 = -1, ma_index1 = 0;
    for(int i = 0; i <= 100010; i++){
        if(ma1 < count1[i]){
            ma1 = count1[i];
            ma_index1 = i;
        }
    }
    int ma2 = -1, ma_index2 = 0;

    for(int i = 0; i <= 100010; i++){
        if(ma2 < count2[i]){
            ma2 = count2[i];
            ma_index2 = i;
        }
    }

    if(ma_index1 != ma_index2){
        cout << n - ma1 - ma2 << endl;
    }
    else{
        sort(count1, count1+100010, greater<int>());
        sort(count2, count2+100010, greater<int>());
        int next_ma = max(count1[1], count2[1]);
        cout << n - ma1 - next_ma << endl;
    }


    return 0;
}



Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int ma = 0; int mi = 10000000;
	int a[100010];
	int b = 0; int c = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ma = max(a[i], ma);
		mi = min(a[i], mi);
	}
	if (ma - mi >= 2) {
		cout << "No" << endl;
	}
	else if (ma - mi) {
		for (int i = 0; i < n; i++) {
			if (a[i] == ma) {
				c++;
			}else{
				b++;
			}
		}
		if (b < ma && 2 * (ma - b) <= c) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (a[0] == n - 1 || 2 * a[0] <= n) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	getchar();
	getchar();
	return	0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define pb(a) push_back(a)
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}


int main()
{
    int n;cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    sort(all(a));sort(all(b));
    if(n%2==1){
        cout << b[(n + 1) / 2 - 1] -a[(n + 1) / 2 - 1] + 1 << endl;
    }
    else{
        double tmp = double(b[n / 2 - 1] + b[n / 2])/2 - double(a[n / 2 - 1] + a[n / 2]) / 2;
        ll ans=tmp/0.5+1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 6412
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> list = new ArrayList<String>();
        while(true) {
	        String line = br.readLine();
	        String[] ary = line.split(" ");
	        if(new Integer(ary[0]).equals(0) && new Integer(ary[1]).equals(0) ) 
	        	break;
	        if(new Integer(ary[0]) >= new Integer(ary[1])) {
		        list.add(ary[1]);
		        list.add(" ");
		        list.add(ary[0]);
	        }else {
		        list.add(ary[0]);
		        list.add(" ");
		        list.add(ary[1]);
	        }
	        list.add("\n");
        }
        for(String s: list) {
	        System.out.print(s);
        }
    }
}

Measured memory_bytes: 25156
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int main(){
    string s;
    cin >> s;
    int len = s.length();
    vector<int> v;
    FOR(i,0,len) v.push_back(s[i]-'a');
    int ans = 1000;
    int check = v[0];
    bool ok = true;
    FOR(i,1,len) if(check != v[i]) ok = false;
    if(ok){
        cout << 0 << endl;
        return 0;
    }

    // iで揃える
    FOR(i,0,26){
        vector<int> tmp = v;
        int cnt = 0;
        int l = len;
        while(l>0){
            FOR(k,0,l-1) if(tmp[k+1] == i) tmp[k] = tmp[k+1];
            cnt++;
            bool ok1 = true;
            FOR(k,0,l-1) if(tmp[k] != i) ok1 = false;
            if(ok1){
                ans = min(ans, cnt);
                break;
            }
            l--;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 82;

int n, a[N];
long long dp[N];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  dp[0] = 1000;
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1];
    for (int j = 1; j < i; ++j) if (a[j] < a[i]) {
      long long cur = dp[j - 1];
      dp[i] = max(dp[i], a[i] * (cur / a[j]) + cur % a[j]);
    }
  }
  cout << dp[n] << '\n';
  return 0;
}



Measured memory_bytes: 3756
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()
    a, b = n

    if a > b*2:
        print(a-b*2)
    else:
        print('0')


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
t = 0
for i in range(n):
  t = a[i]
  if t >= b[i]:
    t -= b[i]
    ans += b[i]
  else:
    ans += t
    b[i] -= t
    t = 0
    if b[i] <= a[i+1]:
      ans += b[i]
      a[i+1] -= b[i]
    else:
      ans += a[i+1]
      a[i+1] = 0
      
print(ans)

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

int main(){
	int N;
	cin >> N;
	vector<pair<int,int>> w(N);
	rep(i,N) {
		int x, y;
		cin >> x >> y;
		w[i] = make_pair(y, x);
	}
	sort(w.begin(), w.end());
	ll tot = 0;
	rep(i,N) {
		tot += w[i].second;
		if (tot > w[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 4836
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	string s;
	cin >> s;
	cout << (s.size() % 2 == 0 ^ (s[0] == s[s.size() - 1]) ? "Second" : "First") << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s,t; cin >>s >> t;
    int L = s.size();
    bool flag = true;
    if((int)t.size() != L+1) flag = false;
    for(int i=0;i<L;i++){
        if(s[i] != t[i]) flag = false; 
    } 
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3580
# -*- coding: utf-8 -*-
# 整数の入力

if __name__ == "__main__":
    
    INPUT = list(map(int, input().split()))

    h1 = INPUT[0]
    m1 = INPUT[1]
    h2 = INPUT[2]
    m2 = INPUT[3]
    k = INPUT[4] 


    output = 0
    a1 = h1 * 60 + m1
    a2 = h2 * 60 + m2

    c = a2 - a1 - k


    print(c)


Measured memory_bytes: 9176
#include <string>
#include <iostream>
using namespace std;
 
bool has[26];
 
int main() {
	string str;
	cin>>str;
	for (int i = 0; i < (int)str.size(); i++) has[str[i]-'a']=1;
	for (int i = (int)str.size()-1; i >= -1; i--) {
		int j;
		for (j = i == (int)str.size()-1 ? 0 : str[i+1]-'a'+1; j < 26 && has[j]; j++);
		if (i>=0) has[str[i]-'a']=0;
		if (j == 26) continue;
//		cout<<i<<" "<<j<<"\n";
		str = str.substr(0,i+1) + char(j+'a');
		cout<<str;
		return 0;
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<bitset>
std::bitset<4000005>S(1);
int n,s;
int main(){
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++)scanf("%d",&x),s+=x,S|=(S<<x);s=(s+1)>>1;
	for(int i=s;;i++)if(S[i])return 0*printf("%d\n",i);
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  double p = sqrt(2*N);
  ll x;
  for (x = max(1LL, ll(p) - 10); x <= ll(p) + 10; x++) {
    if (x * (x + 1) >= 2 * N) {
      break;
    }
  }
  ll sum = 0;
  for (ll y = x; y >= 1; y--) {
    if (sum + y <= N) {
      cout << y << "\n";
      sum += y;
    }
  }

  return 0;
}



Measured memory_bytes: 3648
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val map = hashMapOf<Int, Long>()
    val mod = 1000000007L

    (1..N).forEach {
        val div = divisors(it)
        div.entries.forEach {
            map[it.key] = (map.getOrElse(it.key, { 0 }) + it.value) % mod
        }
    }


    var ans = 1L
    map.entries.forEach {
        ans = (ans * (it.value + 1)) % mod
    }
    println(ans % mod)
}



fun divisors(n: Int) : Map<Int, Int> {
    val map = hashMapOf<Int, Int>()

    var num = n
    for (i in 2 .. Math.sqrt(n.toDouble()).toInt()) {
        while (num % i == 0) {
            num /= i
            map[i] = map.getOrElse(i,  { 0 }) + 1
        }
    }

    if (num != 1) {
        map[num] = map.getOrElse(num, { 0 }) + 1
    }

    return map
}

Measured memory_bytes: 33808
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())

print((n-n//2) / n)

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

class Main
{

	

	private static void exhaustiveSearch(int[] a, boolean[] memo, int currentIndex, int sum) {

		memo[sum] = true;

		if (currentIndex >= a.length) 
			return;

		exhaustiveSearch(a, memo, currentIndex + 1, sum);
		exhaustiveSearch(a, memo, currentIndex + 1, sum + a[currentIndex]);
	}


	public static void main(String[] args) {
		try(Scanner reader = new Scanner(new InputStreamReader(System.in)))
		{

			boolean[] memo = new boolean[2001];
			for (int i = 0; i < memo.length; i++) 
				memo[i] = false;

			int n = reader.nextInt();
			reader.nextLine();
			int[] a = new int[n];

			for (int i = 0; i < a.length; i++) {
				a[i] = reader.nextInt();
			}

			Main.exhaustiveSearch(a, memo, 0, 0);

			reader.nextLine();
			
			int q = reader.nextInt();

			for (int i = 0; i < q; i++) 
				System.out.println(memo[reader.nextInt()] ? "yes" : "no");
			


		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}

Measured memory_bytes: 26612
using System;

class myclass
{
    public static void Main()
    {
        int[] l = new int[10001];
        int x;
        for (int i = 0; ; i++){
            x = Int32.Parse(Console.ReadLine());
            if (x == 0){
                x = i;
                break;
            }
            else
                l[i] = x;
        }
        for (int i = 0; i < x; i++)
        {
            Console.WriteLine("Case "+(i+1)+": "+l[i]);
        }
    }
}

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

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

using namespace std;

int main(){
	int n; cin>>n;
	int p[100000];
	rep(i,n) cin>>p[i], p[i]--;

	int cnt=0;
	rep(i,n-1) if(p[i]==i) {
		swap(p[i],p[i+1]);
		cnt++;
	}
	if(p[n-1]==n-1) cnt++;
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
vector<ll> C(26);
vector<vector<ll>> S;

ll change_evaluation(vector<set<ll>>& contest_data, ll t, ll day, ll old) {
  t -= 1;
  day -= 1;
  old -= 1;
  contest_data.at(old).erase(day);
  ll next_t, last_t, next_old, last_old;
  auto itr_t = contest_data.at(t).lower_bound(day);
  next_t = *itr_t;
  itr_t--;
  last_t = *(itr_t);
  auto itr_old = contest_data.at(old).lower_bound(day);
  next_old = *itr_old;
  itr_old--;
  last_old = *(itr_old);

  ll score = S.at(day).at(t) - S.at(day).at(old);
  score += (next_t - day) * (day - last_t) * C.at(t);
  score -= (next_old - day) * (day - last_old) * C.at(old);
  contest_data.at(t).insert(day);
  return score;
}

ll evaluation(vector<ll>& T) {
  ll D = T.size();
  vector<ll> last(26, 0);
  ll score = 0;
  for (ll i = 0; i < D; ++i) {
    ll contest = T.at(i) - 1;
    last.at(contest) = i + 1;
    score += S.at(i).at(contest);
    for (ll j = 0; j < 26; ++j) {
      score -= (i + 1 - last.at(j)) * C.at(j);
    }
  }
  return score;
}

int main() {
  //-----------input-------------
  ll D;
  cin >> D;
  vector<ll> T(D);
  S = vector<vector<ll>>(D, vector<ll>(26));
  for (ll i = 0; i < 26; ++i) {
    cin >> C.at(i);
  }
  for (ll i = 0; i < D; ++i) {
    for (ll j = 0; j < 26; ++j) {
      cin >> S.at(i).at(j);
    }
  }
  vector<set<ll>> contest_data(26, {-1, D});
  for (ll i = 0; i < D; ++i) {
    cin >> T.at(i);
    contest_data.at(T.at(i) - 1).insert(i);
  }
  //--------------------------------------
  // vector<ll> last(26, 0);
  // for (ll day = 0; day < D; ++day) {
  //   ll max_contest = 0;
  //   ll max_score = -INF;
  //   for (ll contest = 0; contest < 26; ++contest) {
  //     ll temp_score = evaluation(contest, day, last);
  //     if (temp_score > max_score) {
  //       max_score = temp_score;
  //       max_contest = contest + 1;
  //     }
  //   }
  //   last.at(max_contest - 1) = day;
  //   T.at(day) = max_contest;
  // }

  // for (ll i = 0; i < D; ++i) {
  //   cout << T.at(i) << "\n";
  // }

  ll score = evaluation(T);
  // cout << score << "\n";
  ll M;
  cin >> M;
  for (ll i = 0; i < M; ++i) {
    ll d, q;
    cin >> d >> q;
    score += change_evaluation(contest_data, q, d, T.at(d - 1));
    T.at(d - 1) = q;
    cout << score << "\n";
  }

  // vector<ll> ans = evaluation(C, S, T);
  // for (ll i = 0; i < ans.size(); ++i) {
  //   cout << ans.at(i) << "\n";
  // }
}


Measured memory_bytes: 3652
#include <stdio.h>
int main(void){
  int a,b,c,i,j;
  int d=0;
  scanf("%d%d",&a,&b);
  for(i=0;i<=a;i++){
    for(j=0;j<=a-i;j++){
      c=a-i-j;
      d=10000*i+5000*j+1000*c;
      if(d==b){
        printf("%d %d %d",i,j,c);
        return 0;
      }
    }
  }
printf("-1 -1 -1");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m; string s,t;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int gcd(int x, int y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i = 1; i <= ty - sy; i++) {
		cout << "U";
	}
	for (int i = 1; i <= tx - sx; i++) {
		cout << "R";
	}
	for (int i = 1; i <= ty - sy; i++) {
		cout << "D";
	}
	for (int i = 1; i <= tx - sx; i++) {
		cout << "L";
	}
	cout << "L";
	for (int i = 1; i <= ty - sy+1; i++) {
		cout << "U";
	}
	for (int i = 1; i <= tx - sx+1; i++) {
		cout << "R";
	}
	cout << "D";
	cout << "R";
	for (int i = 1; i <= ty - sy + 1; i++) {
		cout << "D";
	}
	for (int i = 1; i <= tx - sx + 1; i++) {
		cout << "L";
	}
	cout << "U" << endl;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(input())
    ans = []
    for _ in range(m):
        a = input().strip()
        if a in d:
            ans.append(d[a])
        else:
            ans.append(a)
    print("".join(ans))

Measured memory_bytes: 8512
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    int N, P;
    int[] data;
    int[] powerOfTen;
    int[] invPowerOfTen;

    void solve(Scanner sc, PrintWriter pw) {
        N = sc.nextInt();
        P = sc.nextInt();
        data = new int[N];
        powerOfTen = new int[N + 1];
        invPowerOfTen = new int[N + 1];
        String str = sc.next();
        for (int i = 0; i < str.length(); i++) {
            data[i] = str.charAt(i) - '0';
        }
        powerOfTen[0] = 1;
        for (int i = 1; i <= N; i++) {
            powerOfTen[i] = (powerOfTen[i - 1] * 10) % P;
        }
        invPowerOfTen[0] = 1;
        for (int i = 1; i <= N; i++) {
            invPowerOfTen[i] = power(powerOfTen[i], P - 2);
        }
        pw.println(solve(0, N));
    }

    private int power(int v, int p) {
        if (p == 0) {
            return 1;
        }
        int part = power(v, p / 2);
        int candidate = (part * part) % P;
        int multiply = (p % 2) == 0 ? 1 : v;
        return (multiply * candidate) % P;
    }

    private long solve(int left, int right) {
        if (left + 1 == right) {
            return data[left] % P == 0 ? 1 : 0;
        }


        int mid = left + (right - left) / 2;
        long partial = solve(left, mid) + solve(mid, right);
        int leftStart = mid - 1;
        int currentLeft = 0;
        Map<Integer, Integer> occurs = new HashMap<>();
        while (leftStart >= left) {
            int len = mid - leftStart;
            currentLeft = (((data[leftStart] * powerOfTen[len - 1]) % P) + currentLeft) % P;
            occurs.put(currentLeft, occurs.getOrDefault(currentLeft, 0) + 1);
            leftStart--;
        }

        long result = 0;
        int rightStart = mid;
        int currentRight = 0;
        while (rightStart < right) {
            currentRight = (data[rightStart] + currentRight * 10) % P;
            int lenRight = rightStart - mid + 1;
            int matchLeft;
            if (P == 2 || P == 5) {
                if (currentRight == 0) {
                    result += (mid - left);
                }
            } else {
                 matchLeft = (P - ((invPowerOfTen[lenRight] * currentRight) % P)) % P;
                result += occurs.getOrDefault(matchLeft, 0);
            }
            rightStart++;
        }
//        System.out.println(String.format("left:%d right:%d partial:%d result:%d", left, right, partial, result));
        return result + partial;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 67876
using System;
using System.Linq;

class prog{
  static void Main(){
    string[] input = Console.ReadLine().Split().ToArray();
    Console.WriteLine((input[0] == "H"&&input[1] == "H")||(input[0] == "D"&&input[1] == "D") ? "H" : "D");
    
  }
}

Measured memory_bytes: 13268
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    int N, Ma, Mb;
    int[] a, b, c;
    const int INF = 1234567890;
    void Solve() {
        //intput
        N = io.Int;
        Ma = io.Int;
        Mb = io.Int;
        a = new int[N];
        b = new int[N];
        c = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = io.Int;
            b[i] = io.Int;
            c[i] = io.Int;
        }
        //cal
        var dp = new int[401, 401];
        for (int i = 0; i < dp.GetLength(0); ++i)
            for (int j = 0; j < dp.GetLength(1); ++j)
                dp[i, j] = INF;
        dp[0, 0] = 0;
        for (int i = 0; i < N;++i)
            for (int j = dp.GetLength(0)-1; j >= 0;--j)
                for (int k = dp.GetLength(1) - 1; k >=0;--k)
                    if (dp[j,k]!=INF)
                        dp[j + a[i], k + b[i]] = 
                            Math.Min(dp[j + a[i], k + b[i]], dp[j, k] + c[i]);
        int ans = INF;
        for (int mul = 1; mul * Math.Max(Ma, Mb) < 401;++mul)
            ans = Math.Min(ans, dp[Ma*mul, Mb*mul]);                
        //res
        Console.WriteLine(ans == INF ? -1 : ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}

class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))

#define MOD 1000000007
#define INF 1000000001
#define epsilon 1e-15

typedef long long int ll;
typedef unsigned long long int ull;

/*int seive(int N){
    bool primes[N+1];
    int cnt=0;
    mem(primes, true); primes[1] = false;
    int m = sqrt(N);
    for(int i=2; i<=m; i++){
        if(primes[i]){
            for(int p = i*i; p<=N; p+=i)
                primes[p] = false;
        }
    }

    for(int i=2; i<=N; i++){
        if(primes[i])
            cnt++;
    }

    return cnt;
} */

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b, a%b);
}


   
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int N;
    cin >> N;
    N = 1000 - N%1000;
    if(N==1000) cout << "0\n";
    else cout << N << '\n';

    return 0;
   
}

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

using namespace std;

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int x;
    cin >> x;
    vector <int> l(n + 1);
    vector <int> d(n + 2);
    for (int i = 1; i <= n; i++) cin >> l[i];
    d[1] = 0;
    for (int i = 2; i <= n + 1; i++) {
        d[i] = d[i - 1] + l[i - 1];
    }
    int ans = 0;
    for (int i = 1; i <= n + 1; i++) {
        if (d[i] <= x) {
            ans++;
//            return 0;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<usize>();
    let a = (0..n).map(|_| input()).collect::<Vec<i64>>();

    let mut l = vec![0; n];
    let mut r = vec![0; n];
    l[0] = a[0];
    r[n - 1] = a[n - 1];
    for i in 0..n - 1 {
        l[i + 1] = gcd(l[i], a[i + 1]);
        r[n - i - 2] = gcd(r[n - i - 1], a[n - i - 2]);
    }

    let mut ans = 1;
    for i in 0..n {
        let g = if i == 0 {
            r[1]
        } else if i == n - 1 {
            l[n - 2]
        } else {
            gcd(l[i - 1], r[i + 1])
        };
        ans = std::cmp::max(ans, g);
    }
    println!("{}", ans);
}

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}


Measured memory_bytes: 6524
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


int main() {
	ll H,W;
	string a[100];
	cin >> H >> W;
	REP(i, H) {
		cin >> a[i];
	}
	REP(i, W + 2) {
		cout << "#";
	}
	cout << endl;
	REP(i, H) {
		cout << "#" << a[i] << "#" << endl;
	}
	REP(i, W + 2) {
		cout << "#";
	}
	cin >> H;

	return 0;
}

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

int main(){
    int LastCell;
    int num_fee;
    int StartCell;
    int all_cost;
    int cost=0;
    int *FeeSta;
    int i,j;
    
    scanf("%d %d %d",&LastCell,&num_fee,&StartCell);
    
    //  料金所の場所をFeeSta[i]に格納する
    FeeSta = (int*)malloc(num_fee);
    for(i=0;i<num_fee;i++){
        scanf("%d",&FeeSta[i]);
    }
    
    //  マス0に向かう場合にかかるコストの総数を計算する
    j=0;
    all_cost = num_fee;
    for(i=1;i<StartCell;i++){
        if(i==FeeSta[j]){
            cost++;
            j++;
        }
    }
    
    //  コストの出力
    if(cost<=all_cost-cost){
        printf("%d\n",cost);
    }
    else{
        printf("%d\n",all_cost-cost);
    }
    
    return 0;
    
}

Measured memory_bytes: 128
fun main() {
    val i = readLine()!!.split(" ").map(String::toInt)
    var T_HP  = i[0]
    val T_ATK = i[1]
    var A_HP  = i[2]
    val A_ATK = i[3]
    // T > A > T > A
    var t = 0
    while (/*T_HP <= 0 || A_HP <= 0*/ true) {
        if (t % 2 == 0) { // Takahashi
            A_HP -= T_ATK
            if (A_HP <= 0) {
                println("Yes")
                break
            }
        } else { // Aoki
            T_HP -= A_ATK
            if (T_HP <= 0) {
                println("No")
                break
            }
        }
        ++t
    }
}

Measured memory_bytes: 36300
#include <bits/stdc++.h>
using namespace std;
int n,K,T,S,cnt,t,x,y,L,R,M,rt;
int ps[10005][2],sz[60005];
int lc[60005],rc[60005],op[60005];
int dfn[60005],low[60005],inq[60005],Q[60005],be[60005];
vector <int> e[60005];
struct O{
	int x,i;
}a[20005];
bool cmx(O a,O b){
	return a.x<b.x;
}
void add(int u,int v){
	e[u].push_back(v);
	e[op[v]].push_back(op[u]);
}
void build(int &u,int p,int q){
	if (p==q) {u=p; return;}
	u=++cnt; ++cnt;
	op[u]=u+1; op[u+1]=u;
	build(lc[u],p,(p+q)/2);
	build(rc[u],(p+q)/2+1,q);
	add(lc[u],u);
	add(rc[u],u);
}
void ADD(int x,int u,int p,int q,int l,int r){
	if (l<=p&&q<=r){
		add(x,op[u]);
		return;
	}
	if (l<=(p+q)/2) ADD(x,lc[u],p,(p+q)/2,l,r);
	if (r>(p+q)/2) ADD(x,rc[u],(p+q)/2+1,q,l,r);
}
void dfs(int x){
	dfn[x]=low[x]=++T;
	inq[x]=1; Q[++K]=x;
	for (unsigned i=0;i<e[x].size();++i)
	if (!dfn[e[x][i]]){
		dfs(e[x][i]);
		low[x]=min(low[x],low[e[x][i]]);
	}else
	if (inq[e[x][i]])
		low[x]=min(low[x],dfn[e[x][i]]);
	if (dfn[x]==low[x]){
		++S; Q[K+1]=0;
		while (Q[K+1]!=x){
			inq[Q[K]]=0;
			be[Q[K]]=S;
			--K;
		}
	}
}
bool check(){
	for (int i=1;i<=cnt;++i) e[i].resize(sz[i]);
	for (int i=1,j=1;i<=t;++i){
		while (a[j].x<=a[i].x-M) ++j;
		if (j<i) ADD(i,rt,1,t,j,i-1);
	}
	for (int i=t,j=t;i;--i){
		while (a[j].x>=a[i].x+M) --j;
		if (j>i) ADD(i,rt,1,t,i+1,j);
	}
	T=S=K=0;
	for (int i=1;i<=cnt;++i) dfn[i]=0;
	for (int i=1;i<=cnt;++i)
	if (!dfn[i]) dfs(i);
	for (int i=1;i<=cnt;++i)
	if (be[i]==be[op[i]]) return 0;
	return 1;
}
int main(){
//	freopen("windmills.in","r",stdin);
//	freopen("windmills.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d%d",&x,&y);
		a[++t]=(O){x,i};
		a[++t]=(O){y,-i};
	}
	sort(a+1,a+t+1,cmx);
	for (int i=1;i<=t;++i)
		if (a[i].i>0) ps[a[i].i][0]=i;
		else ps[-a[i].i][1]=i;
	for (int i=1;i<=n;++i){
		op[ps[i][0]]=ps[i][1];
		op[ps[i][1]]=ps[i][0];
	}
	cnt=t; build(rt,1,t);
	for (int i=1;i<=cnt;++i) sz[i]=e[i].size();
	L=0; R=1000000000;
	while (L<R){
		M=(L+R+1)/2;
		if (check()) L=M; else R=M-1;
	}
	printf("%d\n",L);
	return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int c = 0;
  while (a+1 != b){
  c = a;
  a = a-(b-a)+1;
  b = c;
    //??
  }
  cout << a*-1 << endl;
}

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

int main() {
  string s;
  cin >> s;
  
  string ans = "Good";
  
  for(int i = 0; i < 3; i++){
    if(s.at(i) == s.at(i+1) ){
      ans = "Bad";
      break;
    }
  }
  
  cout << ans << endl;
}

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

int main(){
  long int n;
  cin >> n;
  int m = floor(sqrt(n))+1;
  for(int i = m; i > 0; i--){
    if(n%i != 0) continue;
    n /= i;
    break;
  }
  int k = 0;
  while(n != 0){
    n /= 10;
    k++;
  }
  cout << k << endl;
}


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


int main(){
  map<string,int> days;
  days["SUN"]= 7;
  days["MON"]= 6;
  days["TUE"]= 5;
  days["WED"]= 4;
  days["THU"]= 3;
  days["FRI"]= 2;
  days["SAT"]= 1;
  string s;
  cin>> s;
  cout<<days.at(s)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,d,x[11][11],count=0;
  double sum=0;
  cin>>n>>d;
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin>>x[i][j];
    }
  }

  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      sum=0;
      for(int l=0; l<d; l++){
	sum+=(x[i][l]-x[j][l])*(x[i][l]-x[j][l]);
      }
      if(sqrt(sum)==(int)sqrt(sum))count++;
    }
  }
  cout<<count<<'\n';
  return 0;
}


Measured memory_bytes: 256