akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iostream>
typedef long long ll;
using namespace std;
int main()
{
	int ans = 0;
	vector<int>v(5);
	for(int i = 0; i<5; i++){
		cin >> v[i];
		if(v[i] == 0){
			ans = i+1;
		}
	}
	cout << ans;
}

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

using static Input;
using static Util;
class Program
{
    static long[] T;
    static void INPUT()
    {
        var n = NextInt();
        T = new long[n];
        for (int i = 0; i < n; i++)
            T[i] = NextLong();
    }
    static void OUT()
    {
        var dic = new Dictionary<long, int>();
        foreach(var t in T)
        {
            if (dic.ContainsKey(t))
                dic[t]++;
            else
                dic[t] = 1;
        }

        Console.WriteLine(dic.Where(__ => __.Value % 2 == 1).Count());
    }
    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
       // N = 1000003;
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 24272
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	x := ""
	ans := 0
	for i := 0; ; {
		if i+1 == len(s) {
			if x != s[i:i+1] {
				ans++
			}
			break
		} else if i == len(s) {
			break
		}

		if x != s[i:i+1] {
			x = s[i : i+1]
			i++
		} else {
			x = s[i : i+2]
			i += 2
		}
		ans++
	}
	fmt.Println(ans)
}


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

#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;


const int MAX_H=10000;
const int MAX_N=1000;

int H,N;
int a[MAX_N+10];
int b[MAX_N+10]; 



int main()
{

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

    vector<vector<long long>> memo(N+1,vector<long long>(H+1,INF));
    memo[0][0]=0;

    //DPループ
    for(int i=0;i<N;++i){
        for(int j=0;j<=H;++j){
            chmin(memo[i+1][j],memo[i][j]);
            chmin(memo[i+1][min(j+a[i],H)],memo[i+1][j]+b[i]);
        }
    }


    cout<< memo[N][H]<<endl;
    return 0;
}

Measured memory_bytes: 78592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double h = sc.nextDouble();
		double m = sc.nextDouble();

		double longAngle = m * 6;
		double shortAngle = 30 * h + m * 0.5;

		double diff = 0;
		if (longAngle < shortAngle) {
			diff = shortAngle - longAngle;
		} else {
			diff = longAngle - shortAngle;
		}

		double x = Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(diff));

		System.out.println(Math.sqrt(x));


		sc.close();
	}

}


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

#define fi first
#define se second

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

using namespace std;

int n, k;
int a[N];
long long s[N];
long long A[N], B[N];

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n >> k;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                s[i] = s[i - 1] + a[i];
                A[i] = A[i - 1] + max(a[i], 0);
        }
        for(int i = n; i >= 1; i--){
                B[i] = B[i + 1] + max(a[i], 0);
        }
        long long res = 0;
        for(int i = 1; i + k - 1 <= n; i++){
                res = max(res, A[i - 1] + B[i + k] + max(0ll, s[i + k - 1] - s[i - 1]));
        }
        cout << res << "\n";
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dp[1010101][2];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int ans = 0;
    //reverse(S.begin(), S.end());
    int N = S.size();
    REP(i,1010101) dp[i][0] = dp[i][1] = INF;
    dp[0][0] = 0;
    int a = 0;
    REP(i,N){
        a = S[i] - '0';
        //cout << dp[i+1][0] << " " << dp[i+1][1] << endl;
        chmin(dp[i+1][0], min(dp[i][0], dp[i][1]) + a);
        chmin(dp[i+1][1], min(dp[i][0] + 11 - a, dp[i][1] + 9 - a));
        //cout << dp[i+1][0] << " " << dp[i+1][1] << endl;
    }
    //cout << a << endl;
    //dp[N+1][0] = min(dp[N-1][0] + a, dp[N-1][1] + a + 1);
    //dp[N+1][1] = min(dp[N-1][0] + 10 - a, dp[N-1][1] + 9 - a);
    cout << min(dp[N][0], dp[N][1]) << endl;
    //cout << dp[N+1][0] << " " << dp[N+1][1] << endl;
}


Measured memory_bytes: 9244
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	
	long long int n,max = 1000000000000;
	cin >> n;

	for (long long int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			if (i + n / i < max) {
				max = i + n / i;
			}
		}
		
	}

	cout << max - 2 << endl;
	

	return 0;
}

Measured memory_bytes: 256
h,n = map(int,input().split())

ab_input = [list(map(int,input().split())) for i in range(n)]

max_d = max(a for a,b in ab_input)

dp =[0]*(h+max_d)
for i in range(1,h+max_d):#dp[i-a]でi-a<0のとき影響がでないようにmax_dを足す
    dp[i]=min(dp[i-a]+b for a,b in ab_input)#モンスターの体力を i 減らすため消耗する魔力の最小値

