akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func reverse(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

func main() {
	a := []string{
		"maerd",
		"remaerd",
		"esare",
		"resare",
	}

	var s string
	fmt.Scan(&s)
	s2 := reverse(s)

    n := len(s2)
	for i := 0; i < n; {
		found := false
		for _, k := range a {
			if n < i+len(k) {
				continue
			}
			if s2[i:i+len(k)] == k {
				found = true
				i += len(k)
				break
			}
		}
		if !found {
			fmt.Printf("NO\n")
			return
		}
	}
	fmt.Printf("YES\n")
}


Measured memory_bytes: 1792
n=int(input())
li = list(input())
i = 0
k = 1
counter = 0
done = 0
while True:
    # print(li)
    # print(counter)
    # print("i=", i, li[i])
    if done == 1:
        # print("done")
        break
    if i+k == n:
        # print("owari")
        break
    if li[i] == "W":
        # print("yes")
        if k+i >= n:
            # print("あいうえお")
            break
        while True:
            if li[-k] == "R":
                li[i] = "R"
                li[-k] = "W"
                counter += 1
                k += 1
                break
            k += 1
            if k+i == n:
                done = 1
                if li[-k] == "R":
                    li[-k] = "W"
                    counter += 1
                break
    i += 1
print(counter)


Measured memory_bytes: 10748
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] a = new int[n];
        for (int i = 0; i < n ; i++) {
            a[i] = sc.nextInt();
        }

        long [] b = new long[n];
        for (int i = 0 ; i < n ; i++) {
            int count = 0;
            for (int j = i + 1 ; j < n ; j++) {
                if (a[i] > a[j]) count++;
            }
            b[i] = count;
        }

        long [] c = new long[n];
        for (int i = 0 ; i < n ; i++) {
            int count = 0;
            for (int j = 0 ; j < n ; j++) {
                if (a[i] > a[j]) {
                    count++;
                }
            }
            c[i] = count;
        }
        long ans = 0;
        long mod = 1000000007 ;
        long e = 0;
        for (int i = 0 ; i < n ; i++) {
            e += c[i] % mod;
        }
        long z = k * (k - 1) / 2;
        z %= mod;
        ans += e * z % mod;
        long d = 0;
        for (int i = 0 ; i < n ; i++) {
            d += b[i] % mod;
        }
        long y = d * k % mod;
        ans += y % mod;

        System.out.println(ans % mod);


    }

}

Measured memory_bytes: 26132
def examD():
    N, A, B = LI()
    h = [I() for _ in range(N)]
    upper = max(h); lower = 1; cur = (upper+lower)//2
    while (True):
        curne = 0
        for i in h:
            if i-cur*B>0:
                curne  += (i-cur*B-1)//(A-B) +1
        if upper - lower >= 2:
            if curne > cur:
                #条件満たさない
                lower = cur
                cur = (cur + upper) // 2
            else:
                upper = cur
                cur = (cur + lower) // 2
        else:
            if curne > cur:
                #条件満たさない
                cur = upper
                curne = 0
                for i in h:
                    if i - cur * B > 0:
                        curne += (i - cur * B - 1) // (A - B) + 1
                if curne > cur:
                    break
            else:
                cur = lower
                curne = 0
                for i in h:
                    if i - cur * B > 0:
                        curne += (i - cur * B - 1) // (A - B) + 1
                if curne < cur:
                    ans = lower
                    break
            ans = upper
            break
    print(ans)



import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


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

using namespace std;

#define N 300000

int n,m,ans,num,fl,mn[N],mx[N],a[N],stk[N];

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i){
		scanf("%d",a+i);
	}
	for (int i=1,tp=0;i<=n;++i){
		for (;tp&&a[i]>a[stk[tp]];--tp);
		if (!tp||stk[tp]<=i-m) mx[i]=1;
		stk[++tp]=i;
	}
	for (int i=n,tp=0;i;--i){
		for (;tp&&a[i]<a[stk[tp]];--tp);
		if (!tp||stk[tp]>=i+m) mn[i]=1;
		stk[++tp]=i;
	}
	for (int i=1;i<m;++i){
		num+=a[i]<a[i-1];
	}
	for (int i=m;i<=n;++i){
		num+=a[i]<a[i-1];
		if (!num) fl=1;
		else
			if (i==m||!mx[i]||!mn[i-m]) ++ans;
		num-=a[i-m+2]<a[i-m+1];
	}
	ans+=fl;
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 3328
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int amax=0;
		int bmin=1000000000;
		for(i=0; i < n; i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			if(a[i]>amax)amax=a[i];
			if(b[i]<bmin)bmin=b[i];
		}
		sc.close();
		sc = null;
		System.out.println(amax+bmin);
	}
}


