akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	int N;
	long[] a;
	long[] sum;
	int s = 0;

	ArrayList<Integer> ans = new ArrayList<>();

	//i=0,1,2
	void erase(int i) {
		ans.add(i);
		if (s + i == N - 1) {
			--N;
			return;
		}
		if (i == 0) {
			s += 1;
			return;
		} else if (i == 1) {
			a[s + 2] += a[s];
			s += 2;
		} else if (i == 2) {
			a[s + 3] += a[s + 1];
			a[s + 2] = a[s];
			s += 2;
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		a = new long[N];
		sum = new long[2];
		boolean[] f = new boolean[] { true, true };
		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextLong();
			if (a[i] > 0)
				sum[i % 2] += a[i];
			f[i % 2] &= a[i] < 0;
		}
		if (f[0] && f[1]) {
			long max = -Long.MAX_VALUE / 3;
			for (int i = 0; i < N; ++i) {
				if (max < a[i]) {
					max = a[i];
				}
			}
			while (a[s] != max) {
				erase(0);
			}
			while (true) {
				if (s == N - 1)
					break;
				if (s == N - 2) {
					erase(1);
					break;
				}
				erase(2);
			}
			System.out.println(max);
		} else {
			if (sum[0] < sum[1]) {
				erase(0);
			}
			while (true) {
				if (s == N - 1)
					break;
				if (s == N - 2) {
					erase(1);
					break;
				}
				if (a[s] < 0) {
					erase(0);
					erase(0);
				} else if (a[s + 2] > 0) {
					erase(1);
				} else if (a[s + 2] <= 0) {
					erase(2);
				}
			}
			System.out.println(Math.max(sum[0], sum[1]));
		}
		System.out.println(ans.size());
		for (int v : ans) {
			System.out.println(v + 1);
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 28648
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Fri Feb  8 09:08:27 2019
//
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	S, T := []string{}, []string{}
	for i := range s {
		S = append(S, string(s[i]))
	}

	for i := range t {
		T = append(T, string(t[i]))
	}

	sort.Strings(S)
	sort.Strings(T)

	for i, j := 0, len(T)-1; i <= j; i, j = i+1, j-1 {
		T[i], T[j] = T[j], T[i]
	}

	if strings.Join(S, "") < strings.Join(T, "") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //


// ゼロ除算エラーの対策をしていないので注意
// 関数の引数の評価順序が未規定のため、ceil_divide(ii(), ii())はNG
ll ceil_divide(ll a, ll b) {
  return (a + b - 1) / b;
}

// --------- library end - //


int main(){

  
  ll N = il();
  ll anst = 1;
  ll ansa = 1;
  rep(i, N){
    ll t = il();
    ll a = il();
    ll mul = max(ceil_divide(anst, t), ceil_divide(ansa, a));
    anst = t * mul;
    ansa = a * mul;
  }

  cout << anst + ansa << endk;

}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a == c){
			System.out.println(b);
		}else if(b == c){
			System.out.println(a);
		}else if(b == a){
			System.out.println(c);
		}else{
			System.out.println("error!");
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1e+7
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;
const ll M = 998244353;
const ll SIZE = 300000;
vector<ll> fac(SIZE+1); //n!(mod M)
vector<ll> ifac(SIZE+1); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n) { //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}

ll comb(ll a, ll b) { //aCbをmod計算
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}

void initinalize() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}

int main(){
  int N,M;
  cin >> N >> M;
  initinalize();
  int ans = 0;
  ans += comb(N,2);
  ans += comb(M,2);
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int nmax = 100100;
int N, X;
int a[nmax];

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

void solve(){
    sort(a, a+N);
    int i;
    for(i = 0;i < N && X>0; ++i)
    {
       X-=a[i]; 
       if (X < 0)
           break;
    }
    cout << i + ((i==N && X!=0)?-1:0) << endl;
}

int main(){
    read();
    solve();
}

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

int main(){
  int X;
  cin >> X;
  int x=X/100*100;
  int y=X-x;
  int ans=0;
  if(y<=X/100*5){ans++;}
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
s = input()
t = input()
if(len(s)>=len(t)):
    f = len(s)-len(t)
    e = len(s)
    while(0<=f):
        st = s[f:e]
        flag = True
        for i in range(len(t)):
            if(st[i] != t[i] and st[i] != "?"):
                flag = False
        if(flag):
            ss = s[0:f]+t+(s[e:] if(e<len(s)) else "")
            print(ss.replace("?","a"))
            sys.exit(0)
        f -= 1
        e -= 1
print("UNRESTORABLE")

Measured memory_bytes: 3064
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
w = inl()
acc = [0] * (n+1)
for i in range(n):
    acc[i] = acc[i-1] + w[i]

mn = 3000
x = acc[n-1]
for i in range(n):
    d = abs(acc[i]*2 - x)
    if d < mn:
        mn = d

print(mn)


Measured memory_bytes: 38384
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

void Main() {
  int n;
  cin >> n;
  vector<int> P(100, 0);
  rep(i, n) {
    int x;
    cin >> x;
    x--;
    rep(i, 100) {
      P[i] += (x-i)*(x-i);
    }
  }
  int ans = 10000000;
  rep(i, 100) {
    ans = min(ans, P[i]);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template <size_t I, class H, class... T> struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template <class H, class... T> struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template <class... T> istream& operator>>(istream&i,tuple<T...>& t) { t = TupleReaderWriter<sizeof...(T), T...>::r(i); return i; }
template <class... T> ostream& operator<<(ostream& o, tuple<T...>& t) { string delim = " "; TupleReaderWriter<sizeof...(T) - 1, T...>::w(o, t, delim); return o; }
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int A, B;
    char op;
    cin >> A >> op >> B;
    cout << (op == '+' ? A + B : A - B) << endl;
    return 0;
}

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

int main() {
  string s;cin>>s;
  int n=s.size();
  if(n==2)cout<<s<<endl;
  else {
    rep(i,n){
      cout<<s[n-i-1];
      if(i==n-1)cout<<endl;
    }
  }
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.next().split("");
        
        Set<String> set = new HashSet<>();
        for (String s : line) {
            set.add(s);
        }
        
        String result = "No"; 
        if (set.size() == 2) result = "Yes"; 
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35468
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
 	int a, p;
 	cin >> a >> p;
 	cout << (a*3+p)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
import collections
n = int(input())
a=[input() for _ in range(n)]
anslist=[]
b=collections.Counter(a)
c=max(list(b.values()))
for i in b:
    if b[i]==c:
        anslist.append(i)
d=sorted(anslist)
for i in tuple(d):
    print(i)

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(24);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;

vll a[100];
ll n, m, x, k;
ll c[100];

// <------------- Implement Functions Here ----------> //

ll success(vll X) {
	//DISP(X);
	for(ll i=0;i<X.size();i++) {
		if(X[i] < x) {
			//cout<<"--------"<<X[i]<<" "<<x;newl;
			return 0;
		}
	}
	return 1;
}

ll recur(ll i,vll X,ll cost) {
	//cout<<i<<" "<<cost;newl;
	
	if(success(X)==1) {
		//cout<<"X:   ";DISP(X);
		return cost;
	}
	else if(i==n) return INF;
	
	else {
		vll pick(m);
		for(ll j=0;j<m;j++) {
			pick[j] = a[i][j] + X[j];
		}
		return min(recur(i+1,X,cost),recur(i+1,pick,cost+c[i]));
	}
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> m >> x;
	for (ll i = 0; i < n; i++) {
		cin >> c[i];
		for (ll j = 0; j < m; j++) {
			cin >> k;
			a[i].pb(k);
		}

	}

	vll X(m);
	ll mini = INF;
	mini = min(INF,recur(0,X,0));
	if(mini==INF) cout<<-1; else
	cout<<mini;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


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

int main() {

    int a, b, c, d, e;
    cin >> a;
    
        b = a/1000;
        c = a/100-(b*10);
        d = a/10-(b*100)-(c*10);
        e = a%10;

        if ((b==c&&c==d)||(c==d&&d==e))
            cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }   
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()

    ans = ""
    for c in S:
        asc_c = ord(c) + N
        asc_A = ord("A")
        asc_Z = ord("Z")

        if asc_c > asc_Z:
            asc_c = asc_A + (asc_c % asc_Z) - 1
        
        ans += chr(asc_c)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := intScanner()
	fmt.Println(n*n - a)
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> vec(10000);
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
}

  int sum = 0;
  for (int j = 0; j < M; j++){
    sum = sum + vec.at(j);
  }
  
  if (sum > N){
    cout << -1 <<endl;
  }
  else{
    cout << N - sum << endl;
  }
}


Measured memory_bytes: 3636
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String Sk[] = S.split("");
    int N = S.length();
    
    boolean easyFlag = true;
    
    for(int i=0; i<N; i++){
      if(Sk[i].equals("R")){
        if((i%2)==1){
          easyFlag = false;
          break;
        }
      }
      if(Sk[i].equals("L")){
        if((i%2)==0){
          easyFlag = false;
          break;
        }
      }
    }
    
    if(easyFlag)
      System.out.println("Yes");
    else
      System.out.println("No");
    
  }
}

Measured memory_bytes: 21844
import scala.io.Source.stdin

object Main extends App {
  var b = new StringBuilder

  def loop(l:List[String],s:List[String]):Unit =
    if(l == Nil) return
    else {
      val i::lines = l
      if(i == "0") {
        val hd::tl = s
        b.append(hd+"\n")
        loop(lines,tl)
      } else {
        loop(lines,i::s)
      }
    }

  loop(stdin.getLines.toList,Nil)
  print(b.result)
}

Measured memory_bytes: 43844
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	int cnt=0;
	ll ans=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='B')
			ans+=s.size()-1-i-cnt,cnt++;
	}
	cout<<ans<<endl;
}


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


