akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int N = nk[0];
        int K = nk[1];

        Console.WriteLine(N - K + 1);
    }
    
}


static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}


Measured memory_bytes: 13268
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG 0
#define dd if (DEBUG)

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define rall(a) (a).rbegin (), (a).rend ()
#define sz(a) (int) (a).size ()
#define szl(a) (int) (a).length ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;
typedef pair <int, int> pii;
#define f first
#define s second
#define mp(a, b) make_pair((a), (b))
typedef vector <int> vi;
typedef vector <vi> mi;
typedef vector <ll> vll;
typedef vector <vll> mll;
#define pb(a) push_back ((a))

const ll MOD = 1e+9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INFi = 0x3f3f3f3f;
const ll MAXN = 1e+6+7;

int main ()
{
    FASTIO;
    int i, j, n, h, w;
    cin >> n >> w; char c;
    mi g (n, vi (w)), dp (n, vi (w));
    trav (r, g)
        trav (a, r)
        {
            do cin >> c;
            while (c != '.' && c != '#');
            a = c == '.';
        }
    dd trav (r, g) {
        trav (a, r)
            cout << a << " ";
        cout << '\n'; }
    dd cout << endl;
    for (i = 0; i < n; i++)
        for (j = 0; j < w; j++)
            if (i > 0)
                if (j > 0)
                    dp[i][j] = ((g[i][j]?dp[i-1][j]:0) + (g[i][j]?dp[i][j-1]:0))%MOD;
                else
                    dp[i][j] = g[i][j]?dp[i-1][j]:0;
            else if (j > 0)
                dp[i][j] = g[i][j]?dp[i][j-1]:0;
            else
                dp[i][j] = 1;
    cout << dp[n - 1][w - 1] << '\n';

    return 0;
}



Measured memory_bytes: 8192
import java.util.*;
import java.io.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int a = sc.nextInt();
    int attacks = 0;
    while(h>0){
      h-=a;
      attacks++;
    }
    System.out.println(attacks);
  }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

