akhauriyash/Code-Regression huggingface dataset:
import sys
from copy import deepcopy
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row_list(N): return [i_list() for _ in range(N)]
sys.setrecursionlimit(10 ** 6)
INF = float('inf')

def main():
    d = i_input()
    c_list = i_list()
    s_list = i_row_list(d)

    output_list = []

    last_list = [0] * 26

    for day in range(1,d+1):
        result = 0
        max_point = -INF
        for i in range(26):
            plus_point = s_list[day-1][i]
            minus_point = 0
            for j in range(26):
                if i == j:
                    continue
                minus_point += c_list[j] * (day - last_list[j])
            sum_point = plus_point - minus_point

            if day != d:
                last_list2 = deepcopy(last_list)
                last_list2[i] = day
                max_point2 = -INF
                for k in range(26):
                    plus_point2 = s_list[day][i]
                    minus_point2 = 0
                    for h in range(26):
                        if k == h:
                            continue
                        minus_point2 = c_list[h] * (day+1 - last_list[h])
                    sum_point2 = plus_point2 - minus_point2
                    if sum_point2 > max_point2:
                        max_point2 = sum_point2
                    continue
            else:
                max_point2 = 0
                
            if sum_point + max_point2 > max_point:
                result = i + 1
                max_point = sum_point
        output_list.append(result)
        last_list[result-1] = day

    for out in output_list:
        print(out)

if __name__ == '__main__':
    main()