print(dp[h])

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


int main() {
        int n;
        cin >> n;
        string s;
        bool four = false;
        for (int i = 0; i < n; ++i) {
                cin >> s;
                if (s == "Y") {
                        four = true;
                }
        }
        if (four) {
                cout << "Four" << endl;
        } else {
                cout << "Three" << endl;
        }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_H 10
#define MAX_W 10
 
struct Dice{
    int tmp,d[6];
    Dice(){
	for(int i = 0 ; i < 6 ; i++){
	    d[i] = i;
	}
    }
    void rollN(){
	tmp = d[0];
	d[0] = d[1];
	d[1] = d[5];
	d[5] = d[4];
	d[4] = tmp;
    }
    void rollE(){
	tmp = d[0];
	d[0] = d[3];
	d[3] = d[5];
	d[5] = d[2];
	d[2] = tmp;
    }
    void rollS(){
	tmp = d[0];
	d[0] = d[4];
	d[4] = d[5];
	d[5] = d[1];
	d[1] = tmp;
    }
    void rollW(){
	tmp = d[0];
	d[0] = d[2];
	d[2] = d[5];
	d[5] = d[3];
	d[3] = tmp;
    }
};
 
struct State{
    int cost,x,y;
    Dice d;
    bool operator < (const State &s)const{
	return cost > s.cost;
    }
};
 
int main(){
    int H,W;
    while(cin >> H >> W, H){
	int field[MAX_H][MAX_W];
	int sx,sy,gx,gy;
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W ; j++){
		cin >> field[i][j];
	    }
	}
	cin >> sy >> sx >> gy >> gx;
	int cost[MAX_H][MAX_W][6][6][6];
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W ; j++){
		for(int k = 0 ; k < 6 ; k++){
		    for(int l = 0 ; l < 6 ; l++){
			for(int m = 0 ; m < 6 ; m++){
			    cost[i][j][k][l][m] = 1e9;
			}
		    }
		}
	    }
	}
	Dice die;
	cost[sy][sx][die.d[0]][die.d[1]][die.d[2]] = 0;
	priority_queue<State> Q;
	Q.push((State){0,sx,sy,die});
	const int dx[] = {-1,0,1,0};
	const int dy[] = {0,-1,0,1};
	while(!Q.empty()){
	    State s = Q.top(); Q.pop();
	    int x = s.x, y = s.y;
	    int ncost = cost[y][x][s.d.d[0]][s.d.d[1]][s.d.d[2]];
	    if(ncost < s.cost){ continue; }
	    if(x == gx && y == gy){
		cout << s.cost << endl;
		break;
	    }
	    for(int i = 0 ; i < 4 ; i++){
		int nx = x + dx[i], ny = y + dy[i];
		Dice d = s.d;
		if(0 > nx || nx >= W || 0 > ny || ny >= H){
		    continue;
		}
		switch(i){
		case 0:
		    d.rollW();
		    break;
		case 1:
		    d.rollN();
		    break;
		case 2:
		    d.rollE();
		    break;
		case 3:
		    d.rollS();
		    break;
		}
		int p = (d.d[5]+1)*field[ny][nx];
		if(s.cost + p < cost[ny][nx][d.d[0]][d.d[1]][d.d[2]]){
		    cost[ny][nx][d.d[0]][d.d[1]][d.d[2]] = s.cost + p;
		    Q.push((State){cost[ny][nx][d.d[0]][d.d[1]][d.d[2]],nx,ny,d});
		}
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 3204
#include <stdio.h>

int main(void);

int main(void)
{
    int n, i, j ,k, ln;
    int b, f, r, v;//与えられる情報
    int kousya[5][4][11];//棟、階、部屋を格納する配列

    for(b = 0; b <= 4; b++){
        for(f = 0; f <= 3; f++){
            for(r = 0; r <= 10; r++){
                kousya[b][f][r] = 0;
            }
        }
    }

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%c", &ln);//前の行の改行を読み込む
        scanf("%d %d %d %d", &b, &f, &r, &v);
        kousya[b][f][r] += v;//入居者情報を格納
    }

    for(b = 1; b <= 4; b++){
        for(f = 1; f <= 3; f++){
            for(r = 1; r <= 10; r++){
                printf(" %d", kousya[b][f][r]);
            }
            printf("\n");
        }
        if(b != 4){
            printf("####################\n");
        }    
    }
    return(0);
}


Measured memory_bytes: 2040
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
import re
sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    K = 'keyence'
    if S == K:
        return 'YES'
    if re.fullmatch('[a-z]+'+K, S):
        return 'YES'
    if re.fullmatch(K+'[a-z]+', S):
        return 'YES'

    for i in range(len(K)):
        if re.fullmatch(K[:i]+'[a-z]+'+K[i:], S):
            return 'YES'

    return 'NO'


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6848
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 0 && 0 <= b) {
		cout << "Zero" << endl;
	} else {
		bool neg = false;
		if (a < 0) {
			int bb = min(b, -1);
			neg = (bb - a) % 2 == 0;
		}
		cout << (neg ? "Negative" : "Positive") << endl;
	}
}


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

