akhauriyash/Code-Regression huggingface dataset:
//実験すると、snuke数は, 上2桁以外が全て9になっている。2099999みたいな感じ。よって、このような数だけを候補にして探索すればよい。
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define int long long
using namespace std;

int dsum(int n) {
	int ret = 0;
	while (n > 0) {
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

int p10[20];
vector<int> koho;
int K;
vector<int> snuke;

signed main() {
	int i, j;
	
	p10[0] = 1;
	for (i = 1; i < 20; i++) p10[i] = p10[i - 1] * 10;
	
	for (i = 1; i < 10; i++) koho.push_back(i);
	
	for (i = 1; i <= 15; i++) {	//下i桁が9
		for (j = 1; j < 10000; j++) {	//上1～4桁を試す
			if (j * p10[i] + p10[i] - 1 > 1e+18) break;
			koho.push_back(j * p10[i] + p10[i] - 1);
		}
	}
	sort(koho.begin(), koho.end());
	
	double mini = 1e+18;
	for (i = koho.size() - 1; i >= 0; i--) {
		double res = (double)koho[i] / dsum(koho[i]);
		if (mini >= res) {
			mini = res;
			snuke.push_back(koho[i]);
		}
	}
	sort(snuke.begin(), snuke.end());
	
	cin >> K;
	int cnt = 0;
	for (i = 0; cnt < K; i++) {
		if (i == 0 || snuke[i - 1] < snuke[i]) {
			cout << snuke[i] << endl;
			cnt++;
		}
	}
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define nl '\n'
#define vec vector<ll>
#define pr pair<ll,ll>
#define vecp vector< pr >
#define pq priority_queue<ll>
#define pqp priority_queue<pr>
#define ff first
#define ss second
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define PI 3.14159265
 const ll MOD=1000000007;
 ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=low+((high-low)/2);
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
vec sieve;
void Sieve(int N) {
    const ll maxn = N+1;
    sieve.resize(maxn);
    f(i,0,maxn) sieve[i] = i;
    sieve[1] = -1;
    sieve[0] = -1;
    f(i, 2, maxn) if (i == sieve[i]) for (ll j = 2 * i ; j < maxn ; j += i) if (sieve[j] == j) sieve[j] = i;
}
ll dp[100001];
ll rec(ll n,ll*a)
{
	if(dp[n]!=-1)
	return dp[n];
	if(n==1)
	return 0;
	if(n<1)
	return 1000000000;
	ll ans=min((rec(n-1,a)+abs(a[n-1]-a[n])),(rec(n-2,a)+abs(a[n-2]-a[n])));
	dp[n]=ans;
	return dp[n];
}
int main()
{
	fast
ll n ;
cin>>n;
ll a[n+1];
f(i,1,n+1)
cin>>a[i];
f(i,0,n+1)
dp[i]=-1;
ll final=rec(n,a);
cout<<final<<nl;
return 0;
}




Measured memory_bytes: 7488
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, H: "List[int]"):
    H.sort(reverse=True)
    a = sum(H[K:])
    ret = a
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29404
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else 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;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

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

	if (S.size() < T.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	string U = S;
	vector<string> s(S.size()-T.size()+10);
	ll flag = 0;
	for (int i = 0; i <= S.size() - T.size() ; i++) {
		S = U;
		ll cnt = 0;
		for (int j = i; j < T.size() + i; j++) {
			if (T[j-i] != S[j] && S[j]!= '?') break;
			else {
				if(S[j] == '?') S[j] = T[j-i];
				cnt++;
				if (cnt == T.size()) {
					flag = 1;
					rep(k, S.size()) if (S[k] == '?') S[k] = 'a';
					s[i] = S;
				}
			}
		}
	}
	
	if (flag == 0) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	sort(ALL(s));

	rep(i, S.size() - T.size() + 10) {
		if (s[i] != "") {
			cout << s[i] << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
using pi = pair<lint, lint>;
const int MAXN = 100005;

int st[MAXN], ed[MAXN];
int dap;

int main(){
	int n; cin >> n;
	int wtf = 0;
	for(int i=0; i<n; i++){
		string s; cin >> s;
		for(int j=1; j<s.size(); j++){
			if(s[j-1] == 'A' && s[j] == 'B') dap++;
		}
		st[s[0]]++;
		ed[s.back()]++;
		if(s[0] == 'B' && s.back() == 'A') wtf++;
	}
	dap += min(ed['A'], st['B']);
	if(wtf && ed['A'] == wtf && st['B'] == wtf) dap--;
	cout << dap << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int ans = 15;
    for (int i = 0; i < 5; i++){
      int x = scan.nextInt();
      ans = ans - x;
    }
    System.out.println(ans);
  }
}


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

int main() {
  int A;
  int sum=0;
  cin >> A;
  for(int i=0;i<A;i++){
    int B,C;
    cin >> B >> C;
    sum += C-B+1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a += b;
	if(a>MOD){
		a -= MOD;
	}
}

char s[816225];

int main(void){
	char c;
	s[(int)'A'] = 'T';
	s[(int)'T'] = 'A';
	s[(int)'C'] = 'G';
	s[(int)'G'] = 'C';
	cin >> c;
	cout << s[(int)c] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  vector<vector<int>> c(3,vector<int>(3));
  rep(i, 3){
    rep(j, 3){
      cin >> c.at(i).at(j);
    }
  }
  bool ok = false;
  rep(i, 101){
    rep(j,101){
      rep(k,101){
        if(c.at(0).at(0)-i==c.at(1).at(0)-j && c.at(1).at(0)-j==c.at(2).at(0)-k && c.at(0).at(1)-i==c.at(1).at(1)-j && c.at(1).at(1)-j==c.at(2).at(1)-k && c.at(0).at(2)-i==c.at(1).at(2)-j && c.at(1).at(2)-j==c.at(2).at(2)-k){
          ok = true;
          break;
        }
      }
    }
  }
  if(ok){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1 << 30;
int dp[20010];
int main(){
    int h,n; cin >> h >> n;
    vector<pair<int,int>> ab(n);
    rep(i,n) cin >> ab[i].first >> ab[i].second;

    rep(i,20010) dp[i] = INF;
    dp[0] = 0;
    rep(i,h)rep(j,n){
        int ni = i + ab[j].first;
        if(ni>h) ni = h;
        chmin(dp[ni],dp[i]+ab[j].second);
    }

    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 384
c(int*a,int*b){return*a-*b;}
a[2<<17];i,j;long s;
main(){
	for(gets(a);~scanf("%d",a+i);)a[i++]-=i;
	qsort(a,i,4,c);
	for(;j<i;)s+=fabs(a[i/2]-a[j++]);
	printf("%ld",s);
}

Measured memory_bytes: 1788
#include <iostream>
#include <string>
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
		ans = 1;
	cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, n int
	fmt.Scanf("%d %d %d", &a, &b, &n)
	answer := maxFloor(a, b, n)
	fmt.Println(answer)
}

func maxFloor(a, b, n int) int {
	if n/b >= 1 {
		return floor(a, b, b-1)
	}
	return floor(a, b, n)
	// m := min(b-1, n)
	// return floor(a, b, m)
}

func floor(a, b, x int) int {
	s := a * x / b
	t := a * (x / b)
	return s - t
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}


Measured memory_bytes: 1816
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r=0;int b=0;

    rep(i,s.size()){
        if(s[i]=='R'){r++;}else{b++;}
    }


    if(r>b){cout<<"Yes"<<endl;}else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import OrderedDict
while True:
    num = int(input())
    if not num: break
    result = OrderedDict()
    for _ in range(num):
        x, y, z = [int(el) for el in input().split(' ')]
        if x in result:
            result[x] += y*z
        else:
            result[x] = y*z
    res = [print(k) for k,v in result.items() if v >= 1e6]
    if not res: print('NA')

Measured memory_bytes: 8496
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

queue<int> q1;
priority_queue<LP,vector<LP>,greater<LP> > q2,q3;
int parent[1005];//-1
int num[1005];

long long int pow_mod(long long int p_a,long long int p_n,long long int p_p=1e9+7){
	//p_a^p_n mod p_p
	long long int p_b=1,p_t=1;
	for(;p_b<=p_n;p_b<<=1);
	for(p_b>>=1;p_b>0;p_b>>=1){
		p_t*=p_t;
		if(p_t>=p_p)p_t%=p_p;
		if(p_n&p_b)p_t*=p_a;
		if(p_t>=p_p)p_t%=p_p;
	}
	return p_t;
}

int check_parent(int x){
	if(parent[x]!=-1)return check_parent(parent[x]);
	int a;
	while(!q1.empty()){
		a=q1.front(),q1.pop();
		parent[a]=x;
	}
	return x;
}
 
bool connect(int x,int y){
	x=check_parent(x),y=check_parent(y);
	if(x==y)return false;
	if(num[x]>num[y])swap(x,y);
	parent[x]=y;
	num[y]+=num[x];
	return true;
}

LL n,m,p;
LL path[2005][3];
bool used[2005];
vector<LP> v1;

LL mst(bool first=false){
	int i,j,k;
	LL a,b,c;
	a=0;
	for(i=0;i<v1.size();i++){
		b=v1[i].second;
		if(connect(path[b][0],path[b][1])){
			a+=path[b][2];
			if(first)used[b]=true;
		}
	}
	return a;
}

int main(){
	int i,j,k;
	LL a,b,c;
	LL s=0;
	cin>>n>>m>>p;
	if(n<=2){
		cout<<0<<endl;
		return 0;
	}
	for(i=0;i<m;i++){
		for(j=0;j<3;j++){
			cin>>path[i][j];
		}
	}
	for(i=0;i<m;i++){
		v1.push_back(make_pair(path[i][2],i));
	}
	sort(v1.begin(),v1.end());
	memset(parent,-1,sizeof(parent));
	a=mst(true);
	if(p<a){
		cout<<0<<endl;
		return 0;
	}
	if(p==a){
		s+=(pow_mod(2,n-1)-2)*pow_mod(2,m-n+1);
		if(s>=MAX)s%=MAX;
	}
	v1.clear();
	for(i=0;i<m;i++){
		if(used[i])v1.push_back(make_pair(path[i][2],i));
	}
	sort(v1.begin(),v1.end());
	b=0,c=n-1;
	for(i=0;i<m;i++){
		if(used[i])continue;
		memset(num,0,sizeof(num));
		memset(parent,-1,sizeof(parent));
		connect(path[i][0],path[i][1]);
		a=path[i][2];
		a+=mst();
		if(p==a)b++;
		if(p>a)c++;
	}
	s+=2*(pow_mod(2,b)-1)*pow_mod(2,m-b-c);
	if(s>=MAX)s%=MAX;
	cout<<s<<endl;
		
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;

int main(){
    long double L;
    long double a, b, c;
    long double small = 1e-14;
    cin >> L;
    a = L/3;
    b = L/3;
    c = L/3;

    cout << fixed << setprecision(12) << a*b*c + small;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 998244353;

const int N = 2e5 + 6;
int n , q;

ll ans;

void update(int flg, vector<pii>&vec ) {
    vector<int> rec(n+1, n);
    int last = n;

    for(auto xx : vec) {
        int typ , x;
        tie(typ , x) = xx;
        if(typ == flg) {
            rec[last] = min(rec[last] , x);
        }
        else {

            if(x > last) ans -= (rec[x] - 2);
            else {

                for(int i = last - 1 ; i >= x ; i-- ) rec[i] = rec[last];
                last = x;
                ans -= (rec[x] - 2);
            }
        }
    }

}

int main()  {
    fastio;
    
    cin>>n>>q;
    vector<pii>vec(q) ;
    
    for(int i =0 ; i < q; i++ ) cin>>vec[i].uu>>vec[i].vv;

    ans = 1LL*(n-2)*(n-2);

    update(2, vec);
    update(1 , vec);
    
    cout<<ans<<'\n';
    
    return 0;




}

Measured memory_bytes: 5520
n = int(input())
l = list(map(int,input().split()))
ans = 0
flg = 1
while flg:
  for i in range(n):
    if l[i]%2 < 1:
      l[i] //= 2
    else:
      flg = 0
      break
  ans += flg
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
#define X first
#define Y second
int N;
char S[302][302];
int state[302][302];
void fillState() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			state[i][j] = 1;
			for (int k = 0; k < N; k++) {
				if (S[i][(k+j)%N] != S[(k+i)%N][j]) {
					state[i][j] = 0;
					break;
				}
			}
		}
	}
}
int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%s", S[i]);
	fillState();
	int ans = 0;
	for (int i = 0; i < N; i++) {
		bool isPossible = true;
		for (int k = 0; k < N; k++) {
			if (!state[(i + k) % N][k]) {
				isPossible = false;
				break;
			}
		}
		ans += N * isPossible;

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

Measured memory_bytes: 640
#include<bits/stdc++.h>   
#include<tr1/unordered_map>
#define ll long long int  
#define mkp make_pair 
#define mod 1000000007 
#define maxn 100001 
#define ff first
#define ss second 
using namespace std;    
int par[2*maxn]={0},s[2*maxn]={0}; 
int find(int a){  
    if(par[a]==a) 
       return a; 
    return par[a]=find(par[a]);
}  
void merge(int a,int b){ 
      int p=find(a); 
      int q=find(b); 
      if(p!=q){  
         if(s[p]>=s[q]){  
               par[q]=p; 
               s[p]+=s[q];  
               s[q]=0;
          } 
         else{  
            par[p]=q; 
            s[q]+=s[p]; 
            s[p]=0;
           }
      }
    }
int main(){    
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);    
  int n,m,a,b; 
  cin>>n>>m; 
  for(int i=0;i<=n;++i)  
     par[i]=i,s[i]=1;  

  while(m--){  
      cin>>a>>b; 
      merge(a,b);
  }  
  int ans=0;
  for(int i=1;i<=n;++i){   
     ans=max(ans,s[i]);
        
    }   
  cout<<ans<<"\n";
  
  
  return 0;
}

Measured memory_bytes: 5192
def main():
    ABC = tuple(map(int, input().split()))

    abc = sorted(ABC)
    cnt = abc[2] - abc[1]
    abc = [abc[0] + cnt, abc[1] + cnt, abc[2]]
    n = abc[1] - abc[0]
    if n % 2:
        cnt += -(-n // 2) + 1
    else:
        cnt += n // 2

    print(cnt)

main()


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
int main() {
	int n;
	scanf("%d", &n);
	int a[n+1];
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	std::sort(a, a + n);
	printf("%d\n", a[n - 1] - a[0]);
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0 && m == 0)break;

		VI a(n);
		rep(i, n)cin >> a[i];
		SORT(a);
		int ans = -1;
		rep(i, n - 1) {
			auto it = upper_bound(all(a), m - a[i]);
			size_t pos = distance(a.begin(), it);

			if (pos != 0) {
				int sum = a[i] + a[pos - 1];
				if (sum <= m && pos - 1 != i) {
					if (ans < sum)ans = sum;
				}
			}
		}
		if (ans == -1)puts("NONE");
		else cout << ans << endl;
	}
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int D=in();
    int ans;
    ans=N/(2*D+1);
    if(N%(2*D+1)!=0)ans++;
    cout<<ans<<endl;
    return 0;
}


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

long long  search(int h, int w){
    long long ans = 1e10;
    for(long long i=1; i<=w; i++){
       long long x = h*i;
       long long y = (w-i)*(h/2);
       long long z = (w-i)*(h-h/2);
       auto ma = max(x, max(y,z));
       auto mi = min(x, min(y,z));
       ans = min(ans, ma-mi);
    }
    return ans;
}

int main()
{
    int h,w;
    cin >> h >> w;
    if(h%3 == 0 || w%3 == 0){
        cout << 0 << endl;
        return 0;
    }
    int res = min(search(h,w), search(w,h));
    int ans = min(min(h,w), res);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const double PI=3.14159265358979323846;
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sum=0;
    for(int i=0;i<n;++i) {
        if(s[i]!=s[i+1]) ++sum;
    }
    cout << sum << endl;
}



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

int main() {
    int64_t l, r;
    cin >> l >> r;

    int64_t ans = 9999;
    if (r - l + 1 < 2019) {
        for (int64_t i = l; i <= r - 1; i++) {
            for (int64_t j = i + 1; j <= r; j++) {
                ans = min(((i % 2019) * (j % 2019)) % 2019, ans);
            }
        }
    } else {
        ans = 0;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int h, w, fl=1, a[55][55];
string s;
int main() {
	int i, j;
	cin>>h>>w;
	for(i=1; i<=h; i++) {
		cin>>s;
		for(j=1; j<=w; j++) a[i][j] = s[j-1]=='.' ? 0:1;
	}
	for(i=1; i<=h; i++) for(j=1; j<=w; j++) {
		if(a[i][j]==1 && a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1] == 0) fl=0;
	}
	cout<<(fl ? "Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

int main(void){
    int N;
    cin >> N;
    int A[N],B[N];
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    int dp[(1<<N)][51];
    rep(i,(1<<N)) rep(j,51) dp[i][j]=INF;
    dp[0][0]=0;
    rep(i,(1<<N)){
        int use=Flagcount(i);
        int p=use;
        vector<pint> rem;
        rep(j,N) if(!(i&(1<<j))) rem.push_back(pint(j,p++));
        rep(j,51){
            if(dp[i][j]==INF) continue;
            for(int k=0;k<rem.size();k++){
                int num=abs(rem[k].first-use)%2?B[rem[k].first]:A[rem[k].first];
                if(num>=j){
                    dp[i|(1<<rem[k].first)][num]=min(dp[i|(1<<rem[k].first)][num],dp[i][j]+abs(rem[k].second-rem[k].first));
                }
            }
        }
    }
    int ans=INF;
    rep(i,51) ans=min(ans,dp[(1<<N)-1][i]);
    if(ans==INF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 55836
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N, M = map(int, input().split())
As = list(map(int, input().split()))
s = sum(As)
As.sort(reverse=True)

ok = True
for m in range(M):
    if As[m] * 4 * M >= s:
        pass
    else:
        ok = False
if ok:
    print('Yes')
else:
    print('No')



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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int L, R, ans = 2020;
   cin >> L >> R;

   if (R - L - 1 > 673) ans = 0;
   else {
     for (int i = L; i <= R; i++) {
       for (int j = L; j <= R; j++) {
         if (i == j) continue;
         else ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
       }
     }
   }
   cout << ans << endl;
 }


Measured memory_bytes: 256
from collections import*
n,*a=map(int,open(0).read().split())
o=[];t=[]
for i,x in enumerate(a):o+=i+x,;t+=i-x,
f=lambda l:sum(x*(x-1)//2 for x in Counter(l).values())
print(f(o+t)-f(o)-f(t))

Measured memory_bytes: 70320
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
ll MOD = 10e9 + 7;

int main() {
    int n;
    int t=100000;
    cin >> n;
    int str[n];
    REP(i,n){
        cin >> str[i];
    }
    REP(i,n){
        int c1=0,c2=0,c=0;
        for(int j=0;j<=i;j++){
            c1+=str[j];
        }
        for(int k=i+1;k<n;k++){
            c2+=str[k];
        }
        if(c2>c1)c=c2-c1;
        else c=c1-c2;
        t=min(c,t);
    }
    cout << t <<endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func readStrings() []string {
	return strings.Split(readString(), " ")
}

func readInt() int {
	n, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return n
}

func readInts() []int {
	line := readStrings()
	ints := make([]int, 0)
	for _, s := range line {
		val, err := strconv.Atoi(s)
		if err != nil {
			panic(err)
		}
		ints = append(ints, val)
	}
	return ints
}

func main() {
	// Inputs
	n := readInt()
	ta := readInts()
	t, a := float64(ta[0]), float64(ta[1])
	h := readInts()

	// Solve
	ans := 1
	min := math.Abs(a - (t - float64(h[0])*0.006))
	for i := 1; i < n; i++ {
		diff := math.Abs(a - (t - float64(h[i])*0.006))
		if diff < min {
			min = diff
			ans = i + 1
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
num = []
loop do
	x = gets.chomp.to_i

	if x == 0 then
		break
	else
		num << x
	end
end

i = 1
num.map do |x|
	if x != 0
		puts 'Case ' + i.to_s + ': ' + x.to_s
	else
		break
	end	

 i += 1
end

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

int main()
{
  int m,n;
  cin >> m >> n;
  int l, r;
  int ans;
  int max=1000002;
  int min=1;
  
  for(int j=0;j<m;j++){
    cin >> l >> r;
    if(min < l)
      min = l;
    if(max > r)
      max = r;
  }
  
  ans = max - min +1;
  if(ans<0)
    ans=0;
  
  cout << ans <<"\n";
  
  return 0;
}



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


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

	int a[1000001];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int ma = 0;

	for (int i = 0;i < n -1;i++) {
		int temp = (a[n-1] + 1) / 2;
		if (a[i] > temp) {
			if (temp - a[i-1] <= a[i] - temp)
				ma = a[i-1];
			else
				ma = a[i];
			break;
		}
	}

	cout << a[n - 1] << ' ' << ma << endl;
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  string s,t;
  cin >> s >> t;
  if(s.length()>t.length()){
    printf("GREATER");
    return 0;
  }
  if(s.length()<t.length()){
    printf("LESS");
    return 0;
  }
  rep(i,s.length()){
    if(s[i]<t[i]){
      printf("LESS");
      return 0;
    }
    if(s[i]>t[i]){
      printf("GREATER");
      return 0;
    }
  }
  printf("EQUAL");
}

Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc128/tasks/abc128_e"

#include<bits/stdc++.h>
#define Pair pair<int,int>

using namespace std;

struct Node
{
    int x,s,e;

    Node(int x,int s,int e) : x(x),s(s),e(e) { }
};

bool func1 (Node n1,Node n2)
{
    return n1.x<n2.x;
}

bool func2 (Pair p1,Pair p2)
{
    return p1.first<p2.first;
}

int main()
{
    int n,q;
    cin>>n>>q;
    int s,t,x,i;

    vector<Node>works;
    for(i=0;i!=n;i++)
    {
        cin>>s>>t>>x;

        Node n = Node(x,s-x,t-x-1);
        works.push_back(n);
    }

    sort(works.begin(),works.end(),func1);      // define

    // check
    // for(i=0;i!=works.size();i++)
    //     cout<<works[i].x<<' ';
    map<int,int>M;
    for(i=0;i!=q;i++)
    {
        cin>>s;
        M[s] = i;
    }

    vector<Pair>Ends;
    for(i=0;i!=n;i++)
    {
        map<int,int>::iterator it1,it2;
        it1 = M.lower_bound(works[i].s);
        it2 = M.lower_bound(works[i].e);

        if((*it2).first == works[i].e)
            it2++;

        vector<int>Delete;

        for(auto it=it1;it!=it2;it++)
        {
            Ends.push_back(Pair((*it).second,works[i].x));
            Delete.push_back((*it).first);
        }

        for(auto it=Delete.begin();it!=Delete.end();it++)
            M.erase(*it);
    }

    for(auto it=M.begin();it!=M.end();it++)
        Ends.push_back(Pair((*it).second,-1));

    sort(Ends.begin(),Ends.end(),func2);        // define

    for(i=0;i!=q;i++)
        cout<<Ends[i].second<<'\n';

    return 0;
}


Measured memory_bytes: 17904
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,d;
    cin>>m>>d;
    if(m<4) cout<<0;
    else
    {
        int cnt = 0;
        for(int i=1;i<=d;i++)
        {
            int a = i%10;
            int b = i/10;
            if(a>=2 and b>=2 and a*b>=1 and a*b<=m) cnt++;
        }
        cout<<cnt;
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    tenki = input()
    leng = len(tenki)

    count = 0
    lst = []
    for i in range(leng):
        if tenki[i] == "R":
            count += 1
        else:
            lst.append(count)
            count = 0
    lst.append(count)
    count = 0
    print(max(lst))


if __name__ == '__main__':
    main()


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

using namespace std;

int n;
long long int B[110],A[110];
long long int ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	    scanf("%lld",&B[i]);
	A[1]=B[1];
	A[n]=B[n-1];
	for(int i=2;i<n;i++)
		A[i]=min(B[i-1],B[i]);
	for(int i=1;i<=n;i++)
	    ans=ans+A[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int lg[10000][1260];
int main(){
	int N,M;
	while(cin>>N>>M,N|M){
		REP(i,10000){
			REP(j,1260){
				lg[i][j]=0;
			}
		}
		int r;
		cin>>r;
		vi cnt(M);
		int cur=0;
		REP(i,r){
			int t,n,m,s;
			cin>>t>>n>>m>>s;
			FOR(j,cur,t){
				REP(k,M){
					if(cnt[k]){
						lg[k][j]=1;
					}
				}
			}
			if(s==0){
				cnt[m-1]--;
			}else{
				cnt[m-1]++;
			}
			cur=t;
		}
		int q;
		cin>>q;
		REP(i,q){
			int s,e,m;
			cin>>s>>e>>m;
			cout<<count(lg[m-1]+s,lg[m-1]+e,1)<<endl;
		}
	}

}

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

int main(){
    LL N, A, B;
    cin >> N >> A >> B;
    vector<LL> x(N);
    for(int i = 0;i < N;i++)    cin >> x[i];
    LL ans = 0;
    for(int i = 1;i < N;i++)    ans += min((x[i]-x[i-1])*A, B);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>

using namespace std;

const int MAX_N = 1e3 + 5;

int dist [MAX_N][MAX_N];
int ni [4] = {1, 0, -1, 0};
int nj [4] = {0, 1, 0, -1};

int main () {
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> zeros;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;

      if (c == '#') {
        zeros.push_back(make_pair(i, j));
      }
    }
  }

  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      dist[i][j] = -1;
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dist[i][j] = 1e9;
    }
  }

  queue<pair<int, int>> Q;
  for (auto pr : zeros) {
    Q.push(pr);
    dist[pr.first][pr.second] = 0;
  }

  int ans = 0;
  while (!Q.empty()) {
    pair<int, int> qtop = Q.front();
    Q.pop();

    int r = qtop.first;
    int c = qtop.second;
    
    ans = max(ans, dist[r][c]);
    
    for (int k = 0; k < 4; k++) {
      if (dist[r + ni[k]][c + nj[k]] > dist[r][c] + 1) {
        dist[r + ni[k]][c + nj[k]] = dist[r][c] + 1;
        Q.push(make_pair(r + ni[k], c + nj[k]));
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 20200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int id;
    edge(int t, int w) : to(t),id(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<edge>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }

int main(){

    int h_1,m_1,h_2,m_2,k; cin >> h_1 >> m_1 >> h_2 >> m_2 >> k;
    int time = (h_2-h_1)*60+(m_2-m_1) - k;
    cout << time << endl;
    return 0;
}

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

int main() {
  string S;
  int ans;
  cin >> S;
  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;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    int count=0;


    string s,t;
    cin>>s>>t;

    int k;
    int match;
    int ques;
    int hoge;
    int flag=false;

    for(int i=0;i<s.size()-t.size()+1;i++){
        string tmp=s.substr(i,t.size());
        // cout<<tmp<<endl;

        
        match=0;
        ques=0;

        for(int j=0;j<tmp.size();j++){


            // cout<<tmp[j]<<" "<<t[j]<<endl;

            if(tmp[j]==t[j])match++;
            if(tmp[j]=='?')ques++;


        }
        // cout<<match<<" "<<ques<<" "<<i<<endl;

        if(match+ques==t.size()){
            hoge=i;
            flag=true;
        }
    }

    if(!flag){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }

    REP(i,s.size()){
        if(i==hoge){
            cout<<t;
            i+=t.size()-1;
        }
        else if(s[i]=='?')cout<<"a";
        else cout<<s[i];

    }
    cout<<endl;












    // for(int i=0;i<s.size()-t.size()+1;i++){
    //     count=0;
    //     REP(j,t.size()){
    //         cout<<s[i+j];
    //         for(int k=0;k<t.size();k++){
    //             if(s[i+j]==t[k]){
    //                 count++;
    //             }else if(s[i+j]=='?'){
    //                 count++;
    //             }
    //                         cout<<"count:"<<count<<endl;
    //         }
    //     }cout<<endl;
    // }
    


    return 0;

}

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

int main() {
    int n, m;
    cin >> n >> m;
    long long resx = 0;
    for(int i=0; i<n; ++i) {
        long long tmp;
        cin >> tmp;
        resx -= (n - (2 * i) - 1) * tmp;
        resx %= MOD;
    }
    long long resy = 0;
    for(int i=0; i<m; ++i) {
        long long tmp;
        cin >> tmp;
        resy -= (m - (2 * i) - 1) * tmp;
        resy %= MOD;
    }

    cout << (resx * resy) % MOD << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 9000000000000000000 //9e18:極めて大きい値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 1000001 //10^6:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

int main(){
  ll N;
  cin >> N;
  ll pmemo[MAXR];
  REP(i, MAXR) pmemo[i] = 0;
  ll p = 1;
  ll ret = 0;
  while(p <= sqrt(N)){
    ++p;
    if(pmemo[p]) continue;
    for(int i = p; i <= sqrt(N); i += p) pmemo[i] = 1;
    ll pcnt = 0;
    while(N % p == 0){
      ++pcnt;
      N /= p;
    }
    //cout << p << endl;
    //cout << pcnt << endl;
    FOR(i, 1, INF){
      if(pcnt < i) break;
      ++ret;
      pcnt -= i;
    }
  }
  if(N > 1) ++ret;
  cout << ret << endl;
  return 0;
}


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


int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n), y(n);
  vector<int> a(n);
  rep(i, n) cin >> x[i] >> y[i] >> a[i];
  
  vector<vector<bool>> s(h, vector<bool>(w, true));
  rep(i, n) {
    switch(a[i]) {
      case 1:
        for (int j = 0; j <= x[i]-1; j++) {
          for (int k = 0; k <= h-1; k++) {
            s[k][j] = false;
          }
        }
        break;
        
      case 2:
        for (int j = x[i]; j <= w-1; j++) {
          for (int k = 0; k <= h-1; k++) {
            s[k][j] = false;
          }
        }
        break;
        
      case 3:
        for (int j = 0; j <= y[i]-1; j++) {
          for (int k = 0; k <= w-1; k++) {
            s[j][k] = false;
          }
        }
        break;
        
      case 4:
        for (int j = y[i]; j <= h-1; j++) {
          for (int k = 0; k <= w-1; k++) {
            s[j][k] = false;
          }
        }
        break;

    }
  }
  
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (s[i][j]) {
        ans++;
      }
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
package main
import (
        "bufio"
        "fmt"
        "os"
        "strings"
        "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

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

func Atoi2(c string) int {
  tmp, _ := strconv.Atoi(c)
  return tmp
}

func swap(data []int, a int,b int){
  tmp := data[b]
  data[b] = data[a]
  data[a] = tmp
}

func sort(data []int) {
  if data[0]>data[1] {
    swap(data,0,1)
  }
  if data[1]>data[2]{
    swap(data,1,2)
  }
  if data[0]>data[1]{
    swap(data,0,1)
  }
}

func main() {
	input := nextLine()
	rec := strings.Split(input, " ")
	var hoge []int

	for _, c := range rec{
		hoge = append(hoge, Atoi2(c))
	}

  sort(hoge)

	fmt.Printf("%d %d %d\n",hoge[0],hoge[1],hoge[2])
}


Measured memory_bytes: 1092