Measured memory_bytes: 71100
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
L=[[0 for i in range(w)]for i in range(h)]
R=[[0 for i in range(w)]for i in range(h)]
D=[[0 for i in range(w)]for i in range(h)]
U=[[0 for i in range(w)]for i in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            if j==0:
                R[i][j]=1
            else:
                R[i][j]=R[i][j-1]+1

        if s[h-i-1][w-j-1]=='.':
            if j==0:
                L[h-i-1][w-j-1]=1
            else:
                L[h-i-1][w-j-1]=L[h-i-1][w-j]+1


        if s[h-i-1][w-j-1]=='.':
            if i==0:
                U[h-i-1][w-j-1]=1
            else:
                U[h-i-1][w-j-1]=U[h-i][w-j-1]+1

        if s[i][j]=='.':
            if i==0:
                D[i][j]=1
            else:
                D[i][j]=D[i-1][j]+1


for i in range(h):
    for j in range(w):
        ans=max(ans,L[i][j]+R[i][j]+D[i][j]+U[i][j]-3)

print(ans)

Measured memory_bytes: 314248
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,M,P = map(int,input().split())
ABC = [[int(x) for x in input().split()] for _ in range(M)]

INF = 10 ** 18
dist = [INF] * (N+1)
dist[1] = 0

loop = False
for i in range(2*N+100):
    for a,b,c in ABC:
        x = dist[a] + P - c
        if dist[b] > x:
            dist[b] = x
            if b == N and i > N:
                loop = True

if loop:
    answer = -1
else:
    answer = -dist[N]
    if answer < 0:
        answer = 0

print(answer)


Measured memory_bytes: 44700
#define _CRT_SECURE_NO_DEPRECATE
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define ll  long long
 
int main() {
	//freopen("test.txt", "r", stdin);
	ll a,b,c; cin>>a>>b>>c;
	if(c-a-b<=0) {cout<<"No"<<endl; return 0;}
	if(4*a*b < (c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll lcs(string s,string t,ll m,ll n)
{
    ll dp[m+1][n+1];
    for(ll i=0;i<=m;i++)
    {
        for(ll j=0;j<=n;j++)
        {
            if( i==0 || j==0 )
            dp[i][j]=0;
            else if( s[i-1]==t[j-1] )
            dp[i][j]=dp[i-1][j-1]+1;
            else
            dp[i][j]=max( dp[i-1][j],dp[i][j-1] );
        }
    }

    ll len= dp[m][n];
 //   cout<<dp[m][n]<<endl;
    char a[len+1];
    a[len]='\0';
    while(m>0 && n>0)
    {
        if( s[m-1]==t[n-1]) 
        {
          a[len-1]=t[n-1];
          m--; n--;len--;
        }
        else if( dp[m-1][n]>dp[m][n-1] )
        m--;
        else
        n--;
          
    }
    // for( ll i=0;i<len;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    cout<<a<<endl;
    return 0;
}
int main()
{
    string s,t;
    cin>>s>>t;
    ll m=s.length();
    ll n=t.length();
    ll l= lcs(s,t,m,n);
  //  cout<<l<<endl;
}


Measured memory_bytes: 70656
#include <iostream>
#include <string>
using namespace std;
int n;

void dfs(string s, char mx) {
  if (s.length() == n)
    cout << s << endl;
  else {
    for (char c = 'a'; c <= mx; c++) {
      dfs(s + c, c == mx ? char(mx + 1) : mx);
    }
  }
}

int main() {
  cin >> n;
  dfs("", 'a');
}


Measured memory_bytes: 1536
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
char S[55][105]; int T[55];
char X[105];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%s%d", S[i], T + i);
	scanf("%s", X);

	int t;
	for (int i = 0; i < N; ++i) {
		if (strcmp(S[i], X) == 0) {
			t = i;
		}
	}
	int ret = 0;
	for (int i = t + 1; i < N; ++i) ret += T[i];
	printf("%d\n", ret);
	return 0;
}


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

using namespace std;

using ll = long long int;

int main(){
  int n;
  cin>>n;
  int q=0;
  int seat[100000];
  cout<<q<<endl;
  string s;
  cin>>s;
  if(s=="Male")seat[q]=0;
  else seat[q]=1;
  while(s!="Vacant"){
    int p=q,m=n;
    n/=2;
    q+=n;
    cout<<q<<endl;
    cin>>s;
    if(s=="Male")seat[q]=0;
    else seat[q]=1;
    if((seat[p]+n)%2!=seat[q]){
      q=p;
    }
    else n=m-n;
  }
}


Measured memory_bytes: 852
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(A);
            int ans = 0;
            for(int i = 0; i < N;)
            {
                int j = i + 1;
                for (; j < N;)
                {
                    if (A[j] == A[i]){
                        j++;
                    }
                    else
                    {
                        break;
                    }
                }
                ans += (j - i) % 2;
                i = j;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 15452
#include <cstdio>
#include <cmath>

#define FOR( i, l, r) for(int i = (l)    ; i <  (r); i++)
#define FOR1(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define REV( i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define REV1(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define INC( i, n) FOR( i, 0, n)
#define INC1(i, n) FOR1(i, 1, n)
#define DEC( i, n) REV( i, 0, n)
#define DEC1(i, n) REV1(i, 1, n)

typedef long long   signed int LL;
typedef long long unsigned int LU;

template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

char s[200001];

int main() {
	scanf("%s", s);
	
	int i = 0, p = 0, m = 0;
	while(s[i] != '\0') {
		if(s[i] == 'T') { p++; setmax(m, p); } else { p--; }
		i++;
	}
	
	printf("%d\n", m * 2);
	
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int mod=1e9+7;
const int N=2010;
inline void Add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
int f[N][N],n,K,ans;
int main() {
    rd(n),rd(K);
    f[0][n+1]=1;
    for(int i=1;i<K;++i) {
        int s=0;
        for(int j=n-i+2;j>1;--j) {
            Add(s,f[i-1][j+1]);
            if(j<=n-i+1) f[i][j]=(s+f[i-1][j])%mod;
        }
        // for(int j=n-i+2;j>1;--j) if(f[i-1][j]) {
        //     if(j<=n-i+1) Add(f[i][j],f[i-1][j]);
        //     for(int x=j-1;x>1;--x)
        //         Add(f[i][x],f[i-1][j]);
        // }
    }
    for(int j=2;j<=n+1;++j) Add(ans,f[K-1][j]);
    for(int i=K+1;i<n;++i) ans=ans*2ll%mod;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
#define ld long double
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define MAXN 200100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}
int cnt[MAXN][2];
int a[MAXN];

int32_t main(){
	fastio;
	int n;
	cin>>n;
	vector<int> v1,v2;
	vector<pii> sla;
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]][i%2]++;
	}
	for(int i=1;i<=1e5;i++){
		sla.pb(pii(cnt[i][1],i));
	}
	sort(sla.begin(),sla.end(),greater<pii>());
	int res = 1e9;
	
	for(int i=1;i<=1e5;i++){
		int op1 = n/2 - cnt[i][0];
		int op2;
		if(sla[0].ss==i){
			op2 = n/2 - sla[1].ff;
		}else op2 = n/2 - sla[0].ff;
		res = min(res,op1 + op2);
	}
	cout<<res<<endl;
	
	
}

Measured memory_bytes: 5748
n, m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
p (1...n).map{|i| i * (n-i) * (x[i] - x[i-1])}.reduce(0, :+) * (1...m).map{|i| i * (m-i) * (y[i] - y[i-1])}.reduce(0, :+) % (10**9+7)

Measured memory_bytes: 17176
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long n = scanner.nextLong();
			scanner.nextLine();
			List<Long> list = new ArrayList<>();
			for (int i = 0; i < 5; i++) {
				list.add(scanner.nextLong());
				scanner.nextLine();
			}
			list.sort((x, y) -> {
				if (x > y) {
					return 1;
				} else if (x == y) {
					return 0;
				} else {
					return -1;
				}
			});
			System.out.println((n - 1) / list.get(0) + 5);
		}
	}
}

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

