akhauriyash/Code-Regression huggingface dataset:
//*****************************believer******************************//
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef map<ll,ll> mi;
 
#define f first
#define ss second
#define ins insert
#define pb push_back
#define lb lower_bound 
#define ub upper_bound 
#define pq priority_queue
#define sqr(n) floor(sqrt(n))
#define sz(v) ((ll)(v.size()))
#define trav(a,x) for (auto& a: x)
#define all(v) (v).begin(),(v).end()
#define arl(v) (v).rbegin(),(v).rend()
#define mem(a) memset(a, -1, sizeof (a))
#define ssort(v) sort((v).begin(),(v).end())
#define rsort(v) sort((v).rbegin(),(v).rend())
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define vmn(a) (*min_element(a.begin(),a.end()))
#define vmx(a) (*max_element(a.begin(),a.end()))
#define foo(i,a,b) for (ll i = (a); i < (b); ++i)
#define foor(i,a,b) for (ll i = (a); i >= (b); --i)


///basically in this ques we will try to find the tail probability;
///memset can not be used to fill the double values because meemset fill starting N
///n bits number basically but size of double greater than one that is why it fill garbagevalue
// so we need to intialise it seperaterly;
const ll N=2e5+100;
ll n;
double a[3005];
double dp[3005][3005];

double solve(ll x,ll tail)
{
    
    if(x==0)
    return (tail)?1:a[0];
    
    if(dp[x][tail]!=-1)
    return dp[x][tail];
    
    double ans1=0;
    if(tail)
    ans1+=(1-a[x])*solve(x-1,tail-1)+a[x]*solve(x-1,tail);
    else
    ans1+=a[x]*solve(x-1,tail);
    
    return dp[x][tail]=ans1;
    
}


int main()
{
    cin>>n;
    foo(i,0,n)
    cin>>a[i];
    
    foo(i,0,3005)
    foo(j,0,3005)
    dp[i][j]=-1;
    
    ll tail=n/2;
    double ans=solve(n-1,tail);
    cout<<setprecision(10)<<ans<<"\n";
}


Measured memory_bytes: 74524
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long long N,X,T,a;
	cin >> N >> X >> T;

	string s;
	//cin >> s;

	//int A[5]
	//sort(A, A + 5);
	long long count = 0;
	a = 0;
	while (true)
	{
		a += X;
		count++;
		if (a >= N)
		{
			break;
		}
	}
	if (true)
	{
		cout << count*T << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> b(100000 + 1);
    for (int i =0; i < n; i++) {
        int a;
        cin >> a;
        // avoid index=-1
        b[a]++;
        b[a+1]++;
        b[a+2]++;
    }

    cout << *max_element(b.begin(), b.end()) << endl;

    return 0;
}

Measured memory_bytes: 640
class Node:
    def __init__(self, key:int):
        self.key = key
        self.p = None
        self.left = None
        self.right = None

class Tree:
    def __init__(self):
        self.root = None

    def insert(self, z:Node):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.p = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

def Preorder(target:Node):
    yield target.key
    if target.left != None:
        yield from Preorder(target.left)
    if target.right != None:
        yield from Preorder(target.right)

def Inorder(target:Node):
    if target.left != None:
        yield from Inorder(target.left)
    yield target.key
    if target.right != None:
        yield from Inorder(target.right)

from sys import stdin
tree = Tree()
n = int(input())
lines = stdin.readlines()
for line in lines:
    proc,*key = line.split()
    if proc == "insert":
        tree.insert(Node(int(key[0])))
    else:
        print(" ",end="")
        print(*Inorder(tree.root))
        print(" ",end="")
        print(*Preorder(tree.root))


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


