akhauriyash/Code-Regression huggingface dataset:
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


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


const int N = 100002;
int n, K, A[N], B[N];


int is_valid(int val, int pos){
	if(pos>=0 && ((val >> pos) & 1))	return 0;
	for(int i=29;i>pos;i--){
		if((K >> i) & 1)	continue;
		if((val >> i) & 1)	return 0;
	}
	return 1;
}

 
int main(){
 
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);

	scanf("%d%d", &n, &K);
	for(int i=1;i<=n;i++){
		scanf("%d%d", &A[i], &B[i]);
	}

	bool yes = false;
	ll ans = 0;
	for(int j=1;j<=n;j++)
		ans += B[j] * is_valid(A[j], -1);

// cout<<ans<<endl;

	for(int i=29;i>=0;i--){
		if((K >> i) & 1)	yes = true;
		else	continue;
		if(!yes)	continue;
// cout<<"yolo"<<endl;
		ll temp = 0;
		for(int j=1;j<=n;j++)
			temp += B[j] * is_valid(A[j], i);
		ans = max(ans, temp);
// cout<<temp<<endl;
// 		break;
	}

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








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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point& operator+=(Point p){
		x+=p.x,y+=p.y;
		return *this;
	}
	Point& operator-=(Point p){
		x-=p.x,y-=p.y;
		return *this;
	}
	Point& operator*=(double c){
		x*=c,y*=c;
		return *this;
	}
	Point& operator/=(double c){
		x/=c,y/=c;
		return *this;
	}
};
Point operator+(Point a,Point b){
	return a+=b;
}
Point operator-(Point a,Point b){
	return a-=b;
}
Point operator*(Point a,double c){
	return a*=c;
}
Point operator*(double c,Point a){
	return a*=c;
}
Point operator/(Point a,double c){
	return a/=c;
}
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return !(a==b);
}

double Abs(Point p){
	return sqrt(p.x*p.x+p.y*p.y);
}
double Abs2(Point p){
	return p.x*p.x+p.y*p.y;
}
double Arg(Point p){
	return atan2(p.y,p.x);
}
double Dot(Point a,Point b){
	return a.x*b.x+a.y*b.y;
}
double Cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}
Point Rot(Point p,double t){
	return Point(cos(t)*p.x-sin(t)*p.y,sin(t)*p.x+cos(t)*p.y);
}

struct Line{
	Point pos,dir;
	Line(){}
	Line(Point p,Point d):pos(p),dir(d){}
	Line(double px,double py,double dx,double dy):pos(px,py),dir(dx,dy){}
};

Point Proj(Line l,Point p){
	Point a=p-l.pos,b=l.dir;
	return l.pos+Dot(a,b)/Abs2(b)*b;
}

int main()
{
	Line l;
	{
		double a,b,c,d; cin>>a>>b>>c>>d;
		l=Line(a,b,c-a,d-b);
	}
	int q; cin>>q;
	rep(_,q){
		Point p; cin>>p.x>>p.y;
		Point q=Proj(l,p);
		printf("%.10f %.10f\n",q.x,q.y);
	}
}

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

using namespace std;

#define MOD 1000000007

int main() {
    int h, w;

    cin >> h >> w;

    vector<vector<char>> a(h, vector<char>(w));

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> a.at(i).at(j);
        }
    }

    vector<vector<int>> dp(h, vector<int>(w));

    dp.at(0).at(0) = 1;

    for(int j = 1; j < w; ++j) {
        dp.at(0).at(j) = (a.at(0).at(j) == '.') ? dp.at(0).at(j - 1) : 0;
    }

    for(int i = 1; i < h; ++i) {
        dp.at(i).at(0) = (a.at(i).at(0) == '.') ? dp.at(i - 1).at(0) : 0;
    }

    for(int i = 1; i < h; ++i) {
        for(int j = 1; j < w; ++j) {
            dp.at(i).at(j) = (a.at(i).at(j) == '.') ? (dp.at(i - 1).at(j) + dp.at(i).at(j - 1)) % MOD : 0;
        }
    }

    printf("%d\n", dp.at(h - 1).at(w- 1));

    return 0;
}


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

