akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        N -= a;
    }
    if (N < 0) puts("-1");
    else cout << N << endl;
}

Measured memory_bytes: 3600
from sys import stdin
N = int(stdin.readline().rstrip())
H = [int(_) for _ in stdin.readline().rstrip().split()] 
dp = [10**9] * (N+1)
dp[0] = 0
for i in range(N):
    if i+1 < N:
        dp[i+1] = min(dp[i] + abs(H[i]-H[i+1]), dp[i+1])
    if i+2 < N:
        dp[i+2] = min(dp[i] + abs(H[i]-H[i+2]), dp[i+2])
print(dp[N-1])

Measured memory_bytes: 14052
<?php
fscanf(STDIN, "%d", $n);
$s = $p = $q = 0;
while ($n--) {
	fscanf(STDIN, "%d %d %d", $t, $x, $y);
	$t1 = $t - $s;
	$d1 = abs($p - $x) + abs($q - $y);
	if ($d1 > $t1 || $d1 % 2 != $t1 % 2) {
		exit('No');
	}
	$s = $t; $p = $x; $q = $y;
}
echo 'Yes';

Measured memory_bytes: 4604
import java.util.Scanner;
 
class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);    
    int n = in.nextInt();
    int[] A = new int[n];
    for (int i = 0; n != 0; i++) {
      A[i] = in.nextInt();
      n--;
    }
     
    int q = in.nextInt();
    int[] M = new int[q];
    for (int i = 0; q != 0; i++) {
      M[i] = in.nextInt();
      q--;
    }
     
    for (int i = 0; i < M.length; i++) {
      System.out.println((dfs(0, A, 0, M[i])) ? "yes" : "no" );
    }
  }
  static boolean dfs(int p, int[] A, int t, int sum) {
    if (t > sum ) return false;
    if (p == A.length) return t == sum;
    if (dfs(p + 1, A, t + A[p], sum)) return true;
    if (dfs(p + 1, A, t, sum))        return true;
    return false;
  }
}

Measured memory_bytes: 20784
// Problem : A - Round One
// Contest : AtCoder - AtCoder Beginner Contest 148
// URL : https://atcoder.jp/contests/abc148/tasks/abc148_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int a,b;
    cin>>a>>b;
    cout<<6-a-b;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <math.h>

#define N 10000

int check_prime (int num) {
	int i = 3;

	if (num == 2) return 1; 
	if (num % 2 == 0) return 0;

	while (i <= sqrt(num)) {
		if (num % i == 0) return 0;
		i = i + 2;
	}

	return 1;
}

int main () {
	int n,i;
	int counter = 0;
	int A[N];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		counter += check_prime(A[i]);
	}

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

	return 0;
}

Measured memory_bytes: 632
#include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
while(a!=0 and b!=0){
for(int i=0;i<b;i++)cout<<'#';
cout<<endl;
for(int i=0;i<a-2;i++){
cout<<'#';
for(int j=0;j<b-2;j++)
cout<<'.';
cout<<'#'<<endl;
}
for(int i=0;i<b;i++)cout<<'#';
cout<<endl<<endl;
cin>>a>>b;
}
return 0;
}


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

void solve()
{
	int n;
	cin >> n;
	long long int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
			sum += i;
	}
	cout << sum << "\n";
	return;
}
int main()
{
	solve();





	return 0;
}

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