void solve(long long A, long long B, long long C, long long D){
    if(A >= C && A <= D && D <= B) cout << D - A << endl;
    else if(A >= C && A >= D) cout << 0 << endl;
    else if(A <= C && C <= B && A <= D && D <= B) cout << D - C << endl;
    else if(A <= C && C <= B && B <= D) cout << B - C << endl;
    else if(B <= C && C <= D) cout << 0 << endl;
    else if(C <= A && B <= D) cout << B - A << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const ll INF=1000000000000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	ll w,h,n;
	vector<ll> x,y;
	
	ll add_min = INF ,x_add_min,y_add_min;
	ll add_max = -INF,x_add_max,y_add_max;
	ll dif_min = INF ,x_dif_min,y_dif_min;
	ll dif_max = -INF,x_dif_max,y_dif_max;
	
	
	scanf("%lld%lld%lld",&w,&h,&n);
	rep(i,n){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		if(a+b < add_min){
			add_min = a+b;
			x_add_min = a;
			y_add_min = b;
		}
		if(a+b > add_max){
			add_max = a+b;
			x_add_max = a;
			y_add_max = b;
		}
		if(a-b < dif_min){
			dif_min = a-b;
			x_dif_min = a;
			y_dif_min = b;
		}
		if(a-b > dif_max){
			dif_max = a-b;
			x_dif_max = a;
			y_dif_max = b;
		}
		x.pb( a );
		y.pb( b );
		
	}
	
	sor(x);
	sor(y);
	
	ll ret = INF,ret_x,ret_y;
	ll X[4] = { x_add_min , x_add_max , x_dif_min , x_dif_max };
	ll Y[4] = { y_add_min , y_add_max , y_dif_min , y_dif_max };
	
	rep(i,4){
		vector<ll> x_,y_;
		rep(j,x.size()){
			if(x[j] != X[i]){
				x_.pb ( x[j] );
				x_.pb ( x[j] );
			}
			else {
				x_.pb ( x[j] );
				X[i] = -1;
			}
		}
		rep(j,y.size()){
			if(y[j] != Y[i]){
				y_.pb ( y[j] );
				y_.pb ( y[j] );
			}
			else {
				y_.pb ( y[j] );
				Y[i] = -1;
			}
		}
		
		ll ans_x = x_[x_.size()/2],ans_y = y_[y_.size()/2];
		ll sum = 0;
		
		rep(i,x_.size()){
			sum += abs( x_[i]-ans_x );
		}
		rep(i,y_.size()){
			sum += abs( y_[i]-ans_y );
		}
		
		if(sum < ret){
			ret = sum;
			ret_x = ans_x;
			ret_y = ans_y;
		}
		else if(sum == ret){
			if(ans_x < ret_x){
				ret_x = ans_x;
				ret_y = ans_y;
			}
			else if(ans_x == ret_x){
				if(ans_y < ret_y){
					ret_y = ans_y;
				}
			}
		}
	}
	
	cout << ret << endl;
	cout << ret_x << " " << ret_y << endl;
}

