akhauriyash/Code-Regression huggingface dataset:
'use strict';(function(input){
  
  input=input.trim().split(/\s+/).map(x=>x-0);
  const N =input[0],
        A=input.slice(1,N+2),
        B=input.slice(N+2);
  var ans=0;
  for(let i=0;i<N;i++){
    let a=A[i],a_=A[i+1],b=B[i], c,d;
    A[i]-=(c=Math.min(a,b));
    B[i]-=c;
    ans+=c;
    A[i+1]-=(d=Math.min(a_,Math.max(b-a,0)));
    B[i]-=d;
    ans+=d;
    //console.log(a,b,c,d,ans);
  }
  ans+=Math.min(A[N],B[N-1])
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 57572
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

res = []
for i in range(len(a)):
    for c in range(a[i]):
        res.append(i+1)

for i in range(H):
    row = ""
    for j in range(W):
        r = W*i
        if i % 2 == 0:
            c = j
        else:
            c = W - 1 - j
        row += str(res[r+c])
        row += " "
    print(row)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void read(int &x){
	x=0;char ch=getchar();
	while(ch>'9'||ch<'0') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
}

int a,b,c;

int main(){
#ifdef rqgao2014
	srand(time(0));
	time_tester(0);
#endif
	scanf("%d%d%d",&a,&b,&c);
	if((a&1)||(b&1)||(c&1)){puts("0");return 0;}
	if(a==b&&b==c&&c==a){puts("-1");return 0;}
	for(int i=1;;i++){
		int ta=a,tb=b,tc=c;
		a=((ll)tb+tc)/2,b=((ll)ta+tc)/2,c=((ll)ta+tb)/2;
		if((a&1)||(b&1)||(c&1)){printf("%d\n",i);return 0;}
	}
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    
    buf := make([]byte, 1000)
    sc.Buffer(buf, 1400000000)

	N := inputLineAsNumArray(1)[0]
	spots := inputLineAsNumArray(N)

    spots = append([]int{0}, spots...)
    spots = append(spots, 0)
    var dirs []bool
    base := int(math.Abs(float64(spots[0])))
	for i:=0; i<N+1; i++ {
        if spots[i] < spots[i+1] {
            dirs = append(dirs, true)
        } else if spots[i] > spots[i+1] {
            dirs = append(dirs, false)
        } else {
            if i == 0 {
                dirs = append(dirs, true)
            } else {
                dirs = append(dirs, dirs[i-1])
            }
        }
        base += int(math.Abs(float64(spots[i]-spots[i+1])))
	}

	for i:=1; i<N+1; i++ {
	    diff := 0
        if dirs[i] != dirs[i-1] {
            diff = int(math.Abs(float64(spots[i]-spots[i-1]))) + int(math.Abs(float64(spots[i]-spots[i+1]))) - int(math.Abs(float64(spots[i+1]-spots[i-1])))
        }
        fmt.Println(base-diff)
	}
	
}

func inputLineAsNumArray(length int) []int {
	line := strings.Split(readLine(), " ")
	var nums []int
	for i := 0; i < length; i++ {
		num, _ := strconv.Atoi(line[i])
		nums = append(nums, num)
	}
	return nums
}

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



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

int main(void){
    long n;
    cin >> n;
    vector<long> v(n);
    for(long i=0; i<n; i++){
        cin >> v[i];
    }
    long count=0;
    for(long i=0; i<n; i++){
        while(v[i]%2==0){
            count++;
            v[i]/=2;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 384
s = input()
ans = [0]
for i in range(len(s)):
    if s[i] == "A":
        ans[-1] += 1
    elif s[i] == "C":
        ans[-1] += 1
    elif s[i] == "G":
        ans[-1] += 1
    elif s[i] == "T":
        ans[-1] += 1
    else:
        ans.append(0)
print(max(ans))

Measured memory_bytes: 3064
X = int(input())

if 400<=X<=599:
    print(8)
elif 600<=X<=799:
    print(7)
elif 800<=X<=999:
    print(6)
elif 1000<=X<=1199:
    print(5)
elif 1200<=X<=1399:
    print(4)
elif 1400<=X<=1599:
    print(3)
elif 1600<=X<=1799:
    print(2)
elif 1800<=X<=1999:
    print(1)

Measured memory_bytes: 61656
require 'set'

n, k = gets.chomp.split(' ').map(&:to_i)
set = Set.new
k.times do
  d = gets.chomp.to_i;
  a = gets.chomp.split(' ').map(&:to_i)
  a.each do |num|
    set.add(num);
  end
end

puts n - set.length

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


int main()
{
  string S;
  int result=0;

  cin >> S;

  //処理
  if(S=="SUN") result = 7;    
  else if(S=="MON") result = 6;    
  else if(S=="TUE") result = 5;    
  else if(S=="WED") result = 4;    
  else if(S=="THU") result = 3;    
  else if(S=="FRI") result = 2;    
  else if(S=="SAT") result = 1;    


  cout << result;
    
  return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants ---------- */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

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

    sort(a, a + N);

    double center = 1.0 * a[N-1] / 2;
    ll idx = -1;
    ll minim = INF;

    for (int i = 0; i < N - 1; i++) {
        if (abs(a[i] - center) < minim) {
            idx = i;
            minim = abs(a[i] - center);
        }
    }

    cout << a[N-1] << " " << a[idx] << endl;

    return 0;
}

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

const int mod = 1000000007;

long long power(long long a, int b) {
	if (!b) return 1;
	long long tmp = power(a, b >> 1);
	return b & 1 ? tmp * tmp % mod * a % mod : tmp * tmp % mod;
}

long long pw25[2000010], pw26[2000010], inv[2000010];

int main () {
	pw25[0] = pw26[0] = 1, inv[1] = 1;
	for (int i = 1; i <= 2000000; i++) {
		pw25[i] = pw25[i - 1] * 25 % mod;
		pw26[i] = pw26[i - 1] * 26 % mod;
		if (i > 1) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
	int k; cin >> k;
	string s; cin >> s;
	int n = s.size();
	long long ans = 0, C = 1;
	for (int lst = n; lst <= n + k; lst++) {
		ans = (ans + C * pw25[lst - n] % mod * pw26[n + k - lst]) % mod;
		C = C * lst % mod * inv[lst - n + 1] % mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 52192
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a,b;
   cin>>a;
   b=a;
   int as=a.size();
   for(int i=0;i<as;i++)b[i]=a[as-i-1];
   cout<<b<<endl;    
    return 0;
}

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

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

    int N, K;
    cin >> N >> K;
    vector<int> V(N + 1, 0);
    int div = 0;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        if (V.at(A) == 0) div++;
        V.at(A)++;
    }

    sort(V.begin(), V.end());
    int ans = 0;
    for (auto itr = upper_bound(V.begin(), V.end(), 0); itr != V.end(); ++itr) {
        if (div <= K) break;
        ans += *itr;
        div--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;
ll dp[200010];
ll dp1[200010];
vector<pair<ll, ll>> vt;
pair<ll, ll> a[200010];
ll visited[200010];
int main()
{
	ll n;
	scanf("%lld", &n);
	ll xx = 0;
	ll yy = 1234567890;
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld %lld", &a[i].first, &a[i].second);
		vt.push_back({ min(a[i].first,a[i].second ),-i});
		vt.push_back({ max(a[i].second,a[i].first) ,i});
		visited[i] = max(a[i].first, a[i].second);
	}
	sort(vt.begin(), vt.end());
	int ch = 0;
	int t = vt.size();
	ll fi,la;
	for (int i = 0; i < t; i++)
	{
		if (vt[i].second > 0)
			visited[vt[i].second] = i;
	}
	for (int i = 0;i<t; i++)
	{
		if (vt[i].second > 0)
		{
			fi=i;
			break;
		}
	}
	ch = 0;
	for (int i = t - 1; i >= 0; i--)
	{
		if (vt[i].second < 0) {
			la = i;
			break;
		}
	}
	ll dap = (vt[t - 1].first - vt[fi].first)*(vt[la].first - vt[0].first);
	la = max(la, visited[-vt[0].second]);
	for (int i = 1; i <= fi; i++)
	{
		if (la == t - 1)break;
		dap = min(dap, (vt[t - 1].first - vt[0].first)*(vt[la].first - vt[i].first));
		if (i == fi)continue;
		la = max(la, visited[-vt[i].second]);
	}
	printf("%lld", dap);
}

Measured memory_bytes: 16236
S = input()
MOD = 2019

digit = 1
counts = [0] * 2019
counts[0] = 1
current = 0
for s in S[::-1]:
  current = (current + int(s) * digit) % MOD
  counts[current] += 1
  digit = (digit * 10) % MOD
  
ans = 0
for c in counts:
  ans += c * (c-1) // 2
  
print(ans)  

 

Measured memory_bytes: 9256
# frozen_string_literal: true

n, k = gets.split.map(&:to_i)
cnt = 0
d = 10**9 + 7

k.upto(n + 1) do |i|
  cnt += ((n - i + 1)..n).sum % d - (0..(i - 1)).sum % d + 1
end

puts cnt % d

Measured memory_bytes: 14380
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
const int di[] = {-1, 0 , 1, 0};
const int dj[] = {0, -1, 0 , 1};

int main()
{
    int h , w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    /*
    cout << endl;
    rep(i,h){
        rep(j,w) cout << s[i][j];
        cout << endl;
    } 
    */
    //cout << "hoge" << endl;
    int ans = 0;
    rep(si, h) rep(sj, w){
        if(s[si][sj] == '#') continue;
        queue<pair<int, int>> q;
        vector<vector <int>> table(h, vector<int>(w, -1));
        auto update = [&](int i, int j, int x){
            if(table[i][j] != -1) return;
            table[i][j] = x;
            q.push(pair<int, int>(i,j));
        };
        update(si, sj, 0);
        while(!q.empty()){
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            rep(dir, 4){
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(s[ni][nj] == '#') continue;
                update(ni, nj, table[i][j]+1);
            }
        }
        rep(i,h) rep(j,w) {
            ans = max(ans, table[i][j]);
        }
        //cout << "fuga" << endl;
    }
    cout << ans << endl;
}

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

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

    int n;
    cin >> n;
    set<int> as;
    rep(_, n){
        int a;
        cin >> a;
        as.insert(a);
    }

    if(as.size() == n) puts("YES");
    else puts("NO");

    return 0;
}

Measured memory_bytes: 9600
import java.util.*;
public class Main {
    static long INF = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            char ch = s.charAt(i);
            if (!map.containsKey(ch)) {
                map.put(ch, 0);
            }
            map.put(ch, map.get(ch) + 1);
        }
        long ans = 1;
        for (char key : map.keySet()) {
            ans *= map.get(key) + 1;
            ans %= INF;
        }
        ans--;
        System.out.println(ans);
    }
}


Measured memory_bytes: 27332
#include <stdio.h>

int main() {
  int n;
  int i,j,e;
  int a[101],b[101];
  int t,minj,flag;
  char c[101],kara,m,d[101],f[4];
  char str[3];
  int sta = 0;

  scanf("%d", &n);

  for(i=0; i<n; i++) {

    scanf("%s",str);
    c[i] = str[0];
    a[i]  = str[1] - '0';
    //    printf("%c %d\n",c[i],a[i]);
    b[i] = a[i];
    d[i] = c[i];

  }



  //Bubble Sort

  for(i = 0; i<=n-1;i++) {
    for(j = 0; j<=n-1;j++) {

      if(a[j] < a[j-1]) {

	t = a[j];
	a[j] = a[j-1];
	a[j-1] = t;

	m = c[j];
	c[j] = c[j-1];
	c[j-1] = m;
      }
    }
  }

  for(i = 0;i<n;i++) {

    printf("%c%d",c[i],a[i]);
    
    if(i != n-1) printf(" ");

  }

  printf("\nStable\n");




  // Selsection Sort

  

  for(i = 0; i<=n-1; i++) {
    minj = i;
    flag = 0;
  
    for(j = i; j<=n-1;j++) {
      if(b[j] < b[minj]) {
	//	printf("%d < %d\n",b[j],b[minj]);
	minj = j;
	//printf("minj = %d\n",b[minj]);
	flag = 1;
      }
    }

    

    if(flag == 1) {


      t = b[i];
      b[i] = b[minj];
      b[minj] = t;

      m = d[i];
      d[i] = d[minj];
      d[minj] = m;
  
    }
  }

   
  for(i=0;i<n;i++) {
     printf("%c%d",d[i],b[i]);
    if(i != n-1) {
      printf(" ");
    }

  }


printf("\n");
flag = 0;
for(j=0;j<n;j++){

  //printf("c[%d](%c) = d[%d](%c)\n",j,c[j],j,d[j]);

  if(c[j] != d[j]) {
    flag = 1;
   
  }
 } 

if(flag == 1) printf("Not stable\n");
 else printf("Stable\n");

 return 0;

}

Measured memory_bytes: 616
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#define int long long
#define uint unsigned long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

int n, ma, mb;
int yaku_a[40];
int yaku_b[40];
int yaku_c[40];
int init = 1145141919810;
int inf = 1145141919;
int memo[41][400][400];

int func(int num, int a, int b) //num番目まで来たときの割合がa,bだったときの最小コスト
{
	if (a < 0 || b < 0)
	{
		return inf;
	}
	if (memo[num][a][b] < init)
	{
		return memo[num][a][b];
	}
	if (num == 0)
	{
		if(a == 0 && b == 0)
			return 0;
		else
			return inf;
	}

	int ya = yaku_a[num - 1];
	int yb = yaku_b[num - 1];
	int yc = yaku_c[num - 1];
	int val1 = func(num - 1, a, b);
	int val2 = func(num - 1, a - ya, b - yb) + yc;
	return memo[num][a][b] = MIN(val1, val2);
}

signed main()
{
	for (int i = 0; i <= 40; i++)
	{
		for (int a = 0; a < 400; a++)
		{
			for (int b = 0; b < 400; b++)
			{
				memo[i][a][b] = init;
			}
		}
	}

	cin >> n >> ma >> mb;
	for (int i = 0; i < n; i++)
	{
		cin >> yaku_a[i] >> yaku_b[i] >> yaku_c[i];
	}

	int min_val = init;
	for (int a = 1; a < 400; a++)
	{
		for (int b = 1; b < 400; b++)
		{
			if (ma*b == a*mb)
			{
				int val = func(n, a, b);
				if (val < min_val)
				{
					min_val = val;
				}
			}
		}
	}

	if (min_val < inf)
	{
		cout << min_val << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}


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

int main(void)
{
  int n;
  cin >> n;
  vector<int>data(n);
  for(int i = 0; i < n; i++)
  {
    cin >> data.at(i);
  }
  int res = 0;
  int min = 0;
  for(int i = 0; i < n; i++)
  {
    if(i == 0)
    {
      res++;
      min = data.at(i);
    }
    else if(min >= data.at(i))
    {
      res++;
      min = data.at(i);
    }
  }
  
  cout << res << endl;
}

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

int main(){
  int N;
  cin>>N;
  map<int,int> A;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[a]++;
  }
  int j=0;
  for(pair<int,int> p:A)
    if(p.second>=p.first)
      j+=p.second-p.first;
    else
      j+=p.second;
  cout<<j<<endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;

int dp[2][2020202];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	reverse(ALL(S));
	S+=string(1000005,'0');
	
	dp[0][0]=0;
	dp[1][0]=1<<30;
	
	FOR(i,1000005) {
		dp[0][i+1]=dp[1][i+1]=1<<30;
		
		dp[0][i+1]=min(dp[0][i+1],dp[0][i]+S[i]-'0');
		dp[1][i+1]=min(dp[1][i+1],dp[0][i]+10-(S[i]-'0'));
		dp[0][i+1]=min(dp[0][i+1],dp[1][i]+(S[i]-'0'+1));
		dp[1][i+1]=min(dp[1][i+1],dp[1][i]+10-(S[i]-'0'+1));
	}
	
	cout<<dp[0][1000004]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 13684
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

fn main() {
    input! {
        k: usize,
    }
    let mut queue: VecDeque<u64> = (1..10).collect();

    for _ in 0..k - 1 {
        let x = queue.remove(0).unwrap();

        for i in -1_i32..=1 {
            let d = (x % 10) as i32 + i;
            if d < 0 || d > 9 {
                continue;
            }
            let nx = x * 10 + d as u64;
            queue.push_back(nx);
        }
    }
    println!("{}", queue.get(0).unwrap());
}


Measured memory_bytes: 4044
#include <iostream>
#include <queue>
#include <utility>
#include <algorithm>
#define MAXN 200000
using namespace std;
typedef pair<long long, long long> Pll;
int main(){
	long long N, D, A, ans=0;
	Pll monsters[MAXN];
	queue<Pll> bombend;
	long long bombsum = 0;
	cin >> N >> D >> A;
	for(int i=0; i<N; i++)
		cin >> monsters[i].first >> monsters[i].second;
	sort(monsters, monsters+N);
	for(int i=0; i<N; i++){
		while(!bombend.empty() && bombend.front().first < monsters[i].first){
			bombsum -= bombend.front().second;
			bombend.pop();
		}
		monsters[i].second -= bombsum * A;
		if(monsters[i].second > 0){
			int use = (monsters[i].second + A - 1) / A;
			bombend.push(make_pair(monsters[i].first + D*2, use));
			bombsum += use;
			ans += use;
		}
	}
	cout << ans << endl;
}

			


	



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

int main() {
  int N;
  cin >> N;
  int F[N][5][2];
  for (int i=0 ; i<N ; i++) {
    for (int j=0 ; j<5 ; j++) {
      for (int k=0 ; k<2 ; k++) {
        cin >> F[i][j][k];
      }
    }
  }
  int P[N][11];
  for (int i=0 ; i<N ; i++) {
    for (int j=0 ; j<11 ; j++) {
      cin >> P[i][j];
    }
  }

  int ans = -1000000000;
  for (int open = 1 ; open < 1<<10 ; open++) {
    int p = 0;
    for (int i = 0 ; i < N ; i++) {
      int num = 0;
      for (int j = 0 ; j < 10 ; j++) {
        if ((open >> j & 1) && (F[i][j/2][j%2] == 1)) num++;
      }
      p += P[i][num];
    }
    ans = max(ans, p);
  }

  cout << ans << endl;
}


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

namespace B___Guidebook
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var restaulants = new restaulant[N];
            for(int i = 0 ; i < N ; i++)
            {
                var read = Console.ReadLine().Split(' ');
                restaulants[i] = new restaulant();
                restaulants[i].number = i + 1;
                restaulants[i].city = read[0];
                restaulants[i].point = int.Parse(read[1]);
            }
            restaulants = restaulants.OrderBy(r => r.city).ThenByDescending(r => r.point).ToArray();

            for(int i = 0 ; i < N ; i++) Console.WriteLine(restaulants[i].number);
        }
    }

    struct restaulant
    {
        public int number{get;set;}
        public string city{get;set;}
        public int point{get;set;}
    }
}


Measured memory_bytes: 13536
import fractions
import collections
import math

AB = list(map(int, input().split()))
A = AB[0]
B = AB[1]

GCM = fractions.gcd(A, B)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def isPrime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    for p in range(2,n):
        if n % p == 0:
            return False
    return True

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(GCM))
print(len(list(c.keys()))+1)


