akhauriyash/Code-Regression huggingface dataset:
N = int(input())
W = list(map(int,input().split()))
ans = 100000000000
for i in range(100):
    tmp = []
    tmp.append(abs(sum(W[:i])))
    tmp.append(abs(sum(W[i:])))
    tmp.sort()
    if tmp[1]-tmp[0] < ans:
        ans = tmp[1]-tmp[0]
print(ans)


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

int main(void)
{
	int n;
	char com[3][10] = {"OUT", "HIT", "HOMERUN"};
	int i;
	int ans;
	char str[10];
	int base[3];
	int count;
	
	for (scanf("%d", &n); n; n--){
		memset(base, 0, sizeof(base));
		ans = 0;
		for (count = 3; count;){
			scanf("%s", str);
			
			for (i = 0; i < 3; i++){
				if (!strcmp(com[i], str)){
					break;
				}
			}
			
			switch (i){
				case 0:
				count--;
				break;
				
				case 1:
				for (i = 2; i >= 0; i--){
					if (base[i]){
						base[i] = 0;
						if (i < 2){
							base[i + 1] = 1;
						}
						else{
							ans++;
						}
					}
				}
				base[0] = 1;
				break;
				
				case 2:
				for (i = 0; i < 3; i++){
					if (base[i]){
						ans++;
					}
				}
				ans++;
				memset(base, 0, sizeof(base));
				break;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		out.println(Math.min(sc.nextInt()*sc.nextInt(), sc.nextInt()));
	}
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

int main(){
	fastIo();
	ll n, k; cin >> n >> k;
	ll a[n];
	for(ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<ll> dp(n, INF);
	dp[0] = 0;
	for(ll i = 0; i < n; i++){
		for(ll j = 1; i + j < n && j <= k; j++){
			dp[i + j] = min(dp[i + j], abs(a[i] - a[i + j]) + dp[i]);
		}
	}
	cout << dp[n - 1] << endl;
}


// int main() {
 
// 	ll N, K;
// 	cin >> N >> K;
// 	vector<> H(N);
// 	for (int i = 0; i < N; i++)
// 	{
// 		cin >> H[i];
// 	}
 
// 	vector<ll> ans(N, INF);
// 	ans[0] = 0;
// 	for (int i = 0; i < N; i++)
// 	{
// 		for (int k = 1; i + k < N && k <= K; k++)
// 		{
// 			ans[i + k] = min(ans[i + k], ans[i] + abs(H[i] - H[i + k]));
// 		}
// 	}
 
// 	cout << ans[N - 1] << endl;
 
 
 
// }

Measured memory_bytes: 1792
/*    Mohammed Sami Khan
                       মোহাম্মদ সামী খান
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define endl "\n"
#define mp(a,b) make_pair(a,b)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;

bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}

int main()
{
    fastio;
    ll t, n, a, b, m, p, q, r, i, j, d, f=0;
    char *ye="POSSIBLE", *no="IMPOSSIBLE";
    cin>>n>>a>>b;
    if(a>b){
        cout<<0<<endl;
    }
    else if(a!=b&&n==1) cout<<0<<endl;
    else if(a==b){
        cout<<1<<endl;
    }
    else{
        q=a+b+(n-2)*b;
        p=a+b+(n-2)*a;
        cout<<q-p+1<<endl;
    }
}


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

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int          n;
    vector <int> a;
    bool         fg = true;

    cin >> n;

    rep(i, n) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    rep(i, n) {
        if (a.at(i) % 2 == 0) {
            if (a.at(i) % 3 == 0 || a.at(i) % 5 == 0) { }
            else { fg = false; }
        }
    }

    if (fg) {
        cout << "APPROVED" << endl;
    }
    else {
        cout << "DENIED" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define sz 200100

int a[sz];
int h[sz];
ll tr[4 * sz];

void update(int s, int e, int i, ll val, int idx)
{
	if (s > i || e < i)
		return;
	if (s == e)
	{
		tr[idx] = val;
		return;
	}
	int m = (s + e) / 2;
	update(s, m, i, val, 2 * idx);
	update(m + 1, e, i, val, 2 * idx + 1);
	tr[idx] = max(tr[2 * idx], tr[2 * idx + 1]);
}

ll query(int s, int e, int qs, int qe, int idx)
{
	if (qs > e || qe < s)
		return 0;
	if (qs <= s && qe >= e)
		return tr[idx];
	int m = (s + e) / 2;
	ll a = query(s, m, qs, qe, 2 * idx);
	ll b = query(m + 1, e, qs, qe, 2 * idx + 1);
	return max(a, b);
}

int main()
{
	int n; ll x;
	scanf("%d", &n);

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

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

	for (int i = 0; i < n; ++i)
	{
		x = query(0, n, 0, h[i] - 1, 1);
		update(0, n, h[i], x + a[i], 1);
	}

	cout << tr[1];




	return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
signed main(){
    int N; cin >> N;
    vector<int>v(N);
    for(auto & e : v) cin >> e;
    array<float,13> cnt = {0};
    cnt[0]++;
    for(auto  e : v)cnt[e]++;
    for(auto  e : cnt) if(e >= 3) return puts("0") * 0;
    if(cnt[0] >= 2 or cnt[12] >= 2) return puts("0")* 0;
  
    vector<int>base(25,0LL);
    base[0] = 1;
    for(int i = 1; i <= 12; ++i){
        if(cnt[i] == 1){
            //???
        } else if(cnt[i] == 2){
            base[i] = base[ 24 - i] = 1;
        }
    }
    int ans = -INF;
    for(int bit = 0; bit < (1LL << 12); ++bit){
        vector<int>tbase = base;
        for(int i = 1; i <= 12; ++i){
            if(cnt[i] == 1){
                ((bit & (1LL << (i - 1))) >= 1 ? tbase[i] : tbase[24 - i]) = 1;
            }
        }
        int tans = INF;
        for(int i = 0; i < tbase.size(); ++i){
            for(int j = 0; j < tbase.size(); ++j){
                if(i != j and tbase[i] != 0 and tbase[j] != 0)
                    cmin(tans,min(max(i,j) - min(i,j),24 - (max(i,j) - min(i,j))));
            }
        }
        cmax(ans, tans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define se second
#define fi first
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define y1 y12313312312
#define endl '\n'
#define gcd gcd
#define tm tadsadaagsd
#define next nqweqweeqeqe
#define er erase
#define int ll

using namespace std;
//using namespace gnu_pbds;

//template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 40, T = 4 * N, logN = (int)log2(N) + 1, inf = 1e9 + 7, sx[4] = {1, -1, 0, 0}, sy[4] = {0, 0, 1, -1};
const ll INF = 1e18 + 9;

int n, m, r, l, e, o, z, ts, id, mx, mn = INF, w;
int a[N];
int f;

void freop()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void boos()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int bp (int x, int y) {
    if (y == 0) return 1;
    if (y % 2 == 1) return bp(x, y - 1) * x;
    else
    {
        int asd = bp(x, y / 2);
        return asd * asd;
    }
}

int sum(int x)
{
    int summa = 0;
    while (x)
    {
        summa += x % 10;
        x /= 10;
    }
    return summa;
}

main()
{
    int x, y;
    setprecision(10);
    //freop();
    boos();
    cin >> m >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    mx = a[0] - a[n - 1] + m;
    for (int i = 1; i < n; i++)
    {
        mx = max(mx, a[i] - a[i - 1]);
    }
    cout << m - mx;
}


Measured memory_bytes: 1792
s = input()
n = len(s)
rlist = ["R", "U", "D"]
llist = ["L", "U", "D"]
for i in range(n):
  if i % 2 == 0 and s[i] in rlist:
    continue
  elif i % 2 == 1 and s[i] in llist:
    continue
  else:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3060
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	A := sc.nextInt()
	B := sc.nextInt()

	fmt.Println((A + B) % 24)

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
vector<int> to[MAXN];
vector<int> d1(MAXN, -1), d2(MAXN, -1);

void dfs(int u, int path, vector<int> &d)
{
  if (d[u] != -1)
  {
    return;
  }
  d[u] = path;
  for (auto v : to[u])
  {
    dfs(v, path + 1, d);
  }
}

int main()
{
  int N, u, v, a, b;
  cin >> N >> u >> v;
  u--, v--;
  for (int i = 0; i < N - 1; i++)
  {
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(u, 0, d1);
  dfs(v, 0, d2);
  int ans = 0, same = (1 << 30);
  for (int i = 0; i < N; i++)
  {
    if (d2[i] < d1[i])
      continue;
    if (d2[i] == d1[i])
    {
      same = min(d2[i], same);
    }
    else
    {
      ans = max(ans, d2[i] - 1);
    }
  }
  if (ans == 0 && same != (1 << 30))
  {
    cout << same << endl;
  }
  else
  {
    cout << ans << endl;
  }
}


Measured memory_bytes: 13216
from bisect import bisect_left as bl
while 1:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    s=[int(input())for i in range(n)]
    a=set()
    a.add(0)
    for i in range(n):
        a.add(s[i])
        for j in range(i,n):
            a.add(s[i]+s[j])
    a=sorted(list(a))
    s=0
    for i in a:
        if i<m:
            s=max(s,i+a[bl(a,m-i)-1])
    print(s)


Measured memory_bytes: 52776
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

s = input()
N = len(s)
ans = INF
for i in range(ord('a'),ord('z')+1):
    c = chr(i)
    k = 0
    tmp = 0
    for j in range(N):
        if s[N-1-j]==c:
            tmp = max(k,tmp)
            k = 0
        else:
            k += 1
    tmp = max(k,tmp)
    ans = min(ans,tmp)
print(ans)

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


int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    int ans = 0;
    bool flag = true;
    while(flag){

        
        for(int i = 0;i < n;i++){
            
            if(a[i] % 2 != 0){
                cout << ans << endl;
                return 0;
            }

            a[i] /=2;
            /*if(a[i] % 2 != 0){
                flag = false;
                break;
            }*/
        }
        ans++;
    }

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

Measured memory_bytes: 256
s = input().strip()
s = s[::-1]
r = 0
b = 0
N = len(s)
dp1 = [0] * (N+1)
dp2 = [0] * (N+1)
dp1[1] = int(s[0])
dp2[1] = 11 - int(s[0])
for i, c in enumerate(s[1:]):
    i += 1
    c = int(c)
    dp1[i+1] = min(dp1[i] + c, dp2[i] + c)
    dp2[i+1] = min(dp1[i] + 11 - c, dp2[i] + 9 - c)
#print(dp1)
#print(dp2)

print(min(dp1[-1], dp2[-1]))


Measured memory_bytes: 78204
# include <stdio.h>

int main(){
  int n, k;
  int ans = 1;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++){
    ans += (ans < k)*ans + (ans >= k)*k;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
def solve():
    # 解説放送を実装
    N = int(input())
    flowers = [0]*N
    h = [int(x) for x in input().split(" ")]
    ans = h[0]
    stack = h[0]

    for i in range(1, N):
        if h[i] <= stack:
            stack = h[i]
        else:
            ans += (h[i] - stack)
            stack = h[i]
    
    print(ans)


if __name__ == "__main__":
    solve()

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

int main(){
    int M, D;
    cin >> M >> D;
    int ans = 0;
    for(int m = 1;m<=M;m++){
        for(int d=1;d<=D;d++){
            if(d % 10 >= 2 && d/10 >= 2 && (d%10)*(d/10) == m){
                ans += 1;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for i in range(N)])
P = np.array([list(map(int, input().split())) for i in range(N)])
ans = -10**18
for i in range(2**10):
    box = []
    for k in range(10):
        if ((i>>k)&1):
            box = [1]+ box
        else:
            box = [0]+ box
    if all(i == 0 for i in box):
        continue
    # box は開業する0~9の候補リスト
    # G は F(0か1の各店開業状況)
    G = np.sum(F*box, axis=1)
    a = 0
    for x,y in zip(G,P):
        a += y[x]
    ans = max(ans, a)
    
print(ans)

Measured memory_bytes: 27116
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma region header
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
#pragma endregion
#pragma endregion


int main(void) {
	cout << 100 << ' ' << 100 << endl;
	int a, b; cin >> a >> b;
	vector<vector<char>> d(100, vector<char>(100));
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (i < 50) d[i][j] = '#';
			else d[i][j] = '.';
		}
	}
	a--; b--;
	for (int i = 0; i < 49; i += 2) {
		for (int j = 0; j < 100; j += 2) {
			if (a) d[i][j] = '.';
			else goto Cyan;
			a--;
		}
	}
Cyan:;
	for (int i = 51; i < 100; i += 2) {
		for (int j = 0; j < 100; j += 2) {
			if (b) d[i][j] = '#';
			else goto mond;
			b--;
		}
	}
mond:;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (j != 99) cout << d[i][j];
			else cout << d[i][j] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

template<class T>
bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>
bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}



int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n), dp(n, 2*INF);
    REP(i, n) cin >> h[i];
    dp[0] = 0; dp[1] = abs(h[0]-h[1]);
    FOR(i, 1, n){
        for(int j = 1; j <= k; ++j){
            if(i-j < 0) break;
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << "\n";
    return 0;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli a,b;

int main(){
  cin >> a >> b;
  lli n = b-a;
  n = n*(n+1)/2;
  cout << n-b << endl;

}


Measured memory_bytes: 256
n,m=list(map(int,input().split(' ')))
am=[[0 for j in range(m)] for i in range(n)]
bm=[0 for l in range(m)]
cm=[0 for i in range(n)]
for i in range(n):
    am[i]=list(map(int,input().split(' ')))
for j in range(m):
    bm[j]=int(input())
for i in range(n):
    for j in range(m):
        cm[i]=cm[i]+am[i][j]*bm[j]
for i in range(n):
    print(cm[i])


Measured memory_bytes: 5964
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define mod 1000000007
#define MOD 998244353
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define INF 100000000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int a[N];
int mat[15][15];
int cost[15];
signed main()
{
    
    speed
    int n,m,x;cin>>n>>m>>x;
    rep(i,0,n-1){
        cin>>cost[i];
        rep(j,0,m-1){
            cin>>mat[i][j];
        }
    }
    int ans=INF;
    for(int i=0;i<(1<<n);i++){
        int amt=0;
        vector <int> lol(m,0);
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                for(int k=0;k<m;k++){
                    lol[k]+=mat[j][k];
                }
            }
        }
        int flag=0;
        for(int j=0;j<m;j++){
            if(lol[j]<x)
                {
                    flag=1;
                    break;
                }
        }
        if(flag==0){
            for(int j=0;j<n;j++){
                if(i&(1<<j)){
                    amt+=cost[j];
                }
            }
            ans=min(ans,amt);
        }

    }
    if(ans==INF){
        cout<<-1<<endl;
    }
    else{
        cout<<ans<<endl;
    }





    return 0;
}

Measured memory_bytes: 3672
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define MAXN 100005
# define eps 1e-5
# define MAXM 500001
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
typedef long long LL;
typedef unsigned long long ULL;
int _MAX(int a, int b){return a>b?a:b;}
int _MIN(int a, int b){return a>b?b:a;}

LL a[100005];

int main ()
{
    int n, x;
    LL ans=0;
    scanf("%d%d",&n,&x);
    FOR(i,1,n) scanf("%lld",a+i);
    if (a[1]>x) ans+=a[1]-x, a[1]=x;
    FOR(i,2,n) {
        if (a[i]+a[i-1]>x) ans+=a[i]+a[i-1]-x, a[i]-=(a[i]+a[i-1]-x);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	string S;
	scan(N>>S>>K);
	rep(i,N){
		if(S[i]!=S[K-1]) S[i]='*';
	}
	prin(S);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,a,b;//a 蓝 b红  先蓝 求蓝 
	cin>>n>>a>>b;
	ll l;
	l=n%(a+b);
	if(l>a) l=a;
	cout<<n/(a+b)*(a)+l;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>){
    val(n, q) = readLine()!!.split(" ").map(String::toInt)
    val s = readLine()!!
    val cumSum = mutableListOf(0)
    for(i in 1..(n - 1)) {
        cumSum.add(
            when (s.substring(i - 1, i + 1)) {
                "AC" -> cumSum[i - 1] + 1
                else -> cumSum[i - 1]
            }
        )
    }
    for(i in 1..q){
        val(l, r) = readLine()!!.split(" ").map(String::toInt)
        println(cumSum[r - 1] - cumSum[l - 1])
    }
}

Measured memory_bytes: 73704
#include<bits/stdc++.h>
#define maxn 205050

using namespace std;
typedef long long ll;
ll dp[maxn],n,W,k,w[maxn],v[maxn],E;
int main(){
    cin >> n >> W; E=100000;
    for (int i=1;i<=n;i++) cin >> w[i] >> v[i];
    for (int i=1;i<=E;i++) dp[i]=W+1;
    for (int i=1;i<=n;i++)
        for (int j=E;j>=v[i];j--)
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
    for (int i=1;i<=E;i++) if (dp[i]<=W) k=i;
    cout << k << endl;
}


Measured memory_bytes: 2304
/*
    Flowers, wake up like the sea!
*/
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x7fffffff
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
typedef vector<int> VI;
typedef map<int,int> MII;
const int N = 1e5 + 10, MOD = 7+1e9;
int main()
{
#ifdef YUUKILP
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for(int x, i = 0;i < n;i ++) cin >> x;
    k --, n --;
    cout << (n % k == 0 ? n / k : (n / k + 1));
    return 0;
}

Measured memory_bytes: 256
P,Q,R = list(map(int,input().split()))
if P+Q <= Q+R and P+Q <= P+R :
    print(P+Q)
elif P+R <= P+Q and P+R <= Q+R :
    print(P+R)
elif Q+R <= P+Q and Q+R <= P+Q :
    print(Q+R) 


Measured memory_bytes: 2940
import math
import collections
import copy
import sys

n = int(input())

a = list(map(int,input().split()))

limit = 10 ** 6

sCheck = math.gcd(a[0],a[1])
if n == 2:
    if sCheck == 1:
        print("pairwise coprime")
    else:
        print("not coprime")
    sys.exit()
else:
    for i in range(2,n):
        sCheck = math.gcd(sCheck,a[i])


beforeQ = collections.deque([int(i) for i in range(3,(limit + 1))])
D = dict()
p = 2
D[2] = 2
D[1] = 1

while p < math.sqrt(limit):
    afterQ = collections.deque()
    while len(beforeQ) > 0:        
        k = beforeQ.popleft()
        if k % p != 0:
            afterQ.append(k)
        else:
            D[k] = p
    beforeQ = copy.copy(afterQ)
    p = beforeQ.popleft()
    D[p] = p
while len(beforeQ) > 0:
    k = beforeQ.popleft()
    D[k] = k
    
ansSet = set()
count = 0

for i in a:
    k = i
    kSet = set()
    while k != 1:
        if D[k] in ansSet:
            if not(D[k] in kSet):
                count = 1
                break
        else:
            ansSet.add(D[k])
            kSet.add(D[k])
        k = int(k // D[k])
    if count == 1:
        break

if count == 0:
    print("pairwise coprime")
elif sCheck == 1:
    print("setwise coprime")
else:
    print("not coprime")

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

int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	char x[110];
	for(int i = 0; i < w + 2; i++)
		printf("#");
	printf("\n");
	for(int i = 0; i < h; i++) {
		scanf("%s", x);
		printf("#%s#\n", x);
	}
	for(int i = 0; i < w + 2; i++)
		printf("#");
	printf("\n");
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int X = s.nextInt();
    for (int i = -K+1; i<K;i++){
      System.out.print(X+i + " ");
    }
  }
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int X, Y, Z;
    int K;
    cin >> X >> Y >> Z;
    cin >> K;
    vector<ll> A(X), B(Y), C(Z);

    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];
    
    vector<ll> AB;
    for (int i = 0; i < X; i++) {
        for ( int j = 0; j < Y; j++) {
            AB.push_back(A[i] + B[j]);
        }
    }
    sort(AB.begin(), AB.end());
    reverse(AB.begin(), AB.end());

    vector<ll> ABC;
    for (int i = 0; i < min(K, (int)AB.size()); i++) {
        for ( int j = 0; j < Z; j++) {
            ABC.push_back(AB[i] + C[j]);
        }
    }
    sort(ABC.begin(), ABC.end());
    reverse(ABC.begin(), ABC.end());

    for (int i = 0; i < K; i++) {
        cout << ABC[i] << '\n';
    }
}


Measured memory_bytes: 43240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    int[] parent;
    int[] size;

    private int getRoot(int node) {
        while (parent[node] != node) {
            parent[node] = parent[parent[node]];
            node = parent[node];
        }

        return node;
    }

    private void merge(int i, int j) {
        int rootI = getRoot(i);
        int rootJ = getRoot(j);
        if (rootI == rootJ) return;

        if (size[rootI] > size[rootJ]) {
            parent[rootJ] = rootI;
            size[rootI] += size[rootJ];
        } else {
            parent[rootI] = rootJ;
            size[rootJ] += size[rootI];
        }
    }



    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(f.readLine());
        int[][] coords = new int[n][3];
        for (int i = 0; i < n; i++) {
            StringTokenizer tokenizer = new StringTokenizer(f.readLine());
            coords[i][0] = Integer.parseInt(tokenizer.nextToken()) - 1;
            coords[i][1] = Integer.parseInt(tokenizer.nextToken()) - 1;
            coords[i][2] = i;
        }

        Arrays.sort(coords, new ArrayComparator());

        TreeSet<int[]> components = new TreeSet<int[]>(new ArrayComparator());

        parent = new int[n];
        size = new int[n];
        Arrays.fill(size, 1);
        for (int i = 0; i < n; i++) parent[i] = i;

        for (int i = 0; i < n; i++) {
            int[] resultingComponent = {coords[i][1], i};
            while (!components.isEmpty() && components.first()[0] <= coords[i][1]) {
                int[] ar = components.pollFirst();
                merge(i, ar[1]);
                resultingComponent[0] = Math.min(ar[0], resultingComponent[0]);
            }
            components.add(resultingComponent);
        }

        int[] res = new int[n];
        for (int i  = 0; i < n; i++) {
            res[coords[i][2]] = size[getRoot(i)];
        }
        for (int i = 0; i < n; i++) out.println(res[i]);
        out.close();
    }



    private static class ArrayComparator implements Comparator<int[]> {

        @Override
        public int compare(int[] o1, int[] o2) {
            return Integer.compare(o1[0], o2[0]);
        }
    }
}

