akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

int main(){
  string s;
  bool op[3];
  int tmp;
  cin >> s;
  int p[4];
  rep(i, 4){
    p[i] = s[i] - 0x30;
  }
  for(int bit = 0; bit < (1 << 3); bit++){
    tmp = p[0];
    for(int i = 0; i < 3; i++){
      if(bit & (1 << i)){
        tmp += p[i+1];
        op[i] = true;
      }else{
        tmp -= p[i+1];
        op[i] = false;
      }
    }
    if(tmp == 7){
      cout << p[0];
      rep(i, 3){
        if(op[i]){
          cout << "+";
        }else{
          cout << "-";
        }
        cout << p[i+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll long long

int main(){
    ll N,a[5],ans;
    ll minn = 0x7fffffffffffffff;
    scanf("%lld",&N);
    for(int i = 0;i < 5;i++){
        scanf("%lld",a+i);
        if(minn > a[i])minn = a[i];
    }
    //printf("this\n");
    //printf("minn = %I64d\n",minn);
    if(N <= minn){
        printf("5\n");
    }
    else{
        ans = 4 + N/minn;
        if(N % minn)ans++;
        printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;

string s , t;
int main(){
	cin >> s >> t ;
	int S =s.size();
	int T =t.size();
	vector<char> A(S);
	vector<char> B(T);
		rep(i,S){
			A[i]=s[i];
		}
		SORT(A);
	rep(j,T){
		B[j] = t[j];
	}
	SORT(B);
	REV(B);
	string x;
	rep(i,S){
		x+=A[i];
	}
	string y; 
	rep(i,T){
		y+=B[i];
	}
	if(x<y){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// https://chakku.hatenablog.com/entry/2017/06/13/021049
// dp[i]][j]
// i個使用して重さの総和がj + w_0 iとなる時の最大値
ll dp[128][512];
int main() {
    int N;
    ll W;
    cin >> N >> W;
    vector<ll> weight(N);
    vector<ll> value(N);
    REP(i, N) { cin >> weight[i] >> value[i]; }
    // weight value
    ll sum = 0;
    REP(i, N) {
        ll ww = weight[i] - weight[0];
        //荷物iを複数回使わないように逆に回す
        for(int j = i; j >= 0; j--) {
            for(int k = sum; k >= 0; k--) {
                //荷物iを含まないでj個
                //荷物iを含まない重さがk
                dp[j + 1][k + ww] = max(dp[j + 1][k + ww], dp[j][k] + value[i]);
            }
        }
        sum += ww;
    }
    ll ans = 0;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= sum; j++) {
            if(weight[0] * i + j > W) {
                continue;
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);//高速化、endlは使わない

  int N, p[10], sum=0, max, max_index;

  cin >> N;

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

  max = 0;

  for(int i = 0; i < N; ++i){
    sum += p[i];
    if(max < p[i]){
      max = p[i];
      max_index = i;
    }
  }

  cout << (sum - p[max_index]/2) << endl;
}


Measured memory_bytes: 256
<?php
    fscanf(STDIN, "%d %d", $a, $b);
    if($a < $b){
        echo "a < b" . "\n";
    }else if($a > $b){
        echo "a > b" . "\n";
    }else if($a == $b){
        echo "a == b" . "\n";
    }
?>


Measured memory_bytes: 9172
import sys
import math

n, x = map(int, sys.stdin.readline().split())
s = map(int, sys.stdin.readline().split())
su = [0  for i in range(n+1)]
su[0] = s[0]
su[n] = s[n-1]
for i in range(1,n):
    su[i] = s[i-1]+s[i]

ans = 0
for i in range(n+1):
    if su[i]>x :
        t = su[i]-x
        ans += t
        su[i+1] -= t

print ans


Measured memory_bytes: 12364
package main

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

func bubbleSort(n int, as []string) {
	for i := range as {
		for j := n - 1; j > i; j-- {
			if as[j][1:] < as[j-1][1:] {
				a := as[j]
				as[j] = as[j-1]
				as[j-1] = a
			}
		}
	}
	printArray(as)
}

func selectionSort(n int, as []string) {
	for i := range as {
		min := as[i]
		min_index := i
		for j := i + 1; j < n; j++ {
			if min[1:] > as[j][1:] {
				min = as[j]
				min_index = j
			}
		}
		if min_index > i {
			a := as[min_index]
			as[min_index] = as[i]
			as[i] = a
		}
	}
	printArray(as)
}

func stableSort(n int, as []string) {
	bs := make([]string, n)
	copy(bs, as)
	bubbleSort(n, bs)
	fmt.Println("Stable")
	selectionSort(n, as)
	if isStable(as, bs) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}

func isStable(as []string, bs []string) bool {
	for i, a := range as {
		if a != bs[i] {
			return false
		}
	}
	return true
}

func printArray(as []string) {
	fmt.Println(strings.Trim(fmt.Sprint(as), "[]"))
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	var as []string
	for i := 0; i < n; i++ {
		a := nextStr(sc)
		as = append(as, a)
	}
	stableSort(n, as)
}



Measured memory_bytes: 1172
from math import sqrt

eps = 1e-8

def eq(a, b):
    return a + eps > b and a - eps < b

a, b, c = list(map(int, input().split()))
if a + b >= c:
    print("No")
elif 4 * a * b < (c - a - b) * (c - a - b):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
int gcd(int a,int b){
    if(a<b){
        int tmp=b;
        b=a;
        a=tmp;
    }
    int r=a%b;
    if(r==0)return b;
    while(r>0){
        a=b;
        b=r;
        r=a%b;
    }
    return b; 
}
int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int ans=abs(a[0]-x);
    for(int i=0;i<n;i++){
        ans=gcd(ans,abs(x-a[i]));
    }
    
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 512
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] str = br.readLine().split("\\s+");
		
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		
		int d = a / b;
		int r = a % b;
		double f = (double) a / b;
		
		System.out.printf("%d %d %.6f", d, r, f);
	}
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		string s;
		cin >> s;
		int n = s.length();
		for(int i=0; i < n; i++){
			if(i%2 == 0 && s[i] == 'L'){
				cout << "No" << endl;
				return;
			}
			if(i%2 == 1 && s[i] == 'R'){
				cout << "No" << endl;
				return;
			}
		}
		cout << "Yes" << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int num,num1,num2,num3;
    scanf("%d",&num);
    num3=num%10;
    num=num/10;
    num2=num%10;
    num1=num/10;
    if(num1==num3)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
    int N;
    cin >> N;
    if(N % 2 == 0) {
        cout << "0.5" << endl;
    }
    else {
        cout << (N / 2 + 1) / (N * 1.0) << endl;
    }
}

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

int main() {
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0){
    cout<<1<<endl;
  }
  if(b==0){
    cout<<2<<endl;
  }
  if(c==0){
    cout<<3<<endl;
  }
  if(d==0){
    cout<<4<<endl;
  }
  if(e==0){
    cout<<5<<endl;
  }
  
}


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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

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

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

const int mod = 1e9+7;
const ll N = 1e18;

void solve()
{
	int n;
	cin >> n;
	ll ans = 1;
	ll a[n];
	bool z = 0;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		z |= (a[i] == 0LL);
	}
	if(z)
	{
		cout << 0;
	}
	else
	{
		sort(a,a+n);
		for(int i=n-1;i>=0;i--)
		{
			if(a[i] > N/ans)
			{
				cout << -1;
				return;
			}
			ans*=a[i];
		}
		if(ans > N)
		{
			cout << -1;
		}
		else
		{
			cout << ans;
		}
	}
}

signed main()
{
  	IOS;
  	//freopen("input.txt", "rt", stdin);
  	//freopen("output.txt", "wt", stdout);
  	int t=1;
  	//cin >> t;
  	while(t--)
  	{
   	solve();
  	}
  	return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
int N;
int a[MAX_N];

void solve()
{
	sort(a,a+N);
	const int idx = N/2;
	const int lb = a[idx-1], ub = a[idx];
	if(lb == ub) cout << 0 << endl;
	else cout << ub-lb << endl;
}

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

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final String N_str = sc.next();
			
			long sum = 0;
			for(final char ch : N_str.toCharArray()){
				sum += Character.getNumericValue(ch);
			}
			
			final long N = Long.parseLong(N_str);
			
			
			System.out.println((N % sum) == 0 ? "Yes" : "No");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];
    ll ans = INF;
    rep2(i, 1, 101) {
        ll x = i;
        ll tmp = 0;
        rep(j, N) {
            tmp += abs(X[j] - x) * abs(X[j] - x);
        }
        ans = min(ans, tmp);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

const int MAX_N = 100000;

int n, l, a[MAX_N + 1];

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

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

    int lastKnot = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] + a[i + 1] >= l) {
            lastKnot = i;
        }
    }

    if (lastKnot > 0) {
        printf("Possible\n");

        for (int i = 1; i < lastKnot; i++) {
            printf("%d\n", i);
        }

        for (int i = n - 1; i > lastKnot; i--) {
            printf("%d\n", i);
        }

        printf("%d\n", lastKnot);
    }

    if (lastKnot == 0) {
        printf("Impossible");
    }

    return 0;
}


Measured memory_bytes: 1152
from collections import defaultdict as dd
A,B = map(int,input().split())

def get_p(n):
    th = round(n**0.5)
    ans = (n,1)
    for i in range(2,th+1):
        if n % i ==  0:
            ans = (i,n//i)
            break
    return(ans)
            
def get_yakusu(n):
    flag = 1
    pn_dic = dd(lambda: 0)
    while flag:
        yaku,red = get_p(n)
        if yaku == n:
            pn_dic[str(yaku)] += 1
            flag = 0
        else:
            pn_dic[str(yaku)] += 1
            n = red
    return(pn_dic)

apn_dic = get_yakusu(A)
apn_dic["1"] += 1
bpn_dic = get_yakusu(B)
bpn_dic["1"] += 1

# print("Adic:",apn_dic)
# print("Bdic:",bpn_dic)


kouyaku_dic = dd(lambda:0)

wa_key = list(set(apn_dic.keys()) & set(bpn_dic.keys()))

for key in wa_key:
    kouyaku_dic[key] = min(apn_dic[key],bpn_dic[key])

# print("kouyaku:",kouyaku_dic)    
    
m = len(wa_key)
        
print(m)



Measured memory_bytes: 3436
s=input()
flag1 = False
flag2 = False
flag3 = False

if s[0] == "A":
    flag1 = True
    
cnt = 0
idx = -1
for i in range(2, len(s)-1):
    if s[i]=="C":
        cnt += 1
        idx = i
if cnt == 1:
    flag2 = True
    
if flag2:
    flag3 = True
    for i in range(len(s)):
        if i != 0 and i != idx and s[i].lower()!=s[i]:
            flag3 = False

if flag1 and flag2 and flag3:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 38384
from collections import defaultdict


def main():
    W, H, N = map(int, input().split())
    field = [[1] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        y_s, y_e = 0, H
        x_s, x_e = 0, W
        if a == 1:
            x_s, x_e = 0, x
        elif a == 2:
            x_s, x_e = x, W
        elif a == 3:
            y_s, y_e = H - y, H
        elif a == 4:
            y_s, y_e = 0, H - y

        for y in range(y_s, y_e):
            for x in range(x_s, x_e):
                field[y][x] = 0

    print(sum([sum(line) for line in field]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME:
ll pmid(ll mid, ll tmp){
    // 標準だと-2/3 -> 0となってしまう
    if (mid<0 and mid%tmp!=0) return mid/tmp-1;
    return mid/tmp;
}

ll mmid(ll mid, ll tmp){
    if (mid<0 and mid%tmp!=0) return mid/tmp+1;
    return mid/tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll inf = ll(1e18)+1;
    ll left = -inf, right = inf;
    // mid以下の数を求める
    // left: ng, right: ok
    while(left+1 < right){
        ll mid = (left+right)/2;
        ll cnt = 0;
        rep(i, n){
            ll tmp = a[i];
            if (tmp>0){
                auto iter = upper_bound(a.begin(), a.end(), pmid(mid, tmp)); 
                cnt += iter - a.begin();
            }else if (tmp==0){
                if (mid>=0) cnt+=n;
            }else{
                auto iter = lower_bound(a.begin(), a.end(), mmid(mid, tmp));
                cnt += a.end() - iter;
            }
            if (tmp*tmp <= mid) cnt--;
        }
        cnt /= 2;
        if (cnt >= k){
            right = mid;
        }else{
            left = mid;
        }
    }

    cout << right << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD 1e9+7LL

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

ll binary_square(ll x, ll n);
void factorial(ll n);
void rfactorial(ll n);
vector<ll> fact(2e6), rfact(2e6);

int main() {
  ll x, y, ans=0LL;
  ll m = MOD;
  cin >> x >> y;
//   cout << "START" << endl;
  factorial(2e6);
//   cout << "OK" << endl;
  rfactorial(2e6);
  rep(two, x/2+1){
      ll one = x - 2LL * two;
      if(y==one*2LL + two){
            // cout << fact[one+two] << " : " << rfact[one] << endl;
            ll total = one + two;
            ans = (ans + (fact[total] * ((rfact[one] * rfact[two]) % m)) % m) % m;
      }
  }
  cout << ans << endl;
  return 0;
}

void factorial(ll n) {
    ll m = MOD;
    fact[0] = 1;
    rep2(i, 1, n+1){
        fact[i] = fact[i-1] * i % m;
    }
//   if (n == 0) {
//     return 1;
//   } else {
//     if (fact[n - 1] == -1) {
//       fact[n - 1] = factorial(n - 1);
//     }
//     fact[n] = n * fact[n - 1] % m;
//     return fact[n];
//   }
}

void rfactorial(ll n) {
  ll m = MOD;
  rfact[n] = binary_square(fact[n], m - 2LL);
  rep2(i, 1, n + 1) { rfact[n - i] = rfact[n - i + 1] * (n - i + 1) % m; }
}

ll binary_square(ll x, ll n) {
  ll m = MOD;
  ll ans = 1;
  while (n) {
    if (n & 1) {
      ans = ans * x % m;
    }
    x = x * x % m;
    n >>= 1;
  }
  return ans % m;
}

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

using namespace std;

int main() {
long long a,b;
cin>>a>>b;
if(a>b)
swap(a,b);
if(a==1)
{
    if(b==1)
    {
        cout<<1;
        return 0;
    }
    else 
    {
        cout<<b-2;
        return 0;
    }
}
else  {
    long long ans=(a-2)*(b-2)*1ll;
cout<<ans;
}
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

int main(){
    int n,k,ans=0;
    vector<int> l,r;
    char s[100010];
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    l.push_back(0);
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]){
            l.push_back(i);
            r.push_back(i-1);
        }
    }
    if(l.size()!=r.size()){
        r.push_back(n-1);
    }
    r.push_back(n-1);
    r.push_back(n-1);
    r.push_back(n-1);
    r.push_back(n-1);
    if((l.size()<=2*k)||(l.size()==2*k+1&&s[0]=='1')){
        printf("%d\n",n);
        return 0;
    }
    for(int i=0;i<l.size()-2*k+1;i++){
        if(s[l[i]]=='1'){
            ans=max(ans,r[i+2*k]-l[i]+1);
        }
        else{
            ans=max(ans,r[i+2*k-1]-l[i]+1);
        }
    }
    printf("%d\n",ans);
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e6+5;
string s;
vector<ll> v[N];
ll n,h,k,m,result;
ll a[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> h >> n;
  rep(i,n) {
    cin >> k;
    result += k;
  }
  if (h - result > 0) s = "No";
  else s = "Yes";
  cout << s << endl;
}


Measured memory_bytes: 25344
#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;

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

int c_count = 0;
int c_index;
int a_count = 0;
int a_index;

int upper_count = 0;
for(int i=0; i<s.length(); i++){
    if(s[i] == 'A'){
        a_index = i;
        a_count++;
    }
    if(s[i] == 'C'){
        c_index = i;
        c_count++;
    }
    if(isupper(s[i])){
        upper_count ++;
    }
}

if(c_count == 1 && c_index >=2 && c_index<s.length()-1 && a_count == 1 && a_index ==0 && upper_count == 2){
    cout<<"AC"<<endl;
}else{
    cout<<"WA"<<endl;
}

return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
ans = 0

def rest(a):
    if a == "R":
        return(["G", "B"])
    elif a == "G":
        return(["R", "B"])
    else:
        return (["R", "G"])

for i in range(n - 3):
    rest1 = rest(s[i])[0]
    rest2 = rest(s[i])[1]
    ans = ans + s[i + 1:].count(rest1) * s[i + 1:].count(rest2)

    j = i + 1
    k = 1
    while True:
        if (s[j] == rest1 and s[j + k] == rest2) or (s[j] == rest2 and s[j + k] == rest1):
            ans = ans - 1
        k = k + 1
        j = i + k
        if j + k > n - 1:
            break

print(ans)

Measured memory_bytes: 9284
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int k,x,l,r; cin >> k >> x;
	l = x - k + 1; r = x + k - 1;
	for (int i = l; i <= r; ++i) {
		if (i != l) cout << " " ;
		cout << i;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)
def lcm_all(A):
    return reduce(lcm, A, 1)

n, M = map(int, input().split())
A = tuple(map(lambda x: int(x)//2, input().split()))

scm_core = lcm_all(A)

canmake_scm = True
for a in A:
    if scm_core // a % 2 == 0:
        canmake_scm = False
        break

if canmake_scm:
    print(((M // scm_core)+1) // 2)
else:
    print(0)

Measured memory_bytes: 16416
#include<bits/stdc++.h>
using namespace std;
int n,f[100009][5], a[100009][5], kq = -1;
int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> a[i][1] >> a[i][2] >> a[i][3];
    }
    f[0][1] = 0;
    f[0][2] = 0;
    f[0][3] = 0;
    for(int i = 1; i <= n; ++ i)
    {
        f[i][1] = max(f[i - 1][2], f[i - 1][3]) + a[i][1];
        f[i][2] = max(f[i - 1][1], f[i - 1][3]) + a[i][2];
        f[i][3] = max(f[i - 1][2], f[i - 1][1]) + a[i][3];
    }
    kq = max(kq, f[n][1]);
    kq = max(kq, f[n][2]);
    kq = max(kq, f[n][3]);
    cout << kq;
    return 0;
}


Measured memory_bytes: 4096
import math
def func(a: int, b: int) -> int:
    return max(len(str(a)), len(str(b)))

n = int(input())

ans = 1E10
for a in range(1, math.ceil(math.sqrt(n))+1):
    if n%a != 0:
        continue
    ans = min(ans, func(a, n//a))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class T> pair<int, T> gauss_jordan(VV<T>& A) {
  int n = A.size(), m = A[0].size(), r = 0;
  T det = 1;
  for (int j = 0; j < m; ++j) {
    for (int i = r + 1; i < n; ++i) if (A[i][j]) {
      swap(A[r], A[i]);
      det = -det;
      break;
    }
    if (!A[r][j]) continue;
    det *= A[r][j];
    auto inv = (T) 1 / A[r][j];
    for (auto&& e : A[r]) e *= inv;
    for (int i = 0; i < n; ++i) if (i != r and A[i][j]) {
      auto c = A[i][j];
      for (int k = 0; k < m; ++k) {
        A[i][k] -= c * A[r][k];
      }
    }
    if (++r == n) break;
  }
  return {r, det * (r == n)};
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  using R = long double;
  constexpr R eps = 1e-3;
  auto chk = [&](const V< pair<int, R> >& a) -> bool {
    int d = a.size() - 2;
    VV<R> A(d + 1, V<R>(d + 2));
    for (int i = 0; i <= d; ++i) {
      for (int j = 0; j <= d; ++j) {
        A[i][j] = pow(a[i].first, j);
      }
      A[i][d + 1] = a[i].second;
    }
    int rank = gauss_jordan(A).first;
    assert(rank == d + 1);
    double x = 0;
    for (int i = 0; i <= d; ++i) {
      x += A[i].back() * pow(a.back().first, i);
    }
    auto err = abs(a.back().second - x);
    return err < eps;
  };
  while (true) {
    int d; cin >> d;
    if (!d) break;
    V<R> v(d + 3); for (auto&& e : v) cin >> e;
    for (int i = 0; i < d + 3; ++i) {
      V< pair<int, R> > a;
      for (int j = 0; j < d + 3; ++j) if (j != i) {
        a.emplace_back(j, v[j]);
      }
      if (chk(a)) {
        cout << i << '\n';
        break;
      }
    }
  }
}


Measured memory_bytes: 3204
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;

int main() {
    string S;
    cin >> S;
    string res = "Yes";
    rep(i, 0, S.size()) {
        if(i % 2 == 0) {
            if(S[i] == 'L') {
                res = "No";
                break;
            }
        } else {
            if(S[i] == 'R') {
                res = "No";
                break;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <string>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	ll min = A*X + B*Y;
	FOR(i, max(X + 1, Y + 1), 0)
	{
		ll m = max(X - i, (ll)0)*A + max(Y - i, (ll)0)*B + i * 2 * C;
		min = std::min(min, m);
	}
	cout << min << endl;
	return 0;
}

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

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

  vector<int> suuji;
  for(int i = 0; i < N.size(); i ++){
      suuji.push_back(N.at(i) - '0');
  }

  int ans = 0;
  for(int i : suuji){
      ans += i;
      //cout << i << endl;
  }
  if(ans % 9 == 0){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
}

Measured memory_bytes: 4484
N = gets.to_i
A = gets.split.map(&:to_i)

hash = Hash.new {0}
A.each do |a|
  hash[a] += 1
end

ans = 0
hash.each do |k, v|
  next if k == v
  if k < v
    ans += v - k
  elsif k > v
    ans += v
  end
end

puts ans


Measured memory_bytes: 14468
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) {
      if (s[i] == '0') a++;
      if (s[i] == '1') b++;
    } else {
      if (s[i] == '1') a++;
      if (s[i] == '0') b++;
    }
  }
  cout << min(a, b) << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			execute(scanner);
		}
	}

	private static void execute(Scanner scanner) {
		int r = scanner.nextInt();
		int g = scanner.nextInt();
		System.out.println(2 * g - r);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

void next(int &i, int &j, int W){
    if(i % 2 == 0){
        if(j == W - 1) i++;
        else j++;
    }else{
        if(j == 0) i++;
        else j--;
    }
}

signed main(){

    int H, W; cin >> H >> W;
    int N; cin >> N;
    vec a(N); readvec(a);

    mat ans(H, vec(W));
    int i = 0, j = 0;
    REP(k, N){
        REP(l, a[k]){
            ans[i][j] = k + 1;
            next(i, j, W);
        }
    }
    REP(i, H){
        REP(j, W){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    
    return 0;
}


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

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <cstdio>
//using namespace std;
 //Compiler version g++ 6.3.0

using namespace std;

 int main()
 {
 	double r;
 	cin >> r;
 	printf("%f %f",r*r*M_PI,r*2*M_PI);
 	return 0;
 }
    


Measured memory_bytes: 3172
N,K = map(int,input().split())
A = [int(a) for a in input().split()]
F = [int(f) for f in input().split()]

A.sort()
F.sort(reverse=True)

isOK = max([a*f for a,f in zip(A,F)])
isNG = -1

while(isOK-isNG>1):
    mid = (isOK+isNG)//2
    cnt = 0
    for i in range(N):
        if A[i] * F[i] > mid:
            tmp = (mid//F[i])+2
            while(tmp*F[i] > mid):
                tmp -= 1
            cnt += A[i]-tmp

    if cnt>K:
        isNG = mid
    else:
        isOK = mid
print(isOK)




Measured memory_bytes: 119628
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let line: usize = read_as_vec()[0];

    let a = read_as_vec::<i64>();

    let mut left_length: i64 = 0;
    let mut right_length: i64 = a.iter().sum::<i64>();

    let mut min_cost = (right_length-left_length).abs();

    for &part in &a{
        left_length += part;
        right_length -= part;
        min_cost = cmp::min(min_cost, (right_length-left_length).abs());
    }

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


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

using namespace std;

int c(char t){
    if (t=='y'||t=='u'||t=='i'||t=='o'||t=='p'||t=='h'||t=='j'||t=='k'||t=='l'||t=='n'||t=='m') {
        return 1;
    }
    return 0;
}

int main() {
    string s;
    while (cin >> s) {
        if (s[0] == '#') { break; }

        int now = c(s[0]);
        int ans = 0;

        for (int i = 1; s[i] != '\0'; i++){
            int p = c(s[i]);
            if (now != p) { ans++; }
            now = p;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3172
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
char a[301][301];
bool b[301];
int n;
int main(){
    while(~scanf("%d",&n)){
            int num=0;
            memset(b,false,sizeof(b));
            for(int i=0;i<n;i++){
                getchar();
                for(int j=0;j<n;j++){
                    scanf("%c",&a[i][j]);
                }
            }
            for(int k=0;k<n;k++){
                for(int i=0;i<n;i++){
                    for(int j=0;j<n;j++){
                        if((i+k)%n==j)continue;
                        if(a[(i+k)%n][j]==a[(j+k)%n][i]);
                        else{
                            b[k]=true;
                            break;
                        }
                    }
                    if(b[k])break;
                }
                if(!b[k])num+=n;
            }
            cout<<num<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <queue>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	if ((n % 3 == 0) + (m % 3 == 0) + ((n + m) % 3 == 0))
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int sum[100000];

int main() {
   int H, W, D;
   cin >> H >> W >> D;
   vec<pair<int, int>> p(H*W+10);
   rep (i, H) {
      rep (j, W) {
         int A;
         cin >> A;
         p[A] = {i, j};
      }
   }

   for (int i = D+1; i <= H*W; i++) {
      sum[i] = sum[i-D] + abs(p[i].first - p[i-D].first) + abs(p[i].second - p[i-D].second);
   }

   int Q;
   cin >> Q;
   while (Q--) {
      int l, r;
      cin >> l >> r;
      cout << sum[r] - sum[l] << endl;
   }

   return 0;
}

Measured memory_bytes: 2176
w,h,n = map(int, input().split())
x_left = 0
x_right = w
y_up = h
y_down = 0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a==1 and x_left <= x:
    x_left = x
  elif a==2 and x_right >= x:
    x_right = x
  elif a==3 and y_down <= y:
    y_down = y
  elif a==4 and y_up >= y:
    y_up = y

if x_right <= x_left or y_up <= y_down:
  print(0)
else:
  print((x_right - x_left)*(y_up - y_down))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

// dp[i][j] := i個目まで見たとき、価値がj以上のときの重さの最小値
int N, W, weight[1 << 17], value[1 << 17];
ll dp[111][1 << 17];

int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> weight[i + 1] >> value[i + 1];
    }

    int max_value = 1000 * N;

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= max_value; j++)
        {
            dp[i][j] = inf;
        }
    }

    dp[0][0] = 0;

    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j <= max_value; j++)
        {
            if (j - value[i] < 0)
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - value[i]] + weight[i]);
        }
    }

    ll ans = max_value;
    while (dp[N][ans] > W)
        ans--;

    cout << ans << endl;
}

Measured memory_bytes: 106240
#include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
int dx[] = {-1,0,1};
void saiki(int x,int y) {
  if(y >= h-1) memo[y][x]++;
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = x+dx[i], ny = y+1;
      if(nx==x && mp[ny][nx] == 2)while(mp[ny][nx] == 2) ny+=2;
      if(nx <0|| nx >= w ||mp[ny][nx] == 1) continue;

      if(memo[ny][nx]>0&&mp[ny][nx]==0) memo[y][x] += memo[ny][nx];
      else if(mp[ny][nx] == 0){
	saiki(nx,ny);
	memo[y][x] += memo[ny][nx];
      }
    }
    if(memo[y][x] == 0) mp[y][x] = 1;
  }
}
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
     
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
  
    for(int i=0;i<w;i++)
      if(mp[0][i] !=1) saiki(i,0);
     
    int cnt = 0;
    for(int i=0;i<w;i++)cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

int main(void)
{
    string s;

    cin >> s;

    if (s == "SUN")
    {
        cout << 7 << endl;
    }
    else if (s == "MON")
    {
        cout << 6 << endl;
    }
    else if (s == "TUE")
    {
        cout << 5 << endl;
    }
    else if (s == "WED")
    {
        cout << 4 << endl;
    }
    else if (s == "THU")
    {
        cout << 3 << endl;
    }
    else if (s == "FRI")
    {
        cout << 2 << endl;
    }
    else if (s == "SAT")
    {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

typedef db T;
const db eps = 1e-8;
int sgn(T x){return (x>eps)-(x<-eps);}
struct P{
    T x,y;
    P(){} P(T x,T y):x(x),y(y){}
    void read(){scanf("%lf%lf",&x,&y);}
    P operator - (const P&b) const {return P(x-b.x,y-b.y);}
    P operator + (const P&b) const {return P(x+b.x,y+b.y);}
    T operator * (const P&b) const {return x*b.x+y*b.y;}
    P operator * (const T&k) const {return P(x*k,y*k);}
    T operator ^ (const P&b) const {return x*b.y-y*b.x;}
    bool operator < (const P&b) const {return sgn(x-b.x)?x<b.x:y<b.y;}
    P rot90() {return P(-y,x);}
};
T norm(P x){return x*x;}
T abs(P x){return sqrt(x*x);}
struct C{
    P o;T r;
    void read(){o.read();scanf("%lf",&r);}
};
vector<P> tanCP(C c,P p){
    db x = norm(p - c.o) , d = x - c.r * c.r;
    vector<P> res;
    if(sgn(d) < 0) return res;
    d = max(d,0.);
    P mid = c.o + (p - c.o) * (c.r * c.r / x) ,
      del = ((p-c.o)*(-c.r*sqrt(d)/x)).rot90();
    return {mid + del ,mid - del};
}


int main(){
    P p;
    C o;
    p.read();o.read();
    vector<P> ans = tanCP(o,p);
    sort(all(ans));
    for(auto p : ans) printf("%.10f %.10f\n",p.x,p.y);
    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

vector<lint> rec(vector<lint> v) {
    vector<lint> w;
    for (auto e: v) {
        w.push_back(e*10 + 3);
        w.push_back(e*10 + 5);
        w.push_back(e*10 + 7);
    }
    return w;
}

int main(void) {
    lint n; cin >> n;
    
    vector<lint> t {3, 5, 7};
    vector<lint> v;
    rep (11) {
        for (auto e: t) v.push_back(e);
        t = rec(t);
    }
    
    auto check = [](lint n) -> bool {
        bool is3 = false, is5 = false, is7 = false;
        while (n > 0) {
            int d = n % 10;
            if (d == 3) is3 = true;
            if (d == 5) is5 = true;
            if (d == 7) is7 = true;
            n /= 10;
        }
        return (is3 and is5 and is7);
    };
    
    vector<lint> w;
    for (auto e: v) {
        if (check(e)) w.push_back(e);
    }
    sort(w.begin(), w.end());
    
    lint ans = 0;
    for (auto e: w) {
        if (e <= n) ++ans;
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17344
/**
 *    Coded by : adrirajc
**/
#include<bits/stdc++.h>
#define lli long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix fixed<<setprecision(10)
#define M 1000000007
#define w(x)            int x; cin>>x; while(x--) 
using namespace std;

/*void sieve(int p[],lli n)
{
    for(lli i=3;i<=n;i+=2)
    {
        p[i]=1;
    }
    //Sieve
    for(lli i=3;i<=n;i++)
    {
        if(p[i] == 1)
        {
            for(lli j=i*i;j<=n;j+=i)
            {
                p[j]=0;
            }
        }
    }
    p[2]=1;
    p[0]=p[1]=0;
}

lli recpow(lli x,lli n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return recpow((x*x)%M,n/2);
    else                             //n is odd
        return (x*recpow((x*x)%M,(n-1)/2))%M;
 
}
 
lli modInverse(lli n, lli p)
{
    return recpow(n, p - 2);
}
 
int nCrModPFermat(lli n, lli r)
{
    if (r == 0)
        return 1;
    lli fac[n + 1];
    fac[0] = 1;
    for (lli i = 1; i <= n; i++)
        fac[i] = fac[i - 1] * i % M;
 
    return (fac[n] * modInverse(fac[r], M) % M * modInverse(fac[n - r], M) % M) % M;
}
*/
//const int inf = 1012345678;
int main()
{
    int no_of_stones;
    cin >> no_of_stones;

    vector <int> height(no_of_stones + 1, 0);
    for(int i = 1; i <= no_of_stones; i++)
        cin >> height[i];

    vector <int> minimum_cost(no_of_stones + 1);
    minimum_cost[2] = abs(height[2] - height[1]);
    for(int i = 3; i <= no_of_stones; i++)
        minimum_cost[i] = min(minimum_cost[i - 1] + abs(height[i] - height[i - 1]),
                              minimum_cost[i - 2] + abs(height[i] - height[i - 2]));

    cout << minimum_cost[no_of_stones];
    return 0;
}

Measured memory_bytes: 1024