Measured memory_bytes: 5052
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	string Sc, T;
	cin >> Sc >> T;

	string S = Sc;

	for(int i = Sc.size() - 1; i >= 0; i--) {
		int idx = i;
		bool flag = true;
		for(int j = T.size() - 1; j >= 0; j--) {
			if(Sc[idx] == '?') {
				S[idx] = T[j];
				idx--;
			}
			else if(Sc[idx] == T[j]) {
				S[idx] = T[j];
				idx--;
			}
			else {
				flag = false;
				break;
			}
		}
		if(flag) {
			rep(j, 0, S.size()) {
				if(S[j] == '?') cout << 'a';
				else cout << S[j];
			}
			cout << endl;
			return 0;
		}
		S = Sc;
	}

	cout << "UNRESTORABLE" << endl;


}


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

namespace AtCoder.ABC
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var v = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

            var guusuu = new SortedDictionary<int, int>();
            var kisuu = new SortedDictionary<int, int>();

            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) {
                    if (guusuu.ContainsKey(v[i]) == false) {
                        guusuu.Add(v[i], 0);
                    }

                    guusuu[v[i]]++;
                } else {
                    if (kisuu.ContainsKey(v[i]) == false) {
                        kisuu.Add(v[i], 0);
                    }

                    kisuu[v[i]]++;
                }
            }

            var guusuuList = guusuu.ToList();
            guusuuList.Sort((x, y) => y.Value.CompareTo(x.Value));

            var kisuuList = kisuu.ToList();
            kisuuList.Sort((x, y) => y.Value.CompareTo(x.Value));


            var guusuuMax = guusuuList.First();
            var kisuuMax = kisuuList.First();

            if (kisuuMax.Key != guusuuMax.Key) {
                Console.WriteLine(n - kisuuMax.Value - guusuuMax.Value);
            } else {
                var guusuuMax2 = new KeyValuePair<int, int>(0, 0);

                if (guusuuList.Count >= 2) {
                    guusuuMax2 = guusuuList[1];
                }

                var kisuuMax2 = new KeyValuePair<int, int>(0, 0);

                if (kisuuList.Count >= 2) {
                    kisuuMax2 = kisuuList[1];
                }

                var min = n - guusuuMax.Value - kisuuMax2.Value;

                min = Math.Min(n - guusuuMax2.Value - kisuuMax.Value, min);

                Console.WriteLine(min);
            }
        }
    }
}


