akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define SZ(x) ((int)(x).size()) 
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) 
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
const int N = 1e5 + 7;
const int LOGN = 20;
const int INF = 2e9 + 7;
int n;
int a[N];
int L, Q;
int nxt[LOGN][N];
void ini(){
    REP(i, 0, n){
        nxt[0][i] = upper_bound(a + i + 1, a + n, a[i] + L) - a - 1;
    }
    REP(i, 1, LOGN){
        REP(j, 0, n){
            nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
        }
    }
}
int query(int l, int r){
    int res = 1;
    FOR(i, 0, LOGN){
        if(nxt[i][l] < r){
            l = nxt[i][l];
            res += 1 << i;
        }
    }
    return res;
}
int main(){
#ifdef ac
	freopen("in.txt","r",stdin);
#endif
	//freopen("out.txt","w",stdout);
    scanf("%d", &n);
    REP(i, 0, n) scanf("%d", &a[i]);
    scanf("%d%d", &L, &Q);
    ini();
    while(Q --){
        int l, r;
        scanf("%d%d", &l, &r);
        if(l > r) swap(l, r);
        l --, r --;
        printf("%d\n", query(l, r));
    }
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back 
#define MOD 1e9+7
#define INF 0x3f3f3f3f
using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main()
{
long long a,b;
cin>>a>>b;
bool flag = false;

    for(ll j = 0; j<=a ;j++)
    {
        if((a-j)*4+j*2==b)
        {
            flag = true;
            break;
        }    
    }

if(flag)
cout<<"Yes\n";
else
cout<<"No\n";
}


Measured memory_bytes: 3632
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM	20000000
using namespace std;
int main(void)
{
	int n,m,i,j;
	int np[50001],d[20];
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)	scanf("%d",&d[i]);
	for(i=0;i<=n;i++)	np[i]=MM;
	np[0]=0;
	for(i=0;i<m;i++)	{
		for(j=0;j<=n;j++)	{
			if(j+d[i]>n)	break;
			if(np[j]!=MM)	{
				np[j+d[i]]=min(np[j+d[i]],np[j]+1);
			}
		}
	}
	printf("%d\n",np[n]);
	return 0;
}


Measured memory_bytes: 1220
import bisect
def adj(x,ks):
  idx=bisect.bisect_left(ks,x)
  return ks[idx-1],ks[idx]

def distance(x,a,b):
  return min(abs(x-a),abs(x-b))+abs(a-b)

def helper(x,ss,ts):
  temp1,temp2=adj(x,ts)
  shin1,shin2=adj(x,ss)
  t=min(distance(x,temp1,shin1),distance(x,temp2,shin1),distance(x,temp1,shin2),distance(x,temp2,shin2))
  return t

a,b,q=map(int,input().split())
t=10**20
ss=[-t]+[int(input()) for _ in range(a)]+[t]
ts=[-t]+[int(input()) for _ in range(b)]+[t]
qs=[int(input()) for _ in range(q)]
for x in qs:
  print(helper(x,ss,ts))

Measured memory_bytes: 17296
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

dup = lambda x,y: ((x)+(y)-1)//(y)

def solve():
  s = ni()
  v = 10**9
  
  y = dup(s, v)
  x = y*v-s
  
  print(0, 0, v, 1, x, y)


solve()

Measured memory_bytes: 3060
#include<iostream>

void print_list(std::string* a, int n){
  for(int i = 0; i < n - 1; i++){
    std::cout << a[i] << " ";
  }
  std::cout << a[n - 1] << std::endl;
}


void bubbleSort(std::string* a, int n){
  bool sorted = false;
  while(!sorted){
    sorted = true;
    for(int i = n - 1; i > 0; i--){
      if(a[i][1] < a[i - 1][1]){
	std::string t = a[i]; a[i] = a[i - 1]; a[i - 1] = t;
	sorted = false;
      }
    }
  }
}

void selectionSort(std::string* a, int n){
  for(int i = 0; i < n - 1; i++){
    int minj = i;
    for(int j = i; j < n; j++){
      if(a[j][1] < a[minj][1]){
	minj = j;
      }
      
    }
    if(i != minj){
      std::string t = a[i]; a[i] = a[minj]; a[minj] = t;
    }
  }
}

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

  std::string *a = new std::string[n];
  for(int i = 0; i < n; i++){
    std::cin >> a[i];
  }
  
  std::string *bubble = new std::string[n];
  std::string *select = new std::string[n];
  for(int i = 0; i < n; i++){
    bubble[i] = select[i] = a[i];
  }

  bubbleSort(bubble, n);
  print_list(bubble, n);
  std::cout << "Stable" << std::endl;
  
  selectionSort(select, n);
  print_list(select, n);

  bool eq = true;
  for(int i = 0; i < n; i++){
    if(bubble[i] != select[i]){
      eq = false;
      break;
    }
  }
  if(eq){
    std::cout << "Stable" << std::endl;
  }else{
    std::cout << "Not stable" << std::endl;
  }

 
  return 0;
}



