akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define ll long long
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 1e5;

int n, s, lx, rx;
ll ans, lp, rp;
int x[N + 1], p[N + 1];

inline void solve()
{
	lx = 1;
	rx = n;
	lp = p[lx];
	rp = p[rx];
	int la = 0;
	while (s < x[rx] && s > x[lx]) {
		if (lp < rp) {
			if (la > lx || !la)
				ans += 1ll * (x[rx] - x[lx]);
			rp += lp;
			lx++;
			lp = p[lx];
			la = lx - 1;
		} else {
			if (la < rx || !la)
				ans += 1ll * (x[rx] - x[lx]);
			lp += rp;
			rx--;
			rp = p[rx];
			la = rx + 1;
		}
	}
	if (s > x[rx])
		ans += 1ll * (s - x[lx]);
	else
		ans += 1ll * (x[rx] - s);
	return;
}
int main()
{
	n = read();
	s = read();
	for (int i = 1; i <= n; i++) {
		x[i] = read();
		p[i] = read();
	}

	solve();

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4532
a, b, c= map(int, input().split())
if a<=b<=c:print(a, b, c)
if b<a<=c:print(b, a, c)
if a<=c<b:print(a, c, b)
if b<c<a:print(b, c, a)
if c<a<b:print(c, a, b)
if c<=b<=a:print(c, b, a)


Measured memory_bytes: 5592
#include <stdio.h>
#include <math.h>

int main()
{
	double D,d,a,b,x,y;
	while(scanf("%lf", &D), D)
	{
		scanf("%lf%lf%lf%lf",&a,&b,&x,&y);
		
		d=hypot(a,b);
		if(a*x+b*y>0)d=2-d;

		fabs(a*y-b*x)>1e-7||D<d?puts("impossible"):printf("%.8lf\n", d);
	}
}

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

typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;

#define MOD1        1000000007
#define MOD2        998244353
#define PI          3.1415926535897932384626433832795
#define FILL(a, value) memset(a, value, sizeof(a))
#define BOOST       ios_base::sync_with_stdio(false); cin.tie(NULL)
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ASSERT(left,operator,right) { if(!((left) operator (right))){ std::cerr << "ASSERT FAILED: " << #left << #operator << #right << " @ " << __FILE__ << " (" << __LINE__ << "). " << #left << "=" << (left) << "; " << #right << "=" << (right) << std::endl; } }

#define rep01(k,n)      for (ll i=k; i<n; i++)
#define rep02(k,n)      for (ll j=k; j<n; j++)
#define rep03(k,n)      for (ll k=k; k<n; k++)
#define rep11(k,n)      for (ll i=k; i<=n; i++)
#define rep12(k,n)      for (ll j=k; j<=n; j++)
#define rep13(k,n)      for (ll k=k; k<=n; k++)
#define repIT(c,it)     for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define all(c)      c.begin(), c.end()

using namespace std;

const double pi = acos(-1.0);
const double epsilon = 1e-9;        // Add epsilon when casting double to int to avoid rounding pitfall issues, eg, 0.94*8178 in int
const int maxn = 1e6+10;

void solve()
{
    
    ll n, m, x;
    cin >> n >> m >> x;

    vector<ll> a(n+1, 0);
    for(int i = 1; i <= m; i++)
    {
        int ind;
        cin >> ind;
        a[ind] = 1;
    }

    ll cost1 = 0, cost2 = 0;

    // for(int i = 0; i <= n; i++)
    //     cout << a[i] << " ";
    // cout << "\n";

    for(int i = 0; i <= x; i++)
        cost1 += a[i];

    for(int i = x; i <= n; i++)
        cost2 += a[i];

    //cout << cost1 << " " << cost2 << "\n";
    cout << min(cost1, cost2) << "\n";


}

int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
        solve();

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

Measured memory_bytes: 3748
s = input()

res = [0] * len(s)
cnt_r = 0
cnt_l = 0
curr = "R"
last_idx = 0

for idx, char in enumerate(s):
    if curr == "R":
        if char == "R":
            cnt_r += 1
            continue
        else:
            res[idx] += cnt_r // 2
            res[idx - 1] += (cnt_r - cnt_r // 2)
            last_idx = idx
            curr = "L"
            cnt_r = 0
            cnt_l = 1
            continue
    else:
        if char == "L":
            cnt_l += 1
            continue
        else:
            res[last_idx - 1] += cnt_l // 2
            res[last_idx] += cnt_l - (cnt_l // 2)
            curr = "R"
            cnt_l = 0
            cnt_r = 1

res[last_idx - 1] += cnt_l // 2
res[last_idx] += cnt_l - (cnt_l // 2)

print(*res)


Measured memory_bytes: 6400
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える


n = int(input())
s = str(input())

rb = [0,0]
for i in s:
    if i == "R":
        rb[0] += 1
    else:
        rb[1] += 1

if rb[0] > rb[1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14224
from collections import deque

H, W = [int(s) for s in input().split()]
Ch, Cw = [int(s) - 1 for s in input().split()]
Dh, Dw = [int(s) - 1 for s in input().split()]

fields = [list(input()) for _ in range(H)]
fields_num = [[-1] * W for _ in range(H)]
ok_field = '.'


def get_search_obj(i, j):
    ret = []
    moving_range = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    for dx, dy in moving_range:
        if 0 <= i + dx <= (H - 1) and 0 <= j + dy <= (W - 1) and fields[i + dx][j + dy] == ok_field:
            ret.append((i + dx, j + dy))
    return ret


def get_search_obj_cost2(i, j):
    ret = []
    moving_range = ((x, y) for x in range(- 2, 3) for y in range(- 2, 3))
    for dx, dy in moving_range:
        if 0 <= i + dx <= (H - 1) and 0 <= j + dy <= (W - 1) and fields[i + dx][j + dy] == ok_field:
            ret.append((i + dx, j + dy))
    return ret


def bfs(sx, sy):
    start = ((sx, sy), 0)
    dq = deque([start])
    visited = [[False] * W for _ in range(H)]
    while dq:
        (sx, sy), cost = dq.pop()
        if (sx, sy) == (Dh, Dw):
            return cost
        if visited[sx][sy]:
            continue
        else:
            visited[sx][sy] = True
        for x, y in get_search_obj(sx, sy):
            dq.append(((x, y), cost))
        for x, y in get_search_obj_cost2(sx, sy):
            dq.appendleft(((x, y), cost + 1))
    return -1


print(bfs(Ch, Cw))

Measured memory_bytes: 233060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
const int MOD = 1000000007;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}


int main() {
    int n; cin >> n; int first = 0,second = 0;vector<int> v,z;v.assign(n,0);z.assign(n,0);
    for(int i = 0;i < n;i++){
        cin >> v[i]; z[i] = v[i];
    }
    sort(z.begin(),z.end(),greater<int>());first = z[0]; second = z[1];
    for(auto x:v) first > x ? cout << first << endl: cout << second << endl;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n), bs(n), cs;
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> bs[i];
    }
    for (int i = 0; i < n; i++) {
        cs.push_back(as[i] - bs[i]);
    }
    sort(cs.begin(), cs.end());
    i64 dif = accumulate(as.begin(), as.end(), 0ll) - accumulate(bs.begin(), bs.end(), 0ll);
    if (dif < 0) {
        cout << -1 << endl;
        return 0;
    }
    int cnt = 0;
    i64 sum = 0;
    for (int i = 0; i < n && cs[i] < 0; i++) {
        cnt++;
        sum += cs[i];
    }

    if (sum == 0) {
        cout << 0 << endl;
        return 0;
    }

    for (int i = n - 1; i >= 0; i--) {
        sum += cs[i];
        cnt++;
        if (sum >= 0) {
            cout << cnt << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 2936
n = int(input())
a = [0 for i in range(n)]
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        xx, yy = map(int,input().split())
        x[i].append(xx)
        y[i].append(yy)
ans = 0
for i in range(2**n):
    ok = True
    for j in range(n):
        if ((1 << j) & i):
            for k in range(a[j]):
                if y[j][k] == 0:
                    if (1 << (x[j][k] - 1)) & i:
                        ok = False
                else:
                    if not((1 << (x[j][k] - 1)) & i):
                        ok = False
    if ok:
        cnt = 0
        while i:
            cnt += i & 1
            i >>= 1
        ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int s[10]={63,6,91,79,102,109,125,39,127,111},d=0,n,b=0,i;
int main()
{
	for(;d||(b=0,scanf("%d",&d),d!=-1);d--)
	{
		scanf("%d",&n);
		for(i=64,b^=s[n];i>=1;i/=2)
			printf("%d",(b&i)/i);
		b=s[n];
		puts("");
	}
	return 0;
}

Measured memory_bytes: 612
# coding: utf-8

a, b, c = map(int, input().split())
#print(str(a) + str(b) + str(c))

i = a
j = 0
if b <= c:
    while i <= b:
        if c % i == 0:
            #print(i)
            j += 1
        i += 1
else:
    while i <= c:
        if c % i == 0:
            #print(i)
            j += 1
        i += 1
print(j)


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

bool ok(ll n, ll k){
    ll r = n % k;
    if(r == 1){
        return true;
    }else if(r == 0){
        return ok(n/k, k);
    }
    return false;
}

int main(void)
{
    ll N;
    cin >> N;
    ll total = 2;
    if(N==2){
        cout << 1 << endl;
        return 0;
    }else if (N==3){
        cout << 2 << endl;
        return 0;
    }
    for(ll k=2;k*k<=N;k++){
        if(N%k == 0 && ok(N, k)){
            total++;
        }
    }
    for(ll k=2;k*k<=N-1;k++){
        if((N-1) % k == 0){
            total += 2;
            if(k*k==N-1){
                total--;
            }
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
import math
d, g = map(int, input().split())
questions = [list(map(int, input().split())) for _ in range(d)]
ans = 10**9

for i in range(2**d):
    score = 0
    problems = 0
    resindex = -1  # 完全に解いた問題以外で最も点数が高い問題
    for j in range(d):
        # print(i, j)
        # print(i >> j & 1)
        if i >> j & 1 == 1:
            # 完全にj+1問目を解いた時の合計点数
            score += (j+1)*100*questions[j][0] + questions[j][1]
            problems += questions[j][0]
        else:
            resindex = j
    # 完全に解いた問題だけで，目標点数を超えた場合
    if g <= score:
        ans = min(ans, problems)
    # 完全に解いた問題以外で最も点数が高い問題を全て解いて
    # 目標点を超える場合（ボーナス点は考慮しない）
    elif 0 <= resindex \
            and g <= score + questions[resindex][0]*(resindex+1)*100:
        problems += -(-(g-score) // ((resindex+1)*100))
        # problems += math.ceil((g-score) // ((resindex+1)*100))
        ans = min(ans, problems)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B;
    char op;
    cin >> A >> op >> B;

    if(op == '+') cout << A + B << endl;
    else cout << A - B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<long long int>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i = (a); i < (n); i++)
#define fi(i,a,n) for(i = (a); i <= (n); i++)
#define F first
#define S second
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,k;
    cin>>n>>k;

    string s;
    cin>>s;

    for(ll i=0;i<n;i++){
        if(i==(k-1)){
            cout<<(char)((int)s[i]+32);
        }
        else{
            cout<<s[i];
        }
    }

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm> // min()
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <climits> // INT_MAX
#include <cmath> // ceil()
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;
using ll = long long;
const int INF = INT_MAX;
using Graph = vector<vector<int>>;
using Vi = vector<int>;
using Vpii = vector<pair<int, int>>;
using Pii = pair<int, int>;

vector<int> to[100005];

int main() {
    int n, m;
    cin >> n >> m;

    int a, b;
    rep(i, m) {
        cin >> a >> b;
        --a; --b;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }

    queue<int> q;
    q.push(0);

    Vi pre(n, -1);
    pre[0] = INF;

    int v;
    int cnt = 1;
    while (!q.empty()) {
        v = q.front();
        q.pop();

        for (auto&& next_v : to[v]) {
            if (pre[next_v] != -1) continue;
            pre[next_v] = v;
            q.push(next_v);
            ++cnt;
        }
        if (cnt == n) break;
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; ++i) {
        cout << ++pre[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 10332
#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main() {
	string input;
	cin >> input;
	if (input[0] == 55 || input[1] == 55 || input[2] == 55) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3628
/**
 * Grading.cpp
 * Create:20180425
 * Description:与えられた英文に含まれる、
 * 各アルファベットの数を数えるプログラム。
 */
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <map>

int main(int argc, char* argv[]){
  // 文字列入力
  std::string input = "";
  std::string line;
  while (std::cin >> line){
    input += line;
  }

  // すべて小文字に変更
  std::transform(input.begin(), input.end(), input.begin(), tolower);

  // 辞書の作成
  std::map<char, int> mapci;
  for (int i = 'a'; i <= 'z'; i++){
    mapci[(char)i] = 0;
  }

  // カウント
  for (char c:input){
    mapci[c]++;
  }

  // 出力
  for (int i = 'a'; i <= 'z'; i++){
    std::cout << (char)i << " : " << mapci[char(i)] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
#define N 10000000
#define NOT_FOUND -1
int S[N],T[N],n,q;
int linearSearch(int[],int);

int main(){
    int i,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
      scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&T[i]);
    }

    for(i=0;i<q;i++){
		if(linearSearch(S,T[i])!=NOT_FOUND){
			cnt++;
		}
	}
    
	printf("%d\n",cnt);


    return 0;
}

int linearSearch(int A[N],int x){
         int i = 0,left,right,mid=0;
		 left = 0;
         right = n;
        
		 while(left < right){
			 mid = (left + right) / 2;
                if(A[mid] == x){
                    return mid;
                    }
                    else if(x < A[mid]){
                        right = mid;
                    }
                    else {
                        left = mid + 1;
                    }
		 }
	return NOT_FOUND;;
		
}



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

h, n = map(int, input().split())
a = ["" for _ in range(n)]
b = ["" for _ in range(n)]

for i in range(n):
    a[i], b[i] = map(int, input().split())

inf = 10**12
dp = [[inf for j in range(h+1)] for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
#print("dp", dp)
 
for i in range(n):
    for j in range(1,h+1):
        #print("-"*50)
        #print("i, j", i, j)
        if j <= a[i]:
            #print(str(j)+" <= a["+str(i)+"]", a[i])
            #print("b[i]", b[i])
            #print("dp[i][j]", dp[i][j])
            #print("dp[i+1][j] = min(): ", min(b[i], dp[i][j]))
            dp[i+1][j] = min(b[i], dp[i][j])
            
        else:
            #print(str(j)+" > a["+str(i)+"]", a[i])
            #print("dp[i][j]", dp[i][j])
            #print("dp[i+1][j - a[i]]+b[i]", dp[i+1][j - a[i]]+b[i])
            #print("dp[i+1][j] = min(): ", min(dp[i][j], dp[i+1][j - a[i]]+b[i]))
            dp[i+1][j] = min(dp[i][j], dp[i+1][j - a[i]]+b[i])
    #print(dp)
 
#print(dp)
print(dp[n][h])

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


int main() {
    int A,B; cin >> A >> B;
    int ans = -1;
    int x=10*B;
    while(x<=10*B+9 && x<=13*(A+1)){
        if((8*x)/100==A){
            ans = x;
            break;
        }
        else x++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void swap(int& x,int& y)
{
	int tmp = x; x = y; y = tmp;
}

int main()
{
	int a[5];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	
	for (int i=0; i<5; i++) {
		for (int j=4; j>i; j--) {
			if (a[j-1] < a[j]) swap(a[j-1], a[j]);
		}
	}
	
	cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << " " << a[4] << endl;
	
	return 0;
}

Measured memory_bytes: 3100
N = int(input())
A = list(map(int, input().split()))
 
count = 0
flag = False
while True:
  n = 0
  for n in range(N):
    if A[n] % 2 == 0: A[n] //= 2
    else:
      flag = True
      break
  if flag: break
  count += 1

print(count)

Measured memory_bytes: 9184
n = int(input())
numbers = [int(x) for x in input().split()]
r = 10**9 + 7

cum = [0] * n
cum[0] = numbers[0]
for i in range(1, n):
    cum[i] += cum[i - 1] + numbers[i]
    cum[i] %= r
   
ans = 0
for i in range(n - 1):
    tmp = numbers[i] * (cum[n - 1] - cum[i])
    tmp %= r
    ans += tmp
    ans %= r

print(ans)

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

int main() {
    int L; cin >> L;
    double x = L / 3.0;
    double ans = x * x * x;
    printf("%.15lf\n", ans);
    return 0;
}


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

int main(int argc, char const *argv[])
{   
    int r,g,b,n;cin>>r>>g>>b>>n;
    int cnt=0;
    for (int i=0;i<=n/r;++i){
        for(int j=0;j<=n/g;++j){
            int temp = n-r*i-g*j;
            // cout << temp << endl;
            if(temp%b==0 && temp/b>=0)cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
l = inp.shift().split(' ')
H = l[0] * 1
W = l[1] * 1 
for (i=0; i<H; i++) {
  b = false
  for (j=0; j<W; j++) {
    if (inp[i][j] == '#') {
      b = true
      if (i > 0) b = b && inp[i-1][j] == '.'
      if (i < H-1) b = b && inp[i+1][j] == '.'
      if (j > 0) b = b && inp[i][j-1] == '.'
      if (j < W-1) b = b && inp[i][j+1] == '.'
      if (b) {
        break;
      }
    }
  }
  if (b) {
    break;
  }
}
console.log(!b ? 'Yes' : 'No')

Measured memory_bytes: 7500
N = int(input())
A_list = []
for i in range(1,N+1):
    A = int(input())
    A_list.append(A)
A_list_sort = sorted(A_list)

max_a = A_list_sort[-1]
max_b = A_list_sort[-2]


for i in range(N):
    if A_list[i] == max_a:
        print(max_b)
    else:
        print(max_a)



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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

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

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;


int n, d, cnt[N], was[N];
void no(){
	cout << "Impossible";
	exit(0);
}
int main()
{                         
	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		cnt[x]++;
		d = max(d, x);
	}
	for(int i = 0; i <= d; i++){
		int x = max(i, d - i);
		if(cnt[x] == 0)
			no();
		cnt[x]--;
		if(i != 0 && i != d)
			was[x + 1] = 1;
	}
	for(int i = 0; i < N; i++)
		if(cnt[i] && !was[i])
			no();	
	cout << "Possible";
	return 0;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    string s;
    cin>>s;

    int n=s.length();
    if(s[n-1]=='s')
    	s+="es";
    else
    	s+="s";

    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}



int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n, k;
	cin>>n>>k;
	ld ans = 0;
	forn(i, 1, n+1){
		ll x = i;
		ll z = 0;
		while(x<k){
			x*=2;
			z++;
		}
		ans += ((1.0/n)*(pow(2, -z)));
		
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 4216
class UnionFind:
    __slots__ = ["N", "root"]

    def __init__(self, N):
        self.N = N
        self.root = [-1] * N

    def find(self, x):
        r = x
        while self.root[r] >= 0:
            r = self.root[r]

        while self.root[x] >= 0:
            self.root[x], x = r, self.root[x]

        return r

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.root[y] < self.root[x]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


import sys
input = sys.stdin.readline


def main():
    n, q = map(int, input().split())
    uf = UnionFind(n)
    res = []
    for _ in range(q):
        t, u, v = map(int, input().split())
        if t:
            res.append(int(uf.same(u, v)))
        else:
            uf.union(u, v)
    print("\n".join(map(str, res)))


main()


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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    double dx = 0,dy = 1;
    double x = 0, y = 0;
    double S; cin >> S;
    int K=0; 
    while(1) {
        K++;
        x += dx, y += dy;
        double s = dx,t = dy;
        dx = cos(S/180*PI)*s-sin(S/180*PI)*t;
        dy = sin(S/180*PI)*s+cos(S/180*PI)*t;
        if(abs(x)+abs(y) < 0.0001) break;
    }
    cout << K << endl;

    return 0;
}


Measured memory_bytes: 4092
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
# define ll  long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	ll n;
	cin >> n;
	ll num = 0;
	for(int i = 1; i <= 1e7; i++){
		num = (num*10 + 7)%n;
		if(num == 0){
			cout << i;
			return;
		}
	}
	cout << -1;
}

int  main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
     IOS
     int t = 1;
     //cin >> t;
     while(t--){
     	solve();
     }
     return 0;
}

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

int n, m;
int ans = 0; 

int main(){
  cin >> n >> m;
  vector<int> l(m), r(m);
  
  rep(i, m){
    cin >> l.at(i) >>  r.at(i);
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  
  if((r.at(0) - l.at(m-1)) >= 0) ans = r.at(0) - l.at(m-1) + 1;
  cout << ans << endl; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int NN = 1e6+10;
typedef long long ll;

int N,M;
vector<int> ve[NN];
priority_queue<int> q;
int main(){
//	freopen("test.in","r",stdin); 
	cin>>N>>M;
	for(int i = 1;i<=N;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a>M) continue;
		ve[M-a+1].push_back(b); //表示M-a+1天之后不能做此份工作(也就是做了赚不到钱) 
	}
	ll earn = 0;
	for(int i = M;i>=1;i--){
		for(int m:ve[i]){
			q.push(m);
		}
		if(!q.empty()){
			earn += q.top();
			q.pop();
		}
	}
	cout<<earn<<endl;
	
	return 0;
}

Measured memory_bytes: 26752
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
 
#define out(t) cout << (t) << "\n"
 
using namespace std;
 
typedef long long ll;
 
void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n;
    cin >> n;
 
    string s = to_string(n);
 
    ll f = 0;
    for (int i = 0; i < s.length(); i++) {
        f += s[i] - '0';
    }
 
    out(n % f ? "No" : "Yes");
 
    int ttttttt;
    cin >> ttttttt;
}

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

using namespace std;
#define ll long long
#define endl "\n"
#define least_one_pos(x) __builtin_ffs(x)
#define leading_zeros(x) __builtin_clz(x)
#define tailing_zeros(x) __builtin_ctz(x)
#define num_of_one(x) __builtin_popcount(x)

int main(int argv, char **args) {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
      ll x;
      ll a,b,i,sum=0;
      cin>>x;
      for(i=1; ;i++)
      {
      	sum+=i;
      	if(sum>=x)
      	{
      		cout<<i<<endl;
      		return 0;
		  }
	  }
     
   
    return 0;
}


Measured memory_bytes: 3620
def main():
  A, B, K = map(int, input().split(" "))
 
  i = 1
  result = []
  while i <= min(A, B):
    if A % i == 0 and B % i == 0:
      result.append(i)
    i += 1
  print(result[-K])
  
if __name__ == '__main__':
  main()

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

#define ll long long
#define ii pair<int,int>
#define INF 1e9 + 7
#define vi vector<int>
#define vvi vector<vi>
#define add emplace_back
#define A 0
#define B 1
#define C 2

int main(){ios_base::sync_with_stdio(false);
   
    int n;
    cin >> n;
    vi a(n+1), b(n+1), c(n+1);
    for(int i=1; i<=n; ++i) cin >> a[i] >> b[i] >> c[i];

    vvi dp(n+1, vi(3));
    dp[0][A] = dp[0][B] = dp[0][C] = 0;
    for(int i=1; i<=n; ++i){
        dp[i][A] = max(dp[i-1][C], dp[i-1][B]) + a[i];
        dp[i][B] = max(dp[i-1][A], dp[i-1][C]) + b[i];
        dp[i][C] = max(dp[i-1][A], dp[i-1][B]) + c[i];
    }
    int ans = max(dp[n][A], max(dp[n][B], dp[n][C])); 
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
using vint = vector<int>;
using vvint = vector<vint>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
constexpr double pi = 3.1415926535897932384626433832795028L;

int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int sigma_2(int n) {
  if (n == 0) {
    return 0;
  }
  return n + sigma_2(n - 1);
}
int sum_range(int a, int b) {
  if (a == b) {
    return a;
  }
  return sum_range(a, b - 1) + b;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}

int array_sum_from_i(vint &data, int i) {
  if (i == data.size()) {
    return 0;
  }
  int s = array_sum_from_i(data, i + 1);
  return data[i] + s;
}
int array_sum(vint &data) {
  return array_sum_from_i(data, 0);
}
bool has_divisor(int N, int i) {
  if (i == N) {
    return false;
  }
  if (N % i == 0) {
    return true;
  }
  return has_divisor(N, i + 1);
}

bool is_prime(int N) {
  if (N == 1) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else {
    return !has_divisor(N, 2);
  }
}
bool is_even(int);
bool is_odd(int);

bool is_even(int n) {
  if (n == 0) {
    return true;
  }
  return is_odd(n - 1);
}

bool is_odd(int n) {
  if (n == 0) {
    return false;
  }
  return is_even(n - 1);
}







signed main() {
    int N,K;
    cin >> N >> K;
    int x=N%K;
    int min = x;
    while(true){
        x = abs(x-K);
        if(min > x){
            min = x;
        }
        else{
            cout << min << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
bn = 4
fn = 3
rn = 10
room = [0]*bn*fn*rn

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    num = (b-1)*fn*rn + (f-1)*rn + (r-1)
    room[num] += v

for b in range(1, bn+1):
    for f in range(1, fn+1):
        for r in range(1, rn+1):
            num = (b-1)*fn*rn + (f-1)*rn + (r-1)
            print(' %d' % room[num], end='')
        print()
    if b < bn:print('#'*20)


Measured memory_bytes: 5616
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
ll a[100001],b[100001],c[100001];
int main(void){
    ll n,answer=0;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n; i++)
        cin >> b[i];
    for(int i = 0; i < n; i++)
        cin >> c[i];
    sort(a,a+n);
    sort(c,c+n);
    for(int i = 0; i < n; i++){
        answer += (lower_bound(a,a+n,b[i])-a)*((c+n)-upper_bound(c,c+n,b[i]));
    }
    cout << answer << endl;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll N, M;
vector<ll> A;

int main(int argc, char **argv)
{
	cin >> N >> M;
	A.resize(N);
	REP(i, N) cin >> A[i];
	A[0] %= M;
	REP(i, N-1)
		(A[i+1] += A[i]) %= M;

	map<ll, ll> m;
	for (auto &e : A)
		++m[e];

	ll res{0};
	for (auto &p : m)
	{
		// std::cout << p.first << std::endl;
		// std::cout << p.second << std::endl;
		// std::cout << std::endl;
		res += p.second * (p.second-1) / 2;
		if (p.first == 0)
			res += p.second;
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 4992
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  string s;
  map<string,int> map;
  rep(i,n){
    cin>>s;
    map[s]++;
  }
  cout<<"AC x "<<map["AC"]<<endl;
  cout<<"WA x "<<map["WA"]<<endl;
  cout<<"TLE x "<<map["TLE"]<<endl;
  cout<<"RE x "<<map["RE"]<<endl;
}


Measured memory_bytes: 3664
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
        q: usize,
        bc: [(i64, i64); q]
    };

    let mut sum = 0_i64;
    let mut map = std::collections::BTreeMap::new();
    for &a_i in a.iter() {
        *map.entry(a_i).or_insert(0) += 1_i64;
        sum += a_i;
    }

    for &(b_i, c_i) in bc.iter() {
        if map.contains_key(&b_i) {
            let count = map[&b_i];
            sum += count * c_i;
            sum -= count * b_i;
            map.remove(&b_i);
            *map.entry(c_i).or_insert(0) += count;
        }
        println!("{}", sum);
    }
}


Measured memory_bytes: 7896
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S, T = "keyence";

int main(){
  cin >> S;

  for (int i = 0; i <= 7; i++){
    bool flag = true;

    for (int j = 0; j < i; j++){
      if (S[j] != T[j]) flag = false;
    }
    for (int j = i; j < 7; j++){
      if (S[S.length() - 7 + j] != T[j]) flag = false;
    }

    if (flag){
      YES(); return 0;
    }
  }
  NO();
  return 0;
}


Measured memory_bytes: 256
while True :
    n, x = map(int, input().split())
    count = 0
    if n == 0 and x == 0 :
        break

    for i in range(1, n - 1) :
        for j in range(i + 1, n) :
            k = x - (i + j)
            if j < k <= n :
                count += 1
    print(count)




Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
//最初に設定する.
const ll MOD=998244353;
const int  MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];  void modcinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long modc(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; }
int main( ){
    modcinit();
    ll N,M;
    ll K;
    cin>>N>>M>>K;
    ll ans=0;
    ll mod=MOD;
    rep(i,0,K+1){
       ll add=((M*modc(N-1,i)%mod+mod)%mod*modpow(M-1,N-1-i,mod)%mod+mod)%mod;
       ans=((add+ans)%mod+mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 15572
#include <bits/stdc++.h>
using namespace std;
int N, A[100], res;

void Out() {
	cout << A[0];
	for (int i = 1; i < N; i++)
		cout << ' ' << A[i];
	cout << endl;
}

void SelectionSort() {
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			int tmp = A[i];
			A[i] = A[minj];
			A[minj] = tmp;
			res++;
		}
	}
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
	SelectionSort();
	Out();
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3092
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
import bisect

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()


x = 0
k = readInt()
a = 7%k
ans = 0
for i in range(10**6+1):
  x = (x*10%k+a)%k
  ans += 1
  if x==0:
    print(ans)
    exit()

print(-1)

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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, M = 1e5 + 9, OO = (int) 1e6 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(0);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void READ() {
	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
}
ll n, k, heights[N], mem[N];

ll dp(int i) {
	if (i >= n)
		return OO;
	if (i == n - 1)
		return 0;
	if (mem[i] != -1)
		return mem[i];
//	mem[i] = OO;
	for (int j = 1; j <= k; j++) {
		if (j == 1)
			mem[i] = dp(i + j) + abs(heights[i] - heights[i + j]);
		else
			mem[i] = min(mem[i], dp(i + j) + abs(heights[i] - heights[i + j]));
	}
	return mem[i];
}

int main() {
//	READ();
	OUTPUT();
	clr(mem, -1);
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> heights[i];
	}
	cout << dp(0);

	return 0;

}


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

int main()
{
    int tc,max;
    int cost,time;
    int temp = 9999;
    scanf("%d %d",&tc,&max);
    for(int x=1;x<=tc;x++)
    {
        scanf("%d %d",&cost,&time);
        if(time<=max && cost<temp)
        {
            temp = cost;
        }
    }
    if(temp!= 9999) printf("%d\n",temp);
    else printf("TLE\n");
    
    return 0;
}

Measured memory_bytes: 128
from collections import deque
s = deque(input())
q = int(input())

flag = 0
for _ in range(q):
  query = list(map(str, input().split()))
  if query[0] == "1": flag = 1 - flag
  else:
    if query[1] == "1":
      if flag == 0: s.appendleft(query[2])
      else: s.append(query[2])
    else:
      if flag == 0: s.append(query[2])
      else: s.appendleft(query[2])

if flag == 1: s.reverse()
print(*s, sep="")

Measured memory_bytes: 16688
N = gets.chomp.to_i
dAry = Array.new(N){ gets.chomp.split(' ').map(&:to_i) }

maxCnt = 0
cnt = 0
dAry.each do |d|
    if d[0] == d[1] then
        cnt += 1
        maxCnt = [maxCnt, cnt].max
    else
        cnt = 0
    end
end
puts maxCnt >= 3 ? "Yes" : "No"

Measured memory_bytes: 14328
N = int(input())
C = list(map(int,input().split()))

dp = [-1 for _ in range(N)]

dp[0] = 0
dp[1] = abs(C[0] - C[1])

for i in range(0,N-2):
    dp[i+2] = min(dp[i] + abs(C[i+2]-C[i]) , dp[i+1] + abs(C[i+2] - C[i+1]))

print(dp[N-1]) 


Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, a, b;
    cin >> n >> a >> b;
    if(n == 1) {
        if(a == b) {
            cout << 1 << "\n";
            return 0;
        }
        else {
            cout << 0 << "\n";
            return 0;
        }
    }
    n -= 2;
    ll mn = (ll)n * a;
    ll mx = (ll)n * b;
    cout << max(0LL, mx - mn + 1) << "\n";
    return 0;
}

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

public class Main {
	
	public static int[][] DP = new int[20001][256];
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			if(N == 0 && M == 0){
				break;
			}
			
			short[] data = new short[N];
			short[] code = new short[M];
			
			for(int i = 0; i < M; i++){
				code[i] = sc.nextShort();
			}
			
			for(int i = 0; i < N; i++){
				data[i] = sc.nextShort();
			}
			
			for(int i = 0; i <= N; i++){
				Arrays.fill(DP[i], Integer.MAX_VALUE);
			}
			
			DP[0][128] = 0;
			for(int i = 0; i < N; i++){
				for(int j = 0; j < 256; j++){
					if(DP[i][j] != Integer.MAX_VALUE){
						for(int c = 0; c < M; c++){
							final int next = Math.max(0, Math.min(j + code[c], 255));
							final int diff = (data[i] - next) * (data[i] - next);
							DP[i+1][next] = Math.min(DP[i+1][next], DP[i][j] + diff);
						}
					}
				}
			}
			
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < 256; i++){
				min = Math.min(min, DP[N][i]);
			}
			
			System.out.println(min);
		}
		
	}

}

Measured memory_bytes: 91468
#include<iostream>

using namespace std;

const int N(1e5 + 9);

int n, m;
long long ans;
long long a[N], f[N][2];

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	f[1][0] = a[1];
	f[1][1] = -a[1];
	for (int i=2;i<=n;i++)
	{
		f[i][0] = max(f[i - 1][0] + a[i], f[i - 1][1] - a[i]);
		f[i][1] = max(f[i - 1][0] - a[i], f[i - 1][1] + a[i]);
	}
	cout<<f[n][0]<<endl;
	return 0;
}

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

int main() {
	// your code goes here
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b+c||b==a+c||c==a+b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define INF 1000000000
#define debug3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n";
#define debug2(index, value) cout << index << " " << value << "\n";
#define debug1(value) cout << value << "\n";
#define openfile(string1, string2) \
    freopen(string1, "r", stdin);  \
    freopen(string2, "w", stdout);
using namespace std;

void solve() {
    string s, t;
    getline(cin, s);
    getline(cin, t);
    int res = t.length();

    // cout << s.length() << endl;
    // cout << t.length() << endl;
    for (int i = 0; i <= s.length() - t.length(); i++) {
        int unmatch = 0;
        for (int j = 0; j < t.length(); j++)
            if (t[j] != s[i + j]) unmatch++;
        res = min(res, unmatch);
    }
    cout << res << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // openfile("input.txt", "output.txt");
    solve();

    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    long[][] stu = new long[N][2];
    long[][] poi = new long[M][2];
    for(int i = 0; i < N; i++){
      stu[i][0] = sc.nextLong();
      stu[i][1] = sc.nextLong();
    }
    for(int i = 0; i < M; i++){
      poi[i][0] = sc.nextLong();
      poi[i][1] = sc.nextLong();
    }
    for(int i = 0; i < N; i++){
      int minIndex = -1;
      long minDis = Long.MAX_VALUE;
      for(int j = 0; j < M; j++){
        long tmpDis = Math.abs(stu[i][0]-poi[j][0]) + Math.abs(stu[i][1]-poi[j][1]);
        if(minDis > tmpDis){
          minDis = tmpDis;
          minIndex = j+1;
        }
      }
      System.out.println(minIndex);
    }
  }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007 
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN


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



void init(){
    
}

void solve( ll  tst ){
    ll n,m;
    cin>>n>>m;
    ll sum = 0;
    for( ll i=0;i<m;i++ ){
        ll tx;
        cin>>tx;
        sum+=tx;
    }
    cout<<max(-1LL, n-sum);
    return;
}

int main(){
    FAST;
    init();
    //cout<<"init"<<endl;
    ll t = 1;
    //cin>>t;
    for (ll i=1;i<=t;i++ ) solve(i);
    return 0;
} 

Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>

const int MAXN = 1e5, INF = 0x3f3f3f3f;
int n, val[MAXN + 5], cnt[16], f[1 << 16], xsum[1 << 16];

inline void chkmin ( int& a, const int b ) { if ( b < a ) a = b; }

int main () {
	scanf ( "%d", &n );
	for ( int i = 1, u, v, w; i < n; ++ i ) {
		scanf ( "%d %d %d", &u, &v, &w );
		val[u] ^= w, val[v] ^= w;
	}
	int ans = 0, S = 0;
	for ( int i = 0; i < n; ++ i ) ++ cnt[val[i]];
	for ( int i = 1; i < 16; ++ i ) {
		S |= ( cnt[i] & 1 ) << i >> 1;
		ans += cnt[i] >> 1;
	}
	for ( int i = 1; i < 1 << 15; ++ i ) {
		for ( int j = 0; j < 15; ++ j ) {
			if ( ( i >> j ) & 1 ) {
				++ f[i], xsum[i] ^= j + 1;
			}
		}
		-- f[i];
	}
	for ( int s = 0; s < 1 << 15; ++ s ) {
		if ( xsum[s] ) continue;
		for ( int t = s; ; t = ( t - 1 ) & s ) {
			if ( ! xsum[t] && ! xsum[s ^ t] ) chkmin ( f[s], f[t] + f[s ^ t] );
			if ( ! t ) break;
		}
	}
	printf ( "%d\n", ans + f[S] );
	return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(a) ((int) (a).size())
#define nl '\n'
#define sp ' '

int D, N;

int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> D >> N;
    int base = 1;
    for (int i = 0; i < D; i++) base *= 100;
    cout << base * (N + (N == 100)) << nl;
    return 0;
}


Measured memory_bytes: 256