uint64_t pow(uint64_t &x,uint64_t n){
  // ①０乗になったら１を返す
  if ( n == 0 ) { return 1; } 
  // ②通常は、半分の乗数を求める
  uint64_t half = pow(x,n/2);
  uint64_t res  = half * half;
  // ③奇数乗の場合は、もっかい掛けとく
  if( n&1 ) { res = res * x; }
  return res;
}

int main() {
  ll Ans = 0;  // 回答：
  int N; cin >> N; // 引き出す金額１～10^5

  vector<int> DP(N+1,1e9);  // 各金額別の引き出す回数
  DP.at(0)=0;

  rep1(i,N){
    DP.at(i) = min( DP.at(i) , DP.at(i-1)+1 );  // i-1 円＋１円を１回です。通常は。

    // 6^j ×１回＋mod(6^j)回のパターン
    uint64_t a6=6;
    for(int j=1; i-pow(a6,j)>=0;j++){
      DP.at(i) = min ( DP.at(i) , DP.at(i-pow(a6,j)) +1 );
    }

    // 6^j ×１回＋mod(6^j)回のパターン
    uint64_t a9=9;
    for(int j=1; i-pow(a9,j)>=0;j++){
      DP.at(i) = min ( DP.at(i) , DP.at(i-pow(a9,j)) +1 );
    }
  }

  cout << DP.at(N) << endl;
}


Measured memory_bytes: 640
def slove(n, m):
    tmp = n if n < m // 2 else m // 2
    tmp2 = (m - tmp * 2) // 4
    return tmp + tmp2
    
if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    print(slove(n, m))


Measured memory_bytes: 2940
[r,g,b]=list(map(int,input().split()))
#b>g>r
k=int(input())
m=k
n=0
while m>=0:
  tg=pow(2,m)*g
  tb=pow(2,n)*b
  if tg>r and tb>tg:
    print("Yes")
    exit(0)
  m-=1
  n+=1
print("No")
    

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int len=0;
	char s[2];
	for(int i=1;i<=9;i++)
	{
		printf("? 1");
		for(int j=1;j<=i;j++)putchar('0');
		puts("");
		fflush(stdout);
		scanf("%s",s);
		if(s[0]=='N')
		{
			len=i;
			break;
		}
	}
	if(!len)
	{
		for(int i=1;i<=10;i++)
		{
			putchar('?');
			putchar(' ');
			for(int j=1;j<=i;j++)
			{
				putchar('9');
			}
			puts("");
			fflush(stdout);
			scanf("%s",s);
			if(s[0]=='Y')
			{
				putchar('!');
				putchar(' ');
				putchar('1');
				for(int j=1;j<=i-1;j++)putchar('0');
					puts("");
				fflush(stdout);
				return 0;
			}
		}
	}
	int ans[100];
	for(int i=len;i>=1;i--)
	{
		int l=0,r=9;
		while(l<r)
		{
			if(i==len&&l==0&&r==1)
			{
				break;
			}
			int mid=(l+r)>>1;
			putchar('?');
			putchar(' ');
			for(int k=len;k>i;k--)printf("%d",ans[k]);
			printf("%d" ,mid);
			for(int j=1;j<=12-(len-i);j++)putchar('9');
			puts("");
			fflush(stdout);
			scanf("%s",s);
			if(s[0]=='N')
			{
				l=mid+1;
			}
			else
			{
				r=mid;
			}
		}
		ans[i]=r;
	}

	putchar('!');
	putchar(' ');
	for(int j=len;j>=1;j--)
	{
		printf("%d",ans[j]);
	}
	puts("");
	fflush(stdout);
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S,T;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	FORR(c,S) {
		if(T.size() && c=='C' && T.back()=='B') T.back()='#';
		else T.push_back(c);
	}
	
	ll num=0;
	ll ret=0;
	reverse(ALL(T));
	FORR(c,T) {
		if(c=='B' || c=='C') {
			num=0;
		}
		else if(c=='#') num++;
		else ret+=num;
	}
	
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int maxn=1e5+5;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
import math
import collections
def main():

    N, K = map(int, input().split())
    mod = 998244353
    d = dict()
    cnt = collections.defaultdict(int)
    for _ in range(K):
        l, r = map(int, input().split())
        d[(1-r, 1-l)] = 0
    cnt[1] = 1

    for i in range(2, N+1):
        temp = dict()
        for p in d:
            if p[1]+1 <= N:
                temp[(p[0]+1, p[1]+1)] = d[p]
                if p[0] in cnt: temp[(p[0]+1, p[1]+1)] -= cnt[p[0]]
                if p[1]+1 in cnt: temp[(p[0]+1, p[1]+1)] += cnt[p[1]+1]
            else:
                temp[(p[0]+1, N)] = d[p]
                if p[0] in cnt: temp[(p[0]+1, p[1]+1)] -= cnt[p[0]]
        d = temp
        # print(d)
        cnt[i] = sum(d[v] for v in d) % mod
        # print(cnt)
    return cnt[N]



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

