akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int INF = 1 << 28;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
typedef pair<int, int> Point;

int H, W, K;
char grid[64][64];
vector<Point> rem[4];
int vis[64][64];
int dp[50][50][4][1 << 12];

void init()
{
	memset(grid, '#', sizeof(grid));
	memset(dp, -1, sizeof(dp));
	
	for (int k = 0; k <= 3; k++){
		for (int x = -k; x <= (3 - k); x++){
			for (int y = -k; y <= (3 - k); y++){
				//if (x == 0 && y == 0) continue;
				if (-k <= (x + y) && (x + y) <= (3 - k)){
					rem[k].push_back(Point(x, y));
				}
			}
		}
	}
}

inline int calcBit(int x, int y, int k)
{
	int res = 0;
	for (Point &p : rem[k]){
		res <<= 1;
		int X = x + p.first;
		int Y = y + p.second;
		if (vis[X][Y] > 0) res |= 1;
	}
	return res;
}

int calc(int x, int y, int k)
{
	int bit = calcBit(x, y, k);
	int &res = dp[x - 3][y - 3][k][bit];
	if (~res) return res;
	
	int add = 0;
	if (grid[x][y] >= '1' && grid[x][y] <= '9'){
		if (vis[x][y] == 0){
			add = grid[x][y] - '0';
		}
	}
	
	if (x == H + 2 && y == W + 2 && k == 0){
		return res = add;
	}
	
	res = -INF;
	
	vis[x][y]++;
	for (int dir = 0; dir < 4; dir++){
		int nx = x + dx[dir];
		int ny = y + dy[dir];
		int nk = k - (dir < 2);
		if (grid[nx][ny] == '#') continue;
		if (nk < 0) continue;
		res = max(res, calc(nx, ny, nk));
	}
	vis[x][y]--;
	
	return res += add;
}

int main(void)
{
	init();
	
	scanf("%d %d %d", &H, &W, &K);
	
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			scanf(" %c", &grid[i + 3][j + 3]);
		}
	}
	
	printf("%d\n", calc(3, 3, K));
	
	return 0;
}

Measured memory_bytes: 161212
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if i % 2 == 0 and a[i] % 2 == 1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9460
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N,M;
    cin >> N >> M;
    VI X(M);
    REP(i,M)
    {
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    VI dif(M-1);
    REP(i,M-1)
    {
        dif[i] = abs(X[i] - X[i+1]);
    }
    sort(dif.begin(), dif.end());
    int nes = M - N;
    if(nes == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    LL ans = 0;
    REP(i,nes)
    {
        ans += dif[i] * 1ll;
    }
    cout << ans << endl;



}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a);
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef double db;
const db EPS = 1e-9;
using namespace std;

void dbg() {cout << "\n";}
template<typename T, typename... A> void dbg(T a, A... x) {cout << a << ' '; dbg(x...);}
#define logs(x...) {cout << #x << " -> "; dbg(x);}

