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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


int main()
{
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans = 0;

    if( X > Y )
    {
        if( A > C*2 ) ans = X * C * 2;
        else if( A+B > C*2 )
        {
            ans += min(X,Y) * C * 2;
            ans += (X-Y) * A;
        }
        else
        {
            ans += min(X,Y) * (A+B);
            ans += (X-Y) * A;
        }
    }
    else if( Y > X )
    {
        if( B > C*2 )
        {
            ans = Y * C * 2;
        }
        else if( A+B > C*2 )
        {
            ans += min(X,Y) * C * 2;
            ans += (Y-X) * B;
        }
        else
        {
            ans += min(X,Y) * (A+B);
            ans += (Y-X) * B;
        }
    }
    else
    {
        if( A+B > C*2 ) ans = X * C * 2;
        else ans = (A+B) * X;
    }
    cout << ans << endl;
}


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

if X < Y:
    A,B,X,Y = B,A,Y,X

ans = 0
if A + B >= 2*C:
    ans += Y*2*C
    X,Y = X-Y,0
    if A > 2*C:
        ans += X*2*C
    else:
        ans += X*A
else:
    ans += A*X+B*Y

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long s=0,a,n,i;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
		scanf("%lld",&a);
		while(a%2==0)
		{
			a/=2;
			s++;
		}
	}
	printf("%d",s);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,c,k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for(int i = 0; i < n; i++)
    cin >> t[i];

    int cnt = 1;
    sort(t.begin(),t.end());
    int time = t[0];
    int passenger = 1;
    for(int i = 1; i < n; i++){
        if(passenger >= c ||t[i] - time > k)
            {
                cnt++;
                passenger = 0;
                time = t[i];
            }
            if(t[i] - time <= k || passenger < c)
            passenger++;
    }
    cout << cnt << endl;

}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	for i := 0; i < c; i++ {
		if a+i <= b {
			fmt.Println(a + i)
		} else {
			break
		}
	}
	tmp := a + c
	for i := c - 1; i >= 0; i-- {
		if b-i >= tmp {
			fmt.Println(b - i)
		}
	}

}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    
    int n, qt, ontime=0, count=0, now, top=0, next_in;
    cin >> n >> qt;
    next_in = n;
    string name[1000000];
    int time[n], que[n];
    for(int i=0;i<n;i++){
        cin >> name[i] >> time[i];
        que[i] = i;
    }
    
    while(count<n){
        now = que[top];
        if(top == n){
            top = 0;
        }else{
            top++;
        }
        
        if(time[now]<=qt){
            ontime += time[now];
            cout << name[now] << " " << ontime << endl;
            count++;
        }else{
            ontime += qt;
            time[now] -= qt;
            que[next_in] = now;
            if(next_in == n){
                next_in = 0;
            }else{
                next_in++;
            }
        }
    }
    
    
    return 0;
}



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