using namespace std;

int main ()
{
  long long h;
  cin >> h;
  long long mnum=1;
  long long ans=0;
  while(h>1){
    h/=2;
    ans += mnum;
    mnum *= 2;
  }
  ans+=mnum;
  cout << ans <<endl;
 return 0;
}

Measured memory_bytes: 256
import itertools
n,m,r = map(int,input().split())
ri = [int(i) for i in input().split()]
#abc = [[int(i) for i in input().split()] for j in range(m)]

mat=[[10**18 for i in range(n+1)] for j in range(n+1)]

for i in range(n+1):
	mat[i][i]=0

for i in range(m):
	a,b,c=map(int,input().split())
	mat[a][b] = c
	mat[b][a] = c

for i in range(1,n+1):
	for x in range(1,n+1):
		for y in range(1,n+1):
			mat[x][y] = min(mat[x][y], mat[x][i] + mat[i][y])
            
            
permutations = list(itertools.permutations(range(1, r+1)))
#p = permutations.index(p)

#print(mat)
#exit()
ans = 10**18

for i in range(len(permutations)):
    tmp = 0
    for j in range(r-1):
        #print(permutations[i][j],permutations[i][j+1])
        tmp += mat[ri[permutations[i][j]-1]][ri[permutations[i][j+1]-1]]
    ans = min(ans,tmp)
    #print(permutations[i][0])
print(ans)

Measured memory_bytes: 55000
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int n, m;
  cin >> n >> m;
  int mini = -inf;
  int maxi = inf;
  rep(i,m) {
    int l, r;
    cin >> l >> r;
    mini = max(mini, l);
    maxi = min(maxi, r);
  }
  cout << max(maxi-mini+1, 0) << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
using Grid = vector<vector<char>>;
#define vc vector<char>
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    vl r(A);
    vl g(B);
    vl n(C);
    rep(i,A)cin>>r[i];
    rep(i,B)cin>>g[i];
    rep(i,C)cin>>n[i];
    priority_queue<ll,vl,greater<ll>> q;
    sort(all(r));
    sort(all(g));
    sort(all(n));
    reverse(all(r));
    reverse(all(g));
    reverse(all(n));
    rep(i,X){
        ll a=r[i];
        q.push(a);
    }
    rep(i,Y){
        ll a=g[i];
        q.push(a);
    }
    ll count=0;
    while(q.top()<n[count]){
        q.pop();
        ll a=n[count];
        q.push(a);
        count++;
    }
    ll Ans=0;
    while(!q.empty()){
        Ans+=q.top();
        q.pop();
    }
    cout<<Ans<<endl;
}

Measured memory_bytes: 4724
# coding: utf-8
# Your code here!

n=int(input())
a=[]
for _ in range(n):
    a.append(int(input()))

a.sort()

#print(a)    


ans=0