int n,a,b;

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	a = b-a-1;
	if(a % 2) printf("Alice\n");
	else printf("Borys\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


int main(){
    
    
    ll N;
    cin >> N;
    
    string S = "";
    
    ll ans = N;
    ll a = 1;
    if(N==0){
        cout << 0 << endl;
        return 0;
    }
    while (N!=0) {
        if(N%(a*(-2)) == 0) S+='0';
        else{
            S+='1';
            N -= a;
        }
        a = a*(-2);
    }
    
    for (int i = int(S.length())-1; i>=0; i--) {
        cout << S[i];
    }
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  LL N,i,ans=0;
  scanf("%lld",&N);
  for(i=sqrt(N);i>0;i--)if(N%i==0){
    ans=i+N/i-2;
    break;
  }

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


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Dictionary<long, long> dict = new Dictionary<long, long>();
        long ans = 0;

        for (long i = 0; i < nk[0]; i++)
        {
            if (dict.ContainsKey(a[i]))
            {
                dict[a[i]]++;
            }
            else
            {
                dict[a[i]] = 1;
            }
        }

        int types = dict.Count();
        var d = dict.OrderBy(x => x.Value);

        foreach (var item in d)
        {
            if(types > nk[1])
            {
                ans += item.Value;
                types--;
            }
            else
            {
                break;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 45252
import math

a, b, h, m = map(int, input().split())

#c = (h/6 - m/360)*math.pi
c = 11.0/360.0*(60*h+m)*math.pi
x = math.sqrt(a * a + b * b - 2 * a * b * math.cos(c))
print(x)

#double c = (h/6 - m/360)*pi;
#x = sqrt(a * a + b * b - 2 * a * b * cos(c));
#cout << fixed << setprecision(15) << x << endl;


Measured memory_bytes: 9496
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	int a = 700;
	for (auto ch : s) {
		if (ch == 'o') a += 100;
	}
	cout << a << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include <cstring>
#include<bits/stdc++.h> 
using namespace std;   
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d);
    return 0;  
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;
struct X {
	int a, b;
	bool operator<(X &r) const {
		return a * (r.b + 1) > r.a * (b + 1);
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, T;
	cin >> N >> T;
	vector<X> A;
	vector<int> B;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 0) {
			B.push_back(b);
		} else {
			A.push_back(X{a, b});
		}
	}
	sort(B.begin(), B.end());
	sort(A.begin(), A.end());
	int L = 35;
	int INF = T + 10;
	vector<vector<int> > dp(A.size() + 1, vector<int>(L, INF));
	dp[0][0] = 0;
	for (int i = 0; i < A.size(); i++) {
		for (int j = 0; j < L - 1; j++) {
			if (dp[i][j] < INF) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], (A[i].a + 1) * (dp[i][j] + 1) + A[i].b);
			}
		}
	}
	int res = 0;
	for (int i = 0; i < L; i++) {
		int rest = T - dp[A.size()][i];
		if (rest >= 0) {
			int tmp = i;
			for (int j = 0; j < B.size(); j++) {
				if (rest - (B[j] + 1) >= 0) {
					rest -= (B[j] + 1);
					tmp++;
				} else {
					break;
				}
			}
			cerr << i << " " << rest << " " << tmp << endl;
			res = max(res, tmp);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 65260
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;
  ll cur = 1;
  for (int i = 0; i < N; i++) {
    cur = min(cur * 2, cur + K);
  }
  cout << cur << endl;
  return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scn = new Scanner(System.in);
		int  A = scn.nextInt();
		int  B = scn.nextInt();
		int ans=0;
		if(((A>=1) && (A<=100)) && ((B>=1) && (B<=100))) {
			ans = A*B;
			System.out.println(ans);
		}
}
}

Measured memory_bytes: 35764
#include <bits/stdc++.h>
using namespace std; 
#define ff first
#define ss second
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007
int x,y,d;
void gcd(int a,int b){
	if(b==0){
		d=a;
		x=1;
		y=0;
		return ;
	}
	gcd(b,a%b);
	int X,Y;
	X=y;
	Y=x-(a/b)*y;
	x=X;  y=Y;
}
int a,b,c,m; 
int exp(int a,int b){
	m=b+1;
	int res=1;
	while(b!=0){
		if(b&1){
			res*=a;
			res%=m;
		}
		b/=2;
		a*=a; a%=m;
	}
	return res;
}
void prime(){
	int n; cin>>n;
	if(n<2){
		cout<<"composite\n";
		return ;
	}else if(n==2){
		cout<<"prime\n";
		return ;
	}else if(n%2==0){
		cout<<"composite\n";
		return ;
	}else {
		for(int i=3;i*i<=n;i+=2){
			if(n%i==0){
				cout<<"composite\n";
				return ;
			}
		}
		cout<<"prime\n";
	}
}
void toutient(int n) {
    vector<int> phi(n + 1);
    phi[0] = 0;
    phi[1] = 1;
    for (int i = 2; i <= n; i++)
        phi[i] = i - 1;

    for (int i = 2; i <= n; i++)
        for (int j = 2 * i; j <= n; j += i)
              phi[j] -= phi[i];
	cout<<phi[n];
}
int pr[11000];
int dig(int a){
	int s=0;
	while(a!=0){
		s+=(a%10);
		a/=10;
	}
	return s;
}
int ans[11000];
void seive(){
	pr[0]=pr[1]=1;
	for(int i=2;i<11000;++i){
		if(pr[i]==0){
			for(int j=2*i;j<11000;j+=i){
				pr[j]=1;
			}
		}
	}
	for(int i=0;i<11000;++i)
		ans[i]=-1;
	for(int i=0;i<11000;++i){
		if(pr[i]==0){
			ans[i]=1;
			if(i<100){
				ans[i*i]=1;
			}
		}
		else if(ans[i]==-1) ans[i]=LLONG_MAX;
	}
	vector<int> v;
	for(int i=0;i<11000;++i)
	if(ans[i]==1)
	v.push_back(i);
	for(int i=0;i<11000;++i){
		if(ans[i]!=LLONG_MAX){
			for(auto it : v){
				ans[i+it]=min(ans[i+it],ans[i]+1);
			}
		}
	}
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//seive();
	int k,n; cin>>k>>n;
	int a[n]; for(int i=0;i<n;++i) cin>>a[i];
	sort(a,a+n);
	int mn=LLONG_MIN;
	for(int i=0;i<n-1;++i){
		int dp=abs(a[i]-a[(i+1)%n]);
	//	cout<<dp<<" ";
		mn=max(mn,dp);
	}
	int last=k-a[n-1]+a[0];
	mn=max(mn,last);
	cout<<k-mn<<"\n";
 	return 0;
}

