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

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while (true) {
    if (cur == nil) break;
    if (isf++ > 0) cout << " ";
    cout << cur->key;
    cur = cur->next;
  }
  cout << endl;
}

void deleteNode(Node* t) {
  if (t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n;
  char com[20];
  scanf("%d", &n);
  init();
  for (int i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key);
    } else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') {
          deleteFirst();
        } else if (com[6] == 'L') {
          deleteLast();
        }
      } else {
        deleteKey(key);
      }
    }
  }
  printList();
  return 0;
}



Measured memory_bytes: 34408
#include <bits/stdc++.h>
#define MOD 998244353

using namespace std;

typedef long long ll;

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

    vector<pair<ll, ll>> p(N);
    vector<ll> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        p[i].second = A[i];
    }

    for (int i = 0; i < N; i++)
    {
        cin >> p[i].first;
    }

    sort(p.begin(), p.end());
    sort(A.begin(), A.end());

    for (int i = 0; i < N; i++)
    {
        if (A[i] > p[i].first)
        {
            cout << "No";
            return 0;
        }
    }

    bool possible = false;
    for (int i = 0; i < (N - 1); i++)
    {
        if (A[i + 1] <= p[i].first)
        {
            possible = true;
        }
    }

    unordered_map<int, int> transition;
    for (int i = 0; i < N; i++)
    {
        transition[p[i].second] = i;
    }

    int i = 0, cnt = 0;
    vector<bool> used(N);

    while (!used[i])
    {
        used[i] = true;
        i = transition[A[i]];
        cnt++;
    }

    if (cnt != N)
    {
        possible = true;
    }

    cout << (possible ? "Yes" : "No");
}

