akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.util.List;

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) throws IOException {
        int l = scanner.nextInt();
        int r = Integer.toBinaryString(l).length() - 1;
        System.out.println(r + 1);
        List<Edge> edges = new ArrayList<>();
        for (int i = 0; i < r; i++) {
            edges.add(new Edge(i + 1, i + 2, 0));
            edges.add(new Edge(i + 1, i + 2, 1 << i));
        }
        for (int i = r; i > 0; i--) {
            int j = l - (1 << i - 1);
            if (j >= 1 << r) {
                edges.add(new Edge(i, r + 1, j));
                l = j;
            }
        }
        System.out.println(edges.size());
        for (Edge edge : edges) {
            System.out.println(edge);
        }
    }

    static class Edge {
        int to;
        int from;
        int cost;

        Edge(int to, int from, int cost) {
            this.to = to;
            this.from = from;
            this.cost = cost;
        }

        @Override
        public String toString() {
            return String.format("%s %s %s", to, from, cost);
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21460
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define ins insert 
#define mp make_pair
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000007
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll c,d,x,y,z,n,k,t;
    ll a[32]={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};
    cin>>c;
    cout<<a[c-1];
    return 0 ;
}


Measured memory_bytes: 256
# 鏡餅の段数、X種類の直径の餅があればX段重ねの鏡餅ができることを使う
dan = 0
N = int(input())
A = [int(input()) for i in range(N)]
for j in range(101):
    if j in A:
        dan += 1
print("{}".format(dan))


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
from collections import deque
from operator import itemgetter
key = itemgetter(0)

N, D, A = map(int, input().split())
X = []
for _ in range(N):
    x, h = map(int, input().split())
    X.append((x, h))
X = sorted(X)[::-1]
Q = deque([])

ans = 0
k = 0
while X:
    if len(Q) == 0 or X[-1][0] <= Q[0][0]:
        x, h = X.pop()
        h = max(h - k * A, 0)
        a = (h + A - 1) // A
        ans += a
        k += a
        deque.append(Q, (x + 2 * D, a))
    else:
        x, a = deque.popleft(Q)
        k -= a

print(ans)

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

using namespace std;


int main()
{
  int a;

  cin>>a;

  bool flag = 0;

  for(int i = 1; i <= 9; i++ ){
    if(a%i == 0 and (a/i) <= 9){
      flag = 1;
      break;
    }
  }
    
  
  if(flag)
    puts("Yes");
  else
    puts("No");

  return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main()
{

	string s;
	int i;
	
	cin>>s;
	for(i=0;i<=3;i++){
		cout<<s[i];
	}
	cout<<" ";
	
	for(i=4;i<=11;i++){
		cout<<s[i];
	}
	
	cout<<"\n";
	
}



Measured memory_bytes: 256
N,M = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(M)]
ans = -1
for i in range(10**N):
    if len(str(i)) != N:
        continue
    k = str(i)
    f = True
    for j in range(M):
        if k[L[j][0]-1] != str(L[j][1]):
            f = False
    if f:
        ans = i
        break
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <string>
#include <map>
#include <vector>
using namespace std;

map <string, int> item;
map <string, vector<string> > recipe;
int n, m, k, money;
char name[101], o[101], material[101];

int dp(string str);

int main(void)
{
    
    while (1){
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++){
            scanf("%s %d", name, &money);
            item.insert( map<string, int>::value_type( name, money ) );
        }
        
        scanf("%d", &m);
        for (int i = 0; i < m; i++){
            scanf("%s %d", o, &k);
            for (int j = 0; j < k; j++){
                scanf("%s", material);
                recipe[o].push_back(material);
            }
        }
        
        scanf("%s", name);
        printf("%d\n", dp(name));
        
        item.clear();
        recipe.clear();
    }
    
    return (0);
}

int dp(string str)
{
    int ans = 0;
    
    if (recipe[str].size() != 0){
        for (int i = 0; i < recipe[str].size(); i++){
            ans += dp(recipe[str][i]);
        }
    }
    else {
        ans = item[str];
    }
    
    if (item[str] < ans) ans = item[str];
    
    return ans;
}

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

int main(){
	int n, m;   //K->m
	cin >> n >> m;
    vector<vector<int>> jan(10);
    for(int i=0; i<n; i++){
        int c, g;
        cin >> c >> g;
        jan[g-1].push_back(c);
    }

    int sz;
    for(int i=0; i<10; i++){
        sort(jan[i].begin(), jan[i].end(), greater<>());
        sz=jan[i].size();
        for(int j=1; j<sz; j++){
            jan[i][j] += jan[i][j-1]+2*j;
        }
        jan[i].insert(jan[i].begin(), 0);
    }
    vector<vector<int>> dp(10, vector<int>(m+1, 0));
    sz = jan[0].size();
    for(int i=0; i<min(sz, m+1); i++){
        dp.at(0).at(i)=jan.at(0).at(i);
    }
    for(int i=1; i<10; i++){
        sz += jan[i].size()-1;
        for(int j=0; j<=min(sz, m); j++){
            int sz2=jan[i].size();
            for(int k=0; k<min(j+1, sz2); k++){
                dp[i][j]=max(dp[i][j], dp[i-1][j-k]+jan[i][k]);
            }
        }
    }
    
    cout << dp[9][m] << endl;
}