int main() {
    vector <int> vec;
    vec ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
  	cout << vec.at(K-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
ll mod = 1e9 + 7;
/* CELEBW23 */
#include <stdio.h>                                                              
#include <wchar.h>                                                              

int main(void)
{
	int n, a[30], b[30], c[30], i, j, k,ans=0;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for (i = 1; i <= n; i++)
	{
		cin >> b[i];
		ans += b[i];
	}
	for (i = 1; i <= n-1; i++)
	{
		cin >> c[i];
	}
	for (i = 1; i <= n - 1; i++)
	{
		if (a[i] + 1 == a[i + 1]) ans += c[a[i]];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int m1,d1,m2,d2;cin>>m1>>d1>>m2>>d2;
  if(d2==1)
    cout<<1;
  else
    cout<<0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
int main(void) {
	int x,y;
	while (true) {
		scanf("%d %d", &x, &y);
		if ((x == 0) && (y == 0)) {
			break;
		}
		if (x < y) {
			printf("%d %d\n", x, y);
		}
		else {
			printf("%d %d\n", y, x);
		}
	}
	return 0;
}

Measured memory_bytes: 3176
import java.util.Scanner;
import java.io.FileReader;

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

    int x = in.nextInt();
    int y = in.nextInt();

    if ((x * y)%2 == 1) {
      System.out.print("Odd");
    } else {
      System.out.print("Even");
    }
  }
}

Measured memory_bytes: 23124
N = int(input())
S = input()

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, j-i)
        else:
            dp[i][j] = 0

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans = max(ans, dp[i][j])

print(ans)

Measured memory_bytes: 230152
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
mod = 10**9+7
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        primes[2]+=1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            primes[f]+=1
            n //= f
        else:
            f += 2
    if n != 1:
        primes[n]+=1
    return

primes = [0]*(N+1)
for i in range(1, N+1):
    prime_factorize(i)
ans = 1
for p in primes:
    ans *= (p+1)
    ans %= mod
print(ans)

Measured memory_bytes: 65488
#include<bits/stdc++.h>
#define maxs 202020
#define ll long long
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;
ll va[maxs];
ll c[55][55];

void init(){
    mme(c,0);
    c[0][0]=1;
    for(int i=1;i<51;i++){
        c[i][0]=1;
        for(int j=1;j<=i;j++){
            c[i][j]=c[i-1][j-1]+c[i-1][j];
        }
    }
   // printf("is %d\n",c[1][2]);
}

map<ll,ll>mp;

bool cmp(ll x,ll y){
    return x>y;
}

int main()
{
    init();
    int n,a,b;
    while(~scanf("%d%d%d",&n,&a,&b) ) {

        for(int i=1;i<=n;i++)
            scanf("%lld",&va[i]);

        sort(va+1,va+1+n,cmp);

        double sum = 0;
       // printf("%.6f\n",sum);
        ll cnt=0;
        
        for(int i=1;i<=a;i++)
            sum+=va[i];

        sum/=a;

        ll num=0;

        for(int i=1;i<=n;i++){

            if( va[i]==va[a]){
                num++;
                if(i<=a)
                    cnt++;
            }
        }

        ll opt=0;
        
        if(cnt == a){
            for(int i=a;i<=b;i++)
                opt+=c[num][i];
        }else
            opt+=c[num][cnt];

        printf("%.7f\n%lld\n",sum,opt);
    }
    return 0;
}

Measured memory_bytes: 256
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import Data.Bits
import Data.Array.MArray
import Data.Array.ST
import Control.Monad.ST
import Control.Applicative
import Data.STRef
import qualified Data.Set as S

data UnionFind s = UnionFind {graph :: STArray s Int (Maybe Int), total :: STArray s Int Int}
newUnionFind :: Int -> Int -> ST s (UnionFind s)
newUnionFind start end = liftA2 UnionFind (newArray (start, end) Nothing) (newArray (start, end) 1)

root :: UnionFind s -> Int -> ST s Int
root u i = do
    parent <- readArray (graph u) i
    parent <- case parent of
        Nothing -> do
            writeArray (graph u) i $ Just i
            pure i
        Just p ->
            pure p
    if parent == i then pure parent
    else do
        parent' <- root u parent
        writeArray (graph u) i (Just parent')
        pure parent'

unite :: UnionFind s -> Int -> Int -> ST s ()
unite u ix iy = do
    rx <- root u ix
    ry <- root u iy
    if rx == ry then pure ()
    else do 
        sizex <- size u rx 
        sizey <- size u ry
        if sizex < sizey then do
            -- yが高い yが親
            writeArray (graph u) rx (Just ry)
            writeArray (total u) ry (sizex + sizey) 
        else do
            -- xが高い xが親
            writeArray (graph u) ry (Just rx)
            writeArray (total u) rx (sizex + sizey)

same :: UnionFind s -> Int -> Int -> ST s Bool
same u x y = liftA2 (==) (root u x) (root u y)

size :: UnionFind s -> Int -> ST s Int
size u i = root u i >>= readArray (total u)



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- words <$> getLine
    return (read a, read b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- words <$> getLine
    return (read a, read b, read c)

solve :: Int -> [(Int, Int, Int)] -> Int
solve n xyzs = runST $ do
    uf <- newUnionFind 1 n
    forM_ xyzs $ \(x,y,_) ->
        unite uf x y
    roots <- forM [1..n] $ \i->
        root uf i
    pure . S.size . S.fromList $ roots
    


main = do
    (n, m) <- readTuple2
    xyzs <- replicateM m readTuple3
    print $ solve n xyzs


Measured memory_bytes: 75132
import math

x = int(input())

ans = 0
exponent = []

for i in range(1,int(math.sqrt(x))+1):
  for j in range(2, int(math.log(x, 2))+1):
    ans = i ** j
    exponent.append(ans)

exponent.sort()
exponent = [i for i in exponent if i <= x]

if x == 1:
  print(1)
else:
  print(max(exponent))

Measured memory_bytes: 38512
import java.util.*;
public class Main {
	public static ArrayList<Integer> list = new ArrayList<Integer>();
	public static String[] LIST = new String[] {"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","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"}; 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			int[] key = new int[n];
			for(int i = 0; i < n; i++) {
				key[i] = stdIn.nextInt();
			}
			String list = stdIn.next();
			int c = 0;
			for(int i = 0; i < list.length(); i++) {
				int p = key[c % key.length];
				String a = list.substring(i, i+1);
				for(int j = 0; j < LIST.length; j++) {
					if(a.equals(LIST[j])) {
						int ck = (j - p) % LIST.length;
						while(ck < 0) {
							ck += LIST.length;
						}
						
						System.out.print(LIST[ck]);
						break;
					}
				}
				c++;
 			}
			System.out.println();
			
		}
		
	}
}

Measured memory_bytes: 24460
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 h, w;
vector<string> a;
int main() {
  cin >> h >> w;
  read_n(a, h);

  i64 i = 0, j = 0;
  while (true) {
    a[i][j] = '.';
    if (i < h - 1 && a[i + 1][j] == '#') ++i;
    else if (j < w - 1 && a[i][j + 1] == '#') ++j;
    else break;
  }
  for (i64 i = 0; i < h; ++i) {
    for (i64 j = 0; j < w; ++j) {
      if (a[i][j] == '#') {
        cout << "Impossible\n";
        return 0;
      }
    }
  }
  cout << "Possible\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void){
    int N;
    scanf("%d",&N);
    int D,X,counter = 0;
    scanf("%d %d",&D,&X);
    int i,a[N];
    for(i=0;i<N;i++){
        counter ++;
        scanf("%d",&a[i]);
        counter += (D-1)/a[i];
    }
    counter += X;
    printf("%d\n",counter);
    
    return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  vi an[n];
  int a,b;
  rep(i,m) {
    cin>>a>>b;
    a--;b--;
    an[a].push_back(b);
    an[b].push_back(a);
  }
  
  int bn[n];rep(i,n)bn[i]=-1;
  bn[0]=0;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    for (int nv: an[v]) {
      if (bn[nv] != -1) continue; // すでに発見済みの頂点は探索しない

      //cout<<v<<" "<<nv<<endl;
      // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      bn[nv] = v+1;
      que.push(nv);
    }
  }


  
  cout<<"Yes"<<endl;
  rep(i,n-1) cout<<bn[i+1]<<endl;
}