if n%2==0:
    for i in range(n//2-1):
        ans += 2*(a[n-1-i]-a[i])
    ans += a[n//2] - a[n//2-1]

if n%2==1:
    for i in range(n//2-1):
        ans += 2*(a[n-1-i]-a[i])
    ans += max(a[n//2+1] + a[n//2] - 2*a[n//2-1], 2*a[n//2+1] - a[n//2] - a[n//2-1])

print(ans)

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

int gridsearch(vector<vector<int>> m, int row, int col){
    int cnt = 0;
    for (int i = -1; i <= 1; i++){
        for (int j = -1; j <= 1; j++){
            if ((i != 0) || (j != 0)){
                cnt += m.at(row + i).at(col + j);
            }
        }
    }

    return cnt;
}


int main(){
    int h,w;
    cin >> h >> w;
    string s;
    vector<vector<int>> F;
    F.resize(h+2);
    for (int i = 0; i < h + 2; i++){
        F.at(i).resize(w+2);
        for (int j = 0; j < w + 2; j++){
            F.at(i).at(j) = {};
        }
    }
    /*二次元配列での初期化
	int a, b;
	vector<vector<int> > vc(a, vector<int>(b)); // vc[a][b]と同じ
    三次元の場合
    int a, b, c;
	vector<vector<vector<int> > > vc(a, vector<vector<int> >(b, vector<int>(c))); // vc[a][b][c]と同じ
    */

    char c;
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            cin >> c;
            if (c == '#') ++F.at(i).at(j);
        }
    }

    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            if (F.at(i).at(j) == 0){
                cout << gridsearch(F, i, j);
            }
            else{
                cout << '#';
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())


void Add(ll &a, ll b){
    a=(a+b)%mod;
    return;
}

void Pro(ll &a, ll b){
    a=(a*b)%mod;
    return;
}

ll H,W; 
vector<P> d;

vec ans;
void init(){
    cin>>H>>W;
    rep(i,H){
        ll x,y; cin>>x>>y;
        x--; y--;
        d.pb(mp(x,y));
        ans.pb(-1);
    }
}

void Solve(){
    set<P> x;
    multiset<ll> y;
    rep(i,W) {
        P f=mp(i,i);
        x.insert(f);
        y.insert(0);
    }
    rep(i,H){
        ll Biggest=-INF;
        for(auto itr=x.lower_bound(mp(d[i].first,-INF));itr!=x.end();){
            ll R=(*itr).first, L=(*itr).second;
           // cout<<i<<':'<<R<<' '<<L<<endl;
            if(R>d[i].second+1) break;
            Biggest=max(Biggest,L);
            auto itr1=y.lower_bound(R-L);
            y.erase(itr1);
            itr=x.erase(itr);
        }
        if(Biggest!=-INF) if(d[i].second!=W-1) {x.insert(mp(d[i].second+1,Biggest)); y.insert(d[i].second+1-Biggest);}
        if(y.size()) ans[i]=*(y.begin());
        else break;
    }
    rep(i,H) if(ans[i]>=0) ans[i]+=(i+1);
    
}

int main(){
    init();
    Solve();
    rep(i,H) cout<<ans[i]<<endl;
}




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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin >> A.at(i);
    }
    int flag=1;
    for(int i=0;i<n;i++){
        if(A.at(i)%2==0){
            if(A.at(i)%3!=0 && A.at(i)%5!=0){
                flag=0;
                break;
            }
        }
    }
    if(flag){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

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

ll f(ll b, ll n) { return n < b ? n : f(b, n / b) + n % b; }

ll solve(ll n, ll s) {
    if (n < s) {
        return -1;
    }

    // keta = 1
    if (n == s) {
        return n + 1;
    }

    // keta > 2
    for (ll b = 2; b * b <= n; b++) {
        if (f(b, n) == s) {
            return b;
        }
    }

    // keta = 2
    ll ans = -1;
    for (ll p = 1; p * p < n; p++) {
        ll b = 1 + (n - s) / p;
        if (b >= 2 && f(b, n) == s) {
            ans = b;
        }
    }

    return ans;
}

int main() {
    ll n, s;
    cin >> n >> s;
    cout << solve(n, s) << endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>	
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second 
#define mod 1000000007     
using namespace std;
const int N = 3e5 + 5;
vector<vector<int>> g;
int ans[N];

void bfs(int v, int n){
	int dist[n + 1] = {0};
	memset(dist, 1, sizeof dist);
	dist[v] = 0;
	queue<int> q;
	q.push(v);
	while(!q.empty()){
		int next = q.front();
		q.pop();
		for(auto to: g[next]){
			if(dist[to] > dist[next] + 1){
				dist[to] = dist[next] + 1;
				q.push(to);
			}
		}
	}
	for(int i = 1; i <= n; i++){
		ans[dist[i]]++;
	}
}
main()
{	
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n, x, y;
	cin >> n >> x >> y;
	g.resize(n + 1);
	for(int i = 1; i < n; i++){
		g[i].pb(i + 1);
		g[i + 1].pb(i);
	}
	g[x].pb(y);
	g[y].pb(x);
	for(int i = 1; i <= n; i++){
		bfs(i, n);
	}
	for(int i = 1; i <= n - 1; i++){
		cout << ans[i] / 2 << endl;
	}
}

Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var: ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut sp: [(String, i64); n],
    }
    let mut ans = Vec::new();
    for (i, v) in sp.into_iter().enumerate() {
        ans.push((v.0, -v.1, i + 1));
    }
    ans.sort();
    for a in ans {
        println!("{}", a.2);
    }
}

Measured memory_bytes: 4352
N=int(input())
S=[input() for i in range(N)]
D=dict()
k=0
for i in range(N):
    if S[i] in D:
        D[S[i]]+=1
    else:
        D[S[i]]=1
    k=max(D[S[i]],k)
X=[]
for i in D:
    if D[i]==k:
        X.append(i)
for line in sorted(X):
    print(line)
#私はdictのmaxの仕様を勘違いしてしまいました。

Measured memory_bytes: 99024
#coding:utf-8

L = list(map(int,input().split()))
l =[]
cnt = 0

for i in range(int(L[0]+1)):
      l = [int(x) for x in list(str(i))]
      S = sum(l)
      if L[1] <= S <= L[2]:
              cnt += i

print(cnt)


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

int gcd(int x, int y){
    int r;
    if(x<y)swap(x,y);
    
    while(y > 0){
        r = x%y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    
    return 0;
}


Measured memory_bytes: 3076
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	string S;

	cin >> S;

	bool ok=true;
	for(int i=0;i<(int)S.size();i++)
	{
		if(i%2==0 && S[i]=='L')ok=false;
		if(i%2==1 && S[i]=='R')ok=false;
	}

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



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToList();
			var W = firstLine[0];
			var a = firstLine[1];
			var b = firstLine[2];
			
			if(a + W < b)
			{
				Console.WriteLine(b - (a + W));
			}
			else if(b + W < a)
			{
				Console.WriteLine(a - (b + W));
			}
			else
			{
				Console.WriteLine(0);
			}
        }
	}
}


Measured memory_bytes: 11220
N = int(input())
h = [tuple(map(int,input().split())) for i in range(N)]
inf = float('inf')
DP = [[inf for i in range(3)] for i in range(N)]
DP[0][0]=h[0][0]
DP[0][1]=h[0][1]
DP[0][2]=h[0][2]

for i in range(N-1):
    DP[i+1][0]=h[i+1][0]+max(DP[i][1],DP[i][2])
    DP[i+1][1]=h[i+1][1]+max(DP[i][0],DP[i][2])
    DP[i+1][2]=h[i+1][2]+max(DP[i][0],DP[i][1])

print(max(DP[-1]))

Measured memory_bytes: 41772
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
string s[10005];
int main(){
	int n;
	cin>>n;
	long long cnt=0,ct1=0,ct2=0,ct3=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=1;j<s[i].size();j++){
			if(s[i][j]=='B'&&s[i][j-1]=='A') cnt++;
//			cout<<s[i][j-1]<<" "<<s[i][j]<<endl;
		}
		if(s[i][0]=='B'&&s[i][(int)s[i].size()-1]=='A') ct3++;
		else if(s[i][0]=='B') ct2++;
		else if(s[i][(int)s[i].size()-1]=='A') ct1++;
	}
	if(ct1>ct2) swap(ct1,ct2);
	cout<<cnt+min(ct1,ct2)+ct3-(ct3!=0&&ct1==0)+(ct3!=0&&ct1==0&&ct2!=0);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=2e5,M=1e9+7;