Measured memory_bytes: 1792
S = list(map(int, input().split()))

num5 = num7 = 0
for s in S:
  if s == 5:
    num5 += 1
  if s == 7:
    num7 += 1

if num5 == 2 and num7 == 1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int n;
int a[100],b[100];
int main() {
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        sum+=max(0,a[i]-b[i]);
    }
    cout<<sum;

    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
counts = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if (500*a + 100*b + 50*c) == X:
                counts += 1
                
print(counts)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,n) for(i=0;i<n;i++)
#define PI 3.14159265358979323846264338327950L
int main(){
    double l;
    scanf("%lf",&l);
    printf("%.7f",(l/3)*(l/3)*(l/3));
    return 0;
}

Measured memory_bytes: 1752
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=1005;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
int n,m;
char c[maxn][maxn];
int dist[maxn][maxn];
queue<pii>q;

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,n){
		scanf("%s",c[i]);
		rep(j,m)dist[i][j]=INF;
		rep(j,m){
			if(c[i][j]=='#'){
				dist[i][j]=0;
				q.push(mp(i,j));
			}
		}
	}
	while(!q.empty()){
		int x=q.front().fst,y=q.front().snd;
		q.pop();
		rep(d,4){
			int nx=x+dx[d],ny=y+dy[d];
			if(nx>=0&&nx<n&&ny>=0&&ny<m&&dist[nx][ny]==INF){
				dist[nx][ny]=dist[x][y]+1;
				q.push(mp(nx,ny));
			} 
		} 
	}
	int ans=0;
	rep(i,n)rep(j,m)ans=max(ans,dist[i][j]);
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 13328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
#define INF 1000000007
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    ll ans=0;
    for(ll i=a;i<=b;i++){
        string s=to_string(i);
        if(s[0]==s[4] && s[1]==s[3]){
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for(; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
const int N = 2333;
int n, m, q;
int sum[N][N], sum2[N][N], x[N][N], y[N][N], a[N][N];
char str[N][N];

inline int get1(int fx, int fy, int sx, int sy) {
  return sum[sx][sy] - sum[sx][fy - 1] - sum[fx - 1][sy] + sum[fx - 1][fy - 1];
}

inline int get2(int fx, int fy, int sx, int sy) {
  return sum2[sx][sy] - sum2[sx][fy - 1] - sum2[fx - 1][sy] + sum2[fx - 1][fy - 1];
}

inline int gety(int fx, int fy, int sx, int sy) {
  return y[sx][sy] - y[sx][fy - 1] - y[fx - 1][sy] + y[fx - 1][fy - 1];
}

inline int getx(int fx, int fy, int sx, int sy) {
  return x[sx][sy] - x[sx][fy - 1] - x[fx - 1][sy] + x[fx - 1][fy - 1];
}

inline void init(void) {
  for(int i = 1; i <= n; i ++)
    for(int j = 1; j <= m; j ++)
      sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
  for(int i = 1; i <= n; i ++)
    for(int j = 1; j <= m; j ++) {
      int s = a[i][j] + a[i - 1][j - 1] + a[i - 1][j] + a[i][j - 1];
      sum2[i][j] = (s == 4) + sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1];
    }
  
  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j <= m - 1; j ++) {
      int s = a[i][j] + a[i][j + 1];
      y[i][j] = (s == 2) + y[i - 1][j] + y[i][j - 1] - y[i - 1][j - 1];
    }
  }

  for(int j = 1; j <= m; j ++) {
    for(int i = 1; i <= n - 1; i ++) {
      int s = a[i][j] + a[i + 1][j];
      x[i][j] = (s == 2) + x[i - 1][j] + x[i][j - 1] - x[i - 1][j - 1];
    }
  }
}

