akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

typedef long long int ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b;
  cin >>n>>a>>b;
  ll times = 0;
  times = n / (a+b);

  if(n - (a+b)*times >= a)
    cout << a*times + a<<endl;
  else
    cout << a*times + (n- (a+b)*times) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define For(I,N) for(int I=0;I<N;I++)
typedef unsigned long long ull;
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	rep(n)
	{
		scanf("%d",a+i);
	}
	rep(n)
	{
		scanf("%d",b+i);
	}
	rep(n)
	{
		scanf("%d",c+i);
	}
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		int d=lower_bound(a,a+n,b[i])-a;
		int e=upper_bound(c,c+n,b[i])-c;
		e=n-e;
		ans+=1LL*d*e;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
s=list(map(int,input().split()))
a=0
b=0
c=0
d=0
e=0
f=0
a=s[0]-s[0]%1000
a=a/100
d=s[0]%10
c=s[0]%100-d
b=s[0]-a*100-c-d
b=int(b/100)
e=a+b
f=c+d
if e==0:
  if 1<=f and f<=12:
    print('YYMM')
  else:
    print('NA')
elif 1<=e and e<=12:
  if 1<=f and f<=12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if 1<=f and f<=12:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
inline ll LCM(ll a, ll b){return a / GCD(a, b) * b;}
inline ll powint(ll x, ll y){ll r=1;while(y){if(y&1)r*=x;x*=x;y>>=1;}return r;}
inline ll powmod(ll x, ll y, ll m = MOD){ll r=1;while(y){if(y&1)r*=x;x*=x;r%=m;x%=m;y>>=1;}return r;}
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
puts s=9394,
a=?+,0,1,m=9,?<,2,9,3,
[0,1].map{|p|[a,3,p,p]+(s=0..59).map{[a,u=p+4,u,u,a,3,u,6,[a,6,6,6]*(59-_1),?<,6,p,m+=1,a,u,m,u]}},
s.map{|_|[a,2,2,2]+(1.._).map{[a,40+_-_1,99+_1,5,?<,3,5,5,a,2,5,2]}}

Measured memory_bytes: 14932
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        
        int h,w,i,j;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        while(true){
            String[] str = br.readLine().split(" ");
            h = Integer.parseInt(str[0]);
            w = Integer.parseInt(str[1]);
            
            if(h == 0 && w ==0){
                break;
            }
            
            for(i = 0; i < h; i++){
                for(j = 0; j < w; j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}

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

int main() {
  int A,B,C,D;
  cin >> A>>B>>C>>D;

  if (A-C/B*D>0 ||C%B==0) {
    cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
}
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=0,x=0,l=0;
        if(scan.hasNext())
            n=scan.nextInt();
        ArrayList<pair> list=new ArrayList<>();
        for(int i=0;i<n;i++){
            if(scan.hasNext())
                x=scan.nextInt();
            if(scan.hasNext())
                l=scan.nextInt();
            list.add(new pair(x-l,x+l));
        }
        Collections.sort(list, new Comparator<pair>() {
            @Override
            public int compare(pair p1, pair p2) {
                if(p1.x>p2.x){
                    return 1;
                }else if(p1.x<p2.x){
                    return -1;
                }else{
                    if(p1.y>p2.y){
                        return 1;
                    }else if(p1.y<p2.y){
                        return -1;
                    }else{
                        return 0;
                    }
                }
            }
        });
        int i=1;
        while(i<list.size()){
            if(list.get(i).x>=list.get(i-1).y){
                i++;
            }else{
                if(list.get(i-1).y>=list.get(i).y){
                    list.remove(i-1);
                }else{
                    list.remove(i);
                }
            }
        }
        System.out.println(list.size());

    }
    static class pair{
        int x,y;
        public pair(int x,int y){
            this.x=x;
            this.y=y;
        }
    }
}


Measured memory_bytes: 92796
using System;


class Program
    {
        public static void Main()
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if (a > b)
                Console.WriteLine("a > b");
            else if (a < b)
                Console.WriteLine("a < b");
            else if (a == b)
                Console.WriteLine("a == b");
            
        }
    }


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