Measured memory_bytes: 8784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    int ans = 0;
    rep(i, n)
    {
        int x = i+1;
        int tmp = 0;
        while(x%2 == 0){
            tmp++;
            x /= 2;
        }
        if(cnt <= tmp){
            ans = i+1;
        }
        cnt = max(cnt, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int bb[123456];
void insert(int a,int b,int c)
{
	bb[a]+=c;
	bb[b+1]-=c;
}
int main()
{
	int n,m,q;int x;
	cin>>n>>m>>q;
	bb[0]=m;
	for(int i=0;i<q;i++)
	{
		cin>>x;
		insert(1,x-1,-1);
		insert(x+1,n+1,-1);
	}
	for(int i=1;i<=n;i++)
	{
		bb[i]+=bb[i-1];
		if(bb[i]>0) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

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

int calc(int a,int b,int c){
	int max = a;
	if(b > max) max = b;
	if(c > max) max = c;
	if(((max - a) + (max - b) + (max - c)) % 2 == 0){
		return (max - a) + (max - b) + (max - c);
	}else{
		max += 1;
		return (max - a) + (max - b) + (max - c);
	}
}
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int delta = calc(a,b,c);
	cout << delta / 2 << endl;	
}

Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
x = inp[0]
now = 0
c = 0
(10**10).times do |i|
  now += i
  if(now >= x)
    c = i
    break 
  end
end
p c

=begin
=end

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

int combi(int a)
{
    int ans = 0;
    if (a == 1)
    {
        return 0;
    }
    
    ans = a*(a-1)/2;
    return ans;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    vector<int> cop = A;
    sort(cop.begin(), cop.end());

    int64_t ans = 0;
    map<int, int> hozon;
    vector<int> jb(N), ib(N);
    //vector<int> han(2*abs(N-cop.at(0))+1, 1);
    for (int i = 0; i < N; i++)
    {
        jb.at(i) = A.at(i) - (i+1);
        if (hozon.count(jb.at(i)))
        {
            ans += hozon.at(jb.at(i));
            //ans += han.at(abs(jb.at(i)));  
        }
        
        ib.at(i) = -A.at(i) - (i+1);
        if (hozon.count(ib.at(i)) && i != N-1)
        {
            hozon.at(ib.at(i)) ++;
            //han.at(abs(ib.at(i))) ++;
            continue;
        }
        else
        {
            hozon[ib.at(i)] = 1;
        }
    }



    cout << ans;
    
    
}

Measured memory_bytes: 15432
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	long long q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	n *= 100;

	long long ans = 0;
	long long t = n / 200;
	n -= t * 200;
	ans += min(min(t * d, 2 * t * s), min(4 * t * h, 8 * t * q));

	t = n / 100;
	n -= t * 100;
	ans += min(t * s, min(2 * t * h, 4 * t * q));

	t = n / 50;
	n -= t * 50;
	ans += min(t * h, 2 * t * q);

	t = n / 25;
	n -= t * 25;
	ans += t * q;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main(){
    ll H,W,h,w;
  	ll ans;
  	cin >> H >> W >> h >> w;
  	ans = H * W - (W * h + H * w) + h * w;
  	cout << ans << endl;
  
}

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

int main (){
    string s;

    cin>>s;

    string a = s.substr(0,4);
    string b = s.substr(5,6);
    string c = s.substr(8,9);

   int x= stoi(a);
   int y = stoi(b);
   int z = stoi(c);

    if(x <= 2019 && y <= 4 && z <= 30){
        cout<<"Heisei"<<endl;
    }else{
        cout<<"TBD"<<endl;
    }





}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

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

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n;
	cin >> n;
	vi v(n);
	map<int, int> cnt;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	cnt[1 + v[0]] = 1;
	ll ans = 0;
	for(int i = 1; i < n; i++){
		int c = i + 1 - v[i];
		ans += cnt[c];
		cnt[i + 1 + v[i]]++;
	}
	cout << ans << endl;
}

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

int main() {
  double a, b;
  while (cin >> a >> b) {
    string s = "NA";
    if (a < 35.5 && b < 71.0)s = "AAA";
    else if (a < 37.5 && b < 77.0) s = "AA";
    else if (a < 40.0 && b < 83.0) s = "A";
    else if (a < 43.0 && b < 89.0) s = "B";
    else if (a < 50.0 && b < 105.0) s = "C";
    else if (a < 55.0 && b < 116.0) s = "D";
    else if (a < 70.0 && b < 148.0) s = "E";
    cout << s << "\n";
  }
}


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

ans = 0
for i in range(N):
    if A[i]+A[i+1] >= B[i]:
        ans += B[i]
        if A[i] < B[i]:
            A[i+1] -= B[i]-A[i]
    elif A[i]+A[i+1] < B[i]:
        ans += A[i]+A[i+1]
        A[i+1] = 0
    #print(A)
print(ans)


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

using namespace std;
using ll = long long;

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

struct UnionFind {
  vector<int> p;
  UnionFind(int n) : p(n, -1) {}

  bool unite(int x, int y) {
    x = root(x), y = root(y);

    if (x == y) return false;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  int root(int x) {
    if (p[x] < 0) return x;
    return p[x] = root(p[x]);
  }

  bool same(int x, int y) { return root(x) == root(y); }

  int size(int x) { return -p[root(x)]; }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  UnionFind uf(n);
  vector<int> deg(n);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    ++deg[a];
    ++deg[b];
    uf.unite(a, b);
  }

  vector<int> bl[n];
  rep(i, k) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    bl[a].push_back(b);
    bl[b].push_back(a);
  }

  rep(i, n) {
    int ans = uf.size(i) - 1 - deg[i];
    for (auto v : bl[i]) {
      if (uf.same(i, v)) --ans;
    }
    cout << ans;
    if (i != n - 1) cout << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define F(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define VE(i,v) for(int i = 0;i < (v).size();i++)

using namespace std;
#define trace(...) cerr<<__FUNCTION__<<":"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cerr<<name<<" : "<<arg1<<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...);
}
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned int ui;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
typedef pair<ll,ll> pll;
typedef vector<pll> vpll; 
 




int main()

{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T;
	T=1;
	for(int tc=1; tc<=T;tc++)
	{
		int N;
		string inp;
		cin>>N>>inp;
		string oup="";
		for(int i=0; i < sz(inp);i++)
		{
			int temp =((int) (inp[i] - 'A'+N))%26;
			char c = 'A'+ temp;
			oup = oup+c;
		}
		cout<<oup<<"\n";
	}
 
 
 
	return 0;
}
 
 


Measured memory_bytes: 384
#include "bits/stdc++.h"
using ll = long long;
using namespace std;


void solve() {
   int n;
   cin >> n;
   vector <int> v(n);
   for(auto &e: v) {
      cin >> e;
   }
   ll ans = 0;
   for(auto &e: v) {
      while(e % 2 == 0 && e > 0) {
         e /= 2;
         ans++;
      }
   }
   cout << ans << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int dp[30100][13][13][13];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    fill_n(***dp, 30100 * 13 * 13 * 13, -1);
    // dp[0][10][10][10] = 0;
    
    /*
     int n;
     cin >> n;
     vector<int> a(n);
     rep(i, n) cin >> a[i];
     */
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    
    rep(i, n) {
        // s[i]を追加
        rep(j, 10) rep(k, 10) {
            if (dp[i][j][k][10] == -1) continue;
            
            if (dp[i + 1][j][k][s[i] - '0'] != -1) dp[i + 1][j][k][s[i] - '0'] += dp[i][j][k][10];
            else dp[i + 1][j][k][s[i] - '0'] = 1;
        }
        rep(j, 10) {
            if (dp[i][j][10][10] == -1) continue;
            
            if (dp[i + 1][j][s[i] - '0'][10] != -1) dp[i + 1][j][s[i] - '0'][10] += dp[i][j][10][10];
            else dp[i + 1][j][s[i] - '0'][10] = 1;
        }
        
        if (dp[i][s[i] - '0'][10][10] == -1) dp[i + 1][s[i] - '0'][10][10] = 1;
        else dp[i + 1][s[i] - '0'][10][10] = 1;
        
        rep(j, 13) rep(k, 13) rep(l, 13) chmax(dp[i + 1][j][k][l], dp[i][j][k][l]);
    }
    
    ll ans = 0;
    rep(i, 10) rep(j, 10) rep(k, 10) {
        if (dp[n][i][j][k] == -1) continue;
        ans += dp[n][i][j][k];
    }
    cout << ans << endl;
    
    /*
    rep(keta, n + 1) {
        cout << endl << keta << endl;
        rep(i, 10 + 1) {
            cout << i << endl;
            rep(j, 10 + 1) {
                rep(k, 10 + 1) {
                    cout << dp[keta][i][j][k] << " ";
                }
                cout << endl;
            }
        }
    }
     */
    // cout << dp[0][0][10][10] << endl;
    
}


Measured memory_bytes: 258688
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
ll h[maxn], val[maxn], n;
ll tree[4*maxn];

void update(int ind, ll val, int li=0, int ri=n, int index=1) {
	if(li == ri) tree[index] = max(tree[index], val);
	else {
		int mid = (li + ri) / 2;

		if(ind <= mid) update(ind, val, li, mid, 2*index);
		else update(ind, val, mid+1, ri, 2*index+1);

		tree[index] = max(tree[2*index], tree[2*index+1]);
	}
}

ll query(int ql, int qr, int li=0, int ri=n, int index=1) {
	if(li > qr || ri < ql) return 0LL;
	else if(li >= ql && ri <= qr) return tree[index];
	else {
		int mid = (li + ri) / 2;
		return max(query(ql, qr, li, mid, 2*index), query(ql, qr, mid+1, ri, 2*index+1));
	}
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>h[i];
	}
	for(int i=1;i<=n;i++) {
		cin>>val[i];
	}

	ll result = 0LL;
	for(int i=1;i<=n;i++) {
		ll curr = query(0, h[i]-1) + val[i];
		result = max(result, curr);
		update(h[i], curr);
	}
	cout<<result<<"\n";
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = N;
  rep(i, N-1){
    if(S.at(i) == S.at(i+1)) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;cin >> a >> b;
    if(a>0&&b>0){
        cout << "Positive"<< endl;
    }else if(a<0&&b<0){
        if((b-a)%2==0){
            cout << "Negative" << endl;
        }else{
            cout << "Positive" << endl;
        }
    }else{
        cout << "Zero" << endl;
    }

    return 0;
}

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

int main() {
    for(;;) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        std::vector<int> xs(n);
        for(int i = 0; i < n; ++i) {
            std::cin >> xs[i];
        }
        int dp[310][310] = {{}};
        for(int w = 2; w <= n; ++w) {
            for(int l = 0; l <= n-w; ++l) {
                int r = l + w;
                // sep
                for(int k = l+1; k < r; ++k) {
                    dp[l][r] = std::max(dp[l][r], dp[l][k] + dp[k][r]);
                }
                // 2
                if (std::abs(xs[l] - xs[r-1]) <= 1 && dp[l+1][r-1] == r-l-2) {
                    dp[l][r] = std::max(dp[l][r], dp[l+1][r-1] + 2);
                }
            }
        }
        printf("%d\n", dp[0][n]);
    }
}



Measured memory_bytes: 3600
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

char maze[50][50];
int H,W;

int dfs(int x,int y){
  if(x<0 || H<=x || y<0 || W<=y)return 0;
  int cnt = 0;
  maze[x][y] = '0';
  int dx[] = { 1, 1, 1,-1,-1,-1, 0, 0};
  int dy[] = {-1, 0, 1,-1, 0, 1, 1,-1};
  rep(i,8){
    // if(i==j&&i==0)continue;
    if(maze[x+dx[i]][y+dy[i]]=='1')dfs(x+dx[i],y+dy[i]);
  }
  return cnt;
}
void solve(){
  int h,w;
  while(cin>>W>>H,H+W){
    rep(i,H)rep(j,W)cin>>maze[i][j];
    int res=0;
    rep(i,H)rep(j,W){
      //rep(k,H){rep(l,W)cout<<maze[k][l];cout<<endl;}
      //cout<<endl;
      if(maze[i][j]=='1'){
	dfs(i,j);
	res++;
      }
    }
    cout<<res<<endl;
  }
}

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

Measured memory_bytes: 1376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int m;
    cin >> m;
    cout << 48 - m << endl;
}


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

typedef long long LL ;
typedef pair < int , int > pii ;

#define clr( a , x ) memset ( a , x , sizeof a )

char p[] = { "CODEFESTIVAL2016" } ;
char s[100] ;

void solve () {
	int ans = 0 ;
	for ( int i = 0 ; s[i] ; ++ i ) {
		if ( s[i] != p[i] ) ++ ans ;
	}
	printf ( "%d\n" , ans ) ;
}

int main () {
	while ( ~scanf ( "%s" , s ) ) solve () ;
	return 0 ;
}

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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    string S,T;

    cin>>S>>T;

    T.erase(T.size()-1);

    if(S==T){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

const int M = 24 * 60 * 60 + 10;

int solve(int n) {
    VI cnts(M);
    
    rep(i, n) {
        int a, b, c, x, y, z;
        scanf("%d:%d:%d", &a, &b, &c);
        scanf("%d:%d:%d", &x, &y, &z);
        int s = a * 60 * 60 + b * 60 + c;
        int t = x * 60 * 60 + y * 60 + z;
        cnts[s] += 1;
        cnts[t] -= 1;
    }

    partial_sum(ALL(cnts), cnts.begin());

    return *max_element(ALL(cnts));
}

int main(void) {
    int n;
    while (cin >> n, n) cout << solve(n) << endl;

    return 0;
}

Measured memory_bytes: 3476
n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
cand = []
for i in range(2**n):
    tmp = 0
    for j in range(n):
        if(i>>j)&1:
            tmp += a[j]
    if tmp not in cand:
        cand.append(tmp)
for i in q:
    print('yes' if i in cand else 'no')


Measured memory_bytes: 5628
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
	        String word = kb.readLine().toUpperCase();
	        
	        String str;
	        int cnt = 0;
	       	boolean endoftext = false;
	        while( null != ( str = kb.readLine() ) ) {
	        	for( String wd: str.split( " ", 0 ) ) {
					if( wd.equals( "END_OF_TEXT" ) ) {
		        		endoftext = true;
		        		break;
		        	}
		        	wd = wd.toUpperCase();
		        	if( wd.equals( word ) ) {
		        		cnt++;
		        	}
		        }
	        	if( endoftext ) { break; }
	        }
			System.out.println( cnt );
			
		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 16992
// In the Name of God 

#include <bits/stdc++.h>

using namespace std;

#define	ll long long
#define ull unsigned long long
#define ld long double

#define fi first
#define se second

#define pb push_back
#define mp make_pair

#define sz(a) (a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)

#define IOS ios_base :: sync_with_stdio(false); cin.tie(NULL);

#define itr iterator

#define ioi(i, a, b) for (int i = a; i <= b; ++i)
#define IOI(i, a, b) for (int i = a; i >= b; --i)

#define ub upper_bound
#define lb lower_bound

const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const int Mod = 1e9 + 7;
const double eps = 1e-15;
const int pw = 257;

int p[N], P[N];

int main() {
	#ifdef Madi
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif

	int n;
	cin >> n;

	for (int j = 1; j <= n; ++j) {
		int a;
		cin >> a;
		p[j] = p[j - 1] + a;
	}

	int a[n + 2];
	for (int j = 1; j <= n; ++j)
		cin >> a[j];

	for (int j = n; j >= 1; --j)
		P[j] = P[j + 1] + a[j];

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans = max(ans, p[i] + P[i]);
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
# ABC131C - Anti-Division
from fractions import gcd


def main():
    a, b, c, d = list(map(int, input().rstrip().split()))
    total = b - a + 1
    a -= 1
    divisible = 0
    div_c = b // c - a // c
    divisible += div_c
    div_d = b // d - a // d
    divisible += div_d
    lcm = c * d // gcd(c, d)
    div_lcm = b // lcm - a // lcm
    divisible -= div_lcm
    print(total - divisible)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    int k;
    cin >> k;
    int ans = 0;
    rep(i, n) {
        int h; cin >> h;
        if (h >= k) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660