akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, m; cin >> n >> m;
    vint a(m); vin(a);
    print(max(-1, n - accumulate(all(a), 0)));

    return 0;
}



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

#define gOdSpEeD ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0)
#define Int long long
#define all(x) x.begin(), x.end()
#define el '\n'
#define ints unsigned
#define elif else if
#define test int t; cin>>t; while(t--)

using namespace std;

int main () {
    gOdSpEeD;
    // string s,t;cin>>s>>t;
    double d,t,s;cin>>d>>t>>s;
    if(((double)d/s)<=t) cout << "Yes" << endl;
    else cout << "No"<<endl;
      //bsearch with edu1st
     //pangram thing
    //science actually
    return 0;
}


Measured memory_bytes: 3736
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func f(n int) []int {
	ret := make([]int, n+1)
	for x := 1; x*x < n; x++ {
		xx := x * x
		for y := 1; y*y < n; y++ {
			yy := y * y
			xy := x * y
			for z := 1; z*z < n; z++ {
				zz := z * z
				xz := z * x
				yz := z * y
				tot := xx + yy + zz + xy + xz + yz
				if tot <= n {
					ret[tot]++
				}
			}
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	ans := f(N)
	for i := 1; i <= N; i++ {
		out(ans[i])
	}
}


Measured memory_bytes: 1924
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define bg begin()
#define ed end()
#define fi first()
#define se second()
using namespace std;
using ll = long long;
using vint = vector<int>;
using pint = pair<int,int>;
using vpint = vector<pint>;
template <typename T>
T sq(T x){
  return x * x;
}
ll mod = 1e9 + 7;

signed main (){
  string s;cin >> s;
  cout << s.at(0) << s.size() - 2 << s.at(s.size()-1) << endl;
    return 0;
}


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

int main(){
	int mayors[50]{0};
	vector<int> ansvec;

	for(;;){
		int n, p;
		cin >> n >> p;
		if (n == 0) break;

		for (int i = 0; i < n; i++) mayors[i] = 0;
		int bowlp = p;
		int turn = 0;
		for(;;){
			if (bowlp == 1 && mayors[turn] == p - 1) break;
			else if (bowlp == 0){
				bowlp += mayors[turn];
				mayors[turn] = 0;
			}
			else{
				mayors[turn]++;
				bowlp--;
			}

			if (turn == n - 1) turn = 0;
			else turn++;
		}
		ansvec.push_back(turn);
	}

	for (int ans : ansvec){
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll N,i,k;
  cin >> N;
  ll a[111111];
  k = 0;
  while(N>0){
    N--;
    a[k] = N % 26;
    N = (N-a[k]) / 26;
    k++;
  }
  for(i=k-1;i>=0;i--)
    cout << (char)(a[i]  + 'a');
}



Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	long long int a;
	cin >> a;
	int ans = 0;

	for (int i = 357; i <= a; i+=2) {

		int x = i;
		bool b = 0, c = 0, d = 0;
		while (x) {
			int h = x % 10;
			if (h == 3)b = 1;
			else if (h == 5)c = 1;
			else if (h == 7)d = 1;
			else {
				b = 0, c = 0, d = 0;
				break;
			}
			x /= 10;
		}
		ans += b*c*d;
		if (i % 10 == 7)i += 14;
	}
	cout << ans << endl;

	return 0;



}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappop, heappush
import itertools

"""
・最小費用流。流量2を流せばよい。
・頂点xをx_in,x_outに拡張。x_inからx_outにcapacity1で、価値 a と 0 の辺を貼る
・このままだと最大化問題になっているので、辺のコストをX - a_{ij}とする感じで
"""

class MinCostFlow:
    """
    最小費用流。負辺がないと仮定して、BellmanFordを省略している。
    """
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink
        
    def add_edge(self, fr, to, cap, cost):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, cost, n2])
        self.G[to].append([fr, 0, -cost, n1])

    def MinCost(self, flow, negative_edge = False):
        if negative_edge:
            raise ValueError
        N = self.N; G = self.G; source = self.source; sink = self.sink
        INF = 10 ** 18
        prev_v = [0] * N; prev_e = [0] * N # 経路復元用
        H = [0] * N # potential
        mincost=0
        while flow:
            dist=[INF] * N
            dist[source]=0
            q = [source]
            mask = (1 << 20) - 1
            while q:
                x = heappop(q)
                dv = (x >> 20); v = x & mask
                if dist[v] < dv:
                    continue
                if v == sink:
                    break
                for i,(w,cap,cost,rev) in enumerate(G[v]):
                    dw = dist[v] + cost + H[v] - H[w]
                    if (not cap) or (dist[w] <= dw):
                        continue
                    dist[w] = dw
                    prev_v[w] = v; prev_e[w] = i
                    heappush(q, (dw << 20) + w)
            if dist[sink] == INF:
                raise Exception('No Flow Exists')
            # ポテンシャルの更新
            for v,d in enumerate(dist):
                H[v] += d
            # 流せる量を取得する
            d = flow; v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                cap = G[pv][pe][1]
                if d > cap:
                    d = cap
                v = pv
            # 流す
            mincost += d * H[sink]
            flow -= d
            v = sink
            while v != source:
                pv = prev_v[v]; pe = prev_e[v]
                G[pv][pe][1] -= d
                rev = G[pv][pe][3]
                G[v][rev][1] += d
                v = pv
        return mincost