int main()
{
    string X;
    cin >> X;
    stack<char> st;
    for (char c : X) {
        if (!st.empty() && st.top() == 'S'&&c == 'T') {
            st.pop();
        }
        else {
            st.push(c);
        }
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 644
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter

import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

S = input()
Q=int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入
qs=[]
s=deque(list(S))
for i in range(Q):
    qs.append(list(input().split()))

rev=0
for q in qs:
    if int(q[0])==1: rev=(rev+1)%2
    else:
        if (int(q[1])+rev)%2==1:
            s.appendleft(q[2])
        else:
            s.append(q[2])
    #print(s,rev)

if rev==0:
    for i in range(len(s)): print(s.popleft(), end="")
else:
    for i in range(len(s)): print(s.pop(), end="")
print()


Measured memory_bytes: 123640
N, K = map(int, input().split())
count = [0] * (10**5+1)
for i in range(N):
    a, b = map(int, input().split())
    count[a] += b

for i in range(10**5+1):
    if (K <= count[i]):
        break
    K -= count[i]
print(i)


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

const long long INF = 10000000000000;

long long d[100][100];
int v,e;

int main(){
  scanf("%d %d",&v,&e);
  fill(d[0],d[0]+10000,INF);
  for(int i=0;i<e;i++){
    int s,t,cost;
    scanf("%d %d %d",&s,&t,&cost);
    d[s][t] = cost;
  }
  for(int i=0;i<v;i++) d[i][i] = 0;
  for(int k=0;k<v;k++){
    for(int i=0;i<v;i++){
      for(int j=0;j<v;j++){
        if(d[i][k]!=INF&&d[k][j]!=INF) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  for(int i=0;i<v;i++){
    if(d[i][i]<0){
      printf("NEGATIVE CYCLE\n");
      return 0;
    }
  }
  for(int i=0;i<v;i++){
    for(int j=0;j<v;j++){
      if(d[i][j]==INF) printf("INF");
      else printf("%lld",d[i][j]);
      if(j<v-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2832
import math
def d(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2+(y1-y2)**2)

def distance(p):
    dst = 0
    for i in range(n-1):
        x1 = xval[p[i]]
        y1 = yval[p[i]]
        x2 = xval[p[i+1]]
        y2 = yval[p[i+1]]
        dst += d(x1,y1,x2,y2)
    return dst

def permutation(lst): 
    if len(lst) == 0: 
        return [] 
    if len(lst) == 1: 
        return [lst] 
    l = [] 
    for i in range(len(lst)): 
       m = lst[i] 
       remLst = lst[:i] + lst[i+1:] 
       for p in permutation(remLst): 
           l.append([m] + p) 
    return l 

n = int(input())

xval = []
yval = []

for i in range(n):
    x,y = map(int, input().split())
    xval.append(x)
    yval.append(y)

r = [i for i in range(n)]

per = permutation(r)

dist = []

for p in per:
    dist.append(distance(p))

print(sum(dist)/len(dist))

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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 2e5 + 10;
const int M = (int) 6e5 + 10;
const ll LINF = (ll) 2e18;
const int INF = (int) 1e9 + 7;
const int mod1 = 998244353;
const int mod2 = INF;
const double PI = 3.14159265359;
const ld EPS = (ld) 1e-12;

int n;
vec a;
vector<pii> q;

pii t[2][N * 4];

pii get_min(int tr, int L, int R, int v = 1, int l = 0, int r = n / 2 - 1) {
  if (L > r || l > R) return mp(INF, -1);
  if (L <= l && r <= R) return t[tr][v];
  int m = (l + r) / 2;
  return min(get_min(tr, L, R, v + v, l, m), get_min(tr, L, R, v + v + 1, m + 1, r));
}

void build(int tr, int v = 1, int l = 0, int r = n / 2 - 1) {
  if (l == r) {
    int id = l * 2 + tr;
    t[tr][v] = mp(a[id], id);
    return;
  }
  int m = (l + r) / 2;
  build(tr, v + v, l, m);
  build(tr, v + v + 1, m + 1, r);
  t[tr][v] = min(t[tr][v + v], t[tr][v + v + 1]);
}

pii get_val(int l, int r) {
  if (l % 2 == 0) {
    pii x = get_min(0, l / 2, (r - 1) / 2);
    pii y = get_min(1, x.s / 2, (r - 1) / 2);
    //cout << " 0 " << l << ' ' << r << " -> " << x.s << " " << y.s << "\n";
    return mp(x.s, y.s);
  }
  pii x = get_min(1, l / 2, (r - 1) / 2);
  pii y = get_min(0, x.s / 2 + 1, r / 2);
    //cout << " 1 " << l << ' ' << r << " -> " << x.s << " " << y.s << "\n";
    return mp(x.s, y.s);
  
}

struct cmp {
  bool operator() (const pair<pii, pii>& x, const pair<pii, pii>& y) const {
    return mp(a[x.f.f], a[x.f.s]) < mp(a[y.f.f], a[y.f.s]);
  }
};

int main() {
  #define fn "combination"
  #ifdef witch
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #else
     // freopen(fn".in", "r", stdin);
     // freopen(fn".out", "w", stdout);
  #endif
  srand(time(0));
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  build(0);
  build(1);
  set<pair<pii, pii>, cmp> st;
  st.insert(mp(get_val(0, n - 1), mp(0, n - 1)));
  int tmr = 0;
  while (!st.empty()) {
    pair<pii, pii> fr = *st.begin();
    cout << a[fr.f.f] << ' ' << a[fr.f.s] << " ";
    st.erase(st.begin());
    vector<pii> seg;
    seg.pb(mp(fr.s.f, fr.f.f - 1));
    seg.pb(mp(fr.f.f + 1, fr.f.s - 1));
    seg.pb(mp(fr.f.s + 1, fr.s.s));
    for (auto it : seg) {
      if (it.f <= it.s)
        st.insert(mp(get_val(it.f, it.s), it));
    }
  }
  return 0;
}

Measured memory_bytes: 13056
S = input()

while True:
  if S[-5:] == 'dream':
    S = S[:-5]
    continue
  elif S[-7:] == 'dreamer':
    S = S[:-7]
    continue
  elif S[-5:] == 'erase':
    S = S[:-5]
    continue
  elif S[-6:] == 'eraser':
    S = S[:-6]
    continue
  break

answer = 'YES' if not S else 'NO'
print(answer)


Measured memory_bytes: 3188
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

int dp[101][100001];
int we[101],val[101];

int memo_knapsack(int weight,int n){
    if(n < 0 || weight <=0) return 0;
    int& st = dp[n][weight];
    if(st!=-1) 
        return st;
    if(we[n-1]<=weight)
        st=max(val[n-1]+memo_knapsack(weight-we[n-1],n-1),memo_knapsack(weight,n-1));
    else if(we[n-1]>weight)
        st = memo_knapsack(weight,n-1);
    return st;
} 

signed main()
{
    fasino
    int n,w;
    cin >> n >> w;
    for(int i=0;i<n;i++) cin>>we[i]>>val[i];
    memset(dp,-1,sizeof dp);
    int prof = memo_knapsack(w,n);
    cout<<prof<<'\n';
    return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    int c[] = {500, 100, 50, 10, 5, 1};
    while (true) {
        cin >> n;
        if (n == 0) break;
        n = 1000 - n;
        int ans = 0;
        rep(i, 0, 6) {
            ans += n/c[i];
            n -= n/c[i] * c[i];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a1,a2,a3,a4,a5=0;
    cin >> a1 >> a2 >> a3 >> a4 >> a5;
    if(a1==0){cout<<1<<endl;}
    else if(a2==0){cout<<2<<endl;}
    else if(a3==0){cout<<3<<endl;}
    else if(a4==0){cout<<4<<endl;}
    else if(a5==0){cout<<5<<endl;}

}

Measured memory_bytes: 3592
#!/usr/bin python3
# -*- coding: utf-8 -*-

def factorization(n):
    primen, degree, primend = [], [], []
    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
            primen.append(i)
            degree.append(cnt)
            primend.append([i,cnt])
    if temp!=1:
        primen.append(temp)
        degree.append(1)
        primend.append([temp,1])
    if primen==[]:
        primen.append(n)
        degree.append(1)
        primend.append([n,1])
    return degree
#    return primen,degree


def main():
    N, M = map(int, input().split())
    if M == 1:
        print(1)
    else:
        mod = 10**9+7               # mod素数
        Mf = factorization(M)
        l = max(Mf)
        Comb=[1]*(l+1)
        for i in range(1,l+1):
            tmp = Comb[i-1]
            tmp *= N-1+i
            tmp *= pow(i, mod-2, mod)
            Comb[i] = tmp%mod
        ret = 1
        for i in Mf:
            ret *= Comb[i]
            ret %= mod
        print(ret)



if __name__ == '__main__':
    main()

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

int main() {
  int H,N;
  cin>>H>>N;
  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
}
  int w;
  w=0;
  for (int i = 0; i < N; i++) {
  w += data.at(i);
  }
  if(w>=H){
    cout << "Yes" << endl;
  }
  if(w<H){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
 
using namespace std;
int main()
 
{
    string n;
  cin >> n;
 
    for (int i = 0; i < 3; i++) {
 
        if (n[i] == '1') {
            n[i] = '9';
        } else if (n[i] == '9') {
            n[i] = '1';
        }
    }
 
    cout << n << endl;
 
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

string alphabet = "abcdefghijklmnopqrstuvwxyz";

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

    ll l = 0;
    ll M = 0;
    for (ll i = 1; i < 100; i++)
    {
        l++;
        if (M + pow(26, i) >= N)
        {
            break;
        }
        else
        {
            M += pow(26, i);
        }
    }

    // kth num in l digit base-26
    ll k = N - M - 1;
    string ans = "";
    rep(i, l)
    {
        if (i == l - 1)
        {
            ans += alphabet[k];
        }
        else
        {
            ll d = pow(26, l - 1 - i);
            ll q = k / d;
            ans += alphabet[q];
            k -= d * q;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4044
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    readln;
    readln.split.to!(int[]).sort().stride(2).sum.writeln;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
require 'prime'

$primes = [*Prime.each(100000)]
$eseprimes = $primes.clone
$eseprimes.delete_if {|m| !$primes.include?((m+1)/2) }

$count = Array.new(10**5,0)
c = 0
s = 0
[*$eseprimes, $count.size+1].each do |e|
  $count.fill(c, s..e)
  c += 1
  s = e
end

gets.to_i.times do
  l,r = gets.split.map(&:to_i)
  puts $count[r] - $count[l-1]
end


Measured memory_bytes: 3892
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_u64_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: u64 = input();
    let mut a_vec = input_u64_vec();
    let mut b_vec = input_u64_vec();
    let mut sum = 0;
    for i in 0..b_vec.len() {
        if a_vec[i] < b_vec[i] {
            b_vec[i] -= a_vec[i];
            sum += a_vec[i];
            if a_vec[i+1] < b_vec[i] {
                sum += a_vec[i+1];
                a_vec[i+1] = 0;                
            } else {
                a_vec[i+1] -= b_vec[i];
                sum += b_vec[i];
            }
        } else {
            sum += b_vec[i];
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll val(ll a[],vector<ll> &dp,ll i,ll k){
    if(i==0)
    return 0;
    
    if(dp[i]!=-1) 
    return dp[i];
    ll ans=1e12;
    
    for(ll j=1;j<=k;j++){
        if(i-j<0) break;
        ans=min(ans,val(a,dp,i-j,k)+abs(a[i]-a[i-j]));
    }
    
    return dp[i]=ans;
}

int main() {
    fastio
    
	ll n,i,j,x,t,k,m,y;
	cin>>n>>k;
	
	ll a[n];
	vector<ll> dp(n,-1);
	
	for(j=0;j<n;j++)
	cin>>a[j];
	
	dp[1]=abs(a[1]-a[0]);
	
	cout<<val(a,dp,n-1,k);
	
	return 0;
}


Measured memory_bytes: 12660
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int n,m,a[1000];
int i,j,cen,step;

int main(){
	while(scanf("%d",&n)*n){
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		scanf("%d",&m);
		i=0;j=n-1;step=0;
		while(i<=j){
			step++;
			cen=(i+j)/2;
			if(m==a[cen])break;
			else if(m<a[cen])j=cen-1;
			else i=cen+1;
		}
		printf("%d\n",step);
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a, b, c, d, ans;
  cin >> a >> b >> c >> d;

  ans = a * c;

  long long tmp;
  tmp = a * d;
  if(ans < tmp){
    ans = tmp;
  }
  tmp = b * c;
  if(ans < tmp){
    ans = tmp;
  }
  tmp = b * d;
  if(ans < tmp){
    ans = tmp;
  }
  cout << ans << endl;
}


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

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

  while(1){
    int x=0, y=0;
    cin >> n;
    if( n == 0 ) break;
    if( n <= 10000){
      for( i = 1 ; i <= n ; i++){
	cin >> a >> b ;
	if ( a > b ){
	  x =x+ (a+b); 
	}
	else if ( a == b){
	  x = x+a;
	  y = y+b;
	}
	else y =y+(a+b);
      }
    }
    cout << x << " " << y <<endl;
  }
  
  return 0 ;
}

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

int main() {
string s,t;
cin >> s;
t=s;
if(s=="keyence"){
    cout << "YES";
    return 0;
}
else {
    for(long long i=0;i<s.size();i++){
        
        for(long long j=0;j<s.size();j++){
            
            s.erase(i,j);
        if(s=="keyence"){
            cout << "YES";
            return 0;}
          s=t;
        }
        
    }
}
cout << "NO";
}


Measured memory_bytes: 256
/*
Point.
非負数を２つずつ追加すると、k値が奇数の時に負になり、最大化できない場合がある
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

#define INF ll(1e9+7)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, k; cin >> n >> k;
  vector<ll> a(n);
  int isp = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] >= 0) isp++;
  }
  deque<ll> p, m;
  if(isp == 0 && k%2) sort(a.begin(), a.end());
  else sort(a.begin(), a.end(), greater<ll>());
  for(int i = 0; i < n; i++){
    if(a[i] >= 0) p.push_back(a[i]);
  }
  if(isp == 0 && k%2) sort(a.begin(), a.end(), greater<ll>());
  else sort(a.begin(), a.end());
  for(int i = 0; i < n; i++){
    if(a[i] < 0) m.push_back(a[i]);
  }
  ll ans = 1;

  if(k == n){
    for(int i = 0; i < n; i++){
      ans = ans * a[i] % INF;
    }
  }
  else if(isp == 0 && k%2){
    while(k){
      ans = ans * m[0] % INF;
      m.pop_front();
      k--;
    }
  }
  else{
    while(k){
      if(k >= 2 && !(p.size() < 2 && m.size() < 2)){
        if(p.size() >= 2 && m.size() >= 2){
          if(p[0]*p[1] >= m[0]*m[1]){
            ans = ans * p[0] % INF;
            p.pop_front();
            k--;
          }
          else{
            ans = ans * (m[0] * m[1] % INF) % INF;
            m.pop_front(); m.pop_front();
            k -= 2;
          }
        }
        else if(m.size() < 2){
          ans = ans * p[0] % INF;
          p.pop_front();
          k--;
        }
        else if(p.size() < 2){
          ans = ans * (m[0] * m[1] % INF) % INF;
          m.pop_front(); m.pop_front();
          k -= 2;
        }
      }
      else{
        ans = ans * p[0] % INF;
        p.pop_front();
        k--;
      }
    }
  }

  cout << ((ans>=0)? ans : INF+ans) << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 6364
#include <cstdio>
#define NUM 4
//using namespace std;
int main() {
	
  	int i, j, count;
  	char S[NUM];
  	
  	count=0;
  
  	for(i=0; i<NUM; i++){      
      
  		scanf("%c\n",&S[i]);
    
    }
  
    
  	for(i=0; i<NUM-1; i++){
      
      for(j=1; j<NUM; j++){
      
      	if(S[i]==S[i+j]){
        	count++;
      	}
      
      }		
      
 	
    }
  
  if(count==2){
  	printf("%s","Yes");
  }else{
    printf("%s","No");
  }
  
	
  
 
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
import heapq


t = readint()
ans = []

for _ in range(t):
    n = readint()
    a = []
    b = []
    score = 0
    for i in range(n):
        k,l,r = readints()
        if k==n:
            score += l
        elif l>r:
            a.append([k,l,r])
            score += l
        elif l<r:
            b.append([n-k,l,r])
            score += r
        else:
            score += r
    a.sort()
    b.sort()
    left = []
    right = []
    heapq.heapify(left)
    heapq.heapify(right)
    lenl = 0
    lenr = 0
    for k,l,r in a:
        if k>lenl:
            heapq.heappush(left,[l-r,l,r])
            lenl += 1
        else:
            if l-r>left[0][0]:
                y = heapq.heappop(left)
                heapq.heappush(left,[l-r,l,r])
                score -= y[1]
                score += y[2]
            else:
                score -= l
                score += r
    for k,l,r in b:
        if k>lenr:
            heapq.heappush(right,[r-l,l,r])
            lenr += 1
        else:
            if r-l>right[0][0]:
                y = heapq.heappop(right)
                heapq.heappush(right,[r-l,l,r])
                score -= y[2]
                score += y[1]
            else:
                score -= r
                score += l
    ans.append(score)
printrows(ans)









Measured memory_bytes: 122828
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 10001;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeツδ環スツトツづーツ渉可甘コツ可サ
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;

		// ツづ督づゥツつ「ツづ可つゥツつッツづゥ
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
		cout << flush;
	}
}


int main(){

	erats();

	int n;
	vector<pair<int,int> > twin;
	bool f=false;
	for(int i = 0; i < p; i++){
		for(int j = i+1; j < p; j++){
			if(prime[j]-prime[i]==2){
				twin.push_back(make_pair(prime[i],prime[j]));
				//					cout<<prime[j]<<" "<<prime[i]<<endl;
			}
		}
	}

	while(cin>>n&&n!=0){
		for(int i = twin.size()-1; ; i--){
			if(twin[i].first<=n&&twin[i].second<=n){
				cout<<twin[i].first<<" "<<twin[i].second<<endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cnt = 0
T = 0
maxi=N
cnt = N
for i in range(N):
    T += A[i]
    if T>K:
        maxi = i
        cnt = i
        T = T-A[i]
        break

out = cnt
Life=K-T
Bt = 0
while (Bt<=M-1) and (maxi>=0):
    Bcnt=0
    if Life-B[Bt]>=0:
        Life += -1*B[Bt]
        Bt += 1
        Bcnt+=1
    else:
        Life += A[maxi-1]
        maxi += -1
        Bcnt += -1
    cnt = cnt+Bcnt
    out = max(out,cnt)
print(out)

Measured memory_bytes: 110864
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

void dfs2(vector<vector<int>> &ab, vector<vector<int>> &ab2, int parent, int now){
  for(int i=0; i<ab.at(now).size(); i++){
    if(ab.at(now).at(i)==parent) continue;
    ab2.at(now).push_back(ab.at(now).at(i));
    dfs2(ab,ab2,now,ab.at(now).at(i));
  }
}

ll dfs(vector<vector<int>> &ab, int now, int ban, ll &ans, int k, int depth){
  int l = min(depth,2);
  ans *= max(k-l-ban, 0);
  ans %= MOD;
  int m = ab.at(now).size();
  for(int i=0; i<m; i++){
    dfs(ab, ab.at(now).at(i), i, ans,k,depth+1);
  }
  return ans;
}

int main(){
  
  int n,k; cin>>n>>k;
  vector<vector<int>> ab(n);
  for(int i=0; i<n-1; i++){
    int a,b; cin>>a>>b;
    --a; --b;
    ab.at(a).push_back(b);
    ab.at(b).push_back(a);
  }
  vector<vector<int>> ab2(n);
  dfs2(ab,ab2,-1,0);
  ll ans{1};
  dfs(ab2,0,0,ans,k,0);
  cout << ans << endl;
  
  
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin>>s;
  ll l=s.size();
  if(s[0]==s[l-1])
    l-=3;
  else
    l-=2;

if(l%2==1)
  cout<<"First"<<endl;
else
  cout<<"Second"<<endl;
}



Measured memory_bytes: 512
from itertools import product
while True:
    d, w = map(int, input().split())
    if d == 0:
        exit()

    ans = 0
    e = [list(map(int, input().split())) for _ in range(d)]
    for si, sj in product(range(1, d - 1), range(1, w - 1)):
        for ti, tj in product(range(si + 1, d), range(sj + 1, w)):
            mx = 0
            for i, j in product(range(si, ti), range(sj, tj)):
                mx = max(mx, e[i][j])
            mn = 100
            for i, j in product([si - 1, ti], range(sj - 1, tj + 1)):
                mn = min(mn, e[i][j])
            for i, j in product(range(si - 1, ti + 1), [sj - 1, tj]):
                mn = min(mn, e[i][j])
            if mx >= mn:
                continue

            tmp = 0
            for i, j in product(range(si, ti), range(sj, tj)):
                tmp += mn - e[i][j]
            ans = max(ans, tmp)
    print(ans)




Measured memory_bytes: 5672
#include <bits/stdc++.h>
 
int main() {
    unsigned long long a, b;
    char s[6];
 
    scanf("%lld%s", &a, s);
    b = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0'); 
 
    printf("%llu\n", a*b/100);
 
    return 0;
}

Measured memory_bytes: 3784
N,M=map(int,input().split())
lab=[]
dn={}
for i in range(M):
    #lab.append(list(map(int,input().split())))
    a,b=map(int,input().split())
    lab.append([a,b])
    if not a in dn:
        dn[a]=[b]
    else:
        dn[a].append(b)
    if not b in dn:
        dn[b]=[a]
    else:
        dn[b].append(a)
ans=0
for i in range(M):
    #dtmp=copy.copy(dn)
    #for dd in dtmp:
    #    if dd[]
    st=[lab[i][0]]
    df={lab[i][0]:1}
    ng=lab[i][1]
    #while st:
    f=0
    for j in range(N):
    #while st:
        if not st:
            break
        ntmp=st.pop()
        if ntmp==ng:
            f=1
            break
        for nc in dn[ntmp]:
            if not nc in df and not (ntmp==lab[i][0] and nc==lab[i][1]):
                st.append(nc)
                df[nc]=1
    if f==0:
        ans+=1
print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
#include <vector>

using namespace std;

int S;
vector<int> seq;

int func(int n)
{
	if (n % 2 == 0) return n / 2;
	else return 3 * n + 1;
}

bool check()
{
	int n = seq.size();

	for (int i = 1; i < n; i++)
	{
		if (seq[n - 1] == seq[n - 1 - i]) return true;
	}

	return false;
}

int main()
{
	scanf("%d", &S);
	seq.push_back(S);

	while (check() == false)
	{
		seq.push_back(func(seq[seq.size() - 1]));
	}

	printf("%d", seq.size());

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
	int a,b,c;
  	cin >> a >> b >> c;
  	if(a == b) cout << c << endl;
    	if(c == b) cout << a << endl;
    	if(a == c) cout << b << endl;
    return 0;
}


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

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef STOP_DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <typename T>
lint gcd(T a, T b) {return b?gcd(b, a%b):a;}

template <typename T>
lint lcm(T a, T b) {return a * b / gcd(a, b);};

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

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

struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(0);
      cout << fixed << setprecision(17);
      cerr << fixed << setprecision(17);
    }
} IoSetup;

bool isPrime(int x) {
  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0) return 0;
  }
  return 1;
}

int main() {
  int x; cin >> x;
  while (!isPrime(x)) {
    ++x;
  }
  cout << x << '\n';
  return 0;
}


Measured memory_bytes: 256
while True:
    n = input().split()
    a = int(n[0])
    op = n[1]
    b = int(n[2])
    if op == '?':
        break
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)


Measured memory_bytes: 5592
def calc_min_diff(S):
        min_diff = None
        for i in range(len(S) -2):
                if min_diff is None:
                        min_diff = abs(753 - int(S[i:i + 3]))
                else:
                        min_diff = min(min_diff, abs(753 - int(S[i: i + 3])))
        return min_diff


print(calc_min_diff(input()))

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

int main(){
    int N;
    cin >> N;
    map<string, int> mp;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for(auto& p : mp) mx = max(mx, p.second);
    for(auto& p : mp) if(p.second == mx) cout << p.first << endl;
    return 0;
}


Measured memory_bytes: 25216
#include<cstdio>
using namespace std;
int main()
{
    char a[5],b[5],c[5];
    while(~scanf("%s%s%s",a,b,c))
    {
        putchar(a[0]);
        putchar(b[1]);
        putchar(c[2]);
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 128
#include "stdio.h"
#define goal 1
#define dead 2
#define end 0

int quit=1;

void print(int p[][17][17],int k){
	int i,j;
	for(i=16;i>=1;i--){
		for(j=1;j<17;j++){
			printf("%2d ",p[k][i][j]);
			if(j==16)printf("\n");
		}
	}
}

void initialize(int p[][17][17]){
	int i,j,k;
	for(k=0;k<2;k++){
		for(i=0;i<17;i++){
			for(j=0;j<17;j++){
				p[k][i][j] = 0;
			}
		}
	}
}

void count(int p[][17][17],int goalx,int goaly){
	int i,j,k;
	for(i=1;i<=goalx;i++) p[1][1][i] = 1;
	for(j=1;j<=goaly;j++) p[1][j][1] = 1;
	/*print(p,1);printf("\n");*//**/
	for(i=1;i<=goaly;i++){
		for(j=1;j<=goalx;j++){
			if(p[0][i][j]==dead){
				if(j==1){
					for(k=i;k<=goaly;k++){
						p[1][k][1] = 0;
					}
				}
				else if(i==1){
					for(k=j;k<=goalx;k++){
						p[1][1][k] = 0;
					}
				}
			}
			if(i>1&&j>1&&p[0][i][j]!=dead){
				p[1][i][j] = (p[1][i-1][j]+p[1][i][j-1]);
			}
		}
	}
	/*print(p,1);*//**/
}

int calc(int p[][17][17]){
	initialize(p);
	int i;
	int goalx,goaly;
	int deadx,deady;
	int deadnum;
	scanf("%d %d",&goalx,&goaly);
	if(goalx == 0 &&goaly == 0){
		quit = end;
		return 0;
	}
	/*printf("%d %d? end %d?\n",goalx,goaly,quit); *//**/
	getchar();
	scanf("%d",&deadnum);
	getchar();
	for(i=0;i<deadnum;i++){
		scanf("%d %d",&deadx,&deady);
		p[0][deady][deadx] = dead;
		getchar();
	}
	/*print(p,0);printf("\n");*//**/
	count(p,goalx,goaly);
	return p[1][goaly][goalx];
}
int main(){
	int road[2][17][17];
	int answer[5];
	int i=0;
	int j;
	while(1){
		if(quit == end)break;
		answer[i] = calc(road);
		i++;
	}
	for(j=0;j<i-1;j++)printf("%d\n",answer[j]);
	return 0;
}


Measured memory_bytes: 2036
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn calc(x: i64) -> i64 {
    if x <= 1 {
        1
    } else {
        2 * calc(x / 2) + 1
    }
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(h: i64);
    puts!("{}\n", calc(h));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

struct V
{
	explicit V(u32 idx)
	  : id(idx)
	{}

	u32 id;
	i32 n = -1;
	i32 root = -1;
	std::vector<u32> adj;

	void print()
	{
		std::clog << "V(id=" << id << ", n=" << n << ", root=" << root << ") adj: ";
		for(u32 i=0;i<adj.size();i++)
		{
			std::clog << adj[i] << " ";
		}
		std::clog << "\n";
	}

	void reset()
	{
		n = -1;
		root = -1;
	}
};

struct G
{
	explicit G(u32 n)
	{
		v.reserve(n);
		for(u32 i=0; i<n; i++)
		{
			v.push_back(V{i+1});
		}
	}

	V& vtx(u32 idx)
	{
		return v[idx-1];
	}

	void EdgeD(u32 a, u32 b)
	{
		vtx(a).adj.push_back(b);
	}
	
	void print()
	{
		for(u32 i=0;i<v.size();i++)
		{
			v[i].print();
		}
	}

	void reset()
	{
		for(u32 i=0;i<v.size();i++)
		{
			v[i].reset();
		}
	}

	std::vector<V> v;
};

i32 BFS(G& g, u32 src)
{
	std::list<u32> q;

	q.push_back(src);

	i32 n = 0;
	while(!q.empty())
	{
		u32 vi = q.front();
		V& v = g.vtx(vi);
		v.n = n;
		q.pop_front();

		for(u32 i=0; i<v.adj.size(); i++)
		{
			V& vadj = g.vtx(v.adj[i]);
			vadj.root = vi;
			if(vadj.id == src)
			{
				n++;
				vadj.n = n;
				return n;
			}
			if (vadj.n == -1)
			{
				q.push_back(vadj.id);
			}
		}
		n++;
	}

	return -1;
}

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	u32 n;
	u32 m;

	std::cin >> n >> m;

	G g{n};

	for(u32 i=0; i<m; i++)
	{
		u32 a;
		u32 b;
		std::cin >> a >> b;
		g.EdgeD(a, b);
	}

	std::vector<u32> path;
	path.reserve(n);

	i32 shortest_path = n+100;
	i32 shortest_path_i = -1;

	for(u32 i=1; i<=n; i++)
	{
		g.reset();
		i32 sp = BFS(g, i);
		if(sp != -1)
		{
			if (sp < shortest_path)
			{
				shortest_path_i = i;
				shortest_path = sp;
			}
		}
	}

	if(shortest_path_i != -1)
	{
		g.reset();
		u32 i = shortest_path_i;
		i32 sp = BFS(g, i);
		if(sp != -1)
		{
			u32 cur_v = g.vtx(i).root;
			while(cur_v != i)
			{
				path.push_back(cur_v);
				cur_v = g.vtx(cur_v).root;
			}
			path.push_back(cur_v);
		}
	}

	if(path.empty())
	{
		std::cout << "-1\n";
	}
	else
	{
		std::cout << path.size() << "\n";
		for(u32 i=0;i<path.size(); i++)
		{
			std::cout << path[i] << "\n";
		}
	}
	

	return 0;
}

Measured memory_bytes: 384
'use strict'
function main(i) {
  i = i.trim().split(' ')
  const Y = 2019
  const R = Number(i[1])
  const L = Number(i[0])
  let ans = Y - 1;

  if (L * R > Y){
    if (R - L < Y) {
      const LY = L % Y;
      const RY = R % Y;

      for(let i = LY; i < RY; i++){
        for(let j = i + 1; j <= RY; j++){
          let n = (i * j) % Y
          if (n < ans) ans = n
          if (ans === 0) break
        }
        if (ans === 0) break
      }
	    console.log(ans);
    } else {
      console.log(0);
    }
  } else {
    console.log(L * (L+1));
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf

int main(){
    char ch = getchar();
    if(ch == 'A') pr("T\n");
    if(ch == 'T') pr("A\n");
    if(ch == 'G') pr("C\n");
    if(ch == 'C') pr("G\n");
 	return 0;
}


Measured memory_bytes: 256
import sys
N = int(input())
a = [int(_) for _ in input().split()]

#+,-,+,-
asum = [0]*(N)
ansp = 0
if(a[0] <= 0):
    ansp+=1-a[0]
    asum[0]=1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansp+=1+asum[i]
            asum[i]=-1
        else:
            ansp+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansp)
#-,+,-,+,,,
ansn = 0
if(a[0] >= 0 ):
    ansn+=1+a[0]
    asum[0]=-1
else:
    asum[0] = a[0]
for i in range(1,N):
    asum[i] = asum[i-1] + a[i]
    if(asum[i-1]*asum[i] >= 0):
        if(asum[i-1]>0):
            ansn+=1+asum[i]
            asum[i]=-1
        else:
            ansn+=1-asum[i]
            asum[i]=1
# print(asum)
# print(ansn)
print(min(ansp,ansn))


Measured memory_bytes: 14332
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;


long long a, b, c,now, N, K, M, ans, A[100000], AA[100000];
string S, s;
bool h, k[101];

int main() {
	cin >> N >> K;
	if((N*K)%2==0)
		cout << "No" << endl;
	else {
		cout << "Yes" << endl;
	}
	return 0;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(q)]
ans=0
for com in combinations_with_replacement(range(m),n):
	t=0
	for a,b,c,d in L:
		if com[b-1]-com[a-1]==c:
			t+=d
	if t>ans:
		ans=t
print(ans)

Measured memory_bytes: 67832