int main() {
   int D,T,S;
   cin >> D >> T >> S;
   int time = 0;
   if(D % S == 0){
       time = D / S;
   }else{
       time = D / S + 1;
   }
   if(time <= T){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
//桁
int kt(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){

int N;
	cin >> N;
	vector<int> vec(N + 1);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	vec.at(N) = 1e10;
	sort(vec.begin(),vec.end());
	int answer = 0;
	int count = 0;
	for(int i = 0;i < N;i++) {
		if(vec.at(i) == vec.at(i + 1)) {
			count++;
		}
		else {
			if(count % 2 == 0) {
				answer++;
			}
          	count = 0;
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String[] b = sc.next().split("");
		String[] c = sc.next().split("");
		
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < a ; i++) {
			sb.append(b[i]);
			sb.append(c[i]);
		}
		
		String result = sb.toString();
		
		System.out.println(result);
	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind{
  int n;
  vector<int> p,r;
  UnionFind(){}
  UnionFind(int n):n(n){init();}
  void init(){
    p.clear();
    r.clear();
    p.resize(n);
    r.resize(n,1);
    for(int i=0;i<n;i++) p[i]=i;
  }
  int find(int x){
    return (p[x]==x?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    x=find(x);y=find(y);
    return x==y;
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    p[y]=x;
    r[x]+=r[y];
  }
};
signed main(){
  int n,m;
  cin>>n>>m;
  UnionFind uf(n);
  for(int i=0;i<m;i++){
    int s,t;
    cin>>s>>t;
    uf.unite(s,t);
  }
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int s,t;
    cin>>s>>t;
    cout<<(uf.same(s,t)?"yes":"no")<<endl;
  } 
  return 0;
}

Measured memory_bytes: 4356
n = int(input())
li_a = []
for i in range(n):
  a = list(map(int, input().split()))
  li_a.append(a)
li = list(sorted(li_a))
ans = 0
b = li[0][0] + li[0][1]
for i in range(n-1):
  if li[i+1][0] - li[i+1][1] >= b:
    b = li[i+1][0] + li[i+1][1]
  else:
    b = min(b, li[i+1][0]+li[i+1][1])
    ans += 1
print(n-ans)

Measured memory_bytes: 62936
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;
typedef pair<ll,ll>pl;

const int MAX_N = 40;

ll v[MAX_N];
ll w[MAX_N];
vector<pl> x,y;

void solve(int s,int t,vector<pl> &x)
{
	int z = t-s;
	rep(i,1<<z){
		pl p = pl(0,0);
		rep(j,z){
			if(i&(1<<j)){
				p.first += w[s+j];
				p.second += v[s+j];
			}
		}
		x.push_back(p);
	}
}

int main()
{
	int n;
	ll lm;
	cin >> n >> lm;
	rep(i,n){
		cin >> v[i] >> w[i];
	}
	solve(0,n/2,x);
	solve(n/2,n,y);
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	ll t=0;
	ll maxv = -(1LL<<60);
	ll ans = 0;
	for(int i=x.size()-1;i>=0;i--){
		while(t < y.size() && x[i].first+y[t].first <= lm){
			maxv = max(maxv,y[t].second);
			t++;
		}
		ans = max(ans,maxv+x[i].second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 43748
# -*- coding: utf-8 -*-
import sys

N ,M = map(int, input().split())
X = list(map(int, input().split()))

if N >= M:
    print(0)
    sys.exit()
    
X.sort()
L = [0] * (M - 1)
for i in range(M-1):
    L[i] = X[i+1] - X[i]

L.sort()

ans = sum(L[:M-N])
print(ans)

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

int N;
const int MAX_N = 1e5 + 3;
vector<vector<int>> graph(MAX_N);
int fennec[MAX_N]; //node 0からnode iまでの距離
int snuke[MAX_N];  //node N-1からnode iまでの距離

void init() {
    queue<pair<int,int>> task;
    bool vis[N];
    fill(vis, vis + N, false);
    vis[0] = true;
    fennec[0] = 0;
    task.push(make_pair(0, 0));
    while(!task.empty()) {
        int from = task.front().first;
        int d = task.front().second;
        task.pop();
        for(int i = 0; i < graph[from].size(); ++i) {
            int to = graph[from][i];
            if(vis[to]) continue;
            vis[to] = true;
            fennec[to] = d + 1;
            task.push(make_pair(to, d + 1));
        }
    }

    fill(vis, vis + N, false);
    vis[N-1] = true;
    snuke[N-1] = 0;
    task.push(make_pair(N-1, 0));
    while(!task.empty()) {
        int from = task.front().first;
        int d = task.front().second;
        task.pop();
        for(int i = 0; i < graph[from].size(); ++i) {
            int to = graph[from][i];
            if(vis[to]) continue;
            vis[to] = true;
            snuke[to] = d + 1;
            task.push(make_pair(to, d + 1));
        }
    }
}

int main()
{
    scanf("%d", &N);
    for(int i = 0; i < N-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    init();
    /*
    printf("fennec:\n");
    for(int i = 0; i < N; ++i) printf("%d ", fennec[i]);
    printf("\n");
    printf("snuke:\n");
    for(int i = 0; i < N; ++i) printf("%d ", snuke[i]);
    printf("\n");
    */
    
    int S = 0, F = 0;
    for(int i = 1; i < N-1; ++i) {
        if(snuke[i] < fennec[i]) ++S;
        else ++F;
    }
    if(S >= F) printf("Snuke\n");
    else printf("Fennec\n");
    return 0;
}

Measured memory_bytes: 6784
function readInt(str) {
  return parseInt(str, 10);
}
function calcRun(S: string) {
  let current = "0";
  let run = [0];
  for (const c of S) {
    if (c == current) {
      run[run.length - 1] = run[run.length - 1] + 1;
    } else {
      current = c;
      run.push(1);
    }
  }
  return run;
}
function aggregate(run: number[]) {
  const [sum,arr]=run.reduce(([sum,arr]:[number,number[]], x) => {
    arr.push(sum+x);
    return [sum+x,arr];
  }, [0,[]]);
  return arr;
}
function sum(agg:number[],b:number,e:number){
  return ((e>=agg.length)?agg[agg.length-1]:agg[e])-((b<1)?0:agg[b-1]);
}
function Main(raw: string) {
  const input = raw.split("\n");
  const [N, K] = input[0].split(" ").map(readInt);
  const S = input[1];
  const run = calcRun(S);
  const agg = aggregate(run);
  let max=0;
  // console.log(agg);
  for(let i=-1;i<agg.length;i+=2){
    // console.log(i,K*2+i,sum(agg,i,K*2+i));
    max=Math.max(max, sum(agg,i,K*2+i));
  }
  //出力
  console.log(max);
}

//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15296
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t X, Y;
  cin >> X >> Y;
  // const int64_t L = static_cast<int64_t>(T.length());
  for (int64_t i = 0; i <= X; ++i) {
    const int64_t j = X - i;
    if (j < 0) {
      cout << "No" << endl;
      return 0;
    }
    if (2 * i + 4 * j == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)

int main(){
	int N,X,Y; scanf("%d %d %d",&N,&X,&Y);
	X--; Y--;
	int ans[N];
	rep(i,0,N) ans[i]=0;
	rep(i,0,N){	// i:距離
		int dis[N];
		rep(j,0,N) dis[j]=abs(i-j);
		if( i <= Y ){
			if( dis[X] < dis[Y] ){
				dis[Y] = dis[X]+1;
				rep(k,1,Y-X){
					if( dis[Y-k] > dis[Y]+k ){
						dis[Y-k] = dis[Y]+k;
					}else{
						break;
					}
				}
				rep(k,1,N-Y){
					if( dis[Y+k] > dis[Y]+k ){
						dis[Y+k] = dis[Y]+k;
					}else{
						break;
					}
				}
			}
		}
		rep(j,i,N) ans[dis[j]]++;
	}
	rep(i,1,N) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        while (scanner.hasNext()) {
            String input = scanner.nextLine();
            String[] dataset = input.split(",");
            
            int[] sectionLen  = new int[10];
            double totalLen = 0;

            for (int i = 0; i < sectionLen.length; i++) {
                sectionLen[i] = Integer.parseInt(dataset[i]);
                totalLen += (double) sectionLen[i];
            }
            int v1 = Integer.parseInt(dataset[10]);
            int v2 = Integer.parseInt(dataset[11]);
            
            double time = totalLen / (v1 + v2);
            double distance = v1 * time;
            
            for (int i = 0; i < sectionLen.length; i++) {
                distance -= sectionLen[i];
                if (distance <= 0) {
                    System.out.println(i+1);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 17148
#include<stdio.h>
int main(void){
  int n,x,i,t=0;
  scanf("%d %d",&n,&x);
  int l[n];
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  i=1;
  while(t<=x && i<=n){
    t+=l[i-1];
    i++;
  }
  if(t>x){
    i--;
  }
  printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 128
'use strict';
function Main(inputs) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const input = inputs.split("\n");
  const n = Number(input[0]);
  const a = input[1].split(' ').map(Number);
  const b = [];
  let isGyaku = false;
  for(let i = 0; i < n; i++){
    isGyaku = i % 2 === 1;
    if(isGyaku){
      b.unshift(a[i]);
    }else{
      b.push(a[i]);
    }
  }
  if(!isGyaku){
    b.reverse();
  }
  console.log(b.join(' '));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 65872
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
string s;
cin>>s;
for (int i=0;i<s.size();i++)
if (i % 2 == 0)
cout<<s[i];
system ("pause");
return 0;
}

Measured memory_bytes: 760
#include<stdio.h>
#include<string.h>

int main(void){
    int N, K;
    
    
    scanf("%d", &N);
    char S[N];
    scanf("%s", S);
    scanf("%d", &K);

    for(int i=0; i<N; i++){
        if(S[i] != S[K-1]){
            S[i] = '*';
        }
    }
    printf("%s\n", S);
    
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int A,B;
		A = s.nextInt();
		B = s.nextInt();
		if((A + B) % 3 == 0){
			System.out.println("Possible");
		}else
		if(A % 3 == 0){
			System.out.println("Possible");
		}else
		if(B % 3 == 0){
			System.out.println("Possible");
		}else
			System.out.println("Impossible");
			

		}
	}



Measured memory_bytes: 21844
#include<iostream>

using namespace std;

#define MAX 10000
#define NIL -1

struct Node {
  int parent;
  int left;
  int right;
};

Node T[MAX];
int D[MAX], H[MAX];

void setDepth(int u, int d) {
  if (u == NIL) {
    return;
  }
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if (T[u].left != NIL) {
    h1 = setHeight(T[u].left) + 1;
  }
  if (T[u].right != NIL) {
    h2 = setHeight(T[u].right) + 1;
  }
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
  if (T[u].parent == NIL) {
    return NIL;
  }
  if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
    return T[T[u].parent].left;
  }
  if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
    return T[T[u].parent].right;
  }
  return NIL;
}

void print(int u) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "sibling = " << getSibling(u) << ", ";
  int deg = 0;
  if (T[u].left != NIL) {
    deg++;
  }
  if (T[u].right != NIL) {
    deg++;
  }

  cout << "degree = " << deg << ", ";
  cout << "depth = " << D[u] << ", ";
  cout << "height = " << H[u] << ", ";

  if (T[u].parent == NIL) {
    cout << "root" << endl;
  } else if (T[u].left == NIL && T[u].right == NIL) {
    cout << "leaf" << endl;
  } else {
    cout << "internal node" << endl;
  }
}

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

  for (int i = 0; i < N; i++) {
    T[i].parent = NIL;
  }

  int v, left, right;
  for (int i = 0; i < N; i++) {
    cin >> v >> left >> right;
    T[v].left = left;
    T[v].right = right;
    if (left != NIL) {
      T[left].parent = v;
    }
    if (right != NIL) {
      T[right].parent = v;
    }
  }

  int root = 0;
  for (int i = 0; i < N; i++) {
    if(T[i].parent == NIL) {
      root = i;
    }
  }

  setDepth(root, 0);
  setHeight(root);

  for (int i = 0; i < N; i++) {
    print(i);
  }

  return 0;
}


Measured memory_bytes: 3112
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

void sputs(){}
template <class Head, class... Tail>
void sputs(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) == 0) { cout << endl; }
  else { cout << " "; }
  sputs(std::move(tail)...);
}

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int h,w;cin>>h>>w;
  vector<vector<char>> m(h, vector<char>(w));
  map<char, int> cnt;
  rep(i,h)rep(j,w){
    cin>>m[i][j];
    cnt[m[i][j]]++;
  }
  dump_2d(m,h,w);

  int p2 = 0;
  int p1 = 0;
  int p3 = 0;
  each(el, cnt){
    int c = el.second;
    if (c%4==3){ p3++; }
    if (c%4==2){ p2++; }
    if (c%4==1){ p1++; }
  }

  if (h%2==0 && w%2==0){
    cout << (p1+p2+p3==0?"Yes":"No") << endl;
  }
  else if (h%2==0 || w%2==0){
    if (w%2==0) swap(h, w);
    cout << (p2<=h/2&&p3==0&&p1==0?"Yes":"No") << endl;
  }
  else{
    cout << (p2+p3<=(h-1)/2+(w-1)/2 && (p1+p3)==1?"Yes":"No") << endl;
  }

  return 0;
}


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

using ll = long long;

int main() {
    int N;
    ll ans = 0;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i];
    priority_queue<vector<int>> q;
    rep(i, N) {
        cin >> B[i];
        q.push({B[i], i});
    }
    while (!q.empty()) {
        auto t = q.top();
        q.pop();
        if (t[0] <= A[t[1]]) continue;
        int d = B[(t[1] - 1 + N) % N] + B[(t[1] + 1) % N];
        int r = (t[0] - max(A[t[1]], d) + d - 1) / d;
        t[0] -= d * r;
        ans += r;
        if (t[0] < A[t[1]] || r == 0) {
            cout << -1 << endl;
            return 0;
        }
        if (t[0] > A[t[1]]) {
            q.push({t[0], t[1]});
        }
        B[t[1]] = t[0];
    }
    rep(i, N) {
        if (A[i] != B[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    /*
    9817 1108 6890 4343 8704
    0005
                        4356
              1439
                        0008
                    2896
                    1449
                       2
               329
          774
          440
          106
               221
               113
                5
           96
           86
           76
           66
           56
           46
           36
           26
           16
            6
                            1
    */
}

Measured memory_bytes: 14252
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,k;
    cin >> n >> k;
    vector<bool> b(n, true);
    REP(i,0,k) {
        int d;
        cin >> d;
        int in;
        REP(j,0,d) {
            cin >> in;
            --in;
            b[in] = false;
        }
    }
    int ans = 0;
    REP(i,0,n) ans += b[i];
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3628
/* ITP1_3_C:Swapping Two Numbers  */
/* 20181118 AOJ */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void){
	int x, y;

	while(1){
		scanf("%d %d", &x, &y);
		if( !x && !y) break;
		if(x >= y){
			printf("%d %d\n", y, x);
		}else{
			printf("%d %d\n", x, y);
		}
	}

	return 0;
}




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

int occ[200005];
int cov[200005];
int arr[200005];
int ans;

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    ans = n;
    for (int x = 0; x<n; x++){
        int p;
        scanf("%d",&p);
        int t = p-occ[p];
        occ[p]++;
        if (t>0){
            if (cov[t]==0)ans--;
            cov[t]++;
        }
        arr[x] = p;
    }
    for (int x = 0; x<m; x++){
        int p,v;
        scanf("%d%d",&p,&v);
        p--;
        int t = arr[p] - occ[arr[p]] + 1;
        if (t>0){
            if (cov[t]==1){
                ans++;
            }
            cov[t]--;
        }
        occ[arr[p]]--;
        t = v - occ[v];
        if (t>0){
            if (cov[t]==0){
                ans--;
            }
            cov[t]++;
        }
        occ[v]++;
        arr[p] = v;
        printf("%d\n",ans);
    }

}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ld long double
using namespace std;

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

	ld l;
	cin >> l;
	ld a=l/3;
	cout << a*a*a << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int a[100005];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int flag=0;
	int num=1;
	int t=1;
	for(int i=1;i<n;i++){
		if(flag==0){
			for(int j=i+1;j<=n;j++){
				if(a[j]!=a[i]){
					if(a[j]>a[i]) flag=1;
					else flag=-1;
					i=j-1;
					break;
				}
			}
		}
		else{
			if(flag==1&&a[i+1]<a[i]){
				flag=0;
				t=0;
				num++;
			}
			else if(flag==-1&&a[i+1]>a[i]){
				flag=0;
				t=0;
				num++;
			}
		}	
	}
	if(t==1) printf("1\n");
	else{
		printf("%d\n",num);
	}
	return 0;
}


Measured memory_bytes: 512
// -------- START : snippet -------- //

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

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

// -------- START : macro -------- //

#define ll long long
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define len(c) (ll)c.size()
#define all(v) (v).begin(),(v).end()
#define lb(v,x) (lower_bound(all(v),x)-v.begin())
#define ub(v,x) (upper_bound(all(v),x)-v.begin())
#define has(c,x) (c.find(x) != c.end())
#define uniq(v) v.erase(unique(all(v)),v.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

// -------- END : macro -------- //

// -------- START : debug macro -------- //

template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container

template<class H> void recursive_debug(string s, H h) {
    cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

// -------- END : debug macro -------- //

// -------- END : snippet -------- //

int main(void) {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (k >= x/d) {
        k -= x/d;
        x -= x/d * d;
        k = k%2;
    }
    cout << abs(x - d*k) << endl;
    return 0;
}


Measured memory_bytes: 3596
L = input()
E = []
N = 1
while 2**(N-1) < L:
  N += 1
if 2**(N-1)>L:
  N -= 1
for i in range(N-1):
  E += [(i,i+1,0),
        (i,i+1,2**(N-i-2))]
if 2**(N-1)<L:
  E += [(0,N-1,L-1)]
  for i in range(N-1):
    if (L-1)>>i&1:
      E += [(0, N-i-1, (L-1)>>(i+1)<<(i+1))]
print N, len(E)
for e in E:
  print e[0]+1, e[1]+1, e[2]


Measured memory_bytes: 2692
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] count = new int[10][10];
        for(int i = 1; i <= n; i++){
            String str = String.valueOf(i);
            int first = Integer.parseInt(String.valueOf(str.charAt(0)));
            int last = Integer.parseInt(String.valueOf(str.charAt(str.length() - 1)));
            count[first][last]++;
        }
        long ans = 0;
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= 9; j++){
                ans += count[i][j] * count[j][i];
            }
        }
        System.out.println(ans);
    }
}


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