main(void) {
  read(n); read(m); read(q);
  for(int i = 1; i <= n; i ++) {
    scanf("%s", str[i] + 1);
    for(int j = 1; j <= m; j ++)
      a[i][j] = str[i][j] - '0';
  }
  init();
  for(int i = 1; i <= q; i ++) {
    int x1, y1, x2, y2;
    read(x1); read(y1); read(x2); read(y2);
    int ans = 0;
    ans += get1(x1, y1, x2, y2);
    ans -= getx(x1, y1, x2 - 1, y2);
    ans -= gety(x1, y1, x2, y2 - 1);
    ans += get2(x1 + 1, y1 + 1, x2, y2);
    cout << ans << "\n";
  }
}


Measured memory_bytes: 108288
#方針: 中心点は 101×101パターンしかないので全探索できる。
n = gets.to_i
ary = Array.new(n){gets.split.map(&:to_i)}.sort_by{|a| a[2]}.reverse

(0..100).each do |i|
  (0..100).each do |j|
    tmp1 = [] #h>0が矛盾しないか判定用
    tmp2 =[] #h=0が矛盾しないか判定用

    ary.each do |a|
      if a[2]>0
        tmp1 << (a[0]-i).abs + (a[1]-j).abs + a[2]
      else
        tmp2 << tmp1[0] - (a[0]-i).abs - (a[1]-j).abs
      end
    end

    flag1 = tmp1.all?{|t| t == tmp1[0]}
    flag2 = tmp2.all?{|t| t <= 0}

    puts "%d %d %d" % [i,j,tmp1[0]] if flag1&&flag2

  end
end

Measured memory_bytes: 2424
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ull;
const ull MOD = 1000000007;
const int MAX_N = 100000;
ull fact[MAX_N + 1];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ull ans;
	fact[0] = 0;
	fact[1] = 1;
	ull fs = 1;
	for (int i = 2; i < MAX_N + 1; i++){
		fs = (fs*i) % MOD;
		fact[i] = (fact[i-1] + fs) % MOD;
	}
	while (1){
		int N, R;
		cin >> N;
		if (N == 0) break;
		vector<int> word(N);
		for (int i = 0; i < N; i++) word[i] = i;
		word.push_back(0);
		ans = 0;
		cin >> R;
		vector<int> s(2*R+2, 0);
		s[2 * R + 1] = N;
		for (int i = 0; i < R; i++){
			cin >> s[i] >> s[i+R];
			s[i]--; s[i+R]--;
			s.push_back(s[i] + 1);
			s.push_back(s[i+R] + 1);
			swap(word[s[i]], word[s[i+R]]);
		}
		sort(s.begin(), s.end());
		s.erase(unique(s.begin(), s.end()), s.end());
		for (int i = 0, R = s.size() - 1; i < R; i++){
			ull tmp = fact[N - s[i] - 1] - fact[N - s[i+1] - 1];
			tmp = (tmp * word[s[i]]) % MOD;
			ans =(ans + tmp) % MOD;
			int dif = s[i+1] - s[i];
			for (int j = i + 1; j < R; j++){
				word[s[j]] -= (word[s[j]] > word[s[i]] ? dif : 0);
			}
		}
		cout << (ans + MOD) % MOD << endl;
	}
	return 0;
}

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