Measured memory_bytes: 64864
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	ll a,b,n;
	cin >> a >> b >> n;
	ll ans = 0;
	if(b - 1 <= n){
		gmax(ans, a - (a+b-1)/b);	
	}
	gmax(ans, a*n/b - a * (n/b));
	cout << ans << '\n';
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
const ll mod=1000000007,N=2e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head
int n;
int main(void){
    cin>>n;
    VI ans(n+1);
    rep(i,2,n+1){
        int u;
        cin>>u;
        ans[u]++;
    }
    rep(i,1,n+1){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int win = 0, lose = 0;
  for (int i = 0; i < s.length(); i++) {
    win += i%2 && s[i] == 'g';
    lose += !(i%2) && s[i] == 'p';
  }
  cout << win-lose;
}

Measured memory_bytes: 512
n,a,b=list(map(int,input().split()))
ans=0
for i in range(1,n+1):
  i1=i//10000
  i2=i//1000%10
  i3=i//100%10
  i4=i//10%10
  i5=i%10
  if i1+i2+i3+i4+i5>=a and i1+i2+i3+i4+i5<=b:
    ans+=i
print(ans)


Measured memory_bytes: 3060
#![allow(dead_code)]
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(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[derive(Debug)]
struct UnionFind {
    par: Vec<usize>,
    sizes: Vec<usize>
}
impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let par = (0..n).collect();
        let sizes = vec![1; n];
        UnionFind{par, sizes}
    }
    fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] { x } else {
            self.par[x] = self.find(self.par[x]);
            self.par[x]
        }
    }
    fn unite(&mut self, x: usize, y: usize) {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y { return; }
        if self.sizes[x] < self.sizes[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.par[y] = x;
        self.sizes[x] += self.sizes[y];
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
    fn size(&mut self, x: usize) -> usize {
        let t = self.find(x);
        self.sizes[t]
    }
}
fn main() {
    let nm: Vec<usize> = read_vec();
    let mut uf = UnionFind::new(nm[0]);
    for _ in 0..nm[1] {
        let ab: Vec<usize> = read_vec();
        uf.unite(ab[0] - 1, ab[1] - 1);
    }
    let mut ans = 0;
    for i in 0..nm[0] {
        let t = uf.size(i);
        if t > ans { ans = t; }
    }
    println!("{}", ans);
}

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

int main(void)
{
  char str[1001];
  int n = 0;
  int e = 0;
  int w = 0;
  int s = 0;
  cin >> str;
  for ( int i=0; str[i]!='\0'; i++ ) {
    switch ( str[i] ) {
    case 'N':
      n++;
      break;
    case 'S':
      s++;
      break;
    case 'E':
      e++;
      break;
    case 'W':
      w++;
      break;
    }
  }
  if ( (n>0 && s==0) || (n==0 && s>0) || (e>0&&w==0) ||(e==0&&w>0 ) ) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void solve() {
    int n;cin>>n;
    int a[n][3],dp[n][3];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(int i=1;i<n;i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    n = int(tokens[0])
    tokens = lines[1].split(" ")
    s = tokens[0]

    return (n, s)


def solve(n, s):

    d = dict([(c, 0) for c in "abcdefghijklmnopqrstuvwxyz"])

    for c in s:
        d[c] = d[c] + 1

    count = 1
    for v in [v for v in d.values() if v > 0]:
        count = count * (v+1)
    

    return (count - 1) %(10**9+7)

def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(void)
{
    int A,B;
    cin >> A >> B;
    if(A+B == 3){
        cout << 3;
    }
    else if(A+B == 4){
        cout << 2;
    }
    else if(A+B == 5){
        cout << 1;
    }
}

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

bool check = true;

int main(){
    string s1,s2;
    cin >> s1 >> s2;
    int len1 =s1.size();
    int len2 =s2.size();
    if(len1-len2==0){
        for(int i=0;i<len2;i++)cout << s1[i] << s2[i];
        cout << endl;
    }else{
        for(int i=0;i<len2;i++)cout << s1[i] << s2[i];
        cout << s1[len1-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define FOR(i, j, n) for(int i=j;i<n;i++)

int N;
char data[1000][1000];
int dp[1000][1000];

int search() {
    int max = 0;
    FOR(i, 1, N) {
        FOR(j, 1, N) {
            if(data[i][j] == '*') {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = std::min({dp[i][j - 1], dp[i - 1][j - 1], dp[i - 1][j]}) + 1;
            max = dp[i][j] > max ? dp[i][j] : max;
        }
    }
    return max;
}

int main() {
    while(1) {
        std::cin >> N;
        if (N == 0) return 0;
        memset(dp, 0, sizeof(dp));
        rep(i, N) {
            rep(j, N) std::cin >> data[i][j];
            dp[i][0] = data[i][0] == '.' ? 1 : 0;
            dp[0][i] = data[0][i] == '.' ? 1 : 0;
        }

        std::cout << search() << std::endl;
    }

    return 0;
}

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

const ll MAX = 300000;
const ll MOD = 998244353;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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(){
  ll N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  vector< ll > modP(N, 1);
  COMinit();

  // i組同じ色がある
  REP(i,K+1) {
    ll t = M * modpow(M-1, N-1-i, MOD) % MOD;
    t = t * COM(N-1, i);
    ans = (ans + t) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11968
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;

const int N = 5e5;
typedef long long ll;
ll ST[4 * N + 5];

string s;

void update(int idx, int l, int r, int tar, ll v) {
	if(l == r) {
		ST[idx] = v;
		return ;
	}
	int mid = (l + r) / 2;
	if(tar <= mid) update(2 * idx, l, mid, tar, v);
	else update(2 * idx + 1, mid + 1, r, tar, v);
	ST[idx] = (ST[2 * idx] | ST[2 * idx + 1]);
}

ll query(int idx, int l, int r, int le, int ri) {
	if(r < le || ri < l) return 0;
	if(le <= l && r <= ri) return ST[idx];
	int mid = (l + r) / 2;
	return query(2 * idx, l, mid, le, ri) | query(2 * idx + 1, mid + 1, r, le, ri); 
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin>>n;
	cin>>s;
	for(int i = 0;i < n;i++) update(1, 0, n - 1, i, 1LL<<(s[i] - 'a'));
	int q;
	cin>>q;
	#define endl '\n'
	while(q--) {
		int op;
		cin>>op;
		if(op == 1) {
			int u;
			char c;
			cin>>u>>c;
			u--;
			update(1, 0, n - 1, u, 1LL<<(c - 'a'));
		} else {
			int l, r;
			cin>>l>>r;
			l--, r--;
			ll res = query(1, 0, n - 1, l, r);
			cout<<__builtin_popcount(res)<<endl;
		}
	}
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int ans = 0;
  char c = s[0];
  REP (i, s.size()) {
    if (s[i] != c) {
      c = s[i];
      ++ans;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 512
n=int(input())
keta=len(str(n))

cnt=0

kouho=set([])

def saiki(x):
    global kouho
    global keta
    if len(x)==keta:
        return 1

    for s in ["3","5","7"]:
        temp=x+s
        kouho.add(temp)
        saiki(temp)

saiki("")

cnt=0
for item in kouho:
    if "3" in item and "5" in item and "7" in item:
        if int(item)<=n:
            cnt+=1

print(cnt)
    


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

using State = string::const_iterator;

struct E{
    int x = 0;
    E(){}
    E(int x): x(x){}
    E &operator+=(const E& a){
        if(x==2 || a.x==2){
            x = 2;
        }else if (x==1 || a.x==1){
            x = 1;
        }else{
            x = 0;
        }
        return *this;
    }
    E &operator*=(const E& a){
        if(x==0 || a.x==0){
            x = 0;
        }else if(x==1 || a.x==1){
            x = 1;
        }else{
            x = 2;
        }
    }
    E &operator-(){
        x = 2-x;
        return *this;
    }
    E operator+(const E& a){
        return E(*this) += a;
    }
    E operator*(const E& a){
        return E(*this) *= a;
    }
};

E var[3];

E formula(State &itr);
E variable(State &itr);

E formula(State &itr){
    E res;
    if(*itr == '-'){
        itr++;
        res = -formula(itr);
    }else if(*itr == '('){
        itr++;
        res = formula(itr);
        if(*itr == '*'){
            itr++;
            res *= formula(itr);
        }else if(*itr == '+'){
            itr++;
            res += formula(itr);
        }else{
            // error
        }
        itr++; // ')'
    }else{
        res = variable(itr);
    }
    return res;
}

E variable(State &itr){
    E res;
    if(isdigit(*itr)){
        res = E(*itr-'0');
    }else if(isalpha(*itr)){
        res = var[*itr-'P'];
    }else{
        // error
    }
    itr++;
    return res;
}

int solve(){
    string s;
    cin >> s;
    if(s == ".") return 1;
    int cnt = 0;
    for(int i=0;i<3;i++)for(int j=0;j<3;j++)for(int k=0;k<3;k++){
        var[0] = E(i);
        var[1] = E(j);
        var[2] = E(k);
        State begin = s.begin();
        if(formula(begin).x == 2){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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



Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
using namespace std;
int data[100000];
int m,n;

int main(){
		while(cin>>n>>m,n||m){
			for(int i=0;i<n;i++)cin>>data[i];
			sort(data,data+n);
			int a=0,b=0,ma=0;
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					if(data[i]+data[j]<=m&&data[i]+data[j]>ma){
						ma=data[i]+data[j];
						a=i;
						b=j;
					}
				}
			}
			if(a==0&&b==0)cout<<"NONE"<<endl;
			else cout<<data[a]+data[b]<<endl;
		}
	return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
  int count=0;
  vector<double> s;
  string str;
  while (cin >> str) {
    vector<string> ops = {"+","-","*","/"};
    auto itr = find(begin(ops), end(ops), str);
    if (itr != end(ops)) {
      double b = s.back(); s.pop_back();
      double a = s.back(); s.pop_back();
      if (*itr == "+") s.push_back(a + b);
      if (*itr == "-") s.push_back(a - b);
      if (*itr == "*") s.push_back(a * b);
      if (*itr == "/") s.push_back(a / b);
    } else {
      s.push_back(stof(str));
    }
  }
  cout << setiosflags(ios::fixed) << setprecision(6);
  for (double d : s) {
    cout << d << endl;
  }
  return 0;
}

Measured memory_bytes: 1284
S = input()
g = 10 ** 9 + 7
x = 1
DP = [[0] * 13 for _ in range(2)]
DP[0][0] = 1
for i in range(len(S)):
    for j in range(13):
        DP[1][j] = DP[0][j] % g
        DP[0][j] = 0
    for j in range(13):
        if S[i] == "?":
            for k in range(10):
               DP[0][(j*10+k)%13] += DP[1][j]
        else:
            DP[0][(j*10+int(S[i]))%13] += DP[1][j]

print(DP[0][5] % g)


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

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

    int num = n;
    int ans = 0;
    if (n <= 9) {
        ans = n;
    }
    else if (n <= 99) {
        ans = 9;
    }
    else if (n <= 999) {
        ans = 9 + (n - 100 + 1);
    }
    else if (n <= 9999) {
        ans = 909;
    }
    else if (n <= 99999) {
        ans = 909 + (n - 10000 + 1);
    }
    else if (n == 100000) {
        ans = 90909;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
  int N;cin>>N;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];
  vector<vector<ll>> dig(65,vector<ll>(N+1,0));
  rep(i,60){
    rep(j,N) {
      int one = ((a[j]>>i)&1) ? 1 : 0;
      dig[i][j+1] = dig[i][j] + one;
    }
  }
  ll ans = 0;
  ll two = 1;
  rep(i,60) {
    ll cnt = 0;
    rep(j,N-1) {
      ll num = (dig[i][N] - dig[i][j+1] + MOD) % MOD;
      // cout<<i<<" "<<j<<" "<<num<<endl;
      if((a[j]>>i)&1) {
	cnt = (cnt + (N - (j+1) - num + MOD) % MOD) % MOD;
      } else {
	cnt = (cnt + num) % MOD;
      }
    }
    ans = (ans + (two * cnt) % MOD) % MOD;
    two = (two * 2) % MOD;
    //    cout<<i<<" "<<cnt<<" "<<ans<<endl;
    //cout<<endl;
  }
  cout<<ans % MOD <<endl;
}


Measured memory_bytes: 160312
#include<stdio.h>
#include<numeric>
int main()
{
	int x,y,i,j;
	while(scanf("%d%d",&x,&y),x)
	{
		int m[15][17];
		for(i=0;i<15;++i)for(j=0;j<17;++j) m[i][j]=-1;
		for(i=0;i<y;++i)for(j=0;j<x;++j) scanf("%d",&m[i][1+j]);

		int a[16][17]={0};
		for(j=1;j<=x;++j)a[0][j]=(m[0][j]-1?1:0);
		for(i=0;i<y-1;++i)
			for(j=1;j<=x;++j)
			{
				if(m[i][j]==0)
				{
					if(m[i+1][j-1]==0) a[i+1][j-1]+=a[i][j];
					if(m[i+1][j+1]==0) a[i+1][j+1]+=a[i][j];
					if(m[i+1][j]==0 || m[i+1][j]==2) a[i+1][j]+=a[i][j];
				}
				else if(m[i][j]==2)
				{
					a[i+2][j] += (m[i+2][j]!=1?a[i][j]:0);
				}
			}
		for(i=1;i<=x;++i) a[y][i] += a[y-1][i];
		printf("%d\n", std::accumulate(&a[y][1],&a[y][x+1],0));
	}
	return 0;
}

Measured memory_bytes: 0
package main

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

var sc *bufio.Scanner

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

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

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	s := nextStr()
	ans := 0
	mode := '>'
	span, peak := 0, 0
	for _, r := range s {
		switch {
		case r == mode:
			span++
		case r == '>':
			peak = span
			ans += (span * (span + 1)) / 2
			span = 1
			mode = r
		case peak >= span:
			ans += (span * (span - 1)) / 2
			span = 1
			mode = r
		case peak < span:
			ans += (span - peak)
			ans += (span * (span - 1)) / 2
			span = 1
			mode = r
		}
	}
	switch {
	case mode == '<':
		ans += (span * (span + 1)) / 2
	case peak >= span:
		ans += (span * (span - 1)) / 2
	case peak < span:
		ans += (span - peak)
		ans += (span * (span - 1)) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
#include <queue>
#include<map>
#define lli long long int
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i=a;i<n;i++)
using namespace std;
int main(){
    lli n,t=0;
    cin>>n;
    while(n--){
        lli in;
        cin>>in;
        if(in>=t){t=in;}
        else{
            if(t-in>=2) return cout<<"No",0;

        }
    }
    return cout<<"Yes",0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;

void main(){
    auto nk=readln.split.map!(to!long).array;
    auto N=nk[0];
    auto K=nk[1];
    auto tree=new RedBlackTree!(int[],"a[0]<b[0]",true);
    foreach(i;0..N)tree.insert(readln.split.map!(to!int).array);
    long count=0;
    foreach(elm;tree[]){
        count+=elm[1];
        if(count>=K){
            writeln(elm[0]);
            return;
        }
    }
}

Measured memory_bytes: 12924
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int P = in.nextInt();
		while(N != 0 || M != 0 || P != 0){
			int count = 0;
			int count2 = 0;
			for(int i = 0;i < N;i++){
				int X = in.nextInt();
				count = count + X;
				if(i + 1 == M){
					count2 = X;
				}
			}
			count = count * (100-P);
			if(count2 == 0) count = 0;
			else count = count / count2;
			System.out.println(count);
			N = in.nextInt();
			M = in.nextInt();
			P = in.nextInt();
		}
	}
}

Measured memory_bytes: 27704
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		String s = sc.nextLine();
		int K = sc.nextInt();

		List<String> sub = new ArrayList<>();
		char fast_char = 'z';

		for(int i=0;i<s.length();i++) {
			if(s.charAt(i) <= fast_char) {
				fast_char = s.charAt(i);
			}else if(sub.size() > K) {
				continue;
			}

			for(int j=i;j<=Math.min(s.length(),i+5);j++) {
				String temp = s.substring(i, j);
				if(!sub.contains(temp)) {
					sub.add(temp);
				}
			}
		}

		Collections.sort(sub);

		System.out.println(sub.get(K));
	}
}


Measured memory_bytes: 24512
def main(n, x_u):
    ans = 0
    btc = 380000.0

    for x, u in x_u:
        if u == 'JPY':
            ans += int(x)
        else:
            ans += float(x) * btc

    print(ans)


if __name__ == "__main__":
    n = int(input())
    x_u = [input().split() for _ in range(n)]

    main(n, x_u)


Measured memory_bytes: 2940
S = input()

is_odd = True
is_even = True

for i in range(len(S)):
    if (i+1) % 2 == 1:
        if S[i] == 'L':
            is_odd = False
    else:
        if S[i] == 'R':
            is_even = False

print('Yes' if is_odd and is_even else 'No')


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;


ll ans,mx,sum,mn=1e8;
int main(){
	string s;
	cin>>s;
	int t = s[0]+1;
	char c = t;
	cout<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
ll gcd(ll a , ll b){
    return (a == 0)? b : gcd(b%a ,a);
}
ll sum(ll a , ll b , ll n){
    ll l , r ;
    if(a%n == 0)
        l = a;
    else
        l = a + n -a%n;
    if(b%n == 0)
        r = b;
    else
        r = b-b%n;
    
    if(r < l)
        return 0;
    else
        return (r-l)/n+1;

}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    ll a , b , c , d;
    cin >> a >> b >> c >> d;
    ll want = (c*d)/gcd(c , d);
    ll ans = b-a+1;
    ans -= sum(a , b , c);
    ans -= sum(a , b , d);
    ans += sum(a , b , want); 
    cout << ans<< endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.BitSet;
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int[] A = new int[9];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}
		
		int N = sc.nextInt();
		int[] B = new int[N];
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}

		BitSet bits = new BitSet(9);
		for (int i = 0; i < A.length; i++) {
			for (int value : B) {
				if (A[i] == value) bits.set(i);
			}
		}

		System.out.println(bingo(bits) ? "Yes" : "No");
	}
	
	boolean bingo(BitSet bits){
		if (bits.get(0)) {
			if (bits.get(3) && bits.get(6)) return true;
			if (bits.get(1) && bits.get(2)) return true;
			if (bits.get(4) && bits.get(8)) return true;
		}
		if (bits.get(1) && bits.get(4) && bits.get(7)) return true;
		if (bits.get(2) && (bits.get(5) && bits.get(8)) || (bits.get(4) && bits.get(6))) return true;
		if (bits.get(3) && bits.get(4) && bits.get(5)) return true;
		return bits.get(6) && bits.get(7) && bits.get(8);
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 23124
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n,x,t;
	cin>>n>>x>>t;

	int u=ceil(n/(long double)x);

	cout<<u*t<<endl;

}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
	
	fastio;
	
	string s1,s2;
	cin>>s1>>s2;
	int cnt=0;
	for (int i = 0; i < s1.size(); ++i)
	{
	  if(s1[i]!=s2[i])
	  	cnt++;
	}


	cout<<cnt;
	return 0;
}



Measured memory_bytes: 3844
from collections import Counter
N = int(input())
AC = Counter(list(map(int, input().split())))
if N % 2 == 1:
    if N == 1:
        ans = AC[0] == 1
    else:
        ans = AC[0] == 1
        for k, v in AC.most_common(N//2):
            if k > N-1 or k % 2 != 0 or v != 2:
                ans = False
                break
else:
    ans = True
    for k, v in AC.most_common():
        if k > N or k % 2 == 0 or v != 2:
            ans = False
            break
if ans:
    print(pow(2, N//2, 10**9+7))
else:
    print(0)

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    ll i = 0, cur = 1000, num = 0, dec = 1, ans = 0;
    while(i < n){
        if(i == n-1) {
            cur += num * a[i];
            break;
        }
        if(dec) {
            if(a[i] < a[i+1]) {
                num += cur / a[i];
                cur -= (cur / a[i]) * a[i];
                dec = 0;
                i++;
            } else {
                i++;
            }
        }else{
            if(a[i] > a[i+1]) {
                cur += num * a[i];
                num = 0;
                dec = 1;
                i++;
            } else {
                i++;
            }
        }
    }
    cout << cur << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

string to_string(string s) { return '\"' + s + '\"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A,B> p)
{ return "(" + to_string(p.F) + ", " + to_string(p.S) + ")"; }
template <typename T> string to_string(T v) {
	int f = 0; string res = "{";
	for (const auto &x: v)
		res += (f++ ? ", " : "") + to_string(x);
	return res + "}";
}
void debug_out() { cerr << "]\n"; }
template <typename T, typename... V>
void debug_out(T a, V... v)
{ cerr << to_string(a); if (sizeof...(v)) cerr << ", "; debug_out(v...); }

#ifdef LOCAL // add -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = [", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif // debug(var1, var2, ...);

const int N = 2e5;
int modp[N+5]; // 2^x % (mod+1)
int modm[N+5]; // 2^x % (mod-1)
int memo[N+5];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	memo[0] = 0;
	REP(i, 1, N+4)
	{
		int y = i;
		int div = 0;
		while (y > 0)
		{
			if (y & 1) div++;
			y /= 2;
		}
		int nxt = i % div;
		memo[i] = memo[nxt]+1;
	}

	int n; string s;
	cin >> n >> s;
	int mod = 0;
	REP(i, 0, n-1)
	{
		if (s[i] == '1')
			mod++;
	}
	modp[0] = 1;
	modm[0] = 1;
	if (mod > 1)
	{
		REP(i, 1, N)
			modm[i] = 2 * modm[i-1] % (mod-1);
	}
	REP(i, 1, N)
		modp[i] = 2 * modp[i-1] % (mod+1);

	int curp = 0, curm = 0;
	if (mod > 1)
	{
		REP(i, 0, n-1)
		{
			if (s[n-1-i] == '1')
				curm = (curm + modm[i]) % (mod-1);
		}
	}
	REP(i, 0, n-1)
	{
		if (s[n-1-i] == '1')
			curp = (curp + modp[i]) % (mod+1);
	}

	REP(i, 0, n-1)
	{
		int x;
		if (s[i] == '1' and mod == 1)
		{
			cout << 0 << '\n';
			continue;
		}
		else if (s[i] == '1')
		{
			x = (curm - modm[n-1-i] + mod-1) % (mod-1);
		}
		else
		{
			x = (curp + modp[n-1-i]) % (mod+1);
		}
		cout << memo[x]+1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 6108
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
cnt = 0
for i in range(N):
  sum = C
  for j in range(M):
    sum += A[i][j]*B[j]
  if sum > 0:
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
ll compute(ll l) {
	if(l==-1) {
		l=0;
	}
	ll ans[] = {l,1,l+1,0};
	ll lol=l%4;
	return ans[lol];
}


int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	ll a,b; cin>>a>>b;
	ll ans=compute(b)^compute(a-1);
	cout<<ans<<endl;




	return 0;
}


Measured memory_bytes: 256
#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;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[51];
const int C = 2510;
ll dp[52][C*2+10];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, A; cin>>n>>A;
	for(int i = 0; i < n; i++) {cin>>a[i]; a[i]-=A;}
	dp[0][a[0]+C]++;
	dp[0][C]++;
	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j <= C*2+9; j++)
		{
			dp[i][j]+=dp[i-1][j];
			if(j+a[i]<C*2+10&&j+a[i]>=0)
			{
				dp[i][j+a[i]]+=dp[i-1][j];
			}
		}
	}
	dp[n-1][C]--;
	cout<<dp[n-1][C]<<'\n';
}


Measured memory_bytes: 2176
#include<iostream>
#include<climits>
#define P 2019

using namespace std;

int main(){
        long l,r;
        cin >> l >> r;
        if( l%P == 0 || r % P == 0){
                cout << 0 << endl;
        }else if( l / P != r / P){
                cout << 0 << endl;
        }else{
                long ans = LONG_MAX;
                for(long i=l; i<r;i++){
                        for(long j = i+1;j<=r;j++){
                                long m = (i * j) % P;
                                if(ans > m){
                                        ans = m;
                                }
                        }
                }

                cout << ans << endl;
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define sync()      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fileIO()    freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define F           first
#define S           second
#define ers         erase
#define ins         insert
#define db          pop_back
#define pb          push_back
#define df          pop_front
#define pf          push_front
#define SZ(x)       ((ll)x.size())
#define sqr(x)      (x)*(x)
#define Blz(x)      __builtin_clz(x)
#define Brz(x)      __builtin_ctz(x)
#define Bones(x)    __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define kill(x)     return cout<<x,0
#define dbgp(x)     cerr<< #x << " = " << x.F << ", " << x.S << endl
#define dbg(x)      cerr<< #x << " = " << x << endl
#define ddbg(i,x)   cerr<< #i << " = " << i << " / "; dbg(x[i])
#define tdbg(i,E,x) cerr<< #i << " = " << i << " / "; ddbg(E,x[i])
typedef long long                                 ll;
typedef long double                               ld;
typedef unsigned short int                        usi;
typedef pair<long long,bool>                      plb;
typedef pair<long long,long long>                 pll;
typedef string                                    str;
typedef priority_queue<ll>                        maxheap;
typedef priority_queue<ll,vector<ll>,greater<ll>> minheap;
typedef priority_queue<pll,vector<pll>,greater<pll>> djq;
const ll maxn=1e5+12, inf=4e18, mod=1e9+7; const ld pi=3.14159265359, eps=1e-9;
ll dp[10010][2][110];
int main(){
    sync();
    string k; int d; cin>>k>>d;
    int len=SZ(k),x;
    dp[0][1][0]=1;
    for(int i=0;i<len;i++)for(bool j:{0,1}){
        for(int l=0;l<d;l++){
            if(!dp[i][j][l]) continue;
            if(!j) for(int m=0;m<10;m++) dp[i+1][0][(l+m)%d]+=dp[i][j][l], dp[i+1][0][(l+m)%d]%=mod;
            else{
                x=k[i]-'0';
                for(int m=0;m<x;m++) dp[i+1][0][(l+m)%d]+=dp[i][j][l], dp[i+1][0][(l+m)%d]%=mod;
                dp[i+1][1][(l+x)%d]+=dp[i][j][l], dp[i+1][1][(l+x)%d]%=mod;
            }
            //dbg(dp[i][j][l]);
        }
    }
    cout<<(dp[len][0][0]+dp[len][1][0]-1+mod)%mod;
    return 0;
}
/**
 (                            )   (   )
 )\ )             (      )  ( /(  () /(
(()/(  (  (    (  )\  ( /(  )\()) )\ ())
 /(_))_)  )\   )\((_) )(_))(_)\) ((_)(_)
(_)) __| ((_) ((_)| |((_)_)| |(_)| |_| |
  | (_ |/ _ \/ _ \| |/ _` || / / |  _  |
   \___|\___/\___/|_|\__,_||_\_\ |_| |_|
**/


Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    string s;
    cin >> s;
    int a = 0;
    for (char n : s)
    {
        if (n == '+')
        {
            a++;
        }
        else
        {
            a--;
        }
    }
    cout << a;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
	int n,i;
	scanf("%d",&n);
	int h[n];
	int cost[n];	
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	int conpara=0;
	cost[0]=0;
	
	for(i=1;i<n;i++){
		cost[i]=cost[i-1]+abs(h[i-1]-h[i]);
		if(i>=2){
			conpara=cost[i-2]+abs(h[i-2]-h[i]);
			if(cost[i] >conpara){
				cost[i]=conpara;
			}
		}

		//printf("%d; %d\n",i,cost[i]);
	}
	printf("%d\n",cost[n-1]);
	

	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
#define CO(x) cout<<(x)<<endl;
#define COSP(x) cout<<(x)<<" ";
#define DICIMAL(x) fixed<<setprecision(x)
using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

  int N,K; cin>>N>>K;
  string S; cin>>S;

  vi nums;
  if(S[0]=='0') nums.push_back(0); // the first num should be 1
  for(int i=0; i<S.size();){
    int j = i;
    while(j<S.size() && S[j]==S[i]) ++j;
    nums.push_back(j-i);
    i = j;
  }
  if(S.back() == '0') nums.push_back(0); // the las num also shuld be 1

  vi sums((int)nums.size() + 1, 0);
  REP(i,nums.size()) sums[i+1]=sums[i]+nums[i];

  int ans = 0;
  for (int left=0; left<sums.size(); left+=2){
    int right = left + K*2+1;
    if(right>=sums.size()) right = (int)sums.size()-1;
    ans = max(ans, sums[right]-sums[left]);
  }

  cout<<ans<<endl;
  return 0;
}


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

int main()
{
	char str[102];
	int len,count,flg,ans=0;

	while(fgets(str,102,stdin)!=NULL)
	{
		flg=1;
		len=strlen(str)-1;
		for(count=0;count<len/2;count++)
		{
			if(*(str+count)!=*(str+len-count-1))
			{
				flg=0;
			}
		}
		if(flg)
		{
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  set<int> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  if (st.size()==2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
#define all(a) a.begin(),a.end()
int ans;
unordered_map<int,int>m;
signed main(){
	int n;
	cin>>n;
	int a[n],b[n];
	r(i,n)scanf("%ld",&a[i]),b[i]=a[i];
	r(i,n-1)b[i+1]+=b[i];
	r(i,n)m[b[i]]++;
	int sum=0;
	r(i,n){
		ans+=m[sum];
		m[b[i]]--;
		sum+=a[i];
		//ans+=m[-a[i]];
	}
	cout<<ans<<endl;
}

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

int main() {
  int a, b, c;
  int t = 0;

  cin >> a >> b >> c;
  
  for (int i = a; i <= b; i++){
    if ( c % i == 0) t = t + 1;
  }

  cout << t << endl;
  
  return 0;
}



Measured memory_bytes: 3104
import math

n = int(input())
ans = [0] * n

for i in range(1, int(math.sqrt(n))):
    for j in range(1, i + 1):
        for k in range(1, j + 1):
            fn = i * i + j * j + k * k + i * j + j * k + k * i
            if fn > n:
                break
            if i != j and j != k and k != i:
                ans[fn - 1] += 6
            elif i == j and j == k:
                ans[fn - 1] += 1
            else:
                ans[fn - 1] += 3

for i in range(n):
    print(ans[i])


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll nr = 0;
    for(char c : s){
        nr += (c == 'R');
    }
    ll ans = 0;
    REP(i, nr){
        ans += s.at(i) != 'R';
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3752
#include<stdio.h>
#include<string.h>
 
int main(){
  int i,sum=0;
  char number[1001];
 
  while(1){
 
  scanf("%s",number);
  if(number[0]=='0') break;
 
  for(i=0;i<strlen(number);i++){
    sum+=number[i]-'0';
  }
 
  printf("%d\n",sum);
  sum=0;
  }
 
 
  return 0;
}


Measured memory_bytes: 2028
#include<stdio.h>



int main(){
  int A[100][100],a,b,c,d,i,j;

  scanf("%d",&a);
  
  for(i=0;i<a;i++){
    
      for(j=0;j<a;j++){
	
          A[i][j]=0;
	  
      }
      
  }
  
  for(i=0;i<a;i++){
    
    scanf("%d%d",&b,&d);
    
    b--;
    
    for(j=0;j<d;j++){
      
      scanf("%d",&c);
      
      A[i][c-1]=1;
      
    }
  }

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

  return 0;
}



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

int main()
{
    int n, a;
    vector<int> renga;
    int cnt_num = 1;
    int sum = 0;
    int i;
    
    cin >> n;
    for(i=0; i<n; i++){
        cin >> a;
        renga.push_back(a);
    }
    for(i=0; i<n; i++){
        if(cnt_num==renga[i]){
            cnt_num++;
        }
        else { sum += 1; }
    }
    if(sum>=0 && cnt_num>1){cout << sum << endl;}
    else { cout << -1 << endl;}
    return 0;
}


Measured memory_bytes: 1400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  while (cin >> n, n) {
    vector<char> c(n);
    rep(i, n) cin >> c[i];

    int al[30] = {0};
    int cmax = 0;
    int d = -1;
    char cans = 'A';

    rep(i, n) {
      al[c[i] - 'A']++;
      cmax = max(cmax, al[c[i] - 'A']);

      bool f = false;
      int q = 0;
      rep(j, (int)'Z' - 'A' + 1) {
        if (al[j] == cmax) {
          q++;
          continue;
        }
        if (cmax <= al[j] + n - i - 1) f = true;
      }

      if (!f && 1 == q) {
        d = i + 1;
        break;
      }
    }

    int flag = 0;
    rep(i, (int)'Z' - 'A' + 1) {
      if (cmax == al[i]) {
        cans = (char)(i + 'A');
        flag++;
      }
    }

    if (1 < flag) {
      cout << "TIE\n";
    } else {
      cout << cans << " " << d << "\n";
    }
  }

  return 0;
}



Measured memory_bytes: 3120
N = int(input())

restaurants = []

for i in range(N):
    s, p = map(str, input().split())
    p = int(p)
    restaurants.append([i+1, s, p])

restaurants = sorted(restaurants, key=lambda x: (x[1], -x[2]))

for i in range(len(restaurants)):
    print(restaurants[i][0])


Measured memory_bytes: 3060