akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

static const int MAX = 5000;
vector<pair<int, int>> nx;
ll n, k;
vector<bool> visited(MAX, false);
vector<vector<ll>> scores;

void search(int u){
    if(visited[nx[u].first]) return;
    visited[nx[u].first] = true;
    scores.back().push_back(nx[u].second);
    search(nx[u].first);
}

void search_init(int s){
    if(visited[s]) return;
    scores.emplace_back();
    search(s);
}

int main(){
    cin >> n >> k;
    nx.resize(n);
    vector<int> p(n), c(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    for(int i = 0; i < n; i++){
        nx[i] = make_pair(p[i]-1, c[i]);
    }
    for(int i = 0; i < n; i++){
        search_init(i);
    }
    ll ans = -2e18;
    for(auto s : scores){
        int num = s.size();
        ll loop = k / num;
        ll mod = k % num;
        ll sum = 0;
        if(loop){
            for(int i = 0; i < num; i++){
                sum += s[i];
            }
        }
        vector<ll> t(2*num+1);
        for(int i = 0; i < 2*num; i++){
            t[i+1] = s[i % num];
        }
        for(int i = 0; i < 2*num; i++){
            t[i+1] += t[i];
        }
        for(int j = 1; j <= num; j++){
            ll maxv = -2e18;
            for(int i = 0; i + j <= 2*num; i++){
                if(maxv < (t[i+j] - t[i])) maxv = t[i+j] - t[i];
            }
            if(j > k) continue;
            if(sum <= 0){
                ans = max(ans, maxv);
            } else {
                ans = max(ans, sum * ((k - j) / num) + maxv);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int ans=0;
  for (int i=0;i<2;++i) {
    if (a<b) {
      ans+=b; --b;
    }
    else {
      ans+=a; --a;
    }
  }
  cout << ans << endl;
}

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

#define faster     ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define read       freopen("input.txt", "r", stdin);
#define write      freopen("output.txt", "w", stdout);
#define endd        '\n'
#define ll         long long
#define sq(a)      ((a) * (a))

using namespace std;
int main()
{
      faster;
      double pi = 2 * acos(0.0);
      ll int n,i,t,j,k,m=0,a,b,c,d,p,q,r,x=250,y=10,z,count=0;
      cin>>n;
      ll int ara[n+1]={};
      for(i=1;i<=n;i++){
            cin>>ara[i];
            if(i!=ara[i])count++;
      }
      if(count<=2)cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
      return 0;
}
//Sheikh Tafsir Rahman
//CSE IUT

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 
int main(){
    string s,t;  cin >> s >> t;
    int sll=s.length(); int tll=t.length();
    vector<pair<int,string> > dp(sll+1);
    rep(i,sll+1){
        dp[i].first=-1;
        dp[i].second="";
    }
    vector<vector<int> > al(26);
    rep(i,tll) al[t[i]-'a'].push_back(i);
 
    for(int i=1; i<sll+1; i++){
        int id=s[i-1]-'a';
        for(int j=i; j>=1; j--){
            if(al[id].empty()) continue;
          	if(dp[j-1].first==-1 && j!=1) continue;
            auto next=upper_bound(all(al[id]),dp[j-1].first);
            if(next==al[id].begin()+al[id].size()) continue;
            if(*next<dp[j].first || dp[j].first==-1){
                dp[j].first=*next;
                dp[j].second=dp[j-1].second+s[i-1];
            }
        }
    }
 
        for(int j=sll; j>=0; j--){
            if(dp[j].first!=-1){
                cout << dp[j].second << endl;
                return 0;
            }
        }
    return 0;
}

Measured memory_bytes: 7808
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    c = [[0]*(N+1) for _ in range(61)]
    c[0][1:] = A[:]
    for i in range(60):
        for j in range(1, N+1):
            c[i+1][j] = c[i][c[i][j]]
    i = 1 << 60
    j = 1
    k = 60
    while K > 0:
        if i <= K:
            K -= i
            j = c[k][j]
        i >>= 1
        k -= 1
    print(j)


if __name__ == '__main__':
    main()


Measured memory_bytes: 185820
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 2000000
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

char s[maxn+5];

ll fac[maxn+5],ifac[maxn+5],inv[maxn+5];
ll pw26[maxn+5],pw25[maxn+5];

ll C(int n,int m)
{
    if(m<0 || n-m<0) return 0;
    return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

int main()
{
    fac[0]=ifac[0]=inv[1]=1;
    rep(i,2,maxn) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
    rep(i,1,maxn) fac[i]=fac[i-1]*i%mod;
    rep(i,1,maxn) ifac[i]=ifac[i-1]*inv[i]%mod;

    pw25[0]=pw26[0]=1;
    rep(i,1,maxn) pw25[i]=pw25[i-1]*25%mod;
    rep(i,1,maxn) pw26[i]=pw26[i-1]*26%mod;
    int k; scanf("%d",&k);
    scanf("%s",s);
    int n=strlen(s);
    int N=n+k;
    ll ans=0;
    rep(i,n,N) ans=(ans+C(i-1,n-1)*pw25[i-n]%mod*pw26[N-i])%mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 82888
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359

int main(){
double a,b,x;
cin>>a>>b>>x;

double mmax = a*a*b;
double ans=90;


double right = 90,left =0;



for(ll uuu =0;uuu<4000;uuu++){

    double mid = (right+left)/2;
    double rad = mid*(PI/180);

  if(b*cosf(rad)>=a*sinf(rad)){

   double d = b*cosf(rad) - a*sinf(rad);

    if(a*(((b+d/cosf(rad))*a/2))>x){
        left = mid;
    }
    else{
        right = mid;
    }
  }
  else{
     if((b*b*cosf(rad)/sinf(rad)*a/2)>x){
         left = mid;
    }
    else{
        right = mid;
    }
    }



}
printf("%.9lf",left);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

long long M  = 1e9+7;

int powr(int a, int b){
	int res = 1;
	while(b){
		if(b&1)
			res = res*a;
		b = b>>1;
		a = a*a;
	}
	return res;
}

signed main(){
    fast;
    int n; cin >> n;
    for(int i=-1000 ; i<=1000 ; i++){
    	for(int j=-1000 ; j<=1000 ; j++){
    		if(powr(i,5) - powr(j,5) == n){
     			cout << i << " " << j << endl;
    			return 0;
    		}
    	}
    }
}


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

using namespace std;

int cost[1 << 8][3];

int main(void) {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> l(N);
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }
    for (int i = 1; i < (1 << N); i++) {
        int sum = 0;
        for (int j = 0; j < N; j++) {
            if (i & (1 << j)) sum += l[j];
        }
        cost[i][0] = (__builtin_popcount(i) - 1) * 10 + abs(sum - A);
        cost[i][1] = (__builtin_popcount(i) - 1) * 10 + abs(sum - B);
        cost[i][2] = (__builtin_popcount(i) - 1) * 10 + abs(sum - C);
    }
    int ans = (int)1e9;
    for (int i = 1; i < (1 << N); i++) {
        for (int j = 1; j < (1 << N); j++) {
            for (int k = 1; k < (1 << N); k++) {
                if ((i & j) != 0 || (j & k) != 0 || (k & i) != 0) continue;
                ans = min(ans, cost[i][0] + cost[j][1] + cost[k][2]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define F first
#define S second
#define MP make_pair
#define PB push_back
 
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)
int main(){
	string sa,sb,sc;
	cin>>sa>>sb>>sc;
	int i=0,j=0,k=0;
	char loc=sa[i++];
	while(1){
		if(loc=='a'){
			if(i==sa.size()){
				cout<<'A'<<endl;
				break;
			}
			else{
				loc=sa[i++];
			}
		}
		else if(loc=='b'){
			if(j==sb.size()){
				cout<<'B'<<endl;
				break;
			}
			else{
				loc=sb[j++];
			}			
		}
		else{
			if(k==sc.size()){
				cout<<'C'<<endl;
				break;
			}
			else{
				loc=sc[k++];
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())

ab = []
dic = {}

for i in range(N-1):

    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ab.append([a,b])

    if a not in dic:
        dic[a] = []
    if b not in dic:
        dic[b] = []

    dic[a].append(b)
    dic[b].append(a)

ans = float("inf")
ansleef = float("inf")

for r in range(N):

    leef = [0] * N
    
    q = deque([r])
    dep = [float("inf")] * N
    dep[r] = 0
    maxdep = 0

    while len(q) > 0:

        now = q.popleft()
        nchild = 0

        for i in dic[now]:

            if dep[i] > dep[now] + 1:
                nchild += 1
                dep[i] = dep[now] + 1
                maxdep = max(maxdep,dep[i])
                q.append(i)

            leef[dep[now]] = max(leef[dep[now]],nchild)

    if ans > maxdep:
        ans = maxdep

        nl = 1
        for i in range(maxdep):
            nl *= leef[i]

        ansleef = nl

    if ans == maxdep:
        ans = maxdep

        nl = 1
        for i in range(maxdep):
            nl *= leef[i]
        
        ansleef = min(ansleef,nl)

#print (ans + 1,ansleef)

for r in range(N-1):

    leef = [0] * N

    pa = ab[r][0]
    pb = ab[r][1]
    
    q = deque([pa,pb])
    dep = [float("inf")] * N
    dep[pa] = 0
    dep[pb] = 0
    maxdep = 0

    while len(q) > 0:

        now = q.popleft()
        nchild = 0

        for i in dic[now]:

            if dep[i] > dep[now] + 1:
                nchild += 1
                dep[i] = dep[now] + 1
                maxdep = max(maxdep,dep[i])
                q.append(i)

            leef[dep[now]] = max(leef[dep[now]],nchild)

    if ans > maxdep:
        ans = maxdep

        nl = 2
        for i in range(maxdep):
            nl *= leef[i]

        ansleef = nl

    if ans == maxdep:
        ans = maxdep

        nl = 2
        for i in range(maxdep):
            nl *= leef[i]

        ansleef = min(ansleef,nl)

print (ans + 1,ansleef)


Measured memory_bytes: 46576
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var x = ReadLongArray();

		Console.WriteLine(Array.IndexOf(x, 0) + 1);
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


Measured memory_bytes: 27492
A,B,C,X,Y = map(int,input().split())
if 2*C >= A+B:
  print(X*A+Y*B)
else:
  if X >= Y:
    if A > 2*C:
      print(2*X*C)
    else:
      print(2*Y*C + (X-Y)*A)
  else:
    if B > 2*C:
      print(2*Y*C)
    else:
      print(2*X*C+(Y-X)*B)



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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;


    int ex = x2 - x1;
    int ey = y2 - y1;

    int x3 = x2 - ey; 
    int y3 = y2 + ex; 
    int x4 = x3 - ex; 
    int y4 = y3 - ey; 

    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
}

Measured memory_bytes: 3464
N, M, X = map(int,input().split())
A = [[int(x) for x in input().split()] for _ in range(N)]

INF = float('inf')
ans = INF

for i in range(2**N):
    tmp = [0 for _ in range(M+1)]
    b = bin(i)[2:].zfill(N)
    
    for n in range(N):
        for m in range(M+1):
            tmp[m] += A[n][m] * int(b[N-1-n])

    if min(tmp[1:]) >= X:
        ans = min(ans, tmp[0])

if ans == INF:
    ans = -1
print(ans)

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

int K;
int A;
int B;
bool done;

int main(){
  cin >> K >> A >> B;
  done = false;
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      cout << "OK";
      done = true;
      break;
    }
  }
  if(done == false){
    cout << "NG";
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i,n){
    ans += (i+1) * (n-i);
  }
  rep(i,n-1){
    cin >> t1;
    cin >> t2;
    t1--,t2--;
    if(t1 > t2){
      swap(t1,t2);
    }
    ans -= (t1 + 1) * (n - t2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *way=(int *)calloc(100*100+1,sizeof(int));
  way[0]=1;
  int sum=0;
  int i;
  for(i=0;i<n;i++){
    int s;
    scanf("%d",&s);
    int j;
    for(j=sum;j>=0;j--){
      if(way[j]==1) way[j+s]=1;
    }
    sum+=s;
  }
  i=sum;
  while(i>0 && (i%10==0 || way[i]==0)) i--;
  printf("%d\n",i);
}

int main(void){
  run();
  return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int D;
  cin >> D;
  vector<int> c(26);
  REP(i, 26) { cin >> c.at(i); }
  vector<vector<int>> s(D);
  int d;
  REP(i, D) {
    REP(j, 26) {
      cin >> d;
      s.at(i).push_back(d);
    }
  }

  vector<int> t(D);
  REP(i, D) { cin >> t.at(i); --t.at(i); }

  vector<vector<int>> last(D, vector<int>(26, 0));
  ll S = 0ll;

  REP(i, D) {
    last.at(i).at(t.at(i)) = i + 1;

    REPI(j, i+1, D) { last.at(j).at(t.at(i)) = i + 1; }
  }

  REP(i, D) {
    S += s.at(i).at(t.at(i));

    ll minus = 0;
    REP(j, 26) {
      minus += c.at(j) * (i+1 - last.at(i).at(j));
    }
    S -= minus;
    cout << S << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
<?php

$s = 'MARCH';
$c = [0, 0, 0, 0, 0];
$ans = 0;

fscanf(STDIN, "%d", $n);
for($i = 0; $i < $n; $i++){
    $t = fgets(STDIN);
    for($j = 0; $j < 5; $j++){
        if($s[$j] == $t[0]) $c[$j]++;
    }
}

for($i = 0; $i < 5; $i++){
    for($j = $i + 1; $j < 5; $j++){
        for($k = $j + 1; $k < 5; $k++){
            $ans += $c[$i] * $c[$j] * $c[$k];
        }
    }
}

echo $ans;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,char>;
using ll=long long;

int main () {
  ll N;
  cin >> N;
  vector<ll> V(N+1,0);
  ll a;
  for (ll i=0; i<N; i++) {
    cin >> a;
    V[i+1]=V[i]+a;
  }
  ll m=pow(10, 18);
  ll S=V[N];
  for (ll i=1; i<N; i++) {
    ll T=S-2*V[i];
    //cout << T << endl;
    if (T<0) {T=-T;}
    if (m>T) {m=T;}
  }
  cout << m << endl;
}
 

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		2505

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

//
int main(){
	int N;cin >> N;
	V H(N);
	REP(i,N)cin>>H[i];

	int flag = true;
	for(int i=N-1;i>0;--i){
		int d = H[i-1]-H[i];
		if(d>1){flag=false;break;}
		else if(d==1)H[i-1]--;
	}

	puts(flag?"Yes":"No");

	return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m,k=0,l,i,j,s=0;
	cin>>n>>m;
	long long a[n];
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(i=1;i<=n-1;i++)
	for(j=i+1;j<=n;j++)
	{
		if(a[i]<a[j])
		{
			k=a[i];
			a[i]=a[j];
			a[j]=k;
		}
	 } 
	 for(i=1;i<=m;i++)
	 {
	 	s=s+a[i];
	 }
	 cout<<s<<endl;
	 return 0;
 } 

Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as M
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = ((+) 0) . head <$> readLine
readLine = map (read . BS.unpack) . BS.words <$> BS.getLine
readStrings n = replicateM n $ BS.unpack <$> BS.getLine
readLines n = replicateM n readLine
toPair [x, y] = (x, y)


main = do
  [n, k] <- readLine
  p      <- readLine
  print $ solve k p
  return ()

solve :: Int -> [Int] -> Double
solve k p = maximum $ zipWith (-) (drop k sums) sums
 where
  expected = map ((\x -> (x + 1) / 2) . fromIntegral) p
  sums     = scanl' (+) 0 expected


Measured memory_bytes: 15100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
bool vis[200005];
vector<ll> gr[200005];

ll dfs(ll u)
{
	vis[u] = true;
	ll ans=1;
	for(auto v:gr[u])
	{
		if(!vis[v])
		{
			ans += dfs(v);
		}
	}
	return ans;
}


int main()
{
	ll n,m;
	cin>>n>>m;
	memset(vis,false,sizeof(vis));

	ll a,b;
	map<pair<ll,ll> ,ll> ma;
	while(m--)
	{
		cin>>a>>b;
		if(a>b)	swap(a,b);
		if(!ma[{a,b}])
		{
			gr[a].push_back(b);
			gr[b].push_back(a);
		}
	}
	ll mx=0;
	for(ll i=1;i<=n;++i)
	{
		if(vis[i]==false)
		{
			mx = max(mx,dfs(i));
		}
	}
	cout<<mx<<endl;
	

}	

Measured memory_bytes: 36592
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	bs := NewBufScanner(in)
	bw := NewBufWriter(out)
	defer bw.w.Flush()
	n, k := bs.IntScan(), bs.IntScan()

	var mod int64 = 1000000000 + 7
	d := make([]int64, k + 1)
	for i:=1; i<=k; i++ {
		d[i] = modpow(int64(k/i), mod, n)
	}
	for i:=k; i>=1; i-- {
		for j:=2*i; j<=k; j+=i {
			d[i] -= d[j]
			d[i] = (d[i] + mod) % mod
		}
	}

	var ans int64
	for i:=1; i<=k; i++ {
		ans += int64(i) * d[i] % mod
		ans = (ans + mod) % mod
	}
	bw.Printf("%v\n", int(ans))
}

func modpow(x, mod int64, n int) int64 {
	var res int64 = 1
	for n > 0 {
		if n & 1 == 1 {
			res = res * x % mod
		}
		x = x * x % mod
		n >>= 1
	}
	return res
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int {
	v, err := strconv.Atoi(b.Scan())
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 2608
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	int A,B,C,D,x,y;
	cin>>A>>B>>C>>D;
  x = max(A,C);
   y = min(B,D);
	if ((y-x)<=0){
	cout<<0<<endl;}
	else cout<<y-x<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 string s;
 int f=0;
 cin >> s;
 for(int i=0;i<s.size();i++){
   if(i%2==1&&s[i]=='R') f=1;
   if(i%2==0&&s[i]=='L') f=1;
 }
 if(f==0) cout << "Yes";
 else cout << "No";
 return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
s = []
for i in range(n):
    s.append(input())

s = collections.Counter(s)
values, counts = zip(*s.most_common())

ans = []
c_be = counts[0]
for i, c in enumerate(counts):
    if c_be == c:
        ans.append(values[i])

ans.sort()

for a in ans:
    print(a)

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

/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ld, ld>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

//const ll md = 1e9 + 7;//998244353;
const int xn = 2e5 + 10;
const int xm = -20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int Md = 1e9 + 7;
const int TM = 3;
const int Base = 257;

int n, dp[xn], last[2][26][xn], ptr, sz;
string s, ans;

int main(){
    InTheNameOfGod;
    
    cin >> s;
    n = SZ(s);
    for (int i = 0; i < 26; ++ i){
    	ptr = -1;
    	for (int j = 0; j < n; ++ j){
    		if (s[j] - 'a' == i)	ptr = j;
    		last[0][i][j] = ptr;
		}
		ptr = n;
		for (int j = n; j >= 0; -- j){
			if (j < n && s[j] - 'a' == i)	ptr = j;
			last[1][i][j] = ptr;
		}
	}
	dp[0] = n;
	for (int i = 1; i <= n; ++ i){
		if (!dp[i - 1]){
			sz = i;
			break;
		}
		int mn = inf;
		for (int c = 0; c < 26; ++ c) mn = min(mn, last[0][c][dp[i - 1] - 1]);
		if (mn == -1){
			sz = i;
			break;
		}
		dp[i] = mn;
	}
	ptr = -1;
	for (int i = 1; i <= sz; ++ i){
		for (int c = 0; c < 26; ++ c){
			if (last[1][c][ptr + 1] < dp[sz - i])	continue;
			ptr = last[1][c][ptr + 1];
			ans += char(c + 'a');
			break;
		}
	}
	cout << ans << endl;
    
	
    return 0;
}


Measured memory_bytes: 41492
x, y = map(int, input().split())

if x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12:
  x = "a"
elif x == 4 or x == 6 or x == 9 or x == 11:
  x = "b"
if y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12:
  y = "a"
elif y == 4 or y == 6 or y == 9 or y == 11:
  y = "b"

if x == y:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#ALDS1_1_C
b = 0
n = int(input())
for i in range(n):
    a = int(input())
    c = 0
    if a == 2:
        b += 1
    else:
        for j in range(2,int(a**(1/2))+1):
            if a%j == 0:
                c += 1
                break
        if c == 0:
            b += 1
print(b)


Measured memory_bytes: 5692
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  int m=n/7;
  REP(i,m+1){
    if((n-i*7)%4==0){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[105];
    cin>>n;
    long long  int s;
    s=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        s+=arr[i];
    }

    //double avg1,avg2,r1,r2,t;
    long long int avg1,avg2,r1,r2,t;
    avg1=s/n;
    avg2=(s+n-1)/n;
    r1=r2=0;
    for(int i=0;i<n;i++)
    {
        r1+=((arr[i]-avg1)*(arr[i]-avg1));
        r2+=((arr[i]-avg2)*(arr[i]-avg2));
    }

    t=min(r1,r2);
    //cout<<r1<<" "<<r2;
    cout<<t<<endl;

    return 0;
}


Measured memory_bytes: 256
# D - Maze Master
from collections import deque, defaultdict

INF = 1 << 30
MOD = 10 ** 9 + 7
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0)]


def bfs(sx: int, sy: int):
    queue = deque([(sx, sy)])
    dist = defaultdict(lambda: INF)
    dist[sx * MOD + sy] = 0
    while queue:
        x, y = queue.popleft()
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if S[nx][ny] == ".":
                if dist[x * MOD + y] + 1 < dist[nx * MOD + ny]:
                    dist[nx * MOD + ny] = dist[x * MOD + y] + 1
                    queue.append((nx, ny))
    return max(dist.values())


def main():
    global S
    H, W, *S = open(0).read().split()
    H, W = int(H) + 2, int(W) + 2
    S = ["#" * W] + ["#" + s + "#" for s in S] + ["#" * W]  # put sentinels
    ans = max(bfs(i, j) for i, s in enumerate(S) for j, c in enumerate(s) if c == ".")
    print(ans)


if __name__ == "__main__":
    main()


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int n;
    cin>>n;
    vector<int>a(n),b;
    rep(i,0,n){
        cin>>a.at(i);
    }
    rep(i,0,n){
        if(i%2==0)b.insert(b.begin(),1,a.at(i));
        else b.push_back(a.at(i));
    }
    if(n%2==0)reverse(all(b));
    rep(i,0,n){
        cout<<b.at(i)<<' ';
    }
return 0;
}

Measured memory_bytes: 3828
from itertools import permutations
n,m,r=map(int,input().split())
rlis=list(map(int,input().split()))
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
d=[[10**10]*n for _ in range(n)]
for _ in range(m):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  d[a][b]=c
  d[b][a]=c
for i in range(n):
  d[i][i]=0
dist=warshall_floyd(d)
rlisp=list(permutations(rlis,r))
ans=10**10
for i in rlisp:
  cnt=0
  for j in range(r-1):
    cnt+=dist[i[j]-1][i[j+1]-1]
  ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 52380
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a<=b&&b<=c){
		cout<<a<<" "<<b<<" "<<c<<endl;
	}
	else if(c<=a&&a<=b){
	cout<<c<<" "<<a<<" "<<b<<endl;
	}
	else if(a<=c&&c<=b){
		cout<<a<<" "<<c<<" "<<b<<endl;
	}
	else if(b<=a&&a<=c){
		cout<<b<<" "<<a<<" "<<c<<endl;
	}
	else if(b<=c&&c<=a){
		cout<<b<<" "<<c<<" "<<a<<endl;
	}
	else if(c<=b&&b<=a){
		cout<<c<<" "<<b<<" "<<a<<endl;
	}
	else if(a==b&&b==c){
		cout<<a<<" "<<b<<" "<<c<<endl;
	}



	return 0;
}


Measured memory_bytes: 3104
let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f v a) f
let () =
  Scanf.scanf "%d %d %d %d %d" @@ fun n a b c d ->
  let yn = for_fold 0 n false (fun yn k ->
    if yn then true else
    - (n-1-k) * d + k * c <= b-a && b-a <= - (n-1-k) * c + k * d) in
  print_endline @@ if yn then "YES" else "NO"

Measured memory_bytes: 384
# -*- coding: utf-8 -*-

w = int(raw_input())
num = []
for i in range(w+1):
    num.append(i)
n = int(raw_input())
for i in range(n):
    a, b = map(int, raw_input().split(','))
    num[a], num[b] = num[b], num[a]
for i in range(1, w+1):
    print num[i]

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

const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<pair<double,double>> town(n);
  for(int i=0;i<n;i++){
    double x,y;
    cin >> x;
    cin >> y;
    town.at(i).first = x;
    town.at(i).second = y; 
  }
  double keiro = 0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      keiro += sqrt((town.at(i).first - town.at(j).first)*(town.at(i).first - town.at(j).first)+(town.at(i).second - town.at(j).second)*(town.at(i).second- town.at(j).second));
    }
  }
  cout << std::setprecision(10)<<keiro * 2 / n <<endl;
}

Measured memory_bytes: 256
ans = ''
while True:
    m, f, r = map(int, input().split(' '))
    if (m == -1 and f == -1) and r == -1:
        break
    else:
        x = m + f
        if (m == -1) or (f == -1):
            ans += 'F\n'
        elif x >= 80:
            ans += 'A\n'
        elif x >= 65:
            ans += 'B\n'
        elif x >= 50:
            ans += 'C\n'
        elif x >= 30:
            if r >= 50:
                ans += 'C\n'
            else:
                ans += 'D\n'
        else:
            ans += 'F\n'
if ans != '':
    print(ans[:-1])


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
  uint64_t n;
  uint64_t m,x;
  cin>>n>>x>>m;
  vector<int64_t> r(m,-1);
  vector<int64_t> sum(2,0);
  sum[1]=x;
  r[x]=1;
  int curr=2;
  uint64_t next=x*x%m;
  while(r[next]==-1){
    r[next]=curr;
    sum.push_back(sum[sum.size()-1]+next);
    next=next*next%m;
    curr++;
  }
  int roop_num=curr-r[next];
  uint64_t roop_sum=sum[curr-1]-sum[r[next]-1];
  if(n<curr){
    cout<<sum[n]<<endl;
    return 0;
  }
  uint64_t result=sum[r[next]-1];
  uint64_t i=r[next]-1+(n-r[next]+1)/roop_num*roop_num;
  result+=(n-r[next]+1)/roop_num*roop_sum;
  if(i<n){
    result+=sum[r[next]-1+n-i]-sum[r[next]-1];
  }
  cout<<result<<endl;
}
  

Measured memory_bytes: 4676
import collections
n = int(input())
s = [input() for _ in range(n)]
m = int(input())

for i in range(m):
    t = input()
    if t in s:
        s.remove(t)

c = collections.Counter(s)
c = list(c.most_common())
if c:
    print(c[0][1])
else:
    print(0)

Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
using namespace std;
#define Rep(i,n) for(int i = 0; i < n; ++i)
#define For(i, s, e) for(int i = s; i <= e; ++i)
char s[10];

int main()
{
	scanf("%s", &s);
	int a = 0;
	Rep(i, 4) {
		if (s[i] == '+') ++a;
		else --a;
	}
	printf("%d", a);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	int H[21];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> H[i];
	int ans = 0;
	for (int i = 0; i < N; i++) {
		bool ok = true;
		for (int j = 0; j < i; j++) {
			if (H[i] < H[j]) {
				ok = false;
				break;
			}
		}
		if (ok) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3576
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main {
 
    public static void main(String[] args) throws Exception {
        
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringBuffer sb = new StringBuffer();
    	
        int count = Integer.parseInt(br.readLine());
        String[] str = br.readLine().split(" ");
 
        for (int i = 1; i < count; i++) {
            System.out.println(String.join(" ",str));
            for (int j = i - 1; j >= 0; j--) {
                if (Integer.parseInt(str[j]) > Integer.parseInt(str[j + 1])) {
                    String tmpNum = str[j];
                    str[j] = str[j + 1];
                    str[j + 1] = tmpNum;
                }
            }
        }
        System.out.println(String.join(" ",str));
    }
}

Measured memory_bytes: 27356
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<ll> C(n);
    C[0] = 0;
    for (ll i = 0; i <n; ++i) {
        C[i] = C[i-1];
        if (s[i-1] == 'A' && s[i] == 'C') {
            ++C[i];
        }
    }
    for (ll i = 0; i < q; ++i) {
        ll l, r;
        cin >> l >> r;
        //cout << l << "," << r << endl;
        --l;
        --r;
        cout << C[r] - C[l] << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
using namespace std;
int n,m,k;
int a[2][100010];
bool visit[100010];
int res=0;
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<n;i++) cin >>a[0][i];
	sort(a[0],a[0]+n);
	for (int i=0;i<n;i++) a[1][i]=a[0][i]+k;
	for (int i=0;i<n;i++)
	{
		if (visit[i]) continue;
		for (int j=i;j<n;j++)
		{
			if (j-i+1>m) break;
			if (a[0][j]>a[1][i]) break;
			visit[j]=1;
		}
		/*cout <<i<<" ##\n";
		for (int j=0;j<n;j++) cout <<visit[j]<<" ";
		cout <<"\n";*/
		res++;
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
using namespace std;
struct info{
  int value;
  int weight;
};
int search_value(int i,info *item,int bag_weight);
int V[10010];
int main(){
  int N,W;
  int c;
  cin >> N >> W;
  std::vector<info> item(102);
  for(int i = 0; i < N; i ++){
    cin >> item[i].value;
    cin >> item[i].weight;
  }
    for(int i = 0; i < N; i++)
      for(int c = item[i].weight; c <= W; c++){
	if(V[c-item[i].weight]+item[i].value > V[c])
	  V[c] = V[c-item[i].weight]+item[i].value;
    }
  cout << V[W] <<endl;
  return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;
ll dp[100005][5];
// dp[i+1][0] := i文字目まで見た時にABCとの照合をスタートしていないものの個数
// dp[i+1][1] := i文字目まで見た時にABCとの照合においてAまでは照合させたようなものの個数
// dp[i+1][2] := i文字目まで見た時にABCとの照合においてBまでは照合させたようなものの個数
// dp[i+1][3] := i文字目まで見た時にABCとの照合においてCまでは照合させたようなものの個数

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	dp[0][0] = 1;
	
	for(int i=0;i<S.size();i++){
		for(int j=0;j<5;j++){
			if(S[i] == '?') dp[i+1][j] = dp[i][j] * 3;
			else dp[i+1][j] += dp[i][j];
			dp[i+1][j] %= mod;
		}
		if(S[i] =='A' || S[i] == '?')dp[i+1][1] += dp[i][0];
		if(S[i] =='B' || S[i] == '?')dp[i+1][2] += dp[i][1];
		if(S[i] =='C' || S[i] == '?')dp[i+1][3] += dp[i][2];
	}
	cout << dp[S.size()][3]%mod << endl;
}

Measured memory_bytes: 4432
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n; cin>>n;
    vector<T> v;
    for(int i=0; i<n; i++){
        string s; cin>>s;
        int m; cin>>m;
        v.eb(T(s, m, i));
    }

    sort(v.begin(), v.end());

    int cnt = 0;
    vector<int> ans(n+10);
    for(int i=0; i<n; i++){
        vector<P> v2;
        string t = get<0>(v[i]);
        v2.eb(P(get<1>(v[i]), get<2>(v[i])));

        while(i + 1 < n && get<0>(v[i+1]) == t){
            v2.eb(P(get<1>(v[i+1]), get<2>(v[i+1])));
            i++;
        }

        sort(v2.begin(), v2.end(), greater<P>());
        for(int j=0; j<v2.size(); j++){
            ans[cnt++] = get<1>(v2[j]);
        }
    }

    for(int i=0; i<n; i++) cout << ans[i] + 1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N;
	int T , A;
	int H[1000];
	if(scanf("%d %d %d",&N ,&T ,&A));
	for(int i=0;i<N;i++){
		if(scanf("%d",&H[i]));
	}
	int x[N];
	for(int j=0;j<N;j++){
		x[j] = 1000*A - (1000*T - 6*H[j]);
		if(x[j]<0){
			x[j] *= -1;
		}
	}
	int min = 0;
	for(int k=1;k<N;k++){
		if(x[k] < x[min]){
			min = k;
		}
	}
	printf("%d\n",min+1);
	return 0;
}
		
		


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm> 

using namespace std;

int rec_helper(const vector<int>&s, int pos, int k, vector<int>& cache)
{
	if (pos == 0)
		return 0;
	if (cache[pos] != - 1) {
		return cache[pos];
	}	
	int res = numeric_limits<int>::max();
	for(int i = 1; i <= k; i++) {
		if(pos >= i)
			res = min(res, rec_helper(s, pos - i, k, cache) + abs(s[pos] - s[pos - i]));
	}
	cache[pos] = res;
	return res;
}

int sol_rec(const vector<int>&s, int k)
{
	vector<int> cache(s.size(), -1);
	return rec_helper(s, (int)s.size()-1, k, cache);
}




int main()
{
	int N;
	int K;
	cin >> N >> K;
	vector<int> s(N);
	for(int i = 0; i < N; i++) {
		cin >> s[i];
	}
	cout << sol_rec(s, K) << endl;
}


Measured memory_bytes: 8832
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTPAIR(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define PRINTSET(x) for (auto it = x.begin(); it != x.end(); it++) { std::cout << *it << ' '; } std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;
using namespace std;


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

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1) {
        c -= b;
        if (c <= 0) return cout << "Yes",0;
        a -= d;
        if (a <= 0) return cout << "No",0;
    }

    #ifndef ONLINE_JUDGE   
    std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> vec(n);
    REP(i,n)cin >> vec[i];
    vector<ll> kazu1(n,0);
    //一番最初の数；
    REP(i,n){
        FOR(j,i+1,n){
            if(vec[i]>vec[j])kazu1[i]++;
        }
    }
    //それ以降はindezがiよりも小さくても転倒数としてカウントされる
    vector<ll> kazu2(n,0);
    //一番最初の数；
    REP(i,n){
        REP(j,n){
            if(vec[i]>vec[j])kazu2[i]++;
        }
    }
    ll test= (k*(k-1)/2)%MOD;
    ll ans = 0;
    REP(i,n){
        ans += (kazu1[i]*k+kazu2[i]*test)%MOD;
        ans %= MOD;
    }
    COUT(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
const int maxnfact = 100010;
const ll md = 1e9+7;
ll N, K;
ll fact[maxnfact], fact_inv[maxnfact];
ll A[maxnfact];

inline long long add(long long a, long long b) {
 a += b;
 if (a >= md) a -= md;
 return a;
}

inline long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += md;
  return a;
}

inline long long mul(long long a, long long b) {
  return  (a * b) % md;
}

inline long long mdpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

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

void pre() {
  fact[0] = 1;
  fact_inv[0] = 1;
  for(int i = 1; i < maxnfact; i++){
    fact[i] = mul(fact[i-1], i);
  }
  fact_inv[maxnfact - 1] = mdpow(fact[maxnfact - 1], md - 2);
  for (int i = maxnfact-1-1; i >= 1; i--) {
    fact_inv[i] = mul(fact_inv[i+1], i+1);
  }
}

inline ll nck(ll n, ll k) {
  if (k == 0) return 1;
  if (n < k) return 0;
  return mul(mul(fact[n], fact_inv[n-k]), fact_inv[k]);
}

int main() {
  fastio;
  cin >> N >> K;
  pre();
  for (int i = 0; i < N; i++) { cin >> A[i]; }
  sort(A, A + N);
  ll res = 0;
  ll choose;
  for (int i = 0; i < N; i++) {
    choose = nck(N - i - 1, K-1);
    res = sub(res, mul(A[i], choose));
    choose = nck(i, K-1);
    res = add(res, mul(A[i], choose));
  }
  cout << res << endl;
}


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

ll gcd(ll a, ll b) //最大公約数
{
    if(a < b) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a, ll b) //最小公倍数、gcdとセット
{
    ll g = gcd(a,b);
    return a  / g*b;
}

int main(){
    int n;
    cin >> n;
    ll ans=1LL;
    rep(i,n){
        ll t; 
        cin >> t;
        ans=lcm(ans,t);
    }
   
    cout << ans << endl;
    

}

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

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


int main(){
    int X,N;
    cin >> X >> N;
    if(N==0){
        cout << X << endl;
        return 0;
    }
    int Z=0,flag_zero=1,flag_p=0,flag_m=0;
    vector<int>p(N);
    rep(i,N){
        cin >> Z;
        p.at(i)=X-Z;
        if(p.at(i)==0){
            flag_zero=0;
        }
    }

    if(flag_zero==1){
        cout << X << endl;
        return 0;    
    }

    Z=1;
    int i=0;

    while(1){
        flag_p=0;
        flag_m=0;
    rep(i,N){
        if(p.at(i)-Z==0){
            flag_m=1;
        }else if(p.at(i)+Z==0){
            flag_p=1;
        }
    }

        if(flag_m==0){
            cout << X-Z << endl;
            return 0;
        }else if(flag_p==0){
            cout << X+Z << endl;
            return 0;
        }else{
            Z++;
        }
    }
        /*rep(i,N){
            rep(j,N){
            if(-j==p.at(i)){
                flag_m=1;
            }else if(j==p.at(i)){
                flag_p=1;
            }

            if(flag_m=0){
                cout << X-j << endl;
            }else if(flag_p=0){
                cout << X+j << endl;
            }
            }
        }*/
    

    
       
    
       

}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        int x=i/10,y=x/10,z=y/10;
        if(i%3==0){
            cout << " " << i;
        }else if (i%10==3 || x%10==3 || y%10==3 || z%10==3 ){
            cout << " " << i;
        }
        
    }cout << endl;
}


Measured memory_bytes: 3080
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] list = new int[n];
		int tmp = 0;
		int j;
		for(int i = 0;i<n;i++){
			list[i] = sc.nextInt();
		}
		for(int i = 0;i<n;i++){
			tmp = list[i];
			j = i - 1;
			while(j >= 0 && list[j] > tmp){
				list[j+1] = list[j];
				j--;
				list[j+1] = tmp;
			}
			System.out.print(list[0]);
			for(int k = 1;k<n;k++){
				System.out.print(" " + list[k]);
			}
			System.out.println();
		}
	
	}
}



Measured memory_bytes: 33464
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)


int main(){
   ll n;
   ll ans=0;
   string s;
   cin >> n;
   for (ll i=1;i <= n;i++){
      if (i%5==0 || i%3==0) continue;
      ans+=i;
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3624
N = int(input())
T = list(map(int, input().split(" ")))
A = list(map(int, input().split(" ")))
h = [0 for i in range(N)]
mod = 10 ** 9 + 7

h[0] = T[0]
for i in range(N - 1):
    if T[i] < T[i + 1]:
        h[i + 1] = T[i + 1]
    else:
        h[i + 1] = -T[i + 1]

if h[N - 1] == 0:
    h[N - 1] = A[N - 1]
else:
    if -h[N - 1] >= A[N - 1]:
        h[N - 1] = A[N - 1]
    elif h[N - 1] != A[N - 1]:
        h[N - 1] = 0

for i in range(1, N):
    if A[i - 1] > A[i]:
        if -h[i - 1] >= A[i - 1]:
            h[i - 1] = A[i - 1]
        elif h[i - 1] != A[i - 1]:
            h[i - 1] = 0
    else:
        if h[i - 1] < 0:
            h[i - 1] = -min(-h[i - 1], A[i - 1])


ans = 1
for hi in h:
    if hi <= 0:
        ans *= -hi
        ans %= mod

print(ans)

Measured memory_bytes: 90588