akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  constexpr ModInt() : v(0) {}
  constexpr ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt<998244353>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  Mint res;
  for (int i = 0; i < n; ++i) {
    res += Mint(2).pow(n - 1 - i) * a[i] * Mint(1 + a[i]).pow(i);
  }
  cout << res << '\n';
}


Measured memory_bytes: 6704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
//  int a ,b, c, d, e, X, Y;
  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%lld%lld%lld", &a, &b, &c);
  long long border=0;
  border = c - b;
  for(i=0;i<c;i++){
    scanf("%lld%", &d);
    A[d]++;
  }
  for(i=0;i<a;i++){
    if(A[i+1] > border) printf("Yes\n");
    else  printf("No\n");
  }
         
 

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d\n", cnt);
   

return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    char str[10000];
    scanf("%s", str);

    for (int i=0; str[i]!='\0'; i++){
        int temp = str[i] + n;
        if (temp > 90){
            printf("%c", temp-26);
        }
        else{
            printf("%c", temp);
        }
    }
    printf("\n");
    return 0;
}

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

using namespace std;

void solve();

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

void solve() {
    int a,b;
    string s;
    cin >> a >> b >> s;
    if(s.length() != a + b + 1 || s[a] != '-') {
        cout << "No" << endl;
        return;
    }
    for(int i = 0; i < a; i++) {
        if(s[i] < '0' || s[i] > '9') {
            cout << "No" << endl;
            return;
        }
    }
    for(int i = a+1; i < s.length(); i++) {
        if(s[i] < '0' || s[i] > '9') {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;


}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,i;
  scanf("%d",&n);
  long int sum=0;
  for(i=1;i<=n;i++)
  { if(i%3!=0&&i%5!=0)
    sum+=i;
  }
  printf("%ld",sum);
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
using namespace std;
#define tocap(a) (char)((a) - ('a' - 'A'))
int main()
{
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    cout << tocap(s[0][0]) << tocap(s[1][0]) << tocap(s[2][0]) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;

	int m = atoi(S.substr(5, 2).c_str());
	int d = atoi(S.substr(8, 2).c_str());

	if (m < 4 || m == 4 && d < 31)
	{
		cout << "Heisei" << endl;
	}
	else
	{
		cout << "TBD" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace abc116A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            int D;
            int E;
            if (A >= B)
            {
                E = B;
            }
            else
                E = A;
            if (E >= C)
            {
                D = C;
            }
            else if (A >= B)
                D = A;
            else
                D = B;
            int F = (D * E) / 2;
            Console.WriteLine(F);
        }
    }
}


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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

int main(){
  int n, q;
  while(cin >> n >> q and n + q){
    vector<int> day(100, 0);
    REP(i, n){
      int m;
      cin >> m;
      REP(j, m){
        int tmp;
        cin >> tmp;
        day[--tmp]++;
      }
    }
    int maxim = 0;
    int date = -1;
    REP(i, 100){
      date = day[i] > maxim ? i : date;
      maxim = max(day[date], day[i]);
    }
    cout << (maxim >= q ? date + 1 : 0) << endl;
  }

  return 0;
}

Measured memory_bytes: 3088
//tree DP
//ABC036-D
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val > ((sd*)b)->val){return -1;}
if(((sd*)a)->val < ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

long long dist[524288],par[524288];
void dfs(long long t,long long l,long long bp,rs g[],mkj x[]){
  long long i;
  if(dist[t]<=l){return;}
  dist[t]=l;
  par[t]=bp;
  for(i=x[t].st;i<x[t].st+x[t].kz;i++){
    dfs(g[i].fi,l+1,t,g,x);
  }
}

int main(void){
    long long i,j,n,m,k,a,b,c,h,w,r=0,l,t,ng;
    long long bk,wk;
    long long res=0;
    long long grundy[524288]={0};
    rs g[524288];
    mkj x[524288];
    sd dat[524288];
    scanf("%lld",&n);
    for(i=0;i<(n-1);i++){
      scanf("%lld%lld",&a,&b);
      g[2*i].st=a;
      g[2*i].fi=b;
      g[2*i].kr=1;
      g[2*i+1].st=b;
      g[2*i+1].fi=a;
      g[2*i+1].kr=1;
    }
    qsort(g,2*(n-1),sizeof(g[0]),sortfnc);
    makemkj(g,x,2*(n-1));
    for(i=0;i<=n;i++){
      dist[i]=inf;
    }
    dfs(1,0,-1,g,x);
    for(i=0;i<n;i++){
      dat[i].node=i+1;
      dat[i].val=dist[i+1];
    }
    qsort(dat,n,sizeof(dat[0]),sdsortfnc);
    for(i=0;i<n;i++){
      w=dat[i].node;
      ng=0;
      for(j=x[w].st;j<x[w].st+x[w].kz;j++){
        if(par[w]==g[j].fi){continue;}
        ng^=(grundy[g[j].fi]+1);
      }
      grundy[w]=ng;
    }
    if(grundy[1]){printf("Alice\n");}
    else{printf("Bob\n");}
    return 0;
}


Measured memory_bytes: 30380
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
	int x, i, j, t;
	x = A[r];
	i = p - 1;
	for(j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

int main(){
	int i, q;
	
	scanf("%d" ,&n);
	for(i = 0; i < n; i++) scanf("%d",&A[i]);
	
	q = partition(0, n - 1);
	
	for(i = 0; i < n; i++){
		if(i) printf(" ");
		if(i == q) printf("[");
		printf("%d", A[i]);
		if(i == q) printf("]");
	}
	printf("\n");
	
	return 0;
	
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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


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

const ll INF = 1LL << 60;

struct Edge{
  int to,weight;
  Edge(int t, int w) : to(t),weight(w){}
};

using Graph = vector<vector<Edge>>;

int main(){
  int n,k; string s;
  cin >> n >> k >> s;

  vi C;
  int now = 1, cnt = 0;
  rep(i, n){
    if(s[i] == (char)(now + '0')) cnt++;
    else{
      C.pb(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  C.pb(cnt);
  if(C.size()%2 == 0) C.pb(0);

  int m = C.size();
  vi S(m+1); rep(i, m) S[i+1] = S[i] + C[i];

  int ans = 0;
  for (int i = 0; i < m; i += 2) {
    //chmax(ans, S[i+2*k+1] - S[i]); これじゃダメ
    int left = i;
    int right = min(i+2*k+1,m);// ここ気を付ける
    chmax(ans, S[right] - S[left]);
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 1272
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int Q;
    cin >> Q;
    int check[100001];
    int ruiseki[100001];
    for(int i = 0; i <= 100000; i++) check[i] = ruiseki[i] = 0;
    for(int i = 2; i <= 100000; i++){
        if(check[i] < 0) continue;
        if(check[i] == 0){
            check[i] = 1;
            for(int j = 2*i; j <= 100000; j+=i) check[j] = -1;
        } 
    }
    for(int i = 2; i <= 100000; i++){
        if(i % 2 == 1 && check[i] == 1 && check[(i+1)/2] == 1) ruiseki[i] = ruiseki[i-1] + 1;
        else ruiseki[i] = ruiseki[i-1];
    }
    vector<int> ans;
    for(int i = 0; i < Q; i++){
        int l,r;
        cin >> l >> r;
        ans.emplace_back(ruiseki[r] - ruiseki[l-1]);
    }
    for(auto num : ans) cout << num << endl;
    return 0;
}


Measured memory_bytes: 1912
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll dp[3030][3030];
int d[3030];
int main()
{
	int num, query;
	scanf("%d%d", &num, &query);
	for (int i = 0; i < num; i++)scanf("%d", &d[i]);
	for (int i = 0; i < num; i++)for (int j = 0; j < num; j++)dp[i][j] = d[i] < d[j];
	const ll m=(mod+1)/2;
  	for (int p = 0; p < query; p++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		for (int i = 0; i < num; i++)
		{
			if (i != za&&i != zb)
			{
				dp[za][i] = dp[zb][i] = (dp[za][i] + dp[zb][i])*m % mod;
				dp[i][za] = dp[i][zb] = (dp[i][za] + dp[i][zb])*m % mod;
			}
		}
		dp[za][zb] = dp[zb][za] = (dp[za][zb] + dp[zb][za])*m % mod;
	}
	ll r = 0;
	for (int i = 0; i < num; i++)for (int j = 0; j < i; j++)r = (r + dp[i][j]) % mod;
	for (int i = 0; i < query; i++)r = r * 2 % mod;
	printf("%lld\n", r);
}


Measured memory_bytes: 71808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  string s, t;
  cin >> s >> t;
  rep(i, s.size()) {
    cout << s[i];
    if (i < t.size()) cout << t[i];
  }
  cout << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int c = sc.nextInt();
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        int ans = 0;
        int[] a = new int[m];
        for (int i = 0; i < n; i++) {
            int sum = c;
            for (int j = 0; j < m; j++) {
                a[j] = sc.nextInt();
                int tmp = a[j] * b[j];
                sum += tmp;
            }
            if (sum > 0) {
                ans++;
            }
        }
        System.out.println(ans);
        sc.close();
    }
}

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

int main() {
	ll n,m,ans=0,sum,a[100010];
	cin>>n>>m;
	for(int i=0;i<100010;i++){
		a[i]=0;
	}
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	if(a[0]>m){
		ans+=a[0]-m;
		a[0]=m;
	}
	sum=a[0];
	for(int i=1;i<n;i++){
		sum+=a[i];
		if(sum>m){
			ans+=sum-m;
			a[i]-=sum-m;
			sum=m;
		}
		sum-=a[i-1];
	}
	cout <<ans;
}

Measured memory_bytes: 1024
package main

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

//
var (
	N int
	M int
	R int
	r []int
	d [][]int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func fillInts(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}

func warshallFloyd(n int, d [][]int) {
	for k := 0; k < n; k++ {
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				d[i][j] = min(d[i][j], d[i][k]+d[k][j])
			}
		}
	}
}

func dfs(p []int) int {
	if len(p) == R {
		result := 0
		for i := 0; i < R-1; i++ {
			result += d[p[i]][p[i+1]]
		}
		return result
	}

	result := math.MaxInt64
	for i := 0; i < R; i++ {
		used := false
		for j := 0; j < len(p); j++ {
			if r[i] == p[j] {
				used = true
				break
			}
		}
		if !used {
			result = min(result, dfs(append(p, r[i])))
		}
	}
	return result
}

func main() {
	defer flush()

	N = readInt()
	M = readInt()
	R = readInt()
	r = make([]int, R)
	for i := 0; i < R; i++ {
		r[i] = readInt()
	}

	d = make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		d[i] = make([]int, N+1)
		fillInts(d[i], math.MaxInt32)
		d[i][i] = 0
	}

	for i := 0; i < M; i++ {
		A := readInt()
		B := readInt()
		C := readInt()
		d[A][B] = C
		d[B][A] = C
	}
	warshallFloyd(N+1, d)

	println(dfs(make([]int, 0)))
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdoutWriter, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 2048
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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(){
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	REP(i,n) cin >> v[i];
	
	ll ans = 0;
	for(int border=0; border<=n; border++){
		for(int l=0; l<=border; l++){
			for(int r=n; r>=border; r--){
				ll value = 0;
				int count = 0;
				priority_queue<int> minus;
				
				for(int i=0; i<l; i++){
					value += v[i];
					count++;
					if(v[i] < 0) minus.push(-1*v[i]);
				}
				for(int i=n-1; i>=r; i--){
					value += v[i];
					count++;
					if(v[i] < 0) minus.push(-1*v[i]);
				}
				
				if(count > k) continue;
				while(k-count>0 && !minus.empty()){
					value += minus.top();
					minus.pop();
					count++;
				}
				chmax(ans, value);
			}
		}
	}
	
	cout << ans << endl;
	
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int N;
    cin>>N;
    vi s(N),l(N),p(N);
    rep(i,N)cin>>s[i]>>l[i]>>p[i];
    int M;
    cin>>M;
    vi w(M);
    rep(i,M)cin>>w[i];
    vii dp(N+1,vi(400,-1));
    rep(i,N)dp[i][0]=0;

    rep(i,N){
        rep(j,400){
            chmax(dp[i+1][j],dp[i][j]);
            REP(k,s[i],l[i]+1){
                if(j-k>=0)chmax(dp[i+1][j],dp[i+1][j-k]+p[i]);
            }
            //cout<<dp[i+1][j]<<" ";
        }
        //cout<<endl;
    }
    vi ANS;
    for(auto x:w){
        if(dp[N][x]==-1){
            cout<<-1<<endl;
            return 0;
        }else ANS.pb(dp[N][x]);
    }
    for(auto x:ANS)cout<<x<<endl;
    return 0;
}

//a=97,z=122


Measured memory_bytes: 3416
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 4e18L + 1;
const int IINF = 1e9 + 1;
const int N = 1048576;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#define LOCAL
#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    #ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #endif
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    h = min(h, 2 * q);
    s = min(s, 2 * h);
    d = min(d, 2 * s);
    cout << n / 2 * d + n % 2 * s;
}


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

using namespace std;
typedef pair<int, int> pii;
#define int long long

signed main(){

    while(1){
        int N, M;
        cin>> N>> M;
        if(!(N||M)) break;

        int D[N], P[N];
        for(int i=0; i<N; i++) cin>> D[i]>> P[i];

        vector<pii> v;
        for(int i=0; i<N; i++) v.push_back(pii(P[i], D[i]));
        sort(v.rbegin(), v.rend());
        int m=0, ans=0;
        for(int i=0; i<N; i++){
            int ikd=m+v[i].second;
            if(ikd>M){
                ans+=(v[i].second-(ikd-M))*v[i].first;
                break;
            }else{
                ans+=v[i].second*v[i].first;
                if(ikd==M){
                    break;
                }else{
                    m=ikd;
                }
            }
        }
        int s=0;
        for(int i=0; i<N; i++){
            s+=D[i]*P[i];
        }
        cout<< s-ans<< endl;
    }

    return 0;
}

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

int cost (int a, int b, int c){
	int co = abs(b-a) + abs(c-b);
	return co;
}

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int s = min(cost(a,b,c),cost(a,c,b));
	int t = min(cost(b,a,c),cost(b,c,a));
	int u = min(cost(c,a,b),cost(c,b,a));
	cout << min(s,min(t,u)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
const int N = 1e6 + 5;
typedef long long LL;
int cnt;
LL ans = 1, n, p;
int main() {
    scanf("%lld %lld", &n, &p);
    if(n == 1){
        printf("%lld\n", p);
        return 0;
    }
    for (LL i = 2LL; i * i <= p; ++i){
        cnt = 0;
        while((p != 1) && (p % i == 0) ) {
            p /= i;
            cnt++;
        }
        while(cnt >= n){
            cnt -= n;
            ans *= i;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
typedef pair<int, int> P;

lint N, M, A, B;
map<lint, lint> cnt;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> M;
	REP(i, M) {
		cin >> A >> B;
		cnt[A]++;
		cnt[B]++;
	}
	REP(i, N) {
		if (cnt[i + 1] % 2 == 1) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
}


Measured memory_bytes: 6528
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main()
{
    int n,m;
	cin>>n>>m;
	string s[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	sort(s+1,s+n+1);
	for(int i=1;i<=n;i++)
	{
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left,bisect_right
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
    ai=bisect_left(a,b[i])
    ci=bisect_right(c,b[i])
    ans+=ai*(n-ci)
print(ans)



Measured memory_bytes: 23360
#include<stdio.h>

void trace(int A[], int N){
    int i ;
    for(i=0; i<N;i++){
        if(i>0){
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}
void intsertionSort(int A[], int N){
    int i,j,v;
    for(i=1;i<=N-1;i++){
        v = A[i];
        j = i -1;
        while(j>=0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace (A, N);
    }
}

int main(){
    int a,i,num[100];
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d",&num[i]);        
    }
    trace(num, a);
    intsertionSort(num,a);
}

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

int main()
{
  ll N, M;
  cin >> N >> M;
  
  vector<ll> A(N);
  ll sum = 0;
  rep(i, N)
  {
    cin >> A[i];
    sum += A[i];
  }
  
  sort(A.begin(), A.end(), greater<ll>());
  
  if (sum <= 4 * M * A[M - 1])
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

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

using namespace std;
typedef long long ll;

int main() {

    ll N;
    cin >> N;
    ll A[N];
    ll B[N];
    ll map[N];
    rep(i,N) map[i] = 0;
    rep(i,N){
        cin >> A[i];
        B[i] = A[i];
        map[A[i]-1]++;
    }
    sort(B,B+N);
    ll C[N];
    rep(i,N) C[i] = 0;
    ll D[N];
    rep(i,N) D[i] = 0;
    ll M = 0;
    ll num = 0;
    bool isSame = false;
    rep(i,N){
        if(i>0 && B[i] == B[i-1]){
            C[num] ++;
            if(isSame == false){
                D[num] = B[i];
                M++;
            }
            isSame = true;
        }else{
            if(isSame == true){
                num++;
                isSame = false;
            }
        }
    }
    ll sum = 0;
    rep(i,N){
        if(C[i]>0) sum += C[i]*(C[i]+1)/2;
    }
    ll out = 0;
    rep(i,N){
        out = sum - map[A[i]-1] + 1;
        cout << out << endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;

const int MOD = 1e9 + 7;

template<typename T>
void min_self(T& a, T b)
{
    a = min(a,b);
}

template<typename T>
void max_self(T& a, T b)
{
    a = max(a,b);
}

const int Nax=1000 + 5;

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int H, W;
    cin >> H >> W;
    
    vector<int> dp(W,0);
    
    dp[0] = 1;

    int prev;
    
    for(int i=0; i<H; ++i)
    {
        prev = 0;
        
        for(int j=0; j<W; ++j)
        {
            char ch;
            cin >> ch; 
            if(ch != '#')
            {
                dp[j] += prev;
                dp[j] %= MOD;
            }
            else
            {
                dp[j] = 0;
            }
            
            prev = dp[j];
            
            //cout << dp[j] << " ";
        }
        
        //cout << endl;
    }
    
    cout << prev;
    
}


Measured memory_bytes: 256
F=->{gets.split.map &:to_i};n,*d=F[];g=(0..n).map{d<<p;[]};n.times{A,B,c=F[];c&&g[A]<<[B,c]&&g[B]<<[A,c]};d[B]=0;s=[B];g[n].map{|u,c|d[u]||(d[u]=c+d[n];s<<u)}while n=s.pop;A.times{a,b=F[];p d[a]+d[b]}

Measured memory_bytes: 40316
n,c = map(int,input().split())
xv = [list(map(int, input().split())) for i in range(n)]

# 右まわり
right = [[0,0]]
for i in range(n):
    right.append([xv[i][0],right[-1][1]+xv[i][1]])

right_best =[0]
for i in range(1,len(right)):
    right_best.append(max(right[i][1]-right[i][0],right_best[-1]))

right_return_best = [0]
for i in range(1,len(right)):
    right_return_best.append(max(right[i][1]-right[i][0]*2,right_return_best[-1]))


# 左回り
for i in range(n):
    xv[i][0]=c-xv[i][0]
xv.reverse()

left = [[0,0]]
for i in range(n):
    left.append([xv[i][0],left[-1][1]+xv[i][1]])

left_best =[0]
for i in range(1,len(left)):
    left_best.append(max(left[i][1]-left[i][0],left_best[-1]))

left_return_best = [0]
for i in range(1,len(left)):
    left_return_best.append(max(left[i][1]-left[i][0]*2,left_return_best[-1]))


# 答え計算
ans = 0
for i in range(n+1):
    ans = max(ans,left_best[i]+right_return_best[n-i], right_best[i]+left_return_best[n-i])

print(ans)

Measured memory_bytes: 91992
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template



int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    bool imp = true;
    rep(i, 1, s.size() - 1){
        if(s[i - 1] != s[i + 1]){
            imp = false;
            break;
        }
    }
    if(imp) {
        output("Second");
        return 0;
    }
    bool same = true;
    if(s[0] != s[s.size() - 1]) same = false;
    if(same){
        if(s.size() % 2 == 0) output("First");
        else output("Second");
    }
    else{
        if(s.size() % 2 == 0) output("Second");
        else output("First");
    }
    
    
    return 0;
}

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

const int N = 1e5 + 10;

int a[N];
long long pre[N], suf[N], sum[N];
 
int main(){
	int n, k;
	long long ans;
	scanf("%d %d",&n,&k);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	sum[0] = 0;
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
	pre[0] = 0;
	for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + max(a[i], 0);
	suf[n + 1] = 0;
	for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + max(a[i], 0);
	ans = 0;
	for (int i = 0; i <= n - k; i++)
		ans = max(ans, pre[i] + suf[i + k + 1] + max(sum[i + k] - sum[i], 0LL));
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){
  
  int n;
  ll sum = 0;
  cin >> n;
  vector<int> v(n);
  REP(i,n)cin >> v[i];
  int negative = 0,zero = 0,absmin = INF;
  for(auto au : v){
    if(au < 0){
      negative++;
      absmin = min(absmin,abs(au));
      sum += abs(au);
    }else if(au == 0){
      zero++;
      absmin = 0;
    }else{
      absmin = min(absmin,au);
      sum += au;
    }
  }
  if(zero){
    cout << sum << endl;
  }else if(negative & 1){
    cout << sum - 2*absmin << endl;
  }else{
    cout << sum << endl;
  }




  
  


  return 0;
}


Measured memory_bytes: 640
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    smaller = 0
    for i in range(x):
        if x - i in p:
            pass
        else:
            smaller = x-i
            break

    bigger = 2*x
    for j in range(x):
        if x + j in p:
            pass
        else:
            bigger = x + j
            break

    ans = smaller if x - smaller <= bigger - x else bigger
    #print(bigger)
    print(ans)
else:
    print(x)

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


void solve(long long D, std::vector<long long> c, std::vector<std::vector<long long>> s, std::vector<long long> t, long long M, std::vector<long long> d, std::vector<long long> q){
    vector<vector<long long>> last(D, vector<long long>(26));
    vector<vector<long long>> score(D, vector<long long>(26));
    long long ans = 0;
    for (int d = 0; d < D; d++) {
        for (int i = 0; i < 26; i++) {
            if (i == t[d] - 1) {
                last[d][i] = d;
                ans += s[d][i];
            } else {
                last[d][i] = d == 0 ? -1 : last[d-1][i];
                ans -= c[i] * (d - last[d][i]);
            }
        }
        // cout << ans << endl;
    }

    for (int m = 0; m < M; m++) {
        long long d1 = d[m] - 1;
        long long q1 = t[d1] - 1;
        long long q2 = q[m] - 1;

        long long i = q1;
        last[d1][i] = -1;   // ループの都合で別の値を入れておく
        for (int d = d1; d < D && last[d][i] != d; d++) {
            if (d == d1) {
                ans -= s[d][i];
            } else {
                ans += c[i] * (d - last[d][i]);
            }
            last[d][i] = d == 0 ? -1 : last[d-1][i];
            ans -= c[i] * (d - last[d][i]);
        }

        i = q2;
        for (int d = d1; d < D && last[d][i] != d; d++) {
            ans += c[i] * (d - last[d][i]);
            if (d == d1) {
                last[d][i] = d;
                ans += s[d][i];
            } else {
                last[d][i] = d == 0 ? -1 : last[d-1][i];
                ans -= c[i] * (d - last[d][i]);
            }
        }
        cout << ans << endl;

        t[d1] = q2 + 1;
    }

}

// Generated by 1.1.7.1 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 D;
    scanf("%lld",&D);
    std::vector<long long> c(26);
    for(int i = 0 ; i < 26 ; i++){
        scanf("%lld",&c[i]);
    }
    std::vector<std::vector<long long>> s(D, std::vector<long long>(26));
    for(int i = 0 ; i < D ; i++){
        for(int j = 0 ; j < 26 ; j++){
            scanf("%lld",&s[i][j]);
        }
    }
    std::vector<long long> t(D);
    for(int i = 0 ; i < D ; i++){
        scanf("%lld",&t[i]);
    }
    long long M;
    scanf("%lld",&M);
    std::vector<long long> d(M);
    std::vector<long long> q(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&d[i]);
        scanf("%lld",&q[i]);
    }
    solve(D, std::move(c), std::move(s), std::move(t), M, std::move(d), std::move(q));
    return 0;
}


Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int A[200000];
    int B[200000];
    cin >> n;
    for (int i=0;i<n+1;i++){
        cin >> A[i];
    }
    for (int i=0;i<n;i++){
        cin >> B[i];
    }


    long long ans = 0;
    int del;
    int sub;
    for (int i=0;i<n;i++){
        del = min(A[i],B[i]);
        A[i] -= del;
        ans += del;
        del= min(A[i+1],B[i] - del);
        A[i+1] -= del;
        ans += del;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{ 
  int N;cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  sort(ALL(vec));
  vector<int> acc(N);
  partial_sum(ALL(vec),acc.begin());
  // DEBUG(acc);
  int index = -1;
  for (int i = 0; i < N-1; i++)
  {
    if(vec[i+1] > acc[i]*2)
    {
      index = i;
    }
  }
  // DEBUG(index);
  cout<<N-1 -index<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

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

  int c = a * b % 2;
  
  if (c == 1) {
    cout << "Odd" << endl;
  }
  
  else {
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    p,q,r = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    print(min(p+q,q+r,r+p))




if __name__ == "__main__":
    main()

Measured memory_bytes: 77396
#include<cstdio>
#include<cstring>
using namespace std;
long long n,x;
long long read()
{
	long long x=0,f=1;
	char c=getchar();
	while('0'>c||c>'9'){if(c=='-')f=-1;getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
long long solve(long long a,long long b)
{
	if(a==0) return -b;
	return b/a*2*a+solve(b%a,a);
}
int main()
{
	n=read(),x=read();
	printf("%lld",solve(x,n-x)+n);
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#define INT long long int
#define MOD 1000000007
#define oo 987654321
using namespace std;
int n, m, k, a[100001], p;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    if( n%2 == 1 ) m++;
    for(int i = 0, t ; i < n ; i++ )
    {
        cin>>t;
        if( t%4 == 0 ) m++;
        else if( t%2 == 0 ) k++;
        else p++;
    }
    if( m >= p ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom = label
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = self.rear , self.bottom, self.front, self.top
    def print_top(self):
        print(self.top)
    def print_right(self):
        print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
   
label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)


Measured memory_bytes: 5608
#include <cstdio>
#include <cstring>
#include <functional>
#include <random>

using namespace std;

#define int long long
#define uint unsigned int
#define dotimes(i, n) for (int i = 0, i##max__ = (n); i < i##max__; i++)
#define whole(x, f, ...) ([&](decltype((x)) c) { return (f)(begin(c), end(c), ## __VA_ARGS__); })(x)

int rint() {
  int x;
  scanf("%lld", &x);
  return x;
}

void wint(int x) {
  printf("%lld\n", x);
}

template<typename T> int size(T const& c) { return static_cast<int>(c.size()); }
template <typename T> bool maxs(T& a, T const& b) { return a < b ? a = b, true : false; }
template <typename T> bool mins(T& a, T const& b) { return a > b ? a = b, true : false; }
inline int lg(int x) { return 63 - __builtin_clzll(static_cast<unsigned int>(x)); }

constexpr uint mask30 = (1ull << 30) - 1, mask31 = (1ull << 31) - 1, mask61 = (1ull << 61) - 1;

uint add61(uint x, uint y) {
  uint z = x + y, w = (z >> 61) + (z & mask61);
  return w < mask61 ? w : w - mask61;
}

uint sub61(uint x, uint y) {
  return x >= y ? x - y : mask61 - (y - x);
}

uint mul61(uint x, uint y) {
  uint a = x >> 31, b = x & mask31, c = y >> 31, d = y & mask31, z = a * d + b * c, e = z >> 30, f = z & mask30;
  return (2 * a * c + e + (f << 31) + b * d) % mask61;
}

uint pow61(uint x, int n) {
  uint r = 1;
  for (; n; n >>= 1, x = mul61(x, x))
    if (n & 1)
      r = mul61(r, x);
  return r;
}

signed main() {
  constexpr int s_max = 5e5;
  char s[s_max+1], t[s_max+1];
  scanf("%s\n%s\n", s, t);
  const int m = strlen(s), n = strlen(t);
  const uint b1 =
    []() {
      std::random_device rd;
      std::mt19937_64 prng((static_cast<uint>(rd()) << 32) | rd());
      std::uniform_int_distribution<uint> uid(256, mask61 - 2);
      return uid(prng);
    }();
  bool fs[m];
  uint hs = 0, ht = 0, b = 1;
  for (int i = 0; ; i++, b = mul61(b1, b)) {
    ht = add61(ht, mul61(b, t[n-i-1]));
    hs = add61(hs, mul61(b, s[(n-i-1)%m]));
    if (i == n-1)
      break;
  }
  fs[0] = ht == hs;
  dotimes(i, m-1) {
    hs = add61(mul61(b1, sub61(hs, mul61(b, s[i]))), s[(i+n)%m]);
    fs[i+1] = ht == hs;
  }
  int rs[m] = {}, r = 0;
  function<int(int)> rec;
  rec =
    [&](int i) {
      if (rs[i] || !fs[i])
        return rs[i];
      rs[i] = -1;
      int x = rec((i+n)%m);
      if (x < 0)
        return x;
      return rs[i] = x + 1;
    };
  dotimes(i, m) {
    int x = rec(i);
    if (x < 0) {
      r = -1;
      break;
    }
    maxs(r, x);
  }
  wint(r);
  return 0;
}


Measured memory_bytes: 32068