Measured memory_bytes: 6692
# pragma GCC optimize("Ofast")
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    vector<double> dice(n,0);
    vector<double> point(n,0);
    rep(i,n){
        cin >> dice[i];
        point[i] = (1.0 + dice[i])/2.0; //期待値
    }


    double max = 0;
            double sum = 0;
    rep(i,n-k+1){
        if(i == 0){    
            rep(j,k){
                sum += point[i+j];
            }
        }else{
            sum -= point[i-1];
            sum += point[i+k-1];
        }
        chmax(max,sum);
    }
    cout << fixed << setprecision(12) << max;


    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for(auto &a : A) cin >> a;
	vector<ll> one(62, 0), zero(62, 0);
	for(auto &a : A) {
		for(int i=0;i<62;i++) {
			if((a >> i) & 1) one[i]++;
			else zero[i]++;
		}
	}
	ll ans = 0;
	ll bit = 1;
	for(int i=0;i<62;i++) {
		ans += ((zero[i] * one[i]) % MOD) * bit;
		bit *= 2;
		bit %= MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
int main(void){
    
    int i,j,h,w;
    scanf("%d%d",&h,&w);
    char c[h+1][101];
    
    for(i=0;i<h;i++){
    scanf("%s",c[i]);
    for(j=0;j<2;j++)
    printf("%s\n",c[i]);
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
bool DEBUG = false;


int main(){
    int N;
    cin >> N;
    int p[N];
    for(int i = 0; i < N; i++) {
        cin >> p[i];
    }


    // 最初の判定
    bool success = true;
    for(int k = 0; k < N-1; k++) {
        if(p[k] > p[k+1]){
            success = false;
        }
    }
    if(success){
        cout << "YES" << endl;
        return 0;
    }

    for(int i = 0; i < N-1; i++) {
        for(int j = i+1; j < N; j++) {
            bool success = true;
            int q[N];
            for(int k = 0; k < N; k++) {
                q[k] = p[k];
            }

            int tmp = q[i];
            q[i] = q[j];
            q[j] = tmp;

            for(int k = 0; k < N-1; k++) {
                if(q[k] > q[k+1]){
                    success = false;
                }
            }

            if(success){
                if(DEBUG){
                    for(int k = 0; k < N; k++) {
                        cout << q[k] << endl;
                    }
                }
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    int N, D;
    cin >> N >>D;
    cout << (int)ceil((double)N/(D*2+1)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n, m; cin >> n >> m;
    vector<int> A(n);
    int sum = 0;
    for(int i = 0; i < m; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    if(sum > n)
    {
        cout << -1 << endl;
        return;
    }
    cout << n - sum << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 7164
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
from functools import reduce

def main():
    H, N = MI()
    A = []
    B = []
    A_B = []
    for i in range(N):
        a, b = MI()
        A.append(a)
        B.append(b)
    max_A = max(A)
    #dp[i]=体力iを削るのに必要な最小魔力
    dp = [10 ** 9] * (H + max_A)
    dp[0] = 0
    for j in range(N):
        a_j = A[j]
        b_j = B[j]
        for i in range(H + max_A):
            if i - a_j >= 0:
                dp[i] = min(dp[i - a_j] + b_j, dp[i])
            else:
                dp[i] = min(b_j, dp[i])

    ans = min(dp[H:H + max_A])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 75120
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>

using namespace std;

typedef complex<double> P;
double sq(double x){return x*x;}

double cross(P x,P y){
	return x.real() * y.imag() - x.imag() * y.real();
}

char s[8][9];

char solve()
{
	
	vector<pair<int,int> > mino;
	for (int i = 0; i < 8; i++)
		for (int j = 0; j < 8; j++)
			if(s[i][j] == '1') mino.push_back(pair<int,int>(i,j));

	int hsum = 0,wsum = 0;
	for (int i = 1; i < 4; i++)
	{
		hsum += mino[i].first - mino[0].first;
		wsum += mino[i].second - mino[0].second;
	}
	if(hsum ==2 && wsum == 2) return 'A';
	else if(hsum == 6 && wsum == 0) return 'B';
	else if(hsum == 0 && wsum == 6) return 'C';
	else if(hsum == 4 && wsum == -2) return 'D';
	else if(hsum == 2 && wsum == 4) return 'E';
	else if(hsum == 4 && wsum == 2) return 'F';
	else return 'G';

}

int main(){
	while(true){
		for (int i = 0; i < 8; i++)
			if(!(cin>>s[i])) return 0;

		char ans = solve();
		printf("%c\n",ans);
	}
	return 0;
}

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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
LL c(LL a,LL b){
	return a%b?1:0;
}
LL ans;
int main(){
	ios::sync_with_stdio(false);
	LL n,a,b,c,d,e;
	cin>>n>>a>>b>>c>>d>>e;
	if(n<=a)ans=max(ans,5ll);
	else {
		ans=max(ans,(n-a)/a+((n-a)%a?1:0)+5);
	}
	if(n<=b)ans=max(ans,5ll);
	else {
		ans=max(ans,(n-b)/b+((n-b)%b?1:0)+5);
	}
	if(n<=c)ans=max(ans,5ll);
	else{
		ans=max(ans,(n-c)/c+((n-c)%c?1:0)+5);
	}

	if(n<=d)ans=max(ans,5ll);
	else{
		ans=max(ans,(n-d)/d+((n-d)%d?1:0)+5);
	}
	if(n<=e)ans=max(ans,5ll);
	else{
		ans=max(ans,(n-e)/e+((n-e)%e?1:0)+5);
	}
	cout<<ans;
	return 0;
}

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


int main() {
  double W, H;
  int x, y;
  cin >> W >> H >> x >> y;
  cout << W * H / 2 << endl;
  if (x == W / 2 && y == H / 2) {
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
  
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <istream>
#include <map>
#include <ostream>
namespace ac {
    using namespace std;
}
using namespace std;
using namespace ac;
namespace ac {
    template<typename T> map<T, bool> sieveOfEratosthenes(T n) {
        map<T, bool> res;
        res[0] = false;
        res[1] = false;
        for (size_t i = 2; i <= (size_t)n; i++) {
            res[i] = true;
        }
        // size_t p = 0;
        for (size_t i = 2; i <= (size_t)n; i++) {
            if (res[i]) {
                // prime[p++] = i;
                for (size_t j = 2 * i; j <= (size_t)n; j += i) {
                    res[j] = false;
                }
            }
        }
        return res;
    }
}
int table2017[100005];
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        auto s = sieveOfEratosthenes(100005);
        for (int i = 1; i <= 100000; i++) {
            table2017[i] = (s[i] && s[(i + 1) / 2]) + table2017[i - 1];
        }
        for (int i = 0; i < n; i++) {
            int l, r, ans = 0;
            in >> l >> r;
            ans = table2017[r] - table2017[l - 1];
            out << ans << '\n';
        }
    }
};
void solve(std::istream& in, std::ostream& out) {
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

struct Point{
  double x,y;

  Point(double x = 0,double y = 0) : x(x), y(y) {}

  Point operator + (const Point &p)const{
    return Point(x + p.x , y + p.y);
  }

  Point operator - (const Point &p)const{
    return Point(x - p.x , y - p.y);
  }

  Point operator * (const double &k)const{
    return Point(x * k , y * k);
  }

  Point operator / (const double &k)const{
    return Point(x / k , y / k);
  }
  double norm(){
    return x*x + y*y;
  }
  double dot(const Point &p)const{
    return x*p.x + y*p.y;
  }
};
typedef Point Vector;

struct Segment{
  Vector s, t;

  Segment(){}
  Segment(Vector s, Vector t) : s(s), t(t) {}

  Point projection(Point p){
    Vector base = t - s;
    double t = (p-s).dot(base) / base.norm();
    return s + base*t;
  }
};

int main(){
  Point p1, p2, p3;
  int q;

  std::cin >> p1.x >> p1.y >> p2.x >> p2.y >> q;
  Segment s = Segment(p1, p2);
  for(int i = 0 ; i < q ; i++){
    std::cin >> p3.x >> p3.y;
    Point p = s.projection(p3);
    printf("%.10f %.10f\n",p.x ,p.y);
  }

  return 0;
}

Measured memory_bytes: 1248
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> v(n);
	for (auto &x : v)
		cin >> x;
	sort(v.begin(), v.end());
	vector<int> g(n);
	for (int i = 0; i < v.size(); ++i) {
		int take = min(v[i], x);
		g[i] = take;
		x -= take;
	}
	int res = 0;
	for (int i = 0; i < n; ++i)
		if (g[i] == v[i])
			++res;
	if (x)
		--res;
	cout << res << endl;
	return 0;
}

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

using namespace std;

const int oo = 1e9;

int n, m, x;
int Sum[15], c[15], a[15][15];

int GetBit(int num, int pos)
{
    return (num >> pos) & 1;
}

int test(int k)
{
    memset(Sum, 0, sizeof(Sum));
    int Res = 0;
    for (int i = 0; i < n; i++)
    {
        if (GetBit(k, i))
        {
            Res += c[i];
            for (int j = 0; j < m; j++)
            {
                Sum[j] += a[i][j];
            }
        }
    }
    bool flag = *min_element(Sum, Sum + m) >= x;
    return (flag ? Res : oo);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    int p2n = (1 << n), ans = oo;
    for (int i = 0; i < p2n; i++)
    {
        ans = min(ans, test(i));
    }
    cout << (ans == oo ? -1 : ans);
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;
     
    public class Main{
      public static void main(String[] args){
    	Scanner in=new Scanner(System.in);
    	String S=in.next();
        if(S.charAt(0)==S.charAt(1))
          System.out.println("Bad");
        else if(S.charAt(1)==S.charAt(2))
          System.out.println("Bad");
        else  if(S.charAt(2)==S.charAt(3))
          System.out.println("Bad");
        else
        	System.out.println("Good");
        in.close();
      }
    }

Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>

int main(void){
	int i,j,k;
	char S[11];
	int len;
	
	scanf("%s",S);
	len=strlen(S);
	int ans=0;
	int flag=0;
	for(i=1;i<=len;i++){//長さ
		for(j=0;j<=len-i;j++){//最初の位置
			flag=1;
			for(k=j;k<j+i;k++){//検索位置
				if(S[k]!='A' && S[k]!='C' && S[k]!='G' && S[k]!='T')flag=0;
			}
			if(flag==1)ans=i;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<int> a(n, 0);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());

	int aa = 0;
	int bb = 0;
	for (int i = 0; i < n-1; i=i+2) {
		aa += a[i];
		bb += a[i + 1];
		if (i == n - 3) { aa += a[n - 1]; }
	}
	cout << aa - bb << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(" ").map(String::toInt)
    val s = Array(h, { Array(w, { "." }) })
    for (i in 0..(h - 1)) {
        s[i] = readLine()!!.split("").filter { it.isNotEmpty() }.map(String::toString).toTypedArray()
    }

    var result = true
    for (i in 0..(h - 1)) {
        for (j in 0..(w - 1)) {
            if (checkBlack(s, i, j).not()) result = false
        }
    }

    println(if (result) "Yes" else "No")
}

fun checkBlack(s: Array<Array<String>>, i: Int, j: Int): Boolean {
    if (s[i][j] == ".") return true

    var (ue, migi, sita, hidari) = arrayOf(false, false, false, false)
    if (i != 0 && s[i - 1][j] == "#") ue = true
    if (j != 0 && s[i][j - 1] == "#") hidari = true
    if (i != (s.size - 1) && s[i + 1][j] == "#") sita = true
    if (j != (s[0].size - 1) && s[i][j + 1] == "#") migi = true

    return ue || hidari || sita || migi
}

Measured memory_bytes: 36060
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const auto MOD = static_cast<ll>(1e9 + 7);

ll N, ans;
vector<bool> prime;
vector<ll> memo;

int main() {
    cin >> N;
    prime.resize(N + 1, true); memo.resize(N + 1, 0);
    prime[0] = prime[1] = false;
    for (size_t i = 2; i * i <= N; i++) {
        if (prime[i]) {
            for (size_t j = 2; i * j <= N; j++) {
                prime[i * j] = false;
            }
        }
    }
    for (auto i = 1; i <= N; i++) {
        ll div = 2;
        ll n = i;
        while (n > 1) {
            while (!(n % div)) {
                n /= div;
                memo[div]++;
            }
            while (!prime[++div]);
        }
    }
    ans = 1;
    for (const auto& item : memo) {
        ans *= item + 1;
        ans %= MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

def main():
    d1 = D.pop(0)
    if d1 != 0:
        print(0)
        exit()

    c = Counter(D)
    item_list = list(c.items())
    item_list.sort()
    if item_list[0][0] != 1:
        print(0)
        exit()
    count = 1
    ans = 1
    item_list[0]
    for i in range(1, len(item_list)):
        if item_list[i][0] != count + 1:
            print(0)
            exit()
        count += 1
        ans *= (item_list[i-1][1]**item_list[i][1]) % MOD
        ans %= MOD
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 21468
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define PII pair<int, int>
#define debug std::cout << "---debug---" << std::endl;
using namespace std;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;

int n, m, x;
vector<int> c[13];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("E:\\myprogram\\data.in", "r", stdin);
    //freopen("E:\\myprogram\\data.out", "w", stdout);
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++) {
        c[i].resize(m);
        for(int j = 0; j <= m; j++) {
            cin >> c[i][j];
        }
    }
    int r = (1 << n) - 1, ans = mod;
    while(r >= 0) {
        int tmp = r, tmpans = 0;
        vector<int> res(13);
        for(int i = 0; i < n; i++) {
            if(tmp & (1 << i)) {
                tmpans += c[i][0];
                for(int j = 1; j <= m; j++) {
                    res[j] += c[i][j];
                }
            }
        }
        bool flag = true;
        for(int i = 1; i <= m; i++) {
            if(res[i] < x) flag = false;
        }
        if(flag) ans = min(ans, tmpans);
        r--;
    }
    if(ans == mod) cout << "-1" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
/*
          .  .
          |\_|\
          | a_a\
          | | "]
      ____| '-\___
     /.----.___.-'\
    //        _    \
   //   .-. (~v~) /|
  |'|  /\:  .--  / \
 // |-/  \_/____/\/~|
|/  \ |  []_|_|_] \ |
| \  | \ |___   _\ ]_}
| |  '-' /   '.'  |
| |     /    /|:  |
| |     |   / |:  /\
| |     /  /  |  /  \
| |    |  /  /  |    \
\ |    |/\/  |/|/\    \
 \|\ |\|  |  | / /\/\__\
  \ \| | /   | |__
       / |   |____)
       |_/
*/

#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;
const int INF = 1e9;
int main()
{
    FLASH
    ll n,k;
    cin >> n >> k;
    ll a[n],dp[n + 1];
    for(int i = 0; i <= n ; ++i)dp[i] = INF;
    for(int i = 0; i < n ; ++i)cin >> a[i];
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n && j <= i + k; j++)
            dp[j] = min(dp[j],dp[i] + abs(a[i] - a[j]) );
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#define D 365

int main()
{
	int d=D;
	int i,j,k,l;
	int c[26]={0};
	int s[D][26]={0};
	int t[365]={0};


	int bestcon[365]={0};
	int bestnum=0;


	scanf("%d",&d);
	for(i=0;i<26;i++)
    {
	    scanf("%d",(&c[i]));
    }
    for(j=0;j<365;j++)
    {
        bestnum=0;
        for(k=0;k<26;k++)
        {
            scanf("%d",(&s[j][k]));

            if(bestnum<s[j][k])
            {
                bestnum=s[j][k];
                bestcon[j]=k;
            }

        }
    }
    // input 終了

    int work=0;

    for(j=0;j<365;j++)
    {
        t[j]=j%26;
    }
    for(j=0;j<364;j++)
    {
        int phase=j/26;
        work=t[j];
        t[j]=t[phase*26+bestcon[j]];
        t[phase*26+bestcon[j]]=work;
    }
    t[364]=bestcon[364];
    //printf("ttt:%d\n",t[364]);

    //scoring　開始
    int date=0;
    int last[26]={0};
    int satis=0;

    for(date=0;date<365;date++)
    {
        int todays_con=t[date];
        satis+=s[date][todays_con];
        last[todays_con]=date;
        for(k=0;k<26;k++)
        {
            if(k==todays_con)continue;
            else
            {
                satis-=(c[k]*(date-last[k]));
            }
        }

    }

    //scoring 終了
    //printf("ttt:%d\n",t[364]);
    // output 開始
	for(i=0;i<365;i++)
    {
	    int phase=i/26;
	    //if(t[i]==0)t[i]++;
	    printf("%d\n",t[i]+1);
    }

	//printf("%d",satis);
}

Measured memory_bytes: 1764
# D - I hate Factorization

X = int(input())
fact = []
for i in range(300):
    fact.append(pow(i,5))

for i in range(300):
    for j in range(300):
        if fact[i]-fact[j]==X:
            print(i, j)
            break
        elif fact[i]+fact[j]==X:
            print(i, -j)
            break
    else:
        continue
    break




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

int main(){
    int e,y;
    cin>>e>>y;
    char jp;
    int ans;

    if(e==0){
        
        if(y<=1911){
            jp='M';
            ans=y-1867;
        }else if(y<=1925){
            jp='T';
            ans=y-1911;
        }else if(y<=1988){
            jp='S';
            ans=y-1925;
        }else if(y<=2016){
            jp='H';
            ans=y-1988;
        }
        cout<<jp;

    }else if(e==1){
        ans = y+1867;
    }else if(e==2){
        ans=y+1911;
    }else if(e==3){
        ans=y+1925;
    }else if(e==4){
        ans=y+1988;
    }




    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3096
/* h-ex9_1
   Ohshima */

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 10

//スタックの定義
typedef struct stack{
  int size;
  int count;
  char data[SIZE];
  char *top;
}stack;

//スタックの初期化
void initialize_stack(stack *stk){
  stk->count = 0;
  stk->size = SIZE;
  stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
  if(stk->count >= stk->size){
    fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
    exit(1);
  }else{
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
  }
}

//データの取り出し
void pop(stack *stk){
  if(stk->count <= 0){
    fprintf(stdout, "Error: stack underflow.\n");
    exit(1);
  }else{
    stk->top++;
    stk->count--;
  }
}

//スタックの中身を古いものから出力
void print_stack(stack *stk){
  int i;
  for(i = 0; i < stk->count; i++){
    putchar(stk->data[SIZE - 1 - i]);
  }
  printf("\n");
}

int main(void){
  stack stk;
  char tmp;
  int i;
  //スタックを初期化（ポインタ渡しで関数にわたすこと）
  initialize_stack(&stk);
  //1文字ずつ標準入力から受け取り以下を実行
  while(scanf("%c", &tmp) != EOF && tmp != '\n'){ //テストケースの中に10文字+改行文字の場合が含まれている
    //B以外の文字のときスタックにデータを追加
    if(tmp != 'B'){
      push(&stk, tmp);
    }else{
      //Bがきた場合、文字列が空でないならデータを取り除く
      if(stk.count > 0){
        pop(&stk);
      }
    }
  }
  //最後に、スタックに残っている文字を古いものから出力
  print_stack(&stk);
  return 0;
}


Measured memory_bytes: 1572
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n;
    cin >> n;
    map<ll, ll> l;
    rep(i, n){
        ll o;
        cin >> o;
        l[o]++;
    }
    
    ll a = 0, b = 0;
    for(auto i = l.rbegin(); i != l.rend(); ++i){
        //printf("%lld %lld\n", i->first, i->second);
        if(i->second/2 >= 1){
            if(i->second/2 >= 2){
                if(a == 0 && b == 0) a = b = i->first;
                else b = i->first;
            }else{
                if(a == 0) a = i->first;
                else b = i->first;
            }
            if(a != 0 && b != 0) break;
        }
    }
    
    ll ans  = a*b;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define Rep(i, k, N) for(i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    i64 X;
    cin >> X;
    i64 n = 100ll;
    
    int i = 0;
    while(n < X){
        n = n * (101.0 / 100.0);
        i++;
    }

    cout << i << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long	
int h,w;
char arr[1005][1005];
int dp[1005][1005];
int mod = 1000*1000*1000+7;

void init()
{
	for(int i=0;i<1005;i++)
	{
		for(int j=0;j<1005;j++)
		dp[i][j]=-1;
	}
}
int find_pth(int i, int j)
{
	if(i>=h||j>=w)
	return 0;
	if(i==h-1&&j==w-1)
	{
		return 1;
	}
	if(arr[i][j]=='#')
	return 0;
	
	if(dp[i][j]!=-1)
	return dp[i][j];
	
	int count=0;
	
	count=find_pth(i+1,j)%mod;
	
	count=(count%mod+find_pth(i,j+1)%mod)%mod;
	
	dp[i][j]=count;
	
	return count;
}


int main()
{
	init();
	cin>>h>>w;
	
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		cin>>arr[i][j];
	}
	
	cout<<find_pth(0,0);
}
	


Measured memory_bytes: 8680
# encoding: utf-8

#input
n = int(input())
A = [int(i) for i in input().split()]
# print(A)
def sad_value(A,b):
    sadness = 0
    for i in range(len(A)):
        sadness += abs(A[i]-b-i-1)
    return sadness
A_i = []
for i in range(len(A)):
    A_i.append(A[i]-i)
A_i.sort()
sadness = []
for i in range(5):
    a = int(n/2)
    sadness.append(sad_value(A, A_i[a]-2+i))
sadness.sort()
print(sadness[0])


Measured memory_bytes: 25836
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
H, A = ri_()
print(-(-H // A))

Measured memory_bytes: 63340
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {{typeid(int), "%d"},
                                                      {typeid(ll), "%lld"},
                                                      {typeid(double), "%lf"},
                                                      {typeid(char), "%c"}};

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
  // INFILE();
	string a, b;
	cin >> a >> b;

	if ((a > b && a.size() == b.size()) || a.size() > b.size()) {
		cout << "GREATER\n";
		return 0;
	}

	if (a == b && a.size() == b.size()) {
		cout << "EQUAL\n";
		return 0;
	}

	cout << "LESS\n";
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  auto tFormat = scanType[typeid(T)];
  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


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

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

signed main() {

    int N;
    cin >> N;
    string S;
    __int128 cnt = 1;
    bool ok = true;
    rep(i,N){
        cin >> S;
        __int128 x = parse(S);
        if(x == 0){
            cout << 0 << endl;
            return 0;
        }
        cnt = cnt * x;
        if(cnt > 1000000000000000000) ok = false;
    }
    if(ok) cout << cnt << endl;
    else cout << -1 << endl;
    /*
  string s = "187821878218782187821878218782";
  __int128 x = parse(s);
  x *= 2;
  cout << x << endl;
  */
}

Measured memory_bytes: 3632
def search_num(k, alst):
  left = 0
  right = len(alst) - 1
  cnt = 0
  while left <= right:
    mid = (left + right) // 2
    cnt += 1
    if alst[mid] == k:
      return cnt
    if alst[mid] < k:
      left = mid + 1
    else:
      right = mid - 1
  return cnt

while True:
  n = int(input())
  if n == 0:
    break
  alst = [int(input()) for _ in range(n)]
  k = int(input())
  print(search_num(k, alst))


Measured memory_bytes: 5596
#include<atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1LL<<60;
const int INF = 1LL<<17;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll n, m;    cin >> n >> m;
    dsu tree(n);
    rep(i, m){
        ll a, b;    cin >> a >> b;
        a--, b--;
        tree.merge(a, b);
    }
    set<ll> st;
    rep(i, n) st.insert(tree.leader(i));
    cout << st.size()-1 << endl;
}


Measured memory_bytes: 7764
use proconio::{fastout, input};
use std::cmp::max;

const MIN: i64 = -0x7fffffffffffffff;

#[fastout]
fn main() {
    input! {in_n: usize, in_a: [i64; in_n]};
    let mut dp = Vec::new();

    for _ in 0..(in_n % 2 + 2) {
        dp.push(vec![MIN; in_n / 2]);
    }

    for i in 0..dp.len() {
        dp[i][0] = in_a[i];
    }

    for i in 1..(in_n / 2) {
        let p = i * 2;

        for j in 0..dp.len() {
            for k in 0..=j {
                dp[j][i] = max(dp[k][i - 1] + in_a[p + j], dp[j][i]);
            }
        }
    }

    let mut maxval = MIN;

    for i in 0..dp.len() {
        maxval = max(dp[i][dp[i].len() - 1], maxval);
    }

    println!("{}", maxval);
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
    if((A==B & B!=C) || (B==C && C!=A) || (C==A && B!=A)){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	vector<int> A(3);
	rep(i,3){
		cin>>A[i];
	  }
	int five=0;
	int seven=0;
	rep(i,3){
		if(A[i]==5){
			five++;
		  }
		  else if(A[i]==7){
			  seven++;
			}
	  }
	  if(five==2&&seven==1){
		  cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		  }

}

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

using namespace std;

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

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


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

int main() {
	string s;
	int zero=0, one=0, c=0;
	cin >> s;
	for(char x:s){
		if(c%2 == 0){
			if(x == '1') ++zero;
			else ++one;
		}
		else if(x=='0') ++zero;
		else ++one;
		++c;
	}
	cout << min(zero,one);

}


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

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

void rec(int i, int N, int diff, string str){
    //cout << i << " " << N << " " << str << endl;
    if(i == N) cout << str << endl;
    else if(i == 0) rec(i+1, N, 1, str+'a');
    else {
        char last = str[i-1];
        for(int j=0;j<diff; j++){
            rec(i+1, N, diff, str+(char)('a'+j));
        }
        rec(i+1, N, diff+1, str+(char)('a'+diff));
    }
}

int main()
{
    int N; cin >> N;
    rec(0, N, 0, "");
    
    
    return 0;
    
}



Measured memory_bytes: 1536
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i==0 or i==H-1 or j==0 or j==W-1:
                print("#",end="")
            else:
                print('.',end="")
        print()
    print()


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

struct segt{
	int l;
	int r;
	int maxv;
}tree[2500005];

int a[300005],dp[300005];

void build(int le,int ri,int i){
	tree[i].l=le,tree[i].r=ri,tree[i].maxv=0;
	if(le==ri) return;
	int mid=(le+ri)>>1;
	build(le,mid,i<<1);
	build(mid+1,ri,i<<1|1);
}

void change(int p,int x,int i){
	if(tree[i].l==tree[i].r){
		tree[i].maxv=max(tree[i].maxv,x);
		return;
	}
	if(tree[i<<1].r>=p) change(p,x,i<<1);
	else change(p,x,i<<1|1);
	tree[i].maxv=max(tree[i<<1].maxv,tree[i<<1|1].maxv);
}

int ask(int le,int ri,int i){
	if(le<=tree[i].l&&tree[i].r<=ri)
		return tree[i].maxv;
	int cnt=0;
	if(tree[i<<1].r>=le)
		cnt=ask(le,ri,i<<1);
	if(tree[i<<1|1].l<=ri)
		cnt=max(cnt,ask(le,ri,i<<1|1));
	return cnt;
}

signed main(){
	int n,k,ans=1;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	build(1,300002,1);
	for(int i=1;i<=n;i++){
		dp[i]=max(1ll,ask(max(0ll,a[i]-k)+1,min(300000ll,a[i]+k)+1,1)+1);
		change(a[i]+1,dp[i],1);
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 32892
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int r,g;
    cin >> r >> g;
    print(g+g-r);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main(){
    double a , b , c , d , e , f;
    while(cin >> a >> b >> c >> d >> e >> f){
        double x , y;
        x=(b*f-c*e)/(b*d-a*e);
        y=(c - a * x )/ b;
        if(x==-0) x=0;
		if(y==-0) y=0;
        printf("%.3lf %.3lf\n", x , y);
    }
}


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

int main() {
  int N;
  string S;

  cin >> N >> S;

  string T = S.substr(0, S.size() / 2);

  if (S == T + T) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)

	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		b[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		c[i] = nextInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Ints(b)
	sort.Ints(c)

	ans := 0
	for bi := 0; bi < n; bi++ {
		bv := b[bi]
		ai := sort.Search(n, func(i int) bool {
			return a[i] < bv
		})
		if n <= ai {
			continue
		}

		ci := sort.Search(n, func(i int) bool {
			return c[i] > bv
		})
		if n <= ci {
			continue
		}

		ans += (n - ai) * (n - ci)
	}

	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

int main() {
  int n;
  string s;
  
  cin >> n >> s;
  
  //rは赤の数
  int r = 0, w = 0;
  
  rep(i,n) if(s[i] == 'R') ++r;
  int ans = max(r,w);
  rep(i,n){
    if(s[i] == 'R') --r;
    else ++w;
    
    //赤を全部左に寄せたときの
    int now = max(r,w);
    ans = min(ans, now);
  }
  
  cout << ans << endl;
  
  return 0;
  
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve(){
	int i,n, l,r,c=0;
string s;
cin>>n;
cin>>s;
l=0;
r=n-1;
while(l<r){
while(s[l]!='W' and l<n){
	l++;
}
while(s[r]!='R' and r>-1){
	r--;
}
if(s[l]=='W' and s[r]=='R' and l<r){
	swap(s[l],s[r]);
	c++;
}
l++;
r--;
}
cout<<c<<endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	int i,t=1;
	//cin>>t;
	for(i=1;i<=t;i++){
		solve();
	}
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




Measured memory_bytes: 10808
T = {
  ' ' => '101',
  ?' => '000000',
  ?, => '000011',
  ?- => '10010001',
  ?. => '010001',
  ?? => '000001',
  ?A => '100101',
  ?B => '10011010',
  ?C => '0101',
  ?D => '0001',
  ?E => '110',
  ?F => '01001',
  ?G => '10011011',
  ?H => '010000',
  ?I => '0111',
  ?J => '10011000',
  ?K => '0110',
  ?L => '00100',
  ?M => '10011001',
  ?N => '10011110',
  ?O => '00101',
  ?P => '111',
  ?Q => '10011111',
  ?R => '1000',
  ?S => '00110',
  ?T => '00111',
  ?U => '10011100',
  ?V => '10011101',
  ?W => '000010',
  ?X => '10010010',
  ?Y => '10010011',
  ?Z => '10010000',
}.freeze
S = {
  0b00000 => ?A,
  0b00001 => ?B,
  0b00010 => ?C,
  0b00011 => ?D,
  0b00100 => ?E,
  0b00101 => ?F,
  0b00110 => ?G,
  0b00111 => ?H,
  0b01000 => ?I,
  0b01001 => ?J,
  0b01010 => ?K,
  0b01011 => ?L,
  0b01100 => ?M,
  0b01101 => ?N,
  0b01110 => ?O,
  0b01111 => ?P,
  0b10000 => ?Q,
  0b10001 => ?R,
  0b10010 => ?S,
  0b10011 => ?T,
  0b10100 => ?U,
  0b10101 => ?V,
  0b10110 => ?W,
  0b10111 => ?X,
  0b11000 => ?Y,
  0b11001 => ?Z,
  0b11010 => ' ',
  0b11011 => ?.,
  0b11100 => ?,,
  0b11101 => ?-,
  0b11110 => ?',
  0b11111 => ??,
}.freeze
$<.each_line do |l|
  s = ''
  l.chomp.each_char {|c| s << T[c] }
  s << ?0 * ((5 - s.size) % 5)
  puts s.each_char.each_slice(5).map {|a| S[a.join.to_i 2] }.join
end

Measured memory_bytes: 9088
from collections import deque

k = int(input())

x = 0
q = deque(list(range(1, 10)))
for _ in range(k):
    x = q.popleft()
    d = x % 10
    y = 10 * x + d
    if d > 0:
        q.append(y - 1)
    q.append(y)
    if d < 9:
        q.append(y + 1)
print(x)


Measured memory_bytes: 74656
# 愚直にやったけど、もうちょいよい方法はないものか
def genP(W):
    P = []
    D = [0]*(W-1)
    P.append(D[:])
    for i in range(2**(W-1)-1):
        d = 0
        while D[d] == 1:
            D[d] = 0
            d+=1
        D[d] = 1
        if any(D[i] == 1 and D[i+1] == 1 for i in range(W-2)):
            continue
        P.append(D[:])
    return P 

# ここがちょっと煩雑
def make_swap(p, W):
    base = [x for x in range(0,W)]
    b = base[:] 
    for w in range(len(p)):
        if p[w] == 1:
            b[w], b[w+1] = b[w+1], b[w]
    return b


def solve(H, W, K):
    swaps = []
    for p in genP(W):
        s = make_swap(p, W)
        swaps.append(s)

    count = [[0]*W for i in range(H+1)]
    count[0][0] = 1

    for h in range(0,H):
        for w in range(0, W):
            for swap in swaps:
                count[h+1][w] += count[h][swap[w]]
                count[h+1][w] %= 1000000007
    #print(count[H])
    print(count[H][K-1])

def main():
    H, W, K = map(int, input().split())
    solve(H, W, K)
main()


Measured memory_bytes: 3192