Measured memory_bytes: 40864
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;


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

	// a + b + 2√ab < cか？
	llong left = 4 * a * b;
	llong center = (c - a - b);
	if (center < 0)
		cout << "No";
	else
	{
		center *= center;
		if (left < center)
			cout << "Yes";
		else
			cout << "No";
	}
}

Measured memory_bytes: 256
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<usize>();
    let (n, m) = (input[0], input[1]);
    let mut map = HashMap::new();
    for _ in 0..m {
        let input = read_vec::<usize>();
        let (x, y) = (input[0]-1, input[1]-1);
        map.entry(x).or_insert_with(|| vec![]).push(y);
        map.entry(y).or_insert_with(|| vec![]).push(x);
    }
    let mut used = vec![false; n];
    

    let mut count = 0;
    for i in 0..n {
        if used[i] {
            continue;
        }
        count += 1;
        dfs(i, &map, &mut used);
    }

    println!("{}", count);
}

fn dfs(index: usize, map: &HashMap<usize, Vec<usize>>, used: &mut Vec<bool>) {
    used[index] = true;
    if let Some(val) = map.get(&index) {
        for &key in val.iter() {
            if used[key] {
                continue;
            }
            dfs(key, map, used);
        }
    }
}

Measured memory_bytes: 16444
#include <stdio.h>