using namespace std;
const int N=5e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,k;
    long long sum=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-k;i++)
        sum+=a[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

#define ll long long

const int maxn = 350;

int A[2];

int main(){
    scanf("%2d%2d",&A[0],&A[1]);
    bool l=false,r=false;
    if(A[0]>=1&&A[0]<=12)l=true;
    if(A[1]>=1&&A[1]<=12)r=true;
    if(l&&r)puts("AMBIGUOUS");
    else if(l)puts("MMYY");
    else if(r)puts("YYMM");
    else puts("NA");
}


Measured memory_bytes: 384
#include<stdio.h>

#define MAX 2000010

int Tree[MAX]; // Tree

int n;

void maxHeapify(int i){
  int largest, exchange, gl, gr;
  gl = getLeft(i);
  gr = getRight(i);
  
  if((n >= gl) && (Tree[gl] > Tree[i])) largest = gl;

  else largest = i;
  
  if((n >= gr) && (Tree[gr] > Tree[largest])) largest = gr;

  if (largest != i){

    exchange =  Tree[i];
    Tree[i] = Tree[largest];
    Tree[largest] = exchange;
    maxHeapify(largest);

  }  
}

void buildMaxHeap(){
  int i;
  for (i=(n/2); i>=1; i--){
    maxHeapify(i);
  }
}

void heapIncrease(int i, int key){
  int exchange;
  if(key < Tree[i]) printf("new key is smallar than current key");
  
  Tree[i] = key;

  while((i > 1) && (Tree[getParent(i)] <  Tree[i])){
    exchange = Tree[i];
    Tree[i] = Tree[getParent(i)];
    Tree[getParent(i)] = exchange;
    i = getParent(i);
  }

}
void maxHeapInsert(key){
  n = n + 1;
  Tree[n] = -2000000;
  heapIncrease(n, key);
}



int heapExtractMax(){
  int max;
  if(n < 1)return -1;
  max = Tree[1];
  Tree[1] = Tree[n];
  --n;
  maxHeapify(1);
  return max;
}

int getParent(int i){
  return i/2;
}

int getLeft(int i){
  return (2*i);
}

int getRight(int i){
  return (2*i + 1);
}


main()
{
  int n, i, x;
  char com[20];
  scanf("%d",&n);

  while(1){
    scanf("%s",com);
    if (com[0] == 'i'){
      scanf("%d",&x);
      maxHeapInsert(x);
    } else if (com[0] == 'e' && com[1] == 'x'){
      scanf("%d",&x);
      printf("%d\n",heapExtractMax());
    } else if (com[0] == 'e' && com[1] == 'n'){
      break;
    }
  }

  return 0;
}

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

int check(int n){
    if (n == 2){
        return 2;
    }
    else if (n == 4 or n == 6 or n == 9 or n == 11){
        return 1;
    }
    else{
        return 0;
    }
}

int main() {
    int a, b;
    cin >> a >> b;
    int A, B;
    A = check(a);
    B = check(b);
    if (A == B){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
from collections import deque


class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.cnt = n

    def root(self, x):
        """頂点xの根を求める"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """頂点xを含む集合と頂点y含む集合を結合する"""
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.parent[x] > self.parent[y]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x
            self.cnt -= 1

    def is_same(self, x, y):
        """頂点xと頂点yが同じ集合に属するかどうかを返す"""
        return self.root(x) == self.root(y)

    def get_size(self, x):
        """頂点xを含む集合の要素数を返す"""
        return -self.parent[self.root(x)]

    def get_cnt(self):
        """木の個数を返す"""
        return self.cnt
      

n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

# 辺数が奇数のときは構成不可能
if m % 2 != 0:
    print(-1)
    exit()

# 全域木の構成
uf = UnionFind(n)
tree = [[] for i in range(n)]
cnt = [0] * n
ans = []
for i in range(m):
    a, b = info[i]
    a -= 1
    b -= 1
    if uf.is_same(a, b):
        cnt[a] += 1
        ans.append((a + 1, b + 1))
    else:
        uf.merge(a, b)
        tree[a].append(b)
        tree[b].append(a)

# トポロジカルソート
root = 0
tps = [None] * n
q = deque([(-1, root)])
i = 0
while q:
    par, pos = q.pop()
    tps[i] = (par, pos)
    i += 1
    for child in tree[pos]:
        if par == child:
            continue
        else:
            q.append((pos, child))

# トポロジカル順の逆順で集めていく
for par, pos in tps[::-1]:
    if par == -1:
        continue
    if cnt[pos] % 2 == 0:
        cnt[par] += 1
        ans.append((par + 1, pos + 1))
    else:
        cnt[pos] += 1
        ans.append((pos + 1, par + 1))

# 答えの出力
for i in ans:
    print(*i)

Measured memory_bytes: 125400
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

inline int toInt(string s) { int v; istringstream sin(s); sin>>v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout<<x; return sout.str(); }

const int num[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
	ll N,M;
	cin >> N >> M;
	VLL a(M);
	VLL A(M);
	vector<PII> Ap;
	for(int i = 0; i < M; ++i) {
		 cin >> a[i];
		 Ap.push_back( make_pair(num[a[i]],i) );
	}
	sort(all(Ap));
	for(int i = 0; i < M; ++i)
		A[i] = a[Ap[i].second];
	vector<char> numChar;
	for(int i = 0; i < M; ++i) {
		string s = toString(A[i]);
		numChar.push_back(s[0]);
	}
	vector<string> dp(10101, "x");
	dp[0] = "";
	for(int i = 0; i < M; ++i) {
		for(int j = 0; j < N - num[A[i]] + 1; ++j)
			if(dp[j] != "x"){
				if(dp[j + num[A[i]]] != "x") {
					if(dp[j + num[A[i]]].size() < dp[j].size() + 1) dp[j + num[A[i]]] = dp[j] + numChar[i];
					else if(dp[j + num[A[i]]].size() > dp[j].size() + 1) continue;
					else if(dp[j + num[A[i]]].size() == dp[j].size() + 1) {
						string headS = dp[j] + numChar[i];
						string tailS = numChar[i] + dp[j];
						dp[j + num[A[i]]] = max(tailS,max(headS,dp[ j + num[ A[i] ] ]));
					}
				}
				else {
					string headS = dp[j] + numChar[i];
					string tailS = numChar[i] + dp[j];
					dp[j + num[A[i]]] = max(tailS, headS);
				}
			}
	}
	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 38528
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890l
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define space " "
#define cbr cout << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll H, W, h, w;
int main()
{
	cin>>H>>W>>h>>w;
	cout << (H*W)-(h*W + w*H - (h*w)) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
int main()
{
  std::string line;
  while (std::getline(std::cin, line)) {
    std::transform(line.cbegin(), line.cend(), line.begin(), ::toupper);
    std::cout << line << std::endl;
  }
  return 0;
}

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

typedef long long ll;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

string S;
mint dp[100005][13];
bool q[100005];
int mod13[] = {1, 10, 9, 12, 3, 4};

int s2i(char c) {
  return ((c-'0')==15 ? -1 : c-'0');
}

int mod13_pad(int i) {
  return mod13[i%6];
}

void solve(int N, int remain) {
  int cnt=0;
  rep(i, N) {
    if(!q[i]) continue;
    if(cnt==0) {
      rep(j, 10) {
        dp[0][(mod13_pad(N-i-1)*j)%13] += 1;
      }
    } else {
      rep(j, 10) {
        rep(k, 13) {
          dp[cnt][(k+(mod13_pad(N-i-1)*j))%13] += dp[cnt-1][k];
        }
      }
    }
    cnt++;
  }
  cout << dp[cnt-1][remain].x << endl;
}

int main() {
  cin >> S;
  int N = S.size();
  int sum=0;
  bool q_flag=true;
  rep(i, N) {
    int x=s2i(S[i]);
    if(x==-1) {
      q[i]=true;
      q_flag=false;
    }
    else sum+=x*mod13_pad(N-i-1);
  }
  sum = sum%13;
  int remain=(18-sum)%13;
  if(q_flag) {
    cout << (remain==0 ? 1 : 0) << endl;
    return 0;
  }
  solve(N, remain);
  return 0;
}



Measured memory_bytes: 10752
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const static int INFTY = (1 << 30);
int nums[10][10];
int xs[10], ys[10];
map<int, pair<int, int> > dist;
char a[100001];

int main()
{
    int N, curr, next;
    int test[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int finalNum[10];
    scanf("%d", &N);
    scanf("%s", a);
    memset(nums, 0, sizeof (nums));
    curr = int(a[0] - '0');
    for (int i = 1; i < N; i++) {
        next = int(a[i] - '0');
        nums[curr][next]++;
        curr = next;
    }
    int global_min = INFTY;
    do {
        curr = 0;
        int idx = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) xs[test[idx]] = i, ys[test[idx++]] = j;
        }

        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (nums[i][j]) curr += nums[i][j] * (abs(xs[i] - xs[j]) + abs(ys[i] - ys[j]));
            }
        }
        if (curr < global_min) {
            for (int i = 0; i < 9; i++) finalNum[i] = test[i];
            global_min = curr;
        }

    } while (next_permutation(test, test+9));

    int idx = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) printf("%d", finalNum[idx++]);
        printf("\n");
    }

    return 0;
}



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

using namespace std;


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

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

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

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

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

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

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

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

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

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

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

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

void debug_out()
{
    cerr << endl;
}

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

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


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    cout << ((x >= 30) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a[5];
  for(int i=0;i<5;i++){
    cin>>a[i];
  }
  sort(a,a+5,greater<int>());
  for(int i=0;i<5;i++){				
    cout<<a[i];
    if(i!=5-1) cout<<" ";
  }
  cout<<"\n";
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define pb push_back 
#define ff first 
#define ss second
#define all(c) c.begin(), c.end()
#define sz(z) (int)z.size()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define rev(i,a,b) for(int i=a; i>=b; i--)
//Debugging tools 
#define debug(v) cout<<#v<<endl;for(ll i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define debugn(v,n) cout<<#v<<endl;for(ll i=0; i<n; i++) cout<<v[i]<<" "; cout<<endl;
#define deb(sum) cout<<#sum<<" = "<<sum<<endl;
//Predefined values
#define INF (ll)1e18
#define endl "\n"
#define pi 3.142857142857143
const ll MOD = 1e9 + 7;


int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.in","r",stdin);
        freopen("output.in","w",stdout);
    #endif
    int t=1;    
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> a(n);
        rep(i,0,n) cin>>a[i];
        ll ans = 0;
        rep(i,1,n){
            if(a[i]<a[i-1]){
                ans += a[i-1]-a[i];
                a[i] = a[i-1];
            }
        }
        cout<<ans<<endl;
    }
  return 0;
 }

















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

int main() {
  int N,K;
  cin >> N >> K;
  
  int Ans=0;
  int h;
  
  for(int i=0;i<N;i++){
    cin >> h;
    if(h >= K) Ans++;
  }
  
  cout << Ans << endl;
}


Measured memory_bytes: 3612
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = list()

for a_list in range(0, n):
    a_list = list(map(int, input().split())) 
    a.append(a_list)

count = 0
calc_n = 0
while calc_n < n:
    ab = 0
    calc_m = 0
    while calc_m < m:
        ab += a[calc_n][calc_m] * b[calc_m]
        calc_m += 1
    check = ab + c
    if check > 0:
        count += 1
    calc_n += 1
print(count)

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

int main() {
  int m,d,ans = 0;
  cin >> m >> d;
  rep(i,m){
    rep(j,d){
      if(j/10 == 1 || j%10 == 1) continue;
      if((j/10)*(j%10) == i) ans++;
    }
  }
  cout<< ans << endl;
}

Measured memory_bytes: 256
// 桁ごとに獲得ポイントを計算してDP
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 40;
// const int MAX_N = 6;
int v[MAX_N];

pair<ll, ll> ps[1 << (MAX_N / 2)];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    ll k;
    cin >> n >> k;
    ll a[n];
    
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ll copy_a = a[i];
        for (int &e : v) {
            e += (copy_a & 1);
            copy_a /= 2;
        }
    }

    ll n2 = MAX_N / 2;
    for (int i = 0; i < 1 << n2; ++i) {
        ll sw = 0, sv = 0;
        ll base = 1;
        for (int j = 0; j < n2; ++j) {
            if (i >> j & 1) {
                sw += base;
                sv += (n - v[j]) * base;
            } else {
                sv += v[j] * base;
            }
            base *= 2;
        }
        ps[i] = make_pair(sw, sv);
    }

    sort(ps, ps + (1 << n2));

    int m = 1;
    for (int i = 1; i < 1 << n2; ++i) {
        if (ps[m - 1].second < ps[i].second) {
            ps[m++] = ps[i];
        }
    }

    ll x = 0;
    ll best_v = 0;
    for (int i = 0; i < 1 << (MAX_N - n2); ++i) {
        ll sw = 0, sv = 0;
        ll base = 1 << n2;
        for (int j = 0; j < MAX_N - n2; ++j) {
            if (i >> j & 1) {
                sw += base;
                sv += (n - v[n2 + j]) * base;
            } else {
                sv += v[n2 + j] * base;
            }
            base *= 2;
        }
        if (sw <= k) {
            auto itr = lower_bound(ps, ps + m, make_pair(k - sw, (ll)1e12 + 1)) - 1;
            ll tv = itr->second;
            if (best_v < sv + tv) {
                best_v = sv + tv;
                x = itr->first + sw;
            }
        }
    }

    ll res = 0;
    for (int i = 0; i < n; ++i) {
        res += a[i] ^ x;
    }

    cout << res << '\n';
    
    return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector<int> plus, minus;
    rep(i, n){
        int x;
        cin >> x;
        if(x < 0) minus.push_back(-x);
        else plus.push_back(x);
    }
    reverse(minus.begin(), minus.end());

    ll res = 1LL << 60;
    rep(i, minus.size()){
        ll cost = minus[i];
        int cnt = i+1;
        if(cnt >= k){
            res = min(res, cost);
            break;
        }

        cost += minus[i];

        if((int)plus.size() + cnt < k) continue;
        cost += plus[k - cnt - 1];

        res = min(res, cost);
    }

    rep(i, plus.size()){
        ll cost = plus[i];
        int cnt = i+1;
        if(cnt >= k){
            res = min(res, cost);
            break;
        }

        cost += plus[i];

        if((int)minus.size() + cnt < k) continue;
        cost += minus[k - cnt - 1];

        res = min(res, cost);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1020
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

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

	a.sort_by_key(|&x| std::cmp::Reverse(x));

	let mut turn = 0usize;
	let mut score = [0usize, 0usize];
	for i in 0..n {
		score[turn] += a[i];
		turn = 1 - turn;
	}

	println!("{}", score[0] - score[1]);
}



Measured memory_bytes: 2132
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    s = list(map(int, input()))
    d = [float("inf")]*(n+1)
    d[n] = 0
    i = n
    p = n
    while i:
        nd = d[i]+1
        for j in range(1,min(i,m)+1):
            k = p-j
            if not s[k]:
                d[k] = nd
                i = k
        if i == p:
            print(-1)
            return
        p = i
    ans = []
    l = 0
    while l < n:
        for i in range(1,min(m,n-l)+1):
            if d[l+i] < d[l]:
                l += i
                ans.append(i)
                break
    print(*ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 57308
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    ll ans = 1e12;
    for (int i=-100; i<=100; i++) {
        ll buf = 0;
        for (int x : a) {
            buf += (x-i)*(x-i);
        }
        ans = min(ans, buf);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >>N>>K;
  int p=0;
  int A=1;
  while(p<N){
    if (A<K){
      A=A*2;
    }else{
      A+=K;
    }
    p++;
  }
  cout << A<<endl;
}

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

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

  bool can = false;
  for (int i = 1; i <= 9; i++) {
      for (int j = i; j <= 9; j++)
      {
          int product = i * j;
          if (product == n) {
              can = true;
          }
      }
  }

  cout << (can ? "Yes" : "No") << endl;
  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ta = a;
  int tb = b;
  int tc = c;
  int tot = a + b + c;
  int ans = 0;
  while (true) {
    if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
      break;
    }
    a = (tot - a) / 2;
    b = (tot - b) / 2;
    c = (tot - c) / 2;
    ans++;
    if (a == ta && b == tb && c == tc) {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();

        int xd = tx - sx;
        int yd = ty - sy;

        for (int y = 0; y < yd; y++) {
            out.print("U");
        }

        for (int x = 0; x < xd; x++) {
            out.print("R");
        }

        for (int y = 0; y < yd; y++) {
            out.print("D");
        }

        for (int x = 0; x < xd; x++) {
            out.print("L");
        }

        out.print("L");
        for (int y = 0; y < yd + 1; y++) {
            out.print("U");
        }

        for (int x = 0; x < xd + 1; x++) {
            out.print("R");
        }
        out.print("D");

        out.print("R");
        for (int y = 0; y < yd + 1; y++) {
            out.print("D");
        }

        for (int x = 0; x < xd + 1; x++) {
            out.print("L");
        }
        out.print("U");

        out.println();
    }
}

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

#ifdef DEBUG
    #include "debug.h"
    #define DEB
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define DEB if (false)
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)


void solve(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N){ cin >> A[i];
        if(A[i]==0){cout <<0<<endl; return;}
    }
    int ans = 1;
    rep(i,N){
        if(A[i] > 1000000000000000000LL/ans){ cout << -1 << endl; return;}
        ans *= A[i];
        if(ans >1000000000000000000LL ){ cout << -1 << endl; return;}
    }
    cout << ans << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 4040
nums={}
while True:
    p,s=map(int,input().split(','))
    if(p==0 and s==0):break
    if not s in nums:
        nums[s]=[]
    nums[s].append(p)

while True:
    try:
        q=int(input())
        ans=len(nums)
        for ns in nums.items():
            if q in ns[1]:
                print(ans)
                break
            ans-=1
    except:
        break

Measured memory_bytes: 7560
import sys
import numpy as np
input = sys.stdin.readline
N, T = [int(x) for x in input().split()]
C = []
for _ in range(N):
    temp = [int(x) for x in input().split()]
    C.append(temp)
ans = []
for i in C:
    c, t = i
    if t <= T:
        ans.append(c)
if len(ans) > 0:
    print(min(ans))
else:
    print("TLE")

Measured memory_bytes: 12692