akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
#define llint long long
#define mod 1000000007

using namespace std;

llint sx, sy, tx, ty;
const int FACT_MAX = 3000005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	make_fact();
	
	cin >> sx >> sy >> tx >> ty;
	
	llint ans = 0;
	for(int i = sx; i <= tx; i++){
		ans += comb(i+ty+1, ty), ans %= mod;
		ans += mod - comb(i+(sy-1)+1, sy-1), ans %= mod;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 47104
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [a,b,c,d] = nexts(4);
  while(a > 0 && c > 0){
    c -= b;
    a -= d;
  }
  return c <= 0 ? "Yes" : "No";
}

Measured memory_bytes: 29992
#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int main() {
  ios;
  int repeat;
  cin >> repeat;
  if(repeat==0)cout<<1<<endl;
  else if(repeat==1)cout<<0<<endl;

  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

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

    int n;
    cin >> n;
    vector<PINT> red(n),blue(n);
    REP(i,n) cin >> red[i].f1 >> red[i].s2;
    REP(i,n) cin >> blue[i].f1 >> blue[i].s2;

    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());

    vector<bool> jud(n,false);
    int ans=0;
    REP(i,n){
        int max;
        bool flg=false;
        for(int j=0;red[j].f1<blue[i].f1&&j<n;j++){
            if(jud[j]) continue;
            if(red[j].s2 < blue[i].s2){
                if(!flg){
                    max=j;
                    flg=true;
                }
                if(red[max].s2 < red[j].s2) max = j;
            }
        }
        if(flg){
            jud[max] = true;
            ++ans;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void num_swap(int num[], int x, int y) {
  int t;
  t = num[x];
  num[x] = num[y];
  num[y] = t;
}


int main(void) {
  int w, n, a, b, i, num[31];

  scanf("%d", &w);
  scanf("%d", &n);

  for (i = 1; i <= w; i++)
    num[i] = i;
  
  for (i = 1; i <= n; i++) { 
    scanf("%d, %d", &a, &b);
    num_swap(num, a, b);
  }
  
  for (i = 1; i <= w; i++)
    printf("%d\n", num[i]);

  return 0;
}

Measured memory_bytes: 596
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
    public class Program
    {
        public static void Main(string[] args)
        {
            new B().test();
        }
    }
	public class B
	{
		public void test()
		{
			var cards = CommonRead.ReadLongL();

			var A = cards[0];
			var B = cards[1];
			var C = cards[2];
			var K = cards[3];

			if (K < A)
			{
				Console.WriteLine(K);
			}
			else if (K <= A + B)
			{
				Console.WriteLine(A);
			}
			else
			{
				// -1する回数 = K - A + B
				var exec = K - A - B;

				Console.WriteLine(A - exec);
			}


		}
	}
static class CommonRead
{
    public static string ReadStr()
    {
        return Console.ReadLine();
    }
    public static string[] ReadStrA()
    {
        return ReadStr().Split(' ');
    }
    public static List<string> ReadStrL()
    {
        return ReadStrA().ToList();
    }
    public static int ReadInt()
    {
        return Convert.ToInt32(ReadStr());
    }
    public static int[] ReadIntA()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray();
    }
    public static List<int> ReadIntL()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToList();
    }
    public static long ReadLong()
    {
        return Convert.ToInt64(ReadStr());
    }
    public static long[] ReadLongA()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray();
    }
    public static List<long> ReadLongL()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToList();
    }

    public static decimal ReadDecimal()
    {
        return Convert.ToDecimal(ReadStr());
    }
    public static decimal[] ReadDecimalA()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray();
    }
    public static List<decimal> ReadDecimalL()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList();
    }

    public static double ReadDouble()
    {
        return Convert.ToDouble(ReadStr());
    }
    public static double[] ReadDoubleA()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray();
    }
    public static List<double> ReadDoubleL()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToList();
    }

}


Measured memory_bytes: 28248
<?php
fscanf(STDIN, "%d%d", $N, $K);
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$F = array_map("intval", explode(" ", trim(fgets(STDIN))));
rsort($A);
sort($F);

$ng = -1;
$ok = 10**12;
while($ok > $ng+1){
    $mid = floor(($ok+$ng)/2);
    if(isOK($mid)){
        $ok = $mid;
    }else{
        $ng = $mid;
    }
}
echo $ok;

function isOK($t){
    global $A, $F, $N, $K;
    $needed = 0;
    for($i = 0; $i < $N; $i++){
        $needed += max(0,$A[$i] - intdiv($t, $F[$i]));
    }
    return $needed <= $K;
}