int main() {
    int n; cin >> n;
    int d[110];
    for(int i = 0; i < n; ++i) cin >> d[i];
    
    set<int> value;
    for(int i = 0; i < n; ++i) {
        value.insert(d[i]);
    }
    
    cout << value.size() << endl;
}


Measured memory_bytes: 256
n,q = map(int,input().split())
rl = [0] * n
scores = [0] * n
for i in range(n-1):
    a,b = map(int,input().split())
    rl[b-1] = a-1
for j in range(q):
    p,x = map(int,input().split())
    scores[p-1] += x
for k in range(1,n):
    scores[k] += scores[rl[k]]
print(*scores)


Measured memory_bytes: 25828
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main(){
	int n;
	cin >> n;
	vector<vector<char>> a(n, vector<char>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int k = 0; k < n; k++) {
		bool flag = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (a[i][(j + k) % n] != a[j][(i + k) % n]) flag = false;
			}
		}
		if (flag) ans += n;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n,mod;
int a[2*MAXN];

int calc(int nleft) {
	assert(nleft%2==0);
	int lmx=0;
	REP(i,nleft/2) {
		int cur=a[i]+a[nleft-i-1];
		if(cur>=mod) return -1;
		lmx=max(lmx,cur);
	}
	int nright=2*n-nleft; assert(nright%2==0);
	int rmx=0;
	REP(i,nright/2) {
		int cur=a[nleft+i]+a[nleft+nright-i-1];
		if(cur<mod) return -2;
		rmx=max(rmx,cur-mod);
	}
	return max(lmx,rmx);
}