H,W = map(int,readline().split())
A = list(map(int,read().split()))

N = 2 * H * W + 2
source = N-2; sink = N-1

G = MinCostFlow(N,source,sink)
add = G.add_edge
X = 10 ** 6

# スタート地点
add(fr=source, to=0, cap=2, cost=0)
# ゴール
add(2*H*W-1, sink, 2, 0)

# x_in to x_out
for x,a in enumerate(A):
    add(x+x,x+x+1,1,X) # とらない
    add(x+x,x+x+1,1,X - a) # とる

# 左から右への辺
for i,j in itertools.product(range(H),range(W-1)):
    x = W * i + j; y = x + 1
    add(x+x+1,y+y,1,0)
# 上から下への辺
for i,j in itertools.product(range(H-1),range(W)):
    x = W * i + j; y = x + W
    add(x+x+1,y+y,1,0)

cost = G.MinCost(2)

# 1点通るごとに、X - costになっている。2人合わせて、(H+W-1) * 2個のXが足されている

answer = 2 * (H+W-1) * X -cost
print(answer)

Measured memory_bytes: 100588
import math
n,d=map(int,input().split())
cnt=0
d=float(int(d))
for i in range(int(n)):
  x,y=map(int,input().split())
  x=float(int(x))
  y=float(int(y))
  res=float(math.sqrt(x*x+y*y))
  if(res<=d):
    cnt+=1
print(cnt)    

Measured memory_bytes: 69848
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a[105],ans; 
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);for(int i=1;i<=n;i++)in(a[i]);
	for(int i=2;i<=n;i++)
	for(int j=1;j<i;j++)
	ans+=a[i]*a[j];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;

void solve(){
    int n, k;
    cin >> n >> k;
    vector<long long> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    sort(h.begin(), h.end(), greater<int>());
    for(int i=0; i<min(n, k); i++) h[i] = 0;
    cout << accumulate(h.begin(), h.end(), 0LL) << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <vector>
#include <set>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, l, n, m, a, b, now, min;
  scanf("%lld%lld", &n, &m);
  vector<ll> vec[n], rev[n];
  ll d[n], be[n];
  pair<ll, ll> p;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &a, &b);
    vec[--a].push_back(--b);
    rev[b].push_back(a);
  }
  for(i = 0; i < n; ++i) {
    set< pair<ll, ll> > s;
    for(j = 0; j < n; ++j) d[j] = 1e9;
    d[i] = 0;
    for(j = 0; j < n; ++j) s.insert(make_pair(d[j], j));
    while(s.size()) {
      p = *s.begin(), s.erase(s.begin());
      if(p.first == 1e9) break;
      for(j = 0; j < vec[p.second].size(); ++j) if(d[vec[p.second][j]] > p.first + 1) {
        s.erase(make_pair(d[vec[p.second][j]], vec[p.second][j]));
        d[vec[p.second][j]] = p.first + 1;
        be[vec[p.second][j]] = p.second;
        s.insert(make_pair(p.first + 1, vec[p.second][j]));
      }
    }
    for(j = 0; j < rev[i].size(); ++j) if(d[rev[i][j]] != 1e9) {
      vector<ll> ans;
      now = rev[i][j];
      while(now != i) ans.push_back(now), now = be[now];
      ans.push_back(i);
      min = ans.size();
      ll flg[n];
      for(k = 0; k < n; ++k) flg[k] = ans.size();
      flg[i] = ans.size() - 1;
      for(now = ans.size() - 2; now >= 0; --now) {
        for(k = 0; k < vec[ans[now]].size(); ++k) if(flg[vec[ans[now]][k]] < min) min = flg[vec[ans[now]][k]];
        if(min != ans.size()) break;
        flg[ans[now]] = now;
      }
      printf("%lld\n", min - now + 1);
      for(k = min; k >= now; --k) printf("%lld\n", ans[k] + 1);
      return 0;
    }
  }
  printf("-1");
  return 0;
}