int main()
{
    int n;
    cin>>n;
    int h[n];
    rep(i,n)cin>>h[i];
    int ans=0;
    while(1)
    {
        bool zeroexist=false;
        int count=0;
        int zerocount=0;
        rep(i,n)
        {
            if(i==0 && h[0]!=0)
            {
                count++;
            }
            if(h[i]!=0)
            {
                if(zeroexist)count++;
                h[i]--;
                zeroexist=false;
            }
            else
            {
                zeroexist=true;
                zerocount++;
            }
            
        }
        if(zerocount==n)break;
        ans+=count;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N=int(input())
K=list(map(int,input().split()))
L=sorted(K)
maxi=1
for i in range(18):
  maxi=maxi*10
pro=1
for i in range(N):
  pro=pro*L[i]
  if maxi<pro:
    print(-1)
    break
if maxi>=pro:
  print(pro)


Measured memory_bytes: 21760
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

long MOD = 1000000007;

long calc(long N)
{
    long v = 1;
    for (long i = 2; i <= N; ++i) {
        v *= i;
        v %= MOD;
    }
    return v;
}

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

    if (abs(N - M) >= 2) {
        cout << "0\n";
        return 0;
    }

    long a = calc(N);
    long b = calc(M);

    long ans = a * b;
    ans %= MOD;

    if (N == M) {
        ans *= 2;
        ans %= MOD;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
const double PI = 3.14159265359;

int main()
{
    char a; cin >> a;
    if ('a' <= a && a <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;
}


Measured memory_bytes: 3632
using System;

namespace AOJ.Volume0
{
    public class Videotape
    {
        public static int Main()
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                int t = int.Parse(input[0]);
                int h = int.Parse(input[1]);
                int s = int.Parse(input[2]);

                if (t == -1 && h == -1 && s == -1) { break; }

                // ????????????????§???§?¨????
                // 3?????????????¨????
                int rest = 7200 - (t * 60 * 60) - (h * 60) - s;
                int rest_3x = rest * 3;

                // ??????
                // ???
                string output = ((int)Math.Floor((decimal)rest / 3600)).ToString("00") + ":";
                string output_3x = ((int)Math.Floor((decimal)rest_3x / 3600)).ToString("00") + ":";
                rest = rest % 3600;
                rest_3x = rest_3x % 3600;

                // ???
                output += ((int)Math.Floor((decimal)rest / 60)).ToString("00") + ":";
                output_3x += ((int)Math.Floor((decimal)rest_3x / 60)).ToString("00") + ":";
                rest = rest % 60;
                rest_3x = rest_3x % 60;

                // ?§?
                output += rest.ToString("00");
                output_3x += rest_3x.ToString("00");

                Console.WriteLine(output);
                Console.WriteLine(output_3x);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9376
#include <stdio.h>

int main() {
	int n, a, b;

	scanf("%d %d %d", &n,&a,&b);
	
	if ((a * n) > b) {
		printf("%d", b);
	}
	else
	{
		printf("%d", a * n);
	}
	//getch();
	return 0; 
}

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

using namespace std;
#define INF 1000000001

int main()
{
    int N;
    cin >> N;
    int a;
    for(int i = 0;i < N;i++){
        cin >> a;
        if(a%2 == 0 && (a%3 != 0 && a%5 != 0)){
            cout << "DENIED" << endl;
            break;
        }
        if(i == N-1) cout << "APPROVED" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

int N, T;
int A[3000], B[3000];
int r[3000];
int knapsack[6000];

bool cmp(int i, int j) {
        return A[i] < A[j];
}

int main() {
        scanf("%d%d", &N, &T);
        for (int i = 0; i < N; i++) {
                scanf("%d%d", &A[i], &B[i]);
                r[i] = i;
        }
        sort(r, r + N, cmp);
        for (int i = 1; i <= T; i++)
                knapsack[i] = -1;
        for (int i = 0; i < N; i++)
                for (int j = T + A[r[i]] - 1; j >= A[r[i]]; j--)
                        if (knapsack[j - A[r[i]]] >= 0)
                                knapsack[j] = max(knapsack[j], knapsack[j - A[r[i]]] + B[r[i]]);
        int ans = 0;
        for (int i = 0; i < 6000; i++)
                ans = max(ans, knapsack[i]);
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 256
main :: IO ()
main = do
    n <- getLine
    as <- map read . words <$> getLine
    putStrLn (show $ pirupiru as)

pirupiru :: [Int] -> Int
pirupiru xs = if godFizzNa xs then 1 + (pirupiru $ fmap (`div` 2) xs)
              else 0

-- 次が可能か調べる
godFizzNa :: [Int] -> Bool
godFizzNa [] = True
godFizzNa (x:xs) = if x `mod` 2 == 0 then godFizzNa xs
                 else False

-- 回数を記録する必要がある

Measured memory_bytes: 1020
N,A,B,C = map(int,input().split())
S = [input() for _ in range(N)]

ANS = ['']*N
for i in range(N):
    if S[i]=='AB':
        if A==0 and B==0:
            print('No')
            exit()
        if i != N-1 and A==B and S[i+1]!='AB':
            if S[i+1]=='AC':
                ANS[i] = 'A'
                A += 1
                B -= 1
            elif S[i+1]=='BC':
                ANS[i] = 'B'
                B += 1
                A -= 1

        elif A<B:
            ANS[i] = 'A'
            A += 1
            B -= 1
        else:
            ANS[i] = 'B'
            A -= 1
            B += 1
            

    elif S[i]=='AC':
        if A==0 and C==0:
            print('No')
            exit()
        if i != N-1 and A==C and S[i+1]!='AC':
            if S[i+1]=='AB':
                ANS[i] = 'A'
                A += 1
                C -= 1
            elif S[i+1]=='BC':
                ANS[i] = 'C'
                C += 1
                A -= 1
        elif A<C:
            ANS[i] = 'A'
            A += 1
            C -= 1
        else:
            ANS[i] = 'C'
            A -= 1
            C += 1


    elif S[i]=='BC':
        if C==0 and B==0:
            print('No')
            exit()
        if i != N-1 and C==B and S[i+1]!='BC':
            if S[i+1]=='AC':
                ANS[i] = 'C'
                C += 1
                B -= 1
            elif S[i+1]=='AB':
                ANS[i] = 'B'
                B += 1
                C -= 1
        elif C<B:
            ANS[i] = 'C'
            C += 1
            B -= 1
        else:
            ANS[i] = 'B'
            C -= 1
            B += 1
if A<0 or B<0 or C<0:
    print('No')
    exit()

print('Yes')
for a in ANS:
    print(a)

Measured memory_bytes: 81616
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations

# input = sys.stdin.readline
Xa, K, D = map(int, input().split())
X = abs(Xa)
Xs = X // D
Xm = X % D
if K < Xs:
#     print("A")
    print(abs(X-K*D))
elif Xa == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
elif Xm == 0:
    if K % 2 == 0:
        print(D)
    else:
        print(0)
elif ((K-Xs) % 2 == 0):
    print(abs(Xm))
else:
    print(abs(D-Xm))















Measured memory_bytes: 27116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int K = sc.nextInt();
		String a = S.substring(K-1, K);

		String ans = "";
		for (int i = 1; i <= N; i++) {
			String add = S.substring(i-1,i);
			if (!a.equals(add)) {
				ans += "*";
			} else {
				ans += add;
			}
		}

		System.out.println(ans);
	}
}


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

#include <atcoder/convolution>
using namespace atcoder;

const long long MOD = 998244353;

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
    vector<long long> result = convolution<MOD>(a, b);
    for (int i = 0; i < N + M - 1; i++) {
        cout << result[i] << ((i == N + M - 1) ? "" : " ");
    }
}

// Generated by 1.1.7.1 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 N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(M-1-0+1);
    for(int i = 0 ; i < M-1-0+1 ; i++){
        scanf("%lld",&b[i]);
    }
    solve(N, M, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 27208
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int m = Integer.parseInt(scan.next());

        int[][] s = new int[m][];
        for (int i = 0; i < m; i++) {
            int k = Integer.parseInt(scan.next());
            s[i] = new int[k];
            for (int j = 0; j < k; j++) {
                s[i][j] = Integer.parseInt(scan.next());
                s[i][j]--;
            }
        }

        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = Integer.parseInt(scan.next());
        }
        scan.close();

        int ans = 0;
        for (int bit = 0; bit < (1 << n); bit++) {
            Set<Integer> onSet = new HashSet<Integer>();
            for (int i = 0; i < n; i++) {
                if ((bit & (1 << i)) != 0) {
                    onSet.add(i);
                }
            }

            boolean isSatisfy = true;
            for (int i = 0; i < m; i++) {
                int onCount = 0;
                for (int j = 0; j < s[i].length; j++) {
                    if (onSet.contains(s[i][j])) {
                        onCount++;
                    }
                }
                if (onCount % 2 != p[i]) {
                    isSatisfy = false;
                    break;
                }
            }
            if (isSatisfy) {
                ans++;
            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 22100
n = int(input())

dish = []
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    dish.append(a + b)
    ans += -1 * b

dish.sort(reverse=True)
for i in range(n):
    if i % 2 == 0:
        ans += dish[i]
print(ans)

Measured memory_bytes: 80968
//created by pyoxiao on 2020/05/03
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
string s;
void solve() {
    cin >> s;
    if(s == "ABC") puts("ARC");
    else puts("ABC");
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

//https://atcoder.jp/contests/abc138/submissions/8719035 写経

using Graph = vector<vector<int>>;

int ci[200010];
ll ans[200010];
ll cnt;

void dfs(const Graph &G, int v, int p) {
	cnt += ci[v];
	for (auto nv : G[v]) {
		if (nv == p) continue;
		dfs(G, nv, v);
	}
	ans[v] += cnt;
	cnt -= ci[v];
}

int main(void){
	int n, q; cin>>n>>q;
	Graph G(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin>>a>>b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for (int i = 0; i < q; i++) {
		int p, x; cin>>p>>x;
		p--;
		ci[p] += x;
	}

	cnt = 0;
	dfs(G, 0, -1);
	for (int v = 0; v < n; v++) {
		cout << ans[v] << " ";
	}cout<<endl;
	
	return 0;
}

Measured memory_bytes: 27904
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
ll m=sqrt(n)+100;
ll ans=inf;
for(int i=1;i<=m;i++){
  if(n%i==0){
    chmin(ans,(i-1)+(n/i-1));
  }
}
if(ans==inf)cout<<n-1<<endl;
else cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N,A,count,min=1000000,i;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        count = 0;
        scanf("%d",&A);
        while(A%2==0){
            count++;
            A = A/2;
        }
        if(count<min) min = count;
    }

    printf("%d",min);

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define int         long long
#define endl        "\n"
#define pii         pair<int, int>

const int mod = 1e9+7;
const int MAXN = 1e5+5;
const int N = 1e5+5;

int fac[N];
int spf[MAXN]; 

void pre(int p) {
    fac[0] = 1;
    for(int i=1; i<N; i++) {
        fac[i] = (fac[i-1] * i) % p;
    }
}


void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (int j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i; 
        } 
    } 
} 

vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 

unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCr(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) return 1; 
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}

///////////////////////////////////////////////////////////////////////////////////////////////////
 
void solve(int TC) { 
    string s; cin >> s;
    vector<int> cnt(26, 0);
    for(char c : s) {
        cnt[c - 'a']++;
    }
    for(int i=0; i<26; i++) if(cnt[i] == 0) {
        cout << char('a' + i);
        return;
    }
    cout << "None";
}
 
signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);
 
 
    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve(i);
    }
    return 0;
 
}

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

using namespace std;
struct data
{
    int sum=0;
    int red=0;
}s[100005];
int main()
{
    ios::sync_with_stdio(false);
    int n,m,i;
    cin>>n>>m;
    s[1].sum=s[1].red=1;
    for(i=2;i<=n;i++) s[i].sum=1;
    int x,y,ans=0;
    while(m--){
        cin>>x>>y;
        if(s[x].red==1&&s[x].sum==1){
            s[y].red=1;
            s[x].sum=s[x].red=0;
            s[y].sum++;
        }
        else if(s[x].red==0&&s[x].sum!=0){
            s[y].sum++;
            s[x].sum--;
        }
        else if(s[x].red==1&&s[x].sum>1){
            s[x].sum--;
            s[y].red=1;
            s[y].sum++;
        }
    }
    for(i=1;i<=n;i++){
        if(s[i].red==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdlib>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ABS(x) (((x)<0)?(-(x)):(x))
#define MAX(x,y) (((x)<(y))?(y):(x))
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;

int main(){
  int N=0;
  cin >> N;
  int Crd[N][3],ans[3];
  int base=-1;
  for(int i=0;i<N;++i){
    cin >> Crd[i][0] >> Crd[i][1] >> Crd[i][2];
    if(Crd[i][2]!=0 && base==-1) base=i;
  }
  ans[2] = 0;
  for(int Cx=0;Cx<=100;++Cx){
    bool flag=true;
    for(int Cy=0;Cy<=100;++Cy){
      flag = true;
      ans[2]=Crd[base][2]+ABS(Cx-Crd[base][0])+ABS(Cy-Crd[base][1]);
      for(int i=0;i<N && flag;++i)
        flag = Crd[i][2]==MAX(ans[2]-ABS(Cx-Crd[i][0])-ABS(Cy-Crd[i][1]),0);
      if(flag){
        ans[0]=Cx;
        ans[1]=Cy;
        break;
      }
    }
    if(flag) break;
  }
  cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;;
}


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

struct unionFind {
  int n;
  vector<int> v, s;

  //     void init(){
  //         // v.resize(n);
  //         // for(int i=0;i<n;i++)v[i]=i;
  //         v.assign(n,-1);
  //         s.assign(n,1);
  //     }

  unionFind(){};

  unionFind(int _n) {
    n = _n;

    v.resize(n, -1);
    s.resize(n, 1);

    // for (int i = 0; i < n; i++) {
    //   v.push_back(i);
    //   s.push_back(1);
    // }
  }

  int root(int i) {
    if (v[i] == -1)
      return i;
    else
      return v[i] = root(v[i]);
  }

  void join(int i, int j) {
    int ri = root(i);
    int rj = root(j);
    if (ri == rj) return;
    if (s[ri] < s[rj]) swap(ri, rj);
    v[rj] = ri;
    s[ri] += s[rj];
  }

  int size(int i) { return s[root(i)]; }

  bool connected() { return size(0) == n; }
};

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<int> a(m), b(m);

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[i] = x;
    b[i] = y;
  }

  for (int i = 0; i < m; i++) {
    auto u = unionFind(n);
    for (int j = 0; j < m; j++) {
      if (j != i) u.join(a[j], b[j]);
    }

    // for(int i=0;i<n;i++)cout<<u.root(i)<<" ";
    // cout<<endl;
    // for(int i=0;i<n;i++)cout<<u.size(i)<<" ";
    // cout<<endl;

    // if (!u.connected()) ans++;
    if (u.size(0) != n) ans++;
  }
  //      cout<<endl;
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
    chrono::system_clock::time_point start;
    start = chrono::system_clock::now();

    ios::sync_with_stdio(false);
    cin.tie(0);

    const int INF = 1000000000;

    int d;
    cin >> d;
    vector<int> c(26);
    vector<vector<int>> s(d, vector<int>(26));
    for(int i = 0; i < 26; ++i) cin >> c[i];
    for(int j = 0; j < d; ++j)
        for(int i = 0; i < 26; ++i) cin >> s[j][i];

    int m;
    vector<int> t(d);
    vector<vector<int>> blank(d, vector<int>(26, 1));
    for(int j = 0; j < d; ++j) {
        for(int i = 0; i < 26; ++i) 
            if(j != 0) blank[j][i] = blank[j - 1][i] + 1;
        m = - INF;
        for(int i = 0; i < 26; ++i) {
            if(s[j][i] + c[i] * blank[j][i] > m) {
                t[j] = i;
                m = s[j][i] + c[i] * blank[j][i];
            }
        }
        blank[j][t[j]] = 0;
    }

    int d_, q, dt, diff = 0, m2;
    vector<int> t_ = t;
    vector<vector<int>> blank_ = blank;
    srand((unsigned int)time(NULL));
    while(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count() < 1980) {
        d_ = rand() % d;
        m2 = - INF;
        // for(int i = 0; i < 26; ++i) {
        //     if(s[d_][i] > m2) {
        //         m2 = s[d_][i];
        //         q = i;
        //     }
        // }
        q = rand() % 26;

        diff = 0;

        diff -= s[d_][t_[d_]];
        diff += s[d_][q];

        if(d_ != 0) blank_[d_][t_[d_]] = blank_[d_ - 1][t_[d_]] + 1;
        else blank_[d_][t_[d_]] = 1;
        diff -= c[t_[d_]] * blank_[d_][t_[d_]];
        dt = d_ + 1;
        while(t_[dt] != t_[d_] && dt < d) {
            diff += c[t_[d_]] * blank_[dt][t_[d_]];
            blank_[dt][t_[d_]] = blank_[dt - 1][t_[d_]] + 1;
            diff -= c[t_[d_]] * blank_[dt][t_[d_]];
            dt++;
        }

        diff += c[q] * blank_[d_][q];
        blank_[d_][q] = 0;
        dt = d_ + 1;
        while(t_[dt] != q && dt < d) {
            diff += c[q] * blank_[dt][q];
            blank_[dt][q] = blank_[dt - 1][q] + 1;
            diff -= c[q] * blank_[dt][q];
            dt++;
        }

        t_[d_] = q;

        // printf("%d\n", diff);

        if((double)rand() / RAND_MAX < exp((double)diff / 4000)) {
        // printf("updated\n");
            t = t_;
            blank = blank_;
        } else {
        // printf("unchanged\n");
            t_ = t;
            blank_ = blank;
        }
    }

    for(int j = 0; j < d; ++j) {
        printf("%d\n", t[j] + 1);
    }

    return 0;
}

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

const int MAXN = 105;

int N;
int a[MAXN], b[MAXN];

struct node {
	int to, next;
} edge[MAXN*2];
int head[MAXN], top = 0, d[MAXN];
inline void push(int i, int j)
{ edge[++top] = (node) {j, head[i]}, head[i] = top; }

int ans;
long long tot = 0;

int depth[MAXN], max_deg[MAXN];

void dfs(int nd, int f, int flag = 0)
{
	max_deg[depth[nd]] = max(max_deg[depth[nd]], d[nd]-flag);
	for (int i = head[nd]; i; i = edge[i].next) {
		int to = edge[i].to;
		if (to == f) continue;
		depth[to] = depth[nd]+1;
		dfs(to, nd, 1);
	}
}

int main()
{
	scanf("%d", &N), ans = N;
	for (int i = 1; i < N; i++) {
		scanf("%d%d", &a[i], &b[i]), d[a[i]]++, d[b[i]]++;
		push(a[i], b[i]), push(b[i], a[i]);
	}
	for (int i = 1; i <= N; i++) {
		depth[i] = 0;
		memset(max_deg, 0, sizeof max_deg);
		dfs(i, 0, 0);
		long long cur_tot = 1;
		int cur_ans = 0;
		for (int j = 1; j <= N; j++)
			cur_ans = max(cur_ans, depth[j]);
		for (int j = 0; j < cur_ans; j++)
			cur_tot = cur_tot*max_deg[j];
		cur_ans++;
		if (cur_ans < ans) ans = cur_ans, tot = cur_tot;
		else if (cur_ans == ans) tot = min(tot, cur_tot);
	}
	for (int i = 1; i < N; i++) {
		int x = a[i], y = b[i];
		depth[x] = depth[y] = 0;
		memset(max_deg, 0, sizeof max_deg);
		dfs(x, y, 1), dfs(y, x, 1);
		long long cur_tot = 1;
		int cur_ans = 0;
		for (int j = 1; j <= N; j++)
			cur_ans = max(cur_ans, depth[j]);
		for (int j = 0; j < cur_ans; j++)
			cur_tot = cur_tot*max_deg[j];
		cur_tot *= 2;
		// cerr << x << " " << y << " " << cur_ans+1 << " " << cur_tot << endl;
		cur_ans++;
		if (cur_ans < ans) ans = cur_ans, tot = cur_tot;
		else if (cur_ans == ans) tot = min(tot, cur_tot);
	}
	cout << ans << " " << tot << endl;
	return 0;
}


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

int main() {
  int a,b,n=0;
  cin >>a >>b ;
  for(int i=a;i<b+1;i++){
    int man,sen,zyu,iti;
    man=i/10000;
    sen=(i-man*10000)/1000;
    iti=i%10;
    zyu=((i-iti)/10)%10;
    if(man==iti&&sen==zyu){n++;}
  
  
  }
  
  
  
  
  cout<<n <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int ans,i,j;
string s;               
int main(){	
    cin>>s;
    i=0;
    j=s.size()-1;
    while(i<=j)
    {
    	if(s[i]!=s[j]) ans++;
    	i++;
    	j--;
	}
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int row, col;
char grid[1005][1005];
int dist[1005][1005];

int dx[5] = {-2, -1, 0, +1, +2}, dy[5] = {-2, -1, 0, +1, +2};
const int inf = 1e10;

bool isSafe(int x, int y) {
    if(x <= 0 || y <= 0 || x > row || y > col || grid[x][y] == '#' )return false;
    return true;
}

int32_t main() {

    fast

    cin >> row >> col;
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;


    for(int i = 1; i <= row; i++) {
        for(int j = 1; j <= col; j++) {
            cin >> grid[i][j];
            dist[i][j] = inf;
        }
    }

    multiset<pair<int, pair<int, int>> >ms;
    dist[sx][sy] = 0;
    ms.insert({0, {sx, sy}});
    int newX, newY;
    while(!ms.empty()) {
        int curX = (*ms.begin()).second.first;
        int curY = (*ms.begin()).second.second;
        int wt = (*ms.begin()).first;
        ms.erase(ms.begin());

        for(int i = 0; i < 5; i++) {
            for(int j = 0; j < 5; j++) {
                if(dx[i] == 0 && dy[j] == 0)continue;
                newX = curX + dx[i];
                newY = curY + dy[j];
                if(!isSafe(newX, newY))continue;
                if(abs(newY - curY) + abs(newX - curX) == 1) {
                    if(dist[newX][newY] > wt) {
                        dist[newX][newY] = wt;
                        ms.insert({wt, {newX, newY}});
                    }
                } else {
                    if(dist[newX][newY] > wt + 1) {
                        dist[newX][newY] = wt + 1;
                        ms.insert({wt + 1, {newX, newY}});
                    }
                }
            }
        }

    }
    if(dist[ex][ey] >= inf) {
        cout << -1 << endl;
    } else {
        cout << dist[ex][ey] << endl;
    }


    return 0;
}



Measured memory_bytes: 12992
#pragma GCC optimize("Ofast")

// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
// #define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
// typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
// using vvvi=vector<vvi>;
/*
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
*/
template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
// template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
/*
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10); x/=10;} reverse(all(res)); return res;}
*/
void solve() {
  ll n; cin>>n; vi A(n); rep(i,n) cin>>A[i];
  sort(all(A)); bool f=true;
  rep(i,n-1){
    if(A[i]==A[i+1]){
      f=false;
    }
  }
  if(f) out("YES");
  else out("NO");
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(){
  int u,i,j,c,x,y,z,G[100][100],a[100],d[100];
 
  scanf("%d", &u);
  for(i = 0; i < u; i++){
    a[i] = 0;

    if(i == 0){
      d[i] = 0;
    }
    else d[i] = 150000;

    for(j = 0; j < u; j++){
      G[i][j] = -1;
    }
  }
 
  for(i = 0; i < u; i++){
    scanf("%d %d", &x, &y);
    for(j = 0; j < y; j++){
      scanf("%d", &z);
      scanf("%d", &G[x][z]);
    }
  }
 
  while(c != 150000){
    c = 150000;
    for(i = 0; i < u; i++){
      if(a[i] != 1 && d[i] < c){
        c = d[i];
        x = i;
      }
    }
 
    for(i = 0; i < u; i++){
      if(G[x][i] != -1 && a[i] != 1 && d[x] + G[x][i] < d[i])
        d[i] = d[x] + G[x][i];
    }
    a[x] = 1;
  }
 
  for(i = 0; i < u; i++){
    printf("%d %d\n", i, d[i]);
    }

  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int y;
string x;
int main()
{
	cin>>x;
	for(int i=0; i<x.size()-1; i++)
		if(x[i]=='C')
			for(int j=i+1; j<x.size(); j++)
				if(x[j]=='F')
				{
					y=1;
					cout<<"Yes"<<endl;
					return 0;
				}
	if(y==0)
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int N_FLOOR = 10;
		int N_H = 3;
		int N_TO = 4;
		int table[][][] = new int[N_TO][N_H][N_FLOOR];

		int n, b, f, r, v;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		for(int i=0;i<n;i++) {
			b = in.nextInt() - 1;
			f = in.nextInt() - 1;
			r = in.nextInt() - 1;
			v = in.nextInt();

			table[b][f][r] += v;
		}
		for(int i=0; i < N_TO;i++) {
			for(int j=0;j<N_H;j++) {
				for(int k=0;k<N_FLOOR;k++) {
					System.out.print(" "+table[i][j][k]);
				}
				System.out.println("");
			}
			if(i != N_TO-1) {
				System.out.println("####################");
			}
		}
	}
}

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

N = int(input())

ans = ""
while N != 0:
    # 末尾の桁が偶奇を決めているので、そこが0か1かは判断できる
    if N % 2 == 0:
        ans = "0" + ans
    else:
        # 今の末尾の桁は1だったので、まずはその分を引く
        N -= 1
        ans = "1" + ans
    # -2進数は-2で割れば桁を落とせる(10進数で割る10する感じ)
    N /= -2
# Nが元々0だった場合
if ans == "":
    ans = 0

print(ans)

Measured memory_bytes: 2940
import java.util.Scanner;

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

        Scanner in = new Scanner(System.in);

        String input = in.nextLine();
        String [] param_line = input.split(" ", 0);
        int [] dice_no = new int[6];
        for(int i=0; i<dice_no.length; i++)
            dice_no[i] = Integer.parseInt(param_line[i]);

        // create dice class instance
        Dice dice = new Dice(dice_no);

        //System.out.println(dice);

        // dice operation
        input = in.nextLine();
        for(int i=0; i<input.length(); i++){
            switch(input.charAt(i)){
                case 'W':
                    dice.toW();
                    break;
                case 'E':
                    dice.toE();
                    break;
                case 'S':
                    dice.toS();
                    break;
                case 'N':
                    dice.toN();
                    break;
            }
            //System.out.println(dice);
            //System.out.println(input.charAt(i));
        }
        System.out.println(dice.get(0));
    }
}

class Dice{

    static final int W = 6;
    static final int E = 7;
    static final int S = 8;
    static final int N = 9;

    static  final int[][] dice_table = {

    // top,front,right,left,back,bottom,W,E,S,N
        {0, 1, 2, 3, 4, 5, 9, 15, 16, 6},
        {0, 2, 4, 1, 3, 5, 17, 7, 12, 10},
        {0, 4, 3, 2, 1, 5, 13, 11, 4, 18},
        {0, 3, 1, 4, 2, 5, 5, 19, 8, 14},
        {1, 0, 3, 2, 5, 4, 12, 8, 20, 2},
        {1, 3, 5, 0, 2, 4, 21, 3, 9, 13},
        {1, 5, 2, 3, 0, 4, 10, 14, 0, 22},
        {1, 2, 0, 5, 3, 4, 1, 23, 15, 11},
        {2, 0, 1, 4, 5, 3, 4, 16, 23, 3},
        {2, 1, 5, 0, 4, 3, 20, 0, 17, 5},
        {2, 5, 4, 1, 0, 3, 18, 6, 1, 21},
        {2, 4, 0, 5, 1, 3, 2, 22, 7, 19},
        {3, 0, 4, 1, 5, 2, 16, 4, 21, 1},
        {3, 4, 5, 0, 1, 2, 22, 2, 5, 17},
        {3, 5, 1, 4, 0, 2, 6, 18, 3, 23},
        {3, 1, 0, 5, 4, 2, 0, 20, 19, 7},
        {4, 0, 2, 3, 5, 1, 8, 12, 22, 0},
        {4, 2, 5, 0, 3, 1, 23, 1, 13, 9},
        {4, 5, 3, 2, 0, 1, 14, 10, 2, 20},
        {4, 3, 0, 5, 2, 1, 3, 21, 11, 15},
        {5, 1, 3, 2, 4, 0, 15, 9, 18, 4},
        {5, 3, 4, 1, 2, 0, 19, 5, 10, 12},
        {5, 4, 2, 3, 1, 0, 11, 13, 6, 16},
        {5, 2, 1, 4, 3, 0, 7, 17, 14, 8},
    };

    private int status;
    private int[] page_no;

    Dice(int [] a){
        page_no = a.clone();
        status = 0;
    }

    void toW(){
        status = dice_table[status][W];
    }

    void toE(){
        status = dice_table[status][E];
    }

    void toS(){
        status = dice_table[status][S];
    }

    void toN(){
        status = dice_table[status][N];
    }

    int get(int index){
        return page_no[dice_table[status][index]];
    }


    @Override
    public String toString(){
        String str = "";
        for(int i=0; i<page_no.length-1; i++)
            str += page_no[dice_table[status][i]] + ", ";
        str += page_no[dice_table[status][page_no.length-1]];
        return str;
    }
}

Measured memory_bytes: 26148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }


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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];


  vector<vi> tate_cnt(h, vi(w)), yoko_cnt(w, vi(h));
  rep(i, h) {
    int c = 0;
    rep(j, w) {
      if (s[i][j] == '.') {
        c++;
      } else {
        c = 0;
      }
      tate_cnt[i][j] = c;
    }
  }
  rep(i, w) {
    int c = 0;
    rep(j, h) {
      if (s[j][i] == '.') {
        c++;
      } else {
        c = 0;
      }
      yoko_cnt[i][j] = c;
    }
  }

  rep(i, h) {
    int c = 0;
    rep(j, w) {
      if (tate_cnt[i][w-1-j] != 0) {
        if (c == 0) c = tate_cnt[i][w-1-j];
        cmax(tate_cnt[i][w-1-j], c);
      } else {
        c = 0;
      }
    }
  }

  rep(i, w) {
    int c = 0;
    rep(j, h) {
      if (yoko_cnt[i][h-1-j] != 0) {
        if (c == 0) c = yoko_cnt[i][h-1-j];
        cmax(yoko_cnt[i][h-1-j], c);
      } else {
        c = 0;
      }
    }
  }

//  rep(i, h) {
//    rep(j, w) {
//      cout << tate_cnt[i][j];
//    }
//    cout << endl;
//  }
//  rep(i, w) {
//    rep(j, h) {
//      cout << yoko_cnt[i][j];
//    }
//    cout << endl;
//  }
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      cmax(ans, tate_cnt[i][j]+yoko_cnt[j][i]-1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 35968
from collections import deque
robin=deque()

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

for i in range(n):
    p,t=input().split()
    robin.append([p,int(t)])

time=0
while(len(robin)!=0):
    proc=robin.popleft()
    if(proc[1]<=q):
        print(proc[0],time+proc[1])
        time+=proc[1]
    else:
        proc[1]-=q
        robin.append(proc)
        time+=q




Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
int n;
ll a[MN];
ll ps[MN];

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

    cin >> n;
    F0R(i, n+1) cin >> a[i];
    RFOR(i, n, 0) ps[i] = ps[i+1]+a[i];
    ll sm = 0;
    ll amt = 1;
    F0R(i, n+1){
        sm += amt;
        amt -= a[i];
        amt *= 2;
        amt = min(amt, ps[i+1]);
        if(amt < 0){
            cout << "-1\n";
            return 0;
        }
    }
    cout << sm << "\n";

    return 0;
}


Measured memory_bytes: 5184
N, K = map(int, input().split())
h = list(map(int, input().split())) + [0]*K

dp = [float('inf') for _ in range(N+K)]
dp[0] = 0
'配るdp'
for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])

Measured memory_bytes: 57568
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int n,k;
    cin>>n>>k;
    double q = 0.0;
    for(int i = 0; i<n; i++){
        int c=0;
        int sum = i+1;//出た目
        while(sum<k){
            sum*=2;
            c++;
        }
        q+=(1.0/pow(2.0,c));
    }
    cout<<setprecision(12)<<q/(double)n<<endl;
    return 0;
}

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