Measured memory_bytes: 103040
#include<bits/stdc++.h>
using namespace std;
int num[1000];
int main(){
    int i,n,ans=0;
    cin>>n;
    for(i=0;i<n;i++){
    	cin>>num[i];
	}
	sort(num,num+n);
	bool flag=0;
	for(i=n-1;i>=0;i--){
		if(!flag)ans+=num[i];
		if(flag)ans-=num[i];
		flag=!flag;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
sss = [ input() for _ in range(n) ]
sss = sorted(map("".join, map(sorted, sss)))

ans = 0
left = 0
while left<n-1:
    for right in range(left+1, n):
        if sss[left] != sss[right]:
            dis = right - left -1
            ans += dis * (dis+1) // 2
            left = right
            break
    if right == n-1:
        break


dis = right - left
ans += dis * (dis+1) // 2


print(ans)

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - b) <= d && abs(b - c) <= d)
        cout << "Yes" << endl;
    else if (abs(a - c) <= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
def read():
    A, B = list(map(int, input().strip().split()))
    return A, B


def solve(A, B):
    if A <= 5:
        return 0
    elif A <= 12:
        return B // 2
    return B


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int N;
long long M;
std::vector<long long > A(100000);
std::vector<long long > kumisuu(200000, 0); // A_i>=x を満たすiの数
std::vector<long long > souwa(200000, 0); // A_i>=x を満たすiについてA_iの総和

long long get_possible_count(int value){ // 値がvalue以上となる組み合わせ総数を求める
  long long count = 0;
  for (int i=0; i<N; i++){
    count += kumisuu[std::max(value-A[i], (long long)0)];
  }
  return count;
}

int main(){
  scanf("%d",&N);
  scanf("%lld",&M);

  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    kumisuu[A[i]]++;
  }
  sort(A.begin(), A.end(), std::greater<long long>());

  for (int i=0; i<N; i++){
    souwa[i+1] = souwa[i] + A[i];
  }

  /*  累積和を求める */
  for (int i=200000; i>0; i--){
    kumisuu[i-1] += kumisuu[i];
  }

  int left = 0;
  int right = 200001;
  int mid;
  long long ans;
  std::map<long long, long long > mp;
  while(right-left>1){
    ans = 0;
    mid = (left+right)/2;
    if (get_possible_count(mid)>=M){ // 
      left = mid;
    } else {
      right = mid;
    }
    mp[mid] = get_possible_count(mid);
  }

  long long ans_temp= 0;
  if (left == mid){
    for (int i=0; i<N; i++){
      ans_temp += souwa[kumisuu[std::max(left-A[i],(long long)0)]];
      ans_temp += A[i]*kumisuu[std::max(left-A[i],(long long)0)];
    }
    std::cout << ans_temp-abs(M-mp[left])*left << std::endl;
  } else if (right==mid){
    for (int i=0; i<N; i++){
      ans_temp += souwa[kumisuu[std::max(right-A[i],(long long)0)]];
      ans_temp += A[i]*kumisuu[std::max(right-A[i],(long long)0)];
    }
    std::cout << ans_temp + abs(M-mp[right])*left << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
    int n = (int)s.size();

    string t;
    vc<int> v(1);
    for(int i = 0; i < n; i ++){
        while(s[i] == 'x' && i < n) v.back() ++, i ++;
        if(i == n) break;
        t += s[i];
        v.push_back(0);
    }

    string u = t;
    Reverse(u);
    if(t != u){
        Cout(-1); return 0;
    }

    int ans = 0;
    For(i, (int)v.size()/2) ans += abs(v[i] - v[v.size()-1-i]);
    Cout(ans);
}





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

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

        double a;
        a = sqrt(2*x);
        long b = a;
        if (b*(1+b)/2<x) {
                cout << b+1 << endl;
        } else {
                cout << b << endl;
        }
        return 0;
}


