akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
  vector<int> c(26);
  for(int i=0;i<26;i++)
    cin>>c.at(i);
  vector<vector<int>> s(d,vector<int>(26));
  for(int i=0;i<d;i++)
    for(int j=0;j<26;j++)
      cin>>s.at(i).at(j);
  vector<int> t(d);
  for(int i=0;i<d;i++){
    cin>>t.at(i);
    t.at(i)--;
  }
  vector<set<int>> l(26);
  for(int i=0;i<26;i++)
    l.at(i).insert(0);
  int64_t p=0;
  for(int i=1;i<=d;i++){
    p+=s.at(i-1).at(t.at(i-1));
    l.at(t.at(i-1)).insert(i);
    for(int j=0;j<26;j++)
      p-=c.at(j)*(i-*rbegin(l.at(j)));
  }
  for(int i=0;i<26;i++)
    l.at(i).insert(d+1);
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int di,qn;
    cin>>di>>qn;
    qn--;
    int qo=t.at(di-1);
    l.at(qo).erase(di);
    auto io=lower_bound(l.at(qo).begin(),l.at(qo).end(),di);
    auto in=lower_bound(l.at(qn).begin(),l.at(qn).end(),di);
    p+=s.at(di-1).at(qn)-s.at(di-1).at(qo);
    p+=(di-*prev(in,1))*(*in-di)*c.at(qn)-(di-*prev(io,1))*(*io-di)*c.at(qo);
    cout<<p<<endl;
    l.at(qn).insert(di);
    t.at(di-1)=qn;
  }
}

Measured memory_bytes: 3604
#!/bin/bash

read A B C D

AC=$(echo $((A-C)) | awk '{print ($1<0)?-$1:$1}')
AB=$(echo $((A-B)) | awk '{print ($1<0)?-$1:$1}')
BC=$(echo $((B-C)) | awk '{print ($1<0)?-$1:$1}')

[ $AC -le $D -o $AB -le $D -a $BC -le $D ] && ANS="Yes" || ANS="No"
echo $ANS

Measured memory_bytes: 704
import Control.Applicative ((<$>))
import Control.Monad (unless)
import Data.List (intercalate)
import Data.List.Split (splitOn, split, startsWithOneOf)
import Data.Char (toUpper, toLower)

main :: IO ()
main = do
  [nm, tp] <- words <$> getLine
  unless (tp == "X") $ do
    putStrLn $ solve nm tp
    main

solve :: String -> String -> String
solve nm tp = f tp $ toWords nm
  where f t ss | t == "D" = intercalate "_" ss
               | t == "U" = concat . map capitalize $ ss
               | otherwise = concat . g $ ss
        g (s:ss) = s : map capitalize ss
          
toWords :: String -> [String]
toWords s | '_' `elem` s = splitOn "_" s
          | otherwise = map (map toLower) $ split (startsWithOneOf ['A'..'Z']) s

capitalize :: String -> String
capitalize [] = []
capitalize (s:ss) = toUpper s : ss



Measured memory_bytes: 4060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

vector <int> mod,d;
int N,K;
int a[550];
int sum=0,sum_mod=0;

void qiuys(int x)
{
    for(int i=1;i*i<=x;i++)
    {
        if(x%i==0)
        {
            d.push_back(i);
            if(i*i!=x)
            {
                d.push_back(x/i);//cout<<x/i<<endl;
            }

        }
    }
}

void qiuyus(int x)
{
    for(int i=0;i<N;i++)
    {
        int modx=a[i]%x;
        if(modx) mod.push_back(modx);
        sum_mod+=modx;
    }
}

int main()
{
    cin>>N>>K;
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }//cout<<sum<<endl;
    qiuys(sum);
    sort(d.begin(),d.end(),greater<int>() );
