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

using namespace std;

int main(){
        long long n,k;
        cin>>n>>k;
        long long ans = 0;
        for(int i=k+1;i<=n;i++){ //B
                ans += (i-k)*(n/i);
                if(k!=0) ans += max(0LL,(n%i)-k+1);
                else ans += max(0LL,(n%i)-k);
                //cout<<"total:" <<((i-k)*(n/i))<<" tail:"<<max(0LL,(n%i)-k)<<endl;
        }
        cout<<ans<<endl;
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9
// fflush(stdout);
//lower_bound,upper_bound,equal_range
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	int n,k;
	cin>>n>>k;
	vector<int>h(n+1);
	h[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	vector<int>dp(n+1,INT_MAX);
	dp[1]=0;
	dp[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i-j>=1)dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}	
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 4056
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll A, B;
	char op;
	cin >> A >> op >> B;
	if (op == '+') { cout << A + B << endl; }
	else { cout << A - B << endl; }
}


Measured memory_bytes: 3568
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int count = 0;
    int sum = 0;

    Integer a[] = new Integer[N];
    for(int i = 0; i < N; i++){
      a[i] = sc.nextInt();      
    }
    Arrays.sort(a, Comparator.reverseOrder());
    
    for (int i = 0; i < N; i++){
     sum += a[i];
    }

    for (int i = 0; i < N; i++){
      if(a[i]*4*M >= sum){
        count++;
      }
    }
    
    if(count >= M){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(vector<T> v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    int c[1010], s[1010], f[1010];
    cin >> n;
    rep(i, n-1){
        cin >> c[i] >> s[i] >> f[i];
    }

    rep(i, n){
        ll time = 0;
        reps(j, i, n-2){
            if(time < s[j]) time = s[j];
            else if(time % f[j] == 0);
            else time = time + f[j] - time % f[j];
            time += c[j];
        }
        cout << time << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

const double EPS = 1e-5;

double ix1, ix2, ix3, ixp;
double iy1, iy2, iy3, iyp;

//2点の座標から辺の長さを求める
double sideLength(double x1, double y1, double x2, double y2) {
    return sqrt( pow(fabs(x1-x2), 2.0) + pow(fabs(y1-y2), 2.0) );
}

//3辺の長さから三角形の面積を求める
double heron(double a, double b, double c) {
    double s = (a + b + c) / 2;
    return sqrt( s * (s-a) * (s-b) * (s-c) );
}

int solve1() {
    double ab = sideLength(ix1, iy1, ix2, iy2),
           bc = sideLength(ix2, iy2, ix3, iy3),
           ca = sideLength(ix3, iy3, ix1, iy1),
           ap = sideLength(ix1, iy1, ixp, iyp),
           bp = sideLength(ix2, iy2, ixp, iyp),
           cp = sideLength(ix3, iy3, ixp, iyp);
    
    double Sabc  = heron(ab, bc, ca);
    double Sabcp = heron(ab, bp, ap) + heron(ca, ap, cp) + heron(bc, bp, cp);
    return fabs(Sabcp - Sabc) < EPS;
}

int main() {
     while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &ix1, &iy1, &ix2, &iy2, &ix3, &iy3, &ixp, &iyp) != EOF){
         if(solve1()) {
         	printf("YES\n");
         } else {
         	printf("NO\n");
         }
     }
}


Measured memory_bytes: 1984
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(BigInt,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  a,b=pM(split(readline()))
  if (a>0) != (b>0) || a==0 || b==0
    println("Zero")
  elseif a<0 && abs(a-b)%2==0
    println("Negative")
  else
    println("Positive")
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


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

int main () 
{
    int A, B, X;
    
    std::cin >> A >> B >> X;
    
    if (A <= X)
    {
        if ( A + B >= X )
        {
            std::cout << "YES" << std::endl;
        }
        else
        {
            std::cout << "NO" << std::endl;
        }
    }
    else
    {
        std::cout << "NO" << std::endl;
    }
    
    
    return 0;
}

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

using namespace std;
typedef unsigned long long ullong;

ullong power(ullong x, ullong n, ullong M){
	ullong res = 1;
	if(n>0){
		res = power(x, n/2, M);
		if(n%2 == 0)
			res = (res*res)%M;
		else
			res = (((res*res)% M)*x) % M;
	}
	return res;
}

int main() {
	int m, n;
	cin >> m >> n;
	cout << power(m, n, 1000000007) << endl;
	return 0;
}


Measured memory_bytes: 3100
A, B, C, X, Y = map(int, input().split())

non_AB = A*X + B*Y
if X>Y:
#BをABから作る
    non_B = C*2*Y + A*(X-Y)
#AをABから作る
    non_A = C*2*X
else:
    non_A = C*2*X + B*(Y-X)
    non_B = C*2*Y


# print(min(non_AB, use_AB))
print(min(non_AB, non_A, non_B))




Measured memory_bytes: 2940
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 入力
        int n = sc.nextInt();
        int k = sc.nextInt();

        // 処理
        long[] mon = new long[n];
        for (int i = 0; i < n; i++) {
            mon[i] = sc.nextLong();
        }
        Arrays.sort(mon);

        long out = 0;
        if (k >= n) {
            out = 0;
        } else {
            for (int i = (n - 1 - k); i >= 0; i--) {
                out += mon[i];
            }
        }

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 90940
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        a: char
    }

    if a.is_lowercase() {
        println!("a");
    } else {
        println!("A");
    }
}


