akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    int n,m;
    cin >> n >> m;
    cout << (n - 1) * (m-1) << endl;

    return 0;

}


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

using namespace std;
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a[4],tmp;cin>>tmp;
  //各桁をa配列に格納
  repr(i,3){
    a[i]=tmp%10;
    tmp/=10;
  }
  int res;
  char op[3];
  for(int i=0;i<( 1 << 4 );i++){
    //今回の結果
    res=a[0];
    for(int j=1;j<4;j++){
      if( i & ( 1 << j ) ){
        res+=a[j];
        op[j-1]='+';
      }else{
        res-=a[j];
        op[j-1]='-';
      }
    }
    if(res==7){
      rep(i,3){
        cout<<a[i]<<op[i];
      }
      cout<<a[3]<<"=7"<<'\n';
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  
  double n;
  cin>>n;
  vector<int> cou(10001);

   for(int i=1;i<=101;++i){
    for(int j=1;j<=101;++j){ 
      for(int k=1;k<=101;++k){
        int mo=i*i+j*j+k*k+i*j+i*k+j*k;
        if(mo<10001)
          ++cou[mo];
      }
    }
  }
  for(int i=1;i<=n;++i){
    cout <<cou[i]<<endl;
  }
}

Measured memory_bytes: 3668
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

int N;

vector<pii> L;
vector<pii> W;
int memo[101];

int rec(int n){
	if(memo[n])
		return memo[n];
	if(W[n].first == -1 && W[n].second == -1){
		int l=L[n].second;
		int r=L[n].first;
		int gcd_ = gcd(l, r);
		l /= gcd_;
		r /= gcd_;
		return memo[n]=l+r;
	}else if(W[n].first == -1){
		int l, r;
		r = rec(W[n].second);
		int lcm_ = lcm(r*L[n].second, L[n].first);
		r= lcm_/L[n].second;
		l = lcm_/L[n].first;
		return memo[n]=l+r;
	}else if(W[n].second == -1){
		int l, r;
		l = rec(W[n].first);
		int lcm_ = lcm(l*L[n].first, L[n].second);
		r = lcm_/L[n].second;
		l=lcm_/L[n].first;
		return memo[n]=l+r;
	}else{
		int l, r;
		l = rec(W[n].first);
		r = rec(W[n].second);
		int lcm_ = lcm(l*L[n].first, r*L[n].second);
		l = lcm_/L[n].first;
		r = lcm_/L[n].second;
		return memo[n]=l+r;
	}

	return 0;
}

int main() {
	while(cin >> N, N){
		L.clear();
		W.clear();
		memset(memo, 0, sizeof(memo));
		rep(i, N){
			int p,q,r,b;
			cin >> p >> q >> r >> b;
			L.pb(mp(p, q));
			W.pb(mp(r - 1 ,b - 1));
		}
		int m=0;
		rep(i, N){
			m=max(m,rec(i));
		}
		cout << m << endl;

	}


	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  string ans="No";
  if(y>=(2*x) && y<=(4*x) && y%2==0)
  {
   ans="Yes"; 
  }
  cout<<ans<<endl;
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    vector<int> p(m), y(m);
    vector<vector<int>> ans(n);
    inc(i, 0, m){
        cin >> p[i] >> y[i];
        p[i]--;
        ans[p[i]].pb(y[i]);
    }
    inc(i, 0, n) sort(ans[i].begin(), ans[i].end());
    inc(i, 0, m){
        printf("%06d%06d\n", p[i]+1, int(lower_bound(ans[p[i]].begin(), ans[p[i]].end(), y[i]) - ans[p[i]].begin() + 1));
    }

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	string ans;

	ans += string(abs(ty - sy), 'U') + string(abs(tx - sx), 'R');
	ans += string(abs(ty - sy), 'D') + string(abs(tx - sx), 'L');

	ans += 'L' + string(abs(ty - sy) + 1, 'U') + string(abs(tx - sx) + 1, 'R') + 'D';
	ans += 'R' + string(abs(ty - sy) + 1, 'D') + string(abs(tx - sx) + 1, 'L') + 'U';

	cout << ans << "\n";
}

Measured memory_bytes: 256
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True
for i in range(N+1):
    if i == 0:
        memo[0]["****"] = 1
    elif i == 1:
        memo[1]["***A"] = 1
        memo[1]["***C"] = 1
        memo[1]["***G"] = 1
        memo[1]["***T"] = 1
    else:
        #print("aa")
        for c in 'ACGT':
            for j in memo[i-1]:
                #print(j)
                if ok(j[1:] + c):
                    if j[1:] + c not in memo[i]:               
                        memo[i][j[1:] + c] = memo[i-1][j] % MOD
                    else:
                        memo[i][j[1:] + c] += memo[i-1][j] % MOD

s = 0
for i in memo[N].values():
    s += i % MOD
print(s % MOD)

Measured memory_bytes: 6176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		for(int i = 0; i < 5; i++)
		{
			if(p[i] == 0)
			{
				Console.WriteLine(i+1);
				return;
			}
		}
		
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 27540
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        int quiz_num = sc.nextInt();
        String str = sc.next();
        char[] seq = str.toCharArray();
        
        int[] DP = new int[seq.length];
        int cnt = 0;
        boolean flg = false;
        for(int i = 0; i < seq.length; i++){
                if(seq[i] == 'C' && flg){
                    cnt++;
                    flg = false;
                } else if(seq[i] == 'A'){
                    flg = true;
                } else{
                    flg = false;
                }
                DP[i] = cnt;
            }
        
        int start = 0;
        int end = 0;

        for(int n = 0; n < quiz_num; n++){
            start = sc.nextInt();
            end = sc.nextInt();
            
            System.out.println(DP[end-1] - DP[start-1]);
        }
    }
}