Measured memory_bytes: 384
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    map<int,int> m;
    int max = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        m[A[i]]++;
        if(A[i]>max) max = A[i];
    }
    vector<bool> dp(max+1,true);
    for(int i=0;i<N;i++){
        if(dp[A[i]]){
            for(int j=2;j*A[i]<=max;j++){
                dp[j*A[i]] = false;
            }
        }
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        if(dp[A[i]]&&m[A[i]]==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13456
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	int a = ri();
	int b = ri();
	printf("%d", (a-1) * (b-1));
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    
    int min = 400, dis = 200;
    REP(i, 8){
        if (N >= min & N < min+dis){
            int ans = 8-i;
            cout << ans << endl;
        }
        min += dis;
    }
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	lli n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	lli x[n];
	rep(i, n) scanf("%lld", &x[i]);
	
	lli ans = 0;
	
	rep(i, n-1) ans += min((x[i+1] - x[i]) * a, b);

	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Collections;
import java.util.Arrays;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		String S = reader.next();
		int[] dp1 = new int[S.length()];
		int[] dp2 = new int[S.length()];
		dp1[0] = 1;
		dp2[0] = 0;
		for(int i=1; i<S.length(); i++) {
		    // update dp2
		    if(i==1) {
		        dp2[i] = 1;
		    } else if(i==2) {
		        dp2[i] = Math.max(dp1[i-2]+1, dp2[i-2]+1);
		    } else {
		        if (S.charAt(i-3)==S.charAt(i-1) && S.charAt(i-2) == S.charAt(i)) {
		            dp2[i] = dp1[i-2]+1;
		        } else {
		            dp2[i] = Math.max(dp1[i-2]+1, dp2[i-2]+1);
		        }
		    }
		    // update dp1
		    if (S.charAt(i-1) == S.charAt(i)) {
		        dp1[i] = dp2[i-1]+1;
		    } else {
		        dp1[i] = Math.max(dp1[i-1]+1, dp2[i-1]+1);
		    }
		}
		
		System.out.println(Math.max(dp1[S.length()-1], dp2[S.length()-1]));
	}
	
	public static void solver(int H, int W, int N, int[] A) {
		// write logic
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


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

using namespace std;

int main() {
  string str;
  cin >> str;
  int tmp = 0;
  for(int i = 0; i < str.size(); ++i) {
    tmp += str[i] - '0';
  }
  if (tmp % 9) printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  
  cout << (H-h)*(W-w) << endl;
}

Measured memory_bytes: 3636
X, K, D = map(int, input().split())

X = abs(X)
a = min(X//D, K)
X -= D * a
K -= a

if K == 0:
    print(X)
    exit()

if abs(X-D) < X:
    X = abs(X-D)
    K -= 1

if K == 0:
    print(X)
else:
    if K%2 == 0:
        print(X)
    else:
        print(abs(X-D))

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

#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n  >> m;
    v<int> a(m); rep(i, m) cin >> a[i];
    int sum = 0;
    rep(i,m) {
        sum += a[i];
    }
    if (sum > n) {
        cout << "-1" << endl;
        return 0;
    }

    cout << n - sum << endl;

    return 0;
}


Measured memory_bytes: 3700
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef pair <ii,int> iii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

LL  res, c, x[N], akt, last, best, cl[N], acl[N];
int n, v[N], i;

int main() {
scanf("%d %lld", &n, &c);
for (i=0;i<n;i++) scanf("%lld %d", &x[i], &v[i]);
res = 0;
akt = 0;
last = 0;
best = -INF * 1LL * INF;
for (i=0;i<n;i++) {
	akt -= (x[i] - last);
	akt += v[i]; 
	last = x[i];
	best = max(best, akt);
	cl[i] = best;
	//printf("%d %lld\n", i, cl[i]);
}
res = max(res, cl[n - 1]);
akt = 0;
last = c;
for (i=n-1;i>=1;i--) {
	akt -= (last - x[i]);
	akt -= (last - x[i]);
	last = x[i];
	akt += v[i];
	res = max(res, akt + cl[i - 1]);
}

akt = 0;
last = c;
best = -INF * 1LL * INF;
for (i=n-1;i>=0;i--) {
	akt -= (last - x[i]);
	akt += v[i];
	last = x[i];
	best = max(best, akt);
	acl[i] = best;
	//printf("%d %lld\n", i, acl[i]);
}
res = max(res, acl[0]);
akt = 0;
last = 0;
for (i=0;i<n-1;i++) {
	akt -= (x[i] - last);
	akt -= (x[i] - last);
	last = x[i];
	akt += v[i];
	res = max(res, akt + acl[i + 1]);
}
printf("%lld\n", res);

return 0;
}



Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		if(a.charAt(0) == 'A')System.out.println('A');
		else if(a.charAt(0) == 'B')System.out.println('A');
		else if(a.charAt(0) == 'C')System.out.println('A');
		else if(a.charAt(0) == 'D')System.out.println('A');
		else if(a.charAt(0) == 'E')System.out.println('A');
		else if(a.charAt(0) == 'F')System.out.println('A');
		else if(a.charAt(0) == 'G')System.out.println('A');
		else if(a.charAt(0) == 'H')System.out.println('A');
		else if(a.charAt(0) == 'I')System.out.println('A');
		else if(a.charAt(0) == 'J')System.out.println('A');
		else if(a.charAt(0) == 'K')System.out.println('A');
		else if(a.charAt(0) == 'L')System.out.println('A');
		else if(a.charAt(0) == 'M')System.out.println('A');
		else if(a.charAt(0) == 'N')System.out.println('A');
		else if(a.charAt(0) == 'O')System.out.println('A');
		else if(a.charAt(0) == 'P')System.out.println('A');
		else if(a.charAt(0) == 'Q')System.out.println('A');
		else if(a.charAt(0) == 'R')System.out.println('A');
		else if(a.charAt(0) == 'S')System.out.println('A');
		else if(a.charAt(0) == 'Y')System.out.println('A');
		else if(a.charAt(0) == 'T')System.out.println('A');
		else if(a.charAt(0) == 'U')System.out.println('A');
		else if(a.charAt(0) == 'V')System.out.println('A');
		else if(a.charAt(0) == 'W')System.out.println('A');
		else if(a.charAt(0) == 'X')System.out.println('A');
		else if(a.charAt(0) == 'Z')System.out.println('A');
		else {
			System.out.println('a');
		}
		
	}
}