int main(void)
{
    int i, n, x;
    
    scanf("%d", &n);
    
    for(i = 1; i <= n; i++)
    {
        x = i;
        if(x % 3 == 0)
        {
            printf(" %d", i);
            continue;
        }
        else
        {
            while(x != 0)
            {
                if(x % 10 == 3)
                {
                    printf(" %d", i);
                    break;
                }
                else 
                {
                    x /= 10;
                }
            }
        }
        
    }
    
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 600
N = int(input())
S = [input() for i in range(N)]

countAC = 0
countWA = 0
countTLE = 0 
countRE = 0

for i in range(N):
    if S[i]=="AC":
        countAC += 1
    elif S[i]=="WA":
        countWA += 1
    elif S[i]=="TLE":
        countTLE += 1
    else:
        countRE += 1

print("AC x ",end='')
print(countAC)
print("WA x ",end='')
print(countWA)
print("TLE x ",end='')
print(countTLE)
print("RE x ",end='') 
print(countRE)

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007LL;

ll mm(ll a, ll b) {
    return ((a * b) % MOD + MOD) % MOD;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    ll ans = 1LL;
    if (n == k) {
        for (int i = 0; i < n; ++i) {
            ans = mm(ans, a[i]);
        }
        cout << ans << "\n";
        return;
    }
    
    vector<ll> ap(2, 0LL);
    vector<ll> an(2, 0LL);
    for (int i = 0; i < n; ++i) {
        if (a[i] > 0LL) {
            ap.push_back(a[i]);
        } else {
            an.push_back(a[i]);
        }
    }
    sort(ap.begin(), ap.end());
    sort(an.begin(), an.end());
    reverse(an.begin(), an.end());
    
    if (ap.size() == 2 && k % 2 == 1) {
        for (int i = 0; i < k; ++i) {
            ans = mm(ans, an[2 + i]);
        }
        cout << ans << "\n";
        return;
    }
    
    if (k % 2 == 1) {
        --k;
        ans = mm(ans, ap.back());
        ap.pop_back();
    }
    while (k > 0 && ans > 0) {
        k -= 2;
        if (ap.back() * ap[ap.size() - 2] > an.back() * an[an.size() - 2]) {
            for (int i = 0; i < 2; ++i) {
                ans = mm(ans, ap.back());
                ap.pop_back();
            }
        } else {
            for (int i = 0; i < 2; ++i) {
                ans = mm(ans, an.back());
                an.pop_back();
            }
        }
    }
    
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int t = 1;
    //cin >> t;
    for (int qq = 0; qq < t; ++qq) {
       solve();
    }
   
    return 0;
}

Measured memory_bytes: 6948
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
    int n,m,l,r,min=100000,max=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        if(min>r)min=r;
        if(max<l)max=l;
    }
    if(max<=min)cout<<min-max+1<<"\n";
    else cout<<0<<"\n";
}