Measured memory_bytes: 65164
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = inf;
  rep(i, (1 << n)) {
    vector<int> f(m, 0);
    int res = 0;
    rep(j, n) {
      if (i >> j & 1) {
        res += c[j];
        rep(k, m) f[k] += a[j][k];
      }
    }
    bool ff = true;
    rep(i, m) {
      if (f[i] < x) {
        ff = false;
        break;
      }
    }
    if (ff) chmin(ans, res);
  }
  cout << (ans == inf ? -1 : ans) << '\n';




  
  return 0;
}

Measured memory_bytes: 3656
# ABC102 C - Linear Approximation
N = int(input())
A = list(map(int, input().split()))

bl = []
for i in range(N):
    bl.append(A[i] - (i+1))
bl.sort()
if N % 2 == 0:
    b = (bl[N//2-1] + bl[N//2]) // 2
else:
    b = bl[N//2]

ans = 0
for i in range(N):
    ans += abs(A[i] - (b + (i+1)))
print(ans)

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

int main() {
 //最初にZを引く
 //forでまわす
 //aは椅子の長さbは人の幅cは人と人の間
  
  int a,b,c;
  	cin>>a>>b>>c;
  a-=c;
  int sum=0;
  
  for(int i=0;i<100001;i++){
	a-=(b+c);
    sum+=1;
    
    if(a<(b+c)){
      cout<<sum<<endl;
      break;
    }
  }
    
}


Measured memory_bytes: 256
#abc 109 b
n=int(input())
w=[]
for i in range(n):
    word=input()
    w.append(word)

flag=True
if len(w)!=len(set(w)):
    flag=False
else:
    for i in range(n-1):
        if w[i][-1]!=w[i+1][0]:
            flag=False
            break

if flag:
    print("Yes")
else:
    print("No")


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

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

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int a,b,c;

int main(){
  scanf("%d %d %d",&a,&b,&c);
  if(c>=a && c<=b){
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
}


Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
    var series = input[1].split(" ");
    series = series.map(str => parseInt(str, 10));
    var n = parseInt(input[0], 10);
    var water = 0;
    for(var i = 0; i < n; i++){
        water += (i==0)?series[i]:((series[i-1] < series[i])?(series[i]-series[i-1]):0);
    }
    console.log(water);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

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

money = 1000
stock = 0

def is_minimal(idx):
    if idx!=N-1:
        if A[idx+1]>A[idx]:
            return True
        else:
            return False

def is_maximal(idx):
    if idx!=N-1:
        if A[idx+1]<A[idx]:
            return True
        else:
            return False

for i in range(N-1):
    if is_minimal(i):
        stock += money//A[i]
        money %= A[i]
    elif is_maximal(i):
        money += A[i]*stock
        stock = 0

money += A[N-1]*stock
stock = 0
print(money)
    


Measured memory_bytes: 9196
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >>n >>k;
	n %= k;
	cout <<min(n, k - n);
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"

#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define LINF ((ll)1 << 60)
#define INF (1 << 28)
template<typename T>
void chmax(T& a, T b) {
        if (a < b) a = b;
}
template<typename T>
void chmin(T& a,T b) {
        if (a > b) a = b;
}
bool debug = false;
//.....................
ull mod = (int)1e9 + 7;
const int MAX = (int)2e5 + 5;

ll N;
vector<ll> a;
ll res;

void solve() {
        cin >> N;
        a.resize(N);
        rep(i, N) cin >> a[i];
        res += a[0] / 2;
        a[0] %= 2;
        REP(i, 1, N) {
                if (debug) dump(res);
                if (a[i] == 0) continue;
                a[i] += a[i-1];
                res += a[i] / 2;
                a[i] %= 2;
        }
        cout << res << endl;
}

signed main(int argc, char *argv[]) {
        int T = 1;
        cout << fixed << setprecision(20);
        rep(i, argc) {
                if (argv[i] == "-debug"s) {
                        debug = true;
                }
        }
        rep(i, T) {
                solve();
        }
        return 0;
}

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

int main() {
  int n; cin>>n;
  vector<int> a(n),b(n);
  rep(i,n){
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
 
  sort(b.begin(),b.end());
  rep(i,n){
    if(a.at(i)==b.at(n-1)){cout<<b.at(n-2)<<endl;}
    else{cout<<b.at(n-1)<<endl;}
  }
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int w,n;
	cin>>w>>n;
	int c[31];
	int a,b;
	for(int x=1;x<=w;x++){
		c[x]=x;
	}
	for(int y=0;y<n;y++){
		scanf("%d,%d",&a,&b);
		swap(c[a],c[b]);
	}
	for(int z=1;z<=w;z++){
		cout<<c[z]<<endl;
	}
	return 0;
	}



Measured memory_bytes: 3144
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N, Q = iim()
    it = map(int, sys.stdin.read().split())

    dp = [-1] * N

    def find(x):
        if dp[x] < 0:
            return  x

        ans = dp[x] = find(dp[x])
        return ans

    def union(x, y):
        x1 = find(x)
        y1 = find(y)

        if x1 == y1:
            return

        xr = dp[x1]
        yr = dp[y1]
        if xr <= yr:
            dp[y1] = x1
            dp[x1] += yr
        else:
            dp[x1] = y1
            dp[y1] += xr

    ans = []
    for t, u, v in zip(it, it, it):
        if t == 1:
            ans.append(1 if find(u) == find(v) else 0)
        else:
            union(u, v)

    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()


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

typedef long long ll;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

ll mod=1e9+7;

using namespace std;


ll inputValue(){
	ll a;
	cin >> a;
	return a;
};

void inputArray(int * p, ll a){
	rep(i, a){
		cin >> p[i];
	}
};

template<typename T>
void inputVector(vector<T>& p, ll a){
	rep(i, a){
		T input;
		cin >> input;
		p.emplace_back(input);
	}
}


template <typename T>
void output(T a) {
	cout << a << "\n";
}

int main(int argc, const char * argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    ll i;
    cin >> i;
    cout << (i/2+i%2) << endl;
	return 0;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	_, s := nextInt(), next()
	r, b := 0, 0
	for _, v := range s {
		if v == 'R' {
			r++
		} else {
			b++
		}
	}
	if r > b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

typedef long long ll;

ll p(int l) {
	if(l == 0) return 1;
	else return 1 + 2 * p(l-1);
}

ll g(int l) {
	if(l == 0) return 1;
	else return 3 + 2 * g(l-1);
}

ll f(int l, ll n) {
	if(l == 0) return (n >= 1);
	else {
		ll u = g(l-1);
		if(n-1 <= u) return f(l-1, n-1);
		return p(l-1) + (n >= u+2) + f(l-1, n-u-2);
	}
}

int main(){
	int n;
	ll x;
	cin >> n >> x;
	cout << f(n, x) << endl;
	return 0;
}


Measured memory_bytes: 256
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  ll a, b, c; cin >> a >> b >> c;
  ll k; cin >> k;
  ll ans = min(a, k);
  k -= min(a, k);
  k -= min(b, k);
  ans -= min(c, k);
  print(ans);
}

int main() {
  int t; t = 1;
  while(t--) solve();
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main(void){
    int a,b,k,mn,mx;
    vector<int> kou;
    cin >> a >> b >> k;
    mn = min(a,b);
    mx = max(a,b);
    for(int i = 1;i <= mn;i++){
        if(mn % i == 0 && mx % i == 0){
            kou.push_back(i);
        }
    }
    reverse(kou.begin(),kou.end());
    cout << kou[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1010;
int a[55][55];
int num[55] , low[55];
int n , m , ans , k;
void dfs(int t,int da){
    num[t] = ++k;
    low[t] = k;
    for (int i=1; i<=n; i++){
        if (a[t][i] == 1){
            if (num[i] == 0){
                dfs(i,t);
                low[t] = min(low[i] , low[t]);
                if (low[i] > num[t])  ans ++;
            }
            else if (i != da)
                low[t] = min(low[t] , num[i]);
        }
    }
}
int main()
{
    while (~scanf("%d%d",&n,&m)){
        memset(a , 0 , sizeof a);
        memset(low , 0 , sizeof low);
        memset(num , 0 , sizeof num);
        for (int i=1; i<=m; i++)  {
            int x , y;
            scanf("%d%d",&x,&y);
            a[x][y] = a[y][x] = 1;
        }

        k = 0;
        ans = 0;
        dfs(1,1);
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
using ll=long long int;

int main(){
    int N,D;
    cin >> D >> N;
    int tmp = pow(100,D);
    int ans=0;
    for(int i=1;i<=N;i++){
        if(i%100==0){
            ans += tmp*2;
        }
        else{
            ans+=tmp;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

# 約数の列挙
#############################################################
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
#############################################################

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

# 操作後も総和は変わらない
# 操作後にdivが公約数なら、divは総和の約数でもある
sum_A = sum(A)
div_list = make_divisors(sum_A)
ans = 1

for div in div_list:
    # divで割った余りのリストをソート
    # どこかを境に、左側は-1をして右側は+1をすると仮定する
    tmp = [a % div for a in A]
    tmp.sort()

    # 累積和
    cumsum1 = [0]
    cumsum2 = [0]
    for i in tmp:
        cumsum1.append(cumsum1[-1] + i)
        if i != 0:
            cumsum2.append(cumsum2[-1] + (div - i))
        else:
            cumsum2.append(cumsum2[-1])

    for i in range(1, N):
        cnt_minus = cumsum1[i]
        cnt_plus = cumsum2[N] - cumsum2[i]
        # 条件を満たす時、必ずどこかで等しくなる
        # （証明が理解できていないが、実験すると確かにそうなりそう）
        if cnt_minus == cnt_plus and cnt_minus <= K:
            ans = div

print(ans)


Measured memory_bytes: 74104
//package src.com.jetman.atcoder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @description:
 * @author: Jetman
 * @create: 2020-08-29 14:39
 **/
public class Main {

    Scanner sc = new Scanner(System.in);

    long MOD = 1000000000 + 7;


    private void slove() {

        int n = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[n-i-1] = sc.nextInt();
        }

        int c = -1;
        for (int i = 0; i < n; i++) {
            if (a[i] == b[i]) {
                c = a[i];
                break;
            }
        }
        int l = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == c && b[i] == c) {
                l = i;
                break;
            }
        }
        int r = -1;
        for (int i = n-1; i >=0; i--) {
            if (a[i] == c && b[i] == c) {
                r = i;
                break;
            }
        }

        for (int i = 0; i < n; i++) {
            if (c != -1 && a[i] != c && b[i] != c && l <= r) {
                int tmp = b[i];
                b[i] = b[l];
                b[l] = tmp;
                l++;
            }
        }
        if (l <= r) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
            for (int i = 0; i < n; i++) {
                System.out.print(b[i] + " ");
            }
        }








    }

    public static void main(String[] args) {
        new Main().slove();
    }
}


Measured memory_bytes: 63332
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	LL N, K;
	cin >> N >> K;
	LL ret = 0;
	for (LL b = K + 1; b <= N; b++) {
		LL lb = K;
		LL ub = b;
		while (lb <= N) {
			LL cnt = min(N + 1, ub) - max(1ll, lb);
			if(cnt>0)ret += cnt;
			lb += b;
			ub += b;
		}
	}
	cout << ret << endl;
	return 0;
}


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

int main() {

    int a, b; cin >> a >> b;
    string s; cin >> s;
    bool can = true;
    for (int i = 0; i < a + b + 1; i++) {
        if (i == a) {
            if (s[i] != '-') {
                can = false;
                break;
            }
        }
        else {
            if (!(0 <= s[i] - '0' && s[i] - '0' <= 9)) {
                can = false;
                break;
            }
        }
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;        
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	

	int a;
	cin >> a;
	
	
	
	cout << (a*(a+1))/2<< endl;
	
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> dark(n,-1);
    vector<ll> d(m);
    for(int i=0;i<m;i++){
        ll a;
        cin>>a;
        a--;
        dark[a]=i;
        d[i]=a;
    }
    vector<vector<ll>> edge(n,vector<ll>(k));
    for(auto &i:edge){
        for(auto &t:i){
            cin>>t;
            t-=1;
        }
    }
    vector<ll> dp(1LL<<m,E);
    dp.back()=0;
    queue<ll> Q;
    Q.push((1LL<<m)-1);
    while(!Q.empty()){
        ll w=Q.front();
        Q.pop();
        for(int i=0;i<k;i++){
            ll next=0;
            for(int t=0;t<m;t++){
                if((w>>t&1) && (dark[edge[d[t]][i]]>=0)){
                    next|=1LL<<dark[edge[d[t]][i]];
                }
            }
            if(dp[next]>dp[w]+1){
                if(next==0){cout<<dp[w]+1<<endl; return 0;}
                dp[next]=dp[w]+1;
                Q.push(next);
            }
        }
    }
    cout<<dp[0]<<endl;
    
    
    
    return 0;
}



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

int main()
{
	int n , k;
	cin >> n >> k;
	bool arr[n+1] = {false};
	for(int i = 0; i < k; i++)
	{
		int d;
		cin >> d;
		for(int j = 0; j < d; j++)
		{
			int t;
			cin >> t;
			arr[t] = true;
		}
	}
	int count = 0;
	for(int i = 1; i <= n; i++)
	{
		if(arr[i] == 0)
			count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;

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
        ll n,k;cin>>n;
        ll arr[n],sum=0;map<ll,ll> mp;
        for(ll i=0;i<n;i++)cin>>arr[i],mp[arr[i]]++,sum+=arr[i];
        ll q;cin>>q;
        ll a,b;
        while(q--){
            cin>>a>>b;
            sum=sum+(b-a)*mp[a];
            mp[b]+=mp[a];
            mp[a]=0;
            cout<<sum<<endl;
        }

}


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

typedef long long ll;

int main(){
  ll N,M;
  cin >> N >> M;
  map<ll,ll> m;
  for(int i = 0; i < N; i++){
    ll tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    if(m.count(tmp1) == 0){
      m[tmp1] = tmp2;
    } else { 
      m[tmp1] += tmp2;
    }
  }
  
  ll ans = 0;
  ll cnt = 0;
  for(auto x:m){
    if(cnt + x.second < M){
      cnt += x.second;
      ans += x.first * x.second;
    } else { 
      ans += (M - cnt) * x.first;
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {
    int N; cin >> N;
    vector<int> D(N);
    rep(i, 0, N) cin >> D[i];
    sort(D.begin(), D.end());
    function<int(int, int)> calc = [&](int a, int b) {
        int res = abs(a - b);
        if(res > 12) res = 24 - res;
        return res;
    };
    function<int(int)> solve = [&](int d) {
        vector<int> T;
        T.push_back(0);
        rep(i, 0, N) {
            if((i + d) % 2) T.push_back(D[i]);
            else T.push_back(24 - D[i]);
        }
        int res = 12;
        rep(i, 0, N) rep(j, i + 1, N + 1) {
            res = min(res, calc(T[i], T[j]));
        }
        return res;
    };
    cout << max(solve(0), solve(1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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);
    int h,w;cin>>h>>w;
    const char M = 110;
    char grid[M][M];
    bool lok[M], cok[M];
    rep(i,h){
        rep(j,w){
            cin>>grid[i][j];
        }
    }
    rep(i, h){
        bool flag=false;
        rep(j, w){
            if(grid[i][j]=='#'){
                flag = true;
                break;
            }
        }
        lok[i] = flag;
    }
    rep(j,w){
        bool flag = false;
        rep(i,h){
            if(grid[i][j]=='#'){
                flag = true;
                break;
            }
        }
        cok[j]=flag;
    }
    rep(i, h){
        if(lok[i]){
            rep(j,w){
                if(cok[j]){
                    cout<<grid[i][j];
                }
            }
        cout<<endl;
        }
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int M = 2019;

int main()
{
  ll L,R;
  cin >> L >> R;
  vint mod2019(M);
  
  for(ll i=L; i<=R; i++){
    int m = i%M;
    mod2019[m]++;
    if(2 == mod2019[m]){
      break;
    }
  }
  
  int ans = M*M;
  REP(i,M){
    if(0 == mod2019[i])continue;
    REP(j,M){
      if(0 == mod2019[j] || i>=j)continue;
      ans = min(ans,(i*j)%M);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
a, b, k = map(int, raw_input().split())

if b - a + 1 <= k * 2:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)
    for i in range(b-k+1, b+1):
        if i >= 1:
            print(i)


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

int main() {
	int N, count = 0;
	cin >> N;
	if (N == 1 || N == 2 || N == 4) cout << 4 << endl;
	else {
		while (N != 1) {
			if (N % 2 == 0) N /= 2;
			else  N = N * 3 + 1;
			count++;
		}
		cout << count + 2 << endl;
	}
}


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

int main(){
  int n;
  cin >> n;
  vector<P> b(n);
  rep(i,n) {
    int x, y;
    cin >> x >> y;
    b[i] = {x,y};
  }
  map<P,int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      mp[{b[i].first - b[j].first, b[i].second - b[j].second}]++;
     }
  }

  int res = 0;
  for (auto p : mp) {
    res = max(res, p.second);
  }
  cout << n - res << endl;
  return 0;
} 

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
using namespace std;

int extgcd(int a,int b,int &x,int &y){
	int g=a;
	x=1,y=0;
	if(b!=0){
		g=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}
	return g;
}
 
// 逆元
int mod_inverse(int a,int m){
	int x, y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}
 
// 階乗
std::vector<int>fact;
void mod_fact(int n, int m){//N,MOD
	fact.resize(n+1);
	fact[0]=1;
	for(int i=1;i<=n;i++){
		fact[i]=fact[i-1]*i%m;
	}
}
 
// nCk mod p
int mod_nCr(int n, int k, int m){
	if(n<k)return 0;
	return fact[n]*mod_inverse(fact[k]*fact[n-k]%m,m)%m;
}

int n,k;
int a[111111];
signed main(){
    
    cin>>n>>k;
    mod_fact(n,MOD);
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int maxmin=a[k-1],minmax=a[n-k];
    
    int sum[111111]={0},sum2[111111]={0};
    int b[111111],b2[111111];
    int maxsum=0,minsum=0;
    for(int i=k-1;i<n;i++){
    	b[i]=mod_nCr(i,k-1,MOD);//max
    	//DEB(b[i])END
    	//DEB(a[i])END
    	maxsum+=b[i]*a[i];
    	maxsum%=MOD;
    }
    int cnt=k-1;
    for(int i=n-k;i>=0;i--){
    	b2[i]=mod_nCr(cnt,k-1,MOD);//min
    	cnt++;
    	//DEB(b2[i])END
    	//DEB(a[i])END
    	minsum+=b2[i]*a[i];
    	minsum%=MOD;
    }
    
    /*int maxsum=0,minsum=0;
    for(int i=k-1;i<n;i++){
    	sum[i+1]=b[i]-sum[i];
    	sum[i+1]%=MOD;
    	DEB(sum[i+1])END
    	maxsum+=sum[i+1]*a[i];
    	maxsum%=MOD;
    }
    for(int i=n-k+1;i>0;i--){
    	sum2[i]=b2[i-1]-sum2[i-1];
    	sum2[i]%=MOD;
    	DEB(sum2[i])END
    	minsum+=sum2[i]*a[i-1];
    	minsum%=MOD;
    }
    /*
    int maxsum=0,minsum=0;
    repb(i,n){
    	maxsum+=sum[i+1]*a[i];
    	maxsum%=MOD;
    	
    }
    rep(i,n){
    	minsum+=sum2[i]*a[i-1];
    	minsum%=MOD;
    }*/
    cout<<(maxsum-minsum)%MOD<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	while (1)
	{
		int n = 0, p = 0; cin >> n >> p;
		if (n == 0 && p == 0) { return 0; }
		vector<int> man(n, 0);
		int stn = p, win = -1;
		while (1)
		{
			rep(i, n)
			{
				if (stn > 0)
				{
					man[i] += 1;
					stn -= 1;
				}
				else if (stn == 0)
				{
					stn = man[i];
					man[i] = 0;
				}
				if (*max_element(all(man)) == p)
				{
					win = i;
					break;
				}
			}
			if (win >= 0) { break; }
		}
		printf("%d\n", win);
	}
}

Measured memory_bytes: 1196
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x,i,j,c=0;x=n;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
//snippet


#define N 1009

void run() {
	LL x, k, d, f;
	in("%lld%lld%lld", &x, &k, &d);
	x = Ma(x, -x);
	f = mi(x / d, k);
	k -= f; x -= f * d;
	printf("%lld\n", k % 2 ? d - x : x);
}

int main() {
	int times = 1;
//	in("%d", &times);
	while (times--) {
		run();
	}
}

Measured memory_bytes: 1736
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

const int MAX = 21;
const int  INF = (1<<25);
const int DM = 4; //number of direction
const int MM = 16;//number that memory can be set


char M[MAX][MAX];
int T[DM][MM][MAX][MAX];
int R,C,gx,gy;
bool ans;

const int UP = 0;
const int RIGHT = 1;
const int DOWN = 2;
const int LEFT = 3;
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

void input(){
  cin >> R >> C;
  for(int i = 0; i < R; i++)
    for(int j = 0; j < C; j++){
      cin >> M[i][j];
      if(M[i][j] == '@'){
	gx = j;
	gy = i;
      }
    }
}

bool isInside(int x, int y){return 0<=x&&x<C&&0<=y&&y<R;}
    
void dfs(int dir, int mem, int y, int x){
  
  if(T[dir][mem][y][x]) return;
  T[dir][mem][y][x] = true;

  int nx,ny;

  if(x == -1 && y == -1){
    nx = 0;
    ny = 0;
  }else{
    nx = x+dx[dir];
    ny = y+dy[dir];
  }

  //  cout << "come " << mem  << " " << nx  << " " << ny  << M[ny][nx] << endl;
  //  if(!isInside(nx,ny)) return;
  if(nx >= C) nx = 0;
  if(nx < 0) nx = C-1;
  if(ny >= R) ny = 0;
  if(ny < 0) ny = R-1;
  
  if(M[ny][nx] == '<') dfs(LEFT,mem,ny,nx);
  if(M[ny][nx] == '>') dfs(RIGHT,mem,ny,nx);
  if(M[ny][nx] == '^') dfs(UP,mem,ny,nx);
  if(M[ny][nx] == 'v') dfs(DOWN,mem,ny,nx);
  if(M[ny][nx] == '_' && mem == 0) dfs(RIGHT,mem,ny,nx);
  if(M[ny][nx] == '_' && mem != 0) dfs(LEFT,mem,ny,nx);
  if(M[ny][nx] == '|' && mem == 0) dfs(DOWN,mem,ny,nx);
  if(M[ny][nx] == '|' && mem != 0) dfs(UP,mem,ny,nx);
  if(M[ny][nx] == '?') dfs(UP,mem,ny,nx),dfs(RIGHT,mem,ny,nx),dfs(DOWN,mem,ny,nx),dfs(LEFT,mem,ny,nx);
  if('0' <= M[ny][nx] && M[ny][nx] <= '9') dfs(dir,M[ny][nx]-'0',ny,nx);
  if(M[ny][nx] == '+') dfs(dir,(mem+1)%16,ny,nx);
  if(M[ny][nx] == '-') dfs(dir,(mem+15)%16,ny,nx);
  if(M[ny][nx] == '.') dfs(dir,mem,ny,nx);
  if(M[ny][nx] == '@'){
    ans = true;
    return;
  }
}

int main(){
  input();
  dfs(RIGHT,0,-1,-1);
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 2788
#define REP(i, n) for (int (i) = 0;(i)<(int)(n);(i)++)
#define rep(i, n) REP(i, n)
#define REPI(i, a, n) for(int i=int(a);i<int(b);i++)
#define repi(i, a, n) REPI(i, a, n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<#x<<" : "<<x<<endl
#define putn(x, n) cout<<fixed<<setprecision(n)<<x<<endl
#define PB push_back

typedef long long ll;

#include <bits/stdc++.h>

using namespace std;


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

    char a;
    int i=0;
    while(cin>>a){
        if(a=='+')i++;
        else i--;
    }
    cout << i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
    if(x>y)return x;
    else return y;
}
ll min(ll x,ll y){
    if(x<y)return x;
    else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    ll a,b,c,d;cin >> a >> b >> c >> d;
    cout << max({a*c,a*d,b*c,b*d}) << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
long long N, M;
int main() {
	scanf("%lld%lld", &N, &M);
	if (N == 1 || M == 1) {
		printf("%lld\n", 1);
	} else printf("%lld\n", (N / 2) * M + (N % 2) * ((M + 1) / 2));
}


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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];

		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		Arrays.sort(h);

		int ans = Integer.MAX_VALUE;

		for (int i = 0; i < n - k + 1; i++) {
			int tmpans = 0;
			tmpans = h[i + k - 1] - h[i];
			if (tmpans < ans) {
				ans = tmpans;
			}
		}

		System.out.println(ans);
		sc.close();
	}
}

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

int an = 0;
int n;

struct inf{
    int x, y;
};

void solve(vector<vector<inf> > &lis, int num, int f, vector<int> flag, int ans, vector<int> truth){
    if(f == 0){
        truth[num] = 0;
        if(flag[num] == 1){
            return;
        }
        for(int i = 0; i < lis[num].size(); i++){
            int a = lis[num][i].x - 1;
            if(lis[num][i].y == 1){
                if(flag[a] == 1){
                    return;
                }
                flag[a] = 0;
                if(truth[a] == 1){
                    return;
                }
            }else{
                if(flag[a] == 0){
                    return;
                }
                flag[a] = 1;
                if(truth[a] == 0){
                    return;
                }
            }
        }
        ans++;
    }else{
        truth[num] = 1;
        if(flag[num] == 0){
            return;
        }
    }
    if(num == n-1){
        an = max(ans, an);
        return;
    }
    num++;
    solve(lis, num, 0, flag, ans, truth);
    solve(lis, num, 1, flag, ans, truth);
}

int main(){
    cin >> n;
    vector<vector<inf> > lis(n);
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        for(int l = 0; l < a; l++){
            int x, y; cin >> x >> y;
            inf k = {x, y};
            lis[i].push_back(k);
        }
    }
    vector<int> flag(n, -1);
    vector<int> truth(n, -1);
    solve(lis, 0, 0, flag, 0, truth);
    solve(lis, 0, 1, flag, 0, truth);
    cout << an << endl;
}

Measured memory_bytes: 256