int main(){
	char a[11];
	scanf("%s",a);
	for(int i=0;i<strlen(a);i++){
		int db=0;
		if(a[i]=='B'&&i!=0){
			int j=i;
			int k=1;
			while(a[j]=='B'){
				a[i-k]='B';
				k++;
				j++;
			}
			db++;
		}
	}
	for(int i=0;i<strlen(a);i++){
		if(a[i]!='B'){
			printf("%c",a[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1660
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

N = getN()
D = getList()
if D[0] != 0:
    print(0)
    exit()
D = Counter(D)
D = sorted(D.items(), key = lambda x: x[0])
if D[0][1] != 1:
    print(0)
    exit()

x1 = 0
y1 = 1
ans = 1
for i in D[1:]:
    if x1 + 1 != i[0]:
        ans = 0
        break
    ans *= y1 ** i[1]
    x1 = i[0]
    y1 = i[1]
print(ans % 998244353)

Measured memory_bytes: 94136
#include <bits/stdc++.h>
using namespace std;
const int MAXN=500010;
const int MOD=1e9+7;
int N,fa[MAXN],ans[MAXN],F[MAXN],size[MAXN],fac[MAXN],inv[MAXN];
int tot,head[MAXN];
struct Edge {int to,net;}E[MAXN<<1];
void addedge(int x,int y)
{
	E[++tot].to=y;E[tot].net=head[x];head[x]=tot;
	E[++tot].to=x;E[tot].net=head[y];head[y]=tot;
}
int POW(int x,int k)
{
	int ans=1;
	for (;k;k>>=1,x=1LL*x*x%MOD) if (k&1) ans=1LL*ans*x%MOD;
	return ans;
}
void dfs(int x)
{
	F[x]=1;
	size[x]=1;
	for (int i=head[x];i;i=E[i].net)
		if (E[i].to!=fa[x])
		{
			fa[E[i].to]=x;
			dfs(E[i].to);
			F[x]=1LL*F[x]*F[E[i].to]%MOD;
			F[x]=1LL*F[x]*inv[size[E[i].to]]%MOD;
			size[x]+=size[E[i].to];
		}
	F[x]=1LL*F[x]*fac[size[x]-1]%MOD;
}
void dfs2(int x)
{
	ans[x]=F[x];
	//printf("root=%d\n",x);
	//for (int i=1;i<=N;++i) printf("%d ",F[i]);printf("\n");
	for (int i=head[x];i;i=E[i].net)
		if (E[i].to!=fa[x])
		{
			int a=F[x];
			int b=F[E[i].to];
			int c=size[x];
			int d=size[E[i].to];
			F[x]=1LL*F[x]*fac[d]%MOD;
			F[x]=1LL*F[x]*inv[c-1]%MOD;
			size[x]-=size[E[i].to];
			F[x]=1LL*F[x]*fac[c-d-1]%MOD;
			F[x]=1LL*F[x]*POW(b,MOD-2)%MOD;
			
			F[E[i].to]=1LL*F[E[i].to]*inv[c-d]%MOD;
			F[E[i].to]=1LL*F[E[i].to]*inv[d-1]%MOD;
			size[E[i].to]=c;
			F[E[i].to]=1LL*F[E[i].to]*fac[c-1]%MOD;
			F[E[i].to]=1LL*F[E[i].to]*F[x]%MOD;
			
			dfs2(E[i].to);
			F[x]=a;
			F[E[i].to]=b;
			size[x]=c;
			size[E[i].to]=d;
		}
}
int main()
{
	fac[0]=1;
	for (int i=1;i<MAXN;++i) fac[i]=1LL*fac[i-1]*i%MOD;
	inv[MAXN-1]=POW(fac[MAXN-1],MOD-2);
	for (int i=MAXN-2;i>=0;--i) inv[i]=1LL*inv[i+1]*(i+1)%MOD;
	cin>>N;
	for (int i=1;i<N;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y);
	}
	/*
	for (int i=1;i<=N;++i)
	{
		fa[i]=0;
		dfs(i);
		ans[i]=F[i];
	}
	*/
	dfs(1);
	dfs2(1);
	for (int i=1;i<=N;++i) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 20736
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

n = read()
a = reads()

result = 10**16

sig = (1, -1)

count = 0
psum = 0
for i in range(n):
  psum += a[i]
  if psum * sig[i%2] <= 0:
    count += 1 - psum * sig[i%2]
    psum = sig[i%2]

result = count

count = 0
psum = 0
for i in range(n):
  psum += a[i]
  if psum * sig[(i+1)%2] <= 0:
    count += 1 - psum * sig[(i+1)%2]
    psum = sig[(i+1)%2]

result = min(result, count)

print(result)


Measured memory_bytes: 14824
#include <bits/stdc++.h>
using namespace std;
 
const int Shurui=26;//今回は26種類
int Date;//今回は1年間なので365日
long long Seigenjikan=1800000;//実行時間
long long s[400][Shurui];
long long c[Shurui];
long long last[Shurui];

long long range(long long l,long long r){
  long long len=r-l-1;
  return -len*(len+1)/2;
}
struct ContestJouhou{
  set<long long>kaisai[Shurui];
  vector<long long>t;
  int Date;
  long long tensuu=0;
  ContestJouhou(int Date):Date(Date){
    t.resize(Date,-1);
    for(int i=0;i<Shurui;i++){
      kaisai[i].insert(-1);
      kaisai[i].insert(Date);
      tensuu+=c[i]*range(-1,Date);
    }
  }
  void tasu(int d,int q){
    if(t[d]!=-1){
      cout<<"tasemasendesita"<<endl;
      exit(1);
    }
    t[d]=q;
    tensuu+=s[d][q];
    kaisai[q].insert(d);
    auto it=kaisai[q].find(d);
    auto rit=next(it);
    auto lit =prev(it);
    tensuu-=c[q]*range(*lit,*rit);
    tensuu+=c[q]*range(*it,*rit);
    tensuu+=c[q]*range(*lit,*it);
  }
  void hiku(int d){
    if(t[d]==-1){
      cout<<"hikemasendesita"<<endl;
      exit(1);
    }
    int q=t[d];
    t[d]=-1;
    tensuu-=s[d][q];
    auto it=kaisai[q].find(d);
    auto rit=next(it);
    auto lit=prev(it);
    tensuu+=c[q]*range(*lit,*rit);
    tensuu-=c[q]*range(*it,*rit);
    tensuu-=c[q]*range(*lit,*it);
    kaisai[q].erase(it);
  }
  void kaeru(int d,int q){
    hiku(d);
    tasu(d,q);
  }
};
      

int main() {
  clock_t start = clock();
  cin >>Date;
  //vector<int>c(400,0);
  //vector<int>last(400,0);//前回の日にち
  //vector<int>t(400,0);//開催する順番
  //for(int i=0;i<Date;i++)t[i]=i%Shurui;//とりあえずの値
  long long wa=0;
  for(int i=0;i<Shurui;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<Date;i++){
    for(int j=0;j<Shurui;j++){
      cin>>s[i][j];
    }
  }
  ContestJouhou cj(Date);
  for(int i=0;i<Date;i++){
    long long t=i%Shurui;
    cj.tasu(i,t);
  }
  
  long long tensuu=cj.tensuu;
  
  clock_t end = clock();
  long long time = end - start;
  while(time<Seigenjikan){
    int d=rand()%Date;
    int q=rand()%Shurui;
    int old=cj.t[d];
    cj.kaeru(d,q);
    long long new_tensuu=cj.tensuu;
    //cout<<new_tensuu<<endl;
    if(new_tensuu<tensuu){
      cj.kaeru(d,old);
    }else{
      tensuu=new_tensuu;
    }
    end = clock();
    time = end - start;
  }
  for(int i=0;i<Date;i++){
    cout<<cj.t[i]+1<<endl;
  }
  return 0;
}

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

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

typedef long long LL;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  int mi=n,ma=0;
  for(int i=0;i<n;i++){
    mi=min(mi,a[i]);
    ma=max(ma,a[i]);
  }
  if(ma-mi>1){
    cout << "No" << endl;
    return 0;
  }
  if(ma==mi){
    if((1<=ma&&ma<=n/2)||ma==n-1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else{
    int mic=0,mac=0;
    for(int i=0;i<n;i++){
      if(a[i]==ma) mac++;
      else mic++;
    }
    if(1<=ma-mic&&ma-mic<=mac/2) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005,mod=1e9+7;
int n,k,f[N][N],fac[N*N],ifac[N*N];
int Pow(int x,int k){
	int ret=1;
	while(k){
		if(k&1)ret=(ll)ret*x%mod;
		k>>=1;x=(ll)x*x%mod;
	}
	return ret;
}
int C(int n,int m){
	if(n<m)return 0;
	return (ll)fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
int main(){
	scanf("%d%d",&n,&k);
	fac[0]=1;
	for(int i=1;i<=n*k;i++)fac[i]=(ll)fac[i-1]*i%mod;
	for(int i=0;i<=n*k;i++)ifac[i]=Pow(fac[i],mod-2);
	if(k==1){
		puts("1");
		return 0;
	}
	f[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=i;j<=n;j++){
			f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
			f[i][j+1]=(f[i][j+1]+(ll)f[i][j]*C((k-1)*j+i+k-2,k-2))%mod;
		}
	cout<<(ll)f[n][n]*fac[n]%mod<<"\n";
}

Measured memory_bytes: 47360
import java.util.Scanner;


public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();
        if(s.length()<=a){
            System.out.println(s);
        }
        else{
            System.out.println(s.substring(0,a)+"...");
        }
    }
}



Measured memory_bytes: 38624
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;

vector<long long> buf;

long long ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

long long calc(long long n) {
   if (n < 3) {
      return 0;
   }
   if (n >= 3) {
      return n * (n - 1) * (n - 2) * pow(3, n - 3);
   }
}


void dfs(long long i, const long long size, const long long range_start, const long long range_end, long long &cnt, long long N)
{
   if (i == size) {
      long long tmp = 0;
      for(long long i = 0; i < buf.size(); ++i){
         tmp += buf[i] * pow(10, buf.size() - 1 - i);
      }
      if (tmp <= N) {
         string s = to_string(tmp);
         long long cnt3 = 0;
         long long cnt5 = 0;
         long long cnt7 = 0;
         bool flg = true;
         for (long long j = 0; j < (long long)s.size(); j++) {
            if (s[j] == '3') cnt3++;
            else if (s[j] == '5') cnt5++;
            else if (s[j] == '7') cnt7++;
         }
         if (cnt3 > 0 && cnt5 > 0 && cnt7 > 0) {
            cnt++;
         }
      }
   }
   else{
      for(long long j = range_start; j <= range_end; ++j){
         if (j == 1) buf[i] = 3;
         if (j == 2) buf[i] = 5;
         if (j == 3) buf[i] = 7;
         dfs(i + 1, size, range_start, range_end, cnt, N);
      }
   }
}

int main() {
   long long N;
   cin >> N;
   long long ans = 0;
   string S = to_string(N);
   long long len = (long long)S.size();

   long long range_start = 1;
   long long range_end = 3;
   buf.resize(len);
   dfs(0, len, range_start, range_end, ans, N);

   if (len - 1  >= 3) ans += 6;
   if (len - 1  >= 4) ans += 36;
   if (len - 1  >= 5) ans += 150;
   if (len - 1  >= 6) ans += 540;
   if (len - 1  >= 7) ans += 1806;
   if (len - 1  >= 8) ans += 5796;
  
   cout << ans << endl;
   return 0;

}


Measured memory_bytes: 256
n = int(input())
s = [int(i) for i in input().split()]
i = 0
sss = 0
ans = 0
while i < n-1:
    ss = s[i]
    if s[i+1] <= ss:
        sss += 1
        ans = max(ans, sss)
    else:
        sss = 0
    i += 1
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{

	string s, t;
	cin >> s >> t;

	string alph = "abcdefghijklmnopqrstuvwxyz";
	mat alphpos(26, vec(0));
	vec alphmax(26, -1);

	ll S = s.length();
	REP(i, S) {
		REP(j, 26) {
			if (s[i] == alph[j]) {
				alphpos[j].emplace_back(i);
				alphmax[j] = max(alphmax[j], i);
			}
		}
	}

	// vdebug(alphpos[19]);

	ll tlen = t.length();
	ll ansloop = 0;
	ll jnow = -1;
	// ll anslastid = -1;
	// ll loopwithnoans = 0;
	// ll tnow = 0;

	ll alphanow = -1;
	REP(i, tlen) {
		// ansloop++;
		REP(alpha, 26) {
			if (t[i] == alph[alpha]) alphanow = alpha;
		}
		if (alphpos[alphanow].size() == 0) {
			cout << -1 << endl;
			return 0;
		}
		if (jnow + 1 > alphmax[alphanow]) {
			ansloop++;
			jnow = -1;
			jnow = alphpos[alphanow][Lower_bound(alphpos[alphanow], jnow + 1)];
			// debug(ansloop);
		} else {
			jnow = alphpos[alphanow][Lower_bound(alphpos[alphanow], jnow + 1)];
			// debug(alph[alphanow]);
			// debug(jnow);
		}
	}

	ll ans = ansloop * S + jnow + 1;
	cout << ans << endl;
	// 	loopwithnoans++;
	// 	if (loopwithnoans > 3) break;
	// 	REP(j, s.length()) {
	// 		if (s[j] == t[tnow]) {
	// 			loopwithnoans--;
	// 			anslastid = j;
	// 			if (tnow == tlen - 1) {
	// 				ll ans = (ansloop - 1) * s.length() + anslastid + 1;
	// 				cout << ans << endl;
	// 				return 0;
	// 			} else {
	// 				tnow++;
	// 			}
	// 		}
	// 	}
	// }

	return 0;
}

Measured memory_bytes: 1724
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if(n==1){
            System.out.println("Hello World");
        }
        else{
            int a=scanner.nextInt(),b=scanner.nextInt();
            System.out.println(a+b);
        }
    }
}

Measured memory_bytes: 21844
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer; 
  
public class Main
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
  
    public static void main(String[] args) 
    { 
        FastReader fr = new FastReader(); 
        
        int N = fr.nextInt();
        
        int[] h = new int[N];
        int[] dp = new int[N];
        
        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;
        
        for(int i = 0; i < N; i++) {
        	h[i] = fr.nextInt();
        }
        
        for (int i = 0; i < N; i++) {
        	if (i+1 < N) {
        		dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(h[i] - h[i+1])); 
        	} if (i+2 < N) {
        		dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(h[i] - h[i+2]));
        	}
        }
        
        System.out.println(dp[N-1]);
        
    }

}

Measured memory_bytes: 42668
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    cout << (n * (n + 1)) / 2 << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b,c;
    int x=0,y=0,z=0;
    cin>>a>>b>>c;
    string k="a";
    for(int i=1;;i++){
    	if(k=="a"){
    	    k=a.substr(0,1);
		    a=a.erase(0,1);
		    if(x==1){
		    	cout<<"A";
		    	return 0;
			}
		    if(a==""){
		       x=1;
			}
		}
		if(k=="b"){
    	    k=b.substr(0,1);
		    b=b.erase(0,1);
		    if(y==1){
		    	cout<<"B";
		    	return 0;
			}
		    if(b==""){
		       y=1;
			}
		}
		if(k=="c"){
    	    k=c.substr(0,1);
		    c=c.erase(0,1);
		    if(z==1){
		    	cout<<"C";
		    	return 0;
			}
		    if(c==""){
		       z=1;
			}
		}
		}
	}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
        for (int i = 1; i <= 9; i++) {
                for (int j = 1; j <= 9; j++) {
                        cout << i << "x" << j << "=" << i * j << endl;
                }
        }
        return 0;
}

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