Measured memory_bytes: 256
R, C = gets.split.map(&:to_i)
N = gets.to_i
V = Array.new(R + C + 1)
G = Array.new(R + C + 1) { [] }
E = N.times.map { gets.split.map(&:to_i) }

E.each do |r,c,a|
    G[r] << [R + c, a]
    G[R + c] << [r, a]
end
def dfs(s)
    stack = []
    stack << [s, 0]
    rmin = 10 ** 20
    cmin = 10 ** 20
    
    until stack.empty?
        v, w = stack.pop
        V[v] = w
        rmin = w if v <= R && w < rmin
        cmin = w if v >  R && w < cmin
        G[v].each do |to, a|
            if !V[to]
                stack << [to, a - w] 
            elsif w + V[to] != a
                return false
            end
        end
    end
    rmin + cmin >= 0
end

puts (1 .. R + C).all? {|u| V[u] || dfs(u) } ? "Yes" : "No"


Measured memory_bytes: 46204
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <climits>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s; cin >> s;
	int ans=0;
	bool p=0;
	for(int i=0;i<n;i++){
		if(s[i]=='x'&&p)break;
		else{
			if(s[i]=='x'){
				p=1;
			}else{
				p=0;
			}
			ans++;
		}
	} 
	cout << ans << endl;
}


Measured memory_bytes: 3352
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

constexpr int INF = 1 << 29;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int H, W;
string s[303];