//    for(int i=0;i<d.size();i++)
//    {
//        cout<<d[i]<<endl;
//    }
    for(int i=0;i<d.size();i++)
    {
        mod.clear();
        sum_mod=0;
        qiuyus(d[i]);
        sort(mod.begin(),mod.end(),greater<int>());
//        for(int a=0;a<mod.size();a++)
//    {
//        cout<<mod[a]<<endl;
//    }
        int step=0;
        if(sum_mod%d[i]!=0)
            continue;
        int times=sum_mod/d[i];
        for(int j=0;j<times;j++)
        {
            step+=d[i]-mod[j];//cout<<d[i]<<" "<<mod[i]<<" "<<step<<endl;
        }
        if(step<=K)
        {
            cout<<d[i]<<endl;
            break;
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i, n)   for(int i = 0;            i <  (int)(n); i++)
#define cREP(i, n)  for(int i = 1;            i <= (int)(n); i++)
#define rREP(i, n)  for(int i = (int)(n) - 1; i >= 0;        i++)
#define rcREP(i, n) for(int i = (int)(n);     i >  0;        i++)

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

    std::string s;
    int K;

    std::cin >> s;
    std::cin >> K;

    std::set<std::string> substr_set;
    REP(begin_index, s.size()) {
        cREP(i, s.size() - begin_index) {
            std::string substr = s.substr(begin_index, i);
            if(substr_set.size() <= 5) {
                substr_set.insert(substr);
            }
            else if(substr < *(--substr_set.end())) {
                substr_set.erase(--substr_set.end());
                substr_set.insert(substr);
            }
            else {
                break;
            }
        }
    }

    auto itr = substr_set.begin();
    REP(i, K - 1) {
        itr++;
    }
    std::cout << *itr << std::endl;
    
    return 0;
}


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

ll n, q, temp, s;

int main() {
  cin >> n;
  vector<ll> a(100000);
  rep (i, n) {
    cin >> temp;
    temp--;
    a[temp]++;
  }
  cin >> q;
  vector<ll> b(q);
  vector<ll> c(q);
  rep (i, q) {
    cin >> b[i] >> c[i];
    b[i]--;c[i]--;
  }
  s = 0;
  rep (i, 100000) {
    s += a[i] * (i+1);
  }
  rep (i, q) {
    s -= a[b[i]] * (b[i]+1);
    s += a[b[i]] * (c[i]+1);
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
vector<int> divi;
void printDivisors(int n)
{
   // Note that this loop runs till square root
   for (int i = 1; i <= sqrt(n); i++)
   {
      if (n % i == 0)
      {
         // If divisors are equal, print only one
         if (n / i == i)
            divi.pub(i);
         else // Otherwise print both
           divi.pub(i),divi.pub(n/i);
      }
   }
}
int32_t main(){
   fastIO
   int n;
   cin>>n;
   vector<int> v;
   unordered_map<int,int> m;
   rep(i,0,n){
      int t;
      cin>>t;
      v.pub(t);
      m[t]++;
   }
   if(m[1]>=2){
      cout<<0<<"\n";
      return 0;
   }
   if(m[1]==1){
      cout<<1<<"\n";
      return 0;
   }
   int ans=0;
   rep(i,0,n){
      divi.clear();
      printDivisors(v[i]);
      int ok=1;
      rep(j,0,divi.sz){
         if(m[divi[j]]>=1){
            if(divi[j]==v[i]&&m[v[i]]>=2)ok=0;
            if(divi[j]!=v[i])ok=0;
         }
         if(!ok)break;
      }
      if(ok)ans++;
   }
   cout<<ans<<"\n";
   return 0;
}

Measured memory_bytes: 33348
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	while(n)
	{
		if(n%10==7)
		{
			cout<<"Yes";
			return 0;
		}
		n/=10;
	}
	cout<<"No";
	return 0;
} 

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

int main(){
	int* s;
	int n,i,sum=0,min=100;
	scanf("%d",&n);

	s=(int *)malloc(sizeof(int)*n);

	for(i=0;i<n;i++){
		scanf("%d",&s[i]);
	}

	for(i=0;i<n;i++){
		sum+=s[i];
		if(s[i]%10!=0&&min>s[i]){
			min=s[i];
		}
	}

	if(sum%10==0){
		if(min!=100) sum-=min;
		else sum=0;
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;
const int MAXN = 100010;

int n, a[MAXN], maxv = 0, minv = 1e9;

void quit( bool flag ) {
	puts( flag ? "Yes" : "No" );
	exit(0);
}

bool check1() {
	return minv <= n/2;
}
bool check2() {
	return n == minv+1;
}
bool check3() {
	int m = maxv, left = n;
	for( int i = 0; i < n; ++i )
		if( a[i] == minv ) --m, --left;
	return m > 0 && m <= left/2;
}

int main() {
	scanf( "%d", &n );
	for( int i = 0; i < n; ++i ) {
		scanf( "%d", a+i );
		minv = min( minv, a[i] );
		maxv = max( maxv, a[i] );
	}
	if( maxv - minv >= 2 ) quit(0);
	if( minv == maxv ) quit( check1() || check2() );
	else quit( check3() );
	return 0;
}



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

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

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int idx = 0,
        ans = 0;
    while (idx < N) {
        ans++;

        int asc = idx + 1,  // 昇順
            des = idx + 1;  // 降順
        while (asc < N && A[asc - 1] <= A[asc]) {
            asc++;
        }
        while (des < N && A[des - 1] >= A[des]) {
            des++;
        }
        idx = max(asc, des);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];


signed main(){
	IOS();
	ll n;
	cin >> n;
	ll h[114514];
	for (int i = 1;i <= n;++i) {
		cin >> h[i];
	}
	ll dp[114514];
	dp[1] = 0; dp[2] = abs(h[1] - h[2]);
	for (int i = 3;i <= n;++i) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[n] << endl;
	
}

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

int main() {

    int N;
    cin >> N;
    int r = N % 1000;
    if(r==0) cout << 0 << endl;
    else cout << 1000 - r << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int a[n][3];
    for(int i=0; i<n; i++) {
    	for(int j=0; j<3; j++) {
    		scanf("%d", &a[i][j]);
    	}
    }
    int dp[n][3];
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for(int i=1; i<n; i++) {
    	for(int j=0; j<3; j++) {
    		dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + a[i][j];
    	}
    }
    printf("%d\n", max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])));
    return 0;
}

