akhauriyash/Code-Regression huggingface dataset:
//main
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long n;
    cin>>n;
    vector<vector<long long>> s(3,vector<long long>(0));
    set<long long> g;
    for(long long i=0;i<n;i++){
        char t;
        cin>>t;
        if(t=='R') s.at(0).push_back(i);
        else if(t=='G') s.at(1).push_back(i);
        else{
            s.at(2).push_back(i);
            g.insert(i);
        }
    }
    long long a=s.at(0).size();
    long long b=s.at(1).size();
    long long c=s.at(2).size();
    long long x=a*b*c;

    // cout<<a<<endl;
    // cout<<b<<endl;
    // cout<<c<<endl;


    long long count=0;

    for(auto &p:s.at(0)){
        for(auto &q:s.at(1)){
            if((p-q)%2==0){
                if(g.count((p+q)/2)){
                    count++;
                }
            }
            if(g.count(p*2-q)) count++;
            if(g.count(q*2-p)) count++;
        }
    }
    cout<<x-count;
    // cin>>s;
    // long long64_t sum;
    // vector<long long>
    // for(long long i=0;i<n;i++){
    //     for(long long j=i+1;j<n;j++){

    //     }
    // }
}

Measured memory_bytes: 3668
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  T := make([][]int, N)
  for i := range T {
    T[i] = make([]int, 0)
  }
  var a, b int
  for i := 1; i < N; i++ {
    NextInt(&a, &b)
    a, b = a - 1, b - 1
    T[a] = append(T[a], b)
    T[b] = append(T[b], a)
  }
  P := make([]int, N)
  for i := range P[1:] {
    P[i + 1] = -1
  }
  Q := make([]int, N)
  pos := 1
  for _, q := range Q {
    for _, adj := range T[q] {
      if P[adj] != -1 { continue }
      P[adj] = q
      Q[pos] = adj
      pos++
    }
  }
  S := make([]int, N)
  C := make([]int, N)
  ans := "YES"
  for i := N - 1; 0 < i; i-- {
    u := Q[i]
    p := P[u]
    if u != 0 && len(T[u]) == 1 {
      S[u] = A[u]
    }
    c := 2 * A[u] - S[u]
    C[u] = MaxInt(c, C[u])
    if c < 0 || A[u] < C[u] {
      ans = "NO"
      break
    }
    S[p] += c
    C[p] = MaxInt(c, C[p])
  }
  if 1 < len(T[0]) { A[0] *= 2 }
  if S[0] != A[0] { ans = "NO" }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 13976
n = int(input())
num = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ans = 'No'
for i in range(len(num)):
  for s in range(len(num)):
    if num[i] * num[s] == n:
      ans = 'Yes'
      break
print(ans)

Measured memory_bytes: 9048
Card = [list(map(int, input().split())) for _ in range(3)]
Bingo = [[False]*3 for _ in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        if b in Card[j]:
            Bingo[j][Card[j].index(b)] = True
ans = False
for i in range(3):
    if all(Bingo[i][j] for j in range(3)):
        ans = True

for j in range(3):
    if Bingo[0][j] and Bingo[1][j] and Bingo[2][j]:
        ans = True

if Bingo[0][0] and Bingo[1][1] and Bingo[2][2]:
    ans = True
if Bingo[0][2] and Bingo[1][1] and Bingo[2][0]:
    ans = True

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 8932
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	int n, q, l, r, forward;
	string s, sub_s;
	cin >> n >> q;
	cin >> s;
	vector<int> vec_sum(n,0);
	for(int i=1; i<=n-1; ++i){
		if(s[i] == 'C' && s[i-1] == 'A'){
			vec_sum[i] = vec_sum[i-1] + 1;
		}
		else{
			vec_sum[i] = vec_sum[i-1];
		}
	}
	while(q){
		cin >> l >> r;
		cout << vec_sum[r-1] - vec_sum[l-1] << '\n';
		q--;
	}
	return 0;
}


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

#define vi vector<int>
#define pb push_back
#define ll long long
#define qi queue<int>
#define vll vector<long long>
#define si set<int>
#define mi map<int,int>
#define mod %
#define frt(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define pair_int pair<int,int>
#define pair_ll pair<ll,ll>
#define pq priority_queue
#define N 3001

double dp[N][N];

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

   double h[n+1];
   double t[n+1];


   fre(i,1,n) {
   	cin >> h[i];
   	t[i] = 1-h[i];
   }

   dp[0][0] = 1;

   for(int i=1;i<=n;i++)
   {
   	  for(int j=n;j>=0;j--)
   	  {
   	  	  if(j==0)
   	  	  	dp[i][j] = dp[i-1][j]*t[i];
   	  	  else
   	  	    dp[i][j] = dp[i-1][j-1]*h[i] + dp[i-1][j]*t[i];
   	  }
   }

   double sum = 0;

   for(int i=(n/2)+1;i<=n;i++)
   		sum+=dp[n][i];

   cout << fixed;
   cout << setprecision(10);
   cout << sum << endl;
   return 0;

}

  