Measured memory_bytes: 37360
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9 + 7;
const int inf = 1e8;

int main() {
	string S;
	cin>>S;
	string ans = "None";
	rep(i,26){
		char c = 'a'+i;
		if(!(count(all(S),c))){
			ans=c;
			break;
		}
	}
	cout<<ans<<endl;
}

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

int main() {
    while(true){
        int n; cin >> n;
        if (n == 0)break;

        vector<double> V(n);
        double sum = 0;
        rep(i, n){
            cin >> V[i];
            sum += V[i];
        }

        double ave = 1.0 * sum / n;

        double sum2 = 0.0;
        rep(i, n){
            sum2 += (V[i] - ave) * (V[i] - ave);
        }

        double stan = sqrt(sum2 / n);

        printf("%f\n", stan);

    }
}


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

int N, M, L[100001], R[100001];
 
int main(){
    cin >> N >> M;
    for(int i=0;i<M;i++)    cin >> L[i] >> R[i];

    int maxL=0, minR=10000000;
    for(int i=0;i<M;i++){
        maxL = max(maxL, L[i]);
        minR = min(minR, R[i]);
    }

    int ans = minR - maxL + 1;
    if( ans < 0 )   ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 1000005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;



int main(){
  int X, Y;
  cin >> X >> Y;

  if((X+Y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }

  int P = (X+Y)/3;
  
  if(X < P || P + P < X){
    cout << 0 << endl;
    return 0;
  }
  if(Y < P || P + P < Y){
    cout << 0 << endl;
    return 0;
  }
  
  int Q = X-P;
  
  cout << mutil.comb(P, Q) << endl;
  
  return 0;
}



Measured memory_bytes: 15872
#include<iostream>
#include<stdio.h>
using namespace std;

int main() {
	char s;
	int n = 0;
	for (int i = 0; i < 4; i++) {
		scanf("%c", &s);
		if (s == '+')
			n++;
		else
			n--;
	}
	cout << n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c||a+c==b||b+c==a){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int count=0;
		while(true){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n==0&&x==0) break;
			for(int i=1; i<=n; i++){
				for(int j=i+1; j<=n; j++){
					for(int k=j+1; k<=n; k++){
						if(i+j+k==x) { 
							count++;
						}
					}
				}
			}
			System.out.println(count);
			count = 0;
		}
	}
}

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

int main(){
  long int N;
  long int total = 0;
  cin >> N;
  for( int i = 0; i < N+1; i++){
    if(i % 3 != 0 && i % 5 != 0)
      total += i;
  }
  cout << total << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y));

int crack(int x,int y,int** list,int m,int n)
{
	int c[4] = {0,0,0,0};
	list[x][y] = 0;
	if(x <(m-1))
	{
		if(list[x+1][y] == 1)
		{
			c[0] = crack(x+1,y,list,m,n);
		}
	}
	if(x > 0)
	{
		if(list[x-1][y] == 1)
		{
			c[1] = crack(x-1,y,list,m,n);
		}
	}
	if(y <(n-1))
	{
		if(list[x][y+1] == 1)
		{
			c[2] = crack(x,y+1,list,m,n);
		}
	}
	if(y > 0)
	{
		if(list[x][y-1] == 1)
		{
			c[3] = crack(x,y-1,list,m,n);
		}
	}
	list[x][y] = 1;
	int i,max = 0;
	for(i = 0;i < 4;i++)
	{
		if(c[i] > max)
		{
			max = c[i];
		}
	}
	return max+1;
}