Measured memory_bytes: 67008
from collections import defaultdict

N = int(raw_input())
A = map(int, raw_input().split())

lookup = defaultdict(int)
for a in A:
  lookup[a] += 1
  
cur_sum = 0
for k in lookup:
  cur_sum += k*lookup[k]
  
Q = int(raw_input())
for q in xrange(Q):
  b, c = map(int, raw_input().split())
  cur_sum -= b*lookup[b]
  cur_sum += c*lookup[b]
  
  lookup[c] += lookup[b]
  lookup[b] = 0
  
  print cur_sum

Measured memory_bytes: 97080
s = gets.chomp.chars
# 文字列のままやるとTLE

# headが1のときは順方向とする
head = 1

Q = gets.chomp.to_i

Q.times do |i|
  query = gets.chomp.split

  # 1なら反転
  if query[0] == '1'
    head = head == 0 ? 1 : 0
    next
  end

  if query[1] == '1'
    # 表かつ前ならそのまま足す
    if head == 1
      s.unshift(query[2])
    else
      s.push(query[2])
    end
  else
    if head == 1
      s.push(query[2])
    else
      s.unshift(query[2])
    end
  end
end


if head == 1
  puts s.join
else
  puts s.reverse.join
end


Measured memory_bytes: 30204
k = int(input())
ans = 0
import math
for i in range(1, k + 1):
    for j in range(i + 1, k + 1):
        for g in range(j + 1, k + 1):
            u = math.gcd(i, j)
            w = math.gcd(u, g)
            ans += w * 6
            