int solve() {
	sort(a,a+2*n);
	int ret=INT_MAX;
	{ int cur=calc(0); if(cur>=0) ret=min(ret,cur); }
	{ int cur=calc(2*n); if(cur>=0) ret=min(ret,cur); }
	int lo=1,hi=n-1;
	while(lo<=hi) {
		int mi=lo+(hi-lo)/2;
		int cur=calc(2*mi);
		if(cur==-1) { hi=mi-1; continue; }
		if(cur==-2) { lo=mi+1; continue; }
		ret=min(ret,cur); hi=mi-1;
	}
	return ret;
}

void run() {
	scanf("%d%d",&n,&mod);
	REP(i,2*n) scanf("%d",&a[i]);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;
typedef pair<P, P> R;

const int inf = (int)2e6;

int n, d;
Q z[200000];
R st[(2 << 19) - 1];

R st_init(int k, int l, int r){
	if(r - l == 1){
		return st[k] = R(z[l].second, z[l].second);
	}
	R p = st_init(k * 2 + 1, l, (l + r) / 2);
	R q = st_init(k * 2 + 2, (l + r) / 2, r);
	return st[k] = R(
		P(min(p.first.first, q.first.first), min(p.first.second, q.first.second)),
		P(max(p.second.first, q.second.first), max(p.second.second, q.second.second))
	);
}

R st_minmax(int a, int b, int k, int l, int r){
	if(b <= l || r <= a){
		return R(
			P(inf, inf),
			P(0, 0)
		);
	}
	if(a <= l && r <= b){
		return st[k];
	}
	R p = st_minmax(a, b, k * 2 + 1, l, (l + r) / 2);
	R q = st_minmax(a, b, k * 2 + 2, (l + r) / 2, r);
	return R(
		P(min(p.first.first, q.first.first), min(p.first.second, q.first.second)),
		P(max(p.second.first, q.second.first), max(p.second.second, q.second.second))
	);
}

int main(){
	scanf("%d%d", &n, &d);
	rep(i, n){
		int x, y, b;
		scanf("%d%d%d", &x, &y, &b);
		z[i] = Q(b, P(x, y));
	}

	sort(z, z + n);
	st_init(0, 0, n);

	ll ans = 0;
	int s = 0, t = 0;
	while(t < n){
		while(t < n && z[t].first <= z[s].first + d){
			++t;
		}
		R x = st_minmax(s, t, 0, 0, n);
		ans = max(ans, ll(x.second.first - x.first.first) * ll(x.second.second - x.first.second));
		++s;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 19760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define infy 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
bool f(string s)
{
       string ss = s;
       reverse(all(ss));
       return ss == s;
}
int main(){
       ld l;
       cin>>l;
       ld xx = (l/3.0)*(l/3.0)*(l/3.0);
       cout<<setprecision(20);
       cout<<xx<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int w,h;
int C[50][50];

void dfs(i,j){
  int x,y,mx,my;
  C[i][j]=-1;
  for (y=-1;y<=1;y++)
    for (x=-1;x<=1;x++){
      mx=x+j;
      my=y+i;
      if (mx<0 || my<0 || mx>=w || my>=h)
        continue;
      if (C[my][mx]==1)
        dfs(my,mx);
    }
}

int main(){
  int i,j,cnt;
  while (1){
    scanf("%d %d",&w,&h);
    if (w==0 && h==0) break;
    for (i=0;i<h;i++)
      for (j=0;j<w;j++)
        scanf("%d",&C[i][j]);
    cnt=0;
    for (i=0;i<h;i++)
      for (j=0;j<w;j++)
        if (C[i][j]==1){
          dfs(i,j);
          cnt++;
        }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	string S;
	cin >> S;
	int N = S.length();
	sort(S.begin(), S.end());
	bool judge = true;
	if(N == 1){
		judge = false;
	}else {
		for(int i = 1; i < N; i++){
			if(i % 2 == 1 && S[i - 1] != S[i]){
				judge = false;
				break;
			}
		}
	}
	cout << ((judge) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun main() {
    val pw = PrintWriter(System.out)

    val (n, k) = readInputLine().split(" ").map { it.toInt() }

    val cnt = IntArray(n)

    repeat(k) {
        readInputLine()
        readInputLine().split(" ").map { cnt[it.toInt() - 1]++ }
    }

    pw.println(cnt.count { it == 0 })

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 38784
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> P;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;
const ll MOD=1e9+7;
struct edge{
    int to;
    int cost;
};
int N,M;
vector<vector<pii> > G;
vector<vector<bool> > used;
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    vector<int> d(N,INF);
    d[s]=0;
    que.push(P(0,pii(s,-1)));
    while(!que.empty()){
        P p=que.top();que.pop();
        int md=p.first,u=p.second.first,t=p.second.second;
        if(md>d[u]) continue;
        if(t!=-1) used[t][u]=used[u][t]=true;
        for(auto e:G[u]){
            int v=e.first,c=e.second;
            if(d[v]>d[u]+c){
                d[v]=d[u]+c;
                que.push(P(d[v],pii(v,u)));
            }
        }
    }
}
int main(){
    cin>>N>>M;
    G=vector<vector<pii> >(N);
    used=vector<vector<bool> >(N,vector<bool>(N,true));
    for(int i=0;i<M;++i){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        G[a].push_back(pii(b,c));
        G[b].push_back(pii(a,c));
        used[a][b]=used[b][a]=false;
    }
    for(int i=0;i<N;++i){
        dijkstra(i);
    }
    int ans=0;
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            if(!used[i][j]) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

int main() {

    int n;
    cin >> n;

    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];

    int count = 0;
    for(int i = 1; i < n-1; i++) {
        if(v[i] < v[i-1] && v[i] > v[i+1] || v[i] > v[i-1] && v[i] < v[i+1])
            count++;
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int main() {
	int n, lcm, a[10];
	cin >> n;
	cin >> a[0];
	lcm = a[0];
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		lcm = lcm * a[i] / gcd(lcm, a[i]);
	}
	cout << lcm << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int n,k;
int sum[4040][4040];
int b[2020][2020];

int calc(int x,int y){
  return(sum[y+k][x+k]-sum[y+k][x]-sum[y][x+k]+sum[y][x]);
}

int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int x,y;
    char c;
    cin>>x>>y>>c;
    if(c=='W') x+=k;
    x%=2*k;
    y%=2*k;
    b[y][x]++;
  }

  for(int i=0;i<4*k;i++){
    for(int j=0;j<4*k;j++){
      sum[i][j]=b[i%(2*k)][j%(2*k)];
    }
  }

  for(int i=0;i<4*k;i++){
    for(int j=1;j<4*k;j++){
      sum[i][j]+=sum[i][j-1];
    }
  }

  for(int i=1;i<4*k;i++){
    for(int j=0;j<4*k;j++){
      sum[i][j]+=sum[i-1][j];
    }
  }

  int ans=0;
  for(int i=0;i<2*k;i++){
    for(int j=0;j<2*k;j++){
      int tmp;
      tmp=calc(j,i)+calc(j+k,i+k);
      ans=max(ans,tmp);
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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 char EOL = '\n';
const int MOD = 1000000007;
const int INF = 1000000001;

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

void solve() {
    vector<int> a(5);
    int mn = 10;
    REP(i, 5) {
        cin >> a[i];
        if (a[i] % 10 != 0) chmin(mn, a[i] % 10);
    }

    auto f = [](int n) { return n + (10 - (n % 10)) % 10; };

    int t = 0;
    REP(i, 5) t += f(a[i]);

    cout << t - (10 - mn) << EOL;
}



Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false),in.tie(0),cout.tie(0);
#define input freopen("input.in","right_interval",stdin);
#define output freopen("output.out","w",stdout);
#define e printf("\n");
#define all(it,v) for(it=(v).begin();it!=(v).end();it++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define si(x) scanf("%d",&x)
#define sf(x) scanf("%f",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x);
#define pf(x) printf("%f",x);
#define pl(x) printf("%lld",x);
typedef vector<vector<ll> > mat;
const ll mx=100001;
const ll mod=1000000007;
const ll inf=0x3f3f3f3f;
//ifstream in("input.txt");
//ofstream out("output.txt");
void solve();
int main()
{
  int t=1;
//  si(t);
  rep(i,1,t)
  {
    solve();
    if(i!=t) e
  }
  return 0;
}
int dp[mx];
int ar[mx];
void solve()
{
  int i,j,k,m,n;
  dp[0]=0;
  si(n);
  rep(i,0,n-1) si(ar[i]);
  dp[1]=abs(ar[0]-ar[1]);
  rep(i,2,n-1)
    dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
  cout<<dp[n-1];  
}





























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

typedef struct shutugen{
	char words[33];
	int kaisu;
}shutugen;

int main(void){
	int i,j,k,topkaisu,endflag=0;
	char words[1001];
	shutugen tango[1000];
	
	// 文字列を読み込む
	scanf("%[^\n]",words);
	getchar();
	
	// 文字列を単語に分ける
	j=0,k=0;
	for(i=0;words[i] != '\0';i++){
		if(isalpha(words[i])){
			tango[j].words[k]=words[i];
			k++;
		}else if(words[i] = ' '){
			k = 0;
			j++;
		}
	}
	
	//最も出現頻度が高い単語を探す
	topkaisu = 0;
	for(i=0;tango[i].words[0] != '\0';i++){
		for(j=i+1;tango[j].words[0] != '\0';j++){
			if(strcmp(tango[i].words,tango[j].words) == 0){
				tango[i].kaisu+=1;
				if(topkaisu < tango[i].kaisu) topkaisu = tango[i].kaisu;
			}
		}
	}
	//表示
	for(i=0;tango[i].words[0] != '\0';i++){
		if(topkaisu == tango[i].kaisu){
			printf("%s ",tango[i].words);
			break;
		}
	}
	
	// 文字数が多い単語を探す
	for(i=32;i > 0;i--){
		for(j=0;tango[j].words[0] != '\0';j++){
			if(isalpha(tango[j].words[i])){
				printf("%s\n",tango[j].words);
				endflag = 1;
				break;
			}
		}
		if(endflag == 1) break;
	}
	return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f;
	cin>>n>>k;
	ll ans=1,temp=0;
	for(i=k;i<=n;i++)
	{
	    temp=i*(n+n-i+1)/2;
	    ans+=temp-(i*(i-1))/2+1;
	}
	cout<<ans%MOD;
	return 0;
}


Measured memory_bytes: 3660
def factorize(n):
    x = 2
    f = []
    while x**2 <= n:
        c = 0
        if n % x != 0:
            x += 1
            continue
        else:
            while n % x == 0:
                n //= x
                c += 1
            f.append([x, c])
        x += 1

    if n > 1:
        f.append([n, 1])
    return f

n = int(input())
f = factorize(n)
ans = 0
for el in f:
    m = el[1]
    i = 1
    while True:
        if i*(i+1)//2 > m:
            ans += i-1
            break
        i += 1

print(ans)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007

vector<double> p;
double memo[3000][3000];

double dp(int pos, int c, int n)
{
    if(pos==n)
        return (c<<1)>=n;
    if(memo[pos][c]!=-1)
        return memo[pos][c];
    return memo[pos][c]=p[pos]*dp(pos+1, c+1, n)+(1-p[pos])*dp(pos+1, c, n);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        double x;
        cin>>x;
        p.pb(x);
    }
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            memo[i][j]=-1;
    cout<<setprecision(12)<<dp(0, 0, n);
    return 0;
}

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

ll x[100005];
int main()
{
    ll n,a,b;
    ll sum;
    while(cin >> n >> a >> b)
    {
        sum = 0;
        for(int i = 0;i < n;i++)
            cin >> x[i];
        for(int i = 1;i < n;i++)
        {
            sum += min((x[i] - x[i - 1])* a,b);
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
p = list(map(int, input().split()))
s = 0
for i in range(n - 2):
    if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
        s += 1
    elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
        s += 1
print(s)

Measured memory_bytes: 2940
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#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
#define endl "\n"
using namespace std;

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

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

  vector<string> strs = { "pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon" };
  int n;
  cin >> n;

  cout << strs[n%10] << endl;
  return 0;
}

Measured memory_bytes: 3660