akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

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

    int ans;

    if (k % 2 == 0){
        ans = k * k / 4;
    }else{
        k = k / 2;
        ans = k * (k + 1);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import copy
n = int(input())
a = list(map(int,input().split()))

sa = copy.copy(a)
sa.sort()
L = sa[n//2 -1]
R = sa[n//2]
for i in a:
    if i <=L:
        print(sa[n//2])
    elif i>=R:
        print(sa[n//2 - 1])

Measured memory_bytes: 27156
#include <iostream>
#include <string>
#include <set>
using namespace std;
int n, ans, a[201010];
set<int> s;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    s.insert(a[0]);
    for (int i = 1; i <= n; i++)
    {
        auto it = s.find(a[i]);
        if (it != s.end())
        {
            cout << "NO" << endl;
            return 0;
        }
         s.insert(a[i]);
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 10368
n=int(input())
bar=list(map(int,input().split()))
hev=sum(bar)
hev_sum=[bar[0]]*n 
for i in range(1,len(bar)):
    hev_sum[i]=hev_sum[i-1]+bar[i]
if (hev/2) in hev_sum:
    print(0)
else:
    for i in range(0,len(bar)-1):
        if hev_sum[i]<(hev/2) and hev_sum[i+1]>(hev/2) :
            ans=i
    first=hev_sum[ans]
    second=hev-first-bar[ans+1]
    ab=abs(first-second)
    print(bar[ans+1]-ab)

Measured memory_bytes: 26220
from collections import defaultdict
import sys
input = sys.stdin.readline


n, m = map(int, input().split())
if m == 0:
    print('Yes')
    exit()
edges = defaultdict(list)

for i in range(m):
    left, right, dist = map(int, input().split())
    edges[left-1].append((right-1, dist))
    edges[right-1].append((left-1, -dist))

seen = [None] * n
for node in range(n):
    if seen[node] is not None:
        continue

    seen[node] = 0
    todo = []
    while edges[node]:
        to, dis = edges[node].pop()
        seen[to] = dis
        todo.append([to, dis])

    while todo:
        new, dis = todo.pop()

        while edges[new]:
            to, n_dis = edges[new].pop()
            if seen[to] is None:
                seen[to] = dis + n_dis
            elif seen[to] != dis + n_dis:
                print('No')
                exit()
            todo.append([to, dis + n_dis])

print('Yes')


Measured memory_bytes: 79764
#include<stdio.h>
int main()
{
    int i,j,k,a;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            a=0;
            for(k=1;k<=i;k++)
                a+=j;
            printf("%dx%d=%d\n",i,j,a);
        }
    }
    return 0;
}

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



int main(){
	
	int m;
	cin>>m;
	for(;m;m--){
		int p,y,n;
		cin>>p>>y>>n;
		int ans=0;
		for(;n;n--){
			int ri,cost;
			double ritu;
			cin>>ri>>ritu>>cost;
			int bunbo=8192,bunsi=ritu/0.0001220703125;
			 
			
			int money=p;
			if(ri){//複利
				for(int i=0;i<y;i++){
					long long A=money;
					long long B=A;
					B*=bunsi;
					B/=bunbo;
					A+=(B-cost);
					money=A;
				}
			}else{//単利
				long long B=0;
				long long A=money;
				for(int i=0;i<y;i++){
					B+=(A*bunsi/bunbo);
					A-=cost;
				}
				A+=B;
				money=A;
			}
			ans=max(ans,money);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


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

using namespace std;
int freq[15];
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    freq[a]++;
    freq[b]++;
    freq[c]++;
    if(freq[5] == 2 && freq[7] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

using ll = long long;

int main() {
    int N;
    cin >> N;
    ll res = -1;
    while(N--) {
        ll T;
        cin >> T;
        if(res == -1) {
            res = T;
            continue;
        }
        ll g = __gcd(res, T);
        res /= g;
        res *= T;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
using namespace std;
long long f[100];
int main()
{
    int n;
    scanf("%d",&n);
    f[0]=2;
    f[1]=1;
    for(int i=2; i<=n; i++)
        f[i]=f[i-1]+f[i-2];
    printf("%lld",f[n]);    
    return 0;
}

Measured memory_bytes: 128
t[3600];w,h,c,z;f(x,i){for(t[x]=0;i;t[x+=";;x>x:="[--i]-60]&&f(x,8));}main(i){for(;scanf("%d%d",&w,&h)*h;printf("%d\n",c)){for(i=++h;c=--i;)for(z=w;z;)scanf("%d",i*60+z--+t);for(;!i?i=w,--h:1;)t[z=h*60+i--]&&++c-f(z,8);}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=pair<ll,ll>;
const ll MOD=1e9+7;
const int MAX=1e5+1;
const ll INF=(1ll<<62)-1;
signed main(){
    int N,L,Q; cin>>N;
    vi Point(N);
    rep(i,0,N) cin>>Point[i];
    vii dp(N,vi (60));
    Point.pb(INF);
    cin>>L>>Q;
    rep(i,0,N){
        dp[i][0]=disup(Point,Point[i]+L)-1;
    }
    rep(i,1,60){
        rep(j,0,N){
            dp[j][i]=dp[dp[j][i-1]][i-1];
        }
    }
    rep(_,0,Q){
        int Start,Goal; cin>>Start>>Goal;
        if(Start>Goal) std::swap(Start,Goal);
        int ans=0;
        Start--;
        Goal--;
        while(1){
            int Dist=dislow(dp[Start],Goal);
            if(Dist==0){
                ans++;
                break;
            }
            Start=dp[Start][Dist-1];
            ans+=(1ll<<(Dist-1));
        }
        cout<<ans<<endl;
    }
}
 

Measured memory_bytes: 52608
h, w = map(int, input().split())
sL = [input() for i in range(h)]

ans = "Yes"

for y in range(h):
    for x in range(w):
        if sL[y][x] == ".":
            continue
        if y-1 < 0 or y+1 > h-1 or x-1 < 0 or x+1 > w-1:
            continue
        if sL[y+1][x] == sL[y-1][x]  == sL[y][x+1] == sL[y][x-1] == ".":
            ans = "No"
            break

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<17;

int bio[MAX];
vector <int> Poz[MAX];
int p[MAX];
int nebitan[MAX];

void Nope()
{
  printf("No\n");
  exit(0);
}

vector <int> Kad(vector <int> V, int br)
{
  int ind = (int) V.size() - 1;
  vector <int> R;

  for (; ind >= 0 && Poz[br].size(); ) {
    if (Poz[br].back() < V[ind]) {
      R.push_back(Poz[br].back());
      ind--;
    }
    Poz[br].pop_back();
  }

  if (ind >= 0)
    Nope();

  reverse(R.begin(), R.end());

  return R;
}

int n, m, q;

int main()
{
  scanf("%d%d%d", &n, &m, &q);

  for (int i=0; i<q; i++) {
    scanf("%d", &p[i]);
    Poz[p[i]].push_back(i);
  }

  vector <int> T;
  for (int i=0; i<n; i++)
    T.push_back(MAX);

  vector <int> Por;
  for (int i=q-1; i>=0; i--) {
    if (bio[p[i]]++)
      continue;

    Por.push_back(p[i]);
  }

  for (int i=(int) Por.size()-1; i>=0; i--) {
    if (i != (int) Por.size() - 1 && Por[i] > Por[i+1])
      break;

    int da = 1;
    int poc = (i == (int) Por.size() - 1) ? 1 : Por[i+1];
    for (int j=poc; j<Por[i]; j++)
      if (!bio[j])
        da = 0;

    if (!da)
      break;

    nebitan[Por[i]] = 1;
  }

  memset(bio, 0, sizeof bio);

  for (int i=q-1; i>=0; i--) {
    if (bio[p[i]]++)
      continue;

    if (nebitan[p[i]])
      continue;

    T = Kad(T, p[i]);
  }

  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 8696
n = gets.to_i
shop_list = readlines.map.with_index { |line,i| [line.split(' ')[0],line.split(' ')[1].to_i,i + 1] }
name_list = shop_list.map{|shop| shop[0]}.sort!{|a,b| a <=> b}.uniq
name_list.each do |name|
  shop_list.select{|shop| shop[0] == name}.sort_by{|shop| shop[1]}.reverse.each do |shop|
    puts shop[2]
  end
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,k;
int x[13];
signed main(){
    cin>>n>>k;
    rep(i,k)cin>>x[i];
    while(1){
        int a=(n/1000)%10,b=(n/100)%10,c=(n/10)%10,d=n%10,e=n/10000;
        if(n<10000)e=d;
        if(n<1000)a=d;
        if(n<100)b=d;
        if(n<10)c=d;
        bool ok=true;
        rep(i,k){
            if(x[i]==a||x[i]==b||x[i]==c||x[i]==d||x[i]==e)ok=false;
        }
        if(ok){
            cout<<n<<endl;
            return 0;
        }
        else n++;
    }
    return 0;
}



Measured memory_bytes: 256
//  Created by conan1024hao on 2019/11/19.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b,c;
    cin>>a>>b>>c;
    int ans=-1;
    chmax(ans,c);
    chmin(ans,b/a);
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
n = int(input())
m = list(map(int,input().split()))
ans = []
cou = 0

for i in range(n):
  while m[i] % 2 == 0:
    m[i] = m[i] / 2
    cou += 1
  ans.append(cou)
  cou = 0
print(min(ans))

Measured memory_bytes: 3060
from sys import stdin
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

## main ##
N, K = map(int, input().split())
S = rs()

a = [0] * N
prev = 1
v = 0
for i in range(N):
    if S[i] != prev: v += 1
    a[i] = v
    prev = S[i]

ma = 0
l = 0
r = 0
for lv in range(a[0], a[N - 1] + 1):
    while a[l] < lv : l += 1
    rv = 0
    if S[l] == '0':
        rv = lv + 2 * K - 1
    else :
        rv = lv + 2 * K
    while r < N and a[r] <= rv: r += 1
    ma = max(ma, r - l)

print(ma)
 




Measured memory_bytes: 7156
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll a, b, c;
	std::cin >> a >> b >> c;
	ll x = c - a - b;
	if (x > 0 && 4 * a * b < x * x) {
		std::cout << "Yes" << endl;
	}
	else {
		std::cout << "No" << endl;
	}
	return 0;

}


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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();
        double[] p = Arrays.stream(in.nextIntArray(n)).mapToDouble(i -> (((double) i) + 1d) / 2d).toArray();
        double[] cum = new double[n + 1];
        for (int i = 0; i < p.length; i++) {
            cum[i + 1] = cum[i] + p[i];
        }

        int start = k;
        int end = n + 1;
        double max = 0;
        for (int i = start; i < end; i++) {
            double ans = cum[i] - cum[i - k];
            max = Math.max(ans, max);
        }
        out.println(max);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 45456
using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Array.Sort(l);
        Console.WriteLine(l.Sum() > 2 * l[n - 1] ? "Yes" : "No");
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
int main(void){
    int N,K,X,Y;
    int ans;
    scanf("%d %d %d %d",&N,&K,&X,&Y);

    if(N<=K){
        ans=X*N;
    }else{
        ans=X*K;
        ans+=(N-K)*Y;
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
  long long n,k;
  scanf("%lld%lld",&n,&k);
  if(k%2){
      long long a;
      a=n/k;
      printf("%lld\n",a*a*a);
  }
  if(!(k%2)){
      long long a;
      a=n/(k/2);
      if(!(a%2)){
          printf("%lld\n",a*a*a/4);
      }
      if(a%2){
          long long b,c;
          b=a/2;
          c=a-b;
          printf("%lld\n",b*b*b+c*c*c);
      }
  }
}

Measured memory_bytes: 128
S = input()
K = int(input())

s_list = list(S)

modified = "mdf"

def solve():
    # その単語に1種類の文字しかなければ、合計の文字数を2で割捨てした数
    if len(set(s_list)) == 1:
        return (len(s_list)*K)//2
    
    cnt = 1
    cnt_list = []
    for i in range(len(s_list)-1):
        if s_list[i] == s_list[i+1]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    
    # 最後の対応
    # cnt = 1の時、最後は1文字だけ
    # cnt >= 2の時、最後は同じ文字が続いてる
    cnt_list.append(cnt)
    
    # 最初と最後が同じ時は最初と最後を足したやつを作る必要。
    head = cnt_list[0]
    tail = cnt_list[-1]
    body = cnt_list[1:-1]
    
    def body_change_cnt(body):
        cnt = 0
        for b in body:
            cnt += b//2
        return cnt
    
    if s_list[0] == s_list[-1]:
        head_tail = cnt_list[0] + cnt_list[-1]
        return head//2 + tail//2 + body_change_cnt(body)*K + (head_tail//2)*(K-1)
    else:
        return (head//2 + tail//2 + body_change_cnt(body)) * K

result = solve()

print(result)

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

int main(){
  string S;
  cin>>S;
  int ans;
  if(S=="SUN"){
    ans = 7;
  }else if(S=="MON"){
    ans = 6;
  }else if(S=="TUE"){
    ans = 5;
  }else if(S=="WED"){
    ans = 4;
  }else if(S=="THU"){
    ans = 3;
  }else if(S=="FRI"){
    ans = 2;
  }else if(S=="SAT"){
    ans = 1;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;


int main() {
	string s, t;
	cin >> s >> t;
	s += s;
	int sz = t.size();
	for (auto it = s.begin(); it != s.end() - sz; it++) {
		if (string(it, it + sz) == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}



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

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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    int  a[n];
    FOR(i,0,n) scanf("%d", a + i);
    int mx = 0;
    FOR(i,0,n) mx = max(mx, a[i]);
    int cnt = 0; // 大きい方
    FOR(i,0,n){
        if(a[i] < mx - 1){
            puts("No");
            return 0;
        }
        if(a[i] == mx){
            cnt++;
        }
    }
    if(mx == n - 1 && cnt == n){
        puts("Yes");
        return 0;
    }
    // a[i] == mx -> c[i] is not unique
    // a[i] == mx - 1 - > c[i] is unique
    if(cnt == 1){
        puts("No");
        return 0;
    }
    int p = n - cnt;
    int q = cnt;
    if(p <= mx - 1 && mx <= p + q / 2){
        puts("Yes");
    }
    else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long x, d, k;
int main()
{
    cin>>x>>k>>d;
    x = abs(x);
    if (k>x/d)
    {
        k = k - x/d;
        x = x - ((x/d)*d);
        if (k%2==0)
        {
            cout<<x;
        }
        else
        {
            cout<<d-x;
        }
    }
    else
    {
        cout<<x-d*k;
    }

}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int x = Integer.parseInt(sc.next());
            int num = Math.min(Math.abs(k - x), x);
            ans += num * 2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21588
a,b = map(int,input().split())
if(b != 0):
  c = list(map(int,input().split()))
else:
  print(a)
  exit()
ans = 0
for i in range(101):
  if(a+i not in c):
    if(a+i > 101):
      break
    else:
      ans = a+i
      break
for i in range(101):
  if(a-i not in c):
    if(a-i < 0):
      break
    else:
      if(i < abs(a-ans)):
        ans = a-i
      elif(i == abs(a-ans)):
        ans = min(a-i,ans)
      break
print(ans)

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a,b;
    cin >> a >> b;
    if(a - b * 2 < 0) cout << 0 << endl;
    else cout << a - b * 2 << endl;
  }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	string s; cin>>s;
	int a=0;
	rep(i,s.size()){
		if(s[i]=='+') a++;
		else a--;
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)

	x := make([]int, n)
	sum := 0
	for i := 0; i < len(x); i++ {
		fmt.Scan(&x[i])
		sum += x[i]
	}

	p := int((float64(sum)/(float64)(len(x)) + 0.5))
	hp := 0
	for i := 0; i < len(x); i++ {
		hp += (x[i] - p) * (x[i] - p)
	}

	fmt.Println(hp)
}


Measured memory_bytes: 512
import sys
import bisect
input = sys.stdin.readline

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    n=int(input())
    t=[0 for _ in range(n)]
    for i in range(n):
        t[i]=int(input())
    ans=1
    for i in range(n):
        ans=lcm(ans,t[i])
 
    print(ans)
    
    
main()

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

#define int long long
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define fs first
#define sc second
#define mpr make_pair
#define iter iterator
#define all(X) X.begin(),X.end()
#define sau(X) sort(all(X)),X.resize(unique(all(X))-X.begin())
#define exist(X,ele) binary_search(all(X),ele)
#define y0 I_love_Ryougi_Shiki_0
#define y1 I_love_Ryougi_Shiki_1

template<typename T1,typename T2>
ostream& operator << (ostream& out,const pair<T1,T2>& X)
{
	out<<"{"<<X.fs<<","<<X.sc<<"}";
	return out;
}

template<typename T>
ostream& operator << (ostream& out,const vector<T>& X)
{
	for(auto i:X) out<<i<<" ";
	return out;
}

template<typename T>
inline void cmin(T& x,T y)
{
	if(!(x<y)) x=y;
}

template<typename T>
inline void cmax(T& x,T y)
{
	if(x<y) x=y;
}

const int inf=5000000000000000ll;

__int128 a[4000];

main()
{
	ios::sync_with_stdio(false);
	
	a[0]=100;
	for(int i=1;i<=3760;i++)
	{
		a[i]=a[i-1]*101/100;
	}
	int x; cin>>x;
	for(int i=1;i<=3760;i++)
	{
		if(a[i]>=x)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	
	return 0;
}






















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

int main()
{
    int n;
    cin>>n;
    int x=n%10;
    if(x==2||x==4||x==5||x==7||x==9)
    cout<<"hon";
    else if(x==0||x==1||x==6||x==8)
    cout<<"pon";
    else
    cout<<"bon"<<"\n";
}

Measured memory_bytes: 3640
from collections import deque
S=deque(input())
Q=int(input())
r='1'
for _ in range(Q):
    target = input()
    if target == '1':
        if r=='1':
            r='2'
        else:
            r='1'
    else:
        a,b,c=target.split()
        if b=='1' and r=='1':
            S.appendleft(c)
        elif b=='2' and r=='1':
            S.append(c)
        elif b=='1' and r=='2':
            S.append(c)
        else:
            S.appendleft(c)
if r=='2':
    S.reverse()
print(''.join(list(S)))

Measured memory_bytes: 8692
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,x,y,i,j;
  cin>>n>>x>>y;
  ll distance[n]={0};
  for(i=1;i<=n;i++)
  {
    for(j=i+1;j<=n;j++)
    {
     if(i<=x)
     {
      if(j<y)
      {
       distance[min(j-i,x-i+1+abs(j-y))]++;
      }
      if(j>=y)
      {
       distance[min((j-i),(x-i+1+j-y))]++;
      }
     }
     else if(i>x)
     {
      distance[min(j-i,abs(x-i)+1+abs(j-y))]++;
     }
    }
  }
  for(i=1;i<n;i++)
    {
     cout<<distance[i]<<'\n';
    }
   
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
C - Anti-Division
https://atcoder.jp/contests/abc131/tasks/abc131_c

"""
import sys

from fractions import gcd

def solve(A, B, C, D):
    ans = B - A + 1
    div_c = (B // C) - ((A-1) // C)
    div_d = (B // D) - ((A-1) // D)
    lcm_cd = C*D // gcd(C, D)
    div_cd = (B // lcm_cd) - ((A-1) // lcm_cd)
    return ans - div_c - div_d + div_cd


def main(args):
    A, B, C, D = map(int, input().split())
    ans = solve(A, B, C, D)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 5076
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int k;
ll ans=0;
ll gcd(ll a,ll b) {
	if(b==0) return a;
	return gcd(b,a%b);
}
int main()
{
	scanf("%d",&k);
	for(ll i=1;i<=k;++i)
		for(ll j=1;j<=k;++j)
			for(ll l=1;l<=k;++l)
				ans+=gcd(gcd(i,j),l);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3828
houkou={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
S1=list(map(int,input().split()))
S2=list(map(int,input().split()))
for i in "SSSSEEEENEEEENEEEENEEEENWSSSSWSSSSWSSSSWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEWNWSSSSEEEEWSSSSEEEEWSSSSEEEEW:":
  if S1==S2:
    print("Yes")
    break
  if i==":":
    print("No")
    break
  S1=[S1[j]for j in houkou[i]]
  #print(S1)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;


int main(){
    int n;cin >> n;
    int h,w;cin >> h >> w;
    cout << max(1,n-h+1)*max(1,n-w+1) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <iomanip> 

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int L;
    cin >> L;

    double side = L / 3.0;

    cout << std::fixed << side*side*side << "\n";

    return 0;
}


Measured memory_bytes: 256
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const firstLine = input[0].split(" ").map((x) => parseInt(x, 10));
const secondLine = input[1].split(" ").map((x) => parseInt(x, 10));

const N = firstLine[0];
const X = firstLine[1];

const points = secondLine.sort((a, b) => a - b);
const distances = points.map((val, index) => val - points[index - 1]).sort((a, b) => b - a);

let sum = 0;
for (let i = N; i < distances.length; i++) {
  sum += distances[i];
}

console.log(sum);


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,x; cin>>n>>x;
    vector<int> l(n,0);
    REP(i,n) cin>>l[i];
    int cnt=1;
    vector<int> d(n);
    d[0]=0;

    for(int i=0; i<n; i++)
    {
        d[i+1]=d[i]+l[i];
        if(d[i+1]<=x) ++cnt;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,d,x;
    cin>>n>>d;
    vector<ll>v[50];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<d;j++)
        {
            cin>>x;
            v[i].push_back(x);
        }
    }
    ll c=0;
    double y;
    for(ll i=0;i+1<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            y=0;
            for(ll p=0;p<d;p++)
            {
                y+=(v[i][p]-v[j][p])*(v[i][p]-v[j][p]);
            }
            if(ceil(sqrt(y))==floor(sqrt(y)))
            {
                c++;
            }
        }
    }
    cout<<c<<endl;
    return 0;
}


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

int main(){
  using namespace std;
  int n, k;
  string status;
  cin >> n >> k >> status;
  
  int sum_happiness = 0;
  if (n != 1){
    if (status[0] == 'R' && status[1] == 'R')
      sum_happiness += 1;
    if (status[n - 1] == 'L' && status[n - 2] == 'L')
      sum_happiness += 1;
    for (int i = 1; i < n - 1; i++){
      if ((status[i] == 'L' && status[i - 1] == 'L') || (status[i] == 'R' && status[i + 1] == 'R'))
        sum_happiness += 1;
    }
    sum_happiness = sum_happiness + 2 * k;
    sum_happiness = sum_happiness > n - 1 ? n - 1 : sum_happiness;
  }
  cout << sum_happiness << endl;
}

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


int main(){
    ll N;
    cin >> N;
    vector<ll> v(N);
    vector<ll> tmp(N);

    for(ll i = 0; i < N; i++) cin >> v[i];
    tmp = v;
    sort(tmp.begin(), tmp.end());

    ll num1,num2;
    num2 = tmp[N/2];
    num1 = tmp[N/2 - 1];


    for(int i = 0; i < N; i++){
        if(num2 <= v[i]){
            cout << num1 << endl;
        }else{
            cout << num2 << endl;
        }
    }


}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<int> v(n),w(n+1);
    cin >> v[0];
    int sum = v[0];
    w[0] = v[0];
    FOR(i,1,n){
        cin >> v[i];
        sum += v[i];
        w[i] = v[i] - v[i - 1];
    }
    w[n] = -v[n - 1];

    int loop, l=0, result=0,p_flag=0,water_times;
    while(sum){
        for (loop = 0; loop <= n;loop++){
        
            if(w[loop]>0){
                l = loop;
                p_flag = 1;
            }else if(w[loop]<0&&p_flag){
                water_times = min(w[l],-w[loop]);
                result += water_times;
                w[l] -= water_times;
                w[loop] += water_times;
                sum -= (loop - l ) * water_times;
            }
            
            
        }p_flag = 0;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 384
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const arr = input.split(' ').map(Number);
const a = arr[0];
const b = arr[1];
const C = arr[2] * Math.PI / 180;
const S = a * b * Math.sin(C) / 2;
const c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2) - 2 * a * b * Math.cos(C));
const L = a + b + c;
const h = b * Math.sin(C);
console.log(S.toFixed(4) + '\n' + L.toFixed(4) + '\n' + h.toFixed(4));



Measured memory_bytes: 15144
#include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

// やっと会えたね，二乗の木 DP たん
// https://drken1215.hatenablog.com/entry/2019/01/13/024000
vector<lint> a;
vector<vector<lint>> g;

vector<pair<lint, lint>> merge(const vector<pair<lint, lint>> &dpl, const vector<pair<lint, lint>> &dpr) {

  int n = dpl.size();
  int m = dpr.size();
  
  vector<pair<lint, lint>> dp(n + m, {INF, 0});
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      // 和
      // マージする
      chmin(dp[i + j].first, dpl[i].first + dpr[j].first);
      // r はカットする
      if (dpr[j].first < 0 or dpr[j].second) {
        chmin(dp[i + j + 1].first, dpl[i].first);
      }

      // すべて正にできるか
      dp[i + j].second |= dpl[i].second & dpr[j].second;
      // r はカットする
      if (dpr[j].first < 0 or dpr[j].second) {
        dp[i + j + 1].second |= dpl[i].second;
      }
    }
  }

  return dp;
}

// この書き方は半ばテンプレート気味
vector<pair<lint, lint>> dfs(int cur, int par = -1) {

  vector<pair<lint, lint>> dp(1);
  dp[0].first = a[cur];
  dp[0].second = (a[cur] > 0);
  for (auto nxt : g[cur]) {
    if (nxt == par) continue;
    vector<pair<lint, lint>> cdp = dfs(nxt, cur);
    dp = merge(dp, cdp);
  }

  return dp;
}

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

  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v; cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  auto dp = dfs(0);
  int ans = inf;
  for (int i = 0; i < n; i++) {
    if (dp[i].first < 0) {
      ans = min(ans, i);
    }
    if (dp[i].second == true) {
      ans = min(ans, i);
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1328
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;
    string S;
    cin >> S;

    string S1 = string(S.begin(), S.begin() + N), S2 = string(S.begin() + N, S.end());

    vector<pair<string, string>> p;
    REP(i, 1 << N) {
        string r, b;
        REP(j, N) {
            if (i >> j & 1) r.pb(S2[j]);
            else b.pb(S2[j]);
        }

        reverse(ALL(b));

        p.pb({r, b});
    }

    sort(ALL(p));

    ll ans = 0;
    REP(i, 1 << N) {
        string r, b;
        REP(j, N) {
            if (i >> j & 1) r.pb(S1[j]);
            else b.pb(S1[j]);
        }

        reverse(ALL(b));

        auto pp = make_pair(b, r);
        ans += upper_bound(ALL(p), pp) - lower_bound(ALL(p), pp);

    }

    cout << ans << endl;

}


Measured memory_bytes: 33388
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        System.out.println(K == 1 ? 0 : N-K);
    }
}

Measured memory_bytes: 23124
long d['~~'];A,x,i,j;main(n){for(scanf("%d%d",&n,&A),d[n*=A]=1;~scanf("%d",&x);i=5e3-i)for(j=2*n;j--;)d[5000-i+j]=d[i+j]+d[j<x-A?:i+j-x+A];printf("%ld",d[i+n]-1);}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans=0,pw[20],d,cur;
long long bt(long long now,int rem,int dg){
	if(rem==0) return (now==0);
	if(rem==1) return (now==0)*10LL;
	long long prd=pw[dg-1]-pw[cur-dg];
	long long mul=now/prd,ret=0;
	if(rem==dg){
		ret+=1LL*max(0LL,9-abs(mul))*bt(now-prd*mul,rem-2,dg-1);
		if(mul<0) mul--;
		else if(mul==0) mul++, ret+=1LL*max(0LL,9-abs(mul))*bt(now-prd*mul,rem-2,dg-1), mul-=2;
		else mul++;
		ret+=1LL*max(0LL,9-abs(mul))*bt(now-prd*mul,rem-2,dg-1);
	}
	else{
		ret+=1LL*max(0LL,10-abs(mul))*bt(now-prd*mul,rem-2,dg-1);
		if(mul<0) mul--;
		else if(mul==0) mul++, ret+=1LL*max(0LL,10-abs(mul))*bt(now-prd*mul,rem-2,dg-1), mul-=2;
		else mul++;
		ret+=1LL*max(0LL,10-abs(mul))*bt(now-prd*mul,rem-2,dg-1);
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>d;
	pw[0]=1;
	for(int i=1;i<=18;i++) pw[i]=pw[i-1]*10LL;
	for(int i=1;i<=19;i++) cur=i, ans+=bt(d,i,i);
	cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define li(x) x.size()-1
#define oo 1000000000
#define inf 1000000000000000000
#define M 1000000007
#define M2 1000000009
#define pii pair<ll,ll>
using namespace std;
typedef long long ll;
const int N = 2e5+100;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);

int n,k=3;
int a[N];
int dp[N];
int main() {
	cin >> n;
	cin >> k;
	for(int i = 0 ; i < n ; i++){
		scanf("%d",a+i);
	}
	dp[0]=0;
	for(int i = 1 ; i < n ; i++){
		dp[i]=oo;
		for(int j = 1 ; j <= k ; j++){
			if(i-j<0)break;
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

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

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

  long long ans = 0;
  if(n == 1){
    ans = x;
  }
  else{
    for(int i = 0; i < n - 1; i++){
      if(v[i + 1] - v[i] > x){ ans += x; }
      else{ ans += v[i + 1] - v[i]; }
    }
    ans += x;
  }
  cout << ans << endl;

}

Measured memory_bytes: 1792
#pragma GCC target ("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define ull unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "YES"<< "\n"
#define N cout<< "NO"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll k,f=0,v;
    cin>>k;
    if(k%2==0)
        cout<< "-1";
    else
    {
        ll p=7;
        for(ll i=1;i<=k;i++)
        {
            if(p%k==0)
            {
                v=i;
                f=1;
                break;
            }
            p=(10*p+7)%k;
        }
        if(f)
            cout<<v;
        else
            cout<< "-1";
    }
    return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n,k;
  cin>>n>>k;
  ll mn = 1000000000000000000LL;
  rep(i,0,1<<n){
    ll a = 1;
    rep(j,0,n){
      if(((i>>j)&1)==1){
        a*=2;
      }
      else{
        a+=k;
      }
    }
    mn = min(mn,a);
  }
  cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    string o;
    string e;
    cin >> o;
    cin >> e;
    string str;
    int len;
    int shorter = 0;
    if(o.size() < e.size()){
        len = o.size();
        shorter = -1;
    }else if(o.size() > e.size()){
        len = e.size();
        shorter = 1;
    }else{
        len = o.size();
    }
    rep(i, len){
        str += o.at(i);
        str += e.at(i);
        if(i + 1 == len){
            if(shorter == -1){
                str += e.at(i + 1);
            }else if(shorter == 1){
                str += o.at(i + 1);
            }
        }
    }

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N, K, Q; cin >> N >> K >> Q;
  vector<int> A(Q);
  for(int i=0; i<Q; i++) cin >> A[i];
  
  vector<int> win(N, 0);
  for(auto a: A){
    win[a-1]++;
  }
  
  vector<string> ans(N);
  for(int i=0; i<N; i++){
    if(Q - win[i] >= K)
      ans[i] = "No";
    else
      ans[i] = "Yes";
  }
  
  for(auto s: ans){
    cout << s << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> pii;
typedef tuple<ll,ll,ll> tii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef map<ll,ll> mi;
typedef map<pii,ll> mii;


#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define rep(i,a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define PI 3.141592653589793238

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}



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

    string s;
    cin>>s;

    if(s[1]=='B')
    	cout<<"ARC"<<endl;
    else
    	cout<<"ABC"<<endl;
    
    return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean flag = false;
        while (n != 0) {
            var tmp = n % 10;
            n /= 10;
            if (tmp == 7) {
                flag = true;
                break;
            }
        }

        if (flag) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35680