akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX = 1e5 + 100, oo = 1ll << 40;
int v[MX], C[MX * 3];
int change(int v) { return v + MX + 10; }
int check(int m, int n) {
	int ans = 0, s = 0;
	memset(C, 0, sizeof(C));
	C[change(0)] = 1;
	int sum = 1;
	for(int i = 0; i < n; i ++) {
		if(v[i] >= m) s ++, sum += C[change(s)];
		else sum -= C[change(s)], s --;
		ans += sum;
		C[change(s)] ++;
		sum ++;
	}
	return ans;
}
main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n; i ++) cin >> v[i];
	if(n == 1) return cout << v[0], 0;
	int l = 0, r = 1e9 + 10;
	while(l != r) {
		int m = l + r >> 1;
		if(check(m, n) * 2 < n * (n + 1) / 2) r = m;
		else l = m + 1;
	}
	cout << l - 1;
}

Measured memory_bytes: 3456
import sys
x, y = map(int,input().split())
n = list(map(int, input().split()))
if y == 0:
    print(x)
    sys.exit()
for i in range(100):
    a = [x-i, x+i]
    if set(a)<=set(n):
        pass
    elif x-i not in n:
        print(x-i)
        sys.exit()
    else:
        print(x+i)
        sys.exit()
                    

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

int main(void){
    string  s;
    cin >> s;
    int x,y;
    x = stoi(s)/100;
    y = stoi(s)-x*100;

    int ans = 0;
    if (x<13&&x>0){
        ans++;
    }
    if (y<13&&y>0){
        ans += 2;
    }
    if(ans == 1){
        cout << "MMYY" << endl;
    }else if(ans == 2){
        cout << "YYMM" << endl;
    }else if(ans == 3){
        cout << "AMBIGUOUS" << endl;
    }else{
        cout << "NA" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d,p;
    cin>>a>>b>>c>>d>>p;
    int my=b+(p-c)*d,m=a*p;
    if(p<=c){
        my=b;
    }
    if(my<m){
        m=my;
    }
    cout<<m<<endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int H, W;
vector<string> S;

ll white_cnt(vector<string> s) {
  ll res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '.') {
        res++;
      }
    }
  }
  return res;
}

ll bfs(int s, int t) {
  vector<vector<ll>> d(H, vector<ll>(W, -1));
  d[s][t] = 0;
  queue<P> q;
  q.push(P(s, t));
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    ll x = p.first, y = p.second;
    for (int i = 0; i < 4; i++) {
      ll nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || H <= nx || ny < 0 || W <= ny) {
        continue;
      }
      if (d[nx][ny] == -1 && S[nx][ny] == '.') {
        d[nx][ny] = d[x][y] + 1;
        q.push(P(nx, ny));
      }
    }
  }
  return d[H - 1][W - 1];
}

void abc088d() {
  ll res = bfs(0, 0);
  if (res == -1) {
    cout << "-1\n";
  } else {
    cout << white_cnt(S) - (res + 1) << "\n";
  }
  return;
}