int main() {
    cin >> H >> W;
    for (int j = 0; j < H; ++j) {
        cin >> s[j];
    }

    int sum = 0;

    for (int j = 0; j < W-1; ++j) {
        int cost[303][303];
        int dp[303][303];

        for (int k = 0; k <= H; ++k) {
            fill(dp[k], dp[k]+H+1, INF);
        }

        cost[0][0] = cost[0][1] = cost[1][0] = 0;
        for (int k = 1; k <= H; ++k) {
            for (int l = 1; l <= H; ++l) {
                cost[k][l] = ((s[k-1][j] == s[l-1][j+1]) ? 1 : 0) + cost[k-1][l-1];
            }
        }

        dp[0][0] = 0;

        for (int k = 0; k <= H; ++k) {
            for (int l = 0; l <= H; ++l) {
                if (k+l == 0) { continue; }
                if (l > 0) {
                    dp[k][l] = min(dp[k][l], dp[k][l-1] + cost[k][l]);
                }
                if (k > 0) {
                    dp[k][l] = min(dp[k][l], dp[k-1][l] + cost[k][l]);
                }
            }
        }

        sum += dp[H][H];
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
	long long int n, counter, i;
	counter = 0;
	cin >> n;
	for (i = 1; i <= 1000000; i++)
	{
		if (n > i) {;
			if ((n - i) % i == 0&&(n - i) / i>i) {
				counter += (n - i) / i; }
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>

using namespace std;

int main(){

    int n, W;
    cin >> n >> W;

    const int v_max = 100000;

    int w[n], v[n];
    for(int i=0;i<n;i++)cin >> w[i] >> v[i];

    int dp[v_max+1];
    int tmp[v_max+1];
    for(int i=0;i<=v_max;i++)dp[i] = -1;

    for(int i=0;i<n;i++){

        for(int j=0;j<=v_max;j++)tmp[j] = dp[j];

        tmp[v[i]] = max(dp[v[i]], W-w[i]);
        for(int j=0;j<=v_max;j++){
            if(j-v[i]>=0 && dp[j-v[i]]!=-1)tmp[j] = max(dp[j-v[i]]-w[i], dp[j]);
        }

        for(int j=0;j<=v_max;j++)dp[j] = tmp[j];
    }

    for(int i=v_max;i>0;i--){
        if(dp[i]!=-1){
            cout << i << endl;
            //cout << i << ":" << dp[i] << endl;
            break;
        }
    }

}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            b[i] = a[i] - (i + 1);
        }
        Arrays.sort(b);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += Math.abs(a[i] - (b[b.length / 2] + (i + 1)));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 91540
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

#define ll long long 
#define mod 1000000007

int main()
{
	ll n,k;
	cin>>n>>k;
	char a[n+10][k+10];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			cin>>a[i][j];
			//cout<<a[i][j];
		}
		//cout<<endl;
	}
	for(int i=0;i<=n+1;i++)
	{
		for(int j=0;j<=k+1;j++)
		{
			if(i==0||j==0||i==(n+1)||j==(k+1))
			{
				cout<<"#";
			}
			else
			{
				cout<<a[i][j];
			}
		}
		cout<<endl;
	}
}

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


#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define pb push_back
#define len(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
using namespace std;
bool ok[10];
bool check(int num){
    while(num){
        if(!ok[num%10])return false;
        num /= 10;
    }
    return true;
}
signed main(){
    int n , k;cin >> n >> k;
    fill(ok , ok + 10 , 1);
    for(int i = 0; i < k; ++i){
        int x;cin >> x;
        ok[x] = 0;
    }
    while(true){
        if(check(n))return cout << n , 0;
        ++n;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<cmath>
using namespace std;

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

	auto ret = to_string(N).size();
	for(long long i=2; i<sqrt(N)+1; i++)
	{
		if(N%i != 0)
			continue;

		ret = min(ret, max(to_string(i).size(), to_string(N/i).size()));
	}

	cout << ret << endl;

	return 0;
}


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

int main(void){
    int N,X;
    cin>>N>>X;
    
    vector<long long> x(N+1);
    for(int i=0;i<N;i++) cin>>x[i];
    
    if(N==1&&X==x[0])cout<<0<<endl;
    
    x[N]=X;
    
    sort(x.begin(),x.end());
    
    vector<long long> gap(N);
    for(int i=0;i<N;i++){
        gap[i]=x[i+1]-x[i];
    }
    
    sort(gap.begin(),gap.end());
    
    long long i,j;
    long long max=1;
    for(i=gap[0];i>=1;i--){
        if(gap[0]%i==0){
            for(j=0;j<N;j++){
                if(gap[j]%i!=0)break;
                if(j==N-1){
                    max=i;
                    cout<<max<<endl;
                    return 0;
                }
            }
        }
 
    }
    
}

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() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;

  if (U == S) {
    cout << A - 1 << " " << B << endl;
  } else {
    cout << A << " " << B - 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;

using namespace std;

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  cout << min(A*N,B) << endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li n;
    cin >> n;
    li a = n % 1000;
    if (a == 0) {
        cout << 0 << endl;
    } else {
        cout << 1000 - a << endl;
    }


    return 0;
}

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

typedef long double ld;
typedef pair<int, int> pii;
const int N = 20;

int n, x[N], y[N], par[N];
ld a[N], dp[1 << N];

int g_par(int v) {
	return (v == par[v]? v: par[v] = g_par(par[v]));
}

ld power(ld a) {
	return a * a;
}

ld weight(pii p) {
	int a = p.first, b = p.second;
	return sqrt(power(x[a] - x[b]) + power(y[a] - y[b]));
}

ld solve(int mask) {
	vector<int> vec;
	for (int i = 0; i < n; i++)
		if(mask & (1 << i))
			vec.push_back(i);
	iota(par, par + n, 0);
	vector<pii> edge;
	for (int u: vec)
		for (int v: vec)
			edge.push_back(pii(u, v));
	sort(edge.begin(), edge.end(), [&](pii a, pii b) {
		return weight(a) < weight(b);
	});
	ld sum = 0;
	for (int v: vec)
		sum += a[v];
	for (pii p: edge)
		if(g_par(p.first) != g_par(p.second)) {
			sum -= weight(p);
			par[g_par(p.first)] = g_par(p.second);
		}
	return sum / (1. * vec.size());
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i] >> a[i];
	dp[0] = 0;
	for (int mask = 1; mask < (1 << n); mask++) {
		dp[mask] = solve(mask);
		vector<int> vec;
		for (int i = 0; i < n; i++)
			if(mask & (1 << i))
				vec.push_back(i);
		for (int MASK = 1; MASK < (1 << vec.size()) - 1; MASK++) {
			int help = 0;
			for (int i = 0; i < n; i++)
				if(MASK & (1 << i))
					help ^= 1 << vec[i];
			dp[mask] = max(dp[mask], min(dp[help], dp[mask ^ help]));
		}
	}
	cout << fixed << dp[(1 << n) - 1];
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	char A,B;
	cin>>A>>B;
	if(A<B){
		ce("<")
	}else if(A==B){
		ce("=")
	}else{
		ce(">")
	}
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readInt()
    val a = readIntList()

    a.forEach {
        if (it % 2 == 0) {
            if (it % 3 != 0 && it % 5 != 0) {
                println("DENIED")
                return
            }
        }
    }
    println("APPROVED")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
    int n,m;
    cin >> n >> m;
  	vi x(m);
  	rep(i,m) cin >> x[i];
	ll ans = 0;
  	
  	if(n<m){
		sort(all(x));
      	vi l(m-1);
      	rep(i,m-1){
        	l[i] = x[i+1]-x[i];
        }
      	sort(all(l));
        rep(i,m-n) ans += l[i];
    }
  	
  	cout << ans << endl;
  	return;
}

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



Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int h,m,s,ss;
	scanf("%d",&ss);
	h=ss/3600;
	ss=ss%3600;
	m=ss/60;
	s=ss%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}