Measured memory_bytes: 10336
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	string s;
	cin>>s;
	if(s=="ABC"){
		cout<<"ARC"<<endl;
	}else{
		cout<<"ABC"<<endl;
	}
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

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

    int tap = 0;
    int aki = 1;
    while(1){
        if( aki >= B ){
            break;
        }
        tap++;
        aki = aki - 1 + A;
    }
    cout << tap << endl;
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <map>
#include <regex>
#include <sstream>
#include <utility>
#include <list>
#include <unordered_set>
#include <unordered_map>
#define endl	'\n'
#define MOD 1000000

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
int dx[] = { 0,1,0,-1 };
int dy[] = { -1,0,1,0 };
int dz[] = { 0,0,0,0,1,-1 };
const int INF = 1000000000;

bool chk[200001];
vector<int> v[200001];
ll val[200001];
int n, q;


void dfs(int cur, ll pv) {
	chk[cur] = true;
	val[cur] += pv;
	for (int next : v[cur]) {
		if (chk[next]) continue;
		dfs(next, val[cur]);
	}
}


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

	cin >> n >> q;
	int a, b;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	while (q--) {
		int p, x;
		cin >> p >> x;
		val[p] += x;
	}

	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		cout << val[i] << ' ';
	}
}


Measured memory_bytes: 21376
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>

using namespace std;