int m,k;
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);    
    cin>>m>>k;
    int tot=1<<m;
    if(k>=tot)cout<<-1;
    else if(m==1){
        if(k==0)cout<<"0 0 1 1";
        else cout<<-1;
    }
    else{
        vector<int>v;
        for(int i=0;i<tot;i++){
            if(i!=k)v.pb(i);
        }
        v.pb(k);
        for(int i=tot-1;i>=0;i--){
            if(i!=k)v.pb(i);
        }
        v.pb(k);
        for(int u:v){
            cout<<u<<" ";
        }
    }
    
}

Measured memory_bytes: 2932
h,w=map(int,input().split())
n=int(input())
l=list(map(int,input().split()))
l1=[]
l2=[]
ans=[[0]*w for _ in range(h)]
for i in range(n):
    for j in range(l[i]):
        l1.append(i+1)

flag=1
for i in range(h):
    for j in range(w):
        if flag==1:
            l2.append([i,j])
        else:
            l2.append([i,w-j-1])
    flag*=(-1)
for i in range(h*w):
        ans[l2[i][0]][l2[i][1]]=l1[i]
for i in ans:
    print(*i)

Measured memory_bytes: 4984
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

int main() {
	LL n; cin >> n;
	VL a(n); rep(i, n)cin >> a[i];

	LL c1 = 0, c2 = 0, sum = 0;
	rep(i, n) {
		sum += a[i];
		if (i % 2 == 0) {	// +
			if (sum <= 0) { c1 += abs(1 - sum); sum = 1; }
		}
		else {				// -
			if (sum >= 0) { c1 += abs(-1 - sum); sum = -1; }
		}
	}
	sum = 0;
	rep(i, n) {
		sum += a[i];
		if (i % 2 == 0) {	// +
			if (sum >= 0) { c2 += abs(-1 - sum); sum = -1; }
		}
		else {				// -
			if (sum <= 0) { c2 += abs(1 - sum); sum = 1; }
		}
	}
	Cout(min(c1, c2));
}

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