int main(){
    int x;
    cin >> x;
    int sum = 0;
    int t;
    for(t=1;; t++){
        sum+=t;
        if(sum >= x) break;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int K = input.nextInt();

        int snack, people;
        int count = 0;
        boolean[] snuke = new boolean[N];
        for (int i = 0; i < K; i++) {
            people = input.nextInt();
            for (int j = 0; j < people; j++) {
                snuke[input.nextInt() - 1] = true;
            }
        }

        for (int i = 0; i < snuke.length; i++) {
            if (!snuke[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 45872
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const ll mod = 1e9 + 7;
const int n_max = 3030303;

ll fac[n_max];  /// fac[n] = n!
ll finv[n_max]; /// (fac[n] * finv[n]) % MOD = 1
ll inv[n_max];  /// (n * inv[n]) % MOD = 1

void init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, n_max)
    {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll nCk(int n, int k)
{
    if (n < k || k < 0 || n < 0)
        return 0;
    return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

int main()
{

    ll X, Y;
    cin >> X >> Y;

    if ((X+Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    init();
    ll n = (X+Y)/3;
    if (X < Y) swap(X,Y);
    ll k = (n - (X - Y)) / 2;

    cout << nCk(n, k) << endl;
    return 0;
}


Measured memory_bytes: 71296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i= 0;i<(int)c;i++)
int main() {
 long long A;
 long long B;
 cin >> A >> B;
for(int i= 1;i<=B;i++){
  if((A*i)%B==0){
    cout << A*i << endl;
    break;
  }
}
return 0;
}

Measured memory_bytes: 256
#include<iostream>

#define endl '\n'

using namespace std;

const int MAXN=103,MAXW=1e5+3;
long long cost[MAXN],dp[MAXN][MAXW];
int weight[MAXN];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;++i){
        cin>>weight[i]>>cost[i];
    }
    for(int i=1;i<=n;++i){
        for(int i2=1;i2<=w;++i2){
            if(weight[i]>i2){
                dp[i][i2]=dp[i-1][i2];
            }else{
                dp[i][i2]=max(cost[i]+dp[i-1][i2-weight[i]],dp[i-1][i2]);
            }
        }
    }
    cout<<dp[n][w]<<endl;
return 0;
}

Measured memory_bytes: 79360
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h) cin >> s[i];
    int num1[h];
    int num2[w];
    rep(i, h) num1[i] = 0;
    rep(i, w) num2[i] = 0;

    rep(i, h){
        rep(j, w){
            if (s[i][j] == '#'){
                break;
            }
            if (j == w - 1 && s[i][j] == '.'){
                num1[i] = 1;
            }
        }
    }
    rep(i, w){
        rep(j, h){
            if (s[j][i] == '#'){
                break;
            }
            if (j == h - 1 && s[j][i] == '.'){
                num2[i] = 1;
            }
        }
    }
    rep(i, h){
        if (num1[i] == 0){
            rep(j, w){
                if (num2[j] == 0){
                    cout << s[i][j];
                }
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 256
main = do 
 [n,k] <- map (read::String->Int) .words <$> getLine
 --let arr = dropWhile (k<).zipWith ($) (map (f (\x -> abs(k - x) )) $[0..] ) $repeat n
 let diff = n `mod` k
 --print .minimum $[arr!!0,arr!!1]
 print .minimum $[diff, k-diff]
f :: (a->a) -> Int  -> (a->a)
f g 0 = id
f g m = g . f g (m-1) 

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

ifstream in ( "test.in"  );
ofstream out( "test.out" );

const int DIM = 4e2 + 5;

bitset<DIM> oki[DIM][DIM];

int main( void ) {
    
    int n, m;
    cin >> n >> m;
    
    for( int i = 1; i <= n; i ++ )
    for( int j = 1; j <= n; j ++ )
        if( i != j ) oki[i][j] = true;
    
    for( int k = 1; k <= m; k ++ ) {
        int x, y;
        cin >> x >> y;
        
        if( oki[x][y] == true ) {
            oki[x][y] = oki[y][x] = false;
            
            for( int i = 1; i <= n; i ++ ) {
                if( i != x && oki[i][x] == false )
                    oki[i][y] = oki[y][i] = false;
                if( i != y && oki[i][y] == false )
                    oki[i][x] = oki[x][i] = false;
            }
        } else {
            for( int i = 1; i <= n; i ++ )
                oki[i][x] = oki[x][i] = oki[i][y] = oki[y][i] = false;
        }
    }
    
    int ans = 0;
    for( int i = 1; i <= n; i ++ )
    for( int j = i; j <= n; j ++ )
        ans += ( oki[i][j] == true );
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9088
module uf
  implicit none
  integer(8) :: unionfind(100000) = -1

contains

  recursive function root(i) result(res)
    integer(8),intent(in) :: i
    integer(8) res

    if (unionfind(i) < 0) then
       res = i
    else
       unionfind(i) = root(unionfind(i))
       res = unionfind(i)
    end if
  end function root

  subroutine unite(a, b)
    integer(8),intent(in) :: a,b

    if (unionfind(a) < unionfind(b)) then
       unionfind(a) = unionfind(a) + unionfind(b)
       unionfind(b) = a
    else
       unionfind(b) = unionfind(b) + unionfind(a)
       unionfind(a) = b
    end if
  end subroutine unite

end module uf

program abc120d
  use uf
  implicit none
  integer(8) n, m, i, ra, rb
  integer(8),dimension(:),allocatable :: a, b, ans

  read *, n,m
  allocate(a(m),b(m),ans(m))

  do i = 1,m
     read *, a(i),b(i)
  end do

  ans(m) = n*(n-1)/2

  do i = m,2,-1
     ans(i-1) = ans(i)
     ra = root(a(i))
     rb = root(b(i))
     if (ra /= rb) then
        ans(i-1) = ans(i-1)-unionfind(ra)*unionfind(rb)
        call unite(ra,rb)
     end if
  end do

  do i = 1,m
     print *, ans(i)
  end do

end program abc120d


Measured memory_bytes: 5504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] list = new int[n];
        String[] lines = br.readLine().split(" ");
        int m = n;
        while (m-- > 0) {
            list[m] = Integer.parseInt(lines[m]);
        }
        print(list);
        insertionSort(list);

    }

    static void insertionSort(int[] list) {
        for (int i = 1; i < list.length; i++) {
            int v = list[i];
            int j = i - 1;
            while (j >= 0 && list[j] > v) {
                list[j + 1] = list[j];
                j--;
            }
            list[j + 1] = v;
            print(list);
        }
    }

    private static void print(int[] list) {
        for (int i = 0; i < list.length; i++) {
            System.out.print(list[i]);
            if (i < list.length - 1) {
                System.out.print(" ");
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 30132
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, M) = Scanner.Scan<int, int>();
            var passes = new HashSet<int>();
            var wrongs = new int[N + 1];
            var ac = 0L;
            var wa = 0L;
            for (var i = 0; i < M; i++)
            {
                var (p, S) = Scanner.Scan<int, string>();
                if (!passes.Contains(p))
                {
                    if (S == "AC")
                    {
                        passes.Add(p);
                        ac++;
                        wa += wrongs[p];
                    }
                    else wrongs[p]++;
                }
            }
            Console.WriteLine($"{ac} {wa}");
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 49920
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
s = sum(a)
for i in range(n):
    c = min(a[i], b[i])
    a[i] -= c
    b[i] -= c
    a[i+1] = max(0, a[i+1]-b[i])
print(s - sum(a))

Measured memory_bytes: 18476
/**
  @date Time-stamp: <2019-06-22 21:12:08 tagashira>
  @file a.cpp
  @title A - Security
  @brief https://atcoder.jp/contests/abc131/tasks/abc131_a
**/

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

int main() {
  string S;
  cin >> S;

  int count = 0;
  for (int i = 1; i < S.length(); i++) {
    if (S[i] == S[i - 1]) {
      count++;
    }
  }

  if (count != 0) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;

int main() {
    std::ios::sync_with_stdio(false);

    LLI N;
    std::cin >> N;

    std::set<LLI> set;

    rep(i,N) {
        LLI A;
        std::cin >> A;
        auto iter = set.find(A);
        if( iter == set.end()) {
            set.insert(A);
        } else {
            set.erase(iter);
        }
    }
    std::cout << set.size() << std::endl;

    return 0;
}

Measured memory_bytes: 4992
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

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

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

int main()
{
	int n;
	cin >> n;
	priority_queue<int> q;
	rep(i, n) {
		int a;
		cin >> a;
		q.push(a);
	}
	while (q.size() > 1)
	{
		int q1 = q.top(); q.pop();
		int q2 = q.top();
		int c = q1 / q2;
		int sub = q1 - (q2 * c);
		if (sub > 0)
		{
			q.push(sub);
		}
	}
	cout << q.top() << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



Measured memory_bytes: 3908
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e15;
const int N_MAX=1e5;

int N;
struct edge {int to, cost; };
using Graph=vector<edge>;
Graph G[N_MAX];
vector<int>A(N_MAX,0);

void dfs(int i,int x){
    //iは親、xは根
    for(auto v:G[x]){
        if(v.to!=i){
            if(v.cost%2==0)A[v.to]=A[x];
            if(v.cost%2==1)A[v.to]=A[x]+1;
            dfs(x,v.to);
        }
    }
}

signed main(){
    cin>>N;
    REP(i,N-1){
        int a,b,c;cin>>a>>b>>c;a--;b--;
        edge e;
        e.to =b;
        e.cost=c;
        G[a].eb(e);
        e.to=a;
        G[b].eb(e);
    }
    dfs(-1,0);
    REP(i,N)cout<<A[i]%2<<endl;
}

Measured memory_bytes: 10240
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] a = new boolean[n+1];
        boolean[] b = new boolean[n+1];
        for(int i = 0; i < m; i++){
            int p = sc.nextInt();
            int q = sc.nextInt();
            if(p == 1) {
                a[q] = true;
            }else if(q == n){
                b[p] = true;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] && b[i]){
                System.out.println("POSSIBLE");
                return;
            }
        }
        System.out.println("IMPOSSIBLE");
    }
}

Measured memory_bytes: 93336
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    vint l(N);
    REP(i,N) cin>>l[i];

    sort(ALL(l),greater<int>());
    int ans=0;
    REP(i,K) ans+=l[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    int a[n];
    int num=-1;
    rep(i,0,n){
        cin>>a[i];
        if(a[i]==1)num=i;
    }
    int ans=1000000000;
    rep(i,0,k){
        int sum=1;
        int le=num-i-1;
        int ri=num+k-i;
        int zl=max(0,le+1);
        int zr=max(0,n-ri);
        sum+=zl/(k-1)+zr/(k-1);
        if(zl%(k-1)!=0)sum++;
        if(zr%(k-1)!=0)sum++;
        Min(ans,sum);
    }
    cout<<ans<<endl;
}






Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
using namespace std;

int mod = 1000000007;
int n;
string s;
int dp[3001][3001];	//dp[len][sita]

signed main() {
	int i, j;
	
	cin >> n >> s;
	for (i = 0; i < n; i++) dp[1][i] = 1;
	
	for (i = 1; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (!dp[i][j]) continue;
			if (s[i - 1] == '<') {
				dp[i + 1][0] += dp[i][j];
				dp[i + 1][0] %= mod;
				dp[i + 1][j] += mod - dp[i][j];
				dp[i + 1][j] %= mod;
			}
			else {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= mod;
				dp[i + 1][n - i] += mod - dp[i][j];
				dp[i + 1][n - i] %= mod;
			}
		}
		for (j = 0; j < n; j++) {
			dp[i + 1][j + 1] += dp[i + 1][j];
			dp[i + 1][j + 1] %= mod;
		}
	}
	
	int ans = 0;
	for (i = 0; i < n; i++) {
		ans += dp[n][i];
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70656
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

// Distance Sums

using P = pair<int64_t, int64_t>;

vector<int64_t> graph[100001];
bool visited[100001];
P dfs(int64_t v) {  // firstが和,secondがサイズ
  visited[v] = true;
  int64_t sum = 0;
  int64_t size = 1;
  for (const auto& e : graph[v]) {
    if (!visited[e]) {
      auto tmp = dfs(e);
      sum += tmp.first + tmp.second;
      size += tmp.second;
    }
  }
  return make_pair(sum, size);
}

int main() {
  int64_t N;
  cin >> N;
  map<int64_t, P> mp;
  int64_t check;
  for (int64_t i = 1; i <= N; i++) {
    int64_t x;
    cin >> x;
    mp[x] = make_pair(i, 1);  // 頂点番号と木のサイズ
    if (i == 1) check = x;
  }
  if (N == 2) {
    cout << -1 << endl;
    return 0;
  }
  vector<P> ans;
  auto enditr = mp.rend();
  enditr--;
  for (auto itr = mp.rbegin(); itr != enditr; ++itr) {
    auto key = itr->first;
    auto value = itr->second;
    auto vertex = value.first;
    auto size = value.second;
    auto child_key = (key + 2 * size) - N;
    if (child_key >= key) continue;
    auto tmpitr = mp.find(child_key);
    if (tmpitr != mp.end()) {
      auto tmp = tmpitr->second;
      mp.at(child_key) = make_pair(tmp.first, tmp.second + size);
      ans.push_back(make_pair(vertex, tmp.first));
      graph[vertex].push_back(tmp.first);
      graph[tmp.first].push_back(vertex);
    }
  }
  if (ans.size() == N - 1) {
    // これが本当に条件を満たしているか確かめればおそらくACがくる．←模範解答はそうだった．
    // ただ，「不可能なのに可能と言ってしまっている」原因はわからない．
    // 理由はおそらく，相対値しか見ていないから．
    // 一頂点について計算してみる．
    fill(visited, visited + 100001, false);
    auto L = dfs(1);
    // cout << L.first << ' ' << check << endl;
    if (L.first == check) {
      for (const auto& e : ans) {
        cout << e.first << ' ' << e.second << endl;
      }
    } else {
      cout << -1 << endl;
    }

  } else {
    cout << -1 << endl;
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
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; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

ll n, m, x, count=0;
ll MAX= 100000000000000;
ll ans = MAX;
vector<ll> c;
vector<vector<ll>> a;


void dps(vector<ll> A){
  vector<ll> B = A;
  vector<ll> C = A;
  B.pb(0);
  C.pb(1);
  if(B.size()==n+1){
    ll cost=0;
    vector<ll> result(m);
    
    rep(i,n){
      if(B.at(i+1)){
        cost+=c.at(i);
        rep(l,m){
          result.at(l) += a.at(i).at(l);
        }
      }
    }

    rep(i,m){
      if(result.at(i)<x) cost=MAX;
    }

    chmin(ans,cost);
  }

  if(C.size()==n+1){
    ll cost=0;
    vector<ll> result(m,0);
    
    rep(i,n){
      if(C.at(i+1)){
        cost+=c.at(i);
        rep(l,m){
          result.at(l) += a.at(i).at(l);
        }
      }
    }

    rep(i,m){
      if(result.at(i)<x) cost=MAX;
    }

    chmin(ans,cost);
  }
  else {
    dps(B);
    dps(C);  
  }
  
  
}


int main() {

  string s;
 
  cin >> n >> m >> x;
  a.resize(n);
  c.resize(n);

  rep(i,n){
    cin >> c.at(i);
    a.at(i).resize(m);
    rep(l,m){
      cin >> a.at(i).at(l);
    }
  }

  dps({0});

  if(ans==MAX) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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


			String[] days = new String[]{"SUN", "MON" , "TUE", "WED", "THU", "FRI", "SAT"};
			
			String s = sc.next();
			
			List<String> daysList = Arrays.asList(days);
			
			int index = daysList.lastIndexOf(s);
			
			System.out.println(7-index);
		}
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
int D,N;
void solve() {
  LL res=-1;
  if(D==0) res=N==100?101:N;
  if(D==1) res=N==100?10100:100L*N;
  if(D==2) res=N==100?1010000LL:10000L*N;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>D>>N;
  solve();
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF=1e9;
const ll MOD=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


using Weight = ll;
struct Edge {
    int to;
    Weight cost;
};
struct Node {
    int v;
    Node(int v) : v(v) {}
    bool operator<(const Node &rhs) const { return tie(v) < tie(rhs.v); }
};
struct State : public Node {
    Weight cost;
    State(Node node, int cost) : Node(node), cost(cost) {}
    bool operator<(const State &rhs) const { return cost > rhs.cost; }
};

map<Node, Weight> dijkstra(const vector<vector<Edge>> &adj, const Node &source) {
    map<Node, Weight> dist;
    priority_queue<State> que;

    que.push(State(source, 0));
    dist[source] = 0;

    while (que.size()) {
        State s = que.top();
        que.pop();
        Node cur{s.v};

        for (auto u : adj[s.v]) {
            Node next{u.to};
            if (!dist.count(next) || dist[next] > dist[cur] + u.cost) {
                dist[next] = dist[cur] + u.cost;
                que.push(State(next, dist[next]));
            }
        }
    }

    return dist;
}
int main() {
    int V,E,r;
    cin>>V>>E>>r;
    vector<vector<Edge>> adj;
    adj.resize(V);
    rep(i,E) {
        int s,t,d;
        cin>>s>>t>>d;
        adj[s].push_back(Edge{t,d});
    }
    auto dist = dijkstra(adj, r);
    rep(i,V) {
        Node node{i};
        if(dist.count(node)) cout<<dist[node]<<endl;
        else cout<<"INF"<<endl;
    }
    return 0;
}

Measured memory_bytes: 23780
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

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

int N, M;
int s[10];
int c[10];

int main() {

	cin >> N;
	cin >> M;
	rep(i, M) {
		cin >> s[i];
		cin >> c[i];
		s[i]--;
	}
	


	int ans[3] = {-1, -1 , -1};
	rep(i, M) {
		if(ans[s[i]]!=-1)
		{
			if (ans[s[i]] != c[i]) {
				cout << -1 << endl;
				return 0;
			}
		}
		if (N != 1 && s[i] == 0 && c[i] == 0) {
			cout << -1 << endl;
			return 0;
		}

		ans[s[i]] = c[i];
	}

	int ansi = 0;
	rep(i, N) {
		if (ans[i] == -1) {
			if(i==0)
			{
				ansi += pow(10, N-1);
				if (N == 1)ansi = 0;
			}

		}
		else
		{
			ansi += pow(10,N-1-i) * ans[i];
		}

	}
	
	cout << ansi <<endl;
	return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    if(a>0){
        ll ans(0);
        int t(1);
        rep(i,a)    t *= 100;
        rep(i,b){
            ans += t;
        }
        if(b==100)  ans += t;

        cout << ans << endl;
    }else{
        int ans(0);
        if(b==100){
            cout << 101 << endl;
        }else
            cout << b << endl;
    }

    return 0;
}

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

namespace AtCoderTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var t = cin.ReadInt;
            var m = (t / a) * b;
            WriteLine($"{m}");
//            var wait = cin.Read;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0; i<H; ++i) cin >> S.at(i);

    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            if(S.at(i).at(j) == '.'){
                S.at(i).at(j) = '0';

                for(int dx=-1; dx<=1; ++dx){
                    for(int dy=-1; dy<=1; ++dy){
                        int nx = i+dx, ny = j+dy;
                        if(0 <= nx && nx < H && 0 <= ny && ny < W){
                            if(S.at(nx).at(ny) == '#') ++S.at(i).at(j);
                        }
                    }
                }
            }
        }
    }
    for(int i=0; i<H; ++i) cout << S.at(i) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int num[100000][3];
int main(){
    cin>>num[0][0]>>num[0][1]>>num[0][2];
    int a=num[0][0],b=num[0][1],c=num[0][2];
    if(a%2||b%2||c%2){
        cout<<0;
        return 0;
    }if(a==b&&a==c){
        cout<<-1;
        return 0;
    }
    for(int i=1;;i++){
        bool e=false;
        for(int j=0;j<3;j++){
            num[i][j]=num[i-1][(j+1)%3]+num[i-1][(j+2)%3];
            num[i][j]/=2;
            if(num[i][j]%2){
                cout<<i;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
character(len=1) :: e

read(*,*) e

if ( e == 'A' ) then
  write(*,'(a)') 'T'
end if

if ( e == 'T' ) then
  write(*,'(a)') 'A'
end if

if ( e == 'C' ) then
  write(*,'(a)') 'G'
end if

if ( e == 'G' ) then
  write(*,'(a)') 'C'
end if


contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <list>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;

#define mp make_pair
#define pb push_back

typedef long long int64;
typedef unsigned long long uint64;

template<typename T>
void printVector(string &txt, vector<T> &a){
	cout << txt;
	for (int i = 0; i < a.size(); ++i)
		cout << a[i] << ' ';
	cout << endl;
}

int shf[13];
#define MOD 1000000007

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie();

	int n;
	string s;
	for (int i = 0; i <= 12; ++i){
		shf[i] = (i * 10) % 13;
		//cout << shf[i] << endl;
	}


	cin >> s;
	n = s.length();
	vector<vector<int64>> dp;
	dp.resize(n);
	for (int i = 0; i < n; ++i){
		dp[i].resize(13, 0);
	}

	if (s[0] == '?'){
		for (int i = 0; i <= 9; ++i)
			dp[0][i] = 1;
	}
	else{
		dp[0][s[0] - 48] = 1;
	}

	for (int i = 0; i < n - 1; ++i){
		if (s[i + 1] == '?'){
			for (int j = 0; j <= 12; ++j){
				for (int k = 0; k <= 9; ++k){
					int r = (shf[j] + k) % 13;
					dp[i + 1][r] += dp[i][j];
					dp[i + 1][r] %= MOD;
				}
			}
		}
		else{
			int d = s[i + 1] - 48;
			for (int j = 0; j <= 12; ++j){
				int r = (shf[j] + d) % 13;
				dp[i + 1][r] += dp[i][j];
				dp[i + 1][r] %= MOD;
			}
		}
	}

	cout << dp[n - 1][5] << endl;

	return 0;
}


Measured memory_bytes: 13648
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Solver extends Main{
	Solver(){
		
	}
}//Solver_end

@SuppressWarnings("unchecked")
class Main{
	static int imax=Integer.MAX_VALUE;
	static long lmax=Long.MAX_VALUE;
	
	public static void main(String[] args) throws FileNotFoundException{
		
		Scanner sc=new Scanner(System.in);
		String[] n=readlnS(sc,"");
		String[] r=new String[n.length];
		
		for(int i=0; i<n.length; i++){
			r[i]=n[(n.length-1)-i];
		}
		
		if(String.join("",r).equals(String.join("",n))){
			puts("Yes");
		}else{
			puts("No");
		}
		

	}//main_end
	
//---------------------------------------------------------------------------
	static int readI(Scanner sc){
		return Integer.parseInt(sc.nextLine().trim());
	}
	static long readL(Scanner sc){
		return Long.parseLong(sc.nextLine().trim());
	}
	static String readS(Scanner sc){
		return sc.nextLine().trim();
	}
	static int[] readlnI(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToInt(Integer::parseInt).toArray();
	}
	static long[] readlnL(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToLong(Long::parseLong).toArray();
	}
	static String[] readlnS(Scanner sc, String dl){
		return sc.nextLine().trim().split(dl);
	}
	@SuppressWarnings("unchecked")
	static <T> void puts(T... args){
		for(int i=0; i<args.length-1; i++){
			System.out.printf("%s ",args[i]);
		}
		System.out.println(args[args.length-1]);
	}
	static void puts(int[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void puts(long[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void bs(){
		System.out.println("");
	}
	static int sum(int[] ary){
		int sum=0;
		for(int i=0; i<ary.length; i++) sum+=ary[i];
		return sum;
	}
	static long sum(long[] ary){
		long sum=0;
		for(int i=0; i<ary.length; i++) sum+=ary[i];
		return sum;
	}
	static void tblSort(int[][] tbl){
		Arrays.sort(tbl, new Comparator<int[]>(){
			@Override
			public int compare(int[] a, int[] b){
				if(a[0]==b[0]){
					return b[1]-a[1];
				}else{
					return b[0]-a[0];
				}
			}
		});
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e9 +7
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
#define endl '\n'
using namespace std;
int main()
{
    fastio; 
    ll T=1;
    //cin>>T; 
    while(T--)
    {
    	ll n;
    	cin>>n;
    	if(n%1000==0)cout<<"0"<<endl;
    	else
    	cout<<1000-n%1000<<endl;
	}
}



Measured memory_bytes: 3640
A = int(input())
B = int(input())
C = int(input())
X = int(input())
 
cnt = 0
 
for a in range(0,A+1):
  for b in range(0,B+1):
    for c in range(0,C+1):
      if a*500+b*100+c*50 == X:
        cnt +=1
 
print(cnt)

Measured memory_bytes: 3064
#include <iostream> 
#include <cstring> 
#include <climits>
using namespace std;

#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define f first
#define s second
#define all(x) x.begin() , x.end()
#define mii map<int,int>
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define mk(arr,n,type) type *arr=new type[n]
#define w(x) int x;cin>>x;while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define FOR(i,a,n) for(int i = a;i<n;i++)
#define FORD(i,a,n) for(int i = a;i<=n;i++)
#define FORR(i,n,a) for(int i = n;i>=a;i--)
#define endl "\n"



int dp[100009] = {0};

const int inf = 1000000007;

int solve(int *arr,int n,int k) {
    
    dp[0] = 0;
    dp[1] = abs(arr[0]-arr[1]);
    
    FOR(i,2,n) {
        FOR(j,1,k+1) {
            if(i-j >= 0) {
                int val = dp[i-j]+abs(arr[i]-arr[i-j]);
                dp[i] = min(dp[i],val);
            }else {
                break;
            }
        }
    }
    
    return dp[n-1];
}



int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // w(x) {
        int n,k;
        cin >>n>>k;
        int *arr = new int[n+1];
        FOR(i,0,n) {
            cin >>arr[i];
        }
        
        memset(dp,inf,sizeof dp);
        
        cout<<solve(arr,n,k)<<endl;
        
    // }
}

Measured memory_bytes: 4700
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin>>N;
	int bf_x = 0, bf_y = 0, bf_t = 0;
	bool ok = true;
	rep(i,N){
		int x,y,t;
		cin>>t>>x>>y;
		int dist = abs(x-bf_x) + abs(y-bf_y);
		int time = t-bf_t;
		if(dist > time){ok = false;}
		if(dist < time && dist%2 != time%2){ok = false;}
		bf_x = x; bf_y = y; bf_t = t;
	}
	cout<<((ok)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int H,W,i,j,n;
  cin >> H;
  cin >> W;

  while(H != 0 && W != 0){
      for(i = 0; i < H; i++){
          for(j = 0; j < W; j++){
              if((i + j) % 2 == 0){
                  cout << "#";
              }
              else{
                  cout << ".";
              }
          }
          cout << endl;
      }
      cin >> H;
      cin >> W;
      cout << endl;
  }
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi cnt(100, 0);
	REP(i, n) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	int d = 0;
	REP(i, cnt.size())if (cnt[i] != 0)d = i;
	bool ok = true;

	FOR(i, (d + 1) / 2 + 1, d + 1) {
		if (cnt[i] < 2)ok = false;
	}
	REP(i, (d + 1) / 2) {
		if (cnt[i] != 0)ok = false;
	}
	if (cnt[(d + 1) / 2] != (d % 2 == 0 ? 1 : 2))ok = false;


	if (ok)cout << "Possible" << endl;
	else cout << "Impossible" << endl;


}


Measured memory_bytes: 256
def f_b():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    s = b[a[0]]
    for i in range(1, n):
        s += b[a[i]]
        if a[i]==a[i-1]+1:
            s += c[a[i-1]]
    print(s)

if __name__ == "__main__":
    f_b()


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

int main(){
    string s, t;
    cin >> s >> t;
    
    int n = s.size();
    int m = t.size();
    int answer = INT_MAX;
    for(int i = 0; i <= n - m; i++){
        int ans = 0;
        for(int j = 0; j < m; j++){
            if(s[i+j] != t[j]){
                ans += 1;
            }
        }
        answer = min(ans, answer);
    }
    
    cout << answer << endl;
    
    return 0;
}


Measured memory_bytes: 3620
using System;

namespace ITP1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] strs = Console.ReadLine().Split(' ');
                int h = int.Parse(strs[0]);
                int w = int.Parse(strs[1]);
                if (h == 0 && w == 0) break;
                for (int i = 0; i < h; i++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 8748
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = [a - 1 for a in A]

ans = B[A[0]]
for i in range(1, N):
    ans += B[A[i]]
    if A[i] == A[i - 1] + 1:
        ans += C[A[i - 1]]

print(ans)


Measured memory_bytes: 8956
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define MAX 100000000000000
#define INF 1000000 
#define M 1000000007
#define Pi 3.14159265 
using namespace std; 
int main(){ 
   FAST
   string s;
   cin>>s;
   ll n = s.length()-1;
   if(s[n] == 's'){
      cout<<s;
      cout<<"es"<<endl;
   }
   else{
      cout<<s;
      cout<<"s"<<endl;
   }
   return 0;
} 

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	ll sum = 0;
	for (size_t i = 1; i <= N; i++)
	{
		if (i % 3 == 0 || i % 5 == 0)
		{
			continue;
		}

		sum += i;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3180