Measured memory_bytes: 26932
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
bool dp[100001];
int main() {
  int n,k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];

  for(int i = 1;i<=k;i++){
    for(int j = 0;j<n;j++){
      if(i-a[j]>=0) dp[i] |= !dp[i-a[j]];
    }
  }
  cout<<(dp[k]?"First":"Second")<<endl;
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

ll euclid(ll a, ll b, ll &x, ll &y) {
  if (b) { ll d = euclid(b, a % b, y, x);
    return y -= a/b * x, d; }
  return x = 1, y = 0, a;
}

const ll mod = 1000000007;
struct Mod {
  ll x;
  Mod() = default;
  Mod(ll xx) : x(xx % mod) {}
  Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
  Mod operator-(Mod b) { return Mod((x - b.x + mod) % mod); }
  Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
  Mod operator/(Mod b) { return *this * invert(b); }
  Mod invert(Mod a) {
    ll x, y, g = euclid(a.x, mod, x, y);
    assert(g == 1); return Mod((x + mod) % mod);
  }
};

const int MAXN = 3001;
const int MAXR = 100000;
Mod overcnt[MAXN + 5];
Mod dp[MAXN + 5];
Mod fac[2 * MAXR + 5];
void precompute(int n) {
  fac[0] = 1;
  rep(i, 1, n + 1) fac[i] = fac[i - 1] * Mod(i);
}
Mod nck(int n, int k) {return fac[n] / (fac[n - k] * fac[k]);}
Mod ways(int dx, int dy){return nck(dx + dy, dy);}

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

  precompute(2 * MAXR);

  int r, c, n;
  cin >> r >> c >> n;
  vector<pair<int, int>> a(n);
  trav(i, a) cin >> i.first >> i.second;
  sort(all(a), [](auto u, auto v){return u.first + u.second < v.first + v.second;});
  a.PB({r, c}); n++;
  auto precedes = [&](int i, int j){return a[i].first <= a[j].first and a[i].second <= a[j].second;};
  rep(i, 0, n) {
    dp[i] = ways(a[i].first - 1, a[i].second - 1);
    rep(j, 0, n) {
      if (!precedes(j, i) or i == j) continue;
      auto ways_ij = ways(a[i].first - a[j].first, a[i].second - a[j].second);
      dp[i] = dp[i] - dp[j] * ways_ij;
    }
  }
  cout << dp[n - 1].x << '\n';
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
using namespace std;