Measured memory_bytes: 3644
K = int(input())

if K % 7 == 0:
    L = 9 * K // 7
else:
    L = 9 * K

ans = 10
kou = -1
for i in range(1, 10**6):
    ans %= L
    if ans == 1:
        kou = i
        break
    else:
        ans *= 10

print(kou)

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 string s;
	 cin>>s;
	 int n = s.length();
	 if(s[n-1] == 's')
	 {
		 s = s + "es";
	 }
	 else
	 {
		 s = s + 's';
	 }
	 cout<<s<<'\n';
	 return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	int n, q;
	long a[1000], c[1000];

	cin >> n;

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

	cin >> q;

	for (int i = 0; i < q; i++) {
		int b, m, e;
		cin >> b >> m >> e;

		memset(c, 0, sizeof(c));

		for (int i = 0; i < e - b; i++)
			c[i] = a[b + i];

		for (int i = 0; i < e - b; i++) {
			int j = (i + e - m) % (e - b);
			a[b + j] = c[i];
		}
	}

	for (int i = 0; i < n - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;

	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

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

    deque<char> q;
    for(char c : S) q.push_back(c);

    int Q;
    cin >> Q;

    int T,F;
    char C;
    bool flag = true;

    for(int i=0; i<Q; i++){
        cin >> T;

        if(T==1){
          if(flag)
           flag = false;
          else
           flag = true;
        }
        else{
          cin >> F;
          cin >> C;

          if(F == 1){
            if(flag)
              q.push_front(C);
            else
              q.push_back(C);
          }
          else{
            if(flag)
              q.push_back(C);
            else
              q.push_front(C);
          }
        }
    }

    if(!flag)
      reverse(q.begin(),q.end());

    string ans;
    for(char c : q) ans += c;
    cout << ans << endl;

    return 0;
}
/*
int main(void) {
    string S;
    long long int Q;
    cin >> S;
    cin >> Q;

    int T,F;
    string C;
    bool flag = true;
    for(int i=0; i<Q; i++){
        cin >> T;

        if(T==1){
          if(flag) flag =false;
          else flag = true;
          //reverse(S.begin(),S.end());
        }
        else if(T==2){
          cin >> F;
          cin >> C;
          if(F == 1){
            if(flag)
              S = C + S;
            else
              S = S + C;
          }
          else if(F == 2){
            if(flag)
              S = S + C;
            else
              S = C + S;

          }

        }


    }
    if(!flag)
      reverse(S.begin(),S.end());

    cout << S << endl;

    return 0;
}
*/


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  string s;
  cin >> s;
  vector<bool> ans(n);
  REP(mask,4){
    ans[0] = mask & 1;
    ans[1] = (mask >> 1) & 1;
    FOR(i,2,n){
      if(s[i-1] == 'o'){
        ans[i] = (ans[i-1] == ans[i-2]);
      }else{
        ans[i] = (ans[i-1] != ans[i-2]);
      }
    }
    if(s[n-1] == 'o'){
      if((ans[0] == ans[n-2]) != ans[n-1])continue;
    }else{
      if((ans[0] == ans[n-2]) == ans[n-1])continue;
    }
    if(s[0] == 'o'){
      if((ans[n-1] == ans[1]) != ans[0])continue;
    }else{
      if((ans[n-1] == ans[1]) == ans[0])continue;
    }
    REP(i,n){
      if(ans[i]){
        cout << "S";
      }else{
        cout << "W";
      }
    }
    cout << endl;
    return 0;
  }
  ANS(-1);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int A, P; cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;
    return 0;
}

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