int main() {
	int n,k2;cin>>n>>k2;
	long long x[n],y[n];
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n-1;j++){
			if(x[j]>x[j+1]){
				int temp=x[j];
				x[j]=x[j+1];
				x[j+1]=temp;
				temp=y[j];
				y[j]=y[j+1];
				y[j+1]=temp;
			}
		}
	}
	long long ans=5;
	for(int i=0;i<18;i++){
		ans*=10;
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			long long yu=y[i];
			long long yl=y[j];
			long long xu=x[i];
			long long xl=x[j];
			if(yu<yl){
				yu=y[j];
				yl=y[i];
			}
			if(xu<xl){
				xu=x[j];
				xl=x[i];
			}
//			cout<<yu<<yl<<xu<<xl<<endl;
			for(int k=0;k<n;k++){
				if(x[k]>xl)break;
				int count=0;
				for(int l=k;l<n;l++){
					if((yl<=y[l])*(y[l]<=yu))count++;
//					cout<<y[l]<<count<<endl;
					if(count==k2){
						if(ans>(yu-yl)*(x[l]-x[k])){
							ans=(yu-yl)*(x[l]-x[k]);
//							cout<<k2<<endl;
						}
						break;
					}
				}
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			double a=sc.nextInt();
			double b=sc.nextInt();
			double c=sc.nextInt();
			double d=sc.nextInt();
			double e=sc.nextInt();
			double f=sc.nextInt();
			double y=(c*d-a*f)/(b*d-a*e);
			double x=(c-b*y)/a;
			System.out.printf("%.3f %.3f\n",x,y);
		}
	}
}

Measured memory_bytes: 18184
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())
    A = list(map(int, input().split()))

    count = 1
    colors = {"r": 0, "g": 0, "b": 0}

    for a in A:
        _count = 0
        flag = 0
        for k in colors.keys():
            if int(a) == colors[k]:
                _count += 1
                if flag == 0:
                    flag = 1
                    colors[k] += 1
        count *= _count
        # print(int(a), _count)
    print(count % 1000000007)



if __name__ == '__main__':
    main()

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


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int n;
    cin >> n;
    cout << 1 - n << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct mint{
	ll x;
	mint(ll x=0):x((x%mod+mod)%mod){}
	friend ostream &operator<<(ostream& os,const mint& a){
		return os<<a.x;
	}
	friend istream &operator>>(istream& is,mint& a){
		ll t;
		is>>t;
		a=mint(t);
		return (is);
	}
	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;
	}
};

struct combination{
  vector<mint> fact,ifact;
  combination(int n):fact(n+1),ifact(n+1){
	assert(n<mod);
	fact[0]=1;
	for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i;
	ifact[n]=fact[n].inv();
	for(int i=n;i>=1;i--) ifact[i-1]=ifact[i]*i;
  }
  mint operator()(int n,int k){
	if (k<0 || k>n) return 0;
	return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
	}
	mint ans=0;
	rep(i,61){
		ll x=0,y=0;
		rep(j,n){
			if(a[j] & (1ll<<i)) x++;
			else y++;
		}
		ans+=mint(1ll<<i)*mint(x*y);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
from collections import defaultdict


def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    k = min(k, n - k)
    ans = 1
    for i in range(1, k + 1):
        ans *= n - i + 1
        ans //= i
    return ans


n, p = map(int, input().split())
s = input()

if p == 2:
    ans = 0
    for i in range(n):
        if int(s[i]) % 2 == 0:
            ans += i + 1
elif p == 5:
    ans = 0
    for i in range(n):
        if int(s[i]) in [0, 5]:
            ans += i + 1
else:
    mod_list = [0] * (n + 1)
    d = 1
    for i in reversed(range(n)):
        mod_list[i] = int(s[i]) * d + mod_list[i + 1]
        mod_list[i] %= p
        d = (d * 10) % p

    mod_dict = defaultdict(int)
    for i in range(n + 1):
        mod_dict[mod_list[i]] += 1

    # print(mod_list)
    # print(mod_dict)

    ans = 0
    for c in mod_dict:
        ans += comb(mod_dict[c], 2)

print(ans)


Measured memory_bytes: 11984
#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);

	long long n, i, j, k, x;
	cin >> k;
	n = 50;
	vector<long long> a(n);
	x = k % n;
	for (i = 0; i < n; i++) {
		if (i >= x) a[i] = i - x;
		else a[i] = n + 1 - (x - i);
		a[i] += k / n;
	}

	cout << n << "\n";
	for (auto p : a) cout << p << " ";
	cout << "\n";

	return 0;
}



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

long long solve(int N, const vector<int> &a) {
    int iter = 1;
    for (int i = 0; i < N; ++i) {
        if (a[i] == iter) ++iter;
    }

    if (iter == 1) return -1;
    else return N - (iter - 1);
}

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    cout << solve(N, a) << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())