Measured memory_bytes: 3248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int> P(n);
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> P.at(i);
	}

	for (int i = 1; i < n - 1; i++) {
		if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
			count++;
		}
		else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
			count++;
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc = initScanner(os.Stdin)
	h, w := scanInt(sc), scanInt(sc)
	solve(h, w)
}

func solve(h, w int)  {
	c := make([]string, h)
	for i:=0;i<h;i++ {
		c[i] = scanString(sc)
	}

	for i:=0;i<h;i++ {
		fmt.Println(c[i])
		fmt.Println(c[i])
	}
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 1800
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int N, K;
	cin >> N >> K;
	ll sum = 0;
	for (int i = K; i <= N + 1; i++)
	{
    	sum += (ll)i * (N - i + 1) + 1;
   		sum %= (1000000000LL + 7);    
	}
	cout << sum << endl;
}

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 60;

int n, p;

LL C[maxn + 5][maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &p);
	REP(i, 0, n + 1)
	{
		C[i][0] = 1;
		REP(j, 1, i + 1) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
	}
	int cnt[2] = {0};
	REP(i, 0, n)
	{
		int x;
		scanf("%d", &x);
		++cnt[x & 1];
	}
	LL ret = 0;
	REP(i, 0, cnt[1] + 1) if (!((i ^ p) & 1)) ret += C[cnt[1]][i];
	ret <<= cnt[0];
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k ;
  cin >> n >> k ;
  cout << min(n%k,k-n%k) <<endl ;
  
  
  
  return 0 ;
}




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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