int main()
{
    string s;
    cin >> s;
    char head = s[0];
    int cnt = 0;
    if (head == '0')
    {
        for (int i = 0; i < s.size(); i++)
        {
            if (!((i % 2 == 0 && s[i] == '0') || (i % 2 == 1 && s[i] == '1')))
                cnt++;
        }
    }
    else
    {
        for (int i = 0; i < s.size(); i++)
        {
            if (!((i % 2 == 0 && s[i] == '1') || (i % 2 == 1 && s[i] == '0')))
                cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
b,i,j;
main(n){
  float a,x;
  char t[9],l[9];
  for(;;)
    {
      for(i=0;i<9;i++)
	t[i]=l[i]='0';
      scanf("%f",&a);
      if(a<0)break;
      b=a;
      for(i=0;b;)
	t[i++]='0'+b%2,b/=2;
      b=a;
      a-=b;
      x=0.5;
      for(j=0;a>0.0 && j<5;j++)
	{
	  
	  if(a-x>=0)
	    {
	      l[j]='1';
	      a-=x;
	    }
	  else
	    {
	      l[j]='0';
	    }
	  x/=2;
	}
      if(j>4)
	puts("NA");
      else
	{
	  for(b=0;b++<8-i;)
	    printf("0");
	  for(;i;)
	    printf("%c",t[--i]);
	  printf(".");
	  for(;j>i;)
	    printf("%c",l[i++]);
	  for(;4>i++;)
	    printf("0");
	  puts("");
	}
      

    }
  exit(0);
}

Measured memory_bytes: 0
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

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


Measured memory_bytes: 256
f = false
while gets
  a,b = $_.split.map(&:to_i)
  puts if f && !(a == 0 && b == 0)
  f = true
  break if a == 0 and b == 0
  flag = false
  while a != b + 1
    if (a % 4 == 0) && (!(a % 100 == 0) || (a % 400 == 0))
      p a
      flag = true
    end
    a += 1
  end
  puts "NA" if !flag
end

Measured memory_bytes: 9156
#include<iostream>
using namespace std;
   
int main(){
  int m,f,b;
     
  cin >> m >> f >> b;
     
  if(b-m > f){
    cout << "NA" << endl;
  }else{
    cout << max(b-m, 0) << endl;
  }
  
  return 0;
}


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

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

    ll ans;
    if (M >= 2*N) ans = N + (M-2*N)/4;
    else ans = M/2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void bubbleSort(int *arr, int arrsize, int *count) {
  int tmp,flag = 1;
  while (flag) {
    flag = 0;
    for (int i = arrsize - 1; i > 0; i--) {
      if (arr[i] < arr[i-1]) {
        tmp = arr[i];
        arr[i] = arr[i-1];
        arr[i-1] = tmp;
        *count += 1;
        flag = 1;
      }
    }
  }
}
int main() {
  int n,count = 0;
  scanf("%d", &n);
  int arr[n];
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  bubbleSort(arr,n,&count);
  for (int i = 0; i < n; i++) {
    if (i == n-1) printf("%d", arr[i]);
    else  printf("%d ", arr[i]);
  }
  printf("\n%d\n", count);
  return 0;
}



Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        int m = Integer.parseInt(s.substring(5, 7));
        if(m <= 4){
            System.out.println("Heisei");
        }else{
            System.out.println("TBD");  
        }
    }
}

Measured memory_bytes: 21972
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
 */
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int[] a=new int[6];
        for (int i = 0; i < 6; i++) {
            a[i]=sc.nextInt();
        }
        String s=sc.next();
        dice1.init(a);
        for (int i = 0; i < s.length(); i++) {
            dice1.roll(s.charAt(i));
        }
        out.println(dice1.men[0]);
    }
    static class dice1{
        static int[] men=new int[6];
        static void init(int[] a){
            for (int i = 0; i < 6; i++) {
                men[i]=a[i];
            }
        }
        static void roll(char c){
            int t=men[0];
            switch (c) {
                case 'S':
                    men[0]=men[4];
                    men[4]=men[5];
                    men[5]=men[1];
                    men[1]=t;
                    break;
                case 'E':
                    men[0]=men[3];
                    men[3]=men[5];
                    men[5]=men[2];
                    men[2]=t;
                    break;
                case 'W':
                    men[0]=men[2];
                    men[2]=men[5];
                    men[5]=men[3];
                    men[3]=t;
                    break;
                case 'N':
                    men[0]=men[1];
                    men[1]=men[5];
                    men[5]=men[4];
                    men[4]=t;
                    break;
                    default:
                        break;
            }
        }
    }
}


