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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int h,w;
int c[55][55];
bool done[55][55];
vector<pair<int,int>> v{P(-1,-1),P(-1,0),P(-1,1),P(0,-1),P(0,1),P(1,-1),P(1,0),P(1,1)};

void dfs(int x, int y){
    if(done[x][y]) return;
    done[x][y] = true;
    
    for(P p : v){
        int i = p.first, j = p.second;
        if(0<=x+i && x+i<h && 0<=y+j && y+j<w && c[x+i][y+j]) dfs(x+i,y+j);
    }
}

int main(void){

    cin >> w >> h;
    while(h!=0 || w!=0){
        CLR(c); CLR(done);
        REP(i,h)REP(j,w) cin >> c[i][j];

        int ans = 0;
        REP(i,h)REP(j,w){
            if(done[i][j] || c[i][j]==0) continue;
            dfs(i,j);
            ans++;
        }
        cout << ans << en;
        cin >> w >> h;
    }
    return 0;
}


Measured memory_bytes: 3224
import itertools
import sys

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ids = [x for x in range(n)]

diff = [tmpv - tmpc for tmpv, tmpc in zip(v, c)]

result = 0

for i in range(1, n+1):
    tmp = list(itertools.combinations(diff, i))
    tmpMax = max([sum(x) for x in tmp])
    if tmpMax > result:
        result = tmpMax
    # store.extend([sum(x) for x in tmp])
    # print(store)
    # for x, y in zip(vset, cset):
    #     store.append(sum(x)-sum(y))

print(result)