Measured memory_bytes: 70656
class Node:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

class BST:
    def __init__(self):
        self.root = None

    def insert(self, data):
        p = None # parent
        n = self.root
        if n == None:
            self.root = Node(data)
            return
        else:
            while n is not None:
                p = n
                if data < n.data:
                    n = n.left
                else:
                    n = n.right

            if (data < p.data):
              p.left = Node(data)
            else:
              p.right = Node(data)

    def inorder(self):
        self._inorder(self.root)
    def _inorder(self,node):
        if node is not None:
            self._inorder(node.left)
            print(" " + str(node.data), end="")
            self._inorder(node.right)
    def preorder(self):
        self._preorder(self.root)
    def _preorder(self,node):
        if node is not None:
            print(" " + str(node.data), end="")
            self._preorder(node.left)
            self._preorder(node.right)

n = int(input())
t = BST()
for i in range(0, n):
  line = input().split()

  if line[0] == "insert":
    t.insert(int(line[1]))
  elif line[0] == "print":
    t.inorder()
    print()
    t.preorder()
    print()


Measured memory_bytes: 105172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll tmp = 0, sum = 0;
    while (sum < c) {
        tmp++;
        sum += a;
        if (tmp%7 == 0) sum += b;
        
    }
    cout << tmp << endl;
}


Measured memory_bytes: 3112
# -*- coding: utf-8 -*-
# C
# 
# input
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
sa = []
for i in range(m-1):
  sa.append(x[i+1]-x[i])
sa.sort()
g = 0
# calc
if n >= m:
  None
else:
  for j in range(m-n):
    g += sa[j]
# output
print(g)

Measured memory_bytes: 13960
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int ll 
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = 200005;
#ifndef LOCAL
#define cerr if(0)cout
#endif
int A[MAXN];
int sum[MAXN];
int n;
int32_t main() 
{
	IAMSPEED
	cin >> n;
	FOR(i,1,n) cin >> A[i];
	FOR(i,1,n) sum[i] = sum[i-1] + A[i], sum[i] %= MOD;
	int ans = 0;
	FOR(i,1,n) {
		int cur = A[i] * sum[i-1];
		cur %= MOD;
		ans += cur;
		ans %= MOD;
	}
	cout << ans;
}



Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s1,s2;
	int cnt=0;
	cin>>s1>>s2;
	for(int i=0;i<s1.length();i++){
		if(s1[i]!=s2[i]){
			cnt++;
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 3920
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[] result = new int[n];
        List<Integer> candidates = new ArrayList<>(n);
        for(int i = 0 ; i < n ; i++){
            result[i] = 0;
            candidates.add(-1);
        }

        for(int i = 0 ; i < m ; i++){
            int s = scanner.nextInt();
            int c = scanner.nextInt();

            //zero
            if(n > 1 && s == 1 && c == 0){
                System.out.println("-1");
                System.exit(0);
            }

            //Duplicated
            if(candidates.get(s - 1) >= 0 && candidates.get(s - 1) != c){
                System.out.println("-1");
                System.exit(0);
            }
            candidates.set(s -1 , c);
        }

        for(int i = 0 ; i < candidates.size() ; i++){
            int c = candidates.get(i);
            if(c >= 0){
                result[i] = c;
            }
        }
        if(n > 1 && result[0] == 0){
            result[0] = 1;
        }

        StringBuilder r = new StringBuilder();
        for(int i = 0 ; i < result.length ; i++){
            r.append(result[i]);
        }

        System.out.println(r.toString());
    }

}


Measured memory_bytes: 22996
s = input()
t = input()
alpha = 'abcdefghijklmnopqrstuvwxyz'
dic_s = {}
dic_t = {}
for i in alpha:
    dic_s[i] = 0
    dic_t[i] = 0
for i, j in zip(s, t):
    dic_s[i] += 1
    dic_t[j] += 1
val_s = sorted(dic_s.values())
val_t = sorted(dic_t.values())
ans = 'Yes'
for i, j in zip(val_s, val_t):
    if i != j:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DPredictionAndRestriction solver = new DPredictionAndRestriction();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPredictionAndRestriction {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int k = in.nextInt();
            int[] score = new int[3];
            boolean[] changed = new boolean[n];
            Arrays.fill(changed, false);
            score[1] = in.nextInt();
            score[2] = in.nextInt();
            score[0] = in.nextInt();
            String rsp = "rsp";
            String s = in.next();
            int res = 0;
            for (int i = 0; i < s.length(); i++) {
                if (i >= k && s.charAt(i) == s.charAt(i - k) && !changed[i - k]) {
                    changed[i] = true;
                    continue;
                }
                res += score[rsp.indexOf(s.charAt(i))];
            }
            out.println(res);

        }

    }
}



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