int main()
{
	int m,n;
	int** list;
	int i,j,k;
	while(scanf("%d",&m),m)
	{
		scanf("%d",&n);
		list = mem(int*,m);
		for(i = 0;i < m;i++)
		{
			list[i] = mem(int,n);
			for(j = 0;j < n;j++)
			{
				scanf("%d",&list[i][j]);
			}
		}
		int max = 0;
		for(i = 0;i < m;i++)
		{
			for(j = 0;j < n;j++)
			{
				if(list[i][j] == 1)
				{
					int k = crack(i,j,list,m,n);
					if(k > max)
					{
						max = k;
					}
				}
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 0
l=int(input())-1
s=bin(l)[2:]
if s.count("0")==0:
    n=len(s)+1
    print(str(n)+" "+str(2*(n-1)))
    for i in range(n-1):
        print(str(i+1)+" "+str(i+2)+" 0")
        print(str(i+1)+" "+str(i+2)+" "+str(2**i))
else:
    n=len(s)
    res=""
    for i in range(n-1):
        res+=str(i+1)+" "+str(i+2)+" 0\n"
        res+=str(i+1)+" "+str(i+2)+" "+str(2**i)+"\n"
    while True:
        if s[-1]=="1":
            for i in range(1,n+1):
                if s[-i]=="0":
                    break
            ss=s[:-i]+"0"*i
            nnn=int(ss,2)
            res+=str(i)+" "+str(n)+" "+str(nnn)+"\n"
            s=bin(nnn-1)[2:]
            if len(s)<n:
                break
        else:
            res+="1 "+str(n)+" "+str(l)+"\n"
            if s.count("1")>1:
                s=bin(l-1)[2:]
            else:
                break
    r=res.count("\n")
    res=res[:-1]
    print(str(n)+" "+str(r))
    print(res)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1010101010
#define MOD 1000000007
#define LL long long
using Coord = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int c = 0;
    string ans = "";
    for (auto itr = s.rbegin(); itr != s.rend(); itr++) {
        if (*itr == 'B') {
            c++;
            continue;
        }
        if (c > 0) {
            c--;
            continue;
        }
        ans += *itr;
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <map>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

int main(void) {
  int n, l;
  cin>>n>>l;
  vector<int> v;
  for(int i=0; i<n; i++) {
    int x;
    cin>>x;
    v.push_back(x);
  }
  int index=0;
  for(int i=0; i+1<n; i++) {
    if(v[i]+v[i+1]>=l) {
      index = i+1;
    }
  }
  if(index==0) {
    std::cout << "Impossible" << std::endl;
  } else {
    std::cout << "Possible" << std::endl;
    for(int i=1; i<index; i++) {
      std::cout << i << std::endl;
    }
    for(int i=n-1; i>index; i--) {
      std::cout << i << std::endl;
    }
    std::cout << index << std::endl;
  }
  
  
  return 0;
}



Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
    
#define pb push_back
#define PII pair<int,int>
    
#define VS vector<string>
#define VI vector<int>
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m), b(n+1, 0);
    REP(i, m) {
      cin >> a[i];
    }
    REP(i,n+1) { 
      if(a[0] == i) {
        b[i] = 1;
        a.erase(a.begin());
      }
    }
                                                                                                     
    int l=0, r=0;
    int i = x;
    while(1) {
      i--;
      if(b[i] == 1) l++;
      if(i == 0) break;
    } 
    i = x;
    while(1) {
      i++;
      if(b[i] == 1) r++;
      if(i == n) break;
    } 
    
    if(l < r) cout << l << endl;
    else cout << r << endl;
    
}

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

int main () {
	int sum = 0;
	char tem;
	while (scanf ("%c", &tem)) {
		if(tem < '0' || tem > '9') break;
		sum += tem - '0';
//		cout << sum << endl;
	}
	if (sum % 9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3760
# -*- coding: utf-8 -*-

import sys
import os
import math

for s in sys.stdin:
    P = list(map(int, s.split()))

    C = [1, 4, 1, 4, 1, 2, 1, 2]
    enter_num_max_list = []
    enter_num_max = 0

    for i in range(8):
        # rotate
        D = C[i:] + C[:i]

        enter_num = 0
        for j in range(8):
            p = P[j]
            capacity = D[j]
            if capacity >= p:
                enter_num += p
            else:
                enter_num += capacity

        if enter_num > enter_num_max:
            enter_num_max = enter_num
            enter_num_max_list = [D]
        elif enter_num == enter_num_max:
            enter_num_max_list.append(D)

    enter_num_max_list.sort()
    print(*enter_num_max_list[0])

Measured memory_bytes: 7776
//Stable Sort
#include <iostream>
#include <algorithm>

using namespace std;

struct Card {
    char suit;
    int value;
};

void print(Card C[], int n) {
    for(int i=0; i<n-1; i++) cout << C[i].suit << C[i].value << " ";
    cout << C[n-1].suit << C[n-1].value << endl;
}

void bubbleSort(Card C[], int n) {
    for(int i=0; i<n-1; i++) {
        for(int j=n-1; j>i; j--) {
            if(C[j].value < C[j-1].value)
                swap(C[j-1], C[j]);
        }
    }
}

void selectionSort(Card C[], int n) {
    for(int i=0; i<n-1; i++) {
        Card key = C[i];
        int minj = i;
        for(int j=i+1; j<n; j++) {
            if(C[j].value < C[minj].value)
                minj = j;
        }
        if(i != minj) swap(C[i], C[minj]);
    }
}

bool isStable(Card C1[], Card C2[], int n) {
    for(int i=0; i<n; i++)
        if(C1[i].suit != C2[i].suit) return false;
    return true;
}

int main() {
    int n;
    cin >> n;
    Card C1[n], C2[n];
    for(int i=0; i<n; i++) cin >> C1[i].suit >> C1[i].value;
    for(int i=0; i<n; i++) C2[i] = C1[i];

    bubbleSort(C1, n);
    selectionSort(C2, n);

    print(C1, n);
    cout << "Stable" << endl;
    print(C2, n);
    if(isStable(C1, C2, n)) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

    return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
using namespace std;
int n,k,a[105];
bool win[100005];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=0;i<=k;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i<a[j]) continue;
			if(win[i-a[j]]==0) win[i]=1;
		}
	}
	if(win[k]) printf("First\n");
	else printf("Second\n");
}

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

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
    cout << head;
    print0(tail...);
}

struct edge {
    ll u;
    ll v;
    ll a;
    ll b;
};
int main() {
    ll n, m, s, t;
    cin >> n;
    cin >> m;
    cin >> s;
    cin >> t;
    vector<edge> edges;
    vector<vector<edge>> edgemap(n + 1);
    for (ll j = 0; j < m; j++) {
        edge e;
        cin >> e.u;
        cin >> e.v;
        cin >> e.a;
        cin >> e.b;
        edge ee;
        ee.u = e.v;
        ee.v = e.u;
        ee.a = e.a;
        ee.b = e.b;
        edges.push_back(e);
        edgemap[e.u].push_back(e);
        edgemap[ee.u].push_back(ee);
    }
    ll init_yen = 1000000000000000LL;

    vector<ll> min_yen(n + 1);
    for (ll j = 0; j <= n; j++) {
        min_yen[j] = -1;
    }
    min_yen[s] = 0;
    set<ll> instack;
    instack.insert(s);
    while (!instack.empty()) {
        ll nod = (*instack.begin());
        instack.erase(nod);
        for (auto e : edgemap[nod]) {
            auto yen_cost = min_yen[nod] + e.a;
            if (min_yen[e.v] == -1 || min_yen[e.v] > yen_cost) {
                min_yen[e.v] = yen_cost;
                if (instack.count(e.v) == 0) {
                    instack.insert(e.v);
                }
            }
        }
    }

    vector<ll> min_snuuk(n + 1);
    for (ll j = 0; j <= n; j++) {
        min_snuuk[j] = -1;
    }
    min_snuuk[t] = 0;
    set<ll> k_instack;
    k_instack.insert(t);
    while (!k_instack.empty()) {
        ll nod = (*k_instack.begin());
        k_instack.erase(nod);
        for (auto e : edgemap[nod]) {
            auto snuuk_cost = min_snuuk[nod] + e.b;
            if (min_snuuk[e.v] == -1 || min_snuuk[e.v] > snuuk_cost) {
                min_snuuk[e.v] = snuuk_cost;
                if (k_instack.count(e.v) == 0) {
                    k_instack.insert(e.v);
                }
            }
        }
    }

    vector<pair<ll, ll>> last_snuuk(n + 1);
    for (int i = 1; i <= n; i++) {
        last_snuuk[i] = make_pair(i, init_yen - min_yen[i] - min_snuuk[i]);
    }
    last_snuuk[0] = make_pair(0, -1);

    sort(last_snuuk.begin(), last_snuuk.end(), [](pair<ll, ll> p, pair<ll, ll> q) { return p.second > q.second; });

    ll year = 0;
    ll city = 0;
    vector<ll> result(n);
    while (year < n) {
        if (last_snuuk[city].first > year) {
            result[year] = last_snuuk[city].second;
            year++;
        } else {
            city++;
        }
    }

    for (auto r : result) {
        cout << r << endl;
    }
}


Measured memory_bytes: 21548
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;
ll qpow(ll n,ll k)
{
    ll ans=1;
    assert(k>=0);
    n%=mod;
    while(k>0)
    {
        if(k&1)
            ans=(ans*n)%mod;
        n=(n*n)%mod;
        k>>=1;
    }
    return ans%mod;
}
int ar[100009];
int cost[100009];
void run(int i, int n, int k){
    if(i>=n) return;
    if(cost[i]== -1 ){
        REP1(j, k){
            if(i+j < n){
                run(i+j, n, k);
            }
            else break;
        }
    }
    int mn = INT_MAX;
    REP1(j, k){
        if(i+j <= n){
            int c1 = cost[i+j] + abs(ar[i]-ar[i+j]);
            if(mn>c1) mn=c1;
        }
        else break;
    }
    cost[i] = mn;
}
int main()
{
    fast;
    int n, k, v;
    cin>>n>>k;
    REP1(i, n){
        cin>>v;
        cost[i]= -1;
        ar[i] = v;
    }
    cost[n]=0;
    run(1, n, k);
    cout<<cost[1]<<'\n';
    return 0;
}


Measured memory_bytes: 10752
N,M= map(int,input().split())
l=list(map(int,input().split()))
tmp=[]
for i in l:
   tmp.append((1,i))
for i in range(M):
   A,B=list(map(int,input().split()))
   tmp.append((A,B))
from operator import itemgetter
tmp.sort(reverse=True,key=itemgetter(1))
ans,cnt=0,N
for v,s in tmp:
   nd=min(v,cnt)
   ans+=nd*s
   cnt-=nd
print(ans)

Measured memory_bytes: 32088
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
//const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}

ll min(ll a, ll b) {

	if (a < b)
		return a;
	else
		return b;

}


int main() {
	ll N;

	cin >> N;

	ll ans = (N - 1);
	for (ll i = 1; i * i <= N; i++) {

		if (N % i == 0) {
			ans = min(ans, (N / i - 1) + (i - 1));

		}

	}

	cout << ans << endl;
	
	return 0;
}

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

int main(){
	ll n,m;
	cin >> n >> m;
	vector<pair<ll,ll> > ab(n);
	for(int i=0;i<n;i++) {
		int a,b;
		cin >> a >> b;
		ab[i] = make_pair(a,b);
	}
	sort(ab.begin(),ab.end());
	priority_queue<ll> pq;
	ll ans = 0;
	int j = 0;
	for(ll i=1;i<=m;i++) {
		while(ab[j].first <= i and j <n) {
			pq.push(ab[j].second);
			j++;
		}
		if(!pq.empty()) {
			//cout << pq.top() << endl;
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2936
//AOJ 1109

/*
方針:いいから全探索だ!
理論:min{z^3-(x^3+y^3)}(>0)を探しだそう
	y≦x<zは自明

関数説明:
	cube:3乗を返す関数。毎回書くとめんどいカッコ悪い
	cal:見たとおり。
	search:全探索するための関数
		もっとスマートな感じにしたかったけど無理だった。
		再帰関数を無理やり作っている感が非常に高い。
		これ関数2つ作ったほうが・・・(もう書き上がったあとなので修正したくない)
	main:短く

	そもそも見りゃわかるのでこんな解説イランきがしてきた

*/

#include<stdio.h>

long cube(int x){return x*x*x;}
long cal(int x,int y,int z)
	{return cube(z)-cube(x)-cube(y);}

long search(int x,int z, int c){ //1111^3を考慮し一応longで
	long re,y,i,min;
	re=min=cube(z);

	if(c){
		for(i=1;i<z;i++)if(re>search(i,z,0))
			re=search(i,z,0);
		return re;
	}

	else{
		for(i=1;i<=x;i++){
			if(cal(x,i,z)>=0&&cal(x,i,z)<min)
				min=cal(x,i,z);
		}
		return min;
	}
}

int main(){
	int n;
	while(scanf("%d",&n)){ //1<1111らしいのでintでいいよね
		if(!n)break;
		printf("%ld\n",search(1,n,1));
	}
	return 0;
}

/*
　　/　　 /　　/　 /
　　＿n＿
　／//|ヾ＼　/　/
　⌒⌒|⌒⌒
/　　 |∧_∧　/　 /
　　　|・ω・`)
　/　 Oと　 )　/　/
　　　 しーＪ。。。。。
*/

Measured memory_bytes: 600
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Regular091
{
    public class ARC091C_Flip
    {
        public static void Main(string[] args)
        {

            long[] nums = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = nums[0];
            long m = nums[1];

            if(n > m)
            {
                long w = n;
                n = m;
                m = w;
            }

            if(n > 2 && m > 2)
            {
                Console.WriteLine((n - 2) * (m - 2));
            }
            else if(n == 1 && m == 1)
            {
                Console.WriteLine(1);
            }
            else if(n == 1 && m >= 2)
            {
                Console.WriteLine(m - 2);
            }
            else
            {
                Console.WriteLine(0);
            }
            
        }
    }
}

Measured memory_bytes: 13268
#include<cstdio>
typedef long long LL;
const int N=1e6+5,md=1e9+7;
int n,mx[N],a[N];
inline int pow(int a,int b){
	int ret=1;
	for(;b;b>>=1,a=(LL)a*a%md)if(b&1)ret=(LL)ret*a%md;
	return ret;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		int x=a[i];
		for(int i=2;i*i<=x;++i)
		if(x%i==0){
			int cnt=0;
			while(x%i==0)++cnt,x/=i;
			if(cnt>mx[i])mx[i]=cnt;
		}
		if(x>1&&!mx[x])mx[x]=1;
	}
	int s=1,ans=0;
	for(int i=1;i<=1000000;++i)
	if(mx[i])s=1ll*s*pow(i,mx[i])%md;
	for(int i=1;i<=n;++i)
	ans=(ans+(LL)s*pow(a[i],md-2))%md;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>


using namespace std;

long long N, X[1009], Y[1009], H[1009];
vector<tuple<long long, long long, long long>>vec;

int main(){
    cin >> N;
    tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);

    for (int i = 1; i <= N; i++){
        cin >> X[i] >> Y[i] >> H[i];
        if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
    }

    for (int i = 0; i<=100; i++){
        for (int j = 0; j<=100; j++){
            //absは絶対値
            // Vは中心が(i, j)とした時の頂点の高さ
            long long V = get<2>(G) + abs(get<0>(G) -i) + abs(get<1>(G) - j);
            V = max(V,0LL);
            bool flag = true;

            for (int k = 1; k <= N; k++){
                //ここで条件に合うかを確認している感じか
                long long VV = V - abs(X[k] - i) - abs(Y[k] - j);
                VV = max(VV, 0LL);
                //1つでも条件を満たしていなかった場合はfalse
                if (H[k] != VV) flag = false;
            }
            // vecは最終的な答え
            if (flag == true) vec.push_back(make_tuple(i, j, V));
        }
    }
    if (vec.size() == 1){
        cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RFOR(i, a, b) for (int i=a;i>=b;--i)
#define ll long long
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define pb(x) push_back(x)
#define dbg(x) cout<<#x<<" : "<<(x)<<endl;
using namespace std;
const int INF = 1500000000;
const double PI = 3.14159265359;
const int mod = 1000000000 + 7;

int n, r, p[50], c[50], d[50], tmp[50];

void solve() {
  rep(i, r) {
    rep(j, p[i]-1 + c[i]) tmp[j] = d[j];
    rep(j, c[i]) {
      d[j] = tmp[p[i]-1 + j];
    }
    rep(j, p[i] - 1) {
      d[c[i] + j] = tmp[j];
    }
  }
  printf("%d\n", d[0]);
}

int main() {
  while(true) {
    scanf("%d %d", &n, & r);
    if (!n && !r) break;
    rep(i, n) d[i] = n - i;
    rep(i, r) scanf("%d %d", &p[i], &c[i]);
    solve();
  }
  return 0;
}

Measured memory_bytes: 3128
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  int c = 0;
  while (n--) {
    string t;
    cin >> t;
    t += t.substr(0, s.size() - 1);
    c += t.find(s) != string::npos;
  }
  cout << c << endl;
}

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

int main() {
  string s;
  cin >> s;
 int n=0;
  int a,z;
 while (n<s.size()){
   if (s.at(n)=='A'){
    a = n;
    break;
   }
    n++;
 }

while (n<s.size()){
   if (s.at(n)=='Z'){
    z = n;
   }
    n++;
}
 //  cout <<z << a<<s.size()<<endl;;
  cout << z-a+1 ; 
}
  
  

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <limits>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<double> p(n);
	for(int i=0;i<n;i++) cin>>p[i];
	vector<double> dp(n+1);
	dp[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=i;j>=0;j--){
		    if(j==0) dp[j]=dp[j]*(1-p[i-1]);
			else dp[j]=dp[j-1]*p[i-1]+dp[j]*(1-p[i-1]);
		}

	}
	double ans=0;
	for(int i=n/2+1;i<=n;i++){
		ans+=dp[i];
	}
	cout.precision(10);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool ans = [&]{
    int c = 0, m = 0;
    rep(i,n){
      if(i==0 && s[i]!='A') return false;
      if(2<=i&&i<=n-2 && s[i]=='C') ++c;
      if('a'<=s[i]&&s[i]<='z') ++m;
    }
    return c==1 && m==n-2;
  }();
  cout << (ans?"AC":"WA") << endl;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;



int main(){
  int N, M;
  cin >> N >> M;
  double ans = 0;
  int beki = 1;
  double sipai = 1;
  for(int i=0; i < M; ++i){
    beki*=2;
  }
  int time = (N-M)*100+M*1900;
  int sumt = time;
  double kitai = 1;
  while(kitai > 0.001){
    kitai = (double) sumt/beki*sipai;
    ans += kitai;
    sipai *= (double)(beki-1)/beki;
    sumt += time;
  }
  cout << ans << endl;
  

  return 0;
}

Measured memory_bytes: 256
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int yu = c%b;
    int i=1,flag=0;
    while(i<b){
        if(i*a%b==yu){printf("YES");flag=1;break;}
        i++;
    }
    if(flag==0)printf("NO");
    return 0;
}

Measured memory_bytes: 128
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	char a[7],b[7];

	scanf("%s %s",a,b);
	strcat(a,b);
	n = atoi(a);
	if((int)sqrt(n) * (int)sqrt(n) == n)	puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B;
    cin >> A;
    cin >> B;
    vector<string> S(A);
    for(int i = 0;i < (B + 2);i++){
        cout << "#";
    }
    cout << endl;
        for(int i = 0;i < A;i++){
        cin >> S.at(i);
        cout << "#" << S.at(i) << "#" << endl;
    }
        for(int i = 0;i < (B + 2);i++){
        cout << "#";
    }
}

Measured memory_bytes: 256
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース


*/

//main.cpp----------------------------
#define MAX 100000

int a, b;

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

  if(a>b) cout << a+(a-1);
  else if(a<b) cout << b+(b-1);
  else cout << a*2;

  cout << 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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;

int N;

void dfs(string s, char mx) {
    if (s.length() == N) cout << s << endl;
    else {
        for (char c = 'a'; c < mx; c++) {
            dfs(s+c, mx);
        }
        dfs(s+mx, mx+1);
    }
}

int main() {
    cin >> N;
    dfs("", 'a');
}


Measured memory_bytes: 1536
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    if n >= 30 {
        println!("Yes")
    }
    else {
        println!("No")
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 2108
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int A = scan.nextInt();
		int B = scan.nextInt();
		System.out.println(Math.min(A, B) + " " + Math.max(A+B-N,0));
	}
}


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

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    int C[N], A[N][M];
    for(int i = 0; i < N; i++){
        cin >> C[i];
        for(int j = 0; j < M; j++)
            cin >> A[i][j];
    }
    int ans = INT_MAX;
    for(int bit = 0; bit < 1<<N; bit++){
        bool sw = true;
        int Ci = 0, S[M];
        fill(S, S + M, 0);
        for(int i = 0; i < N; i++){
            if(bit & 1<<i) Ci += C[i];
            for(int j = 0; j < M; j++)
                if(bit & 1<<i) S[j] += A[i][j];
        }
        for(int j = 0; j < M; j++)
            sw &= S[j] >= X;
        if(sw) ans = min(ans, Ci);
    }
    if(ans == INT_MAX) cout << -1 << endl;
    else cout << ans << endl;
    
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  string s[N];
  for (int i = 0; i < N; i++) cin >> s[i];
  int M;
  cin >> M;
  string t[M];
  for (int i = 0; i < M; i++) cin >> t[i];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    for (int j = 0; j < N; j++) {
      if (s[i] == s[j]) tmp++;
    }
    for (int j = 0; j < M; j++) {
      if (s[i] == t[j]) tmp--;
    }
    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


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

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string s; cin >> s;
  cout << s.substr(0,4) << " " << s.substr(4) << endl;

  return 0;
}


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