int main(void) {
  long long int n, m;
  scanf("%lld %lld", &n, &m);
  for (long long int i = 0; i < m; i++) {
    long long int a;
    scanf(" %lld", &a);
    n -= a;
    if (n < 0) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", n);

  return 0;
}


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

int main()
{
  long A=998244353;
  long N;
  long D[100010]={0};
  long value;
  long mx=0;
  long ans=0;
  cin>>N;
  cin>>D[0];
  if(D[0]==0){
    for(int i=1;i<N;i++){
      cin>>value;
      D[value]+=1;
      mx=max(value,mx);
    }
    if(D[0]==0){
      ans=1;
      D[0]=1;
      for(int i=1;i<=mx;i++){
        for(int j=0;j<D[i];j++){
         ans=(ans*D[i-1])%A;
        }
      }
    }
  }
  cout<<ans<<endl;
}
          


Measured memory_bytes: 1024
def insertionSort(At, Nt):
	for i in range(Nt):
		v = At[i]
		j = i - 1
		while j >= 0 and At[j] > v:
			A[j + 1] = A[j]
			j = j - 1
		A[j + 1] = v
		print(" ".join(map(str,At)))
	return At

if __name__ == '__main__':

    N = int(input())
    A = list(map(int,input().split()))
    A = insertionSort(A,N)



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

using namespace std;

bool isOK(int ma, int n) {
  for (int i = ma; i >= 1; --i) {
    if (n >= i) {
      n -= i;
    }
  }
  return n == 0;
}

int main() {
  int n;
  cin >> n;
  int left = 0, right = n;
  int ma = n;
  while (right - left > 1) {
    int mid = left + (right - left) / 2;
    if (isOK(mid, n)) {
      right = mid;
      ma = mid;
    } else
      left = mid;
  }
  for (int i = ma; i >= 1; --i) {
    if (n >= i) {
      n -= i;
      cout << i << endl;
    }
  }
}

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

#define REP(i,n) for(long long i=0;i<(n);i++)

int main() {
  string S;
  cin >> S;
  int len = 0;
  vector<int> ans;
  REP(i, S.size()) {
    if(S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
      len++;
    } else {
      ans.push_back(len);
      len = 0;
    }
  }
  ans.push_back(len);
  sort(ans.begin(), ans.end());
  cout << ans[ans.size()-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e3 + 7;
int ls1[Max], ls2[Max];
int n;


int main()
{
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	ll sum = 0;
	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				if (i * 500 + j * 100 + 50 * k == x)
					sum++;
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 3100
#include<iostream>
#define nagasa 3
using namespace std;

int main()
{
	int data[nagasa]={};
	int check;

	for(int i = 0;i<nagasa;i++)
	{
		cin >> data[i];
	}

	for(int i = 0;i<nagasa-1;i++)
	{
		for(int j = nagasa-1; j>=i+1; j--)
		{
			if(data[j]<data[j-1])
			{
				check = data[j];
				data[j] = data[j-1];
				data[j-1] = check;
			}
		}
	}

	cout << data[0] + data[1] << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<string>

using namespace std;
using ll = long long int;

int n, k;
string s;

int main(void) {
	string ret;
	cin >> n >> k;
	cin >> s;
	s[k - 1] = tolower(s[k - 1]);
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  
  sort(d.begin(),d.end(),greater<int>());
  d.erase(unique(d.begin(),d.end()),d.end());
  
  cout << d.size();
  
  return 0;
}

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

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


vector<unsigned int> Divs(unsigned int a, unsigned int p = 2) {
	if (a == 1) return { 1 };
	for (; a % p != 0; p++) if (p*p > a) return { 1, a };
	int n = 1;
	for (; a % p == 0; n++) a /= p;
	vector<unsigned int> buf = Divs(a, p + 1 | 1);
	int i = buf.size(), l = buf.size();
	buf.resize(i * n);
	for (; i < buf.size(); i++) buf[i] = buf[i - l] * p;
	return buf;
}

void solve(){
  int n, k; cin >> n >> k;
  int a[500]; rep(i,n)cin >> a[i];
  unsigned A = 0; rep(i,n)A+=a[i];
  auto divsA = Divs(A);
  sort(divsA.rbegin(), divsA.rend());
  for(auto d : divsA){
    bool ok = true;
    int aModD[500]; rep(i,n) aModD[i] = a[i] % d;
    sort(aModD, aModD+n);
    int pf = 0; int pb = n-1;
    int pk = 0;
    while(pf < pb){
      while(aModD[pf] > 0){
        int usek = min(aModD[pf], (int)d-aModD[pb]);
        aModD[pf] -= usek; aModD[pb] += usek;
        if(aModD[pb] == d) pb--;
        pk += usek;
      }
      pf++;
    }
    if(pk <= k){cout << d << endl; return;}
  }
  cout << 1 << endl;
}
int main(){
  solve();
  return 0;
}

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

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

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

    vector<ll> cost(N, LLONG_MAX);
    cost[0] = 0;
    cost[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++) {
        cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << cost[N-1] << endl;

    return 0;
}


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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;

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

int main(void)
{
  vi a, b;
  int x, ans = 0;
  rep(i, 4){
    cin >> x;
    a.pb(x);
  }
  rep(i, 2){
    cin >> x;
    b.pb(x);
  }

  sort(rall(a));
  sort(rall(b));
  rep(i, 3) ans += a[i];

  cout << ans + b[0] << endl;

  return (0);
}

Measured memory_bytes: 3152
w,h,n=map(int, input().split())
x=[]
y=[]
a=[]
for i in range(n):
  s=input().split()
  x.append(int(s[0]))
  y.append(int(s[1]))
  a.append(int(s[2]))
x_l=0
x_h=w
y_l=0
y_h=h
for i in range(n):
  if a[i]==1:
    if x_l<x[i]:
      x_l=x[i]
  elif a[i]==2:
    if x_h>x[i]:
      x_h=x[i]
  elif a[i]==3:
    if y_l<y[i]:
      y_l=y[i]
  else:
    if y_h>y[i]:
      y_h=y[i]
if x_h>x_l and y_h>y_l:
  print((x_h-x_l)*(y_h-y_l))
else:
  print("0")


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int match[26];
  for (int i = 0; i < 26; i++) {
    match[i] = -1;
  }
  for (int i = 0; i < S.length(); i++) {
    if (match[S[i] - 'a'] == -1) {
      match[S[i] - 'a'] = T[i] - 'a';
    }
    else if (match[S[i] - 'a'] == T[i] - 'a') {
      continue;
    }
    else {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < 26; i++) {
    match[i] = -1;
  }
  for (int i = 0; i < T.length(); i++) {
    if (match[T[i] - 'a'] == -1) {
      match[T[i] - 'a'] = S[i] - 'a';
    }
    else if (match[T[i] - 'a'] == S[i] - 'a') {
      continue;
    }
    else {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 3916
#include <iostream>

using namespace std;

int main(int argc, const char *argv[]) {
  string S;
  cin >> S;
  size_t n = S.size();
  for(int i = 0; i< n; i++){
    if(S[i] == '1'){
      S[i] = '9';
    }else if(S[i] == '9'){
      S[i] = '1';
    }else{
      continue;
    }
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())

xl = [0]*n
yl = [0]*n
hl = [0]*n


for i in range(n):
    xl[i], yl[i], hl[i] = map(int, input().split())
    if hl[i] >= 1:
        si = i

ansx, ansy, ansh = -1, -1, -1

for cx in range(101):
    for cy in range(101):
        H = hl[si]+abs(xl[si]-cx)+abs(yl[si]-cy)
        flag = True
        for i in range(n):
            hi = max(H-abs(xl[i]-cx)-abs(yl[i]-cy), 0)
            if hi != hl[i]:
                flag = False
                break
        if flag:
            ansx, ansy, ansh = cx, cy, H
print(ansx, ansy, ansh)


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

using i64 = int64_t;

pair<string, int> Cipher(string s, int idx);
pair<string, int> Cipher_(string s, int idx);
pair<string, int> String(string s, int idx);
pair<string, int> Letter(string s, int idx);

pair<string, int> Cipher(string s, int idx){
    auto res = String(s, idx);
    auto p = Cipher_(s, idx+res.second);
    res.first += p.first;
    res.second += p.second;
    return res;
}

pair<string, int> Cipher_(string s, int idx){
    if(idx >= s.size() || s[idx] == ']'){
        return make_pair("", 0);
    }
    auto res = String(s, idx);
    auto p = Cipher_(s, idx+res.second);
    res.first += p.first;
    res.second += p.second;
    return res;
}

pair<string, int> String(string s, int idx){
    pair<string, int> res;
    if(s[idx] == '['){
        res = Cipher(s, idx+1);
        reverse(res.first.begin(), res.first.end());
        res.second += 2;
    }else{
        res = Letter(s, idx);
        string str = res.first;
        if(str[0] == '?')str[0] = 'A';
        res.first = str;
    }
    return res;
}

pair<string, int> Letter(string s, int idx){
    pair<string, int> res;
    if(s[idx] == '+'){
        auto p = Letter(s, idx+1);
        string str = p.first;
        char c = str.back();
        if(c != '?'){
            if(c == 'Z')str[str.size()-1] = 'A';
            else str[str.size()-1]++;
        }
        res = make_pair(str, p.second+1);
    }else if(s[idx] == '-'){
        auto p = Letter(s, idx+1);
        string str = p.first;
        char c = str.back();
        if(c != '?'){
            if(c == 'A')str[str.size()-1] = 'Z';
            else str[str.size()-1]--;
        }
        res = make_pair(str, p.second+1);
    }else{
        res = make_pair(s[idx], 1);
    }
    return res;
}

int main(){
    string s;
    while(cin >> s, s != "."){
        cout << Cipher(s, 0).first << endl;
    }

    return 0;
}



Measured memory_bytes: 3184
function solve(S:string):boolean{
    if(S.length<7)return false;
    const key="keyence";
    let pre=0;
    for(let i=0;i<7;i++){
        if(key[i]==S[i])pre++;
        else break;
    }
    let sur=0;
    for(let i=1;i<8;i++){
        if(key[7-i]==S[S.length-i])sur++;
        else break;
    }
    // console.log(pre+ sur);
    return pre + sur >=7;
}
function Main(raw: string) {
    const lines = raw.split("\n");
    const [firstLine] = lines;
    const S = firstLine;
    console.log(solve(S)?"YES":"NO");
}

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


Measured memory_bytes: 7372
d, n = map(int, input().split())

if d == 0:
    print(n+n//100)
elif d == 1:
    if n == 100:
        print(100*n+100)
    else:
        print(100*n)
else:
    if n == 100:
        print(100**2*n+100**2)
    else:
        print(100**2*n)


Measured memory_bytes: 38384
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  var output = "Yay!"
  
  for(var i=0; i<input.length - 1; i++){
    //jはアンテナとの距離まで繰り返す
    for(var j=0; j<5; j++){
      if (Math.abs(input[i] - input[j]) > input[5]){
        output = ":(";
      }
    }
  }
	//出力
	console.log(output);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<stdio.h>

int main(void){
 int a[105];
 int i,n;
 scanf("%d",&n);
 for(i=0;i<n;i++)scanf("%d",&a[i]);
 for(i=n-1;i>=0;i--){
  printf("%d",a[i]);
  i!= 0? printf(" "):printf("\n");
 }
 return 0;
}



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



int main(){
  int n,k;
  cin >> n >> k;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  for(int i=0;i<n-k;i++){
    if(vec.at(i) < vec.at(i+k))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 4044