int main() {
  cin >> H >> W;
  S.resize(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  abc088d();
  return 0;
}

Measured memory_bytes: 256
#2019/09/30
std_input = open(0).readlines()
N, T = map(int, std_input[0].split())
s_t = [list(map(int, i.rstrip("\n").split())) for i in std_input[1:1+N]]

cnt = 0
s_t_T = []
for i in s_t:
    if i[1] > T:
        cnt += 1
    else:
        s_t_T.append(i[0])

if cnt == N:
    print("TLE")
else:
    print(min(s_t_T))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;

const int INF = 1000000010;
const ll MOD = 1000000007;

int main() {FIN
	
	int i, j, m, c;
	string s, t;
	cin >> s;
	cin >> t;
	m = t.size();
	for (i = 0; i < (int)(s.size()-t.size()+1); i++) {
		c = 0;
		for (j = 0; j < (int)t.size(); j++) {
			if (t[j] != s[i+j]) c++;
		}
		m = min(c, m);
	}
	cout << m << "\n";
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<set>
#define ll long long
#define rep(i,a) for (int i=0;i<a;i++)
#define nrep(i,n,a) for (int i=n;i<a;i++)
#define INF 1145141919
#define max(vec) *std::max_element(vec.begin(),vec.end())
#define min(vec) *std::max_element(vec.begin(),vec.end())
#define in(n) cin>>n
#define out(n) cout<<n<<endl
#define P pair<ll,ll>

using namespace std;

int main() {
	ll H,W,N,a, b;
	in(H); in(W); in(N);
	set< P > vec,point;
	rep(i, N){
		in(a);
		in(b);
		point.insert(P(a, b));
		rep(ii, 3) rep(jj, 3) if (a - 2 + ii > 0 && b - 2 + jj > 0 && a + ii <= H && b + jj <= W) vec.insert(P(ii + a - 2, jj + b - 2));
	}
	vector<ll> sum(10, 0);
	ll count;
	ll max = (H - 2)*(W - 2);
	ll one = 0;
	for (auto &ite : vec) {
		count = 0;
		rep(i, 3) rep(j, 3) count += point.count(P(ite.first + i, ite.second + j));
		if (count > 0) one++;
		sum[count]++;
	}out(max - one);
	nrep(i, 1, 10) out(sum[i]);
	return 0;
}

Measured memory_bytes: 62720
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(' ')
    val bb = b.split(".")
    val bbb = bb[0].toInt() * 100 + if (bb.size > 1) bb[1].toInt() else 0
    val ab = a.toLong() * bbb
    println(ab/100)
}


Measured memory_bytes: 35640
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans=1
    for i in range(1,N+1):
        ans = ans%(10**9+7) * i%(10**9+7)
        
    print(ans%(10**9+7))

if __name__ == '__main__':
    main()

Measured memory_bytes: 39700
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int H, W, A, B; cin >> H >> W >> A >> B;
    int X = H / A;
    int Y = W / B;
    cout << H * W - (X * Y * A * B) << endl;
    return 0;
}



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

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

using namespace std;

//v.push_back(123);
//sort(v.begin(), v.end(),greater<int>());
//for(int x : v) {cout << x << endl;}

//for(int x: v) cout << x << endl;
//vector<vector<char>> v(H, vector<char>(W));
//vector<int> v(1000);