int main(){
    // あとで消す
    //std::ifstream in("din1.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N,K;
    cin >> N >> K;
    vector<int> data(N,0);
    long long E=0;
    int pi;

    for(size_t i=0;i<K;i++){
        cin >> pi;
        data.at(i) = pi+1;
        E += data.at(i);
    }

    long long Emax = E;

    for(size_t i=K;i<N;i++){
        cin >> pi;
        data.at(i) = pi+1;
        E -= data.at(i-K);
        E += data.at(i);
        if(Emax<E){
            Emax = E;
        }
    }

    string suffix = Emax%2==0? ".0" : ".5";
    cout << Emax/2 << suffix <<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX 131072
#define NAME 16

typedef struct {
  char name[NAME];
  unsigned int time;
} pros_t;

long head, tail;
pros_t x, Q[MAX];

void initialize(){
  for (head = 0; head < MAX; head++){
    memset(Q[head].name, '\0', NAME);
    Q[head].time = 0;
  }
  head = tail = 0;
}

int isEmpty(){
  return head == tail;
}

int isFull(){
  return head == (tail + 1) % MAX;
}

int enqueue(pros_t x){
  if (isFull())
    puts("over flow");
  Q[tail] = x;
  if (tail + 1 == MAX)
    tail = 0;
  else
    tail++;
  return 0;
}

pros_t dequeue(){
  if (isEmpty())
    puts("under flow");
  x = Q[head];
  if (head + 1 == MAX)
    head = 0;
  else
    head++;
  return x;
}
  
int main(void){
  long n, i, finish = 0;
  int q;
  pros_t tmp;

  initialize();
  scanf("%ld", &n);
  scanf("%d", &q);
  for(i = 0; i < n; i++) {
    scanf("%s", tmp.name);
    scanf("%d", &tmp.time);
    enqueue(tmp);
  }
  while(head != tail){
    tmp = dequeue();
    if (tmp.time <= q) {
      finish += tmp.time;
      printf("%s %ld\n", tmp.name, finish);
    }
    else {
      finish += q;
      tmp.time -= q;
      enqueue(tmp);
    }
  }
  return 0;
}

Measured memory_bytes: 3160
from collections import deque
h,w,k = map(int,input().split())
y1,x1,gy,gx = map(int,input().split())
m = ["@"*(w+2)]+["@"+input()+"@" for i in range(h)]+["@"*(w+2)]
opt = [(1,0),(0,1),(-1,0),(0,-1)]
dq=deque([(y1,x1)])
ans = 0
temp = [[-1]*(w+2) for i in range(h+2)]
temp[y1][x1] = 0
cnt = 0
while dq:
    # cnt += 1
    # print(cnt)
    y,x = dq.popleft()
    # print(dq,y,x)
    for j in opt:
        y1 = y+j[0]
        x1 = x+j[1]
        if m[y1][x1] == "@":
            # print(y1,x1,"@@")
            continue
        if temp[y1][x1] == -1 or temp[y1][x1]-temp[y][x]>0:
            for i in range(k):
                if (temp[y1+i*j[0]][x1+i*j[1]] == -1 or temp[y1+i*j[0]][x1+i*j[1]]-temp[y][x]>0) and m[y1+i*j[0]][x1+i*j[1]] == ".":
                    if temp[y1+i*j[0]][x1+i*j[1]]-temp[y][x]==1:
                        continue
                    temp[y1+i*j[0]][x1+i*j[1]] = temp[y][x]+1
                    dq.append((y1+i*j[0],x1+i*j[1]))
                    # print(y1+i*j[0],x1+i*j[1],"a",k,m[y1+i*j[0]][x1+i*j[1]],temp[y1+i*j[0]][x1+i*j[1]])
                else:
                    # print(y1+i*j[0],x1+i*j[1],"b",k,m[y1+i*j[0]][x1+i*j[1]],temp[y1+i*j[0]][x1+i*j[1]])
                    break
    # for i in temp:
    #     print(i)
# print(temp)
print(temp[gy][gx])

Measured memory_bytes: 54060
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int m,c,f,r; 
    while(1){
        cin>>m>>f>>r;
        c=m+f;  
        if(m==-1&&f==-1&&r==-1)break;
        else if(m==-1||f==-1){
            printf("F\n");
        }
        else if(80<=c){
            printf("A\n");
        }
        else if (65<=c&&c<80){
            printf("B\n");
        }
        else if (50<=c&&c<65){
            printf("C\n");
        }
        else if (c>=30&&r>=50){
            printf("C\n");
        }
        else if (c>=30&&r<50){
            printf("D\n");
        }
        else if (c<30){
            printf("F\n");
        }
    }
     
    return 0;
}

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