Measured memory_bytes: 2560
fun main(args: Array<String>) {
    // 入力
    val input = readLine()
    
    // 変換
    val durations = input!!.split(" ").map(String::toInt)
    val sortedDurations = durations.sorted()

    // 計算
    val answer = sortedDurations[0] + sortedDurations[1]
    
    // 出力
    println(answer)
}

Measured memory_bytes: 37600
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
        ll D, G;
        cin >> D >> G;
        ll P[11];
        ll C[11];
        for(int i = 0; i < D; ++i)
        {
                cin >> P[i] >> C[i];
        }

        ll ans = 1e9;

        for(int i = 0; i < (1<<D); ++i)
        {
                ll point = 0;
                ll cnt = 0;
                ll maxval = -1;
                for(int j = 0; j < D; ++j)
                {
                        if(i>>j & 1)
                        {
                                point += C[j];
                                point += 100 * (j+1) * P[j];
                                cnt += P[j];
                        }
                        else
                        {
                                maxval = j;
                        }
                }

                if(point < G)
                {
                        int s1 = 100 * (maxval + 1);
                        int need = (G - point + s1 - 1) / s1;
                        if(need >= P[maxval])
                        {
                                continue;
                        }
                        cnt += need;
                }

                ans = min(ans, cnt);
        }

        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i,m,n) for(ll i=m ; i<n ; i++)
#define forr(i,m,n) for(ll i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N =1e5+5;
const ll mod=ll(1e9)+7;
using namespace std;
ll fastpow(ll b, ll e) {
    if (!e) re 1;
    ll ret = fastpow(b, e >> 1);
    ret = (ret * ret) % mod;
    if (e & 1) ret = (ret * b) % mod;
    re ret;
}
ll nCr(ll n,ll r){
	ll ans=1;
	for(int i=n;i>=n-r+1;i--){
		ans=ans*i%mod;
	}
	for(int i=1;i<=r;i++){
		ans=ans*fastpow(i,mod-2)%mod;
	}
	re ans;
}
ll n,a,b;
int main()
{
    IO;

    cin>>n>>a>>b;

    cout<<((fastpow(2,n)-nCr(n,a)-nCr(n,b)-1+mod+mod)%mod);
}




Measured memory_bytes: 384
typedef struct point{
    int x_elem;
    int y_elem;
}point;

#include <stdio.h>