using namespace std;

int main(void){
    int a,b;
    int max=-10000,tmp;

    cin>>a>>b;;

    tmp=a+b;
    if(max<=tmp){
        max=tmp;
    }
    tmp=a-b;
    if(max<=tmp){
        max=tmp;
    }
    tmp=a*b;
    if(max<=tmp){
        max=tmp;
    }
    
    cout<<max<<endl;

    
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(55);
    vector<int> t(55);
    for (int i = 0; i < n; i++) {
        cin >> s.at(i) >> t.at(i);
    }
    string x;
    cin >> x;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (s.at(i) == x) {
            break;
        }
        ans += t.at(i);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	s += 'Y';
	vector<int> wh(n + 1,0),bl(n+1,0);
	int co = 0;
	for (int i = 1;i < n + 1;i++) {
		if (s[i-1] == '#')
			co++;
		wh[i] = co;
	}
	co = 0;
	for (int i= n-1;i >= 0;i--) {
		if (s[i] == '.')
			co++;
		bl[i] = co;
	}
	int ans = 200000;
	for (int i = 0;i < n + 1;i++) {
		ans = min(ans, wh[i] + bl[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a;
	string b;
	cin>>a>>b;
	long long b2=(b[0]-'0')*100,b3=(b[2]-'0')*10,b4=(b[3]-'0');
	long long ans=a*(b2+b3+b4);
	ans=ans/100;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

int cnt = 0;


void solve()
{
	ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;
	if (2 * c <= a + b)
	{
		if (x > y)
		{
			cout << min(y * 2 * c + (x - y) * a, x * 2 * c);
		}
		else
		{
			cout << min(x * 2 * c + (y - x) * b, y * 2 * c);
		}
	}
	else
	{
		cout << x * a + y * b;
	}
	
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

#define MAX_N 40
ll w[MAX_N],v[MAX_N];
pair<ll,ll> ps[1<<(MAX_N/2)];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll W;
    cin>>N>>W;
    REP(i,N) cin>>v[i]>>w[i];
    int n2=N/2;
    
    for(int i=0;i<(1<<n2);i++){
        ll sw=0,sv=0;
        for(int j=0;j<n2;j++){
            if(i>>j & 1){
                sw += w[j];
                sv += v[j];
            }
        }
        ps[i] = make_pair(sw,sv);
    }

    sort(ps,ps+(1<<n2));
    ll m=1;
    for(int i=1;i<(1<<n2);i++){
        if(ps[m-1].second<ps[i].second) ps[m++] = ps[i];
    }
    ll res = 0;
    for(int i=0;i<(1<<(N-n2));i++){
        ll sw=0,sv=0;
        for(int j=0;j<N-n2;j++){
            if(i>>j & 1){
                sw += w[n2+j];
                sv += v[n2+j];
            }
        }
        if(sw<=W){
            ll tv = (lower_bound(ps,ps+m,LP(W-sw,LINF))-1)->second;
            chmax(res,sv+tv);
        }
    }
    cout<<res<<endl;
}



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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll W,H,x,y;cin>>W>>H>>x>>y;
  cout<<(double)H*W/2<<" "<<(x*2==W&&y*2==H?1:0)<<endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    l = list(map(int, input().split(' ')))
    l.sort()
    if l[0] == 0:
        print(0)
        return
    
    total = 1

    for i in l:
        total = total * i
        if (total > 1000000000000000000):
            print(-1)
            return
    
    print(total)

main()

Measured memory_bytes: 21704
#include <bits/stdc++.h>
using namespace std;
#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 rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
  double a,b,c;
  cin>>a>>b>>c;
  double d=min(b-1,c);
  cout<<floor(a*d/b);
}

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

using namespace std;

int main()
{
    int n, I;
    cin >> n;
    long double X[n], Y[n], an, SX[n+1], SY[n+1], sx, sy, M=0;
    vector <pair<long double,int>> V;
    for (int i = 0; i < n; i++)
    {
        cin >> X[i] >> Y[i];
        an = atan2(X[i],Y[i]);
        V.push_back({an,i});
    }
    sort(V.begin(),V.end());
    SX[0] = 0;
    SY[0] = 0;
    for (int i = 0; i < n; i++)
    {
        I = V[i].second;
        SX[i+1] = SX[i] + X[I];
        SY[i+1] = SY[i] + Y[I];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int y = 1; y <= n; y++)
        {
            if (i <= y)
            {
                sx = SX[y] - SX[i-1];
                sy = SY[y] - SY[i-1];
            }
            else
            {
                sx = SX[y] + SX[n] - SX[i-1];
                sy = SY[y] + SY[n] - SY[i-1];
            }
            M = max(M, sqrt(sx*sx + sy*sy));
        }
    }
    cout << fixed << setprecision(11) << M;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#define SIZE 10
using namespace std;
typedef long long ll;

int main(void){

	int N;
	int i,j;
	int tmp;
	int counter=0;
	double answer;
	double ave;
	vector<int> given;

	cin >> N;

	for(i=1;i<=N;i++){
		if(i%2) counter++;
	}

	printf("%.10f\n",(double)counter/N);
	return 0;
}



Measured memory_bytes: 256
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let nums = get_line().split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect::<Vec<usize>>();
    let (n, a, b) = (nums[0], nums[1], nums[2]);

    let (repeat_count, diff) = (n / (a + b), n % (a + b));
    let sum;
    if diff > a {
        sum = repeat_count * a + a;
    } else {
        sum = repeat_count * a + diff;
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
		int b = scn.nextInt();
      	if(a<=8 && b<=8){
          System.out.println("Yay!");
        }else{
          System.out.println(":(");
        }
	}
}

Measured memory_bytes: 35668
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void) {

	double r;
	cin >> r;

	//cout << r*r*M_PI << " " << 2*r*M_PI << endl;
	printf("%.6f %.6f", r*r*M_PI, 2*r*M_PI);
	cout << endl;

	return 0;
}

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

int main() 
{
    int a,b;
    cin >> a >> b;
    int x = b-a, sum=0;
    for (int i=1; i<=x; i++)
        sum += i;
    cout << sum - b;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		String s[] = S.split("/");

		if (s[1].equals("04") || s[1].equals("01") || s[1].equals("02") || s[1].equals("03")) {
			System.out.println("Heisei");
		} else {
			System.out.println("TBD");
		}
	}
}

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

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

	int n = s.size();
	int ans = 0;
	int cnt = 0;
	rep(i, n) {
		if (s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T') {
			ans = max(cnt, ans);
			cnt = 0;
		}
		else {
			cnt++;
			if (i == n - 1) ans = max(cnt, ans);
		}
	}
	cout << ans << endl;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	long long a, b;
	cin >> a >> b;
	for (int i = 1; i < n; i++) {
		long long x, y;
		cin >> x >> y;
		long long k = (a + x - 1) / x;
		k = max(k, (b + y - 1) / y);
		a = x * k;
		b = y * k;
	}
	cout << a + b << endl;
	return 0;
}



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