int main(){
  string S;
  string ans = "Yes";
  cin >> S;

  for(int i= 0; i < S.size(); i++){
    if((i % 2 == 0) && (S[i] == 'L')){
      ans = "No";
      break;
    }
    if ((i % 2 == 1) && (S[i] == 'R')){
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll n,m;
  cin>>n>>m;
  cout << n*(n-1)/2+m*(m-1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
import math

def count_factor(n, d=2):
    for i in range(n):
        if n & d<<i:
            return i + 1

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))

    ans = sum([count_factor(a) for a in A if a % 2 == 0])
    print(ans)

if __name__ == '__main__':
    main()

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


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

    int N,T,A;
    cin >> N >> T >> A;
    int H[N];
    rep(i,N) { 
        cin >> H[i];
    }
    int ans=0;
    double dif=11000.0;

    rep(i,N){
        double tep=A-(T-H[i]*0.006);
        tep=abs(tep);
        if(dif>tep) {
            ans=i;
            dif=tep;
        }

    }
    cout <<ans+1 << endl;


}


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

int max(int a,int b){
	if(a>=b) return a;
	else return b;
}

int main(void){
	int n;
	int i;
	int red=0;
	int white=0;
    char *storn;
    scanf("%d",&n);
	int ans,num;

	storn=malloc((n+1)*sizeof(char));
	scanf("%s",storn);
    
	for(i=0;i<n;i++){
		if(storn[i]=='R') red+=1;
	}


  for(i=0;i<=n;i++){
	if(storn[i]=='R'){
       red-=1;
	   num=max(red,white);
	}
	else{
		num=max(red,white);
		white+=1;
	}

	
	if(i==0) ans=num;
	else{
		if(ans>num)
		  ans=num;
	}
  }
   

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

	free(storn);
	return 0;
}

Measured memory_bytes: 1712
if __name__ == '__main__':
    input_list = list(map(int, input().split()))
    A = input_list[0]
    B = input_list[1]
    T = input_list[2]

    cnt = int(T+0.5)//int(A)
    answer = 0

    for i in range(1, cnt+1):
        answer += B

    print(answer)

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABuyingSweets solver = new ABuyingSweets();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABuyingSweets {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println((in.nextInt() - in.nextInt()) % in.nextInt());
        }

    }
}



Measured memory_bytes: 23252
from sys import stdin
import bisect

n,m = [int(x) for x in stdin.readline().rstrip().split()]
if m == 0:
    li = [0]
else:
    li = [int(stdin.readline().rstrip()) for _ in range(m)]

dp = [-1]*(n+1)

dp[0] = 1

if li[0] == 1:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,n+1):
    if li[bisect.bisect_right(li,i)-1] == i:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%(10**9+7))

Measured memory_bytes: 460020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
	long double a[200010];
