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

int		main(void)
{
	int		a = 0;
	string	S;
	cin >> S;
	for (auto &i : S)
	{
		if (i == '+')
			a++;
		else
			a--;
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int dp[100005];

int main(){
  int N, M;
  cin >> N >> M;
  rep(i,M){
    int L, R;
    cin >> L >> R;

    dp[L]++;
    dp[R+1]--;
  }

  int ret = 0;
  int base = 0;
  rep(i,100005){
    base += dp[i];
    if(base == M) ret++;
  }

  cout << ret << endl;
  
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit);
#define int long long
#define ll long long

 
#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);}
#else
#define trace(...)
#endif
 
auto clk=clock();
const int mod = 1e9+7;

//const int mod = 998244353;


signed main()
{
    IOS;
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(10);

    int n ; 
    cin >> n ; 

    cout << (int)pow(n,(int)3) ; 

 cerr<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl<<endl ;
return 0 ;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,f[105][12],p[105][12],a[12],bst=-INF,v[105],t=1;

vector <int> x;

void Gen(int k){
    if(k==11){
        if(t){
            t=0;
            return;
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            v[i]=0;
            for(int j=1;j<=10;j++){
                if(f[i][j] && a[j]){
                    v[i]++;
                }
            }
        }
        for(int i=1;i<=n;i++) ans+=p[i][v[i]];
        //for(int i=1;i<=10;i++) cout << a[i] << ' ';
        //cout << ans << '\n';
        bst=max(bst,ans);
        return;
    }
    a[k]=0;
    Gen(k+1);
    a[k]=1;
    Gen(k+1);
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=0;j<5;j++){
            for(int k=0;k<2;k++){
                cin >> f[i][j*2+1+k];
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=10;j++) cin >> p[i][j];
    }
    Gen(1);
    cout << bst;
}


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

char s[200000];


int main(){
    ll i=0,ans=0,ws=0;
    scanf("%s",s);
    for(;s[i]!='\0';i++){
        if(s[i]=='W'){
            ans+=i-ws;
            ws++;
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            
            
            String str = Console.ReadLine();
            int n = int.Parse(str);
            int i=1;
            int x;
            while (++i != n + 1)
            {
                x = i;
                if (x % 3 == 0)
                {
                    Console.Write(" " + i);

                }
                else
                {
                    while (x != 0)
                    {



                        if (x % 10 == 3)
                        {
                            Console.Write(" " + i);
                            x = 0;
                        }
                        else
                        {
                            x /= 10;
                        }
                    }



                }


            }

                Console.WriteLine();


            

        }
    }
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> v;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        v.emplace_back(tmp);
    }
    sort(v.begin(), v.end());

    double sum = (double)v[0];
    for (int i = 1; i <= N - 1; i++)
    {
        sum = (sum + (double)v[i]) / 2.0;
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define an size()

using namespace std;
const ll maxn=1e9+7;
ll k[5];
int main()
{
    ll W,H,w,h,s,ans=0;
    cin>>W>>H>>w>>h;
    s=(w*h-1)*4000+1;
    if(W%w==0&&H%h==0)
    {
        cout<<"No";
    }
    else
    {

        for(ll i=1; i<=W; i++)
        {
            for(ll j=1; j<=H; j++)
            {
                if(i%w==0&&j%h==0)
                {
                    ans-=s;
                }
                else
                {
                    ans+=4000;
                }
            }
        }
        if(ans<=0)
        {
            cout<<"No";
        }
        else
        {
            cout<<"Yes\n";
            for(ll i=1; i<=W; i++)
            {
                for(ll j=1; j<=H; j++)
                {
                    if(i%w==0&&j%h==0)
                    {
                        cout<<-s<<' ';
                    }
                    else
                    {
                        cout<<4000<<' ';
                    }
                }
                cout<<endl;
            }
        }
    }

}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

typedef struct
{
    double x;
    double y;
}T_Point;

double calcTriangleArea(T_Point pt1, T_Point pt2, T_Point pt3);

int main()
{
    double in_x;
    double in_y;
    char ch; /* dummy */
    double s = 0;
    vector<T_Point> points;
    while(cin >> in_x >> ch >> in_y)
    {
        T_Point pt;
        pt.x = in_x;
        pt.y = in_y;
        points.push_back(pt);
    }
    for(int i=0; i<points.size()-2; i++)
    {
        s += calcTriangleArea(points[0], points[i + 1], points[i + 2]);
    }
    cout << fixed << std::setprecision(6) << s << endl;
    return 0;
}

double calcTriangleArea(T_Point pt1, T_Point pt2, T_Point pt3)
{
    double a = hypot(pt2.x - pt1.x, pt2.y - pt1.y);
    double b = hypot(pt3.x - pt2.x, pt3.y - pt2.y);
    double c = hypot(pt1.x - pt3.x, pt1.y - pt3.y);
    double z = (a + b + c) / 2;
    return sqrt(z * (z - a) * (z - b) * (z - c));
}



Measured memory_bytes: 3352
h, w = map(int, input().split())
s = []
for i in range(h):
  _s = input()
  if '#' in _s:
    s.append(_s)
    
deletes = []
for j in range(w):
  for i in range(len(s)):
    if s[i][j] == '#':
      break
  else:
    deletes.append(j)
    
for i in range(len(s)):
  out = ''
  for j in range(len(s[i])):
    if not j in deletes:
      out += s[i][j]
  print(out)
  

Measured memory_bytes: 3064
use std::io::Read;

fn main() {
    let mut base = 700;
    let topping = 100;
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let splited: Vec<_> = buf.split("").collect();

    for order in splited {
        match order {
            "o" => base += topping,
            _ => {}
        };
    }
    println!("{}", base);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x,z;
  cin >>x;
  n=x/1000;
  n=n*1000;
  z=x-n;
  if(z==0){
    cout<<z;
  }else{
    z=1000-z;
    cout <<z;
  }
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Integer, Boolean>[] a = new Map[n];
        for(int i=0; i<n; i++) {
            Map<Integer, Boolean> ai = new HashMap<>();
            int count = in.nextInt();
            for(int j=0; j<count; j++) {
                int x = in.nextInt() - 1;
                boolean y = in.nextInt() == 1;
                ai.put(x, y);
            }
            a[i] = ai;
        }
        int max = 0;
        int two_pow_n = (int)Math.pow(2, n);
        for(int assume=0; assume<two_pow_n; assume++) {
            int honestCount = Integer.toString(assume, 2).replaceAll("0", "").length();
            if(honestCount <= max) {
                continue;
            }
            if(isValid(n, a, assume)) {
                max = honestCount;
            }
        }
        System.out.println(max);
    }
    private static boolean isValid(int n, Map<Integer, Boolean>[] a, int assume) {
        for(int i=0; i<n; i++) {
            if((assume & (1<<i)) == 0) {
                continue;
            }
            Map<Integer, Boolean> ai = a[i];
            Set<Integer> keySet = ai.keySet();
            Iterator<Integer> it = keySet.iterator();
            while(it.hasNext()) {
                int x = it.next();
                boolean y = ai.get(x);
                int assumption = (assume & (1<<x));
                if(y && assumption > 0) {
                    // valid
                }
                else if(!y && assumption == 0) {
                    // valid
                }
                else {
                    return false;
                }
            }
        }
        return true;
    }
}


Measured memory_bytes: 47292
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC129
{
    class Program
    {
        static void Main(string[] args)
        {
            var pqr = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).Take(2).ToArray();
            Console.WriteLine(pqr.Sum());


        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define MIN(a,b) ((a)<(b)?(a):(b))
#include <math.h>

int main(void) {
   double n;
   double minimum = 1000000000000001L;
   double L[5];
   cin >> n;
   for (int i = 0; i < 5; i++) {
      cin >> L[i];
      minimum = MIN(minimum, L[i]);
   }
   printf("%lld\n",(long long)ceil(n/minimum)+4);

   return 0;

}


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

int main() {
    int K;  cin >> K;
    long long a = 7;
    for (int i = 1; i <= K; ++i) {
        if (a % K == 0) {
            cout << i << endl;
            return 0;
        }
        else a = (10 * a + 7) % K;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3636
import collections

n = int(input())
s_n = [input() for i in range(n)]
c = collections.Counter(s_n).most_common()

ans = []
for index, s in enumerate(c):

    if index == 0:
        ans.append(s[0])
    elif c[index][1] == c[index-1][1]:
        ans.append(s[0])
    else:
        break
for result in sorted(ans):
    print(result)

Measured memory_bytes: 45040
// No.074901032320
#include <bits/stdc++.h>
#define N 100100
using namespace std;
const int Mod = 998244353;

int n, m, vis[N], sg[N], f[3][N], mx, pw[N];
vector<int> G[N];

int main() {
#ifdef isLOCAL
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    cin >> n;

    int base = 1000000000000000000ll % Mod;
    for (int i = pw[0] = 1; i <= n; ++i)
        pw[i] = 1ll * pw[i - 1] * base % Mod;

    for (int g = 0; g < 3; ++g) {
        cin >> m;
        for (int i = 1; i <= n; ++i) G[i].clear();
        for (int i = 1, u, v; i <= m; ++i) {
            scanf("%d%d", &u, &v);
            if (u > v) swap(u, v);
            G[u].push_back(v);
        }
        for (int i = n; i >= 1; --i) {
            for (int v : G[i])
                vis[sg[v]]++;
            sg[i] = 0;
            while (vis[sg[i]]) ++sg[i];
            for (int v : G[i])
                vis[sg[v]]--;
            mx = max(mx, sg[i]);
            f[g][sg[i]] = (f[g][sg[i]] + pw[i]) % Mod;
        }
    }
    
    long long ans = 0;
    for (int i = 0; i <= mx; ++i)
        for (int j = 0; j <= mx; ++j)
            ans = (ans + 1ll * f[0][i] * f[1][j] % Mod * f[2][i xor j]) % Mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num =sc.nextInt();
		String str =sc.next();
		
		if(str.length()>num)
			System.out.println(str.substring(0, num)+"...");
		else
			System.out.println(str);

	}

}

Measured memory_bytes: 27076
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int N, C, K, ans = 0, bus, ppl;
	cin >> N >> C >> K;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	sort(T.begin(),T.end());
	int n = 0;
	while(N != n){
		bus = T[n] + K;
		ppl = 0;
		for(int i = n;; i++){
			if (T[i] > bus || n == N || ppl == C) break;
			else{
				ppl++;
				n++;
			}
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
n,p = map(int,input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

li = factorization(p) 
#print(li)

tmp_score = 1
for l in li:
    if l[1]>= n:
        kaisu = l[1]//n
        tmp_score *= l[0]**kaisu
print(tmp_score)


Measured memory_bytes: 3064
<?php
define('NUMBER_OF_ROOM_OF_FLOOR',10);
define('SCHOOL_BUILDING_HEIGHT',3);
define('SCHOOL_BUILDING_NUMBER',4);
$array_num = intval(trim(fgets(STDIN)));

for ($i = 0; $i < $array_num; $i++){
    $infos[$i] = preg_split("/[\s,]+/",trim(fgets(STDIN)));
    for ($j = 0; $j < count($infos[$i]); $j++) {
        $infos[$i][$j]=intval($infos[$i][$j]);
    }
}

$buildings = array();
for ($s = 0;$s < SCHOOL_BUILDING_HEIGHT; $s++){
    $building[] = array_fill(0, NUMBER_OF_ROOM_OF_FLOOR, 0);
}
for ($r = 0;$r < SCHOOL_BUILDING_NUMBER; $r++){
    $buildings[] = $building;
}
foreach ($infos as $info) {
    $buildings[$info[0]-1][$info[1]-1][$info[2]-1] += $info[3];
}
$count = 0;
foreach ($buildings as $building) {
    $count++;
    foreach ($building as $floor) {
        foreach ($floor as $room) {
            echo " ".$room;
        }
        echo "\n";
    }
    if ($count === SCHOOL_BUILDING_NUMBER) {
    }else {
        echo "####################";
        echo "\n";
    }
}

Measured memory_bytes: 15888
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	ll k;
	cin >> n >> k;
	
	vector<ll> cnt(1e5 + 1, 0);
	for(int i = 0; i < n; ++i) {
		ll a, b;
		cin >> a >> b;
		cnt[a] += b;
	}
	
	int ans = 0LL;
	for(int i = 1; i <= 1e5; ++i) {
		if( cnt[i] >= k ) {
			ans = i;
			break;
		}
		
		k -= cnt[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] A = new String[H];
        char[][] a = new char[H][W];
        for (int i = 0; i < H; i++) {
            A[i] = sc.next();
        }
        for (int i = 0; i < H; i++) {
            a[i] = A[i].toCharArray();
        }
        int c=0;
        for (int i = 0; i < H ; i++) {
            for (int j = 0; j < W; j++) {
                if (a[i][j] == '#') {
                    c++;
                }
            }
        }
        System.out.println(c==H+W-1?"Possible":"Impossible");
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

struct number
{
	int a;
	int b;
};

bool compare(number a, number b)
{
	return a.a < b.a;
}

int N[201000], dp[201000];
number num[201000];

int main ()
{
	int n;
	cin >> n;
	
	if(n == 1)
	{
		cout << "0" << endl;
		return 0;
	}
	
	for(int i = 0; i < 201000; i++)
	{
		N[i] = 0;
		dp[i] = 1;
		num[i].a = 0;
		num[i].b = 0;
	}
	
	int x;
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &x);
		N[i] = x;
		num[i].a = x;
		num[i].b = i;
	}
	
	sort(num, num + n, compare);
	
//	for(int i = 0; i < n; i++)
//		cout << num[i].a << " " << num[i].b << endl;
	
	int max = 0;
	for(int i = 1; i < n; i++)
	{
		if(num[i].b > num[i - 1].b)
			dp[i] = dp[i - 1] + 1;
		
		if(dp[i] > max)
			max = dp[i];
	}
	
	cout << n - max << endl;
	
	return 0;
}

Measured memory_bytes: 3456
def d():
    n, k = map(int, input().split())
    combination = [0] * (n+2)
    min = [0] * (n+2)
    max = [0] * (n+2)
    # print(min, max)

    # i個選ぶ場合、その合計値のパターン: 最大値〜最小値が1つずつ生成できるからそれ
    # min: 0, 1, 2, ..., i-1
    # max: n, n-1, n-2, ..., n+1-i
    for i in range(1, n+2):
        max[i] = max[i-1] + n+1-i
        min[i] = min[i-1] + i-1
        combination[i] = max[i] - min[i] + 1
        # print('i, min_i, max_i, cmb_i', i, min[i], max[i], combination[i])
        # print(min, max)

    mod = 10**9 + 7
    print(sum(combination[k:n+2]) % mod)


##########
if __name__ == "__main__":
    d()


Measured memory_bytes: 37136
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 998244353;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
struct mi {
	ll v; explicit operator ll() const { return v; }
	mi() { v = 0; }
	mi(ll _v) { 
		v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
		if (v < 0) v += MOD;
	}
	friend bool operator==(const mi& a, const mi& b) { 
		return a.v == b.v; }
	friend bool operator!=(const mi& a, const mi& b) { 
		return !(a == b); }
	friend bool operator<(const mi& a, const mi& b) { 
		return a.v < b.v; }
   
	mi& operator+=(const mi& m) { 
		if ((v += m.v) >= MOD) v -= MOD; 
		return *this; }
	mi& operator-=(const mi& m) { 
		if ((v -= m.v) < 0) v += MOD; 
		return *this; }
	mi& operator*=(const mi& m) { 
		v = v*m.v%MOD; return *this; }
	mi& operator/=(const mi& m) { return (*this) *= inv(m); }
	friend mi pow(mi a, ll p) {
		mi ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	friend mi inv(const mi& a) { assert(a.v != 0); 
		return pow(a,MOD-2); }
		
	mi operator-() const { return mi(-v); }
	mi& operator++() { return *this += 1; }
	mi& operator--() { return *this -= 1; }
	friend mi operator+(mi a, const mi& b) { return a += b; }
	friend mi operator-(mi a, const mi& b) { return a -= b; }
	friend mi operator*(mi a, const mi& b) { return a *= b; }
	friend mi operator/(mi a, const mi& b) { return a /= b; }
    friend ostream& operator<<(ostream& os, const mi& m) {
        os << m.v; return os;
    }
    friend istream& operator>>(istream& is, mi& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};
 
 
typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, S; cin >> N >> S;
    mi dp[N+1][S+1];
    F0R(i, N+1) F0R(j, S+1) dp[i][j] = 0;
    dp[0][0] = pow((mi) 2, N);
    int A[N]; F0R(i, N) cin >> A[i];
    mi inv2 = 2; inv2 = inv(inv2);
    F0R(i, N) {
        F0R(j, S+1) {
            dp[i+1][j] += dp[i][j];
            if (j + A[i] <= S) {
                dp[i+1][j+A[i]] += dp[i][j] * inv2;
            }
        }
    }
 
    cout << dp[N][S] << endl;
	return 0;
}

Measured memory_bytes: 74020
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

void hoge(int n, int p) {
	vector<int> a(n);
	int _p = p;
	for (;;)
		for (int i = 0; i < n; i++) {
			if (p > 0) { p--; a[i]++; }
			else { p += a[i]; a[i] = 0; }
			if (a[i] == _p) {
				cout << i << endl;
				return;
			}
		}
}

int main() {
	for (;;) {
		int n, p; cin >> n >> p;
		if (n == 0 && p == 0) break;
		hoge(n, p);
	}
}

Measured memory_bytes: 1192
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, x = LI()
a = LI()
ans = 0
for i in range(n):
    if a[i] > x:
        ans += a[i] - x
        a[i] = x
    if i < n-1:
        if a[i] + a[i+1] > x:
            ans += (a[i] + a[i+1]) - x
            a[i+1] = x - a[i]
print(ans)

Measured memory_bytes: 59632
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}
int main() {
    int n, q;
    int t, x, s;
    cin >> n >> q;
    vector<priority_queue<int>> pq(n);
    for (int i = 0; i < q; i++){
        cin >> t;
        if (t == 0){
            cin >> s >> x;
            pq[s].push(x);
        }else if (t == 1){
            cin >> s;
            if (!pq[s].empty()){
                cout << pq[s].top() << endl;
            }
        }else{
            cin >> s;
            if (!pq[s].empty()){
                pq[s].pop();
            }
        }
    }
}


Measured memory_bytes: 4008
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define EPS (1e-7)
#define IINF ((int)1e9)


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

	int n;
	cin >> n;
	vector<char> altar(n);
	for (int i = 0; i < n; i++)
	{
		cin >> altar[i];
	}

	int most_left_white = 0;
	int most_right_red = n-1;
	int res = 0;
	while (most_left_white < most_right_red)
	{
		while (most_left_white < n && altar[most_left_white] == 'R')
		{
			most_left_white++;
		}
		while (most_right_red >= 0 && altar[most_right_red] == 'W')
		{
			most_right_red--;
		}
		if (most_right_red >= 0 && most_left_white < n && most_left_white < most_right_red)
		{
			altar[most_left_white] = 'R';
			altar[most_right_red] = 'W';
			res++;
		}
	}
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 3636
from collections import defaultdict

V, E = map(int, input().split())
G = defaultdict(list)

for i in range(E):
    s, t = map(int, input().split())
    G[s].append(t)

visited = None
p = None
def dfs(v):
    visited[v] = True
    for k in G[v]:
        if k == p:
            print(1)
            exit()
        if not visited[k]: dfs(k)

for v in range(V):
    p = v
    visited = defaultdict(bool)
    dfs(v)
print(0)



Measured memory_bytes: 6000
#include<stdio.h>

int main(){
    int n, p[50+5];
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &p[i]);
    }
    for (int i = 0; i < n; i++){
        if(p[i]!=i+1){    // 中身と添字が一致しない
            if(p[p[i]-1]==i+1){
                p[p[i]-1]=p[i];
                p[i]=i+1;
                break;
            }
        }
    }
    for (int i = 0; i < n; i++){
        if(p[i]!=i+1){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int M;
	cin >> M;

	Int sum_dc = 0;
	Int sum_c = 0;

	Int d, c;
	for (Int i = 0; i < M; i++) {
		cin >> d >> c;
		sum_c += c;
		sum_dc += c * d;
	}

	cout << (sum_c-1)+(sum_dc-1)/9 << "\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

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

  int cnt = 0;
  int num = 0;
  while(true){
    if(b == 1){
      break;
    }
    num = ( a - 1 ) * cnt + 1;
    if(num >= b){
      break;
    }
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import numpy as np
import sys
input = sys.stdin.readline

def main():
    N, A = map(int, input().split())
    x = np.array(list(map(int, input().split())))
    X = max(A, max(x))
    x -= A
    # print(x)
    dp = np.zeros((N+1, 2*N*X+1), dtype=int)
    # 初期化
    dp[0][N*X] = 1
    for i in range(N):
        dp[i+1] += dp[i]
        if x[i] > 0:
            dp[i+1][x[i]:] += dp[i][:-x[i]]
        elif x[i] < 0:
            dp[i+1][:x[i]] += dp[i][-x[i]:]
        else:
            dp[i+1] += dp[i]
    
    # print(dp[:, N*X-5:N*X+5])
    # print(x)
    print(dp[-1][N*X] - 1)

if __name__ == "__main__":
    main()

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)



int main(){
    ll a,b;

    cin>>a>>b;

    ll Aa,Ba;
    ll ans;
    int j=0;
    for(int i=1;i<=1250;i++){
        Aa = i*0.08;
        Ba = i*0.1;
        if(Aa==a&&Ba==b){
            j=1;
            ans = i;
            break;
        }
    }

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



}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    long n,a,b;
    long sum;
    long x,amari;
    long ans = 0;
    
    scanf("%ld %ld %ld",&n,&a,&b);
    sum = a+b;
    if(n == 0 || sum == 0){
        printf("0\n");
        return 0;
    }
    x = n/sum;
    amari = n % sum;
    
    if(sum >= n){
        if(n <= a){
            printf("%ld\n",n);
            return 0;
        }else{
            printf("%ld\n",a);
            return 0;
        }
    }else{
        ans = a*x;
    }
    
    if(amari > a){
        ans += a;
    }else{
        ans += amari;
    }
    printf("%ld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll K,t;
ll a[100];

int main(){
	cin >> K >> t;
	ll MAX = 0;
	rep(i,t){
		cin >> a[i];
		MAX = max(MAX,a[i]);
	}
	K -= MAX;
	cout << max((ll)0, MAX - (K+1)) << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define rep_(i, m, n) for(int i = m; i < n; i++)
#define inf 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){

  bool ans = true;
  
  ll n;cin >> n;

  rep(i,n){
    int a;cin >> a;
    if(a%2 == 0){
      if( (a%3 != 0 ) && (a%5 != 0))ans = false;
    }
  }

  if(ans)printf("APPROVED");
  else printf("DENIED");

}


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

int main() {
  int N, K, d;
  cin >> N >> K;
  bool D[10];
  fill(D, D+10, true);
  for (int i=0; i<K; i++) {
    cin >> d;
    D[d] = false;
  }
  int i;
  for (i=N; ;i++) {
    int m = i;
    while (m != 0) {
      if (!D[m%10])
        break;
      m /= 10;
    }
    if (m == 0)
      break;
  }
  cout << i << endl;
  return 0;
}


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

int main(){
	int a,b;
	cin >> a >> b;
	
	if(a <= 5) cout << 0 << endl;
	else if(6 <= a && a <= 12) cout << b/2 << endl;
	else cout << b << endl;
	
	return 0;
}

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

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int ans = (n / 100) + (n % 100) / 10 + (n % 10);
    cout << ans << endl;
    
}

Measured memory_bytes: 256
// Shift-JIS（シフトジス）

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

int gcd(long long a, long long b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    long long N;
    cin >> N;
    long long A[N + 1], B[N];
    long long num, M = 0;
    for (int i = 0; i < N + 1; i++)
    {
        cin >> num;
        M += num;
        A[i] = num;
    }
    for (int i = 0; i < N; i++)
    {
        cin >> num;
        B[i] = num;
    }

    for (int i = 0; i < N; i++)
    {
        if (A[i] >= B[i])
        {
            A[i] -= B[i];
            B[i] = 0;
        }
        else
        {
            B[i] -= A[i];
            A[i] = 0;
        }
        if (A[i + 1] >= B[i])
        {
            A[i + 1] -= B[i];
            B[i] = 0;
        }
        else
        {
            B[i] -= A[i + 1];
            A[i + 1] = 0;
        }
    }

    long long ML = 0;
    for (int i = 0; i < N + 1; i++)
    {
        ML += A[i];
    }

    cout << M - ML << endl;

}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{
  public static void main(String[] args)
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    ArrayList<Integer> inputList = new ArrayList<>(50);

    try
    {
      while (input.ready())
      {
        inputList.add(Integer.valueOf(input.readLine()));
      }
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }

    for (int num : inputList)
    {
      System.out.println(getLowerPrimeNumber(num) + " " + getHigherPrimeNumber(num));
    }
  }

  private static int getLowerPrimeNumber(int number)
  {
    for (int i = number - 1; i > 3; i--)
    {
      if (isPrimeNumber(i))
      {
        return i;
      }
    }
    return 2;
  }

  private static int getHigherPrimeNumber(int number)
  {
    for (int i = number + 1; i < Integer.MAX_VALUE; i++)
    {
      if (isPrimeNumber(i))
      {
        return i;
      }
    }
    return 2;
  }

  public static ArrayList<Integer> getPrimeNumberList(int maxNumber)
  {
    ArrayList<Integer> primeNumberList = new ArrayList<>();
    primeNumberList.add(2);
    primeNumberList.add(3);
    primeNumberList.add(5);
    primeNumberList.add(7);

    int[] oneDigitList =
    { 1, 3, 7, 9 };

    int tmp;
    int sqrtTmp;
    boolean addFlag;
    for (int i = 10; i <= maxNumber; i += 10)
    {
      for (int oneDigit : oneDigitList)
      {
        addFlag = true;
        tmp = i + oneDigit;
        sqrtTmp = (int) Math.sqrt(tmp);
        for (int primeNumber : primeNumberList)
        {
          if (tmp % primeNumber == 0)
          {
            addFlag = false;
            break;
          }
          if (sqrtTmp < primeNumber)
          {
            break;
          }
        }
        if (addFlag)
        {
          primeNumberList.add(tmp);
        }
      }
    }
    return primeNumberList;
  }

  private static boolean isPrimeNumber(int number)
  {
    if (number % 2 == 0)
    {
      return false;
    }

    final int limit = (int) Math.sqrt(number);
    for (int i = 3; i <= limit; i++)
    {
      if (number % i == 0)
        return false;

    }

    return true;
  }
}

Measured memory_bytes: 24064
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
bool pairComparesecond(const p& firstElof, const p& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main(){
	string s;
	cin>>s;
	int x=s.size();
	int ans=s.size();
	rep(i,1,s.size()){
		if(s[i-1]!=s[i]){
			ans=min(ans,max(i,x-i));
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B;
  cin>>A>>B;
  
  vector<int> check(90000);
  for(int i=0;i<90000;i++){
    check[i]=i+10000;
    string num=to_string(check[i]);
    char a_1,a_2,a_4,a_5;
    a_1=num[0];
    a_2=num[1];
    a_4=num[3];
    a_5=num[4];
    if(a_1!=a_5||a_2!=a_4){
      check[i]=0;
    }
  }
  
  int ans=0;
  
  
  for(int i=0;i<90000;i++){
    if(A<=check[i]&&check[i]<=B){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}

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

int main() {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  for (int i = 0; i < n; i++) {
    string si;
    cin >> si;
    if(si == "AC") ac++;
    else if(si == "WA") wa++;
    else if(si == "TLE") tle++;
    else if(si == "RE") re++;
  }
  printf("AC x %d\n", ac);
  printf("WA x %d\n", wa);
  printf("TLE x %d\n", tle);
  printf("RE x %d\n", re);
}

Measured memory_bytes: 3724
$n=<>;
@a=(2);
for($i=7;$#a+1<$n;$i+=10){
    $p=1;
    for($d=3;$d<$i;$d+=2){
        $p=0,last if($i%$d==0);
    }
    push(@a,$i) if($p)
}
$,=" ";
print @a

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

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

    int N;
    cin >> N;

    map<string, int> votes;
    rep(i, N) {
        string input;
        cin >> input;
        if (votes.find(input) != votes.end()) {
            votes[input]++;
        } else {
            votes[input] = 1;
        }
    }

    int max_count = 0;
    for (auto vote : votes) {
        max_count = max(max_count, vote.second);
    }

    vector<string> names;
    for (auto vote : votes) {
        if (vote.second == max_count) {
            names.push_back(vote.first);
        }
    }

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

    for (auto name : names) {
        cout << name << endl;
    }
}


Measured memory_bytes: 25584
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

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

    if( max(a,c)<min(b,d) ){
        cout << min(b,d)-max(a,c) << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H) printf("Yes\n");
else printf("No\n");
return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    double p[n+1],dp[n+1][n+2] = {0},ans=0;
    int gap = n - (n/2);
    for(int i = 1; i <= n; i++)
        cin>>p[i];
    for(int j = 0; j <= n; j++) {
        for(int i = 0; i <= n; i++) {
            if(i == 0) 
                dp[i][j] = 1;
            else if(j == 0 && i == 1)
                dp[i][j] = 1 - p[1];
            else if(j == 1 && i == 1)
                dp[i][j] = p[1];
            else {
                if(i - j <= gap && j <= i) {
                    if(i >= 1)
                        dp[i][j] += dp[i-1][j]*(1-p[i]);
                    if(j >= 1)
                        dp[i][j] += dp[i-1][j-1]*p[i];
                    //dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
                }
            }
            //if(i)
                //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    for(int i = n; i > n/2; i--)
        ans += dp[n][i];
    cout<<setprecision(9)<<ans<<endl;
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a*n, b) << endl;
    return 0;
}

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

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

const long long INF = 1LL << 60;
const long long div_n = 1000000007;

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

    vector<int> a(M+1, -2);
    rep(i, M) cin >> a.at(i);

    vector<ll> dp(N+5, -1);
    dp.at(0) = 1;
    dp.at(1) = 1;

    ll tmp = a.at(0);
    ll cnt = 0;

    rep(i, M){
        if(a.at(i+1) == a.at(i) + 1){
            cout << 0 << endl;
            return 0;
        }
    }

    rep(i, N){
        if(i == tmp){
            ++cnt;
            tmp = a.at(cnt);
            chmax(dp.at(i+2), dp.at(i+1));
        }
        else if(i+1 == tmp){
            chmax(dp.at(i+2), dp.at(i));
        }
        else{
            chmax(dp.at(i+2), dp.at(i)%div_n+dp.at(i+1)%div_n);
        }
    }

    cout << dp.at(N)%div_n << endl;

}


Measured memory_bytes: 1408
N,L = map(int,input().split())

A = [L+i-1 for i in range(1,N+1)]

ap = float("inf")

for a in A :
    if ap > abs(a) :
        ap = abs(a)

applepie = sum(A)


if abs(applepie-ap) < abs(applepie+ap) :
    ans = applepie-ap
else :
    ans = applepie+ap


#ans = min(applepie - ap, applepie + ap)


print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] w = new int[n];
        int sum = 0;
        for (int i = 0 ;i < n ; i++) {
            w[i] = sc.nextInt();
            sum += w[i];
        }

        int s = 100000000;
        for (int i = 0 ; i < n  ; i++) {
            int b = 0;
            for (int j = 0 ; j < i ; j++) {
                b += w[j];
            }

            s = Math.min(s, Math.abs(sum - b - b));
        }

        System.out.println(s);
    }

}

Measured memory_bytes: 22228
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  
  int X;
  cin >> X;
  
  int m[N];
  for(int i = 0;i <N;i++){
	cin >> m[i];
  }
  
  sort(m,m+N);
  
  for(int i=0;i <N;i++){
	 X = X - m[i];
  }
  
  cout << N +(X/m[0]) << endl;
  
  return 0;
}

Measured memory_bytes: 256
# @oj:atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-20 10:31
# @url:https://atcoder.jp/contests/dp/tasks/dp_b
import sys
def input():
    return sys.stdin.readline().strip()

def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])

    for i in range(2,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
        # for j in range(max(0,i-k),i):
        #     dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])

    print (dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 13980
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N; cin >> N;
  REP(t,N){
	int a[10]; REP(i,10) cin >> a[i];
	bool flag = true;
	vector<bool> used(10, false);
	int p = -1;
	for(int i=0;i<10;++i)
	  if(p < a[i]){
		p = a[i];
		used[i] = true;
	  }
	p = -1;
	for(int i=0;i<10;++i)
	  if(!used[i])
		if(p < a[i])
		  p = a[i];
		else
		  flag = false;
	
	cout << (flag? "YES": "NO") << endl;
  }
  
  return 0;
}

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}


int main() {
  string S;
  cin >> S;
  reverse(S.begin(),S.end());
  int N=S.size();
  vector<ll> memo(2020,0);
  ll tmp = 0,cnt=1;
  rep(i,N) {
    auto t = S[i] - '0';
    
    tmp =(t*cnt+tmp)%2019;
    cnt = cnt*10%2019;
    memo[tmp]++;
    // cout << tmp << endl;
  }
  ll ans=memo[0];
  rep(i,2020) {
    ans += memo[i]*(memo[i]-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string s;
  cin >> s;
  if (s == "RRR") cout << 3 << endl;
  else if (s == "RRS" || s == "SRR") cout << 2 << endl;
  else if (s == "SSS") cout << 0 << endl;
  else cout << 1 << endl;

  return 0;
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int len(ll n){
    stringstream ss;
    ss<<n;
    return ss.str().size();
}

int main(){
    ll n;
    cin>>n;
    ll f = -1;
    for(ll i=sqrt(n)+1;i>=0;i--){
        if(n%i==0){
            f=i;
            break;
        }
    }
    
    cout<<max( len(f) , len(n/f) )<<endl;
}

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

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

    int a, b, c, d;
    a = N/1000;
    b = (N-a*1000)/100;
    c = (N-a*1000-b*100)/10;
    d = (N-a*1000-b*100-c*10);
    if (b == c){
        if (a == b || c == d){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
    int ans = 0;
    int N, X, T;
    cin >> N >> X >> T;
    ans = (N + X - 1) / X;
    ans = ans * T;

    cout << ans << endl;
}

Measured memory_bytes: 3628
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: One Card Poker
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (a == 1) a = 14;
  if (b == 1) b = 14;

  if (a > b) puts("Alice");
  else if (a < b) puts("Bob");
  else puts("Draw");
  return 0;
}


Measured memory_bytes: 256