Measured memory_bytes: 26320
#include <iostream>
//#include <fstream>
#include <cstdio>
//#include <cstdlib>
//#include <cmath>
#include <algorithm>
//#include <array>
//#include <bitset>
//#include <complex>
//#include <deque>
//#include <functional>
//#include <iomanip>
//#include <iterator>
//#include <limits>
//#include <list>
//#include <map>
//#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <stack>
//#include <string>
//#include <utility>
//#include <valarray>
#include <vector>
//#include <forward_list>
//#include <random>
//#include <tuple>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//#define Mod 1000000007
#define Mod 924844033
#define INF 1073741789
//#define swap(a,b) a^=b^=a^=b

int GCD(int n, int m)
{
	if (m == 0) return n;
	return GCD(m, n % m);
}
int N, K;
ll** comb;
ll* fact;

ll* chain(int n)
{
	auto p = new ll[n / 2 + 1];
	for (int k = 0; k <= n / 2; k++) p[k] = comb[n - k][k];
	return p;
}
ll* conv(ll* a, ll* b, int& p, int q)
{
	auto c = new ll[p + q - 1];
	for (int i = 0; i < p + q - 1; i++) c[i] = 0;
	for (int i = 0; i < p; i++)
		for (int j = 0; j < q; j++)
			c[i + j] = (c[i + j] + a[i] * b[j] % Mod) % Mod;
	p += q - 1;
	return c;
}
ll* pow(ll* a, int& l, int n)
{
	auto p = new ll[1]{ 1 };
	int lenp = 1;
	auto x = a;
	int lenx = l;
	while (n > 0)
	{
		if ((n & 1) == 1) p = conv(p, x, lenp, lenx);
		n >>= 1;
		x = conv(x, x, lenx, lenx);
	}
	l = lenp;
	return p;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> K;
	int M = N / K + 10;
	comb = new ll*[M];
	for (int i = 0; i < M; i++) { comb[i] = new ll[M]; comb[i][0] = 1; for (int j = 1; j < M; j++)comb[i][j] = 0; }
	for (int i = 1; i < M; i++) for (int j = 1; j <= i; j++) comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % Mod;
	int len = (N / K) / 2 + 1, len2 = (N / K + 1) / 2 + 1;
	auto p = pow(chain(N / K), len, 2 * (K - N % K));
	auto q = pow(chain(N / K + 1), len2, 2 * (N % K));
	p = conv(p, q, len, len2);
	fact = new ll[N + 1];
	fact[0] = 1;
	for (int i = 1; i <= N; i++) fact[i] = (i * fact[i - 1]) % Mod;
	ll ans = 0, s = 1;
	for (int i = 0; i < min(N + 1, len); i++)
	{
		ans = (ans + s * fact[N - i] * p[i] % Mod) % Mod;
		s *= -1;
	}
	if (ans < 0) ans += Mod;
	cout << ans << endl;
	cout.flush();
	return 0;
}


Measured memory_bytes: 32000
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}




int main() {

  long n, m, c;
  // string a, b, c;
  // string s[3];

  cin >> n ;
  cin >> m;
  cin >> c ;
  // cin >> c ;

  vector<vector<long>> a(n, vector<long>(m, 0));
  vector<long> b(m);
  for (int j = 0; j < m; ++j) {
    cin >> b[j];
  }

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

  long ans = 0;


  for (int i = 0; i < n; ++i){
    long tmp =0;
    for (int j = 0; j < m; ++j) {
      tmp += a[i][j] * b[j];
    }
    tmp += c;
    if (tmp>0)ans++;
  }



  cout << ans;



}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}

map<ll,ll> prime_fact(ll num) {
    ll now = 2;
    map<ll,ll> divisors; 
    while(now*now<=num) {
        while(num%now==0) {
            divisors[now]++;
            num /= now;
        }
        now++;
    }
    if (num != 1) {
        divisors[num]++;
    }
    return divisors;
}