int main() {
	ll n,k;

	cin>>n>>k;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	long double ch=0;
	for(ll i=0;i<k;i++){
		long double sum=0;
		sum+=(a[i]+1)/2.0;
//		cout << sum<<" "<<i<<endl;
		ch+=sum;
	}
	long double ans=ch;
//	cout << ch<<endl;
	for(ll i=0;i<n-k;i++){
		ch=ch-(a[i]+1)/2.0+(a[i+k]+1)/2.0;
//		cout <<now<<" "<<i<<endl;
		if(ch>ans){
			ans=ch;
//			cout << i<<endl;
	//		ansi=i+1;
		}
	}
//	cout << ansi<<endl;
	printf("%.9Lf",ans);
	// your code goes here
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>

#include<chrono>
#include<initializer_list>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

int main() {
	int N;
	cin>>N;
	int A,T;
	cin>>A>>T;
	long long X=A,Y=T;
	for(int i=1;i<N;++i){
		cin>>A>>T;
		long long num1=(X%A==0?X/A:X/A+1);
		long long num2=(Y%T==0?Y/T:Y/T+1);

		if(num1*A>=X && num1*T>=Y){
			if(num2*A>=X && num2*T>=Y){
				if(num1*A+num1*T<num2*A+num2*T){
					X=num1*A;
					Y=num1*T;
				}
				else{
					X=num2*A;
					Y=num2*T;
				}
			}
			else{
				X=num1*A;
				Y=num1*T;
			}
		}
		else{
			X=num2*A;
			Y=num2*T;
		}
	}
	cout<<X+Y<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC098C - Attention
  // 両サイドからカウントする
  int N; cin >> N;
  string S; cin >> S;
  vector<int> w(N, 0);
  vector<int> e(N, 0);
  REP(i, N){
    if(i == 0){
      if(S[i] == 'W') w[i]++;
      if(S[N-i-1] == 'E') e[N-i-1]++;
    }else{
      if(S[i] == 'W'){
        w[i] = w[i-1] + 1;
      }else{
        w[i] = w[i-1];
      }
      if(S[N-i-1] == 'E'){
        e[N-i-1] += e[N-i] + 1;
      }else{
        e[N-i-1] += e[N-i];
      }
    }
  }
  int ans = 1e6;
  REP(i, N){
    if(i == 0){
      ans = min(ans, e[i+1]);
    }else if(i == N-1){
      ans = min(ans, w[i-1]);
    }else{
      ans = min(ans, w[i-1] + e[i+1]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2964
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++) cin >> d[i];
	int sum = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			sum += d[i] * d[j];
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class SegmentTree:
    def __init__(self, n, func, e, arrange=None):
        self.init(n)
        self.func = func
        self.e = e
        self.make_arrange(arrange)
    
    def init(self, n):
        self.inf = pow(2, 32)
        self.n = n
        self.N = 1
        while self.N < self.n:
            self.N *= 2
        self.size = self.N * 2 - 1
        self.N -= 1
    
    def make_arrange(self, arrange):
        self.set_arrange(arrange)
        self.construct(arrange)

    def set_arrange(self, arrange):
        if arrange == None:
            self.segment = [self.e]*(self.size)
            return
        self.segment = [0]*(self.N) + arrange + [self.e]*(self.size-self.N-self.n)
    
    def construct(self, arrange):
        if arrange == None:
            return
        for i in range(self.N-1, -1, -1):
            self.segment[i] = self.func(self.segment[2*i+1], self.segment[2*i+2])
    
    def update(self, i, x):
        i += (self.N-1)
        self.segment[i] = x
        while i > 0:
            i = (i-1)//2
            self.segment[i] = self.func(self.segment[2*i+1], self.segment[2*i+2])
    
    def find(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.e
        elif a <= l and r <= b:
            return self.segment[k]
        else:
            find_l = self.find(a, b, 2*k+1, l, (l+r)//2)
            find_r = self.find(a, b, 2*k+2, (l+r)//2, r)
            res = self.func(find_l, find_r)
            return res

    def count(self, l, r):
        return self.find(l-1, r, 0, 0, self.size-self.N)
    
    def bisect_sub(self, a, b, k, l, r, x):
        if r <= a or b <= l:
            return b+1
        if self.segment[k] < x:
            return b+1
        if k >= self.N:
            return r
        
        find_l = self.bisect_sub(a, b, 2*k+1, l, (l+r)//2, x)
        if find_l <= b:
            return find_l

        find_r = self.bisect_sub(a, b, 2*k+2, (l+r)//2, r, x)
        return find_r

        

    def bisect(self, l, r, x):
        return self.bisect_sub(l-1, r, 0, 0, self.size-self.N, x)
    

def main():
    n, q = map(int, input().split())
    p = list(map(int, input().split()))
    seg = SegmentTree(n, max, 0, arrange=p)

    res = []
    for i in range(q):
        a, b, c = list(map(int, input().split()))
        if a == 1:
            seg.update(b, c)
        elif a == 2:
            ans = seg.count(b, c)
            res.append(ans)
        else:
            ans = seg.bisect(b, n, c)
            res.append(ans)

    print(*res, sep="\n")
            

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 118660
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(ll (i)=0; (i)<(ll)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll N;
ll X, D;

map<ll, vector<pair<ll,ll>>> v[2];
vector<ll> z[2];

signed main(){
    cin >> N >> X >> D;
    if(D < 0){
        X *= -1;
        D *= -1;
    }
    if(D == 0){
        if(X == 0) cout << 1 << endl;
        else{
            cout << N+1 << endl;
        }
        return 0;
    }
    rep(i, N+1){ // i 個が負
        ll x = X*(N-2*i);
        ll t = 0;
        if(x < 0) t = abs(x)/D+1;
        x += t*D;
        ll xpD = x / D - t;
        ll xmD = x % D;

        ll u = (N-1)*N/2 - 2*(i-1)*i/2;
        ll d = -(N-1)*N/2 + 2*(N-1-i)*(N-i)/2;
        u += xpD;
        d += xpD;

        //for(int j=d; j<=u; j+=2) cout << j*D + xmD << " ";
        //cout << endl;

        //assert((u-d)%2 == 0);

        v[(d+1'000'000'000'000'000LL)%2LL][xmD].pb({d, u});
        z[(d+1'000'000'000'000'000LL)%2LL].pb(xmD);
    }
    
    ll ans = 0;
    
    rep(i, 2){
        if(z[i].size() == 0) continue;
        sort(all(z[i]));
        z[i].erase(unique(all(z[i])), z[i].end());
        rep(j, z[i].size()){
            ll xmD = z[i][j];
            sort(all(v[i][xmD]));
            vector<pair<ll, ll>> tmp;
            rep(k, v[i][xmD].size()){
                if(tmp.size() > 0 && v[i][xmD][k].first <= tmp.back().second){
                    tmp.back().second = max(tmp.back().second, v[i][xmD][k].second);
                }
                else{
                    tmp.pb(v[i][xmD][k]);
                }
            }
            rep(k, tmp.size()){
                ans += (tmp[k].second-tmp[k].first)/2LL + 1LL;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23668
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main(){
  int h,w;
  cin >> h >> w;
  string board[h];
  int ansBoard[h][w];
  int dx[8] = {1,0,-1,0,1,1,-1,-1};
  int dy[8] = {0,1,0,-1,1,-1,1,-1};

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

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

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(board[i][j] == '#'){
        for(int k = 0; k < 8; k++){
          if(i + dy[k] >= 0 && i + dy[k] < h && j + dx[k] >= 0 && j + dx[k] < w){
            ansBoard[i + dy[k]][j + dx[k]]++;
          }
        }
      }
    }
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(board[i][j] == '#') cout << "#" ;
      else cout << ansBoard[i][j] ;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
b=[0 for _ in range(N)]
for i in range(N):
    j=N-1-i
    if sum(b[j:N:j+1])%2!=a[j]:
        b[j]=1

print(sum(b))
for k in range(N):
    if b[k]==1:
        if k<N-1:
            print(k+1,end=" ")
        else:
            print(k+1)

Measured memory_bytes: 8380
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    multiset <int, greater<int>> st;
    st.insert(0);

    for (int i = 0; i < (1 << n); i++) {
        int s;
        cin >> s;
        st.insert(s);
    }

    multiset <int, greater<int>> cur;
    cur.insert(*st.begin());
    st.erase(st.begin());

    for (int i = 0; i < n; i++) {
        vector <int> nxt;
        for (auto cur_itr = cur.begin(); cur_itr != cur.end(); cur_itr++) {
            int val = *cur_itr;
            auto itr = st.lower_bound(val - 1);

            if (*itr == 0) {
                cout << "No\n";
                return 0;
            }

            nxt.push_back(*itr);
            st.erase(itr);
        }

        for (int x : nxt) {
            cur.insert(x);
        }
    }

    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 13304
from sys import stdin,setrecursionlimit
setrecursionlimit(10 ** 6)
input = stdin.readline
N, M = map(int, input().split())
ac = [False] * N # index means p
wa = [0] * N # index means p
wa_cnt = 0
for i in range(M):
  p, s = input().split()
  p = int(p) - 1 # index starts from 0
  if ac[p] is False and s == "AC":
    wa_cnt += wa[p]
    ac[p] = True
  elif s == "WA":
    wa[p] += 1
print(ac.count(True), wa_cnt)

Measured memory_bytes: 4596
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#include<map>
#include<deque>
#include<set>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    string str;
    cin >> str;
    int count = 0;
    REP(i, str.size()){
        count += str[i] == 'o';
    }
    if(15-str.size()+count >= 8){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

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

  int res=0;
  for(int i=0;i<n;i++){
    int tmp=0;
    if(a[i]!=b[i]) tmp++;
    if(b[i]!=c[i]) tmp++;
    if(a[i]!=c[i]) tmp++;
    if(tmp==0) res+=0;
    if(tmp==1 || tmp==2) res+=1;
    if(tmp==3) res+=2;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long k, n;
	string s;

	cin >> k >> s;

	n = (long long)(s.length());

	if (k >= n){
		cout << s << endl;
	}
	else{
		cout << s.erase(k) << "..." << endl;
	}

	return 0;
}


Measured memory_bytes: 3600
splitBy :: Char -> String -> [String]
splitBy _ [] = []
splitBy a x =
  let s = takeWhile (/= a) x
      x'= dropWhile (/= a) x
  in
    if x' == []
    then [s]
    else s:(splitBy a $ drop 1 x')

-- ??´???QR    y = -1*(y2-y1)/(x2-x1) (x-xq) + yq
-- ??´???P1P2  y = (y2-y1)/(x2-x1) (x-x1) + y1
-- 2????????´????????????
-- (y2-y1)/(x2-x1) (x-x1) + y1 = -1*(y2-y1)/(x2-x1) (x-xq) + yq
-- 
ans (x1:y1:x2:y2:xq:yq:_)
  = if x1 == x2
  then [xq+2*(x1-xq),yq]
  else
      if y1 == y2
      then [xq,yq+2*(y1-yq)]
      else
        let a  = (y2-y1)/(x2-x1)
            xs = a/(a*a+1) * ( a*x1 - y1 + xq/a + yq)
            ys = -1/a*(xs-xq)+yq
        in
          [xq+2*(xs-xq),yq+2*(ys-yq)]

main = do
  c <- getContents
  let i = map (map read) $ map (splitBy ',') $ lines c :: [[Float]]
      o = map ans i
  mapM_ putStrLn $ map unwords $ map (map show) o 

Measured memory_bytes: 4264
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq, bisect


def solve(N: int, C: int, K: int, T: "List[int]"):
    T.sort()
    T.append(10000000000000)
    count = 0
    i = 0
    while i < N:
        time = T[i]
        for x in range(C):
            if not time <= T[i] <= time + K:
                count += 1
                break
            i += 1
        else:
            count += 1
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    T = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, C, K, T)

if __name__ == '__main__':
    main()


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

typedef pair<int,int> pii;
#define F first
#define S second

int main() {
    int N, W;
    cin >> N >> W;
    vector<pii> O(N);
    for(pii & x : O)
        cin >> x.F >> x.S;
    vector<long long> dp(W+1, 0);
    for(pii & x : O) 
        for(int w=W; w-x.F>=0; w--)
            dp[w] = max(dp[w], dp[w-x.F]+x.S); 
    cout << dp[W];
}

Measured memory_bytes: 1024
import numpy as np
dishes = [int(input()) for _ in range(5)]
dishes = sorted(dishes, key=lambda x: x % 10)
minutes = 0
first = True
for i in dishes:
    if i % 10 == 0:
        minutes += i
    else:
        if first:
            minutes += i
            first = False
        else:
            minutes += int(np.ceil(i/10)*10)
print(minutes)

Measured memory_bytes: 26604
import java.util.Scanner;
public class Main {
        public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            while (true) {
                int H = sc.nextInt();
                int W= sc.nextInt();
                if (H == 0 && W == 0) {
                    break;
                }else{
                    for(int i=0;i<H;i++){
                        for(int j=0;j<W;j++){
                            System.out.print("#");


                        }
                        System.out.println();
                    }
                    System.out.println();

                }

            }
        }
    }


Measured memory_bytes: 34800
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int a[30]={};
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        a[s[i]-97]=1;
    }
    for(int i=0;i<26;i++){
        if(a[i]==0){
            printf("%c\n",i+97);
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline


S = input().strip()
words = []

while True:
    line = input().strip()
    if line == "END_OF_TEXT":
        break
    w = [word.lower() for word in line.split()]
    words += w

ans = 0

for word in words:
    if word == S:
        ans += 1

print(ans)



Measured memory_bytes: 5572
def break_number():
    N = int(input())

    max_count = 0
    max_index = -1

    for i in range(1,N+1):
        count = 0
        num = i
        while True:
            if num % 2 == 0:
                count += 1
                num /= 2
            else:
                max_count = max(max_count, count)
                if max_count == count:
                    max_index = i
                break
    print(max_index)

if __name__ == "__main__":
    break_number()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(ll i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
#define NMAX 15
ll func(ll a){
    if(a==0)return 0;
    else return 1;
}
int main() {
    ll N;
    cin>>N;
    vector<ll> A(N);
    ll x[NMAX][NMAX],y[NMAX][NMAX];
    REP(i,N){
        cin>>A[i];
        REP(j,A[i]){
            cin>>x[i][j]>>y[i][j];
        }
    }
    bool f;
    ll ans=0,sum;
    REP(i,(1<<N)){
        f=true,sum=0;
        REP(j,N){
            if(func(i&(1<<j))==1)sum++;
            REP(k,A[j]){
                if(func(i&(1<<j))==1){
                    if(func(i&(1<<(x[j][k]-1)))!=y[j][k]){
                        f=false;
                    }
                }
            }
        }
        if(f)chmax(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
		int c = Math.max(a+b,a-b);
       
		System.out.println(Math.max(c,a*b));
	}
}


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

int D[6];
    void spin(char c)
    {
        if(c=='E'){
            swap(D[0],D[3]);swap(D[3],D[5]);swap(D[5],D[2]);
        }
        else if(c=='W'){
        swap(D[0],D[2]);swap(D[2],D[5]);swap(D[5],D[3]);
        }
        else if(c=='S'){
        swap(D[0],D[1]);swap(D[0],D[4]);swap(D[4],D[5]);
        }
        else if(c=='N'){
        swap(D[0],D[1]);swap(D[1],D[5]);swap(D[5],D[4]);
        }
    }
int main(){
    for (int i = 0; i < 6 ; ++i) {
        cin >> D[i];
    }
    char c;
    while(cin >> c){
        spin(c);
    }
    cout << D[0] << endl;
    return 0;
}

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

ans = 1
last = A[0]
n = 0
for i in A:
    if n == 0:
        if last < i:
            n = 1
        elif last > i:
            n = -1
        else:
            n = 0
    elif n == 1:
        if last >  i:
            ans += 1
            n = 0
    else:
        if last < i:
            ans += 1
            n = 0
    last = i

print(ans)
            

Measured memory_bytes: 14224
#include <stdio.h>

long XOR(long a, long b){
  long bit_a[30],bit_b[30],bit_xor[30];
  for (int i = 0; i < 30; i++) {
    bit_a[i] = 0;
    bit_b[i] = 0;
  }
  bit_a[0] = a;
  bit_b[0] = b;
  for (int i = 1; i < 30; i++) {
    bit_a[i] += bit_a[i-1]/2;
    bit_a[i-1] %= 2;
    bit_b[i] += bit_b[i-1]/2;
    bit_b[i-1] %= 2;
  }
  for (int i = 0; i < 30; i++) {
    if (bit_a[i] == bit_b[i]) {
      bit_xor[i] = 0;
    } else {
      bit_xor[i] = 1;
    }
  }
  for (int i = 28; i >= 0; i--) {
    bit_xor[i] += bit_xor[i+1]*2;
  }
  return bit_xor[0];
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long all = a[0];
  for (long i = 1; i < n; i++) {
    all = XOR(all,a[i]);
  }
  long ans;
  for (long i = 0; i < n-1; i++) {
    ans = XOR(all,a[i]);
    printf("%ld ", ans);
  }
  ans = XOR(all,a[n-1]);
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 4076
#define M 1000001
T[M],t[M],a;main(m,n,x,i,j){
	for(i=2;i<M;i++)if(!T[i])for(j=i*2;j<M;j+=i)T[j]=1;
	for(;scanf("%d%d",&n,&x),n;printf(m?"%d\n":"NA\n",m)){
		for(memset(t,0,sizeof(t)),t[0]=1,m=i=0;i<n;i++){
			for(scanf("%d",&a),j=0;j+a<=x;j++)if(t[j])if(t[j+a]=1,!T[j+a]&&m<j+a)m=j+a;
		}
	}
exit(0);}

Measured memory_bytes: 8420
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 10010010010
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

 
int main(){
    int n; cin >> n;
    vector<int> v(n),c(n);
    
    rep(i,n) cin >> v[i];
    rep(i, n) cin >> c[i];
    
    int ans = 0;
    rep(i,n){
        int a = v[i] - c[i];
        ans += max(a, 0);
    }
    
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>

using namespace std;
int main() {
    int x,a;
    cin>>x>>a;
    if(a>x)
        cout<<0<<endl;
    else
        cout<<10<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	double best=10000.0;
	int ans;
	int i,h,w;
	for(int u=0;u<n;u++){
		cin>>i>>h>>w;
		double r=w*10000/(h+0.0)/(h+0.0);
		r-=22;
		if(r<0)
			r=-r;
		if(best>r||(best==r&&ans>i)){
			best=r;
			ans=i;
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  bool OK = true;
  rep(i, N) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if ((a % 3) && (a % 5)) OK = false;
    }
  }
  if (OK)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

D=int(input())
c=[int(i) for i in input().split()]
s=[]
for d in range(D):
    s.append([int(i) for i in input().split()])

v = [0]*D
last = [[0 for i in range(26)] for d in range(D)]
t=[0]*D

for d in range(D):
    # d(>=1)日目以降は, 初期化としてd-1日目のlastをコピー
    if d>=1:
        last[d] = last[d-1][:]
    
    # 初期化
    last[d][0] = d+1
    v=s[d][0] - sum([c[j]*(d+1 - last[d][j]) for j in range(26)])
    idx_best=0

    # d日目の時点で満足度最大となるidxを選ぶ(貪欲法)
    for i in range(1, 26):
        v_tmp=v - s[d][idx_best] + s[d][i] - c[idx_best]*(d+1 - last[d][idx_best]) + c[i]*(d+1 - last[d][i])
        if v < v_tmp:
            v = v_tmp
            last[d][i] = d+1
            
            # lastの更新
            if d>=1:
                last[d][idx_best]=last[d-1][idx_best]
            else:
                last[d][idx_best]=0
            
            idx_best=i
    
    t[d]=idx_best + 1           # 1 <= t[d] <= 26 のため

for d in range(D):
    print(t[d])


Measured memory_bytes: 27348
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define m_p make_pair
#define p_b push_back
#define MOD 1000000007
int main()
{
	nfs;
	int t;
	t=1;
//	cin >> t;

	while(t--)
	{
		ll n;
		cin >> n;
		ll arr[n];
		ll i;
		F(i,0,n)
		{
			cin >> arr[i];
		}
		ll dp[n];
		dp[n-2] = abs(arr[n-2]-arr[n-1]);
		dp[n-3] = min(dp[n-2]+(abs(arr[n-3]-arr[n-2])),abs(arr[n-3]-arr[n-1]));
	//	cout << dp[n-2] << dp[n-3] << endl;
		
		RF(i,n-4,0)
		{
			dp[i] = min(dp[i+1]+abs(arr[i]-arr[i+1]),dp[i+2]+abs(arr[i]-arr[i+2]));
			
	//		cout << dp[i] << endl;
			
		}
		cout << dp[0] ;
		
	}
	return 0;

}



Measured memory_bytes: 1792
#include <iostream>


using namespace std;

int main()
{
	while(true)
	{
		int H, W;
		cin >> H >> W;
		if(H == 0 && W == 0)
		{
			return 0;
		}
		for(int i = 0; i < H; ++i)
		{
			for(int j = 0; j < W; ++j)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define li long
#define pb push_back
#define mem(arr,x) memset(arr,x,sizeof(arr))
ll n,a[3001];
ll dp[3001][3001];
ll maxDiff(ll start,ll end)
{
	if(start>end)
		return 0;

	if(dp[start][end]!=-1)
		return dp[start][end];

	ll ans1=a[start]-maxDiff(start+1,end);
	ll ans2=a[end]-maxDiff(start,end-1);
	return dp[start][end]=max(ans1,ans2);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(ll i=0;i<n;i++)
    cin>>a[i];
	mem(dp,-1);
	cout<<maxDiff(0,n-1);
    return 0;
}

Measured memory_bytes: 74116
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int A[5];
  REP(i, 5) cin >> A[i];
  int ans = 1e9;
  REP(i, 5) {
    int c = 0;
    REP(j, 5) {
      if (i == j) c += A[j];
      else c += (A[j] + 9) / 10 * 10;
    }
    ans = min(ans, c);
  }
  cout << ans << '\n';
}


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

int used_prime[1'000'001];
bool is_prime[1'000'001];
vector<int> prime_list;

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

int main(void)
{
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i < 1001; i++) is_prime[i] = true;
  for (int i = 2; i < 1001; i++)
  {
    if (is_prime[i] == false) continue;
    prime_list.push_back(i);
    for (int j = 2; i * j < 1001; j++) is_prime[i * j] = false;
  }
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int tmp = 0;
  for (int i = 0; i < n; i++) tmp = gcd(a[i], tmp);
  bool flag0 = false;
  if (tmp == 1) flag0 = true;
  bool flag = true;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < prime_list.size(); j++)
    {
      if (a[i] < prime_list[j]) break;
      if (a[i] % prime_list[j] == 0)
      {
        if (used_prime[prime_list[j]]) flag = false;
        used_prime[prime_list[j]] = true;
        while (a[i] > 0 && a[i] % prime_list[j] == 0) a[i] /= prime_list[j];
      }
    }
    if (a[i] > 1) 
    {
      if (used_prime[a[i]]) flag = false;
      used_prime[a[i]] = true;
    }
  }
  if (flag) cout << "pairwise coprime" << endl;
  else if (flag0) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
}

Measured memory_bytes: 10876
#include <bits/stdc++.h>
#define MV 4000005
#define MN 2005
#define R register
std::bitset<MV> b;
int n,sum;
inline int read(){
	R int x; R bool f; R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
	return f?-x:x;
}
int main(){
	n=read();b[0]=1;
	for (R int i=1,x; i<=n; ++i)
		x=read(),b|=b<<x,sum+=x;
	R int ans=sum+1>>1;while(!b[ans]) ++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1664
import sys

for i in sys.stdin.readlines():
    m, f, r = [int(x) for x in i.split()]
    if m == f == r == -1:
        break
    elif (m == -1 or f == -1) or (m + f < 30):
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50 or (30 <= m + f <= 50 and r >= 50):
        print('C')
    elif m + f >= 30:
        print('D')

Measured memory_bytes: 7720
n = int(input())
alp = [chr(i) for i in range(97, 97+26)]
 
def update(a, m):
    a_new = []
    m_new = []
    for val_a, val_m in zip(a,m):
        for i in range(val_m + 2):
            a_new += [val_a + alp[i]]
            m_new += [max(val_m, i)]
    return a_new, m_new
 
a = ['a']
m = [0]
 
for i in range(n-1):
  a, m = update(a,m)
 
for v in a:
  print(v)

Measured memory_bytes: 14128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
cost = 0

for i in range(N):
    index = A[i] - 1
    if i != 0 and A[i] - A[i-1] == 1:
        cost += C[index - 1]
    cost += B[index]
print(cost)





Measured memory_bytes: 3060