int main(void) {
  //point:正方形の頂点
  //diff:2点間のx,y軸方向の距離
  point point[4], diff;

  //入力
  scanf("%d %d %d %d", &point[0].x_elem, &point[0].y_elem, &point[1].x_elem, &point[1].y_elem);

  //2点間のx,y軸方向の距離
  diff.x_elem = point[1].x_elem - point[0].x_elem;
  diff.y_elem = point[1].y_elem - point[0].y_elem;

  //残りの２点を算出
  point[2].x_elem = point[1].x_elem - diff.y_elem;
  point[2].y_elem = point[1].y_elem + diff.x_elem;
  point[3].x_elem = point[0].x_elem - diff.y_elem;
  point[3].y_elem = point[0].y_elem + diff.x_elem;

  //出力
  printf("%d %d %d %d\n", point[2].x_elem, point[2].y_elem, point[3].x_elem, point[3].y_elem);

  return 0;
}

Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int A, B;

        public void Run()
        {
            var line = Input.ReadIntArray();
            A = line[0];
            B = line[1];
            int ret = (B - A) * (B - A - 1) / 2 - A;
            Console.WriteLine(ret);

        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13268
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class Pair
{
	public int I { get; private set; }
	public int J { get; private set; }

	public Pair(int i, int j)
	{
		I = i;
		J = j;
	}
}


public class D
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int H = Int32.Parse(args[0]);
		int W = Int32.Parse(args[1]);
		int D = Int32.Parse(args[2]);

		Pair[] pairs = new Pair[H * W + 1];
		for(int i = 1; i <= H; i++)
		{
			args = Console.ReadLine().Split(' ');
			for(int j = 1; j <= W; j++)
				pairs[Int32.Parse(args[j-1])] = new Pair(i,j);
		}

		int Q = Int32.Parse(Console.ReadLine());
		int[] L = new int[Q];
		int[] R = new int[Q];
		for(int i = 0; i < Q; i++)
		{
			args = Console.ReadLine().Split(' ');
			L[i] = Int32.Parse(args[0]);
			R[i] = Int32.Parse(args[1]);
		}

		int[] csum = new int[H * W + 1];  // csum[1] = ... = csum[D] = 0
		for(int i = D + 1; i <= H * W; i++)
		{
			Pair current = pairs[i];
			Pair prev = pairs[i - D];
			int mp = Math.Abs(current.I - prev.I) + Math.Abs(current.J - prev.J);
			csum[i] = csum[i - D] + mp;
		}

		for(int i = 0; i < Q; i++)
			Console.WriteLine(csum[R[i]] - csum[L[i]]);
	}	
}





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

def main():
    nums = sorted(map(int, input().split()))
    plus1 = nums[2] - nums[1]
    if (nums[2] - nums[0] - plus1) % 2 == 0:
        print(int(plus1 + (nums[2] - nums[0] - plus1) / 2))
    else:
        print(int(plus1 + ((nums[2] - nums[0] - plus1) + 1) / 2 + 1))

if __name__ == '__main__':
    main()


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

int main()
{
    int r,g,b;
    cin>>r>>g>>b;
    

    if(((r*100)+(g*10)+b) % 4 == 0)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
def search_linear(target_list, target_length, key_value):
    i = 0
    target_list.append(key_value)
    while target_list[i] != key_value:
        i += 1
    target_list.pop()
    return i != target_length

target_length = int(input())
target_list = list(map(int,input().split()))
key_length = int(input())
key_list = list(map(int,input().split()))

exist_count = 0
for key_value in key_list:
    exist_count += 1 if search_linear(target_list, target_length, key_value) else 0
print(exist_count)


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

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort(v.begin(), v.end())
#define veci(a, n) vector<int> a(n)
#define vecs(a, n) vector<string> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed

int main(){
    int N, K;
    cin >> N >> K;
    int ans=1;
    rep(i, N){
        if(ans > K) ans += K;
        else ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
        #define F first
        #define S second
        using ll = long long;
        const ll mod = 1000000007;
        const ll infi = 1000000000000000;
        const ll md = 998244353;
        using namespace std;
        using vl = vector<ll>;
        using pll =  pair<ll,ll>;
        
       
        void solve(){
           ll x;
           cin>>x;
           string p = to_string(x);
           for(int j=1;j<p.size();j++){
           string s = to_string(x);
           for(int i=j;i<s.size();i++) s[i] ='0';
           ll mn = stoi(s) , mx = (mn/100)*105;
           if(x>=mn&&x<= mx){ cout<<1;return;}
           
           }
           cout<<0;
        }
        
        int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            solve();
            return 0;
        } 

Measured memory_bytes: 256
s = input()

l = list(s)

x = int(l[0]+l[1])
y = int(l[2]+l[3])

if 0 < x < 13 and (y > 12 or y == 0):
    print("MMYY")
elif (x > 12 or x == 0) and 0 < y < 13:
    print("YYMM")
elif x > 12 or y > 12 or (x == 0 and y == 0):
    print("NA")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 9136
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define INF (1 << 28)
#define MAX_V 1000

long long int d[MAX_V][MAX_V];
long long int A[400][400] = {};
bool check[400][400] = {};

void warshall_floyd(int n){
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			for (int k = 0; k < n; k++){
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
				if(i != j && j != k && k != i && d[j][k] == d[j][i] + d[i][k]){
					check[j][k] = true;
				}
			}
		}
	}
}