Measured memory_bytes: 54144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int N;
        double M,SUM;
 
        try {
            while((N = Integer.parseInt(br.readLine())) != 0){
 
                String input[] = br.readLine().split("\\s+");
                double array[] = new double[input.length];
 
                SUM = 0;
 
                for(int i = 0; i < input.length; i++){
                    array[i] = Double.parseDouble(input[i]);
                    SUM += array[i];
                }
 
                M = SUM/(double)N;
                SUM = 0;
 
                for(int i = 0; i < array.length; i++){
                    SUM += (array[i]-M)*(array[i]-M);
                }
 
                System.out.printf("%.10f\n", Math.sqrt(SUM/(double)N));
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 27712
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , x , l[MAXN];

int main() {
    fast_io;

    cin >> n >> x;
    for(ll i = 1 ; i <= n ; i++)    cin >> l[i];
    partial_sum(l , l + MAXN , l);

    cout << upper_bound(l , l + n + 1 , x) - l << endl;

    return 0;
}
/*
todo :
    1- set constants
    2- check TimeLimit and MemoryLimit
    3- check special test cases
    4- don't forget BS can help you that is good idea(use for loop for floats)
    5- don't forget printf and scanf can help you in your code speed
*/


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

bool solve(ll x){
    for(ll i=-1000;i<=1000;++i){
        ll num = i*i*i*i*i;
        for(ll j=-1000;j<=1000;++j){
            ll num2 = j*j*j*j*j;
            if(num - num2 == x){
                cout << i << " " << j << "\n";
                return 0;
            }else if(num2 - num == x){
                cout << j << " " << i << "\n";
                return 0;
            }
        }
    }
    return false;
}

int main(){
    ll x;cin >> x;
    solve(x);
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int N; cin >> N;   
    vector<long long> As(N);
    long long l = 0;
    for (int i = 0; i < N; i++) {
        long long a; cin >> a;
        l += a;
        As[i] = a;
    }
    int i;
    long long t = 0;
    for (i = 0; i < N; i++) {
        t += As[i];
        if (2 * t > l) break;
    }
    long long k = t - As[i];
    long long ans = min(2 * t - l, l - 2 * k);
    cout << ans << endl;
}

Measured memory_bytes: 1792
h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#") for x in range(h)]+[["#"]*(w+2)]
sx,sy=1,1
gx,gy=w,h
loc=[[sy,sx]]
ans=sum(i.count(".")for i in grid)
for c in range(h*w):
    next_loc=[]
    for y,x in loc:
        for i,j in([0,1],[1,0],[0,-1],[-1,0]):
            if grid[y+i][x+j]=='.':
                grid[y][x]=c+1
                grid[y+i][x+j]=c+2
                next_loc.append([y+i,x+j])
    loc=next_loc
    if [gy,gx] in loc:
        ans-=grid[gy][gx]
#        for i in grid:
#            print(*i)
        print(ans)
        exit()
print(-1)

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n,t,count=10000,cc,ans=0;
  int cost[2000];
  int num[2000];
  cin>>n>>t;
  for(int i=0;i<n;i++){
    cin>>cost[i]>>num[i];
  }
  for(int j=0;j<n;j++){
    if(num[j]<=t){
      ans++;
      cc=min(cost[j],count);
      if(cost[j]<count)
        count=cost[j];
    }
  }
  if(ans==0)
    cout<<"TLE"<<endl;
  else
    cout<<cc<<endl;
}

Measured memory_bytes: 888
my $in = <STDIN>;
my $in2 = <STDIN>;
chomp($in);
chomp($in2);
my @S = split(//,$in);
my @T = split(//,$in2);
my $min = @T;
my $len = @S - $min + 1;
for (my $i=0; $i<$len; $i++) {
  my $sum = 0;
  for (my $j=0; $j<@T; $j++) {
    $sum++ if ($S[$i+$j] ne $T[$j]);
  }
  if ($sum < $min) {
    $min = $sum;
  }
}
print $min;


Measured memory_bytes: 4888
import sys
n = int(input())

for i in range(3, n + 1):
	x = i
	if x % 3 == 0 or x % 10 == 3:
		sys.stdout.write(' ' + str(i))
	else:
		while x != 0:
			x = int(x / 10)
			if x % 10 == 3:
				sys.stdout.write(' ' + str(i))
				break
print()


Measured memory_bytes: 5732
#include<stdio.h>

int main(void) {

	int i, j, k, n, x;
	

	while(1) {

		scanf("%d %d", &n, &x);
		int count = 0;
		if (n == 0 && x == 0)
			break;

		for (i = 1; i <= n - 2; i++) {
			for (j = 2; j <= n - 1; j++) {
				for (k = 3; k <= n; k++) {

					if (x == i + j + k && i < j && j < k)

						count++;
					
				}
			}
		}

		printf("%d\n", count);

	} 
	
	return(0);

}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll l,r;
    scanf("%lld%lld",&l,&r);
    //cout<<l%2019<<" "<<r%2019<<endl;
    if(r-l>=2019)
    {
        printf("0\n");
        return 0;
    }

    if(l%2019>r%2019)
    {
        printf("0\n");
        return 0;
    }
    ll minn=100000;
    for(ll i=l%2019;i<=r%2019;i++)
    {
        for(ll j=l%2019;j<=r%2019;j++)
        {
            if(i==j) continue;
            minn=min(minn,(i*j)%2019);
        }
    }
    printf("%lld\n",minn);
}


Measured memory_bytes: 256
n,k,q = map(int,input().split())
a = [int(input()) for i in range(q)]
player_point = [q]*n
 
for i in range(q):
    player_point[a[i]-1] -= 1
 
for i in range(n):
    if player_point[i] < k:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 10452
#include<stdio.h>

int map[5][5];

int rectangular(int x,int y){
  int i,j,k;
  int a[5];
  int size;

  i = 1;
  while(1){
    if(x+i < 5 && map[x+i][y])i++;
    else break;
  }
  a[0] = i;
  size = i;

  j = 1;
  while(1){
    if(y+j < 5 && map[x][y+j]){
      for(k=1;k<a[j-1];k++){
	if(!map[x+k][y+j])break;
      }
      a[j] = k;
      if(size < (j+1)*a[j])size = (j+1)*a[j];
      j++;
    }else break;
  }

  return size;
}



int main(void){
  int m;
  int i,j,k;
  int max;
  int tmp;

  scanf("%d",&m);

  for(k=0;k<m;k++){

    for(i=0;i<5;i++){
      for(j=0;j<5;j++){
	scanf("%d",&map[i][j]);
      }
    }

    max = 0;
    for(i=0;i<5;i++){
      for(j=0;j<5;j++){
	if(map[i][j]){
	  tmp = rectangular(i,j);
	  if(tmp > max)max = tmp;
	}
      }
    }

    printf("%d\n",max);

  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int N;
	cin>>N;
	int x[100];
	for(int i=0;i<N;i++){
		cin>>x[i];
	}
	sort(x,x+N);
	int w=1;
	for(int j=0;j<N-1;j++){
		if(x[j]<x[j+1]){
			w=w+1;
		}
	}
	cout<<w;
}

Measured memory_bytes: 256
A, B = map(int, input().split())


def f(x):
    res = 1 if 1 <= x % 4 <= 2 else 0
    for i in range(1, x.bit_length()):
        res += 1 << i if ((x >> i) & 1) and (x % 2 == 0) else 0
    return res


ans = f(B) ^ f(A - 1) if A > 0 else f(B)
print(ans)

Measured memory_bytes: 3064
n = gets.chomp.to_i
hs = gets.chomp.split(" ").map(&:to_i)

def f(i, hs)
  return puts i if hs.max == 0
  prev = 0
  g = 0
  for k in hs do
    g += 1 if prev == 0 && k != 0
    prev = k
  end
  hss = hs.map{ |b| b <= 0 ? 0 : b - 1 }
  f(i + g, hss)
end

f(0, hs)


Measured memory_bytes: 1916
#include <iostream>

 

using namespace std;

 

int main()
{
    int a,b,z;
    
    cin >> a >> b;
   z=a-b;
   
    if (z > 0)
      cout << "a"<<" " <<">"<<" "<<"b"<< endl;
    else if (z < 0)
        cout << "a"<<" " <<"<"<<" "<<"b"<< endl;
    else
      cout << "a == b" << endl;
   
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  ll sum=0,mi=A[0];
  rep(i,N){
    sum+=A[i];
    chmin(mi,A[i]);
  }

  bool first=false;
  if(N%2){
    if(sum%2) first=true;
  }else{
    if(sum%2) first=true;
    else if(mi%2) first=true;
  }

  if(first) cout<<"First"<<endl;
  else cout<<"Second"<<endl;

  return 0;
}



Measured memory_bytes: 4424
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		LinkedList<Integer> l = new LinkedList<Integer>();
		for (int i = 0; i < n; i++) {
			String[] str = br.readLine().split(" ");
			String command = str[0];
			if (command.equals("insert")) {
				l.addFirst(Integer.parseInt(str[1]));
			} else if (command.equals("deleteFirst")) {
				l.removeFirst();
			} else if (command.equals("deleteLast")){
				l.removeLast();
			} else if (command.equals("delete")) {
				l.removeFirstOccurrence(Integer.parseInt(str[1]));
			} else {
				throw new IllegalArgumentException();
			}
		}

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder sb = new StringBuilder();
        sb.append(l.poll());
        for (Integer s : l) {
            sb.append(" ");
            sb.append(s);
        }
        bw.write(sb.toString());
        bw.newLine();
        bw.close();

		br.close();
	}

}



Measured memory_bytes: 203016
#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++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

struct kouji{
    int s,t,x;
};


bool comp(kouji k1,kouji k2){
    return k1.x < k2.x;

}
signed main(){
    int n,q;
    cin >> n >> q;
    kouji K[n];
    REP(i,n) cin >> K[i].s >> K[i].t >> K[i].x;
    sort(K,K + n , comp);
    set<pair<int,int>> S;
    REP(i,q){
        int d;
        cin >> d;
        S.insert( pair<int,int>{d,i} );
    }
    int ans[q];
    REP(i,q) ans[i] = - 1;

    REP(i,n){
        auto itr = S.lower_bound(pair<int,int>{K[i].s - K[i].x, - 1});
        while(1){
            if(itr == S.end() or itr->fi >= K[i].t - K[i].x) break;
            ans[itr->se] = K[i].x;
            S.erase(itr++);
            //itr = next(itr);
        }
    }

    REP(i,q){
        cout << ans[i] << endl;
    }
}

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

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;

	int cnt = 0;
	rep(i, N - 2) {
		if(S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C')
			cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
def resolve():
    H, W = list(map(int, input().split(" ")))
    S = ["."*(W+2)]
    S.extend(["."+input()+"." for i in range(H)])
    S.extend(["."*(W+2)])
    
    for i in range(H+2):
        for j in range(W+2):
            if S[i][j] == "#":
                if not (S[i-1][j] == "#" or S[i+1][j] == "#" or S[i][j-1] == "#" or S[i][j+1] == "#"):
                    print("No")
                    return
    print("Yes")
    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 39152
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)

var a, b int

func main() {
	sc.Split(bufio.ScanWords)
	a, b = nextInt(), nextInt()
	sa := strconv.Itoa(a)
	sb := strconv.Itoa(b)
	var A, B string
	for i := 0; i < a; i++ {
		A += sb
	}
	for i := 0; i < b; i++ {
		B += sa
	}

	if A < B {
		fmt.Println(A)
	} else {
		fmt.Println(B)
	}
}


Measured memory_bytes: 640
import java.util.Scanner;

/**
 * Created by khrom on 2017/06/11.
 * ??????????????????????????????????§?????£????????????¨?????????????????????
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in).useDelimiter("\\s");
        int w = scanner.nextInt();
        int h = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int r = scanner.nextInt();
        if (x < 0 || y < 0) System.out.println("No");
        else if (w - x - r >= 0 && h - y - r >= 0) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 26268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iterator>
#include <deque>
#include <bitset>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <fstream>
#include <ios>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <bitset>
#include <queue>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
	string a;
	cin >> a;
	if (a[2] == a[3] and a[4] == a[5]) {
		cout << "Yes";
	}
	else
		cout << "No";
}



Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

// 特定の文字列を数える関数
size_t count(const string& str, const string& sub, const size_t ini = 0, const size_t fin = string::npos) {
	size_t pos = str.find(sub, ini);
	size_t cnt = 0;
	while (pos < fin) {
		cnt += 1;
		pos = str.find(sub, pos + sub.length());
	}
	return cnt;
}

int main() {

	int N, K;
	cin >> N >> K;

	int R, S, P;
	cin >> R >> S >> P;

	string T;
	cin >> T;

	size_t nR = count(T, "r");
	size_t nS = count(T, "s");
	size_t nP = count(T, "p");

	vector<string> str(K, "");

	for (int i = 0; i < N; i++) {
		str[i % K] += T.substr(i, 1);
	}

	for (int i = 0; i < str.size(); i++) {
		nR -= count(str[i], "rr");
		nS -= count(str[i], "ss");
		nP -= count(str[i], "pp");
	}
	
	int ans = P * nR + R * nS + S * nP;

	cout << ans << endl;

	return 0;
}

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

int main () {
  int K, N, M;
  cin >> K >> N;
  vector<int> A(N);
  vector<int> B(N);
  M = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (i == N-1) {
      B.at(i) = K + A.at(0) -A.at(i);
    }
    else {
      B.at(i) = A.at(i+1)-A.at(i);
    }
  }
  
  for (int i = 0; i < N; i++) {
    M = max(M, B.at(i));
  }
  
  cout << K - M << endl;
}

      

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



vector<int> available[100010];

int main(){
    int N, M;
    cin >> N >> M;
    
    priority_queue<int> Q;
    for(int i = 0 ; i < N ; i++){
        int a, b;
        cin >> a >> b;
        if( M >= a ) available[M-a].push_back(b);
    }
    
    long long ans = 0;
    for(int i = M ; i >= 0; i--){
        for( auto v : available[i] )
            Q.push(v);
        if( Q.size() > 0 ) {
            ans += Q.top(); Q.pop();
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 5632
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"a == b"<<endl;
  }
  else if(a>b){
    cout <<"a > b"<<endl;
  }
  else{
    cout<<"a < b"<<endl;
  }
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define  pb(x) push_back(x)
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define mod 1000000007
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[n];
	input(arr,n);
	ld ans=0;
	for(ll i=0;i<n;i++)
	ans+=1/(ld)arr[i];
	ans=1.0/ans;
	cout<<fixed<<setprecision(10)<<ans;
}

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

main()
{
	int n;
	scanf("%d", &n);
	
	vector <int> vc(n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &vc[i]);
	}
	
	ll dp[n];
	dp[0] = 0; dp[1] = abs(vc[1]-vc[0]);
	
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i-1]+abs(vc[i]-vc[i-1]), dp[i-2]+abs(vc[i]-vc[i-2]));
	}
	
	printf("%lld\n", dp[n-1]);
}

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

def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = A[left:left+n1]
    R = A[mid:mid+n2]
    L.append(float('inf'))
    R.append(float('inf'))
    
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            cnt += n1 - i
            j += 1


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    

if __name__ == '__main__':

    n = int(input())
    A = [int(a) for a in input().split(" ")]
    cnt = 0
    mergeSort(A, 0, n)
    print(cnt)



Measured memory_bytes: 27488
#include <iostream>
#include <vector>
#include <set>

using namespace std;

#define _C

#ifdef _C

int main(void)
{
	int A, B, C, D, E, F;
	int maxw = 0, maxs  = 0;
	float rat = -1;
	cin >> A >> B >> C >> D >> E >> F;
#if 1
	set<int> xarr,yarr;
	for (size_t a = 0; 100 * a*A <= F; a++)
		for (size_t b = 0; 100 * a*A + 100 * b*B <= F; b++)
		{
			xarr.insert(100 * a*A + 100 * b*B);
		}
	for (size_t c = 0; c*C   <= F; c++)
		for (size_t d = 0; d*D + c*C <= F; d++)
		{
			yarr.insert(d*D + c*C);
		}
	set<int>::iterator wa = xarr.begin(), su = yarr.begin(), enwa = xarr.end(), ensu = yarr.end();
	wa++;
	for (; su != ensu ; su++) {

		while ((*su) * 100 > E *(*wa))
		{
			wa++;
			if (wa == enwa)break;
		}
		if (wa == enwa)break;

		int sum = *su + *wa;
		if (sum > F) continue;

		float crat = (float)(*su) / sum;

		if (rat > crat) continue;
		rat = crat;
		maxw = sum;
		maxs = *su;
			//cout << crat << ":"<< *wa<<":"<<*su<< endl;

	}


#else


	for (size_t a = 0; 100*a*A  <= F; a++)
		for (size_t b = 0; 100*a*A + 100*b*B <= F; b++)
			for (size_t c = 0; 100 * a*A + 100 * b*B + c*C <= F; c++)
				for (size_t d = 0; 100 * a*A + 100 * b*B + c*C + d*D <= F; d++)
				{
					if (a + b == 0) continue;

					int sum_wa = (a*A + b*B)*100;
					int sum_sug = c*C + d*D;
					int sum = sum_wa + sum_sug;
					float crat = (float)(c*C + d*D) / sum;

					if (sum_sug > E*(a*A + b*B))break;
					if (rat > crat) continue;
					rat = crat;
					maxw = sum;
					maxs = sum_sug;
				}
#endif
	cout << maxw << " " << maxs << endl;

	return 0;
}


#endif // C

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    string s; cin >> s;

    vector<ll> white(N, 0), black(N, 0);

    if(s[0] == '#') black[0] = 1;
    else white[0] = 1;

    for(int i=1; i<N; i++){
        if(s[i] == '.'){
            white[i] = white[i-1]+1;
            black[i] = black[i-1];
        }
        else{
            white[i] = white[i-1];
            black[i] = black[i-1]+1;
        }
    }

    ll ans = 10000000;
    for(int i=0; i<N; i++){
        ll tmp = black[i] + (white[N-1]-white[i]);
        ans = min(ans, tmp);
    }
    for(int i=0; i<N; i++){
        if(i == 0){
            ll tmp = white[N-1];
            ans = min(ans, tmp);
        }
        else{
            ll tmp = black[i-1] + (white[N-1]-white[i-1]);
            ans = min(ans, tmp);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3716
import itertools

n = int(input())
l = list(map(int, input().split()))

a = list(itertools.combinations(l, 3))
ans = 0
for i in a:
    tmp = sorted(i)
    if tmp[0] != tmp[1] != tmp[2] and tmp[0]+tmp[1] > tmp[2]:
        ans += 1
print(ans)

Measured memory_bytes: 20612
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
 
const int maxn = 1005;
const int md = 1e9+7;
 
void add(int &a, int b)
{
	a += b;
	if(a>= md) a -= md;
}
 
char s[maxn][maxn];

int dp[maxn][maxn];

int n, m;
 
int solve(int a, int b)
{
	if(a> n || b> m) return 0;
	if(s[a][b] == '#') return 0;
	if(a == n && b == m) return 1;
	if(dp[a][b] != -1) return dp[a][b];
	int tot = solve(a+1, b);
	add(tot, solve(a, b+1));
	return dp[a][b] = tot;
}
 
int main()
{
	memset(dp, -1, sizeof dp);
	scanf("%d %d", &n, &m);
	for(int i = 1; i<= n; i++)
	{
		scanf("%s", s[i]+1);
	}
	printf("%d\n", solve(1, 1));
}

Measured memory_bytes: 5248
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;


int main(void) {
  string S;
  cin >> S;
  map<char, int> m;
  rep(i, S.length()) {
    m[S[i]]++;
  }

  if (S.length() == 1) { 
    cout << "YES" << endl;
    return 0;
  }

  vector<int> v = {m['a'], m['b'], m['c']};
  sort(v.rbegin(), v.rend());
  if (v[0] - v[2] <= 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
ll n;
vector<pii>a;
void get(ll n){
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			int cnt=0;
			while(n%i==0){
				cnt++;
				n/=i;
			}
			a.pb({i,cnt});
		}
	}
	if(n!=1){
		a.pb({n,1});
	}
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
	if(n==1){
    	cout<<0<<endl;
	}
	else{
		get(n);
		int cnt=0;
		for(auto u:a){
			int n=0;
			while((n*(n+1))/2<=u.se){
				n++;
			}
			n--;
			//cout<<n<<endl;
			cnt+=n;
		}
		cout<<cnt;
	}
    return 0;
}


Measured memory_bytes: 3664
inputs = gets.to_i
a = [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]
puts a[inputs - 1]


Measured memory_bytes: 1788
#include <iostream>
#include<vector>
#include<numeric>

using namespace std;

int main() {
    
    int N,in;
    vector<int> takoyakis;
    vector<int> sum;
    
    scanf("%d",&N);
    
    if(N>=2 && N<=50){
        
        for(int i=1;i<=N;++i){
            
            scanf("%d",&in);
            takoyakis.push_back(in);
            
        }
        
        for(int i=0;i<(N*(N-1))/2;++i){
            
           for(int j=i+1;j<takoyakis.size();++j){
               sum.push_back(takoyakis.at(i)*takoyakis.at(j));
           }
        }
    }
    
    cout << accumulate(sum.begin(),sum.end(),0);
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
//char s[2000000];

using namespace std;

#define ll long long
#define pi pair<ll,ll>
 
vector<ll>v[200005];
ll arr[500005];
ll brr[500005];
//char str[2000000]; 
map<char,ll>mp;
//map<char,ll>cnt;
ll digits[13];
vector<string>names;
//vector<ll>cnt;
int main()
{
   ll i,j,k,l,p,q,r,s=1,t,n,money,x,y,solve;
   string str1,str2;
   n=100000;
   cin>>p>>q;
   for(i=1;i<=n;i++)
   {
      l=p*i;
      if(l%q==0)
      {
        cout<<l;
        return 0;	
      }	
   }
  
   	
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

int main() {
    ll a, b, n;
    cin >> n >> a >> b;
    ll ans;
    if((b - a) % 2 == 0) {
        ans = (b - a) / 2;
    } else {
        ll s = a - 1, e = n - b;
        ans = min(s, e) + 1 + (b - a - 1) / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int l, r, d; cin >> l >> r >> d;
	int cnt = 0;
	for( int i = l; i <= r; ++i ){
		if( i % d == 0 ) ++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000000
using namespace std;
using ll=long long;
using ld=long double;
using vs=vector<string>;


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

Measured memory_bytes: 3584
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

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

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val X = sc.next().toLong()
        var i = 100L
        var ans = 0L
        while (i < X) {
            i = (i * 1.01).toLong()
            ans++
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 34288
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

bool check(int x, int y, int h, int w){
	return x < 0 || x >= w || y < 0 || y >= h;
}

int main(){
	int w, h;
	while(cin>>w>>h && w > 0 && h > 0){
		vector<string> v(h);
		rep(i, h) cin>>v[i];
		pii s;
		rep(i, h) rep(j, w) if(v[i][j] == '@') s.fi = i, s.se = j;
		int ans = 0;
		set<pii> used;
		used.insert(s);
		ans++;
		queue<pii> q;
		q.push(s);
		while(!q.empty()){
			pii p = q.front();
			q.pop();

			int x = p.se, y = p.fi;
			rep(i, 4){
				int nx = x + dx[i], ny = y + dy[i];
				if(check(nx, ny, h, w) || used.count({ny, nx}) || v[ny][nx] == '#') continue;
				used.insert({ny, nx});
				q.push({ny, nx});
				ans++;
			}
		}

		cout<<ans<<endl;

	}
}

Measured memory_bytes: 3164
package main

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

func main() {
	sc := NewScanner(os.Stdin)

	a := sc.Int()

	for i := 0; i < 3; i++ {
		sc.Int()
	}

	e := sc.Int()
	k := sc.Int()


	if (e - a) <= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &Scanner{s}
}

func (s *Scanner) UInt() uint64 {
	s.Scan()
	i, e := strconv.ParseUint(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) Int() int {
	return int(s.UInt())
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;

void solve()
{
	int n, m, k;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> k, n -= k;

	cout << max(n,-1);
}
int main()
{
//	int t;
//	cin >> t;
//	while (t-- > 0)
		solve();
}


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

const int N = 610;
const int mod = 1e9 + 7;

typedef long long LL;

int num[N], vis[N], dp[N][N][N];

int main() {
    int n, ct = 0; scanf("%d", &n), n *= 2;
    for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
    for (int i = 1; i <= n; i += 2) {
        int A = num[i] != -1, B = num[i + 1] != -1;
        if (A && B) vis[num[i]] = vis[num[i + 1]] = 2;
        else if (A || B) vis[num[i] + num[i + 1] + 1] = 1;
        else ct++;
    } 
    int tp = n + 1; dp[tp][0][0] = 1;
    for (int i = n; i >= 1; i--) if (vis[i] != 2) {
        tp--; int remain = n - tp;
        for (int j = 0; j <= remain; j++)
            for (int k = 0; j + k <= remain; k++) if (dp[tp + 1][j][k]) {
                if (!vis[i]) {
                    dp[tp][j + 1][k] = (dp[tp][j + 1][k] + dp[tp + 1][j][k]) % mod;
                    if (j) dp[tp][j - 1][k] = (dp[tp][j - 1][k] + dp[tp + 1][j][k]) % mod;
                    if (k) dp[tp][j][k - 1] = (dp[tp][j][k - 1] + (LL)dp[tp + 1][j][k] * k) % mod;
                } else {
                    dp[tp][j][k + 1] = (dp[tp][j][k + 1] + dp[tp + 1][j][k]) % mod;
                    if (j) dp[tp][j - 1][k] = (dp[tp][j - 1][k] + dp[tp + 1][j][k]) % mod;
                }
            }
    }
    int res = dp[tp][0][0];
    for (int i = 1; i <= ct; i++) res = (LL)res * i % mod;
    printf("%d\n", res);
}

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

using namespace std;

long long n, x[200005], y[200005], res, mul, mdl, mur, mdr;
vector<long long> vx;
map<long long, long long> ml, mr;
const long long INF = 1e12 + 7;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
    	cin >> x[i] >> y[i];
    	vx.push_back(x[i]);
    	if (ml.find(x[i]) == ml.end()) {
    		ml[x[i]] = y[i];
    		mr[x[i]] = y[i];
		}
		else {
			ml[x[i]] = min(ml[x[i]], y[i]);
			mr[x[i]] = max(mr[x[i]], y[i]);
		}
	}
	sort(vx.begin(), vx.end());
    res = abs(x[0] - x[1]) + abs(y[0] - y[1]);
    mul = -INF; mdl = -INF; mur = -INF; mdr = -INF;
    for (int i : vx) {
    	mul = max(mul, mr[i] - i);
    	mur = max(mur, mr[i] + i);
    	mdl = max(mdl, -ml[i] - i);
    	mdr = max(mdr, -ml[i] + i);
	}
	for (int i = 0; i < n; i++) {
		long long disa = mul + x[i] - y[i];
		long long disb = mur - x[i] - y[i];
		long long disc = mdl + x[i] + y[i];
		long long disd = mdr - x[i] + y[i];
		res = max(res, max(max(disa, disb), max(disc, disd)));
	}
	cout << res << endl;
}

Measured memory_bytes: 32824
"use strict";
const main = arg => {
  let city = arg.split("\n")[0];
  let monster = arg.split("\n")[1].split(" ").map(n=> n*1);
  let yusya =  arg.split("\n")[2].split(" ").map(n=> n*1);
  let ans = 0;
  for(let i = 0; i < city; i++){
    // まずは左側にあるモンスターを全力で倒す
    let left = Math.min(monster[i],yusya[i]);
    ans += left;
    monster[i] -= left;
    yusya[i] -= left;
    
    // 残った戦力で右を全力で倒す
    let right = Math.min(monster[i+1],yusya[i]);
    ans += right;
    monster[i+1] -= right;
    //yusya[i] -= right;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 32172
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IM
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO

main :: IO ()
main = do
  xs <- BS.getLine
  let v = VU.map (== 'B') $ VU.unfoldrN (BS.length xs) BS.uncons xs
  print $ query (BS.length xs) v

query :: Int -> VU.Vector Bool -> Int
query s v =
  VU.sum $ VU.map fst $ VU.filter (not . snd) $ VU.zip blackCounts v
  where
    blackCounts :: VU.Vector Int
    blackCounts = VU.prescanl' (flip $ \case{ True -> (+1); _ -> id}) 0 v


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll S;
    cin >> S;

    ll x[3],y[3];
    x[0] = 0;
    y[0] = 0;

    x[1] = (S+999999999)/1000000000;
    y[2] = 1000000000;

    x[2] = 1;
    y[1] = (ll)x[1]*y[2]-S;

    printf ("%lld %lld %lld %lld %lld %lld\n", x[0], y[0], x[1], y[1], x[2], y[2] );

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

long long i,j,k,n,m,N,H,W,K,ans,fact[10],temp;

vector<long long> A;

int main()
{
  cin>>N;
  for(i=0;i<N;i++)
  {
    cin>>j;
    A.push_back(j);
  }
  sort(A.begin(),A.end(),greater<long long>());
  
  ans=0;
  ans+=A[0];
  if(N==2)
  {
    cout<<ans;
    return 0;
  }
  
  i=1;
  for(j=2;j<N;)
  {
    ans+=A[i];
    j++;
    if(j==N) break;
    ans+=A[i];
    i++;
    j++;
  }
  
  cout<<ans;
  

}

Measured memory_bytes: 5340
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
map<ll, ll> mp;
vector<vector<ll>> tree;
vector<bool> visited;
vector<ll> counter;
void dfs(ll now, ll parent)
{
    if (visited[now])
        return;
    visited[now] = true;
    counter[now] += counter[parent] + mp[now];
    for(ll i = 0; i < tree[now].size(); i++){
        dfs(tree[now][i],now);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n, q;
    cin >> n >> q;
    tree.resize(n);
    visited.resize(n, false);
    counter.resize(n, 0);
    for (ll i = 0; i < n - 1; i++)
    {
        ll a, b;
        cin >> a >> b;
        --a;
        b--;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }
    for (ll i = 0; i < n; i++)
    {
        mp[i] = 0;
    }
    for (ll i = 0; i < q; i++)
    {
        ll p, x;
        cin >> p >> x;
        mp[p - 1] += x;
    }
    counter[0] = mp[0];
    visited[0] = true;
    for (ll i = 0; i < tree[0].size(); i++)
    {
        dfs(tree[0][i], 0);
    }
    for (ll i = 0; i < n; i++)
    {
        cout << counter[i] << endl;
    }
}

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

using namespace std;

int main()
{
string word,line;
cin >> word;
int i=0;
for(;;){
     cin >> line;
          if(line=="END_OF_TEXT") break;
     else{
          for(int j=0;j<(int)line.size();j++){
          if(line[j]>='A'&&line[j]<='Z') line[j]+=32;
          }
     }
     if(line==word) i++;
     }
cout << i << endl;
return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

ll N, A, B;


int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  cin >> N >> A >> B;
  
  ll answer = min(N*A, B);
  cout << answer << endl;

  return 0;
}



Measured memory_bytes: 256