//#define int long long
#define DEBUG 1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	string A = "012345678954321012345678954321";
	int n; cin >> n;
	rep(i,0,n){
		int a, b; cin >> a >> b;
		string ans = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
		rep(i, 0, A.size() / 2) {
			if (A[i] - '0' != a) continue;
			string temp = "";
			temp += A[i];
			rep(j, i + 1, A.size()) {
				temp += " ";
				temp += A[j];
				if (A[j] - '0' == b) break;
			}
			if (temp.size() < ans.size())ans = temp;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
from itertools import combinations_with_replacement

def main():
    n, m, q = [int(i) for i in input().split()]
    arr = []
    for _ in range(q):
        arr.append([int(i) for i in input().split()])
    base = [int(i+1) for i in range(m)]

    max_score = 0
    for comb in combinations_with_replacement(base, n):
        score = 0
        for ar in arr:
            a, b, c, d = ar
            if comb[b-1] - comb[a-1] == c:
                score += d
        max_score = max(max_score, score)
    print(max_score)

if __name__ == '__main__':
    main()



Measured memory_bytes: 9116
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int[][]cnt=new int[10][10];
		for(int i=1;i<=n;i++) {
			int last=i%10;
			int first=i;
			while(first>=10)first/=10;
			cnt[first][last]++;
		}
		long ans=0;
		for(int i=1;i<=9;i++) {
			for(int j=1;j<=9;j++) {
				ans+=cnt[i][j]*1l*cnt[j][i];
			}
		}
		pw.println(ans);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cassert>
#include <cmath>


using namespace std;
using ll = long long int;

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

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  ll N; cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  ll ans;
  if (N % 2 == 1) {
    ans = B[N / 2] - A[N / 2] + 1;
  } else {
    ll l = (A[N / 2] + A[N / 2 - 1]);
    ll r = (B[N / 2] + B[N / 2 - 1]);

    ans = (r - l) + 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (ll i = j; i <= n; i++)
#define per(i, j, n) for (ll i = j; i >= n; i--)
#define ll long long
#define ld long double
#define ld long double
#define ii pair<ll, ll>
#define vii vector<ii>
#define vi vector<ll>
#define adj unordered_map<ll, vii>
#define MOD 1000000007
#define PI 3.14159265359
#define db1(x) cout << #x " = " << x << endl;

void i1d(vi &v) {
  for (auto &i : v)
    cin >> i;
}

void p1d(vi &v) {
  for (auto i : v)
    cout << i << ' ';
  cout << endl;
}

vi x(5);

void solve() {
  // Code goes here
  i1d(x);
  rep(i, 0, 4) {
    if (x[i] == 0) {
      cout << i + 1 << '\n';
      break;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

vector<int> a, b, c, d, v;
int best = 0;

void solve(int step, int curr, int n, int m, int q) {
	if (step == n) {
		int s = 0;
		for (int i = 0; i < q; i++) {
			if (v[b[i] - 1] - v[a[i] - 1] == c[i]) s += d[i];
		}
		best = max(best, s);
	}
	else {
		for (int i = curr; i <= m; i++) {
			v[step] = i;
			solve(step + 1, i, n, m, q);
		}
	}
}

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

	int n, m, q, i, j, k;
	cin >> n >> m >> q;

	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	for (i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

	v.resize(n);
	solve(0, 1, n, m, q);

	cout << best << "\n";

	return 0;
}




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

string s;
void solve(){
  cin >> s;
  int id = s.size();
  while(id > 0){
    string a;
    if(id - 5 >= 0){
      a = s.substr(id - 5, 5);
      if(a == "dream" || a == "erase"){
        id -= 5;
        continue;
      }
    }
    if(id - 6 >= 0){
      a = s.substr(id - 6, 6);
      if(a == "eraser"){
        id -= 6;
        continue;
      }
    }
    if(id - 7 >= 0){
      a = s.substr(id - 7, 7);
      if(a == "dreamer"){
        id -= 7;
        continue;
      }
    }
    break;
  }
  if(id == 0) cout << "YES\n";
  else cout << "NO\n";
  return;
}

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


Measured memory_bytes: 512
using namespace std;
#include<iostream>
#include <string>
using namespace std;
int p1[10] = { };
int p2[10][10] = { };
int p3[10][10][11] = { };

char S[30000] = { };
int N;
void pin2(int n1, int n2, int a) {
  for (; a < N; a++) {
    int num = S[a] - '0';
    if (p3[n1][n2][num] == 0) {
      p3[n1][n2][num] = 1;
      p3[n1][n2][10] += 1;
      if (p3[n1][n2][10] == 10) {
        break;
      }
    }
  }
}
void pin1(int n1, int a) {
  for (; a < N - 1; a++) {
    int num = S[a] - '0';
    if (p2[n1][num] == 0) {
      p2[n1][num] = 1;
      pin2(n1, num, a + 1);
    }
  }
}
int main() {
  cin >> N;
  cin >> S;
  for (int a = 0; a < N - 2; a++) {
    int num = S[a] - '0';
    if (p1[num] == 0) {
      p1[num] = 1;
      pin1(num, a + 1);
    }
  }
  int sum = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      sum += p3[i][j][10];
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

void ignore() {
    while (getchar() != '\n');
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    ll N, C, K;

    scanf("%lld %lld %lld", &N, &C, &K);

    vector<ll> T(N);
    ll waiting, next;
    ll riding = 1;
    ll ans = 0;

    ll i, last;

    for (i = 0; i < N; i++) scanf("%lld", &T[i]);

    sort(T.begin(), T.end());

    waiting = T[0];
    riding = 1;
    last = N - 1;
    for (i = 1; i < N; i++) {
        next = T[i];

        if (next <= waiting + K) {
            if (C < riding + 1) {
                ans++;
                riding = 1;
                waiting = next;
            } else {
                riding++;
            }
        } else {
            ans++;
            riding = 1;
            waiting = next;
        }

        if (i == last) ans++;
    }

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

    return 0;
}


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

using namespace std;
using i64 = int64_t;
using ui64 = uint64_t;

/////

const i64 mod = (i64)1e9+7;

i64 power(i64 e, i64 x){
    if(x == 0)return 1LL;
    i64 p = power(e, x/2);
    if(x&1)return p * p % mod * e % mod;
    else return p * p % mod;
}

int main(){
    i64 e,x;
    cin >> e >> x;
    cout << power(e,x) << endl;
}


Measured memory_bytes: 3092
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long int;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 373;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> init_vector2(size_t n0, size_t n1, T e = T()) {
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> init_vector3(size_t n0, size_t n1, size_t n2, T e = T()) {
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int cnt = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int v = i * 500 + j * 100 + k * 50;
                if (v == x) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


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

constexpr int INF = 1e9;

int main() {
    int n;
    while(cin >> n, n) {
        vector<vector<int>> d(10, vector<int>(10, INF));
        for(int i=0; i<10; ++i) {
            d[i][i] = 0;
        }
        for(int i=0; i<n; ++i) {
            int a, b, c;
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
        }
        for(int k=0; k<10; ++k) {
            for(int i=0; i<10; ++i) {
                for(int j=0; j<10; ++j) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        int cost = INF, town = -1;
        for(int i=0; i<10; ++i) {
            int c = 0;
            for(int j=0; j<10; ++j) {
                if(d[i][j] == INF) {
                    continue;
                }
                c += d[i][j];
            }
            if(c != 0 && cost > c) {
                cost = c;
                town = i;
            }
        }
        cout << town << ' ' << cost << endl;
    }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2] && s[2] == s[0])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
using namespace std;
const double Pi=3.1415926;
int n,m,k;
int main()
{
	double r;
	cin >> r;
	cout <<2*r*Pi<<endl;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S;

int dp[200010][5];

void solve() {
	cin >> S;
	N = sz(S);
	rep(i, 0, N + 1) {
		rep(j, 0, 5) {
			dp[i][j] = -inf;
		}
	}
	auto c = [&](int i, int l, int r) {
		if(l != r) return false;
		rep(j, 0, l) {
			if(S[i + j] != S[i - l + j]) return false;
		}
		return true;
	};
	dp[0][0] = 0;
	rep(i, 0, N) {
		rep(j, 0, 5) {
			if(dp[i][j] == -inf) continue;
			rep(k, 1, 5) {
				if(i + k <= N && !c(i, j, k)) {
					MAX(dp[i + k][k], dp[i][j] + 1);
				}
			}
		}
	}
	int res = 0;
	rep(i, 1, 5) {
		MAX(res, dp[N][i]);
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    // 前処理
    COMinit();

    //以前はけんちょんこぴぺ
    int n, k;
    cin >> n >> k;

    //ボールの区別は不要

    for(int i=1;i<=k;i++){
        int ans=(COM(n-k+1,i)*COM(k-1,i-1))%MOD;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 12160
N = int(input())
A = list(map(int,input().split()))

inf = 10**9+7
occ = [0]*(N+1)
#便宜上-1がすでに3回出ていることにする&ナンバリングをずらす
occ[0]=3

ans = 1

for i in range(0,N):
    ans=ans*(occ[A[i]]-occ[A[i]+1])%inf
    occ[A[i]+1]+=1

print(ans)

Measured memory_bytes: 53300
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

dp = [-1 for _ in range(k+1)]

for i in range(min(a)):
    dp[i] = 1

for i in range(k+1):
    tmp = 0
    for x in a:
        if i-x < 0:
            continue
        else:
            tmp += dp[i-x]
    if tmp > 0:
        dp[i] = 0
    else:
        dp[i] = 1

print('First' if dp[k] == 0 else 'Second')


Measured memory_bytes: 44912