akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }

        
         public static long gcd(long x, long y)
        {
            if (x < y) gcd(y, x);
            while (y != 0)
            {
                var z = x;
                x = y;
                y = z % y;
            }
            return x;
        }

        public static long lcm(long x, long y)
        {
            return x * y / gcd(x, y);
        } 

        public static long C(long n, long k)
        {
            long x = 1;
            for (long i = 1; i <= k; i++)
            {
                x *= n - i + 1;
                x /= i;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            long ans = 0;
            var a = new long[n];
            var b = new long[n];
            for (int i = 0; i <n ; i++)
            {
                var q = Reads();
                a[i] = q[0];
                b[i] = q[1];
            }
            for (long i = n-1; i >= 0; i--)
            {
                a[i] += ans;
                if (a[i] % b[i] != 0)
                    ans += b[i] - a[i] % b[i];
            }
           
        
            WriteLine(ans);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 24044
#include "bits/stdc++.h"

using namespace std;

#define ll  long long
#define vi  vector<int>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

int main(){

  int n,m,x;
  cin >> n >> m >> x;
  int l = 0,r = 0;

  rep(i,m){
    int a;cin >> a;
    if(a < x)l++;
    else r++;
  }

  pr(min(l,r));


  return 0;
}


Measured memory_bytes: 256
//2019.8.18 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define unl __int128
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG unl x){
//    if(x>10)write(x/10);
//    putchar(int(x%10)+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
//    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
const int N=2e5+10;
namespace MAIN{
    int n,q;
    vector<int> G[N];
    int val[N];
    void dfs(res x,res fax){
        for(auto tox:G[x]){
            if(tox==fax)continue;
            val[tox]+=val[x],dfs(tox,x);
        }
    }
    inline void MAIN(){
        n=read(),q=read();
        for(res i=1;i<n;i++){
            res u=read(),v=read();
            G[u].pb(v),G[v].pb(u);
        }
        for(res i=1;i<=q;i++){
            res x=read(),y=read();
            val[x]+=y;
        }
        dfs(1,0);
        for(res i=1;i<=n;i++)printf("%d ",val[i]);
    }
}
int main(){
//    srand(19260817);
//    freopen("signin.in","r",stdin);
//    freopen("signin.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 23424
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toDouble).sorted()
    var result = A[0]
    for (i in 1 until A.size) {
        result = (result + A[i]) / 2.0
    }
    println(result)
}

Measured memory_bytes: 37904
using System;
using System.Collections.Generic;

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);

            for (int i = 1; i <= n; i++)
            {
                int x = i;
                if (x % 3 == 0)
                {
                    Console.Write(" " + i);
                }
                else
                {
                    while (x != 0)
                    {
                        if (x % 10 == 3)
                        {
                            Console.Write(" " + i);
                            break;
                        }
                        x /= 10;
                    }
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC147A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A1, A2, A3;

            var word = Console.ReadLine().Split(' ');
            A1 = int.Parse(word[0]);
            A2 = int.Parse(word[1]);
            A3 = int.Parse(word[2]);

            if (A1 + A2 + A3 >= 22)
                Console.WriteLine("bust");

            if (A1 + A2 + A3 <= 21)
                Console.WriteLine("win");

            Console.ReadKey();



        }

    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

struct Data{
	int a, b;
	bool operator>(const Data& d)const{return b > d.b;}
	bool operator<(const Data& d)const{return b > d.b;}
};

int main(){
	int n, h;
	Data d[100000];
	scanf("%d%d", &n, &h);
	for(int i = 0; i < n; i++){
		scanf("%d%d", &d[i].a, &d[i].b);
	}
	sort(d, d+n, greater<Data>());

	priority_queue<int> Q;

	int rest = h;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(Q.empty() || Q.top() < d[i].b){
			rest -= d[i].b;
			ans++;
			if(rest <= 0)
				break;
			Q.push(d[i].a);
		}
		else{
			int a = Q.top();
			int tmp = rest / a;
			if(a * tmp != rest)
				tmp++;
			rest -= a * tmp;
			ans += tmp;
			break;
		}
	}
	if(rest > 0){
		int a = Q.top();
		int tmp = rest / a;
		if(a * tmp != rest)
			tmp++;
		ans += tmp;
	}
	printf("%d\n", ans);


	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  vector<ll> a(m), b(m);
  rep(i,m) cin >> a[i] >> b[i];
  vector<bool> hantei(n, true);
  rep(i,m){
    if(h[a[i]-1] < h[b[i]-1]) hantei[a[i]-1] = false;
    else if(h[a[i]-1] > h[b[i]-1]) hantei[b[i]-1] = false;
    else{
      hantei[a[i]-1] = false;
      hantei[b[i]-1] = false;
    }
  }
  int ans=0;
  rep(i,n){
    if(hantei[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main()
{
    ll n,ctr=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        for(int k=j+1;k<n;k++){
          if(a[i]+a[j]>a[k]) ctr++;
          else break;
        }
      }
    }
    cout<<ctr<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

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

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

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func isPaintable(s [][]byte, i, j int) bool {
	if s[i][j] == '.' {
		return true
	}

	x := []int{-1, 0, 1, 0}
	y := []int{0, -1, 0, 1}
	h := len(s)
	w := len(s[i])

	for d := range x {
		nx := i + x[d]
		ny := j + y[d]
		if nx < 0 || h <= nx || ny < 0 || w <= ny {
			continue
		}
		if s[nx][ny] == '#' {
			return true
		}
	}
	return false
}

func main() {
	defer stdout.Flush()
	h := readInt()
	_ = readInt()
	s := make([][]byte, h)
	for i := range s {
		s[i] = []byte(readString())
	}
	for i := range s {
		for j := range s[i] {
			if !isPaintable(s, i, j) {
				println("No")
				return
			}
		}
	}
	println("Yes")
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
A = LIST()
tmp = [0]*40

for a in A:  #tmpにビット毎の1の出現回数を格納
	for i in range(40):
		if a&(1<<i):
			tmp[i] += 1

a = 0
for i in range(39, -1, -1):
	if a + (1<<i) <= K and tmp[i] < (N+1)//2:
		a += 1<<i

ans = 0
for i in A:
	ans += i^a
print(ans)


Measured memory_bytes: 21940
#include<iostream>
#include<map>
#include<string>
#include<stdio.h>

#include<algorithm>

using namespace std;

bool compare(const pair<string, int> T1, const pair<string, int> T2) {
	return T1.second < T2.second;
}

int main (void){

	string str,maxByLength("");
	//map<int,string> X; //¶Ì·³
	map<string,int> Y; //¶Ì
	//int mm;

	while (cin>>str){
		if (str.size()>maxByLength.size())	maxByLength=str;
		Y[str]++;
	}

	// string maxByCount("");
	// int cnt = 0;
	pair<string, int> maxCountPair = *max_element(Y.begin(), Y.end(), compare);

	// cout << (*Y.rbegin()).first << " " << maxByLength << endl;
	// cout << maxByCount << " " << maxByLength << endl;
	cout << maxCountPair.first << " " << maxByLength << endl;

	return 0;

}

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

#define BR "\n"
#define fcout cout << fixed << setprecision(18)

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

  double pi = 3.14159265358979;
  double r = C / 180.0 * pi;
  double S = a * b * sin(r) / 2;
  double c = sqrt(a * a + b * b - 2 * a * b * cos(r));
  double L = a + b + c;
  double h = S * 2.0 / a;

  fcout << S << BR;
  fcout << L << BR;
  fcout << h << BR;
  return 0;
}


Measured memory_bytes: 3524
import sys

readline = sys.stdin.readline

def d(a, x):
    return abs(a[0] - x[0]) + abs(a[1] - x[1])

def main():
    N, M = map(int, readline().split())
    people = []
    for _ in range(N):
        people.append(tuple(map(int, readline().split())))
    check = []
    for _ in range(M):
        check.append(tuple(map(int, readline().split())))
    
    for i in range(N):
        tmp = float('inf')
        jtmp = 0
        for j in range(M):
            dtmp = d(people[i], check[j])
            if dtmp < tmp:
                tmp = dtmp
                jtmp = j
        print(jtmp+1)
    
if __name__ == "__main__":
    main()


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

int main() {
  double n;
  cin >> n;
  double sum_p2 = 0, sum_p1 = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum_p2 += x * x;
    sum_p1 += x;
  }
  int min_p = sum_p1 / n + 0.5;

  cout << sum_p2 - 2 * sum_p1 * min_p + n * min_p * min_p << endl;
}


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

int main()
{
	ll a,b;
	cin>>a>>b;
	//string s = "";
	if(a>b)
	{
		while(a--)
		{
			cout<<b;
		}
		//cout<<s;
		return 0;
	}
	else if(a<b)
	{
		while(b--)
		{
			cout<<a;
		}
		//cout<<s;
		return 0;
	}
	else if(a==b)
	{
		while(b--)
		{
			cout<<a;
		}
		//cout<<s;
		return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

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

Measured memory_bytes: 256
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
int a[3];
int main()
{
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]+a[1]<<"\n";
	
	


	
	
    return 0;
 
}



Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N,m[111];
int t[44444],c;
int ans;
vector<pair<int,int>>z;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        x*=2;
        z.push_back({c,i});
        while(x--){
            t[++c]=i;
        }
    }
    for(int i=0;i<N;i++){
        cin>>m[i];
        m[i]*=2;
    }
    for(int i=0;i<c;i++){
        t[i]=m[t[i]];
    }
    t[c]=0;
    z.push_back({c,N});
    int v=0;
    for(int i=1;i<=c;i++){
        int fail=0;
        if(v+1<=t[i]){
            for(auto p:z){
                if(p.first<i)continue;
                if(v+1-(p.first-i)>m[p.second]){
                    fail=1;
                    break;
                }
            }
            if(!fail){
                ans+=2*v+1;
                v++;
                continue;
            }
        }
        fail=0;
        if(v<=t[i]){
            for(auto p:z){
                if(p.first<i)continue;
                if(v-(p.first-i)>m[p.second]){
                    fail=1;
                    break;
                }
            }
            if(!fail){
                ans+=2*v;
                continue;
            }
        }
        ans+=2*v-1;
        v--;
    }
    printf("%.12lf",ans/8.0);
    return 0;
}


Measured memory_bytes: 640
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
#define ll long long
using namespace std;



int main(){
    int i;
    int cnt=0;
    string S;
    cin >> S;
    for(char c : S){
        if(c == 'x') cnt++;
    }
    if(cnt < 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<(x)<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5+10;

int main(){
    int n,m;
    cin >> n >> m;
    vi a(m),b(m);
    rep(i,m) cin >> a[i] >> b[i];

    int sum = 0;
    for(int i=1; i<=n; ++i){
        sum = 0;
        rep(j,m){
            if(a[j]==i) ++sum;
            if(b[j]==i) ++sum;
        }
        cout(sum);
    }
    return 0;
}

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

#define ntest 0

using namespace std;
long long x,k,d;
void solve() {
    cin >> x >> k >> d;
    x = abs(x);
    long long tmpk = min(k,x / d);
    long long remain = k - tmpk;
    if (remain&1) cout << (tmpk+1)*d - x;
    else cout << x - tmpk * d;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




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

typedef struct {
	int no;
	int torihiki_num;
	int used;
} kokyaku_t;

kokyaku_t kokyaku[1000];

int qsort_comp(const void* x,const void* y) {
	const kokyaku_t* a=(const kokyaku_t*)x;
	const kokyaku_t* b=(const kokyaku_t*)y;
	if((a->no)>(b->no))return 1;
	if((a->no)<(b->no))return -1;
	return 0;
}


int main(void) {
	char buffer[1000];
	int zenhan_flag=1;
	int now_no;
	int i;
	while(fgets(buffer,sizeof(buffer),stdin)) {
		if(buffer[0]=='\n') {
			for(i=0;i<1000 && kokyaku[i].used;i++);
			qsort(kokyaku,i,sizeof(kokyaku_t),qsort_comp);
			zenhan_flag=0;
			continue;
		}
		sscanf(buffer,"%d",&now_no);
		if(zenhan_flag) {
			for(i=0;i<1000 && kokyaku[i].used;i++) {
				if(kokyaku[i].no==now_no)break;
			}
			kokyaku[i].no=now_no;
			kokyaku[i].torihiki_num++;
			kokyaku[i].used=1;
		} else {
			for(i=0;i<1000 && kokyaku[i].used;i++) {
				if(kokyaku[i].no==now_no) {
					kokyaku[i].torihiki_num++;
					kokyaku[i].used=2;
					break;
				}
			}
		}
	}
	for(i=0;i<1000 && kokyaku[i].used;i++) {
		if(kokyaku[i].used==2) {
			printf("%d %d\n",kokyaku[i].no,kokyaku[i].torihiki_num);
		}
	}
	return 0;
}

Measured memory_bytes: 0
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n, k;
	cin >> n >> k;
	if (k > (n-1)*(n-2) / 2) cout << -1 << endl;
	else{
		ans += n-1;
		ans += (n-1)*(n-2) / 2 - k;
		cout << ans << endl;
		REP1(i, n-1) cout << i << " " << n << endl;
		tmp = n - 1;

		REP1(i, n-2){
			REP1(j, n-1){
				if(tmp < ans && i < j){
					cout << i << " " << j << endl;
					tmp++;
				}
			}
		}

	}		
}

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

int main() {

  int N;
  cin >> N;

  vector<int> a(N);

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

  sort(a.begin(), a.end(), std::greater<int>());

  int Alice = 0;
  int Bob = 0;

  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += a[i];
    } else {
      Bob += a[i];
    }
  }

  cout << Alice - Bob << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  for(int i = 0; i < D; ++i) t[i] = i%26;
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  int lm = 0, renew = 0;
  int sc[26];
  auto one_day = [&](int d) {
    int pi = t[d];
    last[pi].erase(d);
    for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
    int mi = std::max_element(sc, sc+26) - sc;
    if(mi != pi) {
      t[d] = mi;
      ans += sc[mi] - sc[pi];
      ++renew;
    }
    last[mi].insert(d);
  };
  
  // hill climbing
  for(;;) {
    int lp = -1;
    do {
      renew = 0;
      for(int d = 0; d < D; ++d) one_day(d);
      ++lp;
      if(get_time() > 1850) break;
    } while(renew > 0);
    if(lp == 0 && lm > 10) break;
    // swap
    int rep = 1+xor64()%5;
    while(rep-- > 0) {
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-16 || d2 < d1-16 || t[d1] == t[d2]) {
        d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
        ++lm;
      }
    }
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
constexpr long N = 300000;
constexpr long mod = 998244353;

long mpow(long a, long p){
    long x=a;
    long y=1;
    while(p>0){
        if((p&1)==1){
            y=x*y%mod;
        }
        x=x*x%mod;
        p>>=1;
    }
    return y;
}

long minv(long a){
    return mpow(a, mod-2);
}

long fact[N+1];
long ncr[N+1];
void init_ncr(long n){
    long t=1;
    fact[0]=1;
    for(long i=1; i<=n; i++){
        t=t*i%mod;
        fact[i]=t;
    }
    for(long r=0; r<=n/2; r++){
        ncr[r] = fact[n]*minv(fact[n-r]*fact[r]%mod)%mod;
    }
    for(long r=0; r<=n/2; r++){
        ncr[n-r] = ncr[r];
    }
}

int main(void){
    long n, a, b, k;
    scanf("%ld %ld %ld %ld", &n, &a, &b, &k);
    init_ncr(n);
    long sum = 0;
    long s = max(0l, (k-n*b)/a);
    long e = min(n, k/a);
    for(long i=s; i<=e; i++){
        long q=(k-a*i)/b;
        long m=(k-a*i)%b;
        if(m==0){
            //sum = (sum+mcomb(n,i)*mcomb(n,q))%mod;
            sum = (sum+ncr[i]*ncr[q])%mod;
        }
    }
    if(sum==0)sum++;
    printf("%ld\n", sum);
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int result = 1;
  for (int i = 0;i < N;i++) {
    if (result * 2 <= result + K) {
      result *= 2;
    } else {
      result += K;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
/*

Author : AllKilled
Date   : 201910277

Contest: AtCoder Beginner Contest 144.
Problem: Task C.
Result :

*/
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const LL MAXN = 1e6+7;

///--------------------------------------------///



int main()
{
    LL N, ans = 1e15;
    cin >> N;
    LL M = ceil(sqrt(1.0*N));
    for(LL i = 1; i <= M; ++i){
        if(N % i) continue;
        LL j = N / i;
        ans = min(ans, i + j - 1);
    }
    cout << ans - 1 << endl;
    return 0;
}


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

using namespace std;

int main()
{
    string s, t;

    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if (t > s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

int main(void){

    int a,b,c,d,e,f,g,h;
    cin>>a;
    b=a/100;
    c=(a-100*b)/10;
    d=a-100*b-10*c;
    if(b==1){
        e=9;
    }else e=1;
    if(c==1){
        f=9;
    }else f=1;
    if(d==1){
        g=9;
    }else g=1;
    h=e*100+f*10+g;
    cout<<h<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <bitset>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	unsigned long long n,k;
	cin >> n >> k;
	unsigned long long ng = k+1 , ok = 0;
	while(ng-ok > 1){
		unsigned long long mid = (ng+ok)/2;
		unsigned long long sum = 0 , kk = mid;
		int cnt = 0;
		while(kk){
			sum += kk;
			kk /= 2;
			cnt++;
			if(cnt==n)break;
		}
		if(sum<=k){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	cout << ok << endl;
}



Measured memory_bytes: 3112
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define mor > muu & operator << (
#define R22(r) sim > typename \
  enable_if<1 r sizeof dud<c>(0), muu&>::type operator<<(c g) {
sim > struct rge { c b, e; };
sim > rge<c> range(c h, c n) { return {h, n}; }
sim > auto dud(c* r) -> decltype(cerr << *r);
sim > char dud(...);
struct muu {
#ifdef LOCAL
stringstream a;
~muu() { cerr << a.str() << endl; }
R22(<) a << boolalpha << g; ris; }
R22(==) ris << range(begin(g), end(g)); }
sim, class b mor pair < b, c > r) { ris << "(" << r.first << ", " << r.second << ")"; }
sim mor rge<c> u) {
  a << "[";
  for (c i = u.b; i != u.e; ++i)
    *this << ", " + 2 * (i == u.b) << *i;
  ris << "]";
}
#else
sim mor const c&) { ris; }
#endif
muu & operator()() { ris; }
};
#define imie(r...) "[" #r ": " << (r) << "] "
#define imask(r...) "[" #r ": " << bitset<8 * sizeof(r)>(r) << "] "
#define arr(a, i) "[" #a imie(i) ": " << a[i] << "] "
#define arr2(a, i, j) "[" #a imie(i) imie(j) ": " << a[i][j] << "] "
#define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ")

const int N = 3e3 + 7;
int n;
char s[N];
const int mod = 1e9 + 7;
long long dp[N][N];

int main() {
    scanf("%d", &n);
    scanf("%s", s + 2);
    dp[1][1] = 1;
    for (int i = 2; i <= n; ++i) {
        if (s[i] == '>') {
            long long sum = 0;
            for (int j = i; j > 0; --j) {
                sum = (sum + dp[i - 1][j]) % mod;
                dp[i][j] = sum;
            }
        }
        else {
            long long sum = 0;
            for (int j = 1; j <= i; ++j) {
                dp[i][j] = sum;
                sum = (sum + dp[i - 1][j]) % mod;
            }
        }
    }
    
    long long res = 0;
    for (int i = 1; i <= n; ++i) res += dp[n][i];
    printf("%lld\n", res % mod);
    return 0;
}


Measured memory_bytes: 69120
def is_prime(num):
    i = 2
    while i*i <= num:
        if num % i == 0:
            return False
        i = i + 1
    return True

N = int(input())
cnt = 0
for i in range(0, N):
    n = int(input())
    if (is_prime(n)):
        cnt = cnt + 1
        
print(cnt)

Measured memory_bytes: 7724
A,B,C,K = map(int,input().split())

tmp = K
maxSum = 0
i = 0
if(tmp>A):
  maxSum+=A
  tmp-=A
else:
  maxSum+=K
  tmp = 0
#print(str(tmp) + ' sum = ' + str(maxSum))

if(tmp>B):
  tmp-=B
else:
  tmp = 0
#print(str(tmp) + ' sum = ' + str(maxSum))

if(tmp>C):
  maxSum-=C
  tmp-=C
else:
  maxSum-=tmp
  tmp = 0
#print(str(tmp) + ' sum = ' + str(maxSum))

print(maxSum)

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

using namespace std;

int main()
{
  do
  {
    int m, f, r; cin >> m >> f >> r;
    if(m == -1&&f == -1&&r == -1)
    {
      exit(0);
    }
    if(m == -1||f == -1)
    {
      cout << "F" << endl;
    }
    else if(m + f >= 80)
    {
      cout << "A" << endl;
    }
    else if(m + f >= 65)
    {
      cout << "B" << endl;
    }
    else if(m + f >= 50)
    {
      cout << "C" << endl;
    }
    else if(m + f >= 30)
    {
      if(r >= 50)
      {
        cout << "C" << endl;
      }
      else
      {
        cout << "D" << endl;
      }
    }
    else
    {
      cout << "F" << endl;
    }
  }while(1);
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[100];
ll d[100];

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	d[1] = 1000;
	for (int i = 2; i <= n; i++) {
		ll ma = 0;
		for (int j = 1; j < i; j++)for (int k = j; k < i; k++) {
			ma = max(ma, d[j] % a[k] + a[i] * (d[j] / a[k]));
		}
		d[i] = ma;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++)ans = max(ans, d[i]);
	cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int a[500][500];
int main(){
    DRII(H,W);
    DRII(h,w);
    LL sum=0;
    REP(i,H)REP(j,W){
        if(i%h==h-1&&j%w==w-1)a[i][j]=-(h*w-1)*4000-1;
        else a[i][j]=4000;
        sum+=a[i][j];
    }
    puts(sum>0?"Yes":"No");
    if(sum>0){
        REP(i,H)REP(j,W)printf("%d%c",a[i][j]," \n"[j==W-1]);
    }
    return 0;
}


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


int main()
{
	int N,M,Q;
	cin>>N>>M>>Q;
	vector<int> a(M),q(Q);
	for(int i=0;i<M;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<Q;i++)
	{
		cin>>q[i];
	}
	
	list<int> students;
	for(int i=0;i<N;i++)
	{
		students.push_back(i);
	}
	auto it=students.begin();
	
	for(int x:a)
	{
		if(x%2==0)
		{
			for(int i=0;i<x;i++)
			{
				it++;
				if(it==students.end())it=students.begin();
			}
			it=students.erase(it);
			if(it==students.end())it=students.begin();
		}
		else
		{
			for(int i=0;i<x;i++)
			{
				if(it==students.begin())
				{
					it=students.end();
					it--;
				}
				else
				{
					it--;
				}
			}
			it=students.erase(it);
			if(it==students.end())it=students.begin();
		}
	}
	
	for(int x:q)
	{
		int ans=0;
		for(it=students.begin();it!=students.end();it++)
		{
			if(*it==x)
			{
				ans=1;
			}
		}
		cout<<ans<<endl;
	}
	
}

Measured memory_bytes: 9888
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
int main(){
    LL n, a , b, ans;
    cin >> n >> a >> b;
    LL c = b-a;
    if(c%2==0){
        ans = c/2;
    }else{
        LL d = min(n-b, a-1);
        ans = d+c/2+1;
    }
    cout << ans << endl;
}

    



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;
const ld pi = (acos(-1));




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  int n,m; cin >> n >> m;
  vector<ll> a(n);
  vector<pair<ll, ll>> p(m);
  rep(i,0,n){ 
    cin >> a[i];
  }
  rep(i,0,m){
     ll b,c;
     cin >> b >> c;
     p[i].first=c;
     p[i].second=b;
  } 
  sort(ALL(a));
  sort(ALL(p));
  ll ans=0;
  rep(i,0,n){
    if(p.empty() || p.back().first<=a[i]){
      ans+=a[i];
      continue;
    }
    ans+=p.back().first;
    p.back().second--;
    if(!p.back().second) p.pop_back();
  }
  
  cout << ans << endl;
  
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int cnt = 0;
    for (int i = 1;i <= n;i++){
        int sum = 0;
        int I = i;
        while (I > 0){
            sum += I % 10;
            I /= 10;
        }
        if (sum >= a && sum <= b){
            cnt += i;
        }
    }
    cout << cnt << endl;
}

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

int N, M;
vector<int> G[100100];

int dp[100100];
int rec(int v){
    if(dp[v]!=-1) return dp[v];
    int res=0;
    for(auto nv :G[v]){
        res = max(res, rec(nv)+1);
    }
    return dp[v]=res;
}

int main(){
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int x, y; cin >> x >> y;
        G[x].push_back(y);
    }
    for(int i=1; i<=N; i++) dp[i]=-1;
    int res=0;
    for(int i=1; i<=N; i++) res = max(res,rec(i) );
    cout << res << endl;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
    ll H,N;
  cin >>H>>N;
  ll A[N],B[N];
  for(ll i=0;i<N;i++){
  cin >>A[i]>>B[i];
  }
ll dp[H+1];
  dp[0]=0;
  for(ll i=1;i<H+1;i++){dp[i]=1LL<<50;}

  for(ll i=0;i<H+1;i++){
  for(ll j=0;j<N;j++){
  if(i+A[j]>=H){dp[H]=min(dp[H],dp[i]+B[j]);continue;}
  dp[i+A[j]]=min(dp[i+A[j]],dp[i]+B[j]);
  }
}      
  
  
  cout<<dp[H]<<endl;
  
}


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

int main(){
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;

	return 0;

}




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

using namespace std;

const int N=200005;

int n,mx[N],se[N],low[N],z[N];
vector<int>e[N];
char s[N];
long long ans;

inline void upd(int x,int u){if(u>mx[x])se[x]=mx[x],mx[x]=u;else if(u>se[x])se[x]=u;}
void dfs1(int x,int fa){
	low[x]=N;
	if(s[x]=='1')low[x]=0,z[x]=1;
	for(int v:e[x])if(v!=fa){
		dfs1(v,x);int d=mx[v]+1;upd(x,d);
		if(z[v])low[x]=min(low[x],d),z[x]+=z[v];
	}
}
void dfs2(int x,int fa){
	if(fa){
		int d=mx[x]+1==mx[fa]?se[fa]+1:mx[fa]+1;
		upd(x,d);if(z[1]>z[x])low[x]=min(low[x],d);
	}
	for(int v:e[x])if(v!=fa)dfs2(v,x);
	int l=low[x],r=min(se[x]+1,mx[x]-1);
	if(l<=r)ans+=r-l+1;
}

int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),e[u].pb(v),e[v].pb(u);
	scanf("%s",s+1);
	dfs1(1,0);dfs2(1,0);
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 24064
const fs = require('fs')
const reader = (s: string) => (s.split(""))
 
function Main(input: string) {
  let aaa = ''
  reader(input).forEach(r=>{
    if(r ==="B")
    {
      if(aaa.length > 0 ) aaa = aaa.slice(0,aaa.length -1)
    }
    else{
      aaa += r
    }
  })
  console.log(aaa)
}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a+b+c > 21){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }
}

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

int main()
{
ll m , d ;
cin >> m >> d ;
ll m1 , d1 ;
cin >> m1 >> d1 ;
if(m!=m1)ans=1;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>

using namespace std;

typedef long long ll;

ll mod=1e9+7;

ll C(int n, int k){
    if (k == 0) return 1;
    else {
        long num = C(n-1, k-1) * n;
        while (num % k) num += mod;
        return (num / k) % mod;
    }
}

int main()
{
    ll N,M;
    cin >> N >> M;

    vector<ll> dims;
    ll i=2, m=M, cnt=0;
    while(i<=m && i*i<=M){
        if(m%i==0){
            cnt++;
            m/=i;
            continue;
        }
        if(cnt!=0){
            dims.push_back(cnt);
            cnt=0;
        }
        i++;
    }
    if(cnt!=0) dims.push_back(cnt);
    if(m!=1) dims.push_back(1);
    vector<ll> facts;
    for(auto bi: dims){
        facts.push_back(C(bi+N-1, bi)%mod);
    }
    ll ans=1;
    for(auto vt:facts){
        ans*=vt;
        ans%=mod;
    }
    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main() {
  int d, g;
  cin >> d >> g;

  vector<int> p(11), c(11); 
  rep(i, d){
    cin >> p.at(i+1);
    cin >> c.at(i+1);
  }

  int ans=10000;
  rep(i, 1<<d){
    int score=0, cnt=0, maxi=-1;
    rep(j ,d){
      if(i>>j & 1){
        score += (j+1)*100*p.at(j+1) + c.at(j+1);
        cnt += p.at(j+1);
      }else{
        maxi = j;
      }
    }
    if(score>=g) ans=min(ans,cnt);
    else if(maxi!=-1){
      rep(j, p.at(maxi+1)-1){
        score += (maxi+1)*100;
        cnt++;
        if(score>=g) {
          ans=min(ans,cnt);
          break;
        }
      }
    }
  }

  cout << ans << endl;
}

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

int main() {
  ll n;
  cin >> n;
  vll x(n);
  rep(i,n) cin >> x.at(i);
  vll y(n);
  y = x;
  sort(y.begin(),y.end());
  ll b1 = y.at(n/2-1);
  ll b2 = y.at(n/2);
  rep(i,n) {
    if(x.at(i)<=b1) cout << b2 << endl;
    else cout << b1 << endl;
  }
  return 0;
}

Measured memory_bytes: 5376
import heapq

n = int(input())
Edge = [[] for _ in range(n+1)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    # (コスト, 行き先)として追加する
    Edge[a].append([c,b])
    Edge[b].append([c,a])

q, k = map(int, input().split())
XY = []
for _ in range(q):
    x, y = map(int, input().split())
    XY.append([x,y])

# 関数への入力はs(start)とEdgeリスト
def dijkstra_heap(s, Edge):
    Dist = [10**10 for _ in range(n+1)]
    Dist[s] = 0
    Used = [False for _ in range(n+1)]
    Used[s] = True

    Edgelist = []

    for edge in Edge[s]:
        heapq.heappush(Edgelist, edge)

    while len(Edgelist) >= 1:
        minedge = heapq.heappop(Edgelist)
        cost, v = minedge[0], minedge[1]
        if Used[v] == True:
            continue
        Used[v] = True
        Dist[v] = cost

        for next_edge in Edge[v]:
            next_cost = next_edge[0]
            next_v = next_edge[1]
            heapq.heappush(Edgelist, [next_cost + Dist[v], next_v])
    return Dist

# print(Edge)
Dist_k = dijkstra_heap(k, Edge)

for xy in XY:
    x = xy[0]
    y = xy[1]
    ans = Dist_k[x] + Dist_k[y]
    print(ans)

# print(Dist_k)

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

int main(){
int N,M;
  cin>>N>>M;
  vector<int>X(M), L(M); // Lは各X[i+1]-X[i]の間の区間の値
  for(int i=0; i<M; i++){
   cin>>X[i]; }
  
  sort(X.begin(), X.end());
  for(int i=0; i<M-1; i++){
   L[i]=X[i+1]-X[i]; // Lの符号は全て＋になる
  }
  
  int sum=0;
  sort(L.begin(), L.end());// 区間Lをsortすると、L[i]がi<M-N+1以上になる座標は最短距離ではないことが分かる
  for(int i=0; i<M-N+1; i++){ // i<M-N+1以上の座標にコマNを置けばよい。
   sum+=L[i];  // そのため、コマが担当する区間L[i]=X[i+1]-X[i]に該当する距離は移動する必要はなくなる
  } // よってN+1個分の区間距離は加算しなくてよくなり、i<M-N+1までのL[i]を足した距離が答えになる
  
  cout<<sum;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int A[15],n,m,q,a[55],b[55],c[55],d[55],ans;
void dfs(int dep,int pre)
{
	if(dep==n)
	{
		int sum=0;
		for(int i=0;i<q;i++)
		    if(A[b[i]]-A[a[i]]==c[i]) sum+=d[i];
		ans=max(ans,sum);
		return;
	}
	for(int i=pre;i<=m;i++)
	{
		A[dep]=i;
		dfs(dep+1,i);
	}
}
int main(){
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	    cin>>a[i]>>b[i]>>c[i]>>d[i],a[i]--,b[i]--;
	dfs(0,1);
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3592
def main():
    N, K = map(int, input().split())
    td = []
    for _ in range(N):
        ti, di = map(int, input().split())
        td.append([ti, di])
    td.sort(key=lambda x: -x[1])
    num = 0
    kind = set()
    changable = []
    for i in range(K):
        num += td[i][1]
        if td[i][0] in kind:
            changable.append(td[i][1])
        else:
            kind.add(td[i][0])
    num += len(kind) ** 2
    ans = num

    for i in range(K, N):
        if not changable:
            break
        if td[i][0] not in kind:
            num += td[i][1] + 2 * len(kind) + 1 - changable.pop()
            kind.add(td[i][0])
            ans = max(ans, num)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24496
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'

#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

#ifndef __LOCAL
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout); FAST;
#else
#define FILES(namein, nameout) FAST;
#endif //__LOCAL

using namespace std;
using namespace __gnu_pbds;
using python = void;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned short uss;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type> ordered_set;

const ll M = 1e9+7;
const ll N = 3228;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;
ll dp[N][N];
uss p[N][N];
python solve(){
	FAST;
	string s, t;
	cin >> s >> t;
	ll n1 = s.length(), n2 = t.length();
	for(ll i =1;i<=n1;i++){
		for(ll j = 1;j<=n2;j++){
			if(s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
				p[i][j] = 0;
			}else{
				if(dp[i][j-1] >= dp[i-1][j]){
					dp[i][j] = dp[i][j-1];
					p[i][j] = 1;
				}else{
					dp[i][j] = dp[i-1][j];
					p[i][j] = 2;
				}
			}
		}
	}
	string e = "";
	pll k{n1, n2};
	while(k.x && k.y){
		if(!p[k.x][k.y]){
			e += s[k.x-1];
			--k.x, k.y--;
		}else if(p[k.x][k.y] == 1){
			--k.y;
		}else{
			--k.x;
		}
	}
	reverse(itr(e));
	cout << e << '\n';
}

signed main(){
	FAST;
	ll q = 1;
	//cin >> q;
	while(q--){
		solve();
	}
}

Measured memory_bytes: 96512
import numpy as np

N = int(input())
ts = list(map(int, input().split()))
ms = list(map(int, input().split()))
bs = list(map(int, input().split()))

ts = sorted(ts)
ms = sorted(ms)
bs = sorted(bs)

m_count = np.zeros(N, dtype=int)
i = 0
for j, m in enumerate(ms):
    while i < N and m >= bs[i]:
        i += 1
    m_count[j] = N-i
m_cumcount = np.cumsum(m_count[::-1])[::-1]
#import IPython;IPython.embed()

i = 0
ans = 0
for j, t in enumerate(ts):
    while i < N and t >= ms[i]:
        i += 1
    #print(m_cumcount[j])
    if i == N:
        break
    ans += m_cumcount[i] 
    #np.append(m_count, N-i)
print(ans)



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

 int main(){
     int N,K,X,Y,Ans = 0;

     cin >> N >> K >> X >> Y;

    if(N - K <= 0){
        Ans = N*X;
    }else{
        Ans = K*X;
        Ans += (N-K)*Y;
    }
    cout << Ans << endl;
}



Measured memory_bytes: 256