int main(){
  ll n,k,r,s,p,m;
  cin >> n >> k >> r >> s >> p;
  string t,pre,now;
  cin >> t;
  ll sum = 0;
  
  REP(i,k){
    //初回で勝てる手=次回で勝てる手なので初回を見送る必要なし
    pre = "a";
    if(k*floor(n/k)+i < n) m = 1;
    else m = 0;
    REP(j,floor(n/k)+m){
      now = t[i + k*j];
      if(pre == "a"){
        if(now == "r") {sum += p; pre = "p";}
        else if(now == "s") {sum += r; pre = "r";}
        else {sum += s; pre = "s";}
      }
      else if(pre == "r" && now == "s") pre = "a";
      else if(pre == "s" && now == "p") pre = "a";
      else if(pre == "p" && now == "r") pre = "a";
      else{
        if(now == "r") {sum += p; pre = "p";}
        else if(now == "s") {sum += r; pre = "r";}
        else {sum += s; pre = "s";}
      }
      //cout << sum << " ";
    }
    //cout << endl;
  }
  
  cout << sum;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

int n;

const int N = 8e3+50;

char s[N];

vector<int> a[200];

int has[200][N], sum[200][N];

int main() {
    // int t;

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

    for (int i=0; i<n; ++i) {
        has[s[i]][i] = 1;
    }

    for (int i=n-1; i>=0; --i) {
        for (int j=0; j<200; ++j)
            sum[j][i] = sum[j][i+1] + has[j][i];
    }

    const char *ss = "RGB";
    LL ans = 0;
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            if (s[i] == s[j])
                continue;
            for (int k=0; k<3; ++k) {
                if (ss[k] != s[i] && ss[k] != s[j]) {
                    ans += sum[ss[k]][j+1] - has[ss[k]][j+j-i];
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7508
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int dx = c - a, dy = d - b;
    cout << c - dy << " " << d + dx << " " << c - (dx + dy) << " " << d + (dx - dy) << endl;
}

Measured memory_bytes: 256
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C
 */
#include <iostream>
#include <set>

using namespace std;

bool
isprime(const int n, set<int> &known)
{
    int checked;
    for (auto& it : known) {
        if (n == it) {
            return true;
        } else if (n % it == 0) {
            return false;
        }
        checked = it;
    }
    for (int i = checked + 2; i * i <= n; i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int
main()
{
    int N;
    cin >> N; cin.ignore();

    set<int> knownprimes{2, 3, 5, 7};

    set<int> given;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a; cin.ignore();
        given.insert(a);
    }
    int count = 0;
    for (auto& it : given) {
        if (isprime(it, knownprimes)) {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3484
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main(void) {

	ll  N;
	cin >> N;
	vector<ll> A(N+2), ans(N+2, 0);

	for (int i = 2; i <= N; i++) {
		cin >> A[i];
		ans[A[i]]++;
	}

	for (int i = 1; i <= N; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 6428
#include<stdio.h>
#include<stdlib.h>
int n;
int a[100005], b[100005];
long long int c[100005];
int e[100005], f[100005];
int asc1(const void* x, const void* y)
{
	if (a[*(int*)x] > a[*(int*)y])return 1;
	if (a[*(int*)x] < a[*(int*)y])return -1;
	if (b[*(int*)x] > b[*(int*)y])return 1;
	if (b[*(int*)x] < b[*(int*)y])return -1;
	return 0;
}
int asc2(const void* x, const void* y)
{
	if (b[*(int*)x] > b[*(int*)y])return 1;
	if (b[*(int*)x] < b[*(int*)y])return -1;
	if (a[*(int*)x] > a[*(int*)y])return 1;
	if (a[*(int*)x] < a[*(int*)y])return -1;
	return 0;
}
long long int d[100005];
int visited[100005];
void dfs(int x)
{
	int min, mid, max;
	min = 0;
	max = n - 1;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (a[e[mid]] < x)
			min = mid;
		else
			max = mid;
	}
	if (a[e[min]] != x)
		min++;
	if (min < n - 1)
	{
		while (a[e[min]] == x)
		{
			if (visited[b[e[min]]] == 0)
			{
				visited[b[e[min]]] = 1;
				d[b[e[min]]] = d[x] + c[e[min]];
				dfs(b[e[min]]);
			}
			min++;
			if (min == n - 1)
				break;
		}
	}
	min = 0;
	max = n - 1;
	while (max - min > 1)
	{
		mid = (max + min) / 2;
		if (b[f[mid]] < x)
			min = mid;
		else
			max = mid;
	}
	if (b[f[min]] != x)
		min++;
	if (min < n - 1)
	{
		while (b[f[min]] == x)
		{
			if (visited[a[f[min]]] == 0)
			{
				visited[a[f[min]]] = 1;
				d[a[f[min]]] = d[x] + c[f[min]];
				dfs(a[f[min]]);
			}
			min++;
			if (min == n - 1)
				break;
		}
	}
	return;
}
int main()
{
	scanf("%d", &n);
	int i;
	for (i = 0; i < n - 1; i++)
	{
		scanf("%d %d %lld", &a[i], &b[i], &c[i]);
		a[i]--;
		b[i]--;
	}
	int q, k;
	scanf("%d %d", &q, &k);
	int x[100005], y[100005];
	for (i = 0; i < q; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
		x[i]--;
		y[i]--;
	}
	k--;
	for (i = 0; i < n; i++)
		e[i] = f[i] = i;
	qsort(e, n - 1, sizeof(int), asc1);
	qsort(f, n - 1, sizeof(int), asc2);
	for (i = 0; i < n; i++)
		visited[i] = 0;
	d[k] = 0;
	visited[k] = 1;
	dfs(k);
	for (i = 0; i < q; i++)
		printf("%lld\n", d[x[i]] + d[y[i]]);
	return 0;
}

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

int main() {
  int n;

  cin >> n;
  int r[n];

  for(int i = 0; i < n; ++i) {
    cin >> r[i];
  }
  int maxv = -2000000000;
  int minv = r[0];
  for(int j = 1; j < n; ++j) {
    maxv = max(maxv, r[j] - minv);
    minv = min(minv, r[j]);
  }
  cout << maxv << endl;
}

Measured memory_bytes: 3832
# http://wakabame.hatenablog.com/entry/2017/09/03/213522
# おまじない
import sys
input = sys.stdin.readline

# ノード数
N = int(input())

# 各要素は(元ノード, 先ノード, コスト)のタプルになっている
edges = [list(map(int, input().split())) for i in range(N - 1)]

# クエリ数と経由ノード
Q, K = map(int, input().split())

# クエリ一覧
xy = [list(map(int, input().split())) for i in range(Q)]


# まず経由地から各ノードのへの距離をメモする
def BFS(K, edges, N):
    # ノード分のリストを持ったリストの定義
    # ノード番号はインデックス-1に対応．つながっている先のノードとそこへのコストのタプルが入る
    roots = [ [] for i in range(N) ]
    for a, b, c in edges:
        roots[a-1] += [(b-1, c)]
        roots[b-1] += [(a-1, c)]
    # memo
    dist = [-1] * N
    # たどり着いたノードのリスト
    stack = []
    stack.append(K)
    dist[K] = 0
    while stack:
        label = stack.pop(-1)
        for i, c in roots[label]:
            # 初到達ならmemoしてstackに追加
            # これはグラフが木構造であるから言えること．そうでなければコスト最小値しか採用しては行けない？
            if dist[i] == -1:
                dist[i] = dist[label] + c
                stack += [i]
    return dist

distance = BFS(K - 1, edges, N)

for i in range(Q):
    print(distance[xy[i][0] - 1] + distance[xy[i][1] - 1])
            




Measured memory_bytes: 85984
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    char s[100001];
    scanf("%s",s);
    int i;
    int countr=1;
    for(i=0;i<n-1;i++)
    {
        if(s[i+1]!=s[i])
        {
            countr++;
        }
    }
    cout << countr;
}


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


int main(){
    int a[10];
    int A,B;
    cin >> A >> B;
    int count = 0;
    for(int i=A; i<=B; i++){
    
   int s = i % 10;
   int t = (i / 10000) % 10;
   int u = (i / 10) % 10;
   int v = (i / 1000) % 10;
   if(s == t && u == v) count++;

    }
  cout << count;

  return 0;
    

}

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

using namespace std;
using ll = long long;

/*********************************/
template<class T> inline ostream& operator<<(ostream& os,vector<T> arr) {os << "["; for(int i = 0; i < (int)arr.size(); i++)os << arr[i] << (i == (int)arr.size() - 1 ? "]" : ",");os << endl;return os;}
template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A,B>& p){os << "{" << p.first << "," << p.second << "}";return os; }
#define prvec(v) cerr<<#v<<": [";for(int __i = 0;__i < (int)(v).size(); __i++)cerr<<((v)[__i])<<(__i+1==(int)(v).size()?"]\n":",");
#define print(x) cerr<<#x<<": "<<(x)<<endl
/*********************************/

const vector<vector<int>> dir = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int h, w;

int id(int i, int j) {
	return i * w + j;
}

int main()
{
	cin >> h >> w;
	vector<string> g(h);
	atcoder::mf_graph<int> mf(h * w + 2);
	for(int i = 0; i < h; i++)cin >> g[i];

	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) {
		if((i + j) % 2)mf.add_edge(id(i, j), h * w + 1, 1);
		else mf.add_edge(h * w, id(i, j), 1);
	}

	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {

			if((i + j) % 2 || g[i][j] == '#')continue;
			for(auto d : dir) {
				int ny = i + d[0], nx = j + d[1];
				if(ny < 0 || ny >= h || nx < 0 || nx >= w || g[ny][nx] == '#')continue;
				mf.add_edge(id(i, j), id(ny, nx), 1);
			}

		}
	}

	cout << mf.flow(h * w, h * w + 1) << endl;

	auto v = mf.edges();
	for(auto e: v) {
		if(e.from >= h * w || e.to >= h * w)continue;
		if(e.flow) {
			int fy = e.from / w, fx = e.from % w;
			int ty = e.to / w, tx = e.to % w;
			for(int i = 0; i < 4; i++) {
				if(fy + dir[i][0] == ty && fx + dir[i][1] == tx) {
					if(i == 0) g[fy][fx] = '>', g[ty][tx] = '<';
					if(i == 1) g[fy][fx] = 'v', g[ty][tx] = '^';
					if(i == 2) g[fy][fx] = '^', g[ty][tx] = 'v';
					if(i == 3) g[fy][fx] = '<', g[ty][tx] = '>';
				}
			}
		}
	}

	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			cout << g[i][j];
		}
		cout << endl;
	}



}

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

int main() {
    int p,q,r;
    int a,b,c;
    cin >> p >> q >> r;

    a = p + q;
    b = q + r;
    c = r + p;

    if(a <= b && a <= c){
        std::cout << a << std::endl;
    }else if(b <= c && b < a){
        std::cout << b << std::endl;
    }else{
        std::cout << c << std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
  vector<int> A(5);
  for(int i = 0; i < 5 ; i++) cin >> A[i];
  int k = 0;
  cin >> k;
  bool f = false;
  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5 ; j++){
    if(k < A[i] - A[j]) f = true;
    }
  }
  
  if(f) cout << ":(";
  else cout << "Yay!";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI acos(-1.0)
#define test() int t; cin>>t; while(t--)
#define ll long long int
const int INF = 1e9 + 5;
int main()
{
	IOS;
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= i + k; j++) {
			if (j < n)
				dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
vi g[100004];
void ipgraph(int n, int m);
void dfs(int u, int par);
ll gcd (ll a, ll b);
unsigned long long factorial[1000004]; 
//___________________________________________
 unsigned long long power(unsigned long long x,int y,int p)
{unsigned long long res=1;x=x%p;while(y>0){if(y&1)
res=(res*x)%p;y=y>>1;x=(x*x)%p;}
return res;}
//____________________________________________
unsigned long long modInverse(unsigned long long n,int p)
{return power(n,p-2,p);}
//_____________________________________________
unsigned long long nc(unsigned long long n,int r,int p)
{if(r==0)
return 1;return(factorial[n]*modInverse(factorial[r],p)%p*modInverse(factorial[n-r],p)%p)%p;}



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
    #endif
    int t=1;
    //cin>>t;
    while(t--){
      int n;
      cin>>n;
      int a,b;
      int v[n+1]= {0};
      fo(i,n){
          cin>>a>>b;
          if(a==b){
              v[i+1]=1;
          }

      }
      int f=0;
                int c=0;
          for(int i=1;i<=n;i++){
              if(v[i]==0){
                  c=0;
              }
              else{
                  c++;
              }
              if(c==3){
                  f=1;
                  break;
              }
          }
          f?Yes: No;
    }

    


	return 0;
}


void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod; 
    }*/


Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
//map<key,value>

int main(){
  int n;
  cin >> n;
  vector<int> ra(n);
  vector<string> name(n);
  vector<int> va(n);
  for(int i=0;i<n;i++){
    cin >> name[i] >> va[i];
  }
  for(int i=0;i<n;i++){
    int rank=0;
    for(int j=0;j<n;j++){
      if(name[i] >= name[j]){
        if(name[i] == name[j]){
          if(va[i] <= va[j])rank++;
        }
        else rank++;
      }
    }
    ra[i] = rank;
  }
  //sort(ALL(ra));
  for(int i=1;i<=n;i++){
    for(int j=0;j<n;j++){
      if(ra[j] == i)cout << j+1 << "\n";
    }
  }
  return 0;
}

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

map<string,int>mp;

int main() {
  int n;
  cin >> n;
  vector<int>h(n);
  rep(i,n) cin >> h[i];
  int cnt = 1;
  rep(i,n-1){
    --h[0];
    if(h[i+1]>h[i]){
      --h[i+1];
      ++cnt;
    }
    else if(h[i+1]==h[i]){
      ++cnt;
      continue;
    }
    else if (h[i+1]<h[i]){
      break;
    }
  }
  if(cnt==n) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {
    int N, K;
    int[] nums;

    int solve() {
        int[] dp = new int[N+1];
        for (int i = 2; i <= N; i++) {
            int len = K;
            if (i < K) len = i;

            int min = Integer.MAX_VALUE;
            for (int j = 1; j <= len; j++) {
                min = Math.min(min, Math.abs(nums[i]-nums[i-j]) + dp[i-j]);
            }
            dp[i] = min;
        }
        return dp[N];
    }

    void main(FastScanner in, PrintWriter out) {
        N = in.nextInt();
        K = in.nextInt();
        nums = new int[N+1];
        nums[0] = Integer.MAX_VALUE;
        for (int i = 1; i <= N; i++) {
            nums[i] = in.nextInt();
        }
        out.println( solve() );
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Main m = new Main();
        m.main(in, out);
        out.close();
        in.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (IOException e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        public String nextLine() {
            String str = "";
            try { str = br.readLine();
            } catch (IOException e) { e.printStackTrace(); }
            return str;
        }
        public void close() throws IOException { br.close(); }
    }
}

Measured memory_bytes: 34252
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] s = new int[M];
        int[] c = new int[M];
        int[] num = new int[N];
        int MAX_NUM = 10;
        for(int i = 0; i < N; i++) {
            num[i] = MAX_NUM;
            if (i == 0 && N != 1) {
                num[i]++;
            }
        }
        for(int i = 0; i < M; i++) {
            s[i] = sc.nextInt();
            c[i] = sc.nextInt();
            if (N != 1 && s[i] == 1 && c[i] == 0) {
                System.out.println(-1);
                sc.close();
                return;
            }
            if (num[s[i]-1] >= MAX_NUM) {
                num[s[i]-1] = c[i];
            } else {
                if (num[s[i]-1] != c[i]) {
                    System.out.println(-1);
                    sc.close();
                    return;
                }
            }
        }
        sc.close();

        int ans = 0;
        for(int i = 0; i < N; i++) {
            ans += (num[i] % 10) * (int)Math.pow(10, N - i - 1);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
function main(input) {
    let [N, K, ...A] = input.trim().split(/[\s\n]/).map(Number)

    for(let k = 0; k < K; k++) {
        const imos = new Array(N).fill(0)

        for(let i = 0; i < N; i++) {
            let min = i - A[i]
            let max = i + A[i] + 1
            if(min < 0) min = 0
            imos[min]++
            imos[max]--
        }
        imos.length = N
        
        for(let i = 1; i < N; i++) {
            imos[i] += imos[i - 1]
        }
        
        const is_same = imos.every((a,i) => a === A[i])
        if(is_same) break

        A = imos
    }

    console.log(A.join(' '))
}

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


Measured memory_bytes: 118428