#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

const int INF = INT_MAX;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n, k;
std::string s;

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> n; cin >> k;
    cin >> s;

    int m1 = 0;
    int l = 0, r = 0;
    int ct = 0; // (s[0] == '0') ? 1 : 0;
    while(l < s.size() && r < s.size()) {
        while(ct < k && r < s.size()) {
            if(s[r] == '0') {
                ct++;
                while(r < s.size() && s[r] == '0') { r++; }
            } else {
                r++;
            }
        }
        while(r < s.size() && s[r] == '1') { r++; }
        m1 = max(m1, r-l);
        while(l < r) {
           if(s[l] == '0') {
               while(l < r && s[l] == '0') { l++; }
               ct--; break;
           } else {
               l++;
           }
        }
    }

    cout << m1 << "\n";
}


Measured memory_bytes: 512
/**
 *      ABC 97 A
 *      author  : kyomukyomupurin
 *      created : 2018/08/22
**/

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (max(a - c, c - a) <= d){
        cout << "Yes" << endl;
    }
    else if (max(a - b, b - a) <= d && max(b - c, c - b) <= d){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
    
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

L = [0] * (10 ** 5 + 1)
total = sum(A)

for i in range(N):
    n = A[i]
    L[n] += 1

for i in range(Q):
    b = BC[i][0]
    c = BC[i][1]
    m = L[b]
    total -= b * m
    total += c * m
    L[b] = 0
    L[c] = L[c] + m
    print(total)

Measured memory_bytes: 92560