/***** MAIN *****/
signed main() {
  int n, m;
  cin >> n >> m;
  if(m % n == 0)  {
    cout << m/n << endl;
    return 0;
  }
  int div = m/n;
  while(m%div) --div;
  cout << __gcd(div, m-(div*(n-1)));
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

int main() {
	string s;
	cin >> s;
	int ans=0;
	int rcnt = 0, bcnt = 0,sub=0;
	rep(i, s.size()) {
		if (s[i] != s[0]) {
			sub += 2;
		}
		if (s[0] == *"0") {
			if (s[i] == *"0") {
				rcnt++;
			}
		}
		else {
			if (s[i] == *"1") {
				bcnt++;
			}
		}
	}
	if (s[0] == *"0") {
		ans = min(sub, rcnt*2);
	}
	else {
		ans = min(sub, bcnt*2);
	}
	cout << ans;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<functional>
#include<algorithm>
using namespace std;

int main(){
	string sentence[1000];
	int sentenceNum[1000];
	int array[1000];
	string input;
	int count = 0;
	bool flag;
	int maxLength = 0;

	for(int i=0; i < 1000; i++) sentenceNum[i] = 0;

	while(cin >> input){
		flag = false;
		if(!count){
			sentence[0] = input;
			sentenceNum[0]++;
			count++;
			int inputSize = input.size();
			maxLength = max(maxLength, inputSize);
		}

		else {
			for(int i=0; i < count; i++){
				if(sentence[i] == input){
					sentenceNum[i]++;
					flag = true;
					break;
				}
			}
			if(!flag){
				sentence[count] = input;
				sentenceNum[count]++;
				count++;
				int inputSize = input.size();
				maxLength = max(maxLength, inputSize);
			}
		}
	}

	for(int i=0; i < 1000; i++) array[i] = sentenceNum[i];

	sort(array, array+1000, greater<int>());

	for(int i=0; i< count; i++){
		if(array[0] == sentenceNum[i]){
			cout << sentence[i];
		}
	}
	for(int i=0; i< count; i++){
		int sentenceSize = sentence[i].size();
		if(maxLength == sentenceSize){
			cout << " " << sentence[i] << endl;
		}
	}
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	int a[n+5];
	int b[n+5];
	int c[n+5];
	rep(i,1,n)
		cin >> a[i];
	rep(i,1,n)
		cin >> b[i];
	rep(i,1,n-1)
		cin >> c[i];
	int ans=0;
	rep(i,1,n)
	{
		ans += b[a[i]];
	}
	repp(i,1,n)
	{
		if(a[i+1]-a[i]==1)
		{
			ans += c[a[i]];
		}
	}
	cout << ans << endl;
		
}


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

int main() {
    char c1[201], c2[201], c3[101];
    scanf("%s %s",c1,c3);
    strcpy(c2,c1);
    strcat(c1,c2);

    if (strstr(c1,c3) == NULL) printf("No\n");
    else printf("Yes\n");

    return 0;
}

Measured memory_bytes: 3160
import * as fs from 'fs';

namespace AtCoder.abc001 {

    export class Program {

        constructor(private readonly args: string[][]) {
        }

        /**
         * in
         *
         * out
         *
         */
        main(this: Program): void {
            const [s,w]:number[] = this.args[0].map(Number);

            if (w>=s){
                console.log('unsafe');
            } else {
                console.log('safe');
            }
        }
    }
}

const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
const prg: AtCoder.abc001.Program = new AtCoder.abc001.Program(args);
prg.main();


Measured memory_bytes: 29636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

bool survive[600][600];
int N;
bool is(int x,int y){
	return 0<=x && x<2*N && 0<=y && y<2*N && survive[x][y];
}
using P = pair<int,int>;
vector<P> vec;
int col[600][600];
void dfs(int x,int y,int c){
	col[x][y] = c;
	for(P v:vec){
		int nx = x + v.fs, ny = y+v.sc;
		if(is(nx,ny) && col[nx][ny] == -1){
			dfs(nx,ny,1-c);
		}
	}
}

int main(){
	cin>>N;
	rep(i,2*N) rep(j,2*N) survive[i][j] = 1;
	rep(tt,2){
		int D;
		cin>>D;
		vec.clear();
		for(int x = -2*N; x<=2*N; x++) for(int y=-2*N;y<=2*N;y++){
			if(x*x+y*y == D) vec.pb(P(x,y));
		}
		rep(i,2*N) rep(j,2*N) col[i][j] = -1;
		rep(i,2*N) rep(j,2*N) if(survive[i][j] && col[i][j]==-1){
			dfs(i,j,0);
		}
		int sm[2] = {};
		rep(i,2*N) rep(j,2*N) if(survive[i][j]) sm[col[i][j]]++;
		int c = sm[0]>sm[1] ? 0 : 1;
		rep(i,2*N) rep(j,2*N) survive[i][j] = (survive[i][j] && col[i][j]==c);		
	}
	vector<P> ans;
	rep(i,2*N) rep(j,2*N) if(survive[i][j]) ans.pb(P(i,j));
	assert((int)ans.size() >= N*N);
	rep(i,N*N) cout<<ans[i].fs<<" "<<ans[i].sc<<endl;
}


Measured memory_bytes: 21108
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w,count=0;
    char s[60][60];
    
    cin >> h >> w;
    for(int i=0; i< h ; i++){
        cin >> s[i];
    }
    for(int i=0; i< h ; i++){
        for(int j=0; j< w ; j++){
            if(s[i][j]!='#'){
                for(int x=-1; x< 2 ; x++){
                    for(int y=-1; y< 2 ; y++){
                        if(!(i+x <0 || j+y <0)){
                            if(s[i+x][j+y]=='#'){
                                count++;
                            }
                        }
                    }
                }
                s[i][j]= count + '0';
                count = 0;
            }
        }
        cout << s[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    string s;
    cin>>n>>s;
    vi a(26,1);
    rep(i,n)a[s[i]-'a']++;
    int ans=1;
    rep(i,26)ans=ans*a[i]%mod;
    cout<<ans-1<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
long int a,b,c,x,y,z,k;
  scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&x,&y);
  if(a+b<2*c) printf("%ld",a*x+b*y);
  else 
  {
  if(x<y) {z=x;
          k=y-x;
          if(b<2*c) printf("%ld",2*z*c+b*k);
          else{
           printf("%ld",c*(2*z+2*k));
           }
          }
  else {z=y;
       k=x-y;
        if(a<2*c) printf("%ld",2*z*c+a*k);
          else{
           printf("%ld",c*(2*z+2*k));
       }
  }
return 0;}}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
#define modulo 100000
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	vector<int> mini_prime(100001,0);
	mini_prime[0]=0;
	mini_prime[1]=0;
	
	vector<int> primes;
	
	for(int i=2;i<mini_prime.size();i++){
		if(mini_prime[i]==0){
			primes.push_back(i);
			mini_prime[i]=i;
			for(int j=i*2;j<mini_prime.size();j+=i)mini_prime[j]=i;
		}
	}
	
	int N;
	cin>>N;
	
	vector<long long> s(N);
	
	for(int i=0;i<N;i++){
		scanf("%lld",&s[i]);
	}
	
	map<long long,int> mp;
	
	for(int i=0;i<N;i++){
		for(long long j=2;j*j*j<=10000000000;j++){
		
			while(s[i]%(j*j*j)==0)s[i] /= j*j*j;
		}
		mp[s[i]] ++;
	}
	
	int ans = 0;
	
	for(long long i=2;i<=100000;i++){
		//cout<<i<<endl;
		map<int,int> num;
		int now = i;
		while(now!=1){
			num[mini_prime[now]]++;
			now /= mini_prime[now];
		}
		
		vector<int> P,maxi;
		
		bool f = true;
		
		for(auto a:num){
			P.push_back(a.first);
			if(a.second>1)f=false;
			maxi.push_back(3);
		}
		
		if(!f)continue;
		
		long long X = i*i*i;
		
		vector<int> cnt(P.size(),0);
		while(true){
			long long Y = 1;
			for(int j=0;j<cnt.size();j++){
				for(int k=0;k<cnt[j];k++){
					Y *= P[j];
				}
			}
			long long Z = X/Y;
			if(Z==1)break;
			if(Y!=1){
				ans += max(mp[Y],mp[Z]);
				mp.erase(Y);
				mp.erase(Z);
			}
			for(int j=0;j<cnt.size();j++){
				cnt[j]++;
				if(cnt[j]<=maxi[j])break;
				cnt[j] = 0;
			}
		}
		
	}
	
	if(mp[1]>=1)ans++;
	mp[1] = 0;
	for(auto a:mp)ans += a.second;
	
	cout<<ans<<endl;
	
	
	
    return 0;
}


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

using namespace std;

int main(void) {
	int N,W,H;
	cin >> N >> W >> H;
	vector< pair<int,int> > w(N),h(N);
	int x,y,r;
	for (int i = 0; i < N; ++i) {
		cin >> x >> y >> r;
		w[i].first = x - r;
		w[i].second = x + r;
		h[i].first = y - r;
		h[i].second = y + r;
	}
	sort(w.begin(),w.end());
	sort(h.begin(),h.end());

	bool comp,wcomp,hcomp;
	comp = wcomp = hcomp = true;
	if (w[0].first > 0 && h[0].first > 0) {
		comp = false;
	}
	else if (w[0].first > 0) {
		wcomp = false;
	}
	else if (h[0].first > 0) {
		hcomp = false;
	}

	int wm = w[0].second;
	int hm = h[0].second;
	for (int i = 1; comp && i < N; ++i) {
		if (wcomp) {
			if (wm < w[i].first) {
				wcomp = false;
			}
		}
		if (hcomp) {
			if (hm < h[i].first) {
				hcomp = false;
			}
		}
		if (!wcomp && !hcomp) {
			comp = false;
		}
		wm = max(wm,w[i].second);
		hm = max(hm,h[i].second);
	}

	if (comp) {
		if (wcomp) {
			if (wm < W) {
				wcomp = false;
			}
		}
		if (hcomp) {
			if (hm < H) {
				hcomp = false;
			}
		}
		if (!wcomp && !hcomp) {
			comp = false;
		}
	}

	if (comp) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 4392
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

[N,M] = inpl()
Alist = inpl()

minusA = [-x for x in Alist]
heapq.heapify(minusA)
for i in range(M):
    temp = heapq.heappop(minusA)
    heapq.heappush(minusA,-(-temp//2))

ans = - sum(minusA)
print(ans)

Measured memory_bytes: 23152
#include<bits/stdc++.h>
using namespace std;
priority_queue<long long,vector<long long>,greater<long long> >F;
long long X,Y,Z,a[100009],b[100009],c[100009],d[100009],e[100009];vector<pair<int,int> >I;
long long a1[100009],a2[100009],a3[100009];
int main(){
    cin>>X>>Y>>Z;
    for(int i=0;i<X+Y+Z;i++){
        cin>>a[i]>>b[i]>>c[i];
        I.push_back(make_pair(b[i]-a[i],i));
    }
    sort(I.begin(),I.end());
    for(int i=0;i<I.size();i++){a1[i]=a[I[i].second];a2[i]=b[I[i].second];a3[i]=c[I[i].second];}
    for(int i=0;i<I.size();i++){a[i]=a1[i];b[i]=a2[i];c[i]=a3[i];}
    
    long long p1=0;
    for(int i=0;i<I.size();i++){
        p1+=c[i];
        F.push(a[i]-c[i]);p1+=a[i]-c[i];
        while(F.size()>X){p1-=F.top();F.pop();}
        d[i]=p1;
    }
    /*for(int i=0;i<I.size();i++){
        cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<endl;
    }*/
    p1=0;while(!F.empty())F.pop();
    for(int i=I.size()-1;i>=0;i--){
        p1+=c[i];
        F.push(b[i]-c[i]);p1+=b[i]-c[i];
        while(F.size()>Y){p1-=F.top();F.pop();}
        e[i]=p1;
    }
    //for(int i=X;i<=X+Z;i++)cout<<d[i-1]<<' '<<e[i]<<endl;
    long long maxn=0;
    for(int i=X;i<=X+Z;i++){
        maxn=max(maxn,d[i-1]+e[i]);
    }
    cout<<maxn<<endl;
    return 0;
}

Measured memory_bytes: 8820
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			String s = sc.next();
			if (s.equals("#"))
				break;
			char[] c = new char[s.length()];
			for (int i = 0; i < s.length(); i++) {
				switch (s.charAt(i)) {
				case 'a':
				case 'b':
				case 'c':
				case 'd':
				case 'e':
				case 'f':
				case 'g':
				case 'q':
				case 'r':
				case 's':
				case 't':
				case 'v':
				case 'w':
				case 'x':
				case 'z':
					c[i] = 'l';
					break;
				case 'h':
				case 'i':
				case 'j':
				case 'k':
				case 'l':
				case 'm':
				case 'n':
				case 'o':
				case 'p':
				case 'u':
				case 'y':
					c[i] = 'r';
					break;
				default:
					c[i] = ' ';
					break;
				}
			}
			char nc = c[0];
			int result = 0;
			for(int i=0;i<s.length();i++){
				if(nc != c[i]){
					result++;
					nc = c[i];
				}
			}
			System.out.println(result);
		}
		sc.close();
	}
}

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

int main() {
  int N, M;

  cin >> N >> M;

  vector<int> vec(N);

  for (int i = 0; i < N; i++) {
    vec.at(i) = 0;
  }

  for (int i = 0; i < M; i++) {
    int j, k;

    cin >> j >> k;

    vec.at(j - 1)++;
    vec.at(k - 1)++;
  }

  for (int i = 0; i < N; i++) {
    cout << vec.at(i) << endl;
  }
}


Measured memory_bytes: 256
while 1:
    n=int(input())
    if n == 0:
        break
    a = {}
    for i in range(n):
        x,y=input().split()
        a[x]=y
    m=int(input())
    s = ''
    for i in range(m):
        x = input()[0]
        if x in a.keys():
            s = s+a[x]
        else:
            s = s+x
    print(s)


Measured memory_bytes: 5712
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long a[10001] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    long long min = 1000000, max = -1000000, sum = 0;
    for(int i = 0; i < n; i++){
        if(a[i] < min){
            min = a[i];
        }
        if(max < a[i]){
            max = a[i];
        }
        sum = sum + a[i];
    }
    cout << min << " " << max << " " << sum;
    cout << endl;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    int k = 0;
    bool flag = true;
    for (int i = 0; i < N; i++)
    {
        k = max(k,H[i]);
        if(k-1 > H[i]) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


    


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

int N;
vector<int> a;

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

    sort(a.begin(), a.end());
    int ansb = a.back();

    vector<double> diff(N);
    for (int i = 0; i < N; i++)
    {
        diff[i] = abs((double)a[i] - (double)ansb / 2.0);
    }

    int ansa = a[distance(diff.begin(), min_element(diff.begin(), diff.end()))];

    cout << ansb << " " << ansa << endl;
    return 0;
}


Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
 
 
public class Main{
	
	public static final int MAX = 20;
	
    public static void main(String[] args){
    	final Scanner sc = new Scanner(System.in);
    	
    	long[] facts = new long[MAX + 1];
    	facts[0] = 1; 
    	for(int i = 1; i <= MAX; i++){
    		facts[i] = facts[i - 1] * i;
    	}
    	
    	int[] count = new int[26];
    	char[] input = sc.next().toCharArray();
    	
    	for(char c : input){
    		count[c - 'a']++;
    	}
    	
    	final int allow_odd = input.length % 2 == 0 ? 0 : 1;
    	int odd_count = 0;
    	int odd_pos = -1;
    	for(int i = 0; i < 26; i++){
    		if(count[i] % 2 == 1){
    			odd_count++;
    			odd_pos = i;
    		}
    	}
    	
    	if(allow_odd < odd_count){
    		System.out.println(0);
    		return;
    	}
    	
    	if(odd_pos != -1){
    		count[odd_pos]--;
    	}
    	
    	for(int i = 0; i < 26; i++){
    		count[i] /= 2;
    	}
    	
    	int valid = 0;
    	for(int i = 0; i < 26; i++){
    		valid += count[i];
    	}
    	
    	//System.out.println(Arrays.toString(count));
    	
    	long sum = facts[valid];
    	for(int i = 0; i < 26; i++){
    		sum /= facts[count[i]];
    	}
    	
    	System.out.println(sum);
    }
     
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int n = a * 10 + b + c, x = a + b * 10 + c, y = a + b + c * 10;
  if (n > x && n > y) {
    cout << n << endl;
  }
  else if (x > n && x > y) {
    cout << x << endl;
  }
  else if (y > n && y > x) {
    cout << y << endl;
  }
  else {
  cout << n << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

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

int n, k, c;
string s;
vector<int> vec, vec2;

signed main() {
	cin >> n >> k >> c >> s;
	int cnt = 0;
	for (int i = 0; i < n;) {
		if (s[i] == 'o') {
			cnt++;
			vec.push_back(i);
			i += c + 1;
		}
		else i++;
	}
	cnt = 0;
	for (int i = n - 1; i >= 0;) {
		if (s[i] == 'o') {
			cnt++;
			vec2.push_back(i);
			i -= c + 1;
		}
		else i--;
	}
	if (cnt == k) {
		for (int i = 0; i < k; i++) {
			if (vec[i] == vec2[k - i - 1])cout << vec[i] + 1 << endl;
		}
	}
}

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

int a,b;
string s;
void solve(int A, int B){
	if(A==a && B==b){

		int cntA=0, cntB=0;
		bool flag=true;
		for(int i=0;i<A+B;i++){
			if(s[i]=='A')++cntA;
			else if(s[i]=='B')++cntB;

			if(i<A+B-1){
				if(min(cntA,cntB)<=3 && max(cntA,cntB)>=5){
					flag=false;	break;
				}
			}
		}
		if(flag){
			cout<<s<<endl;	return;
		}
	}else if(A>a || B>b)return;



	s.push_back('A');
	solve(A+1,B);
	s.pop_back();

	s.push_back('B');
	solve(A,B+1);
	s.pop_back();
}

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

	return 0;
}



Measured memory_bytes: 3168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      String[] lines = br.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int m = Integer.parseInt(lines[1]);
      int l = Integer.parseInt(lines[2]);
      long[][] mA ; // = new long[n][m];
      long[][] mB ; // = new long[m][l];
      long[][] mC = new long[n][l];

      Function<String,long[]> lineSplitThenArray =
        s -> Stream.of(s.split(" "))
          .mapToLong(Long::parseLong)
          .toArray();
      
      mA =
        br.lines()
          .limit(n)
          .map( lineSplitThenArray )
          .toArray(long[][]::new);

      mB =
        br.lines()
          .limit(m)
          .map( lineSplitThenArray )
          .toArray(long[][]::new);

      for( int i = 0; i < n; i++ ) {
        for( int j = 0; j < l; j++ ){
          for( int k = 0; k < m; k++ )
          mC[i][j] += mA[i][k] * mB[k][j];
        }
      }

      System.out.println(
        Stream.of(mC)
              .map( a -> ArrayToString(a) )
              .collect(Collectors.joining("\n"))
      );
    }
  }

  public static String ArrayToString(long[] a) {
      if (a == null)
          return "null";
      int iMax = a.length - 1;
      if (iMax == -1)
          return "[]";

      StringBuilder b = new StringBuilder();
      for (int i = 0; ; i++) {
          b.append(a[i]);
          if (i == iMax)
              return b.toString();
          b.append(" ");
      }
  }
}


