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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {

    set<int> a{1, 2, 3};

    lint N, M;
    cin >> N >> M;
    vector<lint> H(N, 0);
    rep(i, N) { cin >> H[i]; }
    vector<set<lint>> A(N);
    rep(i, M) {
        lint a, b;
        cin >> a >> b;
        a--, b--;
        A[a].insert(H[b]);
        A[b].insert(H[a]);
    }
    lint cnt = 0;
    for (int i = 0; i < N; i++) {
        // dump(A[i]);
        lint ma = -1;
        for (auto x : A[i]) {
            // d(x);
            ma = max(ma, x);
        }
        // dd(H[i], ma);
        if (H[i] > ma) { cnt++; }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 18044
#include <iostream>
const long long INF = 1LL<<60;

using namespace std;

void chmin(long long int& a, long long int b) {
    if(b < a) {
        a = b;
    }
    return;
}

int main() {
    int N, W;
    cin >> N >> W;
    long long int weight[N], value[N];
    for(int i = 0; i < N; i++) {
        cin >> weight[i] >> value[i];
    }

    int max_v = 1000 * 100;

    long long int dp[N+1][max_v+1];
    for(int i = 0; i < N+1; i++) {
        for(int j = 0; j < max_v+1; j++) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    
    for(int i = 0; i < N; i++) {
        for(int sum_v = 0; sum_v <= max_v; sum_v++) {
            if(sum_v - value[i] >= 0) {
                chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
            }
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    long long int result = 0;

    for(int sum_v = 0; sum_v < max_v + 1; sum_v++) {
        if(dp[N][sum_v] <= W) result = sum_v;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define int long int
#define hell (int)(1e9+7)

using namespace std;

void solve(){
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector <bool> v(n,false);
    int p=0;
    for(int i=0;i<n;i++){
        if(a[i]==p+1){
            p++;
            v[i]=true;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=!v[i];
    if(ans==n)
        ans=-1;
    cout<<ans;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 1792
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,k,q=parseMap(split(readline()))
    points=[k-q for i in 1:n]

    for i in 1:q
        points[parseInt(readline())]+=1
    end
    for i in points
        println(ifelse(i>0,"Yes","No"))
    end
end
main()

Measured memory_bytes: 167444
#include <stdio.h>
int main(){
  int a[10];
  int i,j;
  int tmp;
  for(i=0;i<10;i++)scanf("%d",&a[i]);
  for(i=0;i<9;i++){
    for(j=9;j>i;j--)
      if(a[j]>a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
      }
  }
  printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
 
int main(void)
{
    int a, b, menseki, shu;
 
    scanf("%d %d", &a, &b);
 
    menseki = a * b;
    shu = (a + b) * 2;
 
    printf("%d %d\n", menseki, shu);
 
    return 0;
}

Measured memory_bytes: 596
N=input()
a=int(N)//100
b=(int(N)-a*100)//10
c=int(N)-100*a-10*b
A=(a==7)
B=(b==7)
C=(c==7)
if A==True or B==True or C==True:
    print("Yes")
else:
    print("No")    

Measured memory_bytes: 9084
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int A, B, K;

int main(int argc, const char * argv[]) {
    A = inputValue();
    B = inputValue();
    K = inputValue();

    int count = 0;
    for (auto i=min(A,B); i >= 1; --i) {
        if (A%i == 0 && B%i == 0) {
            count += 1;
        }
        if (count == K)  {
            output(i);
            break;
        }
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    string s;
    int ans=0;
    cin >> s;
    if(s[0] == '1')ans++;
    if(s[1] == '1')ans++;
    if(s[2] == '1')ans++;
    cout << ans;
}


Measured memory_bytes: 256
# include "iostream"
# include "algorithm"
# include "cstdio"

using namespace std;

const int maxm=1e2+10;

int A[maxm];

int main(){
	scanf("%d%d%d",A+1,A+2,A+3);
	sort(A+1,A+4);
	printf("%d",A[1]*A[2]>>1);
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
use=[0]*n
pen=[0]*n
ans=0
for i in range(m):
    p,s=input().split()
    p=int(p)-1
    if s=="AC":
        if use[p]==0:
            use[p]=1
            ans+=1
    else:
        if use[p]==0:
            pen[p]+=1
pe=0
for i in range(n):
    pe+=use[i]*pen[i]
print(ans,pe)

Measured memory_bytes: 4596
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Integer, Integer> freq = new HashMap<>();
        int[] amts = new int[n + 1];
        for (int j = 0; j < n; j++) {
            int k = in.nextInt();
            if (!freq.containsKey(k)) {
                freq.put(k, 1);
            } else {
                freq.put(k, freq.get(k) + 1);
            }
            amts[freq.get(k)]++;
        }
        StringBuilder builder = new StringBuilder();
        int k = 1;
        int nTemp = n;
        for (int m = n; m > 0; m--) {
            while (k <= nTemp / m) {
                builder.append(m);
                builder.append('\n');
                k++;
            }
            nTemp -= amts[m];
        }
        while (k <= n) {
            builder.append("0\n");
            k++;
        }
        System.out.print(builder);
    }
}


Measured memory_bytes: 111116
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

vector<vector<ll>> g(101010);
vector<vector<ll>> dp(101010, vector<ll>(2, -1));

ll dfs(ll pos, ll par, ll col) {
	if(dp[pos][col] != -1) return dp[pos][col];
	ll ret = 1;
	REP(i, g[pos].size()) {
		if(g[pos][i] == par) continue;
		if(col) ret *= dfs(g[pos][i], pos, 0);
		else ret *= (dfs(g[pos][i], pos, 0) + dfs(g[pos][i], pos, 1)) % MOD;
		ret %= MOD;
	}
	return dp[pos][col] = ret % MOD;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	REP(i, n - 1) {
		ll x, y;
		cin >> x >> y;
		x--; y--;
		g[x].pb(y); g[y].pb(x);
	}
	ll ans = dfs(0, -1, 0) + dfs(0, -1, 1);
	cout << (ans % MOD + MOD) % MOD << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 19584
#include <iostream>

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

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

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

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

using namespace std;

using ll = long long;

int main() {
    while (true) {
        int n, x;
        cin >> n >> x;

        if (n == 0 && x == 0) break;

        auto count = 0;
        FOR(i, 1, n + 1) {
            FOR(j, i + 1, n + 1) {
                FOR(k, j + 1, n + 1) {
                    if (i + j + k == x) ++count;
                }
            }
        }
        cout << count << "\n";
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  string s[n];
  rep(i,n) R s[i];
  rep(i,n) {
    rep(j,m) {
      if(s[i][j]!='#') continue;
      int c=0;
      rep(k,4) {
        int x=i+dx[k],y=j+dy[k];
        if(check(n,m,x,y)&&s[x][y]=='#') c++;
      }
      if(!c) {
        pr("No");
        return;
      }
    }
  }   
  pr("Yes");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
n = int(input())
s = list(map(int,input().split()))
count = 0
ans = 0
dum2 = 0
dum = abs(s[0])
for i in range(n):
  if s[i] < 0:
    count += 1
    dum2 = -s[i]
  else:
    dum2 = s[i]
  dum = min(dum,dum2)
  ans += dum2
if count%2 == 0:
  print(ans)
else:
  print(ans-dum*2)



Measured memory_bytes: 14412
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    for i in range(n-1):
        if a[i] <= a[i + 1]:
            continue
        else:
            ans[i+1] = a[i] - a[i+1]
            a[i+1] = a[i]

    ans = sum(ans)
    print(ans)


resolve()

Measured memory_bytes: 32172
N = int(input())

jobs = list()
for index in range(N):
    A, B = map(int, input().split())
    jobs.append([A, B])

sorted_jobs = sorted(jobs, key=lambda x: x[1])

now = 0
remain = 0

for job in sorted_jobs:
    cost = job[0]
    limit = job[1]

    remain += limit - now
    now = limit

    remain -= job[0]

    if remain < 0:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 39600
import Data.Functor( (<$>))
import Data.List( foldl')

main = do
    initialDice <- (read <$>) . words <$> getLine   ::IO [Int]
    directions <- getLine
    let
	roll d 'S' = [d!!4, d!!0, d!!2, d!!3, d!!5, d!!1]
	roll d 'N' = [d!!1, d!!5, d!!2, d!!3, d!!0, d!!4]
	roll d 'W' = [d!!2, d!!1, d!!5, d!!0, d!!4, d!!3]
	roll d 'E' = [d!!3, d!!1, d!!0, d!!5, d!!4, d!!2]

    print . head $ foldl' roll initialDice directions



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

int main() {
    int n;
    string s; 
    cin >> n >> s;
    for(char c : s){
        char ans = c + n;
        int num = (c - 'A' + n);

        if(num >= 25) {
            ans = 'A' + ((c - 'A' + n) % 26);
        }

        cout << ans;
    }
	return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    M = N-1
    ans = 0
    for i in range(1,N):
        ans += M//i
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9228
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int X,Y = 0,Z;
		int sum = 0;
		for(Z=0;Z<=K;Z++){
			S -= Z;
			for(X=0;X<=K&&X<=S;X++){
				Y = S - X;
				if(Y>K)continue;
				sum++;
			}
			S += Z;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
//author CN.TTDragon
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=1e5+7;
const double pi=acos(-1);
using namespace std;
int a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int n,m,sum;
    cin>>n>>m>>sum;
    for(int i=0;i<m;i++)
    {
    	if(i%2==0)
    	{
    		a[i/2]=sum;
		}
		else
		{
			a[n-1-i/2]=sum;
		}
	}
	
	if(sum==1e9)
	{
		for(int i=0;i<n;i++)
		{
			if(a[i]==0)
			{
				a[i]=sum-1;
			}
		}
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			if(a[i]==0)
			{
				a[i]=sum+1;
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
 	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


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

    vector<ll> A(N);
    ll all = 0;
    REP(i,N){
        cin >> A[i];
        all += A[i];
    }

    
    for(int j=1; j<N; j+=2){
        all -= 2*A[j%N];
    }
    cout << all <<" ";

    ll ans = all/2;

    REP(i,N-1){
        ans = A[i] - ans;
        cout << 2*ans << " ";
    }
    
    cout << endl;
   

    return 0;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll A,B,C;
  cin>>A>>B>>C;
  if(A==B &&A!=C)
    cout<<"Yes"<<endl;
  else if(A==C &&A!=B)
    cout<<"Yes"<<endl;
  else if(C==B &&B!=A)
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<deque>
#include<algorithm>

using namespace std;


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

    deque<int>  sunuke(N);
    for(int i =0;i<N;i++){
        cin>>sunuke[i];
        sunuke[i]-=(i+1);
    }

    deque<int> sorted;

    sorted=sunuke;

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

    int b;

    b=sorted[((sorted.size()-1)/2)];

    long ans=0;

    for(auto &x:sorted){
        ans+=abs(x-b);
    }


    cout<<ans<<endl;


}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
char a[50][50];
int ans=0,v[50][50],run[4]= {0,1,0,-1},run1[4]= {1,0,-1,0},sum[50][50],n,m;
void solve(int x,int y,int xx,int yy)
{
    memset(v,0,sizeof(v));
    memset(sum,0,sizeof(sum));
    v[x][y]=1;
    queue<pair<int,int> >q;
    q.push(make_pair(x,y));
    while(!q.empty())
    {
        int qq=q.front().first;
        int ee=q.front().second;
        q.pop();
        for(int i=0; i<4; i++)
        {
            int tmp=qq+run[i];
            int tmp1=ee+run1[i];
            if(v[tmp][tmp1]||a[tmp][tmp1]=='#'||tmp<0||tmp>=n||tmp1<0||tmp1>=m)
                continue;
            v[tmp][tmp1]=1;
            sum[tmp][tmp1]=sum[qq][ee]+1;
            q.push(make_pair(tmp,tmp1));
        }
    }
    ans=max(ans,sum[xx][yy]);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0; i<n; i++)
        scanf("%s",a[i]);
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            for(int k=0; k<n; k++)
                for(int l=0; l<m; l++)
                    if(a[i][j]!='#'&&a[k][l]!='#')
                        solve(i,j,k,l);
    printf("%d",ans);
    return 0;
}

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

int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

void solve(long long K)
{
    long long ans = 0;
    for (int a = 1; a <= K; a++)
    {
        for (int b = 1; b <= K; b++)
        {
            for (int c = 1; c <= K; c++)
            {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long K;
    scanf("%lld", &K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3764
using System;

namespace atPra99A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var num = Console.ReadLine().Split(' ');
            int x = int.Parse(num[0]);
            int y = int.Parse(num[1]);
            if (x <= 8 && y <= 8) Console.WriteLine("Yay!");
            else Console.WriteLine(":(");

        }


    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first 
#define ss second
#define mod 1000000007
#define lim 100005
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mx 10005
using namespace std;

ll dp[mx][101] = {};

void make_dp(int d)
{
	int i,j,k;
	dp[0][0] = 1;
	for(i=1; i<mx; i++)
		for(j=0; j<d; j++)
			for(k=0; k<10; k++)
				dp[i][j] = (dp[i][j] + dp[i-1][(j+d-(k%d))%d])%mod;
}

ll compute(string& k, int d)
{
	ll ans = 0; int i,j,look = 0;
	for(i=k.length()-1; i>=0; i--){
		for(j=0; j<k[i]-'0'; j++)
			ans = (ans + dp[i][(look+d-j%d)%d])%mod;
		look = (look + d - (k[i]-'0')%d)%d;
	}
	if(look) ans = (ans + mod - 1)%mod;
	return ans;
}

int main()
{
	int i,j,d; string k;
	cin>>k>>d;
	reverse(k.begin(), k.end());
	make_dp(d);
	cout<<compute(k,d);
}

Measured memory_bytes: 8192
N, S = gets.split.map(&:to_i)
xs, ps = N.times.map{gets.split.map(&:to_i)}.transpose

pts = []
l, r = 0, N-1
while l <= r
    if S <= xs[l]
        pts.push(xs[r])
        r -= 1
    elsif xs[r] <= S
        pts.push(xs[l])
        l += 1
    elsif ps[l] >= ps[r]
        ps[l] += ps[r]
        pts.push(xs[r])
        r -= 1
    else
        ps[r] += ps[l]
        pts.push(xs[l])
        l += 1
    end
end
pts.push(S)

ans = 0
N.times do |i|
    ans += (pts[i] - pts[i+1]).abs
end
puts ans

Measured memory_bytes: 12024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> dp(n, inf);
  dp[0] = 0;
  rep(i, n) {
    rep3(j, i - k, i) {
      if (j >= 0) chmin(dp[i], dp[j] + abs(a[i] - a[j]));
    }
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    if(a==b) System.out.println(c);
    if(a==c) System.out.println(b);
    if(b==c) System.out.println(a);
  }
}


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


int main()
{
int n ,a[100],c=0;cin>>n;
for(int i=1;i<=n;i++){
    cin>>a[i];
}
for(int i=1;i<=n;i++){if(a[i]%2==1&&i%2==1){c++;}}
cout <<c;
return 0;
}


Measured memory_bytes: 3552
#include<cstdio>
#include<string>
#include<iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = 0;
    int idx = 0;
    while(s[idx] != 0){
        n++;
        idx++;
    }
    // printf("%d\n", n);
    int ans = 0;
    if (n % 2 == 0){
        char num = s[n / 2 - 1];
        for(int i = 0; i < n / 2; i++){
            if(s[n / 2 + i] == num && s[n / 2 - i - 1] == num) ans++;
            else break;
        } 
        ans += n / 2;
    } else{
        char num = s[n / 2];
        for(int i = 0; i < n / 2; i++){
            if(s[n / 2 + i + 1] == num && s[n / 2 - i - 1] == num) ans++;
            else break;
        }

        ans += n / 2 + 1;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vl A(N),B(M);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,M){
        cin >> B[i];
    }
    vl c=atcoder::convolution(A,B);
    rep(i,M+N-1){
        cout << c[i] << ' ';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 27284
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	cin.tie( 0 );
	ios::sync_with_stdio( false );
    
	while(true){
        	int n;
        	cin >> n;
        
        	if(n == 0){ break; }
        	int MAX = INT_MIN ,MIN = INT_MAX;
        	vector<int> vc(n);
        
        	for(int i=0; i<n; i++){
            		cin >> vc[i];
            		MAX = max(MAX, vc[i]);
            		MIN = min(MIN, vc[i]);
        	}
        	auto res = (accumulate(vc.begin(), vc.end(), 0)) - (MAX + MIN);
        	cout << res / (n-2) << endl;
    	}
    	return 0;
}

Measured memory_bytes: 3144
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())

L = []; R = []
for _ in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

maxL = max(L)
minR = min(R)

if minR < maxL:
    ans = 0
else:
    ans = minR-maxL+1
print(ans)

Measured memory_bytes: 16768
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)
ans = 0
for i in range(len(B2)):
    X = B2[i]
    l = bisect.bisect_left(A2,X)
    h = len(C2)-bisect.bisect_right(C2,X)
    #print(l,h)
    ans += l*h
print(ans)
               

Measured memory_bytes: 22720
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	rep(i,n){
		int a;
		cin >> a;
		if(i%2 == 0 && a%2 == 1) ++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int d[100010];

int main() {
  int n, m;
  while(cin>>n>>m) {
    memset(d,0,sizeof(d));
    REP(i,m) {
      int l,r;
      input(l,r);
      d[l]++;
      d[r+1]--;
    }
    int ans = 0;
    int a = 0;
    REP(i,n+1) {
      a += d[i];
      if (a == m) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string N;cin>>N;
    reverse(all(N));


    int ans=0;
    int sum=0;
    for(int i=N.size()-1;i>=0;i--){
        if(N[i]!='0'){
            chmax(ans,sum+N[i]-'0'-1+9*i);
        }
        sum+=N[i]-'0';
    }
    chmax(ans,sum);
    cout<<ans<<endl;
    return 0;
}


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

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

    vector<int> A(N), B(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    B = A;
    sort(B.begin(), B.end());
    for (int i = 0; i < N; i++)
    {
        if (A[i] == B[N - 1])
        {
            cout << B[N - 2] << endl;
        } else
        {
            cout << B[N - 1] << endl;
        }
        
        
    }
    
    

  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
using namespace std;
int n,m;
char a[101][101];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
    for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='.'){
				int ans=0;
				if(a[i-1][j-1]=='#')ans++;
				if(a[i-1][j]=='#')ans++;
				if(a[i-1][j+1]=='#')ans++;
				if(a[i][j-1]=='#')ans++;
				if(a[i][j+1]=='#')ans++;
				if(a[i+1][j-1]=='#')ans++;
				if(a[i+1][j]=='#')ans++;
				if(a[i+1][j+1]=='#')ans++;
				a[i][j]=(char)(ans+48);
			}
			cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;
int main()
{
	int n,a,b;
	int kau1=0,kau2=0,kau3=0;
	
	cin>>n>>a>>b;
	
	int p[n];
	
	for(int i=0;i<n;i++)
	cin>>p[i];
	
	sort(p,p+n-1);
	
	for(int i=0;i<n;i++){
		if(p[i]<=a){
			kau1++;
		}
		else if(p[i]<=b){
			kau2++;
		}
		else{
			kau3++;
		}
	}
	if(kau1<kau2&&kau1<kau3)
	cout<<kau1<<endl;
	else if(kau2<kau1&&kau2<kau3)
	cout<<kau2<<endl;
	else
	cout<<kau3<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int S(int n) {
    int res = 0;
    for (auto x: to_string(n)) {
        res += x-'0';
    }
    return res;
}
int main () {
    int N;
    cin >> N;
    if (N % S(N) == 0) {
        puts("Yes");
    }
    else {
        puts("No");
    }
}

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

// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, set it in Settings(Ctrl+,) in "Icie Template List" entry 🔧
// 📝 If you spot any bugs or miss any features, create an issue at https://github.com/pustaczek/icie 📝

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::string str;
    cin>>str;

    map<char, int> m;
    for(char c: str)
    {
        if(m.count(c))
            m[c]++;
        else
            m[c] = 1;
    }
    bool ok = true;
    for(auto& pair: m)
    {
        if(pair.second != 2)
            ok = false;
    }
    if(ok)
        std::cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,t;
	cin>>n>>x>>t;
	if(n%x==0)
	{
		cout<<(n/x)*t;
	}
	else
	{
		cout<<((n/x)+1)*t;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int K,t[25],tot,cnt,s[10005];
int64 L[10005],p[25],b[25];
int S(int64 x) {
    int res = 0;
    while(x) {res += x % 10;x /= 10;}
    return res;
}

int64 f(int64 x) {
    tot = 0;cnt = 0;int64 h = x;
    while(h) {t[++tot] = h % 10;h /= 10;}
    int64 num = 0;
    for(int i = tot ; i >= 1 ; --i) {
	for(int j = t[i] ; j <= 9 ; ++j) {
	    int64 tmp = num + j * b[i - 1] + p[i - 1];
	    if(tmp >= x) L[++cnt] = tmp;
	}
	num = num + t[i] * b[i - 1];
    }
    
    for(int i = 1 ; i <= cnt ; ++i) s[i] = S(L[i]);
    int r = 1;
    for(int i = 2 ; i <= cnt ; ++i) {
	int64 h = L[i] * s[r] - L[r] * s[i];
	if(h < 0) r = i;
	else if(h == 0 && L[i] < L[r]) r = i; 
    }
    return L[r];
}
void Solve() {
    read(K);
    int64 N = 1;
    p[1] = 9;
    for(int i = 2 ; i <= 16 ; ++i) p[i] = p[i - 1] * 10 + 9;
    b[0] = 1;
    for(int i = 1 ; i <= 16 ; ++i) b[i] = b[i - 1] * 10;
    while(K--) {
	out(N);enter;
	N = f(N + 1);
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 256
N = gets.to_i

tasks = N.times.map do
  cost, limit = gets.split.map(&:to_i)
  [cost, limit]
end

tasks = tasks.sort_by { |i| i[1] }

now_time = 0
flag = "Yes"
tasks.each do |task|
  now_time += task[0]
  if now_time > task[1]
    flag = "No"
    break
  end
end

puts flag

Measured memory_bytes: 22520
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, A[100000], PCount = 0, MCount = 0, sum = 0;
	bool plus = true;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
    //最初のこうが＋
	for (int i = 0; i < N; i++) {
		if (plus) {
			if (sum + A[i] > 0) {
				sum += A[i];
			}
			else {
				PCount += 1 - (sum + A[i]);
				sum = 1;
			}
		}
		else {
			if (sum + A[i] < 0) {
				sum += A[i];
			}
			else {
				PCount += 1 + (sum + A[i]);
				sum = -1;
			}
		}
		plus = !plus;
	}
    //最初のこうがー
	sum = 0, plus = false;
	for (int i = 0; i < N; i++) {
		if (plus) {
			if (sum + A[i] > 0) {
				sum += A[i];
			}
			else {
				MCount += 1 - (sum + A[i]);
				sum = 1;
			}
		}
		else {
			if (sum + A[i] < 0) {
				sum += A[i];
			}
			else {
				MCount += 1 + (sum + A[i]);
				sum = -1;
			}
		}
		plus = !plus;
	}
	cout << min(PCount, MCount);
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main()
{
    int n;
    scanf("%d", &n);
    int a, b, sum=0;
    for(int i=0; i<n; i++){
        scanf("%d%d", &a,&b);
        sum += (b-a+1);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    s=input()
    s1=int(s[:2])
    s2=int(s[2:])
    yymm = 1 <= s2 <= 12
    mmyy = 1 <= s1 <= 12
    if yymm and mmyy:
        print("AMBIGUOUS")
    elif yymm:
        print("YYMM")
    elif mmyy:
        print("MMYY")
    else:
        print("NA")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
LL inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =1000000000000000000;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define F first
#define S second
class StonesOnATree
{

    public:
int minStones(vector <int> p, vector <int> w)
{

}

};
int f[15][15]={};
int main()
{
    for(int i=0;i<15;i++){
        for(int j=0;j<15;j++)
            f[i][j]=inf;
    }
int a,b;
while(cin>>a>>b){
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            int x;
            cin>>x;
            f[i][j]=x;
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            int x;
            cin>>x;
            if(x==1||x==-1)
                con;
            ans+=f[x][1];
        }
    }
    cout<<ans<<endl;






}
    return 0;
}


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

int main() {
  ll n, a, b; cin >> n >> a >> b;
  if ((b - a)%2) {
    ll c = n - a + 1, d = n - b + 1;
    cout << min((a + (b-a-1)/2), (c + (d-c-1)/2));
  }
  else cout << (b - a)/2;
  return 0;
}

Measured memory_bytes: 256
import numpy as np 
h,w,k=map(int,input().split())
c=[None]*h
for i in range(h):
  c[i]=list(map(int,input().replace(".","0 ").replace("#","1 ").split()))
#sum_c=sum(c)
d=np.array(c)
c=np.copy(d)
e=np.copy(c)
r=0
#h+=-1
#w+=-1
for j in range(2**h):
  j_b=bin(j)[:1:-1]
  e=np.copy(c)
  #print(j)
  for i_j,d_j in enumerate(j_b):
    #print(d_j)
    if d_j=="1":
      #print(d[i_j])
      e[i_j]=0
      #print(d)
    #else:
    #  e[i_j]=c[i_j]
  for m in range(2**w):
    d=np.copy(e)
      #print(m)
    m_b=bin(m)[:1:-1]
      #print(j_b)
      #print(m_b)
    for i_m,d_m in enumerate(m_b):
      if d_m=="1":
        d[:,i_m]=0
        #else:
          #print(m_b)
        #  d[:,i_m]=c[:,i_m]
      #print(d)
    if np.sum(d)==k:
      r+=1
        #print(m_b)
        #print(j_b)
        #print(d)
      #d=np.copy(e)
    #d=np.copy(c)
print(r)

Measured memory_bytes: 27124
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
#define INF 10000000000
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
long long int mod=998244353;
struct modint{
    long long int x;
    modint(long long int x=0):x(x%mod){}//メンバ変数を初期化する。
    modint& operator+= (const modint a){
        if((x+=a.x)>=mod){x-=mod;}//%は遅い
        return *this;//関数を終了するためにはreturnを返さなければならないが、return aとでもするとその値が代入されてしまう。そこで、計算された後の自分自身のアドレス、つまり何もしないようにしている？
    }
    modint& operator-= (const modint a){
        if((x+=mod-a.x)>=mod) x-=mod;
        return *this;
    }
    modint& operator*= (const modint a){
        x*=a.x;
        x%=mod;
        return *this;
    }
    modint operator+(const modint a) const{//引数の横のconstは関数自体がconstつまりメンバ変数の変更ができなくなるということ。バグ防止に役立つ
        modint copy(*this);//constがあるのでメンバ変数をいじれないから値だけコピーする
        return copy+=a;
    }
    modint operator-(const modint a)const{
        modint copy(*this);
        return copy+=a;
    }
    modint operator*(const modint a)const{
        modint copy(*this);
        return copy*=a;
    }
    modint pow(long long int t)const{//繰り返し二乗法
        if(t==0) return 1;
        modint a=pow(t>>1);//tを1/2倍したものの累乗
        a*=a;//aを二乗する
        if(t&1) a*=*this;//ビット形式での一桁目が1、つまりtが奇数ならば、もう一回掛ける。
        return a;
    }
    modint inv() const{
        return pow(mod-2);
    }
    modint operator/=(const modint a){
        return (*this)*=a.inv();
    }
    modint operator/(const modint a){
        modint copy(*this);
        return copy/=a;
    }
};




int main(){
    int n,s;
    cin>>n>>s;
    vector<vector<modint>> dp(n+1,vector<modint>(s+1));
    vi a;
    dp[0][0]=1;
    rep(i,n){
        int x;
        cin>>x;
        a.push_back(x);
    }
    rep(i,n){
        rep(j,s+1){
            dp[i+1][j]+=dp[i][j]*2;
            if(j+a.at(i)<=s){
                dp[i+1][j+a.at(i)]+=dp[i][j];
            }
        }
    }
    out(dp[n][s].x);
}

Measured memory_bytes: 73664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

long long int N;

int main(void) {

	cin >> N;

	long long int ans = 99999999999999999;

	for (long long int i = 1; i*i <= N; i++) {
		if (N%i == 0) { ans = min(ans, (i - 1) + (N / i - 1)); }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())

    points = {"taro":0, "hanako":0}

    for _ in range(n):
        taro, hanako = input().split()

        if taro > hanako:
            points['taro']   += 3
        elif taro < hanako:
            points['hanako'] += 3
        else:
            points['taro']   += 1
            points['hanako'] += 1

    print(points['taro'], points['hanako'])

if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N;
	cin >> N;
	vector<double> v(N);
	for(int i=0;i<N;i++)cin >> v[i];
	sort(ALL(v));
	double ans = 0;
	for(int i=0;i<N-1;i++){
		v[i+1] = (v[i]+v[i+1])/2;
	}
	cout << fixed << setprecision(10) << v[N-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
using namespace std;

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

    int dig = 1;
    while(1){
        if(n < pow(k, dig)){
            break;
        }
        dig++;
    }

    cout << dig << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var numSword = Number(tmp[0]);
	var HP = Number(tmp[1]);
	var ans = 0;

	var throwDamage = [];
	var maxCutDamage = 0;
	for(var i = 1; i <= numSword; i++){
		throwDamage[i-1] = Number(line[i].split(" ")[1]);
		var cutDamage = Number(line[i].split(" ")[0]);
		if(maxCutDamage <= cutDamage) maxCutDamage = cutDamage;
	}

	throwDamage.sort(function(a,b){
		return b-a;
	});

	var sumThrowDamage = 0;
	var throwTimes = 0;

	for(i = 0; i < throwDamage.length && throwDamage[i] > maxCutDamage; i++){
		throwTimes++;
		sumThrowDamage += throwDamage[i];
		if(HP <= sumThrowDamage){
			console.log(throwTimes);
			return false;
		}
	}

	var cutTimes = Math.ceil((HP-sumThrowDamage)/maxCutDamage);
	ans = cutTimes + throwTimes;
	console.log(ans);
	return false;

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30924
import sys
from collections import namedtuple
from heapq import heappush, heappop


INF = sys.maxsize
Edge = namedtuple('Edge', 'to yen snuuk')
Vertex = namedtuple('Vertex', 'cost id')

n, m, s, t = map(int, input().split())

edges = [[] for _ in range(n + 1)]

for _ in range(m):
  u, v, a, b = map(int, input().split())
  edges[u].append(Edge(v, a, b))
  edges[v].append(Edge(u, a, b))

costs_in_yen = [INF] * (n + 1)
costs_in_snuuk = [INF] * (n + 1)

q = []

heappush(q, Vertex(0, s))
costs_in_yen[s] = 0

while q:
  v = heappop(q)
  if v.cost > costs_in_yen[v.id]:
    continue
  for edge in edges[v.id]:
    if v.cost + edge.yen < costs_in_yen[edge.to]:
      costs_in_yen[edge.to] = v.cost + edge.yen
      heappush(q, Vertex(costs_in_yen[edge.to], edge.to))
      
heappush(q, Vertex(0, t))
costs_in_snuuk[t] = 0

while q:
  v = heappop(q)
  if v.cost > costs_in_snuuk[v.id]:
    continue
  for edge in edges[v.id]:
    if v.cost + edge.snuuk < costs_in_snuuk[edge.to]:
      costs_in_snuuk[edge.to] = v.cost + edge.snuuk
      heappush(q, Vertex(costs_in_snuuk[edge.to], edge.to))      

# DPっぽく結果を記録しながら解いていく
# n - 1 年後からはじめて0年後まで遡っていく

# n 年後の手持ち snuuk の最大額
snuuk_in_hand = [0] * (n + 1)

# 現在に近づくにつれて、利用できる両替所が毎年ひとつずつ増えていく、と考える
# 新しく増えた両替所で両替したほうがお得であればdpテーブルを更新する
for i in range(n, 0, -1):  
  # 例: 3年後の最大金額は4年後の最大金額と都市4で両替した場合の所持金額のどちらか大きい方
  snuuk_in_hand[i - 1] = max(
    snuuk_in_hand[i],
    # 最初の所持金 - スタートから都市iまでの費用（yen) - 都市iからゴールまでの費用(snuuk）
    10**15 - costs_in_yen[i] - costs_in_snuuk[i]
  )

for i in range(0, n):
  print(snuuk_in_hand[i])  


Measured memory_bytes: 129516
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll t1,t2,a1,a2,b1,b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  ll A=(t1*a1)+(t2*a2);
  ll B=(t1*b1)+(t2*b2);
  ll D,L;
  if(A==B){
    cout << "infinity" << endl;
  }
  else{
    if(A>B){
      if(a1>b1){
        cout << 0 << endl;
      }
      else{
        D=A-B;
        L=(b1-a1)*t1;
        if(L%D==0){
          cout << L/D*2 << endl;
        }
        else{
          cout << L/D*2+1 << endl;
        }
      }
    }
    else{
      if(b1>a1){
        cout << 0 << endl;
      }
      else{
          D=B-A;
          L=(a1-b1)*t1;
          if(L%D==0){
            cout << L/D*2 << endl;
          }
          else{
            cout << L/D*2+1 << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  int k;
  cin>>a>>b>>c;
  cin>>k;
  while(a>=b){
    b*=2;
    k--;
  }
  while(b>=c){
    c*=2;
    k--;
  }
  if(k>=0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3632
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

cnt = 1
ans = 0
temp = 1000000
for h in H:
    if abs(A - (T-h*0.006)) < temp:
        temp = abs(A - (T-h*0.006))
        ans = cnt
    cnt += 1
print(ans)


Measured memory_bytes: 3060
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = [[0] * 2 for _ in range(m)]
for i in range(m):
    bc[i] = list(map(int, input().split()))
bc = sorted(bc, key=lambda x: x[1], reverse=True)
mat = []
for b, c in bc:
    if len(mat) + b > n:
        mat.extend([c] * (n - len(mat)))
        break
    else:
        mat.extend([c]*b)

for i, t in enumerate(a):
    if i == len(mat):
        break
    if t < mat[i]:
        a[i] = mat[i]
    else:
        break

print(sum(a))


Measured memory_bytes: 92780
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		double left = n/1.08;
		double right = (n+1)/1.08;
		
		int x = (int)Math.ceil(left);
		if(x < right) {
			System.out.println(x);
		}else {
			System.out.println(":(");
		}
		
		
	}

}


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

using namespace std;

int main() {
  int64_t a, b, v, w, t;
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  for(int64_t i = 1; i < t + 1; i++) {
    if(a == b) {
      cout << "YES" << endl;
      return 0;
    }
    if(w >= v) {
      cout << "NO" << endl;
      return 0;
    }
    if(b > a) {
      a += v;
      b += w;
      if(a >= b) {
        cout << "YES" << endl;
        return 0;
      }
    }
    if(a > b) {
      a -= v;
      b -= w;
      if(b >= a) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3580