Measured memory_bytes: 3184
import sys
from heapq import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    hp = []
    for a, b in ab:
        heappush(hp, [-a - b, a, b])
    ans = 0
    turn = 1
    while hp:
        mx, a, b = heappop(hp)
        if turn:
            ans += a
        else:
            ans -= b
        turn = 1 - turn
    print(ans)

main()


Measured memory_bytes: 37876
import sys
from collections import Counter
n = int(input())
MOD = 10**9 + 7
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
_sum = 0
res = 1
flg = (n + 1) % 2
if flg == 0:
    res = 0 if ct.get(0) != 1 else 1
for i in range(1, max(a_ls) + 1):
    if flg == i % 2:
        if ct.get(i) == 2:
            res = res * 2 % MOD
        else:
            res = 0
            break
    else:
        if ct.get(i) is None:
            continue
        else:
            res = 0
            break
    if res == 0:
        break
print(res)

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s,t;cin>>s>>t;
    int idx = -1;
    for(int i=0;i+t.size()-1<s.size();i++){
        bool is_res = true;
        for(int j=0;j<t.size();j++){
            if(s[i+j] != t[j] && s[i+j] != '?'){
                is_res = false;
                break;
            }
        }
        if(is_res)idx = i;
    }
    if(idx == -1) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    else{
        for(int i=idx;i<idx+t.size();i++)s[i]=t[i-idx];
    }
    rep(i,s.size())if(s[i] == '?')s[i] = 'a';
    out(s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

struct Node{
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(k < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(k < y->key) y->left = z;
    else y->right = z;
  }
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}

void preorder(Node *u){
  if(u == NIL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n; cin >> n;
  rep(i, n){
    string com; cin >> com;
    if(com[0] == 'i'){
      int k; cin >> k;
      insert(k);
    }
    else if(com[0] == 'p'){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }

  return 0;
}




Measured memory_bytes: 26592
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int a, b, c, m, s, t = 0;
  scanf("%d %d %d", &a, &b, &c);
  m = max(a, max(b, c));
  s = a + b + c;
  if(3*m % 2 != s % 2) ++m;
  t = (3*m-s)/2;
  printf("%d\n", t);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char ch[100];
    char ch1[100];

    int i, count=0, z, a;

    scanf("%s", ch);
    scanf("%s", ch1);

    for(i=0; i<strlen(ch); i++)
    {
        if(ch[i] == ch1[i])
        {
            count++;
        }
    }


    if(count == strlen(ch))
    {
        printf("Yes");
    }

    else
    {
        printf("No");
    }


    return 0;
}







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

main(){
    int n,x,d,D,i;
    cin >> n >> x;
    int l[n];
    for(i=0;i<n;i++) cin >> l[i];
    d=0;
    for(i=1;i<n+1;i++){
        D=d+l[i-1];
        d=D;
        if(D>x) break;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105, INF = 1000000000;

int N, M, dp[MAXN][MAXN];
char denah[MAXN][MAXN];

int f(int r, int c) {
    if (r == N-1 && c == M-1) return denah[r][c] == '.' ? 0 : 1;
    int &ret = dp[r][c];
    if (ret == -1) {
        ret = INF;
        if (r < N-1) {
            if (denah[r][c] == '#' && denah[r+1][c] == '.') ret = min(ret, f(r+1, c) + 1);
            else  ret = min(ret, f(r+1, c));
        }
        if (c < M-1) {
            if (denah[r][c] == '#' && denah[r][c+1] == '.') ret = min(ret, f(r, c+1) + 1);
            else ret = min(ret, f(r, c+1));
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> denah[i];
    }
    
    memset(dp, -1, sizeof(dp));
    cout << f(0, 0) << "\n";
}


Measured memory_bytes: 384
n,m = map(int,input().split())
A = list(map(int,input().split()))
P = [list(map(int,input().split())) for i in range(m)]
for i in range(n):
  P += [[1,A[i]]]
P = sorted(P,key=lambda x: x[1],reverse=True)
ans = 0
count = 0
for i in range(m+n):
  if count+P[i][0]<=n:
    count += P[i][0]
    ans += P[i][0]*P[i][1]
  else:
    ans += P[i][1]*(n-count)
    break
print(ans)

Measured memory_bytes: 45000
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

struct UF{
  int n;
  vector<ll> p,r,s;
  UF(){}
  UF(int sz):n(sz),r(sz,1),p(sz,0),s(sz,1){iota(p.begin(),p.end(),0);}
  int find(int x){
    if(p[x]==x)return x;
    else return p[x]=find(p[x]);
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(r[x]<r[y]){
	 p[x]=y;
	 s[y]+=s[x];
    }
    else {
      p[y]=x;
	 s[x]+=s[y];
      if(r[x]==r[y])r[x]++;
    }
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  ll siz(int x){
    x=find(x);
    return s[x];
  }
};

int main(){
  ll n,m;
  cin>>n>>m;
  vector<int> a(m),b(m);
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    a[i]--,b[i]--;
  }
  reverse(all(a));
  reverse(all(b));

  UF uf(n);
  ll ans=n*(n-1)/2;
  vector<ll> q(m+1);
  q[m]=ans;
  for(int i=0;i<m;i++){
    if(uf.same(a[i],b[i])){
	 q[m-1-i]=ans;
	 continue;
    }
    
    ll x=uf.siz(a[i]);
    ll y=uf.siz(b[i]);
        
    if(x>1)ans+=x*(x-1)/2;
    if(y>1)ans+=y*(y-1)/2;

    uf.unite(a[i],b[i]);
    ll k=uf.siz(a[i]);
    ans-=k*(k-1)/2;
    q[m-1-i]=ans;
  }

  for(int i=1;i<=m;i++)cout<<q[i]<<endl;
  
  return 0;
}


Measured memory_bytes: 5248
N, K = map(int, input().split())
X = list(map(int, input().split()))

x = X[:] + [0]
for _ in range(K):
    if all(v == N for v in x[:-1]):
        break

    new = [0] * (N + 1)
    for i in range(N):
        new[max(0, i - x[i])] += 1
        new[min(N, i + x[i] + 1)] -= 1

    for i in range(N):
        new[i + 1] += new[i]
    x = new[:]

print(*x[:-1])


Measured memory_bytes: 221104
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]




def change(iter, org):
    return sum([org[i-1] for i in iter])

def main():
    n, m = LI()
    cs = []
    a_s = []
    b_s = []
    org = [2**i for i in range(n)]
    for i in range(m):
        a, b = LI()
        a_s.append(a)
        b_s.append(b)
        cs.append(change(LI(), org))

    mem = [[INF for i in range(2**n)] for i in range(m)]

    mem[0][0] = 0
    mem[0][cs[0]] = a_s[0]

    for i in range(1, m):
        mem[i][0] = 0
        for j in range(2**n):
            mem[i][j] = mem[i-1][j]
        for j in range(2**n):
            if mem[i-1][j] != INF:
                # print("MWM", i, j | cs[i], j, cs[i])

                mem[i][j | cs[i]] = min(a_s[i] + mem[i-1][j], mem[i][j | cs[i]])
                # print("NAN", a_s[i] + mem[i-1][j], mem[i-1][j | cs[i]], mem[i-1][j], a_s[i], mem[i][j | cs[i]])
        # print(mem[i][15])
    # print(mem)
    print(mem[-1][-1] if mem[-1][-1] != INF else "-1")



if __name__ == '__main__':
    main()

Measured memory_bytes: 77020
use strict;
use warnings;
package SuffixArray;
sub sa_is(\@$);
sub sa_is(\@$){
	my@s=@{$_[0]};
	my$upper=$_[1];
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
#	elsif($n==2){
#		if($s[0]<$s[1]){
#			return(0,1);
#		}
#		else{
#			return(1,0);
#		}
#	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l=(0)x($upper+1);
	my@sum_s=(0)x($upper+1);
	$ls[$_]?$sum_l[$s[$_]+1]++:$sum_s[$s[$_]]++for 0..$n-1;
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(@sa){
			$sa[$buf[$s[$_-1]]++]=$_-1if$_>=1&&!$ls[$_-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms_map=(-1)x($n+1);
	my$m=0;
	my@lms;
	for(1..$n-1){
		if(!$ls[$_-1]&&$ls[$_]){
			$lms_map[$_]=$m++;
			push@lms,$_;
		}
	}
	@sa=$induce->(@lms);
	if($m>0){
		my@sorted_lms=grep$lms_map[$_]!=-1,@sa;
		my@rec_s;
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms_map[$l]+1<$m?$lms[$lms_map[$l]+1]:$n;
			my$end_r=$lms_map[$r]+1<$m?$lms[$lms_map[$r]+1]:$n;
			my$same=1;
			if($end_l-$l!=$end_r-$r){
				$same=0;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$same=0if$l==$n||$s[$l]!=$s[$r];
			}
			$rec_upper++if!$same;
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper;
		}
		my@rec_sa=sa_is(@rec_s,$rec_upper);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array(\$){
	my@s=map ord,split"",${$_[0]};
	return sa_is(@s,255);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array(\$\@){
	my@s=map ord,split"",${$_[0]};
	return lcp(@s,@{$_[1]});
}
package main;
my$s=<>;
chomp$s;
my@sa=SuffixArray::suffix_array($s);
my@lcp=LcpArray::lcp_array($s,@sa);
my$ans=@sa*(@sa+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


Measured memory_bytes: 252080
#include <iostream>

#define ll long long

using namespace std;

ll gcd(ll x, ll y) {
 ll r;
 
 while(y != 0) {
  r = x % y;
  x = y;
  y = r;
 }

 return x;
}

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

int main() {
 ll a, b;

 while(cin >> a >> b) {
  cout << gcd(a, b) << " " << lcm(a, b) << endl;
 }

 return 0;
}


Measured memory_bytes: 3084
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long K = sc.nextLong();
        sc.close();
        
        if(K <= A) {
        	System.out.println(K);
        }else if(K <= A + B) {
        	System.out.println(A);
        }else {
        	System.out.println(A-(K - A - B));
        }

 

        
        }
	}



Measured memory_bytes: 35744
#include<stdio.h>
int keta(int n)
{
  int sum=0;
  while(0<n){
  	sum=sum+n%10;
    n=n/10;
  }
  return sum;
}
int main()
{
  int n,a,b;
  int i=0,wa=0,sum=0;
  scanf("%d %d %d",&n,&a,&b);
  for(i=n;0<i;i--){
    wa=keta(i);
  	if(a<=wa && wa<=b){
      sum=sum+i;
    }
   // printf("%d\n",keta(i));
  }
  printf("%d\n",sum);
  return 0;
}


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

using namespace std;


int main()
{ 
    int h,w;
    cin>>h>>w;
    char grid[25][25];
    
    vector<pair<int,int>> dir = {{-1,0},{1,0},{0,1},{0,-1}};
    for(int i = 0;i<h;i++)
    {
        for(int j = 0;j<w;j++)
        {
            cin>>grid[i][j];
        }
    }

    int ans = 0;

    for(int i = 0;i<h;i++)
    {
        for(int j = 0;j<w;j++)
        {
            if(grid[i][j] == '.')
            {
               vector<vector<bool>> seen(h,vector<bool>(w));
               vector<vector<int>> dist(h,vector<int>(w));
               dist[i][j] = 0;
               queue<pair<int,int>> temp;
               temp.push({i,j});

               while(!temp.empty())
             {
            pair<int,int> p = temp.front();
            temp.pop();
            int x = p.first;
            int y = p.second;
            if(seen[x][y])
            {
                continue;
            }

            seen[x][y] = true;
            ans = max(ans,dist[x][y]);
            
            for(pair<int,int> pp:dir)
            {
                int m = pp.first + x;
                int n = pp.second + y;
                if(m >= 0 && m < h && n >= 0 && n < w && grid[m][n] == '.')
                {
                    dist[m][n] = 1 + dist[x][y];
                    temp.push({m,n});
                }
            }
           }
         }
        }
    }

    cout<<ans;
    

    return 0;
}

Measured memory_bytes: 3628
import scala.io.StdIn.{readInt,readLine}

object Main {
  def play(a:Int,b:Int,i:Int):(Int,Int) = {
    if(i==0) (a,b)
    else {
      val l = readLine.split(" ").map(_.toInt);val x = l(0);val y = l(1)
      if(x>y) play(a+x+y,b,i-1)
      else if(x<y) play(a,b+x+y,i-1)
      else play(a+x,b+y,i-1)
    }
  }

  def main(args:Array[String]) = {
    var n = 0
    while( { n = readInt; n } > 0 ) {
      val (a,b) = play(0,0,n)
      println(a + " " + b)
    }
  }
}

Measured memory_bytes: 55412
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
using namespace std;

int H,W,K; char c[7][7]; 
void input()
{
    cin>>H>>W>>K;
    for(int i=1;i<=H;++i){
        for(int j=1;j<=W;++j){
            cin>>c[i][j];
        }
    }
}

void solve()
{
    int ans=0;
    bitset<6> brow(0),bcol(0);
    for(int i=0;i<(1<<H);++i){
        for(int j=0;j<(1<<W);++j){
            brow=0|i;
            bcol=0|j;

            // cout<<brow<<" "<<bcol<<"\n";

            int black=0;
            for(int x=1;x<=H;++x){
                for(int y=1;y<=W;++y){
                    if(brow[x-1]==0 && bcol[y-1]==0 && c[x][y]=='#') black++;
                }
            }
            if(black==K) ++ans;
            // cout<<"black: "<<black<<endl;
        }
    }
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(26,50);
    for(int i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;
        vector<int> ta(26);
        for(int j = 0; j < tmp.size(); j++) {
            ta[tmp[j]-'a']++;
        }
        for(int k = 0; k < 26; k++) {
            a[k]=min(a[k],ta[k]);
        }
    }
    string ans={};
    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < a[i]; j++) {
            ans+=(char)('a'+i);
        }
        //cout << (char)('a'+i) << " " << a[i] << "\n";
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <bitset>
#include <cmath>
#include <set>
#include <map>
#include <iostream>

using namespace std;
 
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define dow(i, l, r) for(int i=l; i>=r; i--)
#define clr(x, c) memset(x, c, sizeof(x))
#define travel(x) for(edge *p=fir[x]; p; p=p->n)
#define travel0(x) for(edge *p=fir0[x]; p; p=p->n)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define l(x) Left[x]
#define r(x) Right[x]
#define lowbit(x) (x&-x)
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,int> Pli;
typedef pair<double,int> Pdi;
typedef long double ld;
typedef unsigned long long ull;
 
inline int read()
{
	int x=0, f=0; char ch=getchar();
	while (ch<'0' || '9'<ch) f|=ch=='-', ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar();
	return f?-x:x;
}

#define maxn 100009

int n, a[maxn], b[maxn], c[maxn], d[maxn], s[maxn];
Pdi q[maxn];

inline ll Right(double x)
{
	ll now=0;
	rep(i, 1, n) q[i]=Pdi((1.0*c[i]-x*a[i])/b[i],i), s[i]=0;
	sort(q+1, q+1+n);
	rep(i, 1, n)
	{
		now+=i-1;
		for(int o=d[q[i].se]; o; o-=lowbit(o)) now-=s[o];
		for(int o=d[q[i].se]; o<=n; o+=lowbit(o)) s[o]++;
	}
	return now;
}

inline double Cal()
{
	ll G=1LL*n*(n-1)/2/2;
	double l=-1e9, r=1e9;
	rep(i, 1, 150) if (Right((l+r)/2)>G) l=(l+r)/2; else r=(l+r)/2;
	return (l+r)/2;
}

int main()
{
	n=read();
	rep(i, 1, n) a[i]=read(), b[i]=read(), c[i]=read();
	rep(i, 1, n) q[i]=Pdi(-1.0*a[i]/b[i],i);
	sort(q+1, q+1+n);
	rep(i, 1, n) d[q[i].se]=i;
	printf("%.12lf ", Cal());
	
	rep(i, 1, n) swap(a[i], b[i]);
	rep(i, 1, n) q[i]=Pdi(-1.0*a[i]/b[i],i);
	sort(q+1, q+1+n);
	rep(i, 1, n) d[q[i].se]=i;
	printf("%.12lf\n", Cal());
	return 0;
}

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

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) (container).begin(), (container).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int main() {
  int N, K;
  cin >> N >> K;

  if (K == 1) {
    cout << 0 << endl;
  } else {
    cout << N-K << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long A, long long B, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> x, std::vector<long long> y, std::vector<long long> c){
  ll ans=*min_element(a.begin(),a.end())+*min_element(b.begin(),b.end());
  REP(M){
    ans=min(ans,a[x[i]]+b[y[i]]-c[i]);
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(A);
    for(int i = 0 ; i < A ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(B);
    for(int i = 0 ; i < B ; i++){
        scanf("%lld",&b[i]);
    }
    std::vector<long long> x(M);
    std::vector<long long> y(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&c[i]);
        --x[i];--y[i];
    }
    solve(A, B, M, std::move(a), std::move(b), std::move(x), std::move(y), std::move(c));
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    auto mx = max_element(a.begin(), a.end()), mn = min_element(a.begin(), a.end());

    if(*mx < 0){
        cout << n - 1 <<endl;
        for(int i = 0; i < n - 1; ++i){
            cout << n - i << " " << n - i - 1 << endl;
        }
    }
    else if(*mn > 0){
        cout << n - 1 << endl;
        for(int i = 0; i < n - 1; ++i){
            cout << i + 1 << ' ' << i + 2 << endl;
        }
    }
    else if(abs(*mn) > abs(*mx)){
        cout << 2 * n - 1 << endl;
        for(int i = 0; i < n; ++i){
            cout << mn - a.begin() + 1 << ' ' << i + 1 << endl;
        }
        for(int i = 0; i < n - 1; ++i){
            cout << n - i << " " << n - i - 1 << endl;
        }
    }
    else{
        cout << 2 * n - 1 << endl;
        for(int i = 0; i < n; ++i){
            cout << mx - a.begin() + 1 << ' ' << i + 1 << endl;
        }
        for(int i = 0; i < n - 1; ++i){
            cout << i + 1 << " " << i + 2 << endl;
        }
    }
}


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

int main(){
    string s; cin >> s;

    for(int i = 0; i < 2; ++i){
        int sum = 1;
        for(int j = i+1; j < s.size(); ++j){
            if(s[i] == s[j]) sum++;
            else break;
        }
        if(sum >= 3){
            cout << "Yes\n";
            break;
        }else if(i == 1){
            cout << "No\n";
        }
    }

    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
#define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
#define sortV(v) sort(v.begin(),v.end())
#define revV(v) reverse(v.begin(),v.end())
#define FOR(i,n) for(int i=0;i<n;i++)
    
    ll a,b,c,d,e,f,g,n,m,k,t,p,x,h,w,q;
    ll curr = 1;
    ll mod = 998244353;


    void solve(){
      cin >> n;
      ll m = n;
      n--;
      ll ans = 0;
      for(ll i=1; i <= sqrt(n); i++){
          if(n % i ==0 ){
              ans++;
              if(n / i != i){
                 ans++;
              }
          }
      }
      for(ll i=2; i <= sqrt(m); i++){
          ll x = m;
          if(m % i == 0 ){
             while( x % i == 0){
                 x /= i;
             } 
             if(x == 1 || x % i == 1){
                 ans++;
             }
          }
      }
      cout << ans;
    }
  
   
    int main(){
    ios_base::sync_with_stdio(false);
    
    int cases = 1;
    //cin >> cases;
  
    while(cases--){ 
        solve();
    }

    return 0;

    }

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

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

int main(){
    int a, b, GCD;
    while(std::cin >> a >> b){
        if(a < b)
            std::swap(a, b);
        GCD = getGCD(a, b);
        std::cout << GCD << " " << (a/GCD) * b <<std::endl;
    }
}

Measured memory_bytes: 1156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ACatsAndDogs {
public:
	void solve(istream& in, ostream& out) {
        int a,b,x;
        in >> a >> b >> x;
        if(a > x || a + b < x) out << "NO" << endl;
        else out << "YES" << endl;
	}
};

int main() {
	ACatsAndDogs solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

int main() {
    int n, x;
    int M[100];
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> M[i];
    }

    int ans;
    int sum = 0;
    sort(M, M + n);
    for (int i = 0; i < n; i++) {
        sum += M[i];
    }
    ans = n + (x - sum) / M[0];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
class p
{
  static void Main()
  {
    string[] ipt = Console.ReadLine().Split(' ');
    for (int i = 0; i < 5; i++) {
      int x = int.Parse(ipt[i]);
      if (x == 0) {
        Console.WriteLine(i + 1);
        return;
      }
    }
  }
}

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

const int N = 200010;
const int offset = 2010;
const int md = 1e9 + 7;

int n;
int a[N], b[N];
vector<int> _get[offset + offset];
int f[offset + offset][offset + offset];
int upd[offset + offset][offset + offset];
int ans;
int fact[N], inv[N];

void add(int &x, int y) { x += y; x %= md; if(x < 0) x += md; }

int pw(int a, int b) {
	int res = 1;
	for(int i = 0; (1LL << i) <= b; ++i) {
		if (b & (1LL << i)) res = 1LL * res * a % md;
		a = 1LL * a * a % md;
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i], &b[i]);
		_get[a[i] + offset].push_back(b[i] + offset);
		upd[-a[i] + offset][-b[i] + offset]++;
	}

	for(int x = 0; x < offset + offset; ++x) {
		for(int y = 0; y < offset + offset; ++y) {
			if(x > 0) add(f[x][y], f[x - 1][y]);
			if(y > 0) add(f[x][y], f[x][y - 1]);
			if(upd[x][y]) add(f[x][y], upd[x][y]); 
		}
		for (int y : _get[x]) add(ans, f[x][y]);
	}

	fact[0] = 1; for(int i = 1; i < N; ++i) fact[i] = 1LL * fact[i-1] * i % md;
	for(int i = 0; i < N; ++i) inv[i] = pw(fact[i], md - 2);

	for(int i = 1; i <= n; ++i) {
		int A = a[i] * 2, B = b[i] * 2;
		add(ans, md - (1LL * fact[A + B] * (1LL * inv[A] * inv[B] % md) % md));
	}
	ans = 1LL * ans * pw(2, md - 2) % md;

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

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

int main() {
    double N;
    int X;
    cin >> N;
    X = N;
    if(X % 2 == 0){
    N = (N/2)/N;
    }
    else{
        N = ((N+1)/2)/N;
    }
    cout << fixed << setprecision(20);
    cout << N << endl;
}

Measured memory_bytes: 256
import itertools, math
stdin= open(0).read().split('\n')
N = int(stdin[0])
x, y = [0]*N, [0]*N
for i in range(1,N+1):
    x[i-1], y[i-1] = map(int,stdin[i].split())
num = 0
sum = 0
for p in itertools.permutations(range(N), N):
    num += 1
    for j in range(N-1):
        sum += math.sqrt((x[p[j]]-x[p[j+1]])**2 + (y[p[j]]-y[p[j+1]])**2)
print(sum/num)

Measured memory_bytes: 3188
s=gets.chomp
z=s.size
(z-1).times do |i|
  if s[i]==s[i+1]
    puts [i+1,i+2].join(" ")
    exit
  end
end
(z-2).times do |i|
  if s[i]==s[i+2]
    puts [i+1,i+3].join(" ")
    exit
  end
end
puts "-1 -1"


Measured memory_bytes: 14672
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    a.sort()
    p = a[-1]
    k = 0
    min_cur = INF

    for i in range(n-1):
        temp = abs(a[i] - (p/2))
        if temp < min_cur:
            min_cur = temp
            k = a[i]

    print(p, k)





if __name__ == '__main__':
    main()

Measured memory_bytes: 58864
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n;
  cin>>n;
  vector<vector<vector<double>>> dp(n+1, vector<vector<double>>(n+1, vector<double>(n+1, 0)));
  for(auto&& i:irange(0,n+1)) {
    for(auto&& j:irange(0,n+1)) {
      for(auto&& k:irange(0,n+1)) {
        if (i+j+k > n) break;
        if (!(i||j||k)) continue;
        double sum = n;
        if (i) sum += i * dp[i-1][j+1][k];
        if (j) sum += j * dp[i][j-1][k+1];
        if (k) sum += k * dp[i][j][k-1];
        dp[i][j][k] = sum / (i+j+k);
      }
    }
  }
  vecint cnt(4, 0);
  for(auto&& i:irange(0,n)) {
    int a;
    cin>>a;
    ++cnt[a];
  }
  cout<<fixed<<setprecision(10)<<dp[cnt[3]][cnt[2]][cnt[1]]<<endl;
  return 0;
}


Measured memory_bytes: 216832
import java.util.*;
class Main{
  public static void main(String[] a){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int l = Integer.parseInt(sc.next());
    String[] stringArray = new String[n];
    
    for(int i=0; i<n; i++)stringArray[i] = sc.next();
    
    Arrays.sort(stringArray);
    for(int i=0;i<n;i++)System.out.print(stringArray[i]);
  }
  
  private static String[] merge(String[] sArray){
    if(sArray.length == 1){
      return sArray;
    }else{
      String[] array1 = new String[sArray.length/2];
      String[] array2 = new String[sArray.length-sArray.length/2];
      for(int i=0; i<array1.length; i++){
        array1[i] = sArray[i];
      }
      for(int i=0; i<array2.length; i++){
        array2[i] = sArray[array1.length+i];
      }
      array1 = merge(array1);
      array2 = merge(array2);
      int i1 = 0;
      int i2 = 0;
      while(true){
        if(judge(array1[i1], array2[i2])){
          sArray[i1+i2] = array1[i1];
          i1++;
          if(i1 == array1.length){
            for(int j=0; j<sArray.length-i1-i2; j++){
              sArray[i1+i2+j] = array2[i2+j];
            }
            break;
          }
        }else{
          sArray[i1+i2] = array2[i2];
          i2++;
          if(i2 == array2.length){
            for(int j=0; j<sArray.length-i1-i2; j++){
              sArray[i1+i2+j] = array1[i1+j];
            }
            break;
          }
        }
      }
      return sArray;
    }
  }
  
  private static boolean judge(String s1, String s2){
    byte[] byte1 = s1.getBytes();
    byte[] byte2 = s2.getBytes();
    for(int i=0; i<byte1.length; i++){
      if((int)byte1[i] < (int)byte2[i]){
        return true;
      }else if((int)byte1[i] > (int)byte2[i]){
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n,k;
int h[100101];
int dp[100101];

void input(){
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> h[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    for (int i = 0; i < 100010; ++i) dp[i] = INF;
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            chmin(dp[i+j], dp[i] + abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

int main(void)
{
	int i, num,  *p;

	scanf("%d" , &num);
	
    p = malloc(sizeof(int)*num);
	
	for(i=0; i<num; i++){
		scanf("%d" , p);
		p++;
	}
	for(i=0; i<num-1; i++){
		p--;
		printf( "%d ", *p);
	}
	p--;
	printf( "%d\r\n", *p);
			
	return 0;	 
}

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

int ans;
int pre = 10001;
int tp = 10002;

signed main () {

    int n;
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
        int a;
        scanf("%d", &a);
        if ( pre == a ) {
            ans++;
            pre = tp;
            tp++;
        }
        else pre = a;
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <forward_list>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// sanitize: shift + f11
// debug: shift + f9

void A() {
    ll N;
    cin >> N;

    R1(3) {
        ll nd = N-(floor(N/10)*10);
        if(nd == 7) {
            cout << "Yes" << endl;
            return;
        }
        N/=10;
    }

    cout << "No" << endl;
}

void B() {
    ll N;
    cin >> N;

    ll sum = 0;
    R1(N+1) {
        if((i%3 == 0) || (i%5 == 0))
            continue;
        sum+=(i);
    }

    cout << sum << endl;
}

int main()
{
    B();
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <queue>
using namespace  std;

const int nIMPOS = -1;
struct StDist
{
  int m_nDist;
  int m_nDmy;

  StDist(int nDist) : m_nDist(nDist), m_nDmy(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StDist oDist(nIMPOS);
  rvoDist.resize(nxSiz + 1, oDist);
}

void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, 
                          queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();

    for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
    {
      if (!cnrvvnAdjcy[nx][ny])          continue;
      if (rvoDist[ny].m_nDist != nIMPOS) continue; 

      int nDist = rvoDist[nx].m_nDist + 1;
      rvoDist[ny].m_nDist = nDist;
      rqnBFSrch.push(ny);
    }
  }
}

void fnResult(const vector<StDist>& cnrvoDist)
{
  for (int i = 1; i < cnrvoDist.size(); ++i)
    cout << i <<  " " << cnrvoDist[i].m_nDist << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  queue<int>  qnBFSrch;
  vector<StDist> voDist;

  fnInput(vvnAdjcy, voDist);

  voDist[1].m_nDist = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
  fnResult(voDist);

  return 0;
}

Measured memory_bytes: 3168
#include <iostream>
using namespace std;
int main(){
	int N;
	cin>>N;
	bool ok = false;
	for(int i=0; i<=N/7; i++){
		for(int j=0; j<=N/4; j++){
			if(i*7+4*j==N) ok = true;
		}
	}
	if(ok){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
A=0
try:
    while True:
        d=str(input())
        a=list(d)
        b=len(a)
        
        if b==1:
            A+=1
            
        else:
            if b%2==0:
                c=b//2
                L=d[:c]
                e= ''.join(list(reversed(d)))
                M=e[:c]
                if L==M:
                    A+=1
            
            if b%2==1:
                c=b//2
                L=d[:c+1]
                e= ''.join(list(reversed(d)))
                M=e[:c+1]
                if L==M:
                    A+=1
                
except EOFError:
    print(A)


Measured memory_bytes: 5568
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define endl "\n"
#define loop(i,s,e) for(int i=s;i<e;i++)
#define int long long
#define mp make_pair
#define pii pair<int,int>
#define mset(a,f)  memset(a , f , sizeof(a))
#define pb push_back
const int N = 2e6 + 6;
const int inf = 1e18;
const int M = 1e9 + 7;
int A[N];
int n;

void solve()
{
      int k;
      cin >> k;

      int s = 0;

      loop(i,1,k+1)
      {
            loop(j,1,k+1)
            {
                  int x = __gcd(i,j);

                  loop(l,1,k+1)
                  {
                        s += __gcd(l,x);
                  }
            }
      }

      cout << s;
}
 
int32_t main()
{
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);

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


Measured memory_bytes: 3652
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;

int main() {
	speed;
	int n, m;
	cin >> n >> m;
	vector<int>x(m);
	rep(i, m)
	{
		cin >> x[i];
	}
	sort(All(x));
	vector<int>len(m);
	rep(i, m - 1) {
		len[i] = x[i + 1] - x[i];
	}
	sort(All(len));
	int sum = 0;
	rep(i, n - 1) {
		len.pop_back();
	}
	rep(i, len.size()) {
		sum += len[i];
	}
	c(sum);
	return 0; 
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
#define rep(i, c) for(int i=0; i<(int)c; i++)
int main() {
	int n;
	cin >>n;

	string ans ="No";
	if (n%10==7){
		ans="Yes";
	}
	if ((n/10)%10==7){
		ans="Yes";
	}
	if ((n/100)%10==7){
		ans="Yes";
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  
 int A,B,C,D;
  
  cin >> A >> B >> C >> D;
 if(A+B>C+D)
   cout << "Left" << endl;
  else if(A+B<C+D)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}
  

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	
	a := make(map[int]int)
	
	tmp := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		a[tmp]++
	}
	if len(a) <= k {
		fmt.Println(0)
		return
	}
	
	cnt := make([]int, len(a))
	idx := 0
	for _,v := range a {
		cnt[idx] = v
		idx++
	}
	sort.Ints(cnt)

	ans := 0
	for i := 0; i < len(a) - k; i++ {
		ans += cnt[i]
	}
	fmt.Println(ans)

}

Measured memory_bytes: 15024
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();

        if(Objects.equals(u, s))
            a-=1;
        else if(Objects.equals(u, t))
            b-=1;

        System.out.print(a + " " + b);
    }
}


Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <algorithm>
#include <bitset>

using namespace std;

int main() {
	long long a, b;
	cin >> a >> b;
	bitset<32> A(a), B(b);

	cout << (A&B) << endl;
	cout << (A|B) << endl;
	cout << (A^B) << endl;
}


Measured memory_bytes: 3124
N = int(input())
s = input()
i = 1
li = []
charas = 'abcdefghijklmnopqrstuvwxyz'
while i < N:
  m = 0
  s1 = s[0:i]
  s2 = s[i:]
  for chara in charas:
    if chara in s1 and chara in s2:
      m += 1
  li.append(m)
  i += 1
print(max(li))

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <set>

using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    s.insert(v);
  }
  int dmin = 1000;
  int ans = -1;
  for (int i = 0; i <= 101; i++) {
    auto it = s.find(i);
    if (it == s.end()) {
      int d = abs(i - x);
      if (d < dmin) {
        dmin = d;
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main()
{
	int a, b;

	scanf("%d%d", &a, &b);

	if (a > 0 && b > 0)
		printf("Positive\n");
	else if (a < 0 && b < 0)
	{
		if ((a + b) % 2 == 0)
			printf("Negative\n");
		else
			printf("Positive\n");
	}
	else
		printf("Zero\n");

	return 0;
}

Measured memory_bytes: 128