Measured memory_bytes: 2132
import sys
import math
import fractions
import bisect
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''


H, N = map(int, input().split())
A = []
B = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    A.append(x1)
    B.append(y1)


dp = [[INF] * (H+10) for i in range(N)] # 魔法iまでを使って体力をj減らすのに必要な最小のコスト

for hp in range(H+10):
    dp[0][hp] = ((hp//A[0]) + int(hp%A[0] != 0))*B[0]

for magic in range(1, N):
    for hp in range(H+10):

        if hp-A[magic] >= 0:
            dp[magic][hp] = min(dp[magic-1][hp], dp[magic][hp-A[magic]] + B[magic])
        else:
            dp[magic][hp] = min(dp[magic-1][hp], B[magic])


print(dp[N-1][H])

Measured memory_bytes: 290804
var x = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = x.split(/\n/);
var n = Number(lines[0]);
var arr = lines[1].split(/\s/).map(Number);
min = arr[0]; max = arr[0]; sum = arr[0];
for (var i=1; i < n ; i++){
  if (min > arr[i]) min = arr[i];
  if (max < arr[i]) max = arr[i];
  sum += arr[i];
};
console.log(min +" "+ max +" "+ sum);



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  bool flag = true;
  int a1, a2, a3, b1, b2, b3;
  a1 = 0;
  vector<vector<int>> c(3, vector<int>(3));
  REP(i, 3) REP(j, 3) cin >> c[i][j];
  b1 = c[0][0] - a1;
  b2 = c[0][1] - a1;
  b3 = c[0][2] - a1;
  a2 = c[1][0] - b1;
  a3 = c[2][0] - b1;
  if(a2 + b2 != c[1][1] or a2 + b3 != c[1][2] or a3 + b2 != c[2][1] or
     a3 + b3 != c[2][2]) {
    flag = false;
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main(){
  long long N;
  cin >> N;
  
  vector<long long> staff(N);
  for (long long si = 1; si < N; si++){ cin >> staff[si]; }
  
  vector<long long> res(N+1, 0);
  for (long long si = 0; si < N; si++){ res[staff[si]]++; }
  
  for (long long si = 1; si <=N; si++){
    cout << res[si];
    if (si < N) cout << " ";
    else cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6224
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
//tokiomarine
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    bool ok=0;
    ll at=v*t,bt=w*t;
    if(a<b){
        if(a+at>=b+bt) ok=1;
    }else{
        if(a-at<=b-bt) ok=1;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3692
function main(arg) {
    var a = arg.split(/\s+/g)[0];
    var b = arg.split(/\s+/g)[1];
    var x = arg.split(/\s+/g)[2];
    var theta = 0;
    if(x>=b*(a*a)/2){
	    theta = Math.atan(2/a*(b-x/(a*a)));
    }else{
        theta = Math.atan(a*(b*b)/(2*x));
    }
    var kekka = theta * ( 180 / Math.PI ) ;
    console.log(kekka);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        new aoj0296().doIt();
    }
    class aoj0296 {
        void doIt(){
        	int sum = sc.nextInt();
        	sum = sum + sc.nextInt()*5;
        	sum = sum + sc.nextInt()*10;
        	sum = sum + sc.nextInt()*50;
        	sum = sum + sc.nextInt()*100;
        	sum = sum + sc.nextInt()*500;
        	if(sum >= 1000)System.out.println(1);
        	else System.out.println(0);
        }
    }
}

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

int main() {
  int A , B, C, D ;
  cin >> A >> B >> C >> D;
  int x = A + B, y =C + D;
  cin >> x ,y;
  if ( x > y ){
    cout << " Left " << endl;
  }
  else if ( x == y ) {
    cout << " Balanced " << endl;
  }
  else {
    cout << " Right " << endl;
  return 0 ;
  }
}


Measured memory_bytes: 256
#include<string.h>
#include<stdio.h>
int main(){
	char s1[105],s2[105];
	scanf("%s%s",s1,s2);
	int n=strlen(s1);
	for(int i=0;i<n;i++){
		char s=s2[0];
		for(int j=0;j<n-1;j++){
			s2[j]=s2[j+1];
		}
		s2[n-1]=s;
		if(strcmp(s1,s2)==0){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  
  
  int ans=0;
  
  int sum=1;
  
  for(int i=0;i<N;i++){
    if(A[i]==A[i+1]){
      sum++;
    }
    else{
      if(sum%2==1){
        ans++;
      }
      sum=1;
    }
  }
  
  cout<<ans<<endl;
}

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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define pb              push_back
#define endl            "\n"

#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 2e5 + 7;



void solve()
{
	int n; cin >> n;
	int sum = 0;
	loop(i, 1, n + 1)
	{
		if ((i % 3 != 0) and (i % 5 != 0))
			sum += i;
	}
	cout << sum;

	return;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    string s;
    cin >> n >> s >> k;
    for (auto &&i : s) {
        if(i != s[k-1]) i = '*';
    }
    cout << s << "\n";
    return 0;
}


Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()

accumlate=[0]
now=0
for i in range(1,n):
    if s[i-1]=="A" and s[i]=="C":
        now+=1
    accumlate.append(now)

ans_list=[]
for g in range(q):
    l,r=map(int,input().split())
    ans_list.append(accumlate[r-1]-accumlate[l-1])

for m in range(q):
    print(ans_list[m])


Measured memory_bytes: 59212
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<list>
using namespace std;
struct DFST{
	int to;
	long long cost;
};
vector<DFST> tree[100010];//K距離
long long depth[100010];
void DFS(int v,int parent,long long d){
	//cout <<"aaa" << endl;
	depth[v] = d;
	for(auto &e:tree[v]){
		if(e.to==parent){
			continue;
		}else{
			DFS(e.to,v,d+e.cost);
		}
	}
	return;
}
int main(void){
	int i,j,Q,N,W,K;
	cin >> N;
	int a,b;
	long long c;
	for(i=0;i<N-1;i++){
		cin >>a>>b>>c;
		a-=1;
		b -=1;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	}
	cin >>Q>>K;
	K--;
	DFS(K,-1,0);
	int x,y;
	for(i=0;i<Q;i++){
		cin >> x >> y;
		x-=1;
		y-=1;
		cout <<depth[x]+depth[y]<<endl;
	}

	return 0;
}

Measured memory_bytes: 14336
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

int main(void){
	int x=nextint();
	int y=nextint();
	bool f=(y%2==0 && y>=x*2 && x*4>=y);
	puts(f?"Yes":"No");
}



Measured memory_bytes: 1532
N = int(input())
p = [1] * (N+1)
for i in range(2,N+1):
    j = 2
    while i >= j:
        if i%j == 0:
            p[j] += 1
            i //= j
        else:
            j += 1
    if i > 1:
        p[i] += 1
p.sort(reverse = True)

def num(x):
    i = 0
    while p[i] >= x:
        i += 1
    return i
print(num(75) + num(25)*(num(3)-1) + num(15) * (num(5)-1) + num(5) * (num(5)-1) * (num(3)-2)//2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    ll X;
    cin >> X;
    rep(a,10000)rep(b,10000){
        ll A = a*a*a*a*a;
        ll B = b*b*b*b*b;
        if(A-B== X){
            cout << a << " " << b << endl;
            return 0;
        } else if(A-(-1*B) == X){
            cout << a << " " << -1*b << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3596
#include <iostream>

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

  int debt = 100000;
  for (int i = 0; i < n; ++i) {
  	debt = int(double(debt) * 1.05);
    if (debt % 1000 != 0) {
    	debt = ((debt / 1000) + 1) * 1000;
    }
  }

  std::cout << debt << std::endl;

  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <tuple>
#include <numeric>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <regex>
#include <stack>
#include <limits>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	const int M = 1000000007;
	cin >> n;
	if (n == 1) { cout << "0\n"; return 0;  }
	long long res = 0;
	long long ten = 1;
	for (int i = 0; i < n; ++i) {
		ten = (ten * 10) % M;
	}
	long long nine = 1;
	for (int i = 0; i < n; ++i) {
		nine = (nine * 9) % M;
	}

	long long eight = 1;
	for (int i = 0; i < n; ++i) {
		eight = (eight * 8) % M;
	}

	res = (ten + eight) % M;
	res = (res + 2 * M - 2 * nine) % M;

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3168
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j,k;
  int a[50],b[50],m,n,p;
  while(cin>>m>>n){
    for(i=0;i<m;i++)
      a[i]=i;
    for(i=0;i<n;i++){
      cin>>p;
      h=0;
      for(j=0;j<(m+1)/2;j+=p){
	for(k=0;k<p&&m/2+j+k<m;k++){
	  b[h]=a[m/2+j+k];
	  h++;
	}
	for(k=0;k<p&&j+k<m/2;k++){
	  b[h]=a[j+k];
	  h++;
	}

      }
      memcpy(a,b,sizeof(a));
    }
    cout<<a[m-1]<<endl;;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 52;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

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

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;

string S[NMAX];
vec v;
int dp[26] = {};
string ans;

void solve(){
  // main algorithm
  for(auto&& ch : S[0]) {
    dp[ch - 'a']++;
  }
  for (int i = 1; i < N; ++i)
  {
    int ddp[26] = {};
    for(auto&& ch : S[i]) {
      ++ddp[ch - 'a'];
    }
    for (int j = 0; j < 26; ++j)
    {
      dp[j] = min(dp[j], ddp[j]);
    }
  }

  for(int i = 0; i < 26; ++i) {
    for(int j = 0; j < dp[i]; ++j) ans += (char)('a' + i);
  }
}

void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    cin >> S[i];
  }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    for(int i = 0; i < n; ++i)  cin >> b[i];
    ll ans = 0;
    for(int d = 0; d < 30; ++d){
        vector<int> am(n), bm(n);
        ll Base = 1 << (d + 1);
        for(int i = 0; i < n; ++i){
            am[i] = a[i] % Base;
            bm[i] = b[i] % Base;
        }
        sort(bm.begin(), bm.end());
        ll cnt = 0;
        Base >>= 1;
        for(int i = 0; i < n; ++i){
            cnt += lower_bound(bm.begin(), bm.end(), Base * 4 - am[i]) - lower_bound(bm.begin(), bm.end(), Base * 3 - am[i]);
            cnt += lower_bound(bm.begin(), bm.end(), Base * 2 - am[i]) - lower_bound(bm.begin(), bm.end(), Base - am[i]);
        }
        ans += Base * (cnt % 2 != 0);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int D;
	int[] c;
	int[][] s;
	int[] last;

	Main(BufferedReader in) throws IOException {
		D = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		c = new int[tokens.length];
		for (int i = 0; i < tokens.length; ++i) {
			c[i] = Integer.parseInt(tokens[i]);
		}
		s = new int[D][c.length];
		for (int i = 0; i < D; ++i) {
			tokens = in.readLine().split(" ");
			for (int j = 0; j < tokens.length; ++j) {
				s[i][j] = Integer.parseInt(tokens[j]);
			}
		}
		last = new int[c.length];
		Arrays.fill(last, 0);
	}

	int sub(int day, int contest) {
		int result = s[day][contest];
		int minus = 0;
		for (int i = 0; i < c.length; ++i) {
			if (i != contest) {
				minus += (day - last[contest]) * c[contest];
			}
		}
		return result - minus;
	}

	int sub(int day) {
		// 最も得られる満足度が高いものを選ぶ
		int result = -1;
		int max = Integer.MIN_VALUE;
		for (int contest = 0; contest < c.length; ++contest) {
			int effort = sub(day, contest);
			if (max < effort) {
				result = contest;
				max = effort;
			}
		}

		return result;
	}

	void calc() {
		// まずは最大のSを選ぶことにする
		for (int i = 0; i < D; ++i) {
			int r = sub(i);
			if (r >= 0) {
				System.out.println((r + 1));
				last[r] = i;
			} else {
				System.out.println("1");
				last[0] = i;
			}

		}
	}

	void showResult() {
	}
}

Measured memory_bytes: 36332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X;
  int count = 0;
  cin >> N >> X;
  vector<int> Ls(N);
  vector<int> Ds((N + 1), 0);
  for (int i = 0; i < N; i++) { cin >> Ls.at(i); }
  for (int i = 1; i < N + 1; i++) { Ds.at(i) = Ds.at(i - 1) + Ls.at(i - 1); }
  for (int i = 0; i < N + 1; i++) { if (Ds.at(i) <= X) { count++; } }
  cout << count << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(list(enumerate(a)), key=lambda x: -x[1])
    L = [i for i in range(n+2)]  # 連結成分のうち一番左のindex
    R = [i for i in range(n+2)]  # 連結成分のうち一番右のindex
    ans = 0
    for i, j in a:  # 1-indexなので1ずれる
        M = R[i+1]  # 連結成分の最大値
        m = L[i+1]  # 連結成分の最小値
        ans += j*(M-i)*(i+2-m)  # 計算
        R[m-1] = M  # 連結成分の左端の更新
        L[M+1] = m  # 連結成分の右端の更新
    print(ans)


main()

Measured memory_bytes: 46840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int diffMax = 0;
    int ans = 0;
    for (int i = 0; i < 5; ++i) {
        int a;
        cin >> a;

        int aa = ((a + 9) / 10) * 10;
        ans += aa;
        diffMax = max(diffMax, aa - a);
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

bool isPrime[1000010];

void set_prime() {
    for(int i = 0; i <= 1000010; i++) isPrime[i] = true;
	isPrime[0] = false;
	isPrime[1] = false;
	for (int i = 2; i < 2000; i++) {
		int j = 2;
		while (i * j <= 1000000) {
			isPrime[i*j] = false;
			j++;
		}
	}
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    set_prime();
    REP(i, X, X + 10000) {
        if(isPrime[i]) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;

const int N = 600005;

int n, m;
int a[N];
long long ansLeft[N], ansRight[N];

int main() {
    scanf("%d", &n);
    m = 3 * n;
    for (int i = 1; i <= m; i++) {
        scanf("%d", &a[i]);
    }
    priority_queue<int> Q;
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        Q.push(-a[i]);
        sum += a[i];
    }
    ansLeft[n] = sum;
    for (int i = n + 1; i <= 2 * n; i++) {
        sum += a[i];
        Q.push(-a[i]);
        sum -= -Q.top();
        Q.pop();
        ansLeft[i] = sum;
    }
    sum = 0;
    while (!Q.empty()) Q.pop();
    for (int i = 3 * n; i > 2 * n; i--) {
        sum += a[i];
        Q.push(a[i]);
    }
    ansRight[2 * n + 1] = sum;
    for (int i = 2 * n; i > n; i--) {
        sum += a[i];
        Q.push(a[i]);
        sum -= Q.top();
        Q.pop();
        ansRight[i] = sum;
    }
    
    long long best = -1e18;
    for (int i = n; i <= 2 * n; i++) {
        best = max(best, ansLeft[i] - ansRight[i + 1]);
    }
    printf("%lld\n", best);
}

Measured memory_bytes: 8056
#include <iostream>

using namespace std;

int main()
{
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  for(int i = 0;i < K;i++){
    if(A >= B)
      B = B * 2;
    else if(B >= C)
      C = C * 2;
    else
      continue;
  }
  string ans = "No";
  if(A < B && B < C)
    ans = "Yes";
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
         ll n,k=-1,mt=0;
         cin>>n;
         ll ar[n+5];
         ll ans=0;
         vector<ll>v;
         ar[0]=-1;
         for(ll i=0;i<n;i++)
         {
             cin>>ar[i];
         }
         ll nn=0;
         ll cnt=0;
         ar[n]=*max_element(ar,ar+n);
         ll mx=ar[0];
         for(ll i=1;i<=n;i++)
         {
             if(ar[i]<mx){nn=mx-ar[i];cnt+=nn;mx=max(mx,ar[i]);}
            else {mx=max(mx,ar[i]);}
           // cout<<cnt<<endl;

         }

         cout<<cnt<<endl;

}


Measured memory_bytes: 5092
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=n;i>=0;--i)
const ll INF = 1e16;
using Edges = vector<vector<pii>>;

void dijkstra(Edges &edge, vector<ll> &cost, int start, int N) {
  cost.resize(N);
  priority_queue<pil, vector<pil>, greater<pil> > q;
  fill(cost.begin(), cost.end(), INF); cost[start] = 0;
  q.push(make_pair(0, start));

  while (!q.empty()) {
    pil p = q.top(); q.pop();
    ll u = p.second;
    ll cur_cost = p.first;

    if (cost[u] < cur_cost)
      continue;
    for (const pii e : edge[u]) {
      int v = e.first;
      ll edge_cost = e.second;
      if (cost[v] > cost[u] + edge_cost) {
        cost[v] = cost[u] + edge_cost;
        q.push(make_pair(cost[v], v));
      }
    }
  }
}

int main() {
  int N, M; cin >> N >> M;
  int s, t; cin >> s >> t;
  --s, --t;

  Edges edge(N, vector<pii>()),
       edge2(N, vector<pii>());
  rep(i, M) {
    int u, v;
    int a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    edge[u].emplace_back(v, a);
    edge[v].emplace_back(u, a);
    edge2[u].emplace_back(v, b);
    edge2[v].emplace_back(u, b);
  }
  vector<ll> cost1, cost2;
  dijkstra(edge, cost1, s, N);
  dijkstra(edge2, cost2, t, N);

  ll max_snuuk = 0;
  ll res[N];
  rrep(i, N-1) {
    // sからiまで円で行って、iからtまでスヌークで行く
    ll tmp = 1e15 - (cost1[i] + cost2[i]);
    max_snuuk = max(max_snuuk, tmp);
    res[i] = max_snuuk;
  }
  rep(i, N)
    cout << res[i] << endl;

  return 0;
}


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


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}
int main()
{
	str s, t;
	cin >> s >> t;
	rep(i, t.size() + 1)
	{
		char tmp = t.back();
		t = tmp + t;
		t.pop_back();
		if (s == t)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

/*
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}*/

int n, h, amax, a, mem, cnt;
vector<int>b;

int main(){
	cin >> n >> h;
	amax = 0;
	lp(n) {
		cin >> a >> mem;
		amax = max(amax, a);
		b.push_back(mem);
	}
	sort(b.begin(), b.end());
	cnt = 0;
	for (int i = n - 1; i >= 0 && b[i] > amax; i--) {
		cnt++;
		h -= b[i];
		if (h <= 0) {
			cout << cnt << endl;
			return 0;
		}
	}
	cout << cnt + (h - 1) / amax + 1 << endl;
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
using namespace std;
const int INF=1e9;

double fabs(double n){
  if(n>=0)return n;
  else return -n;
}

main(){
  int N;
  cin >> N;
  int T,A;
  cin >> T >> A;
  int H[N];
  for(int ii=0;ii<N;ii++){
    cin >> H[ii];
  }
  int min=INF;
  int tmp;
  for(int ii=0;ii<N;ii++){
    if(min>fabs(A*1000-(T*1000-H[ii]*6))){
      min=fabs(A*1000-(T*1000-H[ii]*6));
      tmp=ii;
    }
  }
  cout << tmp+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 105;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>>n;
string s,t;
cin>>s>>t;
int ans=0;
rep(i,0,n)
{
	string ss,tt;
	ss=s.substr(i,n-i);
	tt=t.substr(0,n-i);
	if(ss==tt)
	{
		cout<<2*(n)-ss.size();
		return 0;
	}
}
cout<<2*n;
}


Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N;
  cin >> N;
  vi a(N), b(N), c(N);
  rep(i, N) cin >> a[i] >> b[i] >> c[i];

  vvi dp(N + 1, vi(3, 0));
  rep(i, N) {
    dp[i + 1][0] = max(dp[i][1] + b[i], dp[i][2] + c[i]);
    dp[i + 1][1] = max(dp[i][2] + c[i], dp[i][0] + a[i]);
    dp[i + 1][2] = max(dp[i][0] + a[i], dp[i][1] + b[i]);
  }

  out(max(max(dp[N][0], dp[N][1]), dp[N][2]));
}


Measured memory_bytes: 6912
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		String input[] = sc.nextLine().split(" ");
		int k = Integer.parseInt(input[0]);
		int n = Integer.parseInt(input[1]);
		int ar[] = new int[n];
		String input2[] = sc.nextLine().split(" ");
		for(int i = 0; i < n; i++)
			ar[i] = Integer.parseInt(input2[i]);
		int tour[] = new int[(2 * n) - 1];
		for(int i = 0; i < n; i++)
			tour[i] = ar[i];
		
		for(int i = 0; i < n - 1; i++)
			tour[i + n] = ar[i] + k;
		
		/*for(int i = 0; i < tour.length; i++)
			System.out.print(tour[i] + " ");
		
		System.out.println();*/
		int distance = 0;
		for(int i = 1; i < n; i++)
			distance = distance + (tour[i] - tour[i - 1]);
		//System.out.println(distance);
		int mindistance = distance;
		
		for(int i = 1; i < n; i++) {
			distance = distance - Math.abs(ar[i] - ar[i - 1]);
			distance = distance + Math.abs((tour[i + n -1] - tour[i + n -2]));
			//System.out.println(ar[i]+" : " +distance+ " ");
			mindistance = Math.min(distance, mindistance);
		}
		System.out.println(mindistance);
		out.close();
	}

	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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

	}

}


Measured memory_bytes: 50516
#include<stdio.h>
#include<string.h>
int main(){
  char S[200001];
  char T[200001];

  scanf("%s",S);
  scanf("%s",T);

  int n = 0; //文字列の長さ
  while(S[n]!='\0') n++;
  int ans = 0;
  for(int i=0;i<n;i++){
    if(S[i]!=T[i]) ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 2044
n = gets.to_i
d = gets.split.map(&:to_i)
m = gets.to_i
t = gets.split.map(&:to_i)

d_cnt = {}
d.each do |i|
  if d_cnt[i] == nil
    d_cnt[i] = 1
  else
    d_cnt[i] += 1
  end
end

t_cnt = {}
t.each do |i|
  if t_cnt[i] == nil
    t_cnt[i] = 1
  else
    t_cnt[i] += 1
  end
end

ans = 'YES'
t_cnt.each do |k,v|
  if d_cnt[k] == nil || d_cnt[k] < v
    ans = 'NO'
  end
end

puts ans

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

int main(){
  int s,w;
  cin>>s>>w;

  if(w>=s){
    cout<<"unsafe"<<endl;
  }else{
    cout<<"safe"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3600
s = input()
n = len(s)
flag = 1
for i in range(n):
    if (i % 2 == 0) and (s[i] not in {'R', 'U', 'D'}):
        flag = 0
    if (i % 2 == 1) and (s[i] not in {'L', 'U', 'D'}):
        flag = 0

if flag:
    print('Yes')
else:
    print('No')
        

Measured memory_bytes: 3060
d, g = gets.to_s.split.map{|i|i.to_i}
s, c = Array.new(d){ gets.to_s.split.map{|i|i.to_i} }.transpose

ans = 1000
(2**d).times do |b|
  
  tot = 0
  n   = 0
  d.times do |i|
    if 1 == b[i]
      tot += c[i] + s[i] * 100 * (i+1)
      n += s[i]
    end
  end
  
  i = d
  while tot < g && i > 0
    i -= 1
    next if 1 == b[i]
      score = 100 * (i+1)
      r = ( g - tot + score - 1 ) / score
      r = s[i] - 1 if r > s[i] - 1
      tot += score * r
      n   += r
  end
  
  ans = n if ans > n && tot >= g
end

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 

int main()
{	
    std::ios_base::sync_with_stdio(0);
	  cin.tie(0);
	  cout.tie(0);
    
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    //cout<<s<<endl;
    ll n = s.size();
    ll flg[n];
    flg[0] = s[0]-'0';
    map <ll,ll> mp;
    mp[flg[0]]++;
    ll po = 10;
    for(ll i=1;i<n;i++)
    {
        flg[i] = (flg[i-1] + (s[i]-'0')*po)%2019;
        po = (po*10)%2019;
        mp[flg[i]]++;
    //    cout<<flg[i]<<endl;
    }
    ll ans = 0;
    ll st = 0;
    po = 1;
    for(ll i=0;i<n;i++)
    {
    //    cout<<st<<endl;
        ans += max(0LL,mp[st]);
        st = (st + (s[i]-'0')*po)%2019;
        po = (po*10)%2019;
        mp[flg[i]]--;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 5280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	stack<int> st;
	rep(i, n) {
		if (s[i] == '(') {
			st.push(0);
		}
		else {
			if (st.size() == 0);
			else {
				if (st.top() == 0) st.pop();
			}
		}
	}
	int a = st.size();
	stack<int> st2;
	reverse(all(s));
	rep(i, n) {
		if (s[i] == ')') {
			st2.push(0);
		}
		else {
			if (st2.size() == 0) ;
			else {
				if (st2.top() == 0) st2.pop();
			}
		}
	}
	reverse(all(s));
	rep(i, st2.size()) cout << '(';
	rep(i, n) cout << s[i];
	rep(i, a) cout << ')';
	cout << endl;
	return 0;
}


Measured memory_bytes: 256