using namespace std;
using ll = int64_t;

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

  int n;
  string s;
  cin >> n >> s;

  vector<int> sums(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    int c = (s[i - 1] == '#');
    sums[i] = sums[i - 1] + c;
  }

  int ans = min(sums[n], n - sums[n]), after = 0;
  for (int i = n; i > 0; i--) {
    char c = s[i - 1];
    if (c == '.') {
      ++after;
    }
    ans = min(ans, after + sums[i - 1]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1428
import math
def calc(d):
    k = 1
    for key in d.iterkeys():
        if d[key] != 0:
            k *= (int(key) ** (d[key]-1)) * (int(key)-1)
    return k

n = input()

prime = []
#find prime numbers in 1-sqrt(n)
m = int(math.sqrt(n))
for i in range(m+1):
    prime.append(True)

prime[0] = False
prime[1] = False

for i in range(2, int(math.sqrt(m))):
    if not prime[i]:
        continue
    else:
        for j in range(i+1, int(math.sqrt(m))):
            if j % i == 0:
                prime[j] = False

s = []
i = 2
num = n
while True:
    if i == int(math.sqrt(num))+1:
        s.append(str(n))
        break

    if not prime[i] or n % i != 0:
        i += 1
        continue

    if n % i == 0:
        s.append(str(i))
        n /= i
        if n == 1:
            break

tmp_dict = {}
for c in s:
    if not c in tmp_dict.keys():
        tmp_dict[c] = 1
    else:
        tmp_dict[c] += 1

print "%d" % calc(tmp_dict)

Measured memory_bytes: 7804
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner (System.in);
	String num1, num2;
	int[] a, b;
	int[] c;
	int n = Integer.parseInt(scan.nextLine());
	for (int i = 0; i < n; i++) {
	    num1 = scan.nextLine();
	    num2 = scan.nextLine();
	    if (num1.length() > 80 || num2.length() > 80) {
		System.out.println("overflow");
		continue;
	    }
	    a = convertStringToIntArray(num1);
	    b = convertStringToIntArray(num2);
	    c = add(a, b);
	    if (c[0] != 0) {
		System.out.println("overflow");
	    } else {
		printArray(c);
	    }
	}
    }
    public static int[] convertStringToIntArray (String num) {
	int[] a = new int[80];
	int len = num.length();
	for (int i = 0; i < len; i++) {
	    a[79-i] = Integer.parseInt(num.substring(len-1-i, len-i));
	}
	return a;
    }
    public static int[] add (int[] a, int[] b) {
	int tmp;
	int[] c = new int[81];
	for (int i = 79; i >= 0; i--) {
	    tmp = a[i] + b[i] + c[i+1];
	    if (tmp >= 10) {
		c[i+1] = tmp - 10;
		c[i] += 1;
	    } else {
		c[i+1] = tmp;
	    }
	}
	return c;
    }
    public static void printArray (int[] a) {
	StringBuilder sb = new StringBuilder();
	int start = 0;
	while (start < a.length - 1 && a[start] == 0) {
	    start++;
	}
	for (int i = start; i < a.length; i++) {
	    sb.append(a[i]);
	}
	System.out.println(sb);
    }
}

Measured memory_bytes: 26200
N, Y = map(int, input().split())
x,y,z = -1,-1,-1

for i in range(N+1):
  for j in range(N+1-i):
    if 10000 * i + 5000 * j + 1000 * (N - i -j) == Y:
      x,y,z = i, j, N - i -j
      
print(x,y,z)
    

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

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

using namespace std;
using ll = long long;
using P = pair<int,int>;


void calc_primefactorization(long long in, vector<vector<long long> >& out){
	
	long long N = in, Ntmp;
	long long p,e,p_init = 2;
	vector<long long> out_tmp(2);
	
	if( in == 1 ){
		out_tmp[0] = 1;
		out_tmp[1] = 1;
	}
	else{
		while( 1 ){

			Ntmp = N;
				
			p = N;
			e = 1;

			for(long long i = p_init;i * i <= N;i++){
						
				if( Ntmp % i == 0 ){
					e = 0;
					while( 1 ){
						if( Ntmp % i != 0 ){
							break;
						}
						else{
							Ntmp = Ntmp / i;
							e++;
						}
					}
					p = i;
					break;
				}
				
			}
			
			out_tmp[0] = p;
			out_tmp[1] = e;
			out.push_back(out_tmp);
			
			for(int i = 0;i < e;i++){
				N = N / p;
			}
			
			if( N == 1 ){
				break;
			}
			
		}
	}
	
}

int bitmask(int n){
	
	int a = 1;
	
	return ( a << (n - 1) );
	
}