for i in range(1, k + 1):
    for j in range(i + 1, k + 1):
        u = math.gcd(i, j)
        ans += u * 6
        
for i in range(1, k + 1):
    ans += i
print(ans)

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

int main() {
  
  int N, M; cin >> N >> M;
  
  vector<int> vecWA(N, 0); vector<int> vecAC(N, 0);
  
  for (int i = 0; i < M; i++) {
    int p; string s; cin >> p >> s;
    if (s == "WA" && vecAC.at(p - 1) == 0) {
      vecWA.at(p - 1)++;
    }
    if (s == "AC" && vecAC.at(p - 1) == 0) {
      vecAC.at(p - 1)++;
    }
  }
  
  int sumWA = 0; int sumAC = 0;
  
  for (int i = 0; i < N; i++) {
    // sumWA += vecWA.at(i);
    sumAC += vecAC.at(i);
    if (vecAC.at(i) == 1) {
      sumWA += vecWA.at(i);
    }
  }
  
  cout << sumAC << " " << sumWA << endl;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    std::string s, res="";
    std::cin >> s;

    int len = s.length();

    floop(len)
    {
        if(s[i] == 'B')
        {
            if(res != "")
                res.pop_back();
        }

        else
            res += s[i];
    }

    print(res);
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(){
  double i,j,x,r=1;
  scanf("%lf",&x);
  for(i=2;i<=x;i++)for(j=2;pow(i,j)<=x;j++)if(pow(i,j)>r)r=pow(i,j);
  printf("%d",(int)r);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll dp[201][100001];
void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n,greater<ll>());
  dp[0][m]=1;
  rep(i,n) {
    rep(j,m+1) {
      dp[i+1][j%a[i]]+=dp[i][j];
      dp[i+1][j%a[i]]%=MAX;
      dp[i+1][j]+=dp[i][j]*(n-i-1)%MAX;
      dp[i+1][j]%=MAX;
    }
  }
  ll ans=0;
  rep(i,m+1) {
    ans+=dp[n][i]*i%MAX;
    ans%=MAX;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 156544
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
void solve(){
    string s;
    cin >> s;
    int sum = 0;
    for(int i = 0 ; i < s.size() ; i++){
        sum += (s[i] - '0');
        if( sum > 9){
            sum -= 9;
        }
    }
    if( sum % 9){
        cout << "No\n";
    }else{
        cout << "Yes\n";
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}


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

int main(){
  int map[21][21];
  int dx,dy;
  int get;
  int n,m;
  int x,y;
  int len;
  int i,j;

  string A;

  while(1){
    get = 0;
    dx = 10;
    dy = 10;
    for(i = 0 ; i < 21 ; i++){
      for(j = 0 ; j < 21 ; j++){
	map[i][j]=0;
      }
    }
    cin >> n;
    if(n==0) break;
    for(i = 0 ; i < n ; i++){
      cin >> x >> y;
      map[x][y]=1;
    }
 
    cin >> m;
    for(i = 0 ; i < m ; i++){
      cin >> A >> len;
      if(A == "N"){
	for(j = 0 ; j < len ; j++){
	  dy++;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }

      if(A == "E"){
	for(j = 0 ; j < len ; j++){
	  dx++;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }
      if(A == "S"){
	for(j = 0 ; j < len ; j++){
	  dy--;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }

      if(A == "W"){
	for(j = 0 ; j < len ; j++){
	  dx--;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }

    }

    if(get == n){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return;
  }
  ll ans = 0;
  ll current = n;
  for (ll i = 2; i * i <= n; i++) {
    if (current % i != 0) continue;

    ll count = 0;
    ll next = 1;
    while (current % i == 0) {
      current /= i;
      count++;
      if (count == next) {
        ans++;
        next++;
        count = 0;
      }
    }
  }
  if (current == n) cout << 1 << endl;
  else {
    if (current > sqrt(n)) ans++;
    cout << ans << endl;
  }
}

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

Measured memory_bytes: 3632
def resolve():
    N=int(input())
    B=list(map(int,input().split()))
    ans=B[0]
    for i in range(1,N-1):
        #print(min(B[i-1],B[i]),B[i-1],B[i])
        ans+=min(B[i-1],B[i])
    print(ans+B[-1])
resolve()

Measured memory_bytes: 3060
def main():
    N = input()
    x =  int(N[-1])
    if x in [2,4,5,7,9]:
        print('hon')
    elif x in [0, 1, 6, 8]:
        print('pon')
    else:
        print('bon')
main()
#if main():
#    print('Yes')
#else:
#    print('No')


Measured memory_bytes: 9160
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const int MAX = 200002;

int N;

ll a[200][20],b[200][20];

int main()
{
    scanf("%d",&N);
    for(int i = 1;i<=N;i++)
    for(int j = 1;j<=10;j++)
        scanf("%lld",&a[i][j]);
    for(int i = 1;i<=N;i++)
    for(int j = 0;j<=10;j++)
        scanf("%lld",&b[i][j]);

    ll max1 = -INF;
    for(int i = 0;i<1024;i++)
    {
        ll max2 = 0;
        int ii = i,flag = 0;
        for(int k = 1;k<=10;k++){
             if(ii&1==1){flag = 1;break;}
             ii = ii>>1;
        }
        if(flag==0)continue;

        for(int j = 1;j<=N;j++)
        {
            int ti = i,num = 0;
            for(int k = 10;k>=1;k--)
            {
                if(a[j][k]==1&&(ti&1==1))
                    num++;
                ti = ti>>1;
            }
            max2 += b[j][num];
        }
        max1 = max(max1,max2);
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
constexpr int N = 100'000, M = 200'000, INF = 1'000'000'000;
int n, m;
int d[N], color[N], w[M], perm[N];
std::vector<std::pair<int, int>> e[N];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> m;
    for (int i = 0; i < n; ++i)
        std::cin >> d[i];
    std::fill(color, color + n, -1);
    std::fill(w, w + m, INF);
    for (int i = 0; i < m; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u;
        --v;
        if (color[u] == -1 && color[v] == -1 && d[u] == d[v]) {
            color[u] = 0;
            color[v] = 1;
            w[i] = d[u];
        }
        e[u].emplace_back(v, i);
        e[v].emplace_back(u, i);
    }
    std::queue<int> que;
    for (int i = 0; i < n; ++i)
        if (color[i] != -1)
            que.push(i);
    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (auto edge : e[u]) {
            int v, i;
            std::tie(v, i) = edge;
            if (color[v] == -1 && d[v] >= d[u]) {
                color[v] = color[u] ^ 1;
                w[i] = d[v];
                que.push(v);
            }
        }
    }
    std::string s;
    for (int i = 0; i < n; ++i) {
        if (color[i] == -1) {
            std::cout << -1 << "\n";
            return 0;
        }
        if (color[i] == 0) {
            s += 'W';
        } else {
            s += 'B';
        }
    }
    std::cout << s << "\n";
    for (int i = 0; i < m; ++i)
        std::cout << w[i] << "\n";
    return 0;
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k, ans;
string s;


int main(){
  int n; cin >> n;
  cin >> s;
  int ans = 0;
  rep(i,10) rep(j,10) rep(k,10){
    int ite = 0;
    while(ite < n && s[ite]-'0' != i) ite++;
    ite++;
    while(ite < n && s[ite]-'0' != j ) ite++;
    ite++;
    while(ite < n && s[ite]-'0' != k) ite++;
    if(ite < n) ans++;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

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

vector<int> scc(const vector<vector<int>>& adj) {
    const int n = adj.size();
    vector<int> num(n, 0), low(n, 0), color(n, 0);
    vector<int> sta;
    deque<bool> inS(n, 0);
    int t = 0, colnum = 0;
    function<void(int)> visit = [&](int cur) {
        low[cur] = num[cur] = ++t;
        sta.emplace_back(cur); inS[cur] = 1;
        for(int nxt : adj[cur]) {
            if(num[nxt] == 0) {
                visit(nxt);
                low[cur] = min(low[cur], low[nxt]);
            } else if(inS[nxt])
              low[cur] = min(low[cur], num[nxt]);
        }
        if(low[cur] == num[cur]) {
            while(true) {
                int nxt = sta.back(); sta.pop_back(); inS[nxt] = false;
                color[nxt] = colnum;
                if(cur == nxt) break;
            }
            ++colnum;
        }
    };
    for(int v : in(n))
      if(num[v] == 0)
        visit(v);
    return color;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n);
    for(int _ : in(m)) {
        int u, v;
        cin >> u >> v;
        adj[u].emplace_back(v);
    }
    auto color = scc(adj);
    int q;
    cin >> q;
    for(int _ : in(q)) {
        int u, v;
        cin >> u >> v;
        if(color[u] == color[v])
          cout << 1 << '\n';
        else
          cout << 0 << '\n';
    }
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;


int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	VI a(n), b(n+4);
	rep(i,n) cin >>a[i];
	ll ans =1LL;
	rep(i,n) b[a[i]]++;
	//for(auto x :b) printf("%d, ",x); puts("");
	bool ng=0;
	rep(i,n){
		if(n%2){
			if(i%2 && b[i] !=0) ng=1;
			if(i && i%2==0 && b[i] !=2) ng=1;
		}else{
			if(i%2 && b[i] !=2) ng=1;
			if(i%2==0 && b[i] !=0) ng=1;
		}
	}
		
	if(ng) {puts("0"); return 0;}
	rep(i,n){
		if(b[i]>0) (ans *= b[i]) %=mod;
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 1024
<?php
  
$ab = explode(' ',trim(fgets(STDIN)));
$a = $ab[0];
$b = $ab[1];

$c = 0;
for($i=$a; $i<=$b; $i++){
  
  $n = $i;
  $n = strval($n);
  
  $nr = [];  
  for($j=0; $j<strlen($n); $j++){
    $nr[$j]=$n[$j]; 
  }
  $nr = array_reverse($nr);
  $nr = implode('',$nr);
  
  if ($n == $nr) $c++;
}

echo $c;

?>

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

int main(){
  int i;
  char string[1200];
  fgets(string, 1200, stdin);
  for(i=0;i<=(int)strlen(string);i++){
    if( 65 <= string[i] && string[i] <= 90 ){
      string[i] += 32;
    }else if(97 <= string[i] && string[i] <= 122 ){
      string[i] -= 32; 
    }
    //printf("%c", string[i]);
  }
  printf("%s", string);
  return 0;
}



Measured memory_bytes: 2604
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    ll x;
    cin>>x;
    ll a,b;
    for(ll i=-200;i<200;i++){
        for(ll j=-200;j<200;j++){
            if(x==i*i*i*i*i-j*j*j*j*j){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3636