signed main(){
  int N;
  cin>>N;
  int a[N-1], b[N-1];
  int c[N];
  int score = 0;
  int count[N];
  int output[N];
  rep(i, N) count[i]=0;
  rep(i, N-1) cin >> a[i] >> b[i];
  rep(i, N) cin >> c[i];
  sort(c, c+N);
  reverse(c, c+N);
  //rep(i, N) cout << c[i] << endl;
  rep(i, N-1){
    score += c[i+1];
  } 
  
  int flag[N];
  rep(i, N){
    flag[i]=0;
    output[i]=0;
  }
  int v_index = 0;
  rep(j, N){
    rep(i, N-1){
      if(v_index==N) break;
      if(j==0 && i==0){
        //cout << v_index << endl;
        flag[a[i]-1]=1;
        flag[b[i]-1]=1;
        output[a[i]-1]=c[v_index];
        //cout << c[v_index] << endl;
        v_index++;
        output[b[i]-1]=c[v_index];
       // cout << c[v_index] << endl;
        v_index++;
      }

      if(flag[a[i]-1]==1){
        if(flag[b[i]-1]==0){
          flag[b[i]-1]=1;
          output[b[i]-1]=c[v_index];
          v_index++;
        }
      }
      if(flag[b[i]-1]==1){
        if(flag[a[i]-1]==0){
          flag[a[i]-1]=1;
          output[a[i]-1]=c[v_index];
          v_index++;
        }
      }
      
    }
  }

  //cout << v_index << endl;
  cout << score << endl;

  rep(i, N){
    if(i==N-1){
      cout << output[i] << endl;
    }else{
      cout << output[i] << ' ';
    }
  }

  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
using namespace std;

int main() {
  int n;
  int j;
  scanf("%d", &n);
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == n) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  double a, b, x;
  cin >> a >> b >> x;

  double ans;
  if(a * a * b <= 2 * x){
    double y = (-2 * x) / (a * a) + 2 * b;
    ans = atan(y / a) * (180.0 / M_PI);
  } else {
    double y = (2 * x) / (a * b);
    ans = atan(b / y) * (180.0 / M_PI);
  }

  printf("%.6lf\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll inf=10000000000000000; 
ll a,b,c,x,y;
int main(){
   cin>>a>>b>>c>>x>>y;
    c*=2;
    ll sum;
    ll ab=max(x,y)*c;
    ll AB=inf;
    if(x>y){
         AB=(x-y)*a+c*y;
    }
    else if(y>x){
         AB=(y-x)*b+c*x;
    }
 sum=min(min(x*a+y*b,ab),AB);
 cout<<sum<<endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL X;

LL A,B;

void solve(){
	for(LL i=-3981;i<=3981;i++){
		for(LL j=-3981;j<=3981;j++){
			if(i*i*i*i*i - j*j*j*j*j == X){
				A = i;
				B = j;
				return;
			}
		}
	}
}
 
int main(){
    cin >> X;

    solve();

	cout << A << " " << B << endl;
    return 0;
}

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

int s=-1,n,t;

int main(){
    scanf("%d%d",&n,&t);
    while(n--){
        int a,b;
        scanf("%d%d",&a,&b);
        if(b<=t&&(s==-1||a<s))s=a;
    }
    if(s==-1)printf("TLE");else printf("%d",s);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, R, G);
  print((G - R) * 2 + R);
}


Measured memory_bytes: 256
#def test(l):
#    n = len(l)
#    c = 0
#    while max(l) >= n:
#        l.sort()
#        l[-1] -= n
#        for i in range(n-1):
#            l[i] += 1
#        c += 1
#    return c

def main():
    K = int(input())
    if K <= 49:
        print(50)
        l = [0] * (50 - K) + [50] * K
        print(' '.join(str(i) for i in l))
        return l
    l = [(K // 50) + 50] * 50
    a = 50 - K % 50
    for i in range(a):
        l[0] -= 50
        for j in range(1, 50):
            l[j] += 1
        l.sort(reverse=True)
    print(50)
    print(' '.join(str(i) for i in l))
    return l
l = main()
#print('kotae', test(l))


Measured memory_bytes: 3064
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	var ans int

	length := len(s) - 1
	for i := 0; i < 1<<uint(length); i++ {
		now := string(s[0])
		for j := 0; j < length; j++ {
			if i>>uint(j)&1 == 1 {
				now += "+"
			}
			now += string(s[j+1])
		}

		for _, val := range strings.Split(now, "+") {
			t, _ := strconv.Atoi(val)
			ans += t
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static final int MAX_RAW = 6;
	static final int MAX_LINE = 5;
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		while((input = br.readLine()) != null){
			System.out.println(encode(input));
		}
	}

	public static String encode(String input){
		if(input.length() % 2 != 0)	return "NA";
		
		try{
			StringBuffer sbuf = new StringBuffer();
			for(int i = 0; i < input.length(); i += 2){
				int raw = Integer.parseInt(input.substring(i, i + 1));
				int line = Integer.parseInt(input.substring(i + 1, i + 2));
				if(raw < 1 || raw > MAX_RAW|| line > MAX_LINE || line < 1)	return "NA";
				
				//数字を文字に変換
				int c = 'a' + (raw - 1) * 5 + line - 1;
				if(c == 'z' + 1)	c = '.';
				else if(c == 'z' + 2)	c = '?';
				else if(c == 'z' + 3)	c = '!';
				else if(c == 'z' + 4)	c = ' ';
				sbuf.append((char)c);
			}
			return sbuf.toString();
		}catch(NumberFormatException e){
			return "NA";
		}
	}
}

Measured memory_bytes: 16908
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define TARO 0
#define HANAKO 1
int main()
{
  int n,c;
  int i;
  int field;
  bool pass;
  vector<int>hand[2],card;
  vector<int>::iterator it;
  while(cin>>n,n){
    hand[TARO].clear();
    hand[HANAKO].clear();
    card.resize(2*n);
    fill(card.begin(),card.end(),HANAKO);
    for(i=0;i<n;i++){
      cin>>c;
      card[c-1]=TARO;
    }
    for(i=0;i<card.size();i++)hand[card[i]==TARO?TARO:HANAKO].push_back(i+1);

    field=0;
    while(1){
      pass=true;
      for(it=hand[TARO].begin();it!=hand[TARO].end();it++){
	if(*it<field)continue;
	field=*it;
	hand[TARO].erase(it);
	pass=false;
	break;
      }
      if(!hand[TARO].size())break;
      if(pass)field=0;

      pass=true;
      for(it=hand[HANAKO].begin();it!=hand[HANAKO].end();it++){
	if(*it<field)continue;
	field=*it;
	hand[HANAKO].erase(it);
	pass=false;
	break;
      }
      if(!hand[HANAKO].size())break;
      if(pass)field=0;
    }

    cout<<hand[HANAKO].size()<<endl<<hand[TARO].size()<<endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) {
        ld _a;
        cin >> _a;
        a[i] = _a * 1e9 + 0.1;
    }
    map<pll, ll> mp;    // pll:2^i*5^j
    ll ans = 0;
    rep(i, n) {
        ll d2 = 0, d5 = 0;
        while(a[i] % 2 == 0) ++d2, a[i] /= 2;
        while(a[i] % 5 == 0) ++d5, a[i] /= 5;
        d2 -= 9, d5 -= 9;
        if(d2 > 9) d2 = 9;
        if(d5 > 9) d5 = 9;
        for(int j = -d2; j <= 9; ++j) {
            for(int k = -d5; k <= 9; ++k) {
                ans += mp[make_pair(j, k)];
            }
        }
        ++mp[make_pair(d2, d5)];
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    int x;
    cin>>x;
    for (int a = -5000; a < 5000; a++) {
        for (int b = -5000; b < 5000; b++) {
            if (a * a * a * a * a - b * b * b * b * b == x) {
                cout<<a<<' '<<b<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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() {
  cout << fixed << setprecision(10);
  int d;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin>>c[i];
  vector<vector<int>> s(d,vector<int>(26));
  rep(i,d){
    rep(j,26)cin>>s[i][j];
  }
  vector<int> t(d);
  rep(i,d)cin>>t[i];
  ll ans = 0;
  vector<int> last(26,0);
  rep(i,d){
    ans+=s[i][t[i]-1];
    last[t[i]-1]=i+1;
    rep(j,26){
      ans-=c[j]*(i+1-last[j]);
    }
    cout << ans << endl;
  }

}


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

char S[1005];
char T[1005];

int main(){
	cin>>S>>T;

	int ans=1005;
	int len1=strlen(S);
	int len2=strlen(T);	
	
	for(int i=0; i<=len1-len2; i++){
		int cnt=0;
		for(int j=0; j<len2; j++){
			if(T[j]!=S[i+j]) cnt++;
		}
		ans=min(ans, cnt);
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[100005];
ll arr[100005];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        memo[i]=1e18;
    }
    
    memo[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                memo[i]=min(memo[i],memo[i-j]+abs(arr[i]-arr[i-j]));
            }
            else
            {
                break;
            }
        }
    }
    
    printf("%lld\n",memo[n-1]);
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;


//---------------------------------------------------------------
template<int MOD> struct ModInt { int x;
    explicit operator bool() const { return !!x; }
    ModInt(int v = 0) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt(long long v) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt &operator+=(const ModInt &r) { if ((x += r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt &r) { if ((x += MOD - r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(const ModInt &r) { x = 1LL * x * r.x % MOD; return *this; }
    ModInt &operator/=(const ModInt &r) { return *this *= r.inv(); }
    ModInt operator-() const { return x ? ModInt(MOD - x) : ModInt(x); }
    ModInt operator+(const ModInt &r) const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt &r) const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt &r) const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt &r) const { return ModInt(*this) /= r; }
    ModInt inv() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u); } // x.pow(MOD-2)
    ModInt pow(long long k) const { ModInt r(1), a(x);
        while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
    bool operator==(const ModInt r) const { return x == r.x; }
    bool operator!=(const ModInt r) const { return x != r.x; }
    bool operator< (const ModInt r) const { return x <  r.x; }
    friend ostream& operator<<(ostream &os, const ModInt<MOD>& a) { return os << a.x; }
    friend istream& operator>>(istream &is, ModInt<MOD>& a) { return is >> a.x; }
};
template<typename T, int SZ> struct Comb { vector<T> _fac, _ifac, _inv;
    Comb() : _fac(SZ + 1), _ifac(SZ + 1), _inv(SZ + 1) {
        _fac[0] = _ifac[SZ] = _inv[0] = 1;
        for (int i = 1; i <= SZ; i++) _fac[i] = _fac[i - 1] * i;
        _ifac[SZ] /= _fac[SZ];
        for (int i = SZ - 1; i >= 0; i--) _ifac[i] = _ifac[i + 1] * (i + 1);
        for (int i = 1; i <= SZ; i++) _inv[i] = _ifac[i] * _fac[i - 1]; }
    T inv(int n) { return n < 0 ? T(0) : _inv[n]; }
    T fac(int n) { return n < 0 ? T(0) : _fac[n]; }
    T ifac(int n) { return n < 0 ? T(0) : _ifac[n]; }
    T P(int a, int b) { return (b < 0 || a < b) ? T(0) : _fac[a] * _ifac[a - b]; }
    T C(int a, int b) { return b < 0 ? T(0) : P(a, b) * _ifac[b]; }
    T H(int n, int k) { if (n < 0 || k < 0) return T(0);
        return k == 0 ? T(0) : C(n + k - 1, k); }
};
typedef ModInt<MOD> mint;
//---------------------------------------------------------------


int main() {
    Comb<mint, 250000> com;
    int n, k; cin >> n >> k;
    cout << com.P(k, n) << endl;
    return 0;
}


Measured memory_bytes: 5568
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbg=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int n,a[300111];
ll w1[300111],w2[300111];
set<pair<ll,int> > st;
ll sum=0;
int main()
{
	geti(n);
	for(int i=1;i<=3*n;i++)geti(a[i]);
	for(int i=1;i<=n;i++)
	{
		st.insert(MP(a[i],i));
		sum+=a[i];
	}
	w1[n]=sum;
	for(int i=n+1;i<=2*n;i++)
	{
		st.insert(MP(a[i],i));
		sum+=a[i];
		sum-=st.begin()->FF;
		st.erase(st.begin());
		w1[i]=sum;
	}
	st.clear();
	sum=0;
	for(int i=2*n+1;i<=3*n;i++)
	{
		st.insert(MP(-a[i],i));
		sum+=a[i];
	}
	w2[2*n]=sum;
	for(int i=2*n;i>n;i--)
	{
		st.insert(MP(-a[i],i));
		sum+=a[i];
		sum-=-st.begin()->FF;
		st.erase(st.begin());
		w2[i-1]=sum;
	}
	ll mx=w1[n]-w2[n];
	for(int i=n;i<=2*n;i++)
	{
		mx=max(mx,w1[i]-w2[i]);
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 10496
while True:
    (n, r) = [int(x) for x in input().split()]
    if n==0 and r==0:
        exit()
    cards = [n-i for i in range(n)]
    for _ in range(r):
        (p, c) = [int(x) for x in input().split()]
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
    print(cards[0])

Measured memory_bytes: 6724
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main(){
	int N, K, A[200001] = { 0 }, x;
	cin >> N >> K;
	REP(i, N) {
		cin >> x;
		if (A[x] == 0){
			A[0]++;
		}
		A[x]++;
	}

	int ans = 0, k;
	if (A[0] > K){
		sort(A + 1, A + 200001);
		FOR(i, 1, 200001) {
			if (A[i] != 0){
				k = i;
				break;
			}
		}
		REP(i, A[0] - K) {
			ans += A[k + i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f first
//#define s second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define loop(i,n) for(int i=0; i<(n); i++)
#define loop3(i,a,n) for(int i=a; i<(n); i++)

int main()
{
    fast
  string s,t;
  cin>>s>>t;
  ll n=s.size(),m=t.size();
 // vector<vector<pair<ll,string>>>dp(n+1,vector<pair<ll,string>>(m+1,{0,""}));
   int dp[n+1][m+1];
   memset(dp,0,sizeof(dp));

 for(ll i=1; i<=n; i++)
  {
      for(ll j=1; j<=m; j++)
      {
          if(s[i-1]==t[j-1])
          {
              dp[i][j]=dp[i-1][j-1]+1;
          }
          else
          {
                 dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          }
      }
  }
  int i=n,j=m;
  string k="";
  while(i>0 && j>0)
  {
      if(dp[i][j]==dp[i-1][j]) i--;
      else if(dp[i][j]==dp[i][j-1]) j--;
      else
      {
          k+=s[i-1];
          i--;
          j--;
      }
  }
  reverse(k.begin(),k.end());
  cout<<k<<endl;
}


Measured memory_bytes: 38832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x<=599) cout<<8<<endl;
    else if(x<=799) cout<<7<<endl;
    else if(x<=999) cout<<6<<endl;
    else if(x<=1199) cout<<5<<endl;
    else if(x<=1399) cout<<4<<endl;
    else if(x<=1599) cout<<3<<endl;
    else if(x<=1799) cout<<2<<endl;
    else if(x<=1999) cout<<1<<endl;    
    return 0;
}

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

N,M = [int(i) for i in input().split()]
L_max = 0
R_min = 10**9
for _ in range(M):
    L,R = [int(i) for i in input().split()]
    L_max = max(L_max,L)
    R_min = min(R_min,R)

if R_min-L_max+1 > 0:
    print(R_min-L_max+1)
else:
    print(0)


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

int q;
string s;

void solve(int a,int b,int c,int d,char AA,char BB)
{
	int n=a+b,k;
	k=n/(b+1);
	int l=0,r=a/k+1,mid;
	while (r-l>1)
		{
			mid=(l+r)>>1;
			((k*mid+(b-mid)/k<=a)?l:r)=mid;
		}
	int x=l,y=(b-x)/k;
	a-=k*x+y;
	for (int i=c; i<=d; i++)
		if (i<=x*(k+1))  s+=(i%(k+1)?AA:BB);
		else  if (n-i+1<=y*(k+1))  s+=((n-i+1)%(k+1)?BB:AA);
		else  s+=(i<=x*(k+1)+a?AA:BB);
}

void work()
{
	scanf("%d",&q);
	for (int a,b,c,d; q--; )
		{
			scanf("%d %d %d %d",&a,&b,&c,&d),s="";
			if (a>b)
				{
					solve(a,b,c,d,'A','B');					
				}else  if (a<b)
				{
					solve(b,a,(a+b+1)-d,(a+b+1)-c,'B','A');
					reverse(s.begin(),s.end());
				}else
				{
					for (int i=c; i<=d; i++)
						s+=(i&1?'A':'B');
				}
			cout<<s<<endl;
		}
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 384
/*input
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
*/

// Nihesh Anderson - knandy

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

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 500005;

ll n, q;
ll last[MX], bit[MX];
vector<ll> a;
vector<pair<ll, ll> > queries;
map<pair<ll, ll>, ll> ans;

void update(ll idx, ll val) {
	idx++;
	while(idx <= n) {
		bit[idx] += val;
		idx += (idx) & (-idx);
	}
}

ll query(ll idx) {
	ll ans = 0;
	idx++;
	while(idx > 0) {
		ans += bit[idx];
		idx -= (idx) & (-idx);
	}
	return ans;
}

ll getsum(ll l, ll r) {
	return query(r) - query(l - 1);
}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	cin >> n >> q;
	a.resize(n);
	memset(last, -1, sizeof(last));
	for(ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(ll i = 0; i < q; i++) {
		ll l, r; cin >> l >> r;
		--l; --r;
		queries.push_back({l, r});
	}
	vector<pair<ll, ll> > p = queries;
	sort(p.begin(), p.end(), [&](pair<ll, ll> x, pair<ll, ll> y) -> bool {
		return x.second < y.second;
	});
	ll it = 0;
	for(auto val: p) {
		while(it < n && it <= val.second) {
			if(last[a[it]] == -1) {
				update(it, 1);
			}
			else {
				update(last[a[it]], -1);
				update(it, 1);
			}
			last[a[it]] = it;
			it++;
		}
		ans[{val.first, val.second}] = getsum(val.first, val.second);
	}
	for(auto val: queries) {
		cout << ans[val] << endl;
	}
	return 0;
}




















Measured memory_bytes: 62488
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<climits>
#include<string.h>
using namespace std;

int main(){
    int m,n1,n2;
    while(cin>>m>>n1>>n2,m){
        int p[202];
        vector<pair<int,int> >v;
        for(int i=1;i<=m;i++){
            cin>>p[i];
            if(i-1>=n1&&i-1<=n2){
                v.push_back(make_pair(p[i-1]-p[i],i-1));
            }
        }
        sort(v.begin(),v.end());
        cout<<v[v.size()-1].second<<endl;
    }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K, L = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    
    if (x <= K - x) L += x * 2;
    else L += 2 * (K - x);
  }
  
  cout << L << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int a,b; cin >> a >> b;
	int ans = 0;
	for(int i=a;i<=b;i++) {
		int s = i % 10, t = i / 10000 % 10;
		int u = i / 10 % 10, v = i / 1000 % 10;
		if(s==t&&u==v) ans++;
	}
	cout << ans << endl;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

#define MAX_V 100
#define INF INT_MAX

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a){
        cout<<"delicious"<<endl;
    }else if(a+x>=b){
                cout<<"safe"<<endl;
    }else{
        cout<<"dangerous"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
	int N;
	cin >> N;
	string s;
	cin >> s;
	int sum=1;
	for (int i=1; i<N; i++) {
		if (s[i]!=s[i-1]) {
			sum++;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    int ans = Long.toString(n).length();

    for (long i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        ans = Math.min(Long.toString(n / i).length(), ans);
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Optional;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            Map<String, Integer> map = new TreeMap<>();

            {
                int n = in.nextInt();
                for (int i = 0; i < n; i++) {
                    String s = in.nextString();
                    map.merge(s, 1, Integer::sum);
                }
            }

            {
                int n = in.nextInt();
                for (int i = 0; i < n; i++) {
                    String s = in.nextString();
                    map.merge(s, -1, Integer::sum);
                }
            }

            out.println(Math.max(0, map.values().stream().max(Integer::compareTo).get()));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 28372
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int r = sc.nextInt();
      int g = sc.nextInt();
      int b = sc.nextInt();
      int n = 100*r+10*g+b;
      if(n%4==0)System.out.println("YES");
      else System.out.println("NO");
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <vector>
//#include <bits/stdc++.h>
#define ll long long
#define wtcl return
#define PI acos(-1)
#define maxn 1e18
#define debug(a) cout<<" ++ "<<a<<" ++ "<<endl;
using namespace std;
const ll mod = 1e9+7;
inline ll read()
{
	ll s = 0, f = 1;
	char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
	return s * f ;
}
inline void out(ll x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) out(x/10);
	putchar(x%10+'0');
}
ll num[1000005];
int main()
{
	std::ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	priority_queue<ll>q;
	for(int i=0;i<n;i++)
	{
		cin>>num[i];
		q.push(num[i]);
	}
	while(m)
	{
		ll p = q.top();
		q.pop();
		p = p/2;
		m--;
		q.push(p);	
	}
	ll ans = 0;
	while(!q.empty())
	{
		ans += q.top();
		q.pop();
	}
	cout<<ans<<endl;
	wtcl 0;
}


Measured memory_bytes: 1912
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7

N = i()
S = s()
a = 'S'
b = 'W'
kouho = [[a,a],[a,b],[b,a],[b,b]]
for a,b in kouho:
    S1 = [a,b]
    for i in range(1,N):
        if S[i] == 'o':
            if S1[i] == 'S':
                if S1[i-1] == 'S':
                    S1.append('S')
                else:
                    S1.append('W')
            else:
                if S1[i-1] == 'S':
                    S1.append('W')
                else:
                    S1.append('S')
        else:
            if S1[i] == 'S':
                if S1[i-1] == 'S':
                    S1.append('W')
                else:
                    S1.append('S')
            else:
                if S1[i-1] == 'S':
                    S1.append('S')
                else:
                    S1.append('W')
    if S1[-1] != a:
        continue
    S1 = S1[:N]
    if a == 'S' and b == 'S':
        if S[0] == 'o':
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
    elif a == 'S' and b == 'W':
        if S[0] == 'o':
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
    elif a == 'W' and b == 'S':
        if S[0] == 'o':
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
    else:
        if S[0] == 'o':
            if S1[-1] == 'S':
                print(''.join(S1))
                exit()
        else:
            if S1[-1] == 'W':
                print(''.join(S1))
                exit()
print(-1)


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int a,b;
  cin>>a>>b;
  int ans=a-2*b;
  if(ans<=0){
    cout<<0<<endl;
  }else{
    cout<<ans<<endl;
  }
}
///////////////////////////

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var R, G, B, N int
	fmt.Scan(&R, &G, &B, &N)
	// R * x + G * y + B * z = N
	ans := 0
	for x := 0; x <= N; x++ {
		for y := 0; y <= N; y++ {
			t := N - R*x - G*y
			if t >= 0 && t%B == 0 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	int r; cin >> r;
	cout << 3 * r * r << endl;
}
int main() {
	solve();
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b);
#define mins(a,b) a=min(a,b);

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

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

    n=(n-1)/2;

    cout<<n<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int a,b,k;
  bool bb=false;
  cin>>k>>a>>b;
  for(int i=a;i<b+1;i++){
    if(i%k==0){
      bb=true;
      break;
    }
  }
  if(bb==true)cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
  return 0;
}

Measured memory_bytes: 3632
import math

N,K = (int(i) for i in input().split())
roots = []
hoge = K
result = 0

while hoge != 1:
    roots.append(hoge)
    hoge = math.ceil(hoge/2)

roots.append(1)

for i in range(len(roots)):
    if N >= roots[i]:
        result += (N - roots[i] + 1) / 2 ** i
        onon = i
        break

while onon < len(roots) - 1:
    result += (roots[onon] - roots [onon + 1]) / 2 ** (onon + 1)
    onon += 1

result = result / N
print(result)

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

using namespace std;

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

int main(){
    int d, n, ans = 1;
    cin >> d >> n;

    for(int i = 0; i < d; i++)
    {
        ans *= 100;
    }



    if (n < 100) {
        cout << n * ans << endl;
    }
    else
    {
        cout << (n+1) * ans << endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dat[101010], rh[2][101010], rui[101010], d10[101010];
ll get(ll x, int num)
{
	ll beg = 0, end = 10100000000LL;
	for (;;)
	{
		if (beg == end)break;
		ll med = (beg + end + 1) / 2;
		int s1 = lower_bound(d10, d10 + num, x * 10 - 1 - med) - d10;
		int s2 = upper_bound(d10, d10 + num, med + x * 10 - 1) - d10 - 1;
		if (s2 - s1 + 1 <= num - s2 - 1)beg = med;
		else end = med - 1;
	}
	int s1 = lower_bound(d10, d10 + num, x * 10 - 1 - beg) - d10;
	int s2 = upper_bound(d10, d10 + num, beg + x * 10 - 1) - d10 - 1;
	//printf("%lld   %d %d\n", beg, s1, s2);
	ll ans = rui[num] - rui[s2 + 1];
	if (num % 2 == 0)ans += rh[1][(((s1 - 1) % 2 == 1) ? (s1 - 1) : (s1 - 2)) + 2];
	else ans += rh[0][(((s1 - 1) % 2 == 0) ? (s1 - 1) : (s1 - 2)) + 2];
	return ans;
}
int main()
{
	int num, query;
	scanf("%d%d", &num, &query);
	for (int i = 0; i < num; i++)scanf("%lld", &dat[i]);
	for (int i = 0; i < num; i++)
	{
		if (i % 2 == 0)rh[0][i + 2] = rh[0][i] + dat[i];
		else rh[1][i + 2] = rh[1][i] + dat[i];
		rui[i + 1] = rui[i] + dat[i];
		d10[i] = dat[i] * 10;
	}
	for (int p = 0; p < query; p++)
	{
		ll z;
		scanf("%lld", &z);
		printf("%lld\n", get(z, num));
	}
}

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

int main() {
	long K, A, B;
	unsigned long cookie = 1;
	cin >> K >> A >> B;
	if (B-A <= 1 || K == 1) {
		cookie += K;
	} else {
		for (; K > 0;) {
			if (cookie >= A)
				break;
			cookie++;
			K--;
		}
		for (long i = K; i > 0; i--) {
			if (i <= 1) {
				cookie++;
			} else {
				i--;
				cookie -= A;
				cookie += B;
			}
		}
	}
	cout << cookie << endl;

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int n = readNum();
		int[] ia = readNums();
		int[] ary = new int[n+2];
		for (int i=0; i<n; i++) {
			ary[i+1] = ia[i];
		}
		int ans = 0;
		for (int i=1; i<=n+1; i++) {
			ans += abs(ary[i] - ary[i-1]);
		}
		for (int i=1; i<=n; i++) {
			int ao = abs(ary[i] - ary[i-1]) + abs(ary[i+1] - ary[i]);
			int an = abs(ary[i+1] - ary[i-1]);
			pln(ans - ao + an);
		}
	}

	int abs(int a) {
		return (a >= 0) ? a : -a;
	}
	
	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 41904