bool judge(int a, int b){
	
	if( (a & bitmask(b)) > 0 ){
		return true;
	}
	else{
		return false;
	}
	
}

int main(){
	
	int L, R, d;
	
	cin >> L >> R >> d;
	
	int ans = 0;
	for(int i = L;i <= R;i++){
		if( ( i % d ) == 0 ){
			ans++;
		}
	}
	
	cout << ans;
	
	return 0;
	
}


Measured memory_bytes: 3628
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int [] abc = new int [3];
        for(int i=0; i<3; i++){
            abc[i] = sc.nextInt();
        }
        Arrays.sort(abc);
        if(abc[2]==abc[0]+abc[1]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

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

  rep(i, 1001) {
    int g1 = (int)((double)i * 0.08);
    int g2 = (int)((double)i * 0.10);
    if (g1 == a && g2 == b) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;cin>>n>>m;
  ll a[n],ans=0;
  double b=0;
  for(int i=0;i<n;i++){
    cin>> a[i];
    b+=a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]>=b/(4*m)){ans++;};
  }
  if(ans>=m){
    cout << "Yes"<<endl;
  }else{
    cout << "No"<<endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int *num;
  int i,j,v,k,n;
  scanf("%d",&n);
  num=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
  }
  for(k=0;k<n;k++){
	if(k==n-1){
	  printf("%d\n",num[k]);
	}
	else {
	  printf("%d ",num[k]);
	    }
      }
  for(i=1;i<n;i++){
    j=i-1;
    v=num[i];
    while(j>=0 && num[j]>v){
      num[j+1]=num[j];
      j--;
      
    }
    num[j+1]=v;
    for(k=0;k<n;k++){
	if(k==n-1){
	  printf("%d\n",num[k]);
	}
	else {
	  printf("%d ",num[k]);
	    }
      }
  }

  
  
  free(num);
  
  return 0;
}


Measured memory_bytes: 1904
#include<bits/stdc++.h>
#define gc getchar()
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<"\n"
#define pa pair<int,int>
#define fir first
#define sec second
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return  w*s;}
struct node {int u,v,w;} e[1010100];
int n,Q,tot,Min[1001010],fa[1010100];
inline void add(int u,int v,int w){e[++tot].u=u+1,e[tot].v=v+1,e[tot].w=w;}
inline int find(int x){if(x==fa[x]) return x;return fa[x]=find(fa[x]);}
inline bool cmp(node p,node q){return p.w<q.w;}
int main()
{	
	n=read(),Q=read();
	memset(Min,0x3f,sizeof(Min));
	for(rint i=1;i<=n;++i) fa[i]=i;
	for(rint i=1;i<=Q;++i){
		int a=read(),b=read(),c=read();
		add(a,b,c);
		Min[a]=min(Min[a],c+1);
		Min[b]=min(Min[b],c+2);
	}
	for(rint i=0;i<n;++i){
		Min[i]=min(Min[(i-1+n)%n]+2,Min[i]);
	}
	for(rint i=0;i<n;++i){
		Min[i]=min(Min[(i-1+n)%n]+2,Min[i]);
	}
	for(rint i=0;i<n;++i){
		add(i,(i+1)%n,Min[i]);
	}
	sort(e+1,e+tot+1,cmp);
	ll res=0;
	for(rint i=1;i<=tot;++i){
		int x=find(e[i].u),y=find(e[i].v);
		if(x!=y) fa[x]=y,res+=e[i].w; 
	}
	cout<<res<<'\n';
	return 0;
}	

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

vector<int> a;

int partition(int p, int r){
  int x = a[r];
  int i = p - 1;
  int dummy;

  for(int j = p; j < r; j++){

    if(a[j] <= x){
      i++;
      dummy = a[i];
      a[i] = a[j];
      a[j] = dummy;
    }
  }
    
    dummy = a[i+1];
    a[i+1] = a[r];
    a[r] = dummy;
  
  return i+1;
  
}

int main()
{
  int n;
  cin >> n;
  a.resize(n+5);

  for(int i = 0; i < n; i++) cin >> a[i];

  int q = partition(0, n-1);

  for(int i = 0; i < n; i++){
    if(i) cout << " ";
    
    if(i == q) cout << "[" << a[i] << "]";

    else cout << a[i];

  }

  cout << endl;

  return 0;

}



Measured memory_bytes: 3124
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N = 20,ans,cards[20];
bool* state;

int diff_row[8] = {-1,-1,-1,0,0,1,1,1},diff_col[8] = {-1,0,1,-1,1,-1,0,1};

struct Info{
	int value,index;
};


int makeCode(bool removed[]){

	int ret = 0;

	int S = 1;
	for(int i = 0; i <= N-1; i++){
		if(removed[i]){
			ret += S;
		}
		S *= 2;
	}
	return ret;
}

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= 4 && col >= 0 && col <= 3)return true;
	else{
		return false;
	}
}