vector<ll> divs(ll num) {
    ll now = 1;
    vector<ll> divs;
    while(now*now<=num) {
        if (num % now==0) {
            divs.push_back(now);
            if (now*now!=num){
                divs.push_back(num/now);
            }
        }
        now++;
    }
    return divs;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> divs1 = divs(n-1),divs2=divs(n);
    ll res = divs1.size()-1;
    for(auto x:divs2) {
        if (x==1) continue;
        ll tmp = n;
        while(tmp%x==0) {
            tmp /= x;
        }
        if (tmp%x==1) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int n, a[100005]; 
int dp[100005]; 
 
int func(int ind) {
	if(ind==(n-1)) return 0; 
	if(ind>=n) return INT_MAX;
	if (dp[ind] != -1) return dp[ind]; 
	int left = abs(a[ind]-a[ind+1]) + func(ind+1);
	int right = INT_MAX; 
	if(ind+2<n) {
		right = abs(a[ind] - a[ind+2]) + func(ind+2); 
	}
	return dp[ind] = min(left,right);
}
signed main() 
{	
	cin >> n;
	memset(dp, -1, sizeof dp); 
	for(int i = 0;i<n;i++) 
	{
		cin >> a[i]; 
	}
	cout << func(0); 
}

Measured memory_bytes: 9852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s, 0, sizeof(s))
const int mod = 100000007;
const int maxn = 1000000;
const int inf = 0x3f3f3f3f;
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int now = a * n;
    if (now > b)
        cout << b << '\n';
    else
        cout << now << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

long long GCD(long long i,long long j){
	long long alt;
	while(j>0){
		alt=j;
		j=i%j;
		i=alt;
	}
	return i;
}

int main(){
	int a[3],m[3];
	while(cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2],a[0]||a[1]||a[2]||m[0]||m[1]||m[2]){
		int dt[3]={1,1,1};
		long long cnt[3]={0,0,0};
		rep(i,3){
			do{
				dt[i]=a[i]*dt[i]%m[i];
				cnt[i]++;
			}while(dt[i]!=1);
		}
		long long ans,gcd,lcm,lcm2;
		gcd=GCD(cnt[0],cnt[1]);
		lcm=gcd*(cnt[0]/gcd)*(cnt[1]/gcd);
		gcd=GCD(lcm,cnt[2]);
		lcm2=gcd*(lcm/gcd)*(cnt[2]/gcd);
		cout<<lcm2<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    int N, M;
    cin >> N >> M;

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

    vector<pair<int, ll>> BC(M);
    int tmp_B;
    ll  tmp_C;
    for(int i = 0; i < M; i++){
        cin >> tmp_B >> tmp_C;
        BC[i] = make_pair(tmp_B, tmp_C);
    }

    sort(A.begin(), A.end(), greater<ll>());

    sort(BC.begin(), BC.end(), [&](pair<int, ll> x, pair<int, ll> y){
        return x.second > y.second;
    });

    int num_card = 0;
    ll ans = 0;

    int ind_n = 0;
    int ind_m = 0;
    int add_card = 0;
    bool stop = true;
    while(num_card < N){

        if(ind_m < M && (A[ind_n] < BC[ind_m].second)){
            add_card = min(N-num_card, BC[ind_m].first);
            num_card += add_card;
            ans += add_card * BC[ind_m].second;
            ind_m++;
        }else{
            ans += A[ind_n];
            num_card++;
            ind_n++;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,count =0;
    float sum = 0;
    cin >> n;
    vector<int> data;
    
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        data.push_back(k);
        sum += k;
    }

    int ave = round(sum / n);
    
    for(int i=0;i<n;i++){
        count += ((data.at(i) - ave) * (data.at(i) -ave));
    }
    
    cout << count <<endl;
}

Measured memory_bytes: 3676
def should_buy_ab(a,b,c):
    return 2 * c <= a + b


def solve(a,b,c,x,y):
    paid = 0

    if should_buy_ab(a,b,c):
        common = min(x, y)
        paid += (common * 2 * c)
        x -= common
        y -= common

        if x > 0:
            return paid + x * min(a, 2 * c)
        else:
            assert y >= 0
            return paid + y * min(b, 2 * c)

    paid += x * a
    paid += y * b

    return paid


a, b, c, x, y = map(int, raw_input().split())
print solve(a,b,c,x,y)

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


int main(int argc, const char** argv) {
    string s;
    cin>>s;
    int m = 0;
    for(int i=0;i<s.size();i++){
        m+=s[i]-'0';
        if(m>=9)
            m-=9;
    }
    if(m)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
	int N, K;
	vector<int>H;
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		int h; cin >> h;
		H.push_back(h);
	}
	sort(H.begin(), H.end());
	int ans = INF;
	for (int i = 0; i <= N - K; ++i) {
		int A = H[i + K-1] - H[i];
		ans = min(ans, A);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n;
long double d1,x;
int main(){
    cin>>n>>d1>>x;
    d1=(d1+(d1+(2*n-1)*x))/2.0;
    x=0;
    long double ans=0;
    for(int i=1;i<=n;i++) ans+=(n+1)/(long double)(i+1);
    printf("%.10lf\n",(double)(ans*d1));
    return 0;
}

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

int search(int key, vector<int> s){
    int n = s.size();
    int left = 0;
    int right = n;
    int mid;
    while(left<right){
        mid = (left+right)/2;
        if(key==s.at(mid)) return 1;
        else if(key > s.at(mid)) left = mid+1;
        else right = mid;
    }
    return 0;
}
int main(){
    int n,m,i,j,t,c;
    c=0;//answer
    cin >> n;
    vector<int> s(n);//入力
    for(i=0;i<n;i++) cin >> s.at(i);
    cin >> m;
    for(i=0;i<m;i++){
        cin >> t;
        c += search(t,s);
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 3548