int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> A[i][j];
			d[i][j] = A[i][j];
		}
	}
	warshall_floyd(N);
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(d[i][j] != A[i][j]){
				cout << "-1" << endl;
				return 0;
			}
		}
	}
	long long int ans = 0;
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(!check[i][j]){
				ans += A[i][j];
			}
		}
	}
	ans /= 2;
	cout << ans << endl;
	return 0;
}



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

#define pb push_back
#define rb  pop_back
#define rf  pop_front
#define ins insert
#define f   first
#define s   second
#define um  unordered_map
#define us  unordered_set
#define pq  priority_queue

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long ll;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector<double> vd;
typedef pair<double,double> pd;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef us<int> si;
typedef us<double> sd;
typedef us<ll> sll;
typedef vector<vd> md;


const ll MAX = 1e5+5;
const int N = 200043;
const int MOD = 998244353;

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define EE '\n'
#define PI 3.14159265
#define g(a,b) a>b?a:b
#define l(a,b) a<b?a:b
#define SOT(A) sort(A.begin(),A.end())
#define SOTR(A) sort(A.rbegin(),A.rend())
#define REV(a) reverse(ALL(a))

// LOOP Control Statements
#define forn(i,j,n) for ( auto i=j ; i<n ; i++ )
#define fornd(i,j,n) for ( auto i=j ; i>n ; i-- )
#define FORE(i, b) for(auto &i:b)


#define SQ(i) (i*i)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define tcase(term) int tc;cin>>tc;for(int term=0; cout<<EE,term<tc;term++)


int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
    // tcase(term)
    IO
    {

        vl res(1000001,0);
        int N,W;
        cin>>N>>W;
        ll c,b;
        forn(i,0,N){
        	cin>>c>>b;
        	fornd(j,W,c-1){
        		res[j]=max(res[j],res[j-c]+b);
        	}
        }
        cout<<res[W];

    }
}