void recursive(bool removed[],int count){

	ans = max(ans,count);
	if(count == N || ans == N)return;

	Info map[5][4];

	for(int row = 0; row < 5; row++){
		for(int col = 0; col < 4; col++)map[row][col].value = 0;
	}

	int row = 0,col = 0;
	for(int i = 0; i < N; i++){
		if(removed[i] == false){
			map[row][col].value = cards[i];
			map[row][col++].index = i;
			if(col >= 4){
				col = 0;
				row++;
			}
		}
	}

	int ad_row,ad_col,code;

	for(int row = 0; row < 5; row++){
		for(int col = 0; col < 4; col++){
			if(map[row][col].value != 0){
				for(int i = 0; i < 8; i++){
					ad_row = row + diff_row[i];
					ad_col = col + diff_col[i];

					if(rangeCheck(ad_row,ad_col) == true && map[ad_row][ad_col].value == map[row][col].value){
						bool next_removed[N];
						for(int k = 0; k < N; k++)next_removed[k] = removed[k];

						next_removed[map[ad_row][ad_col].index] = true;
						next_removed[map[row][col].index] = true;

						code = makeCode(next_removed);

						if(state[code] == false){
							state[code] = true;
							recursive(next_removed,count+2);
						}
					}

				}
			}
		}
	}
}

void func(){
	for(int i = 0; i < 1048576; i++)state[i] = false;

	int index = 0;

	for(int row = 0; row < 5; row++){
		for(int col = 0; col < 4; col++){
			scanf("%d",&cards[index++]);
		}
	}

	ans = 0;

	bool removed[N];
	for(int i = 0; i < N; i++)removed[i] = false;

	recursive(removed,0);

	printf("%d\n",N-ans);
}

int main(){

	int D;
	state = new bool[1048576];

	scanf("%d",&D);

	for(int i = 0; i < D; i++){
		func();
	}

	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    ll n, k;
    ll ans  = -15*1e8;
    cin >> n >> k;
    vector<ll> p(n);
    vector<ll> c(n);
    vector<vector<ll>> v(n, vector<ll>(n));
    rep(i, n) {
        int kari;
        cin >> kari;
        p[i] = kari - 1;
    }
    rep(i, n) cin >> c[i];
    rep(i, n){
        ll sc = 0;
        ll now = i;
        ll count = 0;
        while (p[now] != i) {
            count++;
            sc += c[p[now]];
            v[i][count - 1] = sc;
            now = p[now];
        }
        count++;
        sc += c[p[now]];
        v[i][count - 1] = sc;
        now = p[now];
        ll pt;
        rep(j, count){
            if (j + 1 > k) break;
            pt = v[i][j];
            if (v[i][count - 1] > 0) {
                pt += ((k - j - 1)/count)*v[i][count - 1];
            }
            ans = max(ans, pt);
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 198856
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

import heapq
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
heap = []
ans = 0
j = 0
 
for i in range(1, M+1): # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i): # 支払いがi日以内
        heapq.heappush(heap, -X[j][1]) # 候補の追加。最大の値が欲しいためマイナスに
        j += 1
    if len(heap):
        ans += - heapq.heappop(heap) # 候補があるとき、候補から最大値を取り出す
print(ans)

Measured memory_bytes: 75612
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

int main() {

	int R = 0;
	int G = 0;
	cin >> R >> G;

	cout << 2*G-R << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  cin >> n >> a >>b;
  int ans = 0;
  for(int i = 1;i<=n;i++){
    int sum = i%10 +i/10%10+i/100%10+i/1000%10+i/10000%10;
    if( sum >=a && sum <=b){
      ans += i;
    }
  }
  cout <<ans;
}

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

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt(), q = scanner.nextInt();
			// 町と町の間の移動最短距離
			long[][] d = new long[n][n];
			IntStream.range(0, n).forEach(i -> {
				Arrays.fill(d[i], Integer.MAX_VALUE);
				d[i][i] = 0;
			});
			int[] r = new int[q];
			IntStream.range(0, q).forEach(i -> r[i] = scanner.nextInt() - 1);
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt() - 1;
				int b = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				d[a][b] = d[b][a] = c;
			});
			warshallFloyd(d, n);
			System.out.println(getResult(d, r, -1, new boolean[q], 1));
		}
	}

	/**
	 * 町と町の間の移動最短距離をワーシャル–フロイド法で計算する
	 * 
	 * @param d 町と町の間の移動最短距離の配列
	 * @param n 町の数
	 */
	private static void warshallFloyd(long[][] d, int n) {
		IntStream.range(0, n).forEach(k -> IntStream.range(0, n)
				.forEach(j -> IntStream.range(0, n).forEach(i -> d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]))));
	}

	/**
	 * 解説通りに実装したメソッド
	 * 
	 * @param d       町と町の最短距離の配列
	 * @param r       訪ねる町の配列
	 * @param prev    直前に訪ねた町（存在しないときは-1）
	 * @param visited 町が訪ねたかどうかの配列
	 * @param depth   訪ねた町の数
	 * @return 訪ねる町をすべて訪ねたときの移動距離
	 */
	private static long getResult(final long[][] d, final int[] r, int prev, boolean[] visited, int depth) {
		if (depth > r.length) {
			return 0L;
		}
		long result = Integer.MAX_VALUE;
		for (int i = 0; i < r.length; i++) {
			if (!visited[i]) {
				visited[i] = true;
				if (-1 == prev) {
					result = Math.min(result, getResult(d, r, i, visited, depth + 1));
				} else {
					result = Math.min(result, getResult(d, r, i, visited, depth + 1) + d[r[prev]][r[i]]);
				}
				visited[i] = false;
			}
		}
		return result;
	}
}