const int MAXN = 4e5 + 10; //dummy
const ll MOD = 1e9 + 7;

template<typename T>
T fast_powerModulo( T a, T b, T M){T res = (T)1;a %= M;while( b ){if( b & 1 ) res = (res * a) % M;b >>= 1;a *= a;a %= M; }return res;}

void solve(){
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for(auto & i : a) cin >> i;
	sort(a.begin(), a.end());
	ll ans = 0;
	int lm = n - k - 1;
	for(int i  = 0; i <= lm; ++i){
		ans += a[i];
	}
	cout << ans << '\n';
}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int K,A,B;
    cin >> K >> A >> B;
    Rep(i,A,B+1){
        if((i%K)==0){
            pr("OK");
            return 0;
        }
    }
    pr("NG");
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int a[10000000];
int main(){
  int n;
  cin >> n;
  rep0(i,n)cin >> a[i];
  int ans  = 0;
  int nowright = a[0];
  while(1){
    if(nowright == 2)break;
    nowright = a[nowright - 1];
    ans++;
    if(ans >= 100000000){
      cout << -1 << endl;
      return 0;
    }
    
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;
int main()
{

	ll a, b = 0, c = 0, d = 0;
	ll l;
	char C[1000][1000] = {};
	string s, t;
	ll n, h[100001], w[100001];
	cin >> n;
	ll x;
	ll z;
	cin >> z;
	ll X[100001];
	cin >> X[0];
	ll tmp;
	a = abs(X[0]-z);
	ll r;
	for (int i = 1; i < n; i++)
	{
		cin >> X[i];
		b = abs(X[i] - z);
		x = a * b;

		/* 自然数 a > b を確認・入替 */
		if (a<b) {
			tmp = a;
			a = b;
			b = tmp;
		}

		/* ユークリッドの互除法 */
		r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		a =  b;

	}




	cout << a << endl;


	//cout << sum << endl;
	//cout <<  endl;

	return 0;
}

//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}



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

int main(){
    int N;
    cin >> N;
    vector<int>A(N);
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        while(A[i]%2 != 1) {
            ans++;
            A[i]/=2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
A,B,C,D=[int(i) for i in input().split()]
n = 1
while True:
    if n:
        C -= B
        if C < 1:
            print("Yes")
            exit()
    else:
        A-=D
        if A < 1:
            print("No")
            exit()
    n ^= 1

Measured memory_bytes: 61648
n = int(input())
P = [int(x) for x in input().split()]
flag = True
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            copy_P = P[:]
            copy_P[i], copy_P[j] = copy_P[j], copy_P[i]
            if copy_P == sorted(P):
                print("YES")
                flag = False
                break
    else:
        continue
    break
    
if sorted(P) == P:
    print("YES")
    flag = False

if flag:
    print("NO")

Measured memory_bytes: 3188