Measured memory_bytes: 8064
def main():
    N = int(input().strip())

    o = [6, 2, 10, 3, 9, 4, 8, 12]
    e = [2, 10, 3, 9, 4, 8, 6, 12]
    if N == 3:
        S = [2, 5, 63]
    else:
        l = o if N % 2 != 0 else e
        S = []
        for i in range(N):
            S.append(l[i % len(l)] + 12*(i//len(l)))

    return ' '.join(map(str, S))


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 5100
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int X,Y,Z,K;
vi A,B,C;
vi AB,res;
signed main(){

    in(X,Y,Z,K);
    A.resize(X);
    B.resize(Y);
    C.resize(Z);
    in(A,B,C);

    for(auto a:A){
        for(auto b:B){
            AB.pb(a+b);
        }
    }
    sort(rall(AB));
    rep(i,min(K,(int)AB.size())){
        for(auto c:C){
            res.pb(AB[i]+c);
        }
    }
    sort(rall(res));
    rep(i,K){
        out(res[i]);
    }

    return 0;
}


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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, a, b) for (int i = (int)(a - 1); i >= b; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX / 3

int main() {
  cin.sync_with_stdio(false);
  double d;
  cin >> d;
  printf("%.10f\n", max((int)d + 1.0, d * sqrt(2.0)));
  return 0;
}



Measured memory_bytes: 3208
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static Dictionary<int, int> dic;

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var k = int.Parse(spl[0]);
        var s = int.Parse(spl[1]);

        long c = 0;
        for(int i=0; i<=k; i++) {
            for(int j=0; j<=k; j++) {
                var l = s-i-j;
                if(0<=l && l<=k && i + j + l == s) c++;
            }
        }

        return c;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<iostream>

using namespace std;
#define ll long long

const ll MOD = 1e9+7;

ll pow(ll a, ll b){
	ll res = 1;
	while(b){
		if(b&1) res = (res * a) % MOD;
		b >>= 1;
		a = (a * a) % MOD;
	}
	return res;
}

ll A(ll a,ll b){
	ll res = 1;
	while(b){
		res = (res * a) % MOD;
		b--; a--;
	}
	return res;
}

ll C(ll a,ll b){
	return (A(a,b) * pow(A(b,b),MOD-2))%MOD;	
}

int main(){
//	freopen("in","r",stdin);
	int n,a,b; cin >> n >> a >> b;
	ll res = pow(2,n);
	res = (res + MOD + MOD - C(n,a) - C(n,b) - 1)%MOD;
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;
// cout << typeid('変数').name() << endl;

ll conbination(int n,int k){
    ll a=1;
    ll b=1;
    if(n<k) return 0;
    for(int i=0;i<k;++i){
        a*=(n-i);
        b*=(k-i);
    }
    return a/b;
}

int main() {
    int n;
    cin >> n;
    map<int,int> a;
    vector<int> b(n);
    for(int i=0;i<n;i++){
        int input;
        cin >> input;
        b.at(i) = input;
        a[input]++;
    }
    ll sum=0;
    for (auto i:a){
        if(i.second>=2){
            sum+=conbination(i.second,2);
        }
    }
    for (int i=0;i<n;++i){
        int now = b.at(i);
        int diff = conbination(a[now],2)-conbination(a[now]-1,2);
        cout << sum - diff << endl; 
    }
    return 0;
}



Measured memory_bytes: 8320
import java.util.*
import kotlin.math.*
import java.io.BufferedReader
import java.io.InputStreamReader


private var fs = BufferedReader(InputStreamReader(System.`in`))
private fun readLn() = fs.readLine()!! // string line
private fun readStrings() = readLn().split(" ") // list of strings
private fun readLong() = readLn().toLong()
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
private fun readInt() = readLn().toInt() // single int
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    solveAtc()
}
fun solveAtc() {
    var (x,n) = readInts()
    if(n == 0){
        println(x)
        return
    }
    var a = readInts()
    var best= Int.MAX_VALUE
    var ans= Int.MAX_VALUE
    for(i in -50..110){
        if (!a.contains(i) && best > abs(x - i)) {
            ans = i
            best = abs(x-i)
        }
        else if(best == abs(x-i)) ans = min(ans,i)
    }
    println(ans)
}

Measured memory_bytes: 36380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	int h, w;
	cin >> h >> w;
	string board[50];
	for(int i = 0; i < h; i++){
		cin >> board[i];
	}
	int dx[8] = {1,0,-1,0,1,-1,-1,1};
	int dy[8] = {0,1,0,-1,1,1,-1,-1};
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(board[i][j] == '#') continue;
			
			int cnt = 0;
			for(int d = 0; d < 8; d++){
				int in = i + dy[d];
				int jn = j + dx[d];
				
				if(in < 0 || in >= h) continue;
				if(jn < 0 || jn >= w) continue;
				if(board[in][jn] == '#') cnt++;	
			}
			board[i][j] = cnt + '0';
		}
	}
	for(int i = 0; i < h; i++)
		cout << board[i] << endl;
	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        boolean enable=false;
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        if(s.contains("7")){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");  
        }
        
    }

}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    ll acc_A = 0, acc_B = 0;
    ll A[N]; rep(i, N) {cin >> A[i]; acc_A += A[i];}
    ll B[N]; rep(i, N) {cin >> B[i]; acc_B += B[i];}
    priority_queue<ll> pq;
    if(acc_A < acc_B) cout << -1 << endl;
    else{
        vector<ll> lack;
        rep(i, N){
            if(A[i] < B[i]) lack.push_back(B[i]-A[i]);
            else if(A[i] > B[i]) pq.push(A[i]-B[i]);
        }
        int ans = lack.size();
        if(lack.empty()) cout << 0 << endl;
        else{
            ll op = pq.top();
            pq.pop();
            ans++;
            rep(i, lack.size()){
                ll val = lack[i];
                while(val > 0){
                    if(op == 0){
                        op = pq.top();
                        pq.pop();
                        ans++;
                    }
                    if(val > op){
                        val -= op;
                        op = 0;
                    }
                    else{
                        op -= val;
                        val = 0;
                    }
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}

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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


struct process{
	string name;
	int time;
};

signed main(){

	int n;
	deque<int> d;

	cin >> n;
	for (int i = 0; i < n; i++){
		string cmd;
		int a;
		cin >> cmd;
		if (cmd == "insert"){
			scanf("%lld", &a);
			d.push_front(a);
		}else if (cmd == "delete"){
			cin >> a;
			auto j = find(d.begin(), d.end(), a);
			if (j!= d.end())
				d.erase( j );
		}
		else if (cmd == "deleteFirst")
			d.pop_front();
		else if (cmd == "deleteLast")
			d.pop_back();
	}

	for (auto i = d.begin(); i != d.end(); i++){
		cout << *i;
		if (i != d.end()-1)
			cout << " ";
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 11072
#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <bitset>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define per(i,x,n) for(int i=n-1;i>=x;i--)
using namespace std;
#define ll long long
//head
int n, L;
int l, r, mid;
struct Bottle {
    int up, down, val;
    bool operator < (const Bottle a)const {
        return val > a.val;
    }
} a[100005];
ll b[100005], c[100005], sum[100005];
bool check(int x) {
    x--;
    rep(k, 1, n + 1) {
        if(c[k] <= x)
            continue;
        ll p = L - a[k].up, go = 0;
        if(k <= x && sum[x + 1] - a[k].val >= p)
            return 1;
        if(k > x && sum[x] >= p)
            return 1;
    }
    return 0;
}
inline char gc() {
    static char buf[1<<20], *head = buf, *tail = buf;
    return (head == tail && (tail = (head = buf) + fread(buf, 1, 1 << 20, stdin), head == tail)? -1: *head++);
}
template <typename T> inline bool read(T &x) {
    static bool f;
    static char c;
    for (c = gc(), f = false; !isdigit(c); c =gc()) {
        if (c == EOF)
            return false;
        else if (c == 45)
            f = true;
    }
    for (x = 0; isdigit(c); c = gc())
        x = x * 10 + c - 48;
    if (f)
        x = -x;
    return true;
}
int main() {
    read(n);read(L);
    rep(i, 1, n + 1)read(a[i].up),read(a[i].down),a[i].val = a[i].up - a[i].down;
    rep(i, 1, n + 1)read(b[i]);
    sort(a + 1, a + n + 1);
    rep(i, 1, n + 1)sum[i] = sum[i - 1] + a[i].val;
    ll cnt = 1, dis = 0;
    rep(i, 2, n + 1) {
        dis += (a[i].val - b[cnt]);
        if(dis <= 0)
            break;
        cnt++;
    }
    c[1] = cnt;
    int k = 2;
    for(; k <= n; k++) {
        if(cnt < k - 1 || cnt == n)
            break;
        dis += (a[k - 1].val - a[k].val);
        while(dis > 0 && cnt < n)
            cnt++, dis += (a[cnt + 1].val - b[cnt]);
        c[k] = cnt;
    }
    for(; k <= n; k++)
        c[k] = cnt;
    int day = 1;
    for(int i = 1; a[i].val > 0 && i <= n; i++, day++);
    l = 1, r = day;
    while(l < r) {
        mid = (l + r) / 2;
        if(check(mid))
            r = mid;
        else
            l = mid + 1;
    }
    if(check(l))
        cout << l << endl;
    else
        cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 7572
buttonList = list(map(int,input().split()))
a = buttonList[0]
b = buttonList[1]
sum = 0

if(a >= b):
  sum += a
  a -= 1
elif(a < b):
  sum += b
  b -=1

if(a >= b):
  sum += a
  a -= 1
elif(a < b):
  sum += b
  b -=1

print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;
 
string grid[1000];

int h_move[4] = {-1, 0, 1, 0};
int w_move[4] = {0, -1, 0, 1};
int main(){
    int H;
    int W;
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        cin >> grid[i];
    }


    queue <pair<int, int> > q;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(grid[i][j] == '#'){
                q.push(make_pair(i, j));
            }
        }
    }
    queue <pair<int, int> > next_q;

    int ans = 0;
    while(true){
        while(!q.empty()){
            auto cur = q.front();
            q.pop();
            bool did_move = false;
            for(int i = 0; i < 4; i++){
                int next_h = cur.first + h_move[i];
                int next_w = cur.second + w_move[i];
                if(0 <= next_h && next_h < H && 0 <= next_w && next_w < W 
                    && grid[next_h][next_w] == '.'){
                    grid[next_h][next_w] = '#';
                    next_q.push(make_pair(next_h, next_w));
                }
            }
        }
        if(next_q.empty()){
           break; 
        }   
        ans ++;
        swap(q, next_q);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


int main() {
    int n; cin >> n;
    ld dp[3000][3000];
    dp[0][0] = 1;
    rep1(i,n+1){
        ld p;
        cin >> p;
        dp[i][0] = dp[i - 1][0] * (1 - p);
        rep1(j,i+1) dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p;
    }
    ld ans = 0;

    for(int i = n; i > n - i; i--) ans += dp[n][i];
    cout << setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 140800
#include<stdio.h>

int main(void)
{
	long long int x;
	scanf("%lld",&x);
	long long int i,a=1,b;
	long long int ans,min=x+1;
	
	while(x>=a*a){
		if(x%a == 0){
			ans = a+x/a-2;
			if(ans<min)
				min = ans;
			}
		a++;
	}
	
	printf("%lld",min);
	return 0;
}
		
	

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    x: i64,
  }
  let l = x / 500;
  let s = (x - l * 500) / 5;

  puts!("{}\n", l * 1000 + s * 5);
}


Measured memory_bytes: 4352
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, m, d;
	cin >> n >> m >> d;

	double ans = (double)(n-d)/n/n*(m-1);
	if(d) ans *= 2;
	setp(10);
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
  int a,b,x;
  cin>>a>>b>>x;
  if(x<=(a+b) && a<=x)
  {
    cout<<"YES"<< endl;
  }
  else 
  {
    cout<<"NO"<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
using namespace std;
int n,a[100002];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    int sum=0;
    for(int i=1;i<=n;i++)sum^=a[i];
    if(sum==0)puts("Yes");
    else puts("No");
}


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

using namespace std;

typedef long long ll;

const int maxn=2e5+5,mod=1e4+7;
const double pi=acos(-1);

int main()
{
    int k,n;
    while(scanf("%d%d",&k,&n)!=EOF)
    {
        int a[maxn];
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        int dis=a[n-1]-a[0];
        for(int i=1;i<n;i++)
            dis=min(dis,k-a[i]+a[i-1]);
        printf("%d\n",dis);
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int n;
cin>>n;
int b[200000];
bool c[200000];
for(int i=0;i<n;i++)cin>>b[i], b[i]--, c[i]=0;
int ans = 0;
int now = 0;
for(int i = 0;i<n;i++){
ans++;
now = b[now];
if(c[now]){
    ans=-1;
    break;
}
else if(now==1)break;
else {
    
c[now]=1;
}
}
cout<<ans<<endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> c(n);
	FOR(i, 1, n) {
		FOR(j, i + 1, n + 1) {
			int notUse = j - i;
			int Use = abs(i - x) + abs(j - y) + 1;
			c[min(notUse, Use)]++;
		}
	}
	FOR(i, 1, n) {
		cout << c[i] << endl;
	}
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#define INF 123456789

int main()
{
	char str[30];
	scanf("%s", str);
	// かぶってないフラグ
	bool flag = true;
	for (int a = 0; a < 30; a++){
		if (str[a] == '\0') break;
		for (int b = a + 1; b < 30; b++){
			if (str[a] == str[b])
			{
				flag = false;
				break;
			}
		}
		if (flag == false)break;
	}

	if (flag == true) puts("yes");
	else puts("no");

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int n; cin>>n;
        string s=to_string(n);
        int sum=0;
        rep(i,s.size())sum+=s[i]-'0';
        cout<<(n%sum==0?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
ans=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
  if s[i]=='R':
    s[i]=1
  elif s[i]=='G':
    s[i]=2
  elif s[i]=='B':
    s[i]=4
for i in range(n):
   for j in range(i+1,n):
      k=2*j-i
      if k>=n:
        continue
      if s[i]+s[j]+s[k]==7:
        ans-=1
print(ans)


Measured memory_bytes: 9148