akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n;
    cin>>n;
    deque<char> q(s.begin(),s.end());
    bool rev=0;
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            rev^=1;
        }
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if(f==1)
            {
                if(rev)q.push_back(c);
                else q.push_front(c);
            }
            else
            {
                if(rev)
                {
                    q.push_front(c);
                }
                else
                {
                    q.push_back(c);
                }
            }
        }
    }
    string res(q.begin(),q.end());
    if(rev) reverse(res.begin(),res.end());
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(){
	int A,B,C,K;
  	int ans;
  	cin >> A >> B >> C >> K;
  	if(K<=A){
    	ans = K;
    }else if(K<=A+B){
    	ans = A;
    }else{
    	ans = A-(K-(A+B));
    }
  	cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>

int main(void)
{
  int a[200], b[200], ab[200];
  int i=0;
  int count;

  while(scanf("%d", &a[i]) != EOF){
    scanf("%d", &b[i]);
    i++;
  }

  for(count=0; count<i; count++){
    if(a[count]+b[count]>=0 && a[count]+b[count] < 10){
      printf("%d\n",1);
    }else if(a[count]+b[count]>=10 && a[count]+b[count] < 100){
      printf("%d\n",2);
    }else if(a[count]+b[count]>=100 && a[count]+b[count] < 1000){
      printf("%d\n",3);
    }else if(a[count]+b[count]>=1000 && a[count]+b[count] < 10000){
      printf("%d\n",4);
    }else if(a[count]+b[count]>=10000 && a[count]+b[count] < 100000){
      printf("%d\n",5);
    }else if(a[count]+b[count]>=100000 && a[count]+b[count] < 1000000){
      printf("%d\n",6);
    }else if(a[count]+b[count]>=1000000 && a[count]+b[count] < 10000000){
      printf("%d\n",7);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;


int main(void){

	string str;
	cin >> str;

	for( int i = 0; i < str.length(); i++ ) {
		char ch = ( str[i] - 'A' + 23 ) % 26 + 'A';
		cout << ch;
	}
	cout << endl;

    return 0;
}

Measured memory_bytes: 1180
n = int(input())
dp = [None] * (n+1)
dp[0] = 1
dp[1] = 1


def main():
    print(fib(n))


def fib(n):
    if n == 0 or n == 1:
        return 1
    elif dp[n] != None:
        return dp[n]
    else:
        dp[n] = fib(n-1) + fib(n-2)
        return dp[n]


if __name__ == "__main__":
    main()



Measured memory_bytes: 5600
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")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

fn main() {
    input!{
        n: usize,
        k: usize,
        c: usize,
//        s: [char; n],
        s: chars,
    }
    let mut l: [usize; 200000] = [0; 200000];
    let mut r: [usize; 200000] = [0; 200000];
    let mut count: usize = 0;
    let mut index: usize = 0;
    while count < k {
        if s[index] == 'o' {
            l[count] = index;
            index = index + c;
            count = count + 1;
        }
        index = index + 1;
    }
    index = n-1;
    count = k;
    while count > 0 {
        if s[index] == 'o' {
            r[count-1] = index;
//        println!("{} {}", r[count], count);
            if index > c {
                index = index - c;
            }
            count = count - 1;
        }
        if index > 0 {
            index = index - 1;
        }
    }
    for i in 0..k {
//        println!("{} {}",l[i]+1, r[i]+1);
        if l[i] == r[i] {
            println!("{}",l[i]+1);
        }
    }
}


Measured memory_bytes: 8700
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll N;
vector<ll> a;

ll M;

class BIT{
public:

  vector<ll> bit;
  BIT(){}
  BIT(int size){
    bit.resize(size,0);
  }

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&(-i);
    }
    return s;
  }

  void add(int i,ll x){//i!=0
    while(i<bit.size()){
      bit[i]+=x;
      i+=i&(-i);
    }
  }
};


bool judge(ll mid){
    vector<ll> b=a;
    for(int i=0;i<N;i++){
        if(b[i]<mid) b[i]=-1;
        else b[i]=1;
    }
    ll sum[N+1]={};
    vector<pair<ll,int>> s;
    s.push_back(make_pair(0,0));
    for(int i=1;i<=N;i++){
        sum[i]+=sum[i-1]+b[i-1];
        s.push_back(make_pair(sum[i],i));
    }
    sort(s.begin(),s.end());
    reverse(s.begin(),s.end());

    BIT bit(N+2);
    ll res=0;
    for(int i=0;i<=N;i++){
        res+=bit.sum(s[i].second+1);
        bit.add(s[i].second+1,1);
    }

    if((M-res)*2>=M) return false;
    else return true;
}

int main(){
  cin>>N;
  M=N*(N-1)/2+N;
  for(int i=0;i<N;i++){
      ll x;
      cin>>x;
      a.push_back(x);
  }

  ll ok=0,ng=1e10;
  while(ng-ok>1){
      ll mid=(ok+ng)/2;
      if(judge(mid)) ng=mid;
      else ok=mid;
  }
  cout<<ok<<endl;

  return 0;
}


Measured memory_bytes: 6260
//096 C
#include<iostream>
using namespace std;
int main(){
	long long h,w;
	cin>>h>>w;
	char a[h+2][w+2];
	for(int i=0;i<=h+1;++i)
	for(int j=0;j<=w+1;++j)
	a[i][j]='.';
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=w;++i){
		for(int j=1;j<=w;++j){
			if(a[i][j]=='#'&&a[i+1][j]!='#'&& a[i-1][j]!='#'&&a[i][j-1]!='#'&&a[i][j+1]!='#'){
				cout<<"No";
				return 0;
			} 
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
inline bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long a,b,c;cin >> a >> b >> c;
	ll k = c - a - b;
	if(k < 0) cout << "No" << endl;
	else if(4 * a * b < k * k) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  }

}


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

#define int long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N;
    cin >> N;
    string cad;
    cin >> cad;

    int res = 0;

    for(int i = 0 ; i < cad.size()-2 ; i++)
    {
    	if(cad.substr(i,3) == "ABC")res++;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		
		int l;
		l = a + a + b + b;
		System.out.println(a * b +" " + l);
	}
}

Measured memory_bytes: 17160
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int fa[N] , n , x[N] , y[N] , id[N];
vector<pair<int,pii> > edge;
int F(int x){return fa[x]==x?x:fa[x]=F(fa[x]);}

int main(){
    scanf("%d",&n);
    rep(i,0,n) {
        scanf("%d%d",x + i,y + i);
        id[i] = i;
    }
    sort(id,id+n,[&](int a,int b){return x[a]<x[b];});
    rep(i,1,n) edge.pb(mp(x[id[i]]-x[id[i-1]],mp(id[i],id[i-1])));
    sort(id,id+n,[&](int a,int b){return y[a]<y[b];});
    rep(i,1,n) edge.pb(mp(y[id[i]]-y[id[i-1]],mp(id[i],id[i-1])));
    sort(all(edge));
    rep(i,0,n) fa[i]=i;
    ll cost=0;
    rep(i,0,sz(edge)){
        int u=edge[i].se.fi,v=edge[i].se.se;
        u=F(u),v=F(v);
        if(u!=v){
            fa[v]=u;
            cost+=edge[i].fi;
        }
    }
    cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 6132
use num_integer::gcd;

fn main() {
    proconio::input! {
        k: usize,
    }
    let mut ans = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    println!("{}", ans);
}


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

ll solve() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    const ll MOD = 998244353;
    auto Add = [&](ll& x, ll y) { x = ( x % MOD + y % MOD ) % MOD; };
    auto Mul = [&](ll& x, ll y) { x = ( x % MOD * y % MOD ) % MOD; };
    vector<vector<ll>> dp(C, vector<ll>(D));
    dp[A-1][B-1] = 1;
    for ( int c = A-1; c < C; c++ ) {
        for ( int d = B-1; d < D; d++ ) {
            if ( c == A-1 && d == B-1 ) continue;
            if ( c > 0 ) {
                ll t = dp[c-1][d];
                Mul(t, d+1);
                Add(dp[c][d],t);
            }
            if ( d > 0 ) {
                ll t = dp[c][d-1];
                Mul(t, c+1);
                Add(dp[c][d],t);
            }
            if ( c > 0 && d > 0 ) {
                ll t = dp[c-1][d-1];
                Mul(t, c);
                Mul(t, d);
                Add(dp[c][d],MOD - t);
            }
        }
    }
    ll ans = dp[C-1][D-1];
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main()
{
  int n;
  std::cin >> n;

  int m;
  std::cin >> m;

  std::vector<int> h(n);
  for (int i = 0; i < n; ++i)
  {
    int v;
    std::cin >> v;
    h[i] = v;
  }

  std::vector<int> r(n);

  for (int i = 0; i < m; ++i)
  {
    int a;
    std::cin >> a;
    --a;

    int b;
    std::cin >> b;
    --b;

    if (h[a] <= h[b])
    {
      ++r[a];
    }

    if (h[a] >= h[b])
    {
      ++r[b];
    }
  }

  int x = 0;
  for (int i = 0; i < n; ++i)
  {
    //std::cout << r[i] << std::endl;
    if (!r[i])
    {
      ++x;
    }
  }

  std::cout << x << std::endl;
}



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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//実行部
void Main()
{
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll p = abs(b - a), q = abs(c - b), r = abs(c- a);
  if(p <= d&&q <= d||r <= d) fin("Yes")
  else fin("No")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
	fastio();
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	int p[a],q[b],r[c];
	for(int i=0;i<a;i++)
	{
		cin>>p[i];
	}
	for(int i=0;i<b;i++)
	{
		cin>>q[i];
	}
	for(int i=0;i<c;i++)
	{
		cin>>r[i];
	}
	sort(p,p+a);
	sort(q,q+b);
	sort(r,r+c);
	reverse(p,p+a);
	reverse(q,q+b);
	reverse(r,r+c);
	int p1=x-1;
	int p2=y-1;
	int p3=0;
	int ans=0;
	for(int i=0;i<x;i++)
	{
		ans+=p[i];
	}
	for(int i=0;i<y;i++)
	{
		ans+=q[i];
	}
	while(p3<c && ((p1>=0 && r[p3]>p[p1]) ||(p2>=0 && r[p3]>q[p2])))
	{
		if(p1<0)
		{
			ans-=q[p2--];
			ans+=r[p3++];
		}
		else if(p2<0)
		{
			ans-=p[p1--];
			ans+=r[p3++];
		}
		else
		{
			if(p[p1]>q[p2])
			{
				ans-=q[p2--];
				ans+=r[p3++];
			}
			else
			{
				ans-=p[p1--];
				ans+=r[p3++];
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	int x,y;
	cin >> x >> y;
	cout << (x%y==0?-1:x) << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, Y int
	fmt.Scan(&N, &Y)

	for x := 0; x <= N; x++ {
		for y := 0; y <= N; y++ {
			if 9000*x+4000*y == Y-1000*N {
				z := N - x - y
				if x >= 0 && y >= 0 && z >= 0 {
					fmt.Println(x, y, z)
					return
				}
			}
		}
	}
	fmt.Println("-1 -1 -1")
}

Measured memory_bytes: 512
from fractions import gcd
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
T = stdin.readline().rstrip()

def lcm(x, n, m):
    return x // gcd(n, m)
  
lcm_n, lcm_m = lcm(N, N, M), lcm(M, N, M)

if S[::lcm_n] != T[::lcm_m]:
    print(-1)
    exit()
print(lcm((N*M), N, M))

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a;
    a.push_back(300);
    rep(i,n) {
        int ai;
        cin >> ai;
        a.push_back(ai);
    }
    a.push_back(-1);

    int soko = 1, top = 0;
    ll mon = 1000;
    while(true){
        bool ok = false;
        for(int j = top+1; j <= n; j++){
            if (a[j-1] >= a[j] && a[j] < a[j+1] && !ok){
                ok = true;
                soko = j;
            }
            else if(a[j-1] < a[j] && a[j] >= a[j+1] && ok){
                top = j;
                break;
            }
        }
        if (!ok) break;
        for(int i = soko; i < top; i++){
            ll kabu = mon / a[i];
            mon %= a[i];
            mon += kabu * a[i+1];
        }
    }
    cout << mon << endl;
}

Measured memory_bytes: 3644
"use strict";

var main = function main(input) {
  var S = input.trim();
  var N = S.split('').length;
  var list = [];

  for (var i = 0; i < Math.pow(2, N - 1); i++) {
    var s = S;

    for (var j = 0; j < N; j++) {
      if (i >> j & 1) {
        var pattern = /[0-9]/;
        var count = 0;

        for (var k = 0; k < s.split('').length; k++) {
          var c = s.split('')[k];

          if (pattern.test(c)) {
            count++;
          }

          if (count == j + 1) {
            s = s.substring(0, k + 1) + '+' + s.substring(k + 1);
            break;
          }
        }
      }
    }

    list.push(s);
  }

  var result = 0;
  list.forEach(function (elem) {
    result += parseInt(elem.split('+').reduce(function (prev, current) {
      return parseInt(prev, 10) + parseInt(current, 10);
    }), 10);
  });
  console.log(result);
};

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

Measured memory_bytes: 10384
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,t,k,cnt;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		vector<int> a;
		vector<int> b;
		rep(i,n){
			scanf("%d",&t);
			a.push_back(t);
		}
		rep(i,n){
			scanf("%d",&t);
			b.push_back(t);
		}
		sort(a.rbegin(),a.rend());
		sort(b.rbegin(),b.rend());
		cnt=0;
		int ans=n;
		rep(i,n){
			if(b[i-cnt]<a[i])cnt++;
			if(i+1>(i+1-cnt)*2){
				ans=i+1;
				break;
			}
		}
		if(ans==n)puts("NA");
		else printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1672
import math

a, b, x = map(int, input().split())
tan = 0

if a*a*b >= 2*x:
    tan = (a*b*b)/(2*x)
else:
    tan = (2*a*a*b-2*x)/(a*a*a)

print(math.degrees(math.atan(tan)))


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

int main(){
    long double a, b, c;
    cin >> a >> b >> c;
    long double _ab, _c;
    _ab = a + b + sqrt(a * b) * 2;
    _c = c;
    if (_ab < _c) puts("Yes");
    else puts("No");
    return 0;
}

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

#define ll long long
#define SZ(x) ((int) (x).size())
#define mk make_pair
#define pb push_back
#define debug(x) cerr << #x << " : " << x << endl;

using namespace std;

int main() {
       ios::sync_with_stdio(false); 
       cin.tie(0);
       ll a, b, n;
       cin >> a >> b >> n;
       if (n >= b - 1) {
           cout << a - (a + b - 1) / b << '\n';
           return 0;
       }
       cout << (a * n) / b << '\n';
       return 0;
}

Measured memory_bytes: 3648
n,m,x=map(int,input().split())
c=[]

for j in range(n):
    c.append([int(i) for i in input().split()])
'''
und_list=[]
for i in range(n):
    for j in range(1,m+1):
        und_list[j-1] += c[i][j]
if min(und_list) < x:
    print(-1)
else:
'''
ans=-1
for i in range(2**n):
    und_list=[0]*m
    sum_money=0
    for j in range(n):
        if((i >> j)&1):
            for k in range(m):
                und_list[k] += c[j][k+1]
            sum_money+=c[j][0]
    if min(und_list)>=x:
        if ans==-1:
            ans= sum_money
        elif ans > sum_money:
            ans=sum_money
print(ans)

Measured memory_bytes: 9244
/*
 
 Author : Bisma
 @ copy from bisma template 1.0
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>
#include <fstream>
#include <cstdio>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b; a>=c; a--)
#define ll long long
#define mem(a, b) memset(a, (b), sizeof(a))
#define loop(a,b,c) for(int a = b ;a<c;a++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;

ll max(ll a, ll b){
    if(a>b) return a;
    return b;
}

ll min(ll a, ll b){
    if(a>b) return b;
    return a;
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

string s;

const int lol = 1e5 + 10;

ll pfx[lol];

int main(){
    fast();
	ll n, k ;
    cin>>n>>k;
    cin>>s;
    ll size = s.size()-1;

    s += '#';

    vector<ll>a;

    ll p = 0;
    rep(i,0,size){
        p++;
       if(s[i] != s[i+1]){
         a.pb(p);
         p = 0;
       }
    }

    mem(pfx, 0);

    size = a.size()-1;

    // rep(i,0,size) cout<<a[i]<<" ";
    // cout<<endl;

    rep(i,1,size+1){
        pfx[i] = pfx[i-1] + a[i-1];
        //cout<<i<<" "<<pfx[i]<<endl;
    }

    pfx[size + 2] = pfx[size + 1];
    ll maxi = -1;

    size = a.size();
     p = 2 * k ;
    if(s[0] == '1'){

        for(int i = 0; i<=size ; i+=2){
            ll range = i - p;

            ll kur = 0;

            if(range >= 0) kur = pfx[range];

            ll tot = pfx[i+1] - kur;

            maxi = max(maxi , tot);
        }

    }else{


        for(int i = 1; i<=size ; i+=2){
            ll range = i - p;

            ll kur = 0;

            if(range >= 0) kur = pfx[range];

            ll tot = pfx[i+1] - kur;

            maxi = max(maxi , tot);
        }

    }

    cout<<maxi<<endl;

    return 0;
    
}
 






Measured memory_bytes: 2116
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
//void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


signed main()
{
	string s;
	string t;
	cin >> s >> t;
	SORT(s);
	SORT(t);
	REVERSE(t);
	YesNo(s < t);
}




Measured memory_bytes: 3628
n, k = map(int, input().split())
a = [int(i) for i in input().split()]


def answer():
    path = [1]
    visited = set([1])
    now = 1
    t = 0

    while True:
        if now == a[now - 1]:
            return now

        now = a[now - 1]
        t += 1

        if t == k:
            return now

        if now in visited:
            ti = path.index(now)
            tc = t - ti
            cycle = path[ti:]
            break
        else:
            path.append(now)
            visited.add(now)

    return cycle[(k - t) % tc]


print(answer())


Measured memory_bytes: 32360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e8;
typedef pair<int,int> P;

int main(){
  int N;cin>>N;
  vector<P> l(N);
  REP(i,0,N){
    l[i].second=i+1;
    cin>>l[i].first;
  }
  sort(l.begin(),l.end());
  REP(i,0,N)cout<<l[i].second<<" ";

  cout<<"\n";
  return 0;

}


Measured memory_bytes: 1536
var print = console.log;

function read_input(_input) {
    var lines = _input.split("\n");
    var i = 0;
    return function () {
        return lines[i++];
    };
}

String.prototype.dot = function dot(x) {
    var res = "";
    for (var i = 0; i < x; i++) {
        res += this.toString();
    }
    return res;
};

function IL(line, min1Flg) {
    var s = line.split(' ');
    var offset = min1Flg ? -1 : 0;
    var res = [];
    for (var i = 0; i < s.length; i++) {
        res.push(parseInt(s[i]));
    }
    return res;
}

function range(i, n) {
    var res = [];
    for (; i < n; i++) {
        res.push(i);
    }
    return res;
}

function IMAX(x, y) {
    return x > y ? x : y;
}

function IMIN(x, y) {
    return x < y ? x : y;
}

function item_getter_key(x) {
    return function (a, b) {
        if (a[x] < b[x]) return -1;
        else if (a[x] > b[x]) return 1;
        return 0;
    };
}

/*

(((???????????)??? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

*/


// input?????\??????????????¨????????\???
function Main(_input) {
    var input = read_input(_input); // input = ?????????????????¢??°
    var N = parseInt(input());
    for (var i = 0; i < N ; i++) {
        var out = 0;
        var runner = 0;
        var pt = 0;
        while (out < 3) {
            var v = input();
            if (v === 'HIT') {
                if (runner === 3) {
                    pt += 1;
                } else {
                    runner++;
                }
            } else if (v === 'HOMERUN') {
                pt += runner + 1;
                runner = 0;
            } else {
                out++;
            }
        }
        print(pt);
    }

}

//*???????????\????????¨??????????????§????????????????¨??????\????????????????????????????????????Main????????????????????????
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//Main(require("fs").readFileSync("input.txt", "utf8"));

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

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int a = vars[0];
        int b = vars[1];

        for(int i = 0; i < 1001; i++)
        {
            if((int)(i * 0.08) == a && (int)(i * 0.1) == b)
            {
                System.Console.WriteLine(i);
                return;
            }
        }

        System.Console.WriteLine(-1);
    }

}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,a,b;
cin>>n>>a>>b;
long long int x=a*(n/(a+b)),y;
if(n<a)
cout<<n;
else
{
if(n%(a+b)==0)
cout<<x;
else
{
 y=n%(a+b);
if(a<=y)
cout<<x+a;
else
cout<<x+y;
}
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int ans = INF;
  REP(i, n){
    int j = 0;
    while(a[i]%2 == 0){
      a[i] /= 2;
      j++;
    }
    chmin(ans, j);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,k=list(map(int,input().split()))
lis=list(map(int,input().split()))
for i in range(len(lis)):
    lis[i]-=1
# print(a[:-1])
count=0
start=0
vis=[0]*len(lis)
trav=[0]*(len(lis)+1)
while(vis[start]==0):
    vis[start]=count+1
    trav[count]=start
    start=lis[start]
    count+=1
start2=0
flag=0
rount=count
while(start!=start2):
    start2=lis[start2]
    k-=1
    count-=1
    if k==0:
        print(start2+1)
        flag=1
if not flag:
    if k==0:
        k=rount
    t=k%count
    for i in range(t):
        start2=lis[start2]
    print(start2+1)

Measured memory_bytes: 92584
// atcoder/abc176/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int h, w, m;
  while (cin >> h >> w >> m) {
    vec<pair<int, int>> v(m);
    cin >> v;
    each (i, v) --i.first, --i.second;
    sort(v.begin(), v.end());

    map<int, int> a, b;
    int mx_a = 0;
    int mx_b = 0;
    each (i, v) {
      setmax(mx_a, ++a[i.first]);
      setmax(mx_b, ++b[i.second]);
    }

    int mx = 0;
    each (i, v) {
      setmax(mx, a[i.first] + b[i.second] - 1);
    }

    vec<int> p, q;
    each (i, a) {
      if (mx_a == i.second) {
        p.push_back(i.first);
      }
    }
    each (i, b) {
      if (mx_b == i.second) {
        q.push_back(i.first);
      }
    }

    each (i, p) {
      each (j, q) {
        if (!binary_search(v.begin(), v.end(), make_pair(i, j))) {
          mx = a[i] + b[j];
          break;
        }
      }
    }

    cout << mx << endl;
  }

  return 0;
}


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

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗する

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) の絶対値

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//配列の受け取り

main(){
  int n=in(),ans=0;
  string a,b,c;
  cin >> a >> b >> c;
  for (int i=0;i<n;i++){
    if (a[i]==b[i]){
      if (a[i]!=c[i]) ans++;
    }
    else {
      if (a[i]==c[i]) ans++;
      else if (b[i]==c[i]) ans++;
      else ans+=2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b, c;
  cin >> a >> b >> c;
  cout << min({(a % 2) * (ll)b * c, a * (b % 2) * (ll)c, a * (ll)b * (c % 2)});

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

struct sec_ord {
  bool operator()(const pair<int, int> &x, const pair<int, int> &y) const {
    return x.second < y.second;
  }
};

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  //vector<vector<bool>> board(h, vector<bool>(w));
  set<pair<int, int>> pos;
  //rep(i, h) rep(j, w) board[i][j] = false;
  map<int, int> xnum, ynum;
  rep(i, m) {
    int y, x;
    cin >> y >> x;
    y--, x--;
    pos.insert(make_pair(y, x));
    xnum[x]++;
    ynum[y]++;
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>, sec_ord> quex, quey;
  for (auto p : xnum) quex.push(p);
  for (auto p : ynum) quey.push(p);

  vector<pair<int, int>> xtop, ytop;
  int xmx = quex.top().second, ymx = quey.top().second;
  while (!quex.empty()) {
    if (quex.top().second < xmx) break;
    xtop.push_back(quex.top());
    quex.pop();
  }
  while (!quey.empty()) {
    if (quey.top().second < ymx) break;
    ytop.push_back(quey.top());
    quey.pop();
  }
  //for (auto p : xtop) cout << "x " << p.first << " : " << p.second << endl;
  //for (auto p : ytop) cout << "y " << p.first << " : " << p.second << endl;

  bool minus = true;
  rep(i, ytop.size()) rep(j, xtop.size()) {
    if (pos.find(make_pair(ytop[i].first, xtop[j].first)) == pos.end()) {
      //cout << i << " " << j << "is empty." << endl;
      minus = false;
      break;
    }
  }
  int mxnum = xmx + ymx - (minus ? 1 : 0);
  cout << mxnum << endl;
  //cout << xmx << " + " << ymx << endl;
  return 0;
}


Measured memory_bytes: 58524
# -*- coding: utf-8 -*-

import math

n = int(input())

tmp=0
if n%27==0:
    tmp=int(n*25/27)
elif (n+1)%27==0:
    tmp=int((n+1)*25/27)-1
else:
    tmp=math.ceil(n*25/27)

if math.floor(tmp*1.08)==n:
    print(tmp)
else:
    print(":(")


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

using namespace std;

int main(void) {
	long long a, b, c;
	cin >> a >> b >> c;
	bool a_ = false, b_ = false, c_ = false;
	if (a % 2 == 0) {
		a_ = true;
	}
	if (b % 2 == 0) {
		b_ = true;
	}
	if (c % 2 == 0) {
		c_ = true;
	}
	if (a_||b_||c_) {
		cout << 0;
	}
	else {
		cout << min(b*c, min(c*a, a*b));
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;

int main() {
    int N, a, b; cin >> N >> a >> b;

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int num = i;
        int sum = 0;
        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }
        if (a <= sum && sum <= b) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
#include<algorithm>

using namespace std;

void solve(string str){
  set <string> train;
  string front,back,rev_front,rev_back;
  train.insert(str);
  for(int j = 1; j < str.size(); j++){
    front = str.substr(0,j);
    rev_front = front;
    reverse(rev_front.begin(),rev_front.end());
	    
    back = str.substr(j,str.size()-j);
    rev_back = back;
    reverse(rev_back.begin(),rev_back.end());
	  
    train.insert(back + front);
    train.insert(rev_front + back);
    train.insert(back + rev_front);
    train.insert(front + rev_back);
    train.insert(rev_back + front);
    train.insert(rev_front + rev_back);
    train.insert(rev_back + rev_front);
  }
  cout << train.size() << endl;

}



int main(){
  int m;
  string str;
  cin >> m;
  for( int i = 0; i < m; i++){
    cin >> str;
    solve(str);

  }

  return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, d;
string str;

int main(){
	cin >> n >> d;
	cout << (n + 2*d) / (2*d+1) << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var A, B int
  fmt.Scanf("%d %d", &A, &B)
  
  if (A + B) % 2 == 0 {
    fmt.Println((A + B) / 2)
  } else {
    fmt.Println("IMPOSSIBLE")
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
//#define kk
#define int long long
#define FOR(a, b) for(int i=a; i<=b; i++)
#define REP(i, a, b) for(int i=a; i<=b; i++)
#define ff first
#define ss second
#define ll long long
#define inf 1000000000
#define pb push_back
#define mod 1000000007
 
const ll INF=1e18+5;
const int maxN=2e5+5;
typedef pair<int, int> pi;

int fact[maxN], inv_fact[maxN];

int power(int a, int n){
	int res=1;
	
	while(n){
		if(n%2) res=(res*a)%mod, n--;
		else a=(a*a)%mod, n/=2;
	}
	return res;
}

void init(){
	fact[0]=inv_fact[0]=1;
	
	for(int i=1; i<maxN; i++){
		fact[i]=(i*fact[i-1])%mod;
		inv_fact[i]=power(fact[i], mod-2)%mod;
	}
}

int combinator(int a, int b){
	if(a<0 || b<0 || a<b) return 0;
	
	return (fact[a]%mod*inv_fact[b]%mod*inv_fact[a-b]%mod)%mod;
}

void solve(){
	int h, w, n;
	cin>>h>>w>>n;
	
	vector<pi> arr(n);
	
	for(int i=0; i<n; i++){
		int a,b;
		cin>>a>>b;
		arr[i]={a-1,b-1};
	}
	arr.pb({h-1, w-1});
	
	sort(arr.begin(), arr.end(), [](pi a, pi b){
		return a.ff+a.ss<b.ff+b.ss;
		});
		
	init();
	
	vector<int> dp(n+1, 0);
	
	for(int i=0; i<=n; i++){
		int a=arr[i].ff, b=arr[i].ss;
		int f=combinator(a+b, b);
		
		for(int j=0; j<i; j++){
			int c=arr[j].ff, d=arr[j].ss;
			if(c<=a && d<=b){
				f=(f-((dp[j]*combinator(a-c+b-d, b-d))%mod)+mod)%mod;
			}
		}
		dp[i]=f;
	}
	cout<<dp[n]<<endl;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cout<<fixed<<setprecision(6);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){		
		solve();
	}
}


Measured memory_bytes: 6844
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int length=scan.nextInt();
        String str=scan.next();
        int count=0;
        int i;
        int max=0;
        for(i=0;i<length;i++){
            if(str.charAt(i)=='I'){
                count++;
            }
            else if(str.charAt(i)=='D'){
                count--;
            }
           if(max<count){
               max=count;
           }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>
#include <cstring>
using namespace std;

const int TM_MAX = 44000;

bool is_valid_time(vector<int> vec) {
    for(int i=0; i<3; i++) {
        vec[i] %= 60;
    }

    int h = vec[0], m = vec[1];
    int tick = h % 5;
    int lb = 12 * tick, ub = 12 * (tick + 1);
    return lb <= m && m < ub;
}

int calc_time(vector<int> vec) {
    for(int i=0; i<3; i++) {
        vec[i] %= 60;
    }
    vec[0] = vec[0] / 5 * 5;
    return vec[0] * 60 * 12 + vec[1] * 60 + vec[2];
}

struct Segment {
    int l, r, len;
    Segment() {}
    Segment(int x, int y) {
        assert(x <= y);
        l = x, r = y;
        len = r - l + 1;
    }
    bool operator<(const Segment &s) const {
        if(len != s.len) return len < s.len;
        return l < s.l;
    }
};

string convert_time(int tm) {
    int h = (tm / 3600) % 12;
    int m = (tm / 60) % 60;
    int s = tm % 60;

    char buf[30];
    sprintf(buf, "%02d:%02d:%02d", h, m, s);

    return string(buf);
}

string convert_seg(Segment s) {
    string ret = "";
    ret += convert_time(s.l) + " ";
    ret += convert_time(s.r);
    return ret;
}

int main() {
    int N;
    while(cin >> N, N) {
        vector<int> watch_list[TM_MAX];
        for(int i=0; i<N; i++) {
            vector<int> times(3);
            for(int k=0; k<3; k++) {
                cin >> times[k];
            }

            sort(times.begin(), times.end());
            do {
                for(int k=0; k<60; k++) {
                    vector<int> tmp = times;
                    for(int x=0; x<3; x++) tmp[x] += k;

                    if(!is_valid_time(tmp)) continue;

                    int point = calc_time(tmp);
                    watch_list[point].push_back(i);
                }
            }while(next_permutation(times.begin(), times.end()));
        }

        int cnt = 0;
        vector<int> appeared(N);

        int ub = 0, lb = 0;
        vector<Segment> seg;
        while(ub < TM_MAX) {
            for(; ub < TM_MAX && cnt != N; ub++) {
                for(auto x : watch_list[ub]) {
                    if(appeared[x] == 0) cnt++;
                    appeared[x]++;
                }
            }

            for(; cnt == N; lb++) {
                for(auto x : watch_list[lb]) {
                    if(appeared[x] == 1) cnt--;
                    appeared[x]--;
                }
            }

            if(ub != TM_MAX) {
                seg.push_back(Segment(lb - 1, ub - 1));
            }
        }

        sort(seg.begin(), seg.end());
        cout << convert_seg(seg[0]) << endl;
    }
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

int H,W;
char s[55][55];
bool visited[55][55];

int main(){
	cin>>H>>W;
	int black=0;
	REP(i,H){
		REP(j,W){
			cin>>s[i][j];
			visited[i][j]=false;
			if(s[i][j]=='#')black++;
		}
	}
	int step=0;
	queue<pii> que;
	que.push(pii(0,0));
	bool judge=false;
	while(true){
		queue<pii>next;
		while(!que.empty()){
			pii p=que.front();
			que.pop();
			for(int i=0;i<4;i++){
				int ny=p.first+vy[i];
				int nx=p.second+vx[i];
				if(ny<0 || ny>=H || nx<0 || nx>=W)continue;
				if(s[ny][nx]=='.' && !visited[ny][nx]){
					next.push(pii(ny,nx));
					visited[ny][nx]=true;
				}
				if(ny==H-1 && nx==W-1){
					judge=true;
					break;
				}
			}
		}
		if(judge || next.empty())break;
		que=next;
		step++;
	}
	if(judge)cout<<H*W-black-step-2<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256