Measured memory_bytes: 37296
N,P=map(int,input().split());S,a,i,j,c=list(map(int,input())),0,0,1,[1]+[0]*P
if 10%P:
	for v in S[::-1]:i,j=(i+v*j)%P,j*10%P;a+=c[i];c[i]+=1
else:
	for i,v in enumerate(S):
		if v%P<1:a+=i+1
print(a)

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

int main(){
    int p, q, r;
    int min = 999;

    cin >> p >> q >> r;

    if(q + p < min) min = q + p;
    if(p + r < min) min = p + r;
    if(r + q < min) min = r + q;

    cout << min << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <type_traits>
#include <limits>
#include <tuple>

template <class Tp>
class lines {
  // based on Li Chao tree
  std::map<Tp, size_t> enc;
  std::vector<Tp> dec;
  std::vector<std::pair<Tp, Tp>> c;
  size_t m = 1;
  Tp inf = std::numeric_limits<Tp>::max() / 8;

private:
  void init_resize(size_t n) {
    while (m < n+n) m <<= 1;
    c.assign(m, {0, inf});
  }

  void inspect() const {
    for (size_t i = 1; i < m; ++i) {
      std::string s = (c[i].first < inf? std::to_string(c[i].first) : "inf");
      std::string t = (c[i].second < inf? std::to_string(c[i].second) : "inf");
      fprintf(stderr, "(%s, %s)%c", s.c_str(), t.c_str(), (i&(i+1))? ' ':'\n');
    }
  }

public:
  template <class ForwardIt>
  lines(ForwardIt first, ForwardIt last): dec(first, last) {
    static_assert(std::is_same<typename ForwardIt::value_type, Tp>::value, "Type mismatch");
    std::sort(dec.begin(), dec.end());
    size_t n = dec.size();
    init_resize(n);
    while (dec.size() < m/2) dec.push_back(dec.back()+1);
    // dec.resize(m/2, dec.back());
    for (size_t i = 0; i < m/2; ++i) enc.emplace(dec[i], i);
  }

  void append(Tp a, Tp b) {
    size_t l = 0;
    size_t j = 1;
    size_t h = 1;
    size_t w = m/2;
    while (w > 1 && l+w-1 < dec.size()) {
      Tp xl = dec.at(l);
      Tp xm = dec.at(l+w/2);
      Tp xr = dec.at(l+w-1);

      Tp a0, b0;
      std::tie(a0, b0) = c[j];

      Tp yl0 = a0*xl + b0;
      Tp ym0 = a0*xm + b0;
      Tp yr0 = a0*xr + b0;

      Tp yl = a*xl + b;
      Tp ym = a*xm + b;
      Tp yr = a*xr + b;

      if (yl0 <= yl && yr0 <= yr) break;
      if (yl0 >= yl && yr0 >= yr) {
        c[j] = {a, b};
        break;
      }

      h <<= 1;
      w >>= 1;

      if (ym0 >= ym) {
        c[j] = {a, b};
        a = a0;
        b = b0;
        j <<= 1;
        if (yr0 < yr) {
          j |= 1;
          l += w;
        }
      } else {
        j <<= 1;
        if (yr0 >= yr) {
          j |= 1;
          l += w;
        }
      }
    }
  }

  Tp min_at(Tp x) const {
    size_t i = enc.at(x) + m/2;
    Tp y = inf;
    while (i > 0) {
      Tp a, b;
      std::tie(a, b) = c[i];
      y = std::min(y, a*x+b);
      i >>= 1;
    }
    return y;
  }
};

int main() {
  size_t N;
  intmax_t C;
  scanf("%zu %jd", &N, &C);

  std::vector<intmax_t> h(N);
  for (auto& hi: h) scanf("%jd", &hi);

  lines<intmax_t> cht(h.begin(), h.end());

  std::vector<intmax_t> dp(N);
  for (size_t i = 0; i+1 < N; ++i) {
    cht.append(-2*h[i], h[i]*h[i]+dp[i]);
    dp[i+1] = cht.min_at(h[i+1]) + h[i+1]*h[i+1] + C;
  }

  printf("%jd\n", dp[N-1]);
}


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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; ++i)
    {
        cout << s[i] << t[i];
    }
    return 0;
}


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

