akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  string s, t;
  cin >> s >> t;

  vector<vector<int>> lcs(s.length() + 1, vector<int>(t.length() + 1, 0));

  REP(i, s.length())
  REP(j, t.length())
  {
    lcs[i + 1][j + 1] = (s[i] == t[j]) ? lcs[i][j] + 1 : max(lcs[i][j + 1], lcs[i + 1][j]);
  }

  int i, j;
  i = s.length();
  j = t.length();

  if (lcs[i][j] == 0)
  {
    cout << "" << endl;
    return 0;
  }

  string result = "";
  while (i > 0 && j > 0)
  {
    if (s[i - 1] == t[j - 1])
    {
      result = s[i - 1] + result;
      i--;
      j--;
    }
    else
    {
      if (lcs[i - 1][j] > lcs[i][j - 1])
        i--;
      else
        j--;
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N;cin>>N;
    vector<string> s(N);
    REP(i,N)cin>>s[i];
    for(int i=0;i<N-1;i++){
        if(s[i][s[i].size()-1]!=s[i+1][0]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    sort(All(s));
    for(int i=0;i<N-1;i++){
        if(s[i]==s[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

A,op,B = input().split()
if str(op) == "+":
    print(int(A)+int(B))
else:
    print(int(A)-int(B))

Measured memory_bytes: 5452
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int**dp;

void func(int N,int C){
	int beat[N][16],push[C][16];

	int maximum = 0;

	for(int i = 0; i < N; i++){
		for(int k = 0; k < 16; k++)scanf("%d",&beat[i][k]);
	}

	for(int i = 0; i < C; i++){
		for(int k = 0; k < 16; k++)scanf("%d",&push[i][k]);
	}

	int tmp,S,code;

	int work[C][16];

	S = 1;
	code = 0;
	for(int i = 0; i < 16; i++){
		code += S*beat[0][i];
		S *= 2;
	}
	dp[1][code] = 0;


	for(int k = 0; k < C; k++){
		tmp = 0;
		for(int p = 0; p < 16; p++){
			work[k][p] = beat[0][p];
			if(work[k][p] == 1){
				if(push[k][p] == 1){
					work[k][p] = 0;
					tmp++;
				}
			}
		}

		S = 1;
		code = 0;
		for(int i = 0; i < 16; i++){
			code += S*work[k][i];
			S *= 2;
		}
		dp[1][code] = max(dp[1][code],tmp);
		maximum = max(maximum,dp[1][code]);
	}

	for(int i = 1; i < N; i++){
		for(int state = 0; state < 65536; state++){
			if(dp[i][state] != -1){

				S = 1;
				code = 0;
				for(int loop = 0; loop < 16; loop++){
					if(state & (1 << loop)){
						code += S;
					}else{
						code += S*beat[i][loop];
					}
					S *= 2;
				}
				dp[i+1][code] = dp[i][state];

				for(int k = 0; k < C; k++){
					tmp = 0;
					for(int p = 0; p < 16; p++){
						if(state & (1 << p)){
							if(push[k][p] == 1){
								work[k][p] = 0;
								tmp++;
							}else{
								work[k][p] = 1;
							}

						}else{
							work[k][p] = beat[i][p];
							if(work[k][p] == 1){
								if(push[k][p] == 1){
									work[k][p] = 0;
									tmp++;
								}
							}
						}
					}

					S = 1;
					code = 0;
					for(int a = 0; a < 16; a++){
						code += S*work[k][a];
						S *= 2;
					}
					dp[i+1][code] = max(dp[i+1][code],tmp+dp[i][state]);
				}
			}
		}
	}

	for(int i = 0; i < 65536; i++)maximum = max(maximum,dp[N][i]);

	printf("%d\n",maximum);
}

int main(){

	int N,C;
	dp = new int*[31];
	for(int i = 0; i < 31; i++){
		dp[i] = new int[65536];
	}

	while(true){
		scanf("%d %d",&N,&C);
		if(N == 0 && C == 0)break;

		for(int i = 0; i <= N; i++){
			for(int k = 0; k < 65536; k++)dp[i][k] = -1;
		}

		func(N,C);
	}

    return 0;
}

Measured memory_bytes: 10828
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x , y , c = 0 , a = 0;
    cin >> x >> y;
    c = x;
    while( c <= y ) {
        c *= 2;
        a++;
    }
    cout << a;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

string s;

int main() {
    cin >> s;

    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
        

    return 0;
}


Measured memory_bytes: 3096
def resolve():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    A = sorted(a)
    count = 0
    ans = 0
    for i in A:
        if count < x:
            count += i
            ans += 1
    if count > x:
        ans -= 1
    if sum(A) < x:
        ans -= 1
    print(ans)
resolve()

Measured memory_bytes: 9112
#N,X,T=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
h=A[0]
ans=0

for i in range(1,N):
    if h>A[i]:
        ans+=(h-A[i])
    elif h<A[i]:
        h=A[i]

print(ans)

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

int main() {
  int a, b;
  cin >> a >> b;
  
  bool ok = true;;
  for (int i = 0; i < a+b+1; i++) {
    char c;
    cin >> c;
    if (i == a && c != '-') {ok = false;}
    if (i != a && c == '-') {ok = false;}
  }
  
  if (ok) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> num(60, 0);
    REP(i, n){
        cin >> a[i];
        REP(j, 60){
            num[j] += (a[i]>>j)&1;
        }
    }
    ll ans = 0;
    ll p = 1;
    REP(i, 60){
        ans = (ans + (num[i]*(n-num[i]))%MOD*p) % MOD;
        p = (p * 2) % MOD;
    }


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

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int A, B, ans1, ans2;
	cin >> A >> B;
	
	ans1 = A/0.08;
	while(ans1*0.08 < A) ++ans1;
	
	ans2 = B/0.1;
	while(ans2*0.1 < B) ++ans2;
	
	ans1 = max(ans1, ans2);
	ans2 = max(ans1, ans2);
	
	while((int)(ans1*0.08) <A || (int)(ans2*0.1) < B){
		++ans1;
		++ans2;
	}
	
	if((int)(ans1*0.08) ==A && (int)(ans2*0.1) == B) cout << ans1;
	else cout << -1;

}


Measured memory_bytes: 256
import bisect

S = input()
T = input()

idx = {}
for i, s in enumerate(S):
    if s in idx.keys():
        idx[s].append(i + 1)
    else:
        idx[s] = [i + 1]

x = 0
current = 0
impossible = 0
for i, t in enumerate(T):
    if t in idx.keys():
        idx_list = idx[t]
        j = bisect.bisect_right(idx_list, current)
        if j < len(idx_list):
            current = idx_list[j]
        else:
            x += 1
            current = idx_list[0]
    else:
        impossible = 1
        break

if impossible:
    print(-1)
else:
    print(x * len(S) + current)


Measured memory_bytes: 48860
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import heapq as hq
gcd = math.gcd
t = ni()

def f1(a2):#a2:2次元配列
    a2.sort(key=lambda x:x[1])
    l = len(a2)
    que = []
    ret = 0
    for dif,k in a2:
        if len(que) < k: #k番目までが空いていれば
            ret +=dif
            hq.heappush(que,dif)
        else:
            if que[0] < dif:#差分が得なら
                ret += dif - que[0]
                hq.heappushpop(que,dif)
    return ret
def f2(a2,n):#a2:2次元配列
    a2.sort(key=lambda x:x[1],reverse=True)
    l = len(a2)
    que = []
    ret = 0
    for dif,k in a2:
        if len(que) + k < n: #k+1番目以降が空いていれば
            ret +=dif
            hq.heappush(que,dif)
        else:
            if que and que[0] < dif:#差分が得なら
                ret += dif - que[0]
                hq.heappushpop(que,dif)
    return ret

def solve(n):
    dp = [] ## rが大きい
    dm = [] ## lが大きい
    ans = 0
    for i in range(n):
        k,l,r = ma()
        if r-l >0:#右ぞろえ,rが得
            dp.append((r-l,k))
        else:#左揃え
            dm.append((l-r,k))
        ans +=min(r,l) ##最低値

    #print(ans);print(dp,f2(dp,n));print(dm,f1(dm))
    ans += f2(dp,n) + f1(dm)

    return ans
for i in range(t):
    n = ni()
    print(solve(n))


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

int main(){
  ll k, q;
  scanf("%lld %lld",&k,&q);
  ll ans[q], d[k], dm[k];
  rep(i,k) scanf("%lld",&d[i]);
  ll n, x, m, s, f;
  rep(i,q) {
    scanf("%lld %lld %lld",&n,&x,&m);
    s = 0, f = x;
    rep(j,k) {
      dm[j] = d[j] % m;
      if(dm[j] == 0) dm[j] = m;
      s += dm[j];
    }
    f += s * ((n-1) / k);
    int p = (n-1) % k;
    rep(j,p) f += dm[j];
    ans[i] = n - 1 - (f / m - x / m);
  }
  for(auto t : ans) printf("%lld\n",t);
  return 0;
}

Measured memory_bytes: 384
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }


immutable long MO = 1_000_000_007;

int D;
string N;

void main() {
  try {
    for (; ; ) {
      N = readToken();
      D = readInt();
      auto dp = new long[][](N.length, D);
      dp[0][0] = 1;
      foreach (i; 1 .. dp.length) {
        foreach (d; 0 .. D) {
          foreach (x; 0 .. 10) {
            (dp[i][(d + x) % D] += dp[i - 1][d]) %= MO;
          }
        }
      }
      
      long ans;
      
      // first differs at pos
      int sum;
      foreach (pos; 0 .. N.length) {
        foreach (x; 0 .. N[pos] - '0') {
          (ans += dp[N.length - 1 - pos][((-(sum + x)) % D + D) % D]) %= MO;
        }
        sum += (N[pos] - '0');
      }
      
      // N
      if (sum % D == 0) {
        ++ans;
      }
      
      // 0
      --ans;
      
      ans = (ans % MO + MO) % MO;
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 14204
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        for (int i = 0; i < N; i++) {
            nums[i]=sc.nextInt();
        }
        int[] nums2 = Arrays.copyOf(nums,nums.length);
        Arrays.sort(nums);

        int diff=0;
        for (int i = 0; i < N; i++) {
            if(nums2[i]!=nums[i]){
                diff++;
            }
        }
        if(diff<=2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}


Measured memory_bytes: 21844
A=int(input())
B=int(input())
if(A==1 and B==2):
  answer=3
elif(A==1 and B==3):
  answer=2
elif(A==2 and B==3):
  answer=1
elif(A==2 and B==1):
  answer=3
elif(A==3 and B==1):
  answer=2
elif(A==3 and B==2):
  answer=1
print(answer)


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

int main(){
int x,y,z;
cin  >> x >> y >> z;
if (x >= y &&  y >=  z ){
  cout  <<  z  << " " << y << " " << x << endl;
} else if ( x <= y && y  <= z ){
  cout << x << " " << y << " " << z << endl;
} else if (x >= z && z >= y) {
  cout << y <<" " << z << " " << x << endl;
}  else if (x <= z && z <= y){
  cout << x << " " << z << " "  << y << endl;
} else if (z <= x && x <= y){
  cout << z << " " << x << " " << y << endl;
} else {
  cout << y << " " << x << " " << z << endl;
}
return 0;}



Measured memory_bytes: 3104
d={"o":1,"x":-1}
w={"S":1,"W":-1}
n={1:"S",-1:"W"}
N=int(raw_input())
s=raw_input()
s+=s[0]
def ans(a):
    for i in range(1,N+1):
        a+=n[w[a[i]]*w[a[i-1]]*d[s[i]]]
    if a[:2]==a[-2:]:
        return a[:-2]
    else:
        return []
for ini in ["SS","SW","WS","WW"]:
    a=ans(ini)
    if a:
        print a
        break
else:
    print "-1"

Measured memory_bytes: 6132
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

struct node{
	int num;
	node *parent,*left,*right;
};
node *root,*NIL;

node *treemin(node *x){
	while(x->left!=NIL)
		x=x->left;
	return x;
}

node *nextnode(node *x){
	if(x->right!=NIL) return treemin(x->right);
	node *y=x->parent;
	while(y!=NIL && x==y->right){
		x=y;
		x=y->parent;
	}
	return y;
}

void denode(node *z){
	node *x,*y;
	if(z->left==NIL||z->right==NIL) y=z;
	else y=nextnode(z);
	if(y->left!=NIL) x=y->left;
	else x=y->right;
	if(x!=NIL) x->parent=y->parent;
	if(y->parent==NIL) root=x;
	else{
		if(y==y->parent->left) y->parent->left=x;
		else y->parent->right=x;
	}
	if(y!=z) z->num=y->num;
//	denode(y);
	return ;
}

node *find(int a){
	node *x=root;
	while(x!=NIL){
		if(x->num<a) x=x->right;
		else if(x->num>a) x=x->left;
		else return x;
	}
	return NIL;
}

void print_inorder(node *x){
	if(x==NIL) return ;
	print_inorder(x->left);
	printf(" %d",x->num);
	print_inorder(x->right);
	return ;
}

void print_preorder(node *x){
	if(x==NIL) return ;
	printf(" %d",x->num);
	print_preorder(x->left);
	print_preorder(x->right);
	return ;
}

void insert(int a){
	node *x=root,*y=NIL;
	node *z=new node();
	z->num=a;z->left=NIL;z->right=NIL;
	while(x!=NIL){
		y=x;
		if(z->num < x->num) x=x->left;
		else x=x->right;
	}
	z->parent=y;
	if(y==NIL) root=z;
	else {
		if(z->num < y->num) y->left=z;
		else y->right=z;
	}
	return ;
}

int main(){
	int n;
	cin>>n;
	string s;
	node *f;
	int a;
	for(int i=0;i<n;i++){
		cin>>s;
		if(s[0]=='i') cin>>a,insert(a);
		else if(s[0]=='p'){
			print_inorder(root);
			printf("\n");
			print_preorder(root);
			printf("\n");
		}
		else if(s[0]=='f'){
			cin>>a;
			f=find(a);
			if(f==NIL) printf("no\n");
			else printf("yes\n");
		}
		else{
			cin>>a;
			denode(find(a));
		}
	}
	return 0;
}


Measured memory_bytes: 21932
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from math import *
from heapq import *

H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
f, ans = 0, []
for i in range(1, H+1):
    if i % 2:
        for j in range(1, W):
            if a[i-1][j-1] % 2:
                if f:
                    f = 0
                else:
                    f = 1
                    ans.append([i, j, i, j+1])
            else:
                if f:
                    ans.append([i, j, i, j+1])
    else:
        for j in range(2, W+1)[::-1]:
            if a[i-1][j-1] % 2:
                if f:
                    f = 0
                else:
                    f = 1
                    ans.append([i, j, i, j-1])
            else:
                if f:
                    ans.append([i, j, i, j-1])
    if i != H:
        j = W if i % 2 else 1
        if a[i-1][j-1] % 2:
            if f:
                f = 0
            else:
                f = 1
                ans.append([i, j, i+1, j])
        else:
            if f:
                ans.append([i, j, i+1, j])


print(len(ans))
for x in ans:
    print(*x)

Measured memory_bytes: 26772
package main

import "fmt"

func main() {
	var X int
	fmt.Scan(&X)
	for a := 0; a <= 1000; a++ {
		ap := 100 * a
		for b := 0; b <= 1000-a && b*101+ap <= X; b++ {
			bp := 101 * b
			for c := 0; c <= 1000-a-b && c*102+bp+ap <= X; c++ {
				cp := 102 * c
				for d := 0; d <= 1000-a-b-c && d*103+ap+bp+cp <= X; d++ {
					dp := 103 * d
					for e := 0; e <= 1000-a-b-c-d && e*104+ap+bp+cp+dp <= X; e++ {
						ep := e * 104
						fp := X - (ap + bp + cp + dp + ep)
						if fp%105 == 0 {
							// fmt.Printf("ap %d, bp %d, cp %d, dp %d, ep %d, fp %d\n", ap, bp, cp, dp, ep, fp)
							fmt.Println(1)
							return
						}
					}
				}
			}
		}
	}
	fmt.Println(0)
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
	int n;
	cin >> n;
	bool f = false; 
	for(int i = 1;i < 10; i++){
		for(int j = 1;j < 10;j++){
			if(n == i * j){
				f = true;
			}
		}	
	}
	if(f){
		cout << "Yes";
	}else{
		cout << "No";
	}
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll A, B; cin >> A >> B;
    cout << max(A-2*B, 0ll) << endstr;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

  int a,b,c,r,d,l=0;
  cin>>a>>b;
  for(int i=1;i<=a;i++)
  {
      for(int j=1;j<=b;j++)
      {
          r=j%10;
          d=j/10;
          if(r>=2 && d>=2)
          {
          if(r*d==i)
          {
              l++;

          }
          }

      }

  }

cout<<l<<endl;
return 0;


}




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

int main(){
    int a,b;
    cin>>a>>b;
    
    string A="";
    string B="";
    
    rep(i,b)
        A+=to_string(a);
    rep(i,a)
        B+=to_string(b);
    
    if(A>B) cout<<B<<endl;
    else cout<<A<<endl;
    
    return 0;
}

Measured memory_bytes: 3592
#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>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;}
template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
bool ans[2200]={false};
int main() {
    int n,m;cin >> n >> m;
    vector<vector<int>>k(m);
    for(int i=0;i<m;i++){
	int a;cin >> a;
	for(int j=0;j<a;j++){
	    int b;cin >> b;
	    k[i].push_back(b);
	}
    }
    vector<int> p(m);
    for(int i=0;i<m;i++) cin >>p[i];
    int ans = 0;
    for(int bit = 0;bit < (1 << n);bit++){
	bool ok = true;
	for(int l=0;l<m;l++){
	    int t=0;
	    for(int i=0;i<k[l].size();i++){
		if(bit & (1<<k[l][i]-1))t++;  
	    }
	    if(t%2!=p[l])ok = false;
	}
	if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b, c) = scan!(String, String, String);
    println!(
        "{}{}{}",
        a.chars().nth(0).unwrap(),
        b.chars().nth(0).unwrap(),
        c.chars().nth(0).unwrap()
    )
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<iostream>
#include<cmath>
#define llong long long
using namespace std;

inline int read()
{
	int x=0; bool f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
	if(f) return x;
	return -x;
}

llong s;

int main()
{
	scanf("%lld",&s);
	llong t = sqrt(s);
	while(t*t<s) {t++;}
	if(t*(t-1ll)>=s)
	{
		llong a = t,b = t-1ll,c = t*(t-1ll)-s,d = 1ll;
		printf("%lld %lld %lld %lld %lld %lld\n",0ll,0ll,a,d,c,b);
	}
	else
	{
		llong a = t,b = t,c = t*t-s,d = 1ll;
		printf("%lld %lld %lld %lld %lld %lld\n",0ll,0ll,a,d,c,b);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
  	int N; 
	string S;
  	cin >> N >> S; 
	int L = S.size();
	long long int P = 1e9 + 7;  
	long long int dp[5010][5010] = {}; 
	dp[0][0] = 1; 
	for(int j = 1; j <= 5000; j++){
		dp[0][j] = (dp[0][j-1] + dp[1][j-1]) % P; 
		for(int i = 1; i <= j; i++){
			dp[i][j] = (dp[i+1][j-1] + 2 * dp[i-1][j-1]) % P; 
		}
	}
	long long int Q = 1; 
	for(int i = 0; i < L; i++){
	Q = (Q * (P+1)/2) % P; 
	}
	cout << (dp[L][N] * Q) % P << endl; 
}

Measured memory_bytes: 196352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
vector< vector<P> > G;
vector<ll> color;
ll n,u,v,w;
void dfs(ll num){
    // cout<<num<<endl;
    for(auto nv:G[num]){
        if(color[nv.fi]==-1){
            if(nv.se%2==0){
                color[nv.fi]=color[num];
                 dfs(nv.fi);
            } else {
                color[nv.fi] = (color[num]==0?1:0);
                 dfs(nv.fi);
            }
        }
    }
}

int main(){
    cin>>n;
    G.assign(n,vector<P>());
    color.assign(n,-1);
    rep(i,n-1){
        cin>>u>>v>>w;
        u--;v--;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    color[0]=0;
    dfs(0);
    rep(i,n) cout<<color[i]<<endl;
    return 0;
}

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

int q, n[25], r;

int main(){
    scanf("%d", &q);
    for(int i = 1; i <=q; i++)scanf("%d", &n[i]);

    for(int i = 2; i<q; i++){
        if((n[i]>n[i-1] && n[i]<n[i+1])||(n[i]<n[i-1] && n[i]>n[i+1]))r++;
    }

    printf("%d\n", r);


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
	ll n;
	cin >> n;
	vector<ll> ans(n);

	for (int i = 0; i < n-1; i++)
	{
		ll temp;
		cin >> temp;
		ans[temp-1]+=1;
	}
	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << " ";
	}
	
	

}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, x ;
    cin >> n >> m >> x ;
    vint c(n) ;
    vvint a(n,vint(m,0)) ;
    REP(i,n){
        cin >> c[i] ;
        REP(j,m){
            cin >> a[i][j] ;
        }
    }
    
    int ans = INF ;
    for (int bitt = 0; bitt < (1 << n); bitt++) {
        bitset<12> bits(bitt); 
        vint b(m,0) ;
        int tmp = 0 ;
    
        for (int i = 0; i < n; i++) {
            if (bits[i]==1) {
                tmp += c[i] ;
                REP(j,m){
                    b[j] += a[i][j] ;
                }
            }
        }
        sort(ALL(b)) ;
        if(b[0]>=x){
            ans = min(ans,tmp) ;
        }
    }

  if(ans==INF){
      ans = -1 ;
  }

  cout << ans <<endl ;


    

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll s,t,d,w[100000],c=0,ans=1e11;
  cin>>s>>t>>d;
  for(int i=0;i<d;i++)cin>>w[i],c-=w[i];
  s-=t;
  for(ll i=0;i<d;i++){
    s+=w[i];
    if(s<=0)ans=min(ans,i+1);
    else if(c>0)ans=min(ans,i+(s+c-1)/c*d+1);
  }
  if(ans==1e11)ans=-1;
  cout<<ans<<endl;
  return 0;
}

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

set<int> shortest_path(auto G, auto s, auto g) {
  vector<int> p(G.size(), -1);
  function<void(int)> dfs = [&](int v) {
    for(auto nex: G[v]) if(p[nex]==-1) {
      p[nex] = v;
      dfs(nex);
    }
  };

  p[0] = 0;
  dfs(0);

  set<int> V;
  V.emplace(0);
  for(auto v = g; v != 0; v = p[v]) V.emplace(v);
  return V;
}

bool check() {
  int N;
  cin >> N;

  vector<vector<int>> G(N);
  for(auto i = 1; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  auto path = shortest_path(G, 0, N-1);
  vector<int> color(N, -1);
  vector<deque<int>> q(2);
  q[0].emplace_front(0);
  q[1].emplace_front(N-1);
  for(auto turn = 0; !q[0].empty() || !q[1].empty(); turn ^= 1) {
    if(q[turn].empty()) continue;
    auto v = q[turn].front();
    q[turn].pop_front();
    if(color[v] != -1) {turn ^= 1; continue;}
    color[v] = turn;
    for(auto nex: G[v]) if(color[nex] == -1) {
      if(path.count(nex)) q[turn].emplace_front(nex);
      else                q[turn].emplace_back(nex);
    }
  }

  vector<int> n(2);
  for(auto i: color) ++n[i];
  return n[0] > n[1];
}

int main() {
  cout << (check() ? "Fennec" : "Snuke") << endl;
}


Measured memory_bytes: 22528
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		int count=1;
		for (int i=1;i<s.length();i++) {
			if (s.charAt(i)!=s.charAt(i-1)) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 39720
while True:
    n, x = [int(i) for i in input().split(" ")]
    if n == x == 0:
        break
    count = 0
    for r1 in range(1, n -1):
        for r2 in range(r1 + 1, n):
            for r3 in range(r2 + 1, n + 1):
                if r1 + r2 + r3 == x:
                    count += 1
    print(count)
       
        

Measured memory_bytes: 7624
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int D = scn.nextInt();
        long[] c = new long[26];
        long[][] s = new long[D][26];
        int maxNum = 0;
        int[] ld = new int[26];
        Arrays.fill(ld,0);

        for(int i=0;i<26;i++){
            c[i]=scn.nextLong();
        }

        for(int i=0;i<D;i++){
            long max = -180000000;
            long sumC = 0;

            for(int j=0;j<26;j++){
                sumC += (i-ld[j])*c[j];
            }
            for(int j=0;j<26;j++){
                s[i][j]=scn.nextLong();
                long tmp = s[i][j];
                long su = tmp - sumC+c[j]*(i-ld[j]);
                if(max < su){
                    max = su;
                    maxNum = j;
                }
            }
            //score += max;
            System.out.println(maxNum+1);
            ld[maxNum]=i;
        }

        //System.out.println(score);

        scn.close();

    }


}


Measured memory_bytes: 37996
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n;
string s;
int main(){
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		int num=s[i]-'A';
		num=(num+n)%26;
		cout<<char(num+'A');
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 100
int main() {
        int n = 0;
        scanf("%d", &n);
        char s[100];
        scanf("%s", s);
        int i = 0;
        int countR = 0;
        while (i < n) {
                if (s[i] == 'R') {
                        countR++;
                }
                i++;
        }
        if (countR > n - countR) {
                printf("Yes");
        } else {
                printf("No");
        }
}

Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int i = 0;
		int j = 0;
		int k = 0;
		int flag = 0;
		
		int baf = 0;
		int[] Li = new int [N];
		int[] Li2 = new int[N];
		for(i=0;i<N;i++) {
			Li[i] = scanner.nextInt();
		}

		
		for(i=0;i<N;i++) {
			for(j=i+1;j<N;j++) {
				System.arraycopy(Li, 0, Li2, 0, N);
				baf = Li2[i];
				Li2[i] = Li2[j];
				Li2[j] = baf;
				flag = 0;
				for(k=0;k<N-1;k++) {
					
					if(Li2[k] > Li2[k+1]) {
						flag  = -1;
						break;
					}
					
				}
				if(flag == 0) {
					flag = 1;
					break;
				}
				
			}
			if(flag == 1) {
				break;
			}
		}
		if(flag != 1) {
			flag = 0;
			for(i=0;i<N-1;i++) {
				
				if(Li[i] > Li[i+1]) {
					flag = -1;
					break;
					
				}
			}
			if (flag != -1) {
				flag = 1;
			}
		}
		if (flag == 1) {
			System.out.print("YES");
		}else {
			System.out.print("NO");
		}
	}
}

Measured memory_bytes: 21844
X, Y = map(int, input().split())
p = {1:300000, 2:200000, 3:100000}

if X == Y == 1:
  print(p[X] + p[Y] + 400000)
elif X <=3 and Y <= 3:
  print(p[X] + p[Y])
elif X <= 3 and not Y <= 3:
  print(p[X])
elif not X <= 3 and Y <= 3:
  print(p[Y])
else:
  print(0)

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

using namespace std;

int main()
{
    int M,N;
    cin>>N>>M;
    if(N>=0&&M>=0&&N<=100&&M<=100&&(M+N)>=2){
    int sum=((N*(N-1))/2) +((M*(M-1))/2);
    cout<<sum;
    }
   return 0;
}

Measured memory_bytes: 3552
N=int(input())
a=list(map(int,input().split()))

a=sorted(a)
base={}
count=0

for i in range(N):
    if a[i] not in base.keys():
        base[a[i]]=1
        if i>=1 and base[a[i-1]]<a[i-1]:
            count+=base[a[i-1]]
    else:
        if base[a[i]]>=a[i]:
            count+=1
        else:
            base[a[i]]+=1
if base[a[N-1]]<a[N-1]:
    count+=base[a[i]]
print(count)

Measured memory_bytes: 18548
import java.util.Scanner;

//  C - Otoshidama

public class Main {
  public static void main(String[] args ) throws Exception {
	  Scanner sc = new Scanner(System.in);
	  Integer N = Integer.parseInt(sc.next());
	  Integer Y = Integer.parseInt(sc.next());

	  for(int i = 0; i <= N; i++) {
		  for(int m =0; m <= N-i; m++) {
			  int n = N-i-m;
			  if(i*10000+m*5000+n*1000 == Y) {
				 System.out.println(i+" "+m+" "+n);
				 return;
			  }
		  }
	  }
	 System.out.println("-1 -1 -1");
//    Scanner sc = new Scanner(System.in);
//    int N = Integer.parseInt(sc.next());
//    int Y = Integer.parseInt(sc.next());
//    Integer man = 0;
//    Integer gosen = 0;
//    Integer sen = 0;
//
//    label: for(int i = 0; i <= N; i++) {
//    	if(i * 10000 == Y && i == N) {
//			man = i;
//			break label;
//    	}
//    	for(int m = 0; m <= (N-i); m++) {
//			if(i * 10000 + m * 5000 == Y && i + m == N) {
//				man = i;
//				gosen = m;
//				break label;
//			}
//
//			for(int n = 0; n <= (N-i-m); n++) {
//				if(i * 10000 + m * 5000 + n * 1000 == Y && i + m + n == N) {
//					man = i;
//					gosen = m;
//					sen = n;
//					break label;
//				}
//			}
//    	}
//    }
//    if(man == 0 && gosen == 0 && sen ==0) {
//    	System.out.println("-1 -1 -1");
//    } else {
////		System.out.println(man*10000+gosen*5000+sen*1000);
////		System.out.println(man+gosen+sen);
//		System.out.println(man.toString()+" "+gosen.toString()+" "+sen.toString());
//    }

  }
}

Measured memory_bytes: 22484
n,k,s=map(int,input().split())
ans=[]
for i in range(k):
    ans.append(str(s))
if s==1:
    for i in range(n-k):
        ans.append("2")
elif s==10**9:
    for i in range(n-k):
        ans.append("1")
else:
    for i in range(n-k):
        ans.append(str(10**9))
print(' '.join(ans))


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

using namespace std;

//////////////////////////////////////////////////
class SegmentTree
{
public:
    typedef long long Int;
    static const Int DEFAULT_VALUE = 0; 
    vector<Int> data;
    Int N;

    inline Int func(Int x, Int y) {
        return x + y;
    }

    SegmentTree(vector<Int> vec) {
        Int x = 1;
        while (x < (Int)vec.size()) {
            x *= 2;
        }
        this->N = x;
        data = vector<Int>(2 * x, DEFAULT_VALUE);
        for (int i = 0; i < (Int)vec.size(); i++) {
            update(i, vec[i]);
        }
    }

    Int get(Int l, Int r) {
        return getSub(l, r, 0, N, 1);
    }

    void update(Int index, Int val) {
        Int v = index + N;
        data[v] += val;

        v /= 2;
        while (v > 0) {
            data[v] = func(data[2 * v], data[2 * v + 1]);
            v /= 2;
        }
    }

    Int getSub(Int l, Int r, Int myl, Int myr, Int v) {
        if (myr <= l || r <= myl) return DEFAULT_VALUE;
        if (l <= myl && myr <= r) return data[v];

        Int mid = (myl + myr) / 2;
        return func(getSub(l, r, myl, mid, 2 * v),
                   getSub(l, r, mid, myr, 2 * v + 1));
    }
};
//////////////////////////////////////////////////

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree seg(vector<long long>(n, 0));
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            seg.update(x - 1, y);
        } else {
            cout << seg.get(x - 1, y) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6020
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k; cin >> n >> k;
	vector<int> h(n);
	for(int i = 0; i < n; i++) cin >> h[i];
	vector<int> dp(n, INT_MAX);
	dp[0] = 0, dp[1] = abs(h[1]-h[0]);
	for(int i = 2; i < n; i++)
		for(int j = 1; j <= k; j++)
			dp[i] = min(dp[i], ((i-j>=0) ? (dp[i-j]+abs(h[i]-h[i-j])) : (dp[i])));
	cout << dp[n-1] << '\n';
	return 0;
}


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


void solve(ll n, string s){
    int ans=1;
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1])ans++;
    }
    cout<<ans<<endl;
}

int main(){
    ll n;
    scanf("%lld",&n);
    string s;
    cin >> s;
    solve(n, s);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

struct edge{int from, to, cost;};

int main(){
    ll L;
    cin >> L;
    vector<ll> a;
    while(L!=2){
        a.push_back(L);
        if (L%2==0){
            L/=2;
        }
        else {
            L--;
        }
    }
    a.push_back(2);
    reverse(a.begin(),a.end());
    ll V=2,E=2;
    vector<edge> es;
    es.push_back(edge{1,2,0});
    es.push_back(edge{1,2,1});
    rep(i,a.size()-1){
        if (a[i+1]==2*a[i]){
            rep(j,E){
                es[j].cost*=2;
            }
            es.push_back(edge{V,V+1,0});
            es.push_back(edge{V,V+1,1});
            E+=2;
            V++;
        }
        else {
            es.push_back(edge{1,V,a[i+1]-1});
            E++;
        }
    }
    cout << V << ' ' << E << endl;
    rep(i,E){
        edge e=es[i];
        cout << e.from << ' ' << e.to << ' ' << e.cost << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    }
}


Measured memory_bytes: 21844
n = int(input())
lis = list(map(int,input().split()))
y = 0
while True:
    x = 0
    for i,v in enumerate(lis):
        j = v/2
        lis[i] = j
        if j.is_integer():
            x += 1
    if not x == n:
        break
    y += 1

print(y)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
ll n,m,a,b;
int ans=0;
int main() {
	scanf("%lld%lld",&n,&m);
	rep(i,0,n){
		scanf("%lld%lld",&a,&b);
		db c=sqrt(a*a+b*b);
		if(m-c>=0){
			ans++;
		}	
	}
	cout<<ans; 
} 

Measured memory_bytes: 3696
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int ll;
typedef int ull;
#define LONGMAX 1e18
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){ll mid=(low+high)/2;if(low>high)return;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
int main()
{
	fastio();
    ll N,R;
    cin>>N>>R;
    if(N>10)
        cout<<R<<endl;
    else
    {
        cout<<R+(10-N)*100<<endl;
    }
}//*-A/BC-/AKL

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

const ll P=1'000'000'007;
ll X,Y;

ll mpow(ll x,ll n){
    if (n==0) return 1;
    if(n%2==1) return x*mpow(x,n-1)%P;
    else return mpow(x*x%P,n/2)%P;
}

int main(){
    cin>>X>>Y;

    ll k,l;
    if((2*Y-X)%3==0 && (2*X-Y)%3==0){
        k=(2*Y-X)/3;
        l=(2*X-Y)/3;
        if(k<0 || l<0){
            cout<<0<<endl;
            return 0;
        }
    }else{
        cout<<0<<endl;
        return 0;
    }

    ll r=min(k,l);
    ll a=1;
    ll b=1;
    for(int i=1;i<=r;i++){
        a=a*(k+l-i+1)%P;
        b=b*i%P;
    }

    ll ans=a*mpow(b,P-2)%P;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <ctime>
#include <set>
#include <sstream>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
char s[20005];int i;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	i=3;
	while(i--)
	{
		scanf("%s",s);
		printf("%c",s[0]);
	}
	printf("\n");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	int n;
	cin>>n;
	ll x,y;
	vector<pair<ll, ll>> ball;
	rep(i,n){
		cin>>x>>y;
		ball.push_back(pair<ll,ll>{x,y});
	}
	ll ans = n;
	rep(i,n){
		rep(j,n){
			if(i==j) continue;
			ll p = ball[i].first - ball[j].first;
			ll q = ball[i].second - ball[j].second;
			ll count = 0;
			rep(s,n){
				rep(t,n){
					if(s==t) continue;
					if(ball[s].first - ball[t].first == p && ball[s].second - ball[t].second == q){
						count++;
					}
				}
			}
			chmin(ans, n - count);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(void){
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=1;i<=1005;i++){
		if(k*i>=a&&k*i<=b){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3636