Measured memory_bytes: 45808
#[allow(dead_code)]
const MOD: usize = 1_000000000 + 7;

fn main() {
    let mut cin = Scanner::new();
    let n = cin.next_usize();
    let mut a = 2_u64;
    let mut b = 1;
    for _ in 0..n {
        let x = a + b;
        a = b;
        b = x;
    }
    println!("{}", a);
}


struct Scanner {
    reader: std::io::Stdin,
    tokens: std::collections::VecDeque<String>,
}

impl Scanner {
    fn new() -> Self {
        Scanner {
            reader: std::io::stdin(),
            tokens: std::collections::VecDeque::new(),
        }
    }

    fn next(&mut self) -> String {
        if self.tokens.is_empty() {
            let mut s = String::new();
            loop {
                self.reader.read_line(&mut s).ok();
                let s = s.trim();
                if s.len() != 0 {
                    for it in s.split_whitespace() {
                        self.tokens.push_back(it.into())
                    }
                    break;
                }
            }
        }
        self.tokens.pop_front().unwrap()
    }

    fn next_generics<T>(&mut self) -> T where
        T: std::str::FromStr + std::marker::Copy,
        <T as std::str::FromStr>::Err: std::fmt::Debug
    {
        self.next().parse().unwrap()
    }
    
    #[allow(dead_code)] fn next_i32(&mut self) -> i32 { self.next_generics::<i32>() }
    #[allow(dead_code)] fn next_i64(&mut self) -> i64 { self.next_generics::<i64>() }
    #[allow(dead_code)] fn next_u64(&mut self) -> u64 { self.next_generics::<u64>() }
    #[allow(dead_code)] fn next_usize(&mut self) -> usize { self.next_generics::<usize>() }
    #[allow(dead_code)] fn next_isize(&mut self) -> isize { self.next_generics::<isize>() }
}



Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  2000007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int ar[MX];
int main(){
  int n;
  I(n);
  int a[n+2];
  for(int i = 1;i<=n;i++){
    I(a[i]);
    ar[a[i]]++;
  }
  int rs= 0;
  for(int i = 1;i<=n;i++){
    ar[a[i]] --;
    int sq = sqrt(a[i]);
    bool fl = 0;

    for(int j = 1; j<=sq;j++){
      if(a[i] %  j == 0){
  
        if(ar[j])fl = 1;
        int k = a[i] / j;
   
    
          if(ar[k])fl = 1;
        
      }

    }

    ar[a[i]] ++;
    if(!fl)rs++;
  }
  cout<<rs<<Endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i, n) for(long long i=0; i<n; i++)
#define repr(i, n, m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template<class T>
inline void chmax(T &ans, T t) { if (t > ans) ans = t; }

template<class T>
inline void chmin(T &ans, T t) { if (t < ans) ans = t; }

int main() {
  string s, t;
  cin >> s >> t;

  auto lens = s.size();
  auto lent = t.size();

  if (lent > lens) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  string ans = "";
  for (int i = 0; i <= lens - lent; ++i) {
    string tmp = s;
    // ? だったらなんでもおｋ
    bool flag = true;
    for (int j = 0; j < lent; ++j) {
      auto idx = j + i;
      if (s[idx] != '?' && s[idx] != t[j]) {
        flag = false;
        break;
      } else {
        tmp[idx] = t[j];
      }
    }

    for (auto &it : tmp) {
      if (it == '?') it = 'a';
    }

    if (flag) {
      if (ans.empty()) ans = tmp;
      else chmin(ans, tmp);
    }
  }

  if (ans.empty()) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 256