//cout << fixed << setprecision(10);

int main(){
  ll n,ans=0; cin>>n;
  if(n%2==1) cout<<0<<endl;
  else{
    ll i=5;
    while(i<n){
    ans+=n/(i*2);
      i*=5;
    }
  cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int n,m;
int gcd(int a,int b) {
	return !b?a:gcd(b,a%b);
}
int main() {
	scanf("%d%d",&n,&m);
	printf("%lld\n",1ll*n*m/gcd(n,m));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int min(int a,int b)
{
    return a<b?a:b;
}
int main() {
    int n,a[100000],i,k,j,diff,b[100000];
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    b[0]=0;
    for(i=1;i<n;i++)
    {    b[i]=1000000000;
        for(j=1;j<=k && i-j>=0;j++)
        {
            b[i]=min(abs(a[i]-a[i-j])+b[i-j],b[i]);
        }
    }
   printf("%d ",b[n-1]);
  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

struct Node{
   Node *lp,*rp,*par;
   int sz,val;

   Node(){
      lp=nullptr; rp=nullptr; par=nullptr;
      sz=1;
   }

   void rotate(){
      Node *pp,*p,*c;
      p=this->par; pp=p->par;
      if(p->lp==this){
         c=this->rp;
         this->rp=p;
         p->lp=c;
      }
      else{
         c=this->lp;
         this->lp=p;
         p->rp=c;
      }
      if(pp&&pp->lp==p)pp->lp=this;
      if(pp&&pp->rp==p)pp->rp=this;
      this->par=pp; p->par=this;
      if(c)c->par=p;
      p->update(); this->update();
   }
   int state(){
      if(!this->par)return 0;
      if(this->par->lp==this)return 1;
      if(this->par->rp==this)return -1;
      return 0;
   }
   void splay(){
      while(this->state()){
         if(this->par->state()==0){
            this->rotate();
         }
         else if(this->state()==this->par->state()){
            this->par->rotate(); this->rotate();
         }
         else{
            this->rotate(); this->rotate();
         }
      }
   }
   void update(){
      this->sz=1;
      if(this->lp)this->sz+=this->lp->sz;
      if(this->rp)this->sz+=this->rp->sz;
   }
};
Node *get(int idx,Node *root){
   Node *cur=root;
   while(1){
      int lb=cur->lp?cur->lp->sz:0;
      if(idx<lb){
         cur=cur->lp;
      }
      if(idx==lb){
         cur->splay();
         return cur;
      }
      if(idx>lb){
         cur=cur->rp;
         idx-=lb+1;
      }
   }
}

Node node[201000];

int main(){
   int q; scanf("%d",&q);
   int sz=0;
   rep(i,0,q){
      node[i].par=&node[i+1];
      node[i+1].lp=&node[i];
      node[i+1].update();
   }
   Node *root=&node[q];
   rep(i,0,q){
      int ord,x; scanf("%d",&ord);
      if(ord==0){
         scanf("%d",&x);
         root=get(sz++,root);
         root->val=x;
      }
      if(ord==1){
         scanf("%d",&x);
         root=get(x,root);
         printf("%d\n",root->val);
      }
      if(ord==2)sz--;
   }
   return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>> n;
    int h[n];
    int f=1;
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    for(int i=n-1;i>=1;i--){
            if(h[i]-h[i-1]<-1){
                f=0;
            }
            if(h[i]-h[i-1]==-1){
                h[i-1]--;
            }
        }
    if(f==0){
        puts("No");
    }
    else{
        puts("Yes");
    }
    return 0;
}


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

int main(){

  int n;
  cin >> n;

  vector<int> t(n);
  int t_max = 0;
  for(int i = 0; i < n; i++){
    cin >> t[i];
    t_max = max(t[i],t_max);
  }

  vector<int> vec(10001);
  for(int i = 1; i <= t_max; i++){
    if(t_max%i == 0) vec.push_back(i);
  }

  long long ans = 0;
  for(int i = 0; i < n; i++){
    int j = 0;
    while(vec[j] < t[i]) j++;
    ans += vec[j] - t[i];
  }
  cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3300
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int N;

  cin >> N;
  long long a;
  vector<long long> S(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    cin >> a;
    S[i + 1] = S[i] + a;
  }
  sort(S.begin(), S.end());

  unordered_map<long long, long long> m;
  for (auto e : S) m[e]++;

  long long ans = 0;
  for (auto p : m) {
    if (p.second > 1) {
      ans += p.second * (p.second - 1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

ll f(ll a, ll x){
	if(a == -1) return -1;
	return max(a,0LL) / x;
}

int main(void){

	ll a, b, x; cin >> a >> b >> x;
	cout << f(b, x) - f(a-1, x) << endl;

	return 0;

}


Measured memory_bytes: 3636
N, M = map(int, input().split())

matrix = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    matrix[a - 1][b - 1] = 1
    matrix[b - 1][a - 1] = 1

def func(p, l):
    '''
    count = 0
    if Pから行ける場所が探索済み:
        if 全頂点探索済み:
            count = 1
        else:
            count = 0
    else:
        foreach Pから行ける未探索頂点:
            count += func(p, l)

    '''
    count = 0
    if all(l):
        count = 1
    else:
        for np, e in enumerate(matrix[p]):
            if e == 0:
                continue
            if p == np:
                continue
            if l[np] == True:
                continue

            l[np] = True
            count += func(np, l)
            l[np] = False

    return count

l = [False] * N
l[0] = True


print(func(0, l))

Measured memory_bytes: 3064
use std::io;

fn next_vec() -> Vec<i64> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map(|n| n.parse().unwrap()).collect()
}

fn main() {
    let v = next_vec();
    let a = v[0];
    let b = v[1];
    let c = v[2];

    for i in 0..b {
        if a * i % b == c {
            println!("YES");
            return
        }
    }
    println!("NO");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N;
  
  A = (N%100)%10;
    
  if ( A == 3 ) {
    cout << "bon" << endl;
  }
  else if ( A == 0 ) {
    cout << "pon" << endl;
  }
  else if ( A == 1 ) {
    cout << "pon" << endl;
  }
  else if ( A == 6 ) {
    cout << "pon" << endl;
  }
  else if ( A == 8 ) {
    cout << "pon" << endl;
  } 
  else {
    cout << "hon" << endl;
  }
}
  

Measured memory_bytes: 3636
k= int(input())
s= str(input())


if int(k)>=1 and int(k)<=100 and len(s)>=1 and len(s)<=100: #check if k and s are between 1 to 100

    if len(s) > k:

        print (s[:k]+"...") #cut the str until value of k and add ... to the end

    else:
        print (s)

Measured memory_bytes: 8988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        int[] a = new int[4];
        for(int i = 0; i < n; i++)
        {
            var s = ReadLine();
            if(s == "AC")
            {
                a[0]++;
            }
            else if(s == "WA")
            {
                a[1]++;
            }
            else if(s == "TLE")
            {
                a[2]++;
            }
            else
            {
                a[3]++;
            }
        }
        WriteLine($"AC x {a[0]}");
        WriteLine($"WA x {a[1]}");
        WriteLine($"TLE x {a[2]}");
        WriteLine($"RE x {a[3]}");
        ReadLine();
    }
}


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

using namespace std;

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

    vector<double> p(N+1);
    for(int i=1; i<=N; i++){
        cin >> p[i];
    }

    vector<double> dp(N+1, 0);
    dp[0] = 1.0;
    for(int i=1; i<=N; i++){
        for(int j=i; j>=0; j--){
            if(j == 0)
                dp[j] = dp[j] * (1-p[i]);
            else
                dp[j] = dp[j-1] * p[i] + dp[j] * (1-p[i]);
        }
    }


    double ans = 0;
    for(int i=(N/2) + 1; i<=N; i++){
        ans += dp[i];
    }

    cout << setprecision(10) << ans << "\n";
        
    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n;
  cin >> n;
  if(n % 2 == 1){
    cout << 0 << endl;
    return 0;
  }
  n /= 2;
  ll ans = 0;
  ll now = 5;
  while(1){
    if(n/now == 0) break;
    ans += n/now;
    now *= 5;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608