// int dp(vector<int>& h, vector<int>& mem, int n, int k) {
//     if( n < k && n >= 0) {
//         mem[n] = abs(h[n] - h[0]);
//         return mem[n];
//     }
//     mem[n] = INT_MAX;
//     for(int i = n-1; i >= n-k; i--) {
//         int temp_dp = mem[i] > -1? mem[i]: dp(h, mem, i, k); 
//         mem[n] = min(mem[n], abs(h[n]-h[i]) + temp_dp);
//     }
//     return mem[n];
// }

int main() {
    int n, k;
    cin >> n;
    cin >> k;
    vector<int> ht(n, 0);
    vector<int> mem(n, -1);
    for(int i = 0; i < n; i++) {
        cin >> ht[i];
    }

    for(int i = 0; i < k & i < n; i++) {
        mem[i] = abs(ht[i] - ht[0]);
    }

    for(int i = k; i < n; i++) {
        mem[i] = INT_MAX;
        for(int j = i-1; j >= i-k; j--) {
            mem[i] = min(mem[i], mem[j] + abs(ht[i]-ht[j]));
        }
    }
    cout << mem[n-1];

    return 0;
} 

Measured memory_bytes: 1024
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main(){
	double ans = 0;
	int n;
	double v[10];
	vector<string> s(10);
	cin >> n;
	rep(i, n) {
		cin >> v[i] >> s[i];
	}

	rep(i, n) {
		if (s[i] == "JPY") {
			ans += v[i];
		}
		else {
			ans += v[i] * 380000;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
w=list(map(int,input().split()))
s_1=0
s_2=sum(w)
for i in range(n):
  if abs(s_2 - s_1) >= abs(s_2-s_1-2*w[i]):
    s_2 -= w[i]
    s_1 += w[i]
  else:
    break
print(abs(s_2-s_1))

Measured memory_bytes: 9180
#include<stdio.h>
#define INF 10000000
int c,n,m,s,g;
int e[100][100];
int d[11][100];
int i,j;
bool used[11][100];

int min(int a,int b){return a<b?a:b;}

int main(){
	while(1){
		scanf("%d %d %d %d %d",&c,&n,&m,&s,&g);
		if(c==0)return 0;
		for(i=0;i<n;i++)for(j=0;j<n;j++)e[j][i]=INF;
		for(i=0;i<m;i++){
			int a,b,f;
			scanf("%d %d %d",&a,&b,&f);
			e[a-1][b-1]=f;
			e[b-1][a-1]=f;
		}
		for(i=0;i<n;i++)for(j=0;j<=c;j++){
			d[j][i]=INF;
			used[j][i]=false;
		}
		d[c][s-1]=0;
		while(1){
			int nei=-1;
			int nej;
			for(i=0;i<n;i++)for(j=0;j<=c;j++){
				if(!used[j][i]&&(nei==-1||d[j][i]<d[nej][nei])){
					nei=i;
					nej=j;
				}
			}
			if(nei==-1)break;
			used[nej][nei]=true;
			for(i=0;i<n;i++){
				d[nej][i]=min(d[nej][i],d[nej][nei]+e[nei][i]);
				if(nej>0)d[nej-1][i]=min(d[nej-1][i],d[nej][nei]+e[nei][i]/2);
			}
		}
		int ans=INF;
		for(i=0;i<=c;i++)ans=min(ans,d[i][g-1]);
		printf("%d\n",ans);
	}
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,i,j,result=0,x=-1;
    cin>>n;
    long long int A[n];
    map<long long int,long long int>mt;
    for(i=0;i<n;i++){
        cin>>A[i];
        mt[A[i]]+=1;
        x=max(x,A[i]);
    }
    long long int visited[x+1]={0};
    sort(A,A+n);
    /*for(i=n-1;i>=0;i--){
        mt[A[i]]-=1;
        for(j=1;j*j<=A[i];j++){
            if(A[i]%j==0){
                if(mt[j]>0||mt[A[i]/j]>0)
                break;
            }
        }
        mt[A[i]]+=1;
    if(j*j>A[i]){
        result+=1;
        //cout<<A[i]<<" ";
    }
    }
    cout<<result;*/
    for(i=0;i<n;i++){
        mt[A[i]]-=1;
        if(mt[A[i]]==0&&visited[A[i]]==0)
            result+=1;
        for(j=1;A[i]*j<=x;j++){
            visited[A[i]*j]=A[i];
        }
        mt[A[i]]+=1;
    }
    cout<<result;
    return 0;
}


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

string S;

int main() {
    cin >> S;
    int ans = 0;
    for (int i=0; i<S.length(); i++) {
        if (S[i] != 'R') continue;
        else ans = max(ans, 1);
        for (int j=i+1; j<S.length(); j++) {
            if (S[j] != 'R') break;
            else ans = max(ans, j-i+1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int inf=1000000000;
const int N=500010;
int n,ncnt,c[N],a[N],lnum[2*N],rnum[2*N],lch[2*N],rch[2*N],delta[2*N],key[2*N],ans[N],deg[N];
pii b[N];
priority_queue<int> q;

inline int lowbit(int x) {return x&(-x);}

void change(int x)
{
	while (x<=n)
	{
		c[x]++;x+=lowbit(x);
	}
}

int query(int x)
{
	int y=0;
	while (x)
	{
		y+=c[x];x-=lowbit(x);
	}
	return y;
}

void build(int k,int l,int r)
{
	lnum[k]=l;rnum[k]=r;delta[k]=0;
	if (l==r)
	{
		if (!deg[l]) key[k]=inf; else key[k]=deg[l];
		return;
	}
	int mid=(l+r)>>1;
	lch[k]=++ncnt;build(ncnt,l,mid);
	rch[k]=++ncnt;build(ncnt,mid+1,r);
	key[k]=min(key[lch[k]],key[rch[k]]);
}

void pushdown(int k)
{
	if (delta[k])
	{
		delta[lch[k]]+=delta[k];key[lch[k]]-=delta[k];
		delta[rch[k]]+=delta[k];key[rch[k]]-=delta[k];
		delta[k]=0;
	}
}

void modify(int k,int l,int r)
{
	if (lnum[k]==rnum[k]&&key[k]==1)
	{
		q.push(lnum[k]);key[k]=inf;return;
	}
	if (l<=lnum[k]&&r>=rnum[k]&&key[k]>1)
	{
		delta[k]++;key[k]--;return;
	}
	pushdown(k);
	if (l<lnum[rch[k]]) modify(lch[k],l,r);
	if (r>rnum[lch[k]]) modify(rch[k],l,r);
	key[k]=min(key[lch[k]],key[rch[k]]);
}

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int k;scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) b[i]=mp(a[i],i);
	sort(b+1,b+n+1);
	memset(c,0,sizeof(c));
	for (int i=n;i;i--)
	{
		int l=max(1,b[i].y-k+1),r=min(n,b[i].y+k-1);
		deg[b[i].y]=query(r)-query(l-1);
		if (!deg[b[i].y]) q.push(b[i].y);
		change(b[i].y);
	}
	ncnt=0;build(0,1,n);
	for (int i=n;i;i--)
	{
		int x=q.top();q.pop();
		ans[x]=i;
		int l=max(1,x-k+1),r=min(n,x+k-1);
		modify(0,l,r);
	}
	for (int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 40816
#include <iostream>
#include <iomanip>
#include <cstdlib>

int main(){
  while(true){
    int n;
    std::cin >> n;
    if (n == 0) return EXIT_SUCCESS;
    char s, t, b;
    std::cin >> s >> t >> b;
    double p[9];
    for(int i=0; i<9; i++) p[i] = 0.0;
    p[s-'A'] = 1.0;
    for(int i=0; i<n; i++){
      double newp[9];
      for(int j=0; j<9; j++) newp[j] = 0.0;
      for(int j=0; j<9; j++){
        double p4 = p[j]/4.0;
        //left
        if(j%3==0) newp[j]+=p4;
        else if(j-1 == b-'A') newp[j]+=p4;
        else newp[j-1]+=p4;
        //right
        if(j%3==2) newp[j]+=p4;
        else if(j+1 == b-'A') newp[j]+=p4;
        else newp[j+1]+=p4;
        //up
        if(j<3) newp[j]+=p4;
        else if(j-3 == b-'A') newp[j]+=p4;
        else newp[j-3]+=p4;
        //down
        if(j>=6) newp[j]+=p4;
        else if(j+3 == b-'A') newp[j]+=p4;
        else newp[j+3]+=p4;
      }
      //update
      for(int j=0; j<9; j++) p[j] = newp[j];
    }
    std::cout << std::fixed;
    std::cout << std::setprecision(8) << p[t-'A'] << std::endl;
  }
}


Measured memory_bytes: 3200
N,M,X = map(int,input().split())
books = []

for _ in range(N):
  info = list(map(int,input().split()))
  books.append(info)

res = float('inf')
for i in range(1<<N):
  scores = [0] * M
  cost = 0
  for j in range(N):
    if (i>>j)&1:
      for k,p in enumerate(books[j][1:]):
        scores[k] += p
      cost += books[j][0]

  if all([ score >= X for score in scores]):
    res = min(res, cost)

print(res) if res < float('inf') else print('-1')

Measured memory_bytes: 69268
#include<stdio.h>
int main()
{
	int a,b;
	char c;
	//scanf("%d%c%d",&a,&c,&b);
	scanf("%d",&a);
	getchar();
	scanf("%c",&c);
	scanf("%d",&b);
	if(c=='+')
	 printf("%d\n",a+b);
	else
	 printf("%d\n",a-b);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
 
  int64_t prev = 2;
  int64_t current = 1;
  int64_t next;
  for(int i = 1;i < n;i++){
  	next = current + prev;
    prev = current;
    current = next;
  }
  
  cout << current << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
VI G[1011];
int X[1011];

int dp[1011];
int buf[2][5011];
int *cur = buf[0];
int *nxt = buf[1];

void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int p;
	scanf("%d", &p);
	G[p-1].push_back(i+1);
    }
    REP (i, N) scanf("%d", X+i);

    memset(dp, 0x3f, sizeof dp);
    for (int v=N; v--;) {
	memset(cur, 0x3f, sizeof buf[0]);
	cur[0] = 0;
	EACH (e, G[v]) {
	    memset(nxt, 0x3f, sizeof buf[0]);
	    REP (a, X[v]-X[*e]+1) amin(nxt[a + X[*e]], cur[a] + dp[*e]);
	    REP (a, X[v]-dp[*e]+1) amin(nxt[a + dp[*e]], cur[a] + X[*e]);
	    swap(cur, nxt);
	}

	dp[v] = *min_element(cur, cur+X[v]+1);
	if (dp[v] >= dp[N]) {
	    puts("IMPOSSIBLE");
	    return;
	}
    }
    puts("POSSIBLE");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll N,K,Q;
    cin>>N>>K>>Q;
    vector<ll> A(Q+1);
    rep(i,0,Q){
        cin>>A[i];
    }

    vector<ll> ans(N+1,K-Q);
    rep(i,0,Q){
        ans[A[i]]++;
    }
    rep(i,1,N+1){
        if(ans[i]>0){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2176
from itertools import accumulate

N,K=map(int,input().split())
p = list(map(int,input().split()))

pp=[0]*N
for i in range(N):
  pp[i]=(p[i]+1)/2

sum=0
temp=0
for i in range(0,K):
  temp+=pp[i]
sum=temp
for i in range(0,N-K):
  temp=temp-pp[i]+pp[i+K]
  sum=max(sum,temp)
print(sum)


Measured memory_bytes: 25152