akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

typedef uint64_t     ul;
typedef uint32_t     ui;

using namespace std;

int main(void)
{
	ui N{ 0 };
	cin >> N;

	vector<ul> arrayA(N, 0);
	ul sum{ 0 };
	ul halfSum{ 0 };

	for (ui i = 0; i < N; ++i)
	{
		cin >> arrayA[i];

		sum += arrayA[i];
		if (i % 2 == 0)
		{
			halfSum += arrayA[i];
		}
	}

	// X_0の導出
	ul ans = halfSum * 2 - sum;
	cout << ans << " ";

	for (ui i = 0; i < N - 1; ++i)
	{
		// X_i = A_i * 2 - X_(i-1)
		ans = arrayA[i] * 2 - ans;
		cout << ans;

		if (i != N - 2)
		{
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 2048
from copy import deepcopy

while True:

    m = int(raw_input())
    n = int(raw_input())

    if m == 0 and n == 0:
        break

    field = [[False] * m for y in xrange(n)]

    for y in xrange(n):
        line = map(int, raw_input().split(' '))
        for x in xrange(m):
            if line[x] == 1:
                field[y][x] = True

    ans = 0

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    def search(x, y, d):
        global ans

        if d > ans:
            ans = d

        for i in xrange(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < m and 0 <= ny < n and field[ny][nx]:
                field[ny][nx] = False
                search(nx, ny, d + 1)
                field[ny][nx] = True

    for x in xrange(m):
        for y in xrange(n):
            if field[y][x]:
                field[y][x] = False
                search(x, y, 1)
                field[y][x] = True

    print ans

Measured memory_bytes: 4400
#include <stdio.h>
#include <iostream>
#include <vector>
#include <array>
#include <stack>
#define NUM 100010
#define NIL -1

using namespace std;

stack<int> S;
vector<pair<int,int>> w[NUM];
array<int, NUM> d;

void init(){
    for(int i = 0; i < NUM; i++){
        d[i] = NIL;
    }
}

int main(void){
    init();
    int N;
    scanf("%d\n", &N);

    for(int i = 1; i <= N-1; i++){
        int u_, v_, w_;
        scanf("%d %d %d", &u_, &v_, &w_);
        w[u_].push_back(make_pair(v_, w_));
        w[v_].push_back(make_pair(u_, w_));
    }

    d[1] = 0;
    S.push(1);
    while(S.size()){
        int num = S.top(); S.pop();
        //printf("num: %d\n", num);
        for(int i = 0; i < w[num].size(); i++){
            if(d[w[num][i].first] == NIL){
                S.push(w[num][i].first);
                d[w[num][i].first] = d[num] + w[num][i].second;
            }
        }
    }

    for(int i = 1; i <= N; i++){
        //printf("%d\n", d[i]);
        if(d[i] % 2 == 0){
            printf("1\n");
        }else{
            printf("0\n");
        }
    }

}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N,K;
    cin >> N >> K;

    string s;
    cin >> s;

    if( s[K-1] == 'A' ) s[K-1] = 'a';
    if( s[K-1] == 'B' ) s[K-1] = 'b';
    if( s[K-1] == 'C' ) s[K-1] = 'c';
    cout << s << endl;

}


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

int main(){
   string y;
  int count =0;
  bool t=0;
  cin>>y;
  if(y=="SSS")cout<<0<<endl;
  if(y=="SSR")cout<<1<<endl;
  if(y=="SRR")cout<<2<<endl;
  if(y=="SRS")cout<<1<<endl;
  if(y=="RSS")cout<<1<<endl;
  if(y=="RSR")cout<<1<<endl;
  if(y=="RRS")cout<<2<<endl;
  if(y=="RRR")cout<<3<<endl;
}


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

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

int main() {
  ll x,k,d;
  cin >> x >> k >> d;
  ll b=labs(x);
  ll m=b/d;
  ll n=b%d;
  if(m>=k){
    cout << b-k*d << endl;
  }
  else{
    if((k-m)%2==0){
      cout << n << endl;
    }
    else if((k-m)%2==1){
      cout << labs(n-d) << endl;
    }
  }
  return 0;
 
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include<random>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define MAX 100002

int n;
vector<long long int> v;


int main(){
	cin >> n;
	for (int i = 0; i < 3*n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	long long int ans = 0;
	int cnt = 0;
	for (int i = 1; i < v.size(); i += 2){
		ans += v[i];
		cnt++;
		if (cnt == n)break;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6512
N = int(input())
A = list(map(int, input().split()))
even_num = []
for i in A:
    if i % 2 == 0:
        even_num.append(i)
for j in range(len(even_num)):
    if even_num[j] % 3 != 0 and even_num[j] % 5 != 0:
        print('DENIED')
        exit()
print('APPROVED')

Measured memory_bytes: 3060
#include <stdio.h>
 
int main (void)
{
 
    int a,b,c,d,e;
    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
  	if(a==0){
    printf("1\n");
    }else if(b==0){
    printf("2\n");
    }else if(c==0){
    printf("3\n");
    }else if(d==0){
    printf("4\n");
    }else if(e==0){
    printf("5\n");
    }
 
    return(0);
 
}

Measured memory_bytes: 1624
import sys

if __name__ == "__main__":
    N = int(input())
    digit = len(str(N))
    digit_list = [int(x) for x in list(str(N))]
    if digit == 1:
        print(N)
        sys.exit()
    buf = 0
    for i in range(digit):
        buf += (9 * pow(10, i))
    if N == buf:
        print(9 * digit)
        sys.exit()
    buf = 0
    for i in range(digit - 1):
        buf += (9 * pow(10, i))
    if (N - digit_list[0] * pow(10, digit - 1)) == buf:
        cand = 0
        for ele in digit_list:
            cand += ele
        print(cand)
        sys.exit()
    cand = 0
    if digit_list[0] == 1:
        cand = 9 * (digit - 1)
    else:
        cand = digit_list[0] - 1 + 9 * (digit - 1)
    print(cand)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m, l[2], r[2];
  cin >> n >> m;
  l[0] = 1;
  r[0] = 1 + m;
  l[1] = m + 2;
  r[1] = m + 2 + m - 1;
  for (int i = 0; i < m; i++) {
    if (i % 2 == 0) {
      cout << l[0] << " " << r[0] << endl;
      l[0]++;
      r[0]--;
    } else {
      cout << l[1] << " " << r[1] << endl;
      l[1]++;
      r[1]--;
    }
  }
}


Measured memory_bytes: 3636
var
	s:array[1..100]of String[100];
	h,w,i,j:Longint;
	a,b:array[1..100]of Boolean;
begin
	readln(h,w);
	for i:=1 to h do readln(s[i]);
	for i:=1 to h do begin
		a[i]:=false;
		for j:=1 to w do
			if s[i][j]='#' then begin
				a[i]:=true;
				break;
			end;
	end;
	for j:=1 to w do begin
		b[j]:=false;
		for i:=1 to h do
			if s[i][j]='#' then begin
				b[j]:=true;
				break;
			end;
	end;
	for i:=1 to h do
		if a[i] then begin
			for j:=1 to w do
				if b[j] then write(s[i][j]);
			writeln('');
		end;
end.


Measured memory_bytes: 128
import numpy as np

N, D = map(int, input().split())
x = [list(map(int, input().split())) for i in range(N)] 
def main(x2, x3):
  y2 = np.array(x2)
  y3 = np.array(x3)
  l = np.linalg.norm(y3-y2)
  return l

count = 0

for i in range(N):
  for j in range(i+1, N):
    if main(x[i], x[j]).is_integer() == True:
      count += 1

print(count)

Measured memory_bytes: 21792
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

struct UnionFind {
    int n, cnt;
    vi par, rank, sz;

    UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

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

    int size(int x) {
        return sz[find(x)];
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<pair<int, int>> es;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        es.emplace_back(a, b);
    }
    vector<long long> ans;
    long long nax = 1ll * n * (n - 1) / 2;
    for (int i = m - 1; i >= 0; i--) {
        ans.push_back(nax);
        if (!uf.same(es[i].first, es[i].second)) {
            int a = uf.size(es[i].first), b = uf.size(es[i].second);
            uf.unite(es[i].first, es[i].second);
            nax -= 1ll * a * b;
        }
    }
    reverse(ans.begin(), ans.end());
    for (long long a : ans) {
        cout << a << '\n';
    }
}

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

struct node {
	unsigned int key;
	struct node *next;
	struct node *prev;//前previous
};

typedef struct node * NodePointer;

NodePointer nil;//無し空

NodePointer listSearch(int key) {
	/* your code */
	NodePointer x=nil->next;
	while(x != nil && x->key != key) {
		x=x->next;
	}
	return x;
}

void init() {
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(void) {
	NodePointer cur = nil->next;
	int isf = 1;
	while(1) {
		if (cur == nil) break;
		if (isf == 0)  printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
		isf = 0;
	}
	printf("\n");
}

void deleteNode(NodePointer t) { ///////////////
	/* your code */
	//NodePointer pr = t->prev, nx=t->next;
	if(t==nil) return;
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);
}

void deleteFirst() { //1
	NodePointer t = nil->next;
	if ( t == nil ) return;
	deleteNode(t);
	//printf("deleteFirst\n");
}

void deleteLast() { //2
	/* your code */
	NodePointer t = nil->prev;
	if ( t == nil ) return;
	deleteNode(t);
	//printf("deleteLast\n");
}

void delete(int key) { //3
	/* your code */
	NodePointer x=listSearch(key);
	if(x==nil) return;
	deleteNode(x);
	
	//printf("delete\n");
}

void insert(int key) { //4
	NodePointer x;
	x = malloc(sizeof(struct node));
	x->key = key;
if (nil->prev == NULL) {
    nil->prev = x;
  }
  
  if (nil->next == NULL) {
    nil->next = x;
    x->prev = nil;
    x->next = nil;
  } else {
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
	
  }
	//printf("insert%d\n", key);
	//printList();
}

int main(void) {
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for (i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {
      insert(key); 
      np++; 
      size++;
    } else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') deleteFirst();
        else if (com[6] == 'L') deleteLast();
      } else {
        delete(key);
        nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 33004
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
#define debugCont(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define double long double
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

signed main(){

    fastIO

    int a, b, h, m;
    scanf("%lld%lld%lld%lld",&a, &b, &h, &m);
    double rad = PI * 2 * ((double)h/12.0 + ((double)m/60.0)/12.0 - (double)m/60.0);
    double rsq = (double)(a*a + b*b) - (double)(2*a*b)*cosl(rad);
    printf("%20.20Lf\n", sqrtl(rsq));


 //    int a, b, h, m;
 //    cin >> a >> b >> h >> m;
 //    double angle = ((double)h + (double)m/60.0)*30 - (double)m*6;
	// // trace(angle);
	// double rad = PI * 2 * ((double)h / 12.0 + ((double)m / 60.0) / 12.0 - (double)m / 60.0);
	// angle *= (PI/180);
	// trace(angle, rad)
	// double ans1 = sqrtl((double)(b*b + a*a) - (double)2*b*a*cosl(angle));
	// double ans2 = sqrtl((double)(b*b + a*a) - (double)2*b*a*cosl(rad));
	// // printf("ans2 = %Lf\n", ans2);
	// printf("%Lf\n", ans1);

    return 0;
}

Measured memory_bytes: 4236
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : m : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  scs <- sequence . replicate m $ unsafeListToTuple . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    cs :: [[Int]]
    cs | n == 1    = sequence [[0..9]]
       | otherwise = sequence $ [1..9] : replicate (pred n) [0..9]
    p :: [Int] -> Bool
    p xs = all (\(s, c) -> xs !! pred s == c) scs
    rs :: [[Int]]
    rs = filter p cs
  putStrLn $ if null rs then "-1" else map (toEnum . (48 +)) (head rs)

unsafeListToTuple :: [Int] -> (Int, Int)
unsafeListToTuple (x : y : _) = (x, y)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
bool a[100005];
int b[100005];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int i;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(i=1;i<=n;i++)
            b[i]=1;
        a[1]=1;
        while(m--)
        {
            int x1,x2;
            cin>>x1>>x2;
            if(a[x1]==1&&b[x1]==1)
            {
                a[x1]=0;
                a[x2]=1;
            }
            else if(a[x1]==1)
                a[x2]=1;
            b[x1]--;
            b[x2]++;
        }
        int sum=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]&&b[i]>0)
            {
                sum++;
            }
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 768
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

      
#(方針)Union Findは「結合」はできるけど「分離」はできないので
#一番最後のケースから逆算（徐々につなげる）をしていく
N,M = map(int,input().split())
uncomfortable = []
Edge = []
for i in range(M):
  a,b = map(int,input().split())
  Edge.append([a-1,b-1])
Edge.reverse() 

ans = N*(N-1)//2 #逆算していくときの初期(全部が孤立)の不便さはN
union = UnionFind(N)
for i in range(M):
  uncomfortable.append(ans)
  a,b = Edge[i][0],Edge[i][1]
  if(union.isSameGroup(a,b) == False):
   n1,n2 = union.Count(a),union.Count(b)
   ans -= n1*n2     
  union.Unite(a,b)

uncomfortable.reverse()
for i in range(M):
  print(uncomfortable[i])

Measured memory_bytes: 26392
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

ll calc_gcd(ll a, ll b) {
    ll s = min(a, b);
    ll l = max(a, b);
    if (s == 0) {
        return l;
    }
    return calc_gcd(s, l % s);
}

int main(void) {
    ll A, B;
    cin >> A >> B;

    ll gcd = calc_gcd(A, B);
    cout << A * B / gcd << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#define ll long long
using namespace std;
ll min(ll a,ll b)
{
	return a<b?a:b;
}
ll max(ll a,ll b)
{
	return a>b?a:b;
}
ll abs_val(ll a)
{
	return a<0?(-1*a):a;
}
int main() {
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	ll dp[n+1];
	dp[0]=0;
	for(ll i=1;i<n;i++)
	{
		dp[i]=-1;
		for(ll j = max(0,i-k);j<i;j++)
		{
			if(dp[i]==-1)
			{
				dp[i]=dp[j]+(abs_val(arr[i]-arr[j]));
			}
			else
			{
				dp[i] = min(dp[j]+(abs_val(arr[i]-arr[j])),dp[i]);
			}
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nの約数を返す関数.sortされてない.
vector<long long int> divisors(long long int n){
	vector<long long int> res;
	for (long long int i = 1; i * i <= n;i++){
		if (n % i == 0){
			res.push_back(i);
			if(i * i != n){
				res.push_back(n / i);
			}
		}
	}
	return res;
}

int main()
{
	int x;
	cin >> x;
	if(x==0)
		cout << 1 << endl;
	else
		cout << 0 << endl;

	return 0;
}




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

using namespace std;

typedef long long ll;
typedef pair<int, int> duo;

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T    In(T& x){ cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

struct Solver {
  Solver(int w, int h) : w(w), h(h) { memset(field, 0, sizeof(field)); }
  void input(){
    for (int y = 0; y < h; y++){
      for (int x = 0; x < w; x++){
        field[y][x] = in();
      }
    }
  }
  int solve(){
    int count = 0;
    for (int y = 0; y < h; y++){
      for (int x = 0; x < w; x++){
        if (field[y][x]){
          count++;
          erase(x, y);
        }
      }
    }
    return count;
  }

  void erase(int x, int y){
    if (invalid(x, y)) return;
    if (!field[y][x]) return;
    field[y][x] = 0;
    for (int d = 0; d < 8; d++){
      erase(x + dx[d], y + dy[d]);
    }
  }
  bool invalid(int x, int y){
    return x < 0 || w <= x || y < 0 || h <= y;
  }
  const int w, h;
  int field[64][64];
};

int main()
{
  int w, h;
  while (w = in(), h = in()){
    Solver s(w, h);
    s.input();
    printf("%d\n", s.solve());
  }
  return (0);
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  string s;
  cin >> s;
  bool flag = true;
  rep(i,s.size()){
    char c = s[i];
    if(i%2==0)
      flag &= (c == 'R'||c=='U'||c=='D');
    if(i%2==1)
      flag &= (c == 'L'||c=='U'||c=='D');
  }
  cout << (flag ? "Yes" :"No") << endl;
}



Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    str_cnt = defaultdict(int)
    for _ in range(N):
        s = str(sorted(ST()))
        str_cnt[s]+=1
    ans = 0
    for cnt in str_cnt.values():
        ans += cnt*(cnt-1)//2
    print(ans)

if __name__ == '__main__':
    main()

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

int main(void){
    int count[26] = {0};
    char c;
    while(cin.get(c)){
        c = tolower(c);
        count[static_cast<int>(c - 'a')]++;
    }
    
    int i;
    for(i = 0; i < 26; i++){
        cout << static_cast<char>(i + 'a') << " : " << count[i] << endl;
    }
    
    return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);

  if (N % 2 == 1) {
    put(0);
    return 0;
  }

  ll count = N / 2;
  ll zero_count = 0;
  ll div = 5;
  while (div <= count) {
    zero_count += count / div;
    div *= 5;
  }
  put(zero_count);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for(int i=s;i<e;i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(),(a).end()
typedef long long LL;
const LL mod = 1000000007;
int cnta[4444][26],cntb[4444][26];
string st[4444][26];
string u="abcdefghijklmnopqrstuvwxyz";

int dp[505050];
int bt = 0;
int m = 0;
int main(){
    int n;
    cin >> n;
    REP(i, n){
        int x;
        cin >> x;
        if(bt == -1){
            puts("No");
            continue;
        }
        if(x > 500000){
            m = 505050;
            puts("Yes");
            continue;
        }
        if(x < bt) puts("No");
        else if(x == bt){
            if(m == x){
                puts("Yes");
                bt = -1;
            }else{
                puts("No");
            }
        }
        else{
            puts("Yes");
            dp[x]++;
            if(x > m) m = x;
            while(dp[x] == 2){
                dp[x] = 0;
                if(x == m) m--;
                dp[--x]++;
            }
            while(dp[bt+1]) bt++;
        }

    }

}



Measured memory_bytes: 5984
#![allow(non_snake_case)]

use proconio::input;
use proconio::marker::Usize1;
use proconio::fastout;
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        R: usize,
        C: usize,
        K: usize,
    }
    let mut a = vec![vec![0u64; C]; R];
    {
        input! {
            rcv: [(Usize1, Usize1, u64); K],
        }
        for (r, c, v) in rcv {
            a[r][c] = v;
        }
    };

    let mut dp = vec![vec![vec![0u64; 4]; C]; R];
    for i in 0..R {
        for j in 0..C {
            for k in 0..=3 {
                let mut tmp = if k > 0 { a[i][j] } else { 0 };
                if i > 0 {
                    if k > 0 {
                        tmp = max(tmp, dp[i - 1][j][3] + a[i][j]);
                    } else {
                        tmp = max(tmp, dp[i - 1][j][3]);
                    }
                }
                if j > 0 {
                    tmp = max(tmp, dp[i][j - 1][k]);
                    if k > 0 {
                        tmp = max(tmp, dp[i][j - 1][k - 1] + a[i][j]);
                    }
                }
                dp[i][j][k] = tmp;
            }
        }
    }
    println!("{}", dp[R - 1][C - 1][3]);
}


Measured memory_bytes: 708360
#include <iostream>

using namespace std;

int main(void){
	int n;cin>>n;
	for(int i=0;i<n;++i){
		int x,y,b,p,ans;
		cin>>x>>y>>b>>p;
		ans = x*b+y*p;
		int fare = (x*((b>5)?b:5)+y*((p>2)?p:2))*8/10;
		ans=min(fare,ans);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main()
{
	int X, Y;
	cin >> X >> Y;

	bool flag = false;
	for (int i = 0; i <= X; i++) {
		int a = i; 
		int b = X - i;
		if ((a * 2 + b * 4) == Y)
			flag = true;
	}

	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3636
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	x := nextInt()
	al := make([]int, n)

	for i := 0; i < n; i++ {
		al[i] = nextInt()
	}
	sort.Ints(al)

	cnt := 0
	for i := 0; i < n-1; i++ {
		if x >= al[i] {
			x -= al[i]
			cnt++
		}
	}
	if x == al[n-1] {
		cnt++
	}
	fmt.Println(cnt)

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger n = sc.nextBigInteger();
		sc.close();
		prtln(n.remainder(new BigInteger("9")).equals(new BigInteger("0")) ? "Yes" : "No");
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i, s.length())
  {
    if (s[i] == t[i])
      ans++;
  }
  pr(ans);
  return 0;
}


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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#define setmin_rv(x)		for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) (x)[i][j] = -1
#define setnul_rv(x)		for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) (x)[i][j] = 0
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 1e9 + 5;
const LL infll = 1e18+5;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 305;
const LL mod = 1e15+7;
const LL base = 29;
int n, dif[MAXN][MAXN];
LL chs[MAXN], rhs[MAXN][MAXN], kr[MAXN];
char val[MAXN+MAXN][MAXN];
bool valid[MAXN];


void precomp() {
	LL hsh;
	for (int i=0; i<n; i++) {
		hsh = 0LL;
		for (int j=n-1; j>=0; j--) {
			hsh = ((hsh*base) + ((LL)(val[i][j]-'a')+1))%mod;
			rhs[i][j] = hsh;
			// printf ("%lld ", rhs[i][j]);
		}
	}
	for (int j=0; j<n; j++) {
		hsh = 0LL;
		for (int i=n-1; i>=j; i--) 
			hsh = ((hsh*base) + ((LL)(val[i][j]-'a')+1))%mod;
		chs[j] = hsh;
	}
}

void shif () {
	for (int i=0; i<n; i++) 
		val[i][n] = val[i][0];
	for (int j=0; j<n; j++)
		for (int i=0; i<n; i++)
			val[i][j] = val[i][j+1];
}

int getans() {
	int ret = 0;
	// for (int i=0; i<n; i++, endln)
	// 	for (int j=0; j<n; j++)
	// 		printf ("%c", val[i][j]);
	precomp();
	for (int k=0; k<n; k++) {
		bool bs = 1;
		for (int j=0; j<n; j++) {
			// printf ("%lld ", chs[j]);
			if (chs[j] != rhs[(j-k+n)%n][j]) bs = 0;
		}
		// endln;
		// printf ("k = %d, bs = %d\n", k, bs);
		if (bs) ret++;
		for (int j=0; j<n; j++) {

			LL mn = (kr[j] * (val[n-1-k][j]-'a'+1))%mod;
			// printf ("mn = %lld\n", mn);
			chs[j] = (chs[j] - mn +mod)%mod;
			chs[j] = (chs[j] * base) + ((LL)(val[(j-k-1+n)%n][j]-'a')+1);
			chs[j] %= mod;
		}
	}
	return ret;
}

int solve () {
	int ret = 0;
	kr[n-1] = 1LL;
	for (int i=n-2; i>=0; i--) {
		kr[i] = (kr[i+1]*base)%mod;
		// printf ("%lld -", kr[i]);
	}
	// endln;

	for (int j=0; j<n; j++) {
		if (j) shif();
		ret += getans();
		// printf ("ret = %d\n", ret);
	}
	return ret;
}



int main() {
	gi(n);
	for (int i=0; i<n; i++) {
		scanf("%s", val[i]);
		for (int j=0; j<n; j++) 
			val[i+n][j] = val[i][j];
	}
	printf ("%d\n", solve());

	return 0;
}

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

int main() {
    string S;
    cin >> S;
    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < S.size(); i++)
    {
        int k = i;
        while(S[k] == 'A' || S[k] == 'C'|| S[k] == 'G' || S[k] == 'T')
            k++;
        ans = max(ans, k - i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int K, S, x, y, z, cnt = 0;

	cin >> K >> S;

	for (x = 0;x <= K;x++) {
		for (y = 0;y <= K;y++) {
			z = S - x - y;
			if (z >= 0 && z <= K)
				cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

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

int dp[ 1001 ];

int main( void ) {
	int i, j;
	int cs, maxW, n, v[ 1000 ], w[ 1000 ], maxV, minW;

	cs = 0;
	while( scanf( "%d %d", &maxW, &n ), maxW ) {
		for ( i = 0; i < n; i++ )
			scanf( "%d,%d", v + i, w + i );

		memset( dp, -1, sizeof dp );
		dp[ 0 ] = 0;

		for ( i = 0; i < n; i++ )
			for ( j = maxW - w[ i ]; j >= 0; j-- )
				if ( dp[ j ] != -1 )
					dp[ j + w[ i ] ] = dp[ j + w[ i ] ] > dp[ j ] + v[ i ] ? dp[ j + w[ i ] ] : dp[ j ] + v[ i ];

		maxV = -1;
		for ( i = 0; i <= maxW; i++ )
			if ( maxV < dp[ i ]) {
				maxV = dp[ i ];
				minW = i;
			}

		printf( "Case %d:\n%d\n%d\n", ++cs, maxV, minW );
	}

	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


string to_string(string s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(char ch) {
	return string("'")+ch+string("'");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <class InputIterator>
string to_string (InputIterator first, InputIterator last) {
	bool start = true;
	string res = "{";
	while (first!=last) {
		if (!start) {
			res += ", ";
		}
		start = false;
		res += to_string(*first);
		++first;
	}
	res += "}";
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x){
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x){
	for(auto& i:x)
		input>>i;
	return input;
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



const int mod=1e9+7;

int mul(int a,int b)
{
	return (a*1ll*b)%mod;
	}
	
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	}
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
		}
	return res;
	}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=2005;



void solve()
{  
int m,k;
cin>>m>>k;
if(m==1)
{
	if(k==0){cout<<"0 0 1 1";}
	else cout<<-1;
	}
else{
	if(k>=(1<<m)){cout<<-1;return;}
	cout<<k<<' ';
	for(int i=0;i<(1<<m);i++)if(i!=k)cout<<i<<' ';
	cout<<k<<' ';
	for(int i=(1<<m)-1;i>=0;i--)if(i!=k)cout<<i<<' ';
	
	}	
	}
	
   
	
	

int main()
{   
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//cin>>tc;
    while(tc--)
	{
        solve();
		}
	
	}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int cnt = 0;
        for (int i = 1 ; i <= n; i ++) {
            for (int j = 1; j <= n; j++) {
                if ((i % 2 == 0 && j % 2 != 0) || (j % 2 == 0 && i % 2 != 0)) {
                    cnt++;
                }
            }
        }
        System.out.println(cnt / 2);
    }
}

Measured memory_bytes: 24020
N,M=map(int,input().split())
A = list(map(int, input().split()))
B = [0]
s = 0
for nums in A:
  s += nums
  B.append(s%M)
C = {}
for nums in B:
  if nums in C.keys():
    C[nums] += 1
  else:
    C[nums] = 1
ans = 0
for keys in C:
  x = C[keys]
  ans += x*(x-1)//2
    
print(ans)


Measured memory_bytes: 16172
#include <iostream>
#include <algorithm>
using namespace std;
int main (){
	int a[2];
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a,a+3);
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
	return 0;
}
	

Measured memory_bytes: 1180
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <map>
#include <complex>
#include <ctime>
#include <numeric>
#include <set>

using namespace std;

typedef long long ll;

typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;

const ll N = 5e5 + 10;
int occs[(int)1e6 + 5], tree[4 * N], n, ans[N];

void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}

int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
#endif
    
    int q, s, e;
    vector<node> v;
    scanf("%d", &n);
    scanf("%d", &q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &s);
        v.push_back(node(i, i, s, -1));
    }
    for(int i = 0; i < q; i++){
        scanf("%d %d", &s, &e);
        v.push_back(node(s, e, 0, i));
    }
    
    sort(v.begin(), v.end());
    
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
    
    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 25360
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        double ans=0;
        double n2=1;
        double count=1;
        while(n*n2<m){
            n2*=2;
            count/=2;
        }
        ans+=count;
        for(int i=n-1;i>0;i--){
            while((n2)*i<m){count/=2;
                n2*=2;
            }
            ans+=count;
        }
        System.out.println(ans/n);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
typedef vector<vecll>     vec2ll;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
void init(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main()
{
  init();
  int n, x;
  cin >> n >> x;
  vecint w(n,0), v(n,0); REP(i,n){cin >> w[i] >> v[i];}
  vec2ll dp(n + 1, vecll(x + 1,0));
  REP(i,n){
    REP(j, x + 1){
      if(j - w[i] >= 0){
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }else{
        dp[i + 1][j] = dp[i][j];
      }
    }
  }
  // REP(i,n + 1){
  //   cout << dp[i][x] << endl;
  // }
  cout <<dp[n][x] << endl;
}


Measured memory_bytes: 80372
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int N, vector<string> W) {
  map<string, bool> m;
  m[W[0]] = true;
  for (int i = 0; i < N - 1; i++) {
    char &a = W[i].back();
    char &b = W[i + 1].front();
    if (a == b && (m.find(W[i + 1]) == m.end())) {
      m[W[i + 1]] = true;
      continue;
    } else {
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
}

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

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int S, h, m, s;

	scanf("%d", &S);

	h = S / (60 * 60);
	s = S % (60*60);
	m = s / 60;
	s = s % 60;
	S = s;

	printf("%d:%d:%d\n",h,m,S);

	return 0;

}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin>>x;
    x %= 10;
    if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9){
        puts("hon");
    }
    else if(x == 3)puts("bon");
    else puts("pon");
    return 0;
}


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

template <typename T>
struct BIT {
    int n;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int n_) { init(n_); }
    void init(int n_) {
        n = n_ + 1;
        for (int p = 0; p < 2; p++) bit[p].assign(n, 0);
    }
 
    void add_sub(int p, int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[p][idx] += x;
        }
    }
    void add(int l, int r, T x) {  // [l,r) に加算
        add_sub(0, l, -x * (l - 1));
        add_sub(0, r, x * (r - 1));
        add_sub(1, l, x);
        add_sub(1, r, -x);
    }
 
    T sum_sub(int p, int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[p][idx];
        }
        return s;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
};

const ll MAXN = 200000;
const ll INF = 1001001001;

signed main(){
    ll N, K, ans=0, tmp=0;
    cin >> N >> K;
    vector<ll> A(N,0);
    for(int i=0;i<N;i++) {
        cin >> A[i];
    }
    for(int i=0;i<min(K,50LL);i++) {
        BIT<ll> bit(200001);
        //cout << "aioueaonvaoe" << endl;
        for(int i1=0;i1<N;i1++) {
            bit.add(max(i1+1-A[i1], 1LL), 1+min(i1+1+A[i1], N), 1);
        }
        /*
        for(int i2=0;i2<N+1;i2++) {
            cout << bit.sum(i2) << endl;
        }
        */

        for(int i2=0;i2<N;i2++) {
            A[i2] = bit.sum(i2+1)-bit.sum(i2);
            if(i==min(K,50LL)-1) {
                if(i2) cout << " ";
                cout << A[i2];
            }
        }
    }
    /*
    for(int i=0;i<N;i++) {
        if(i) cout << " ";
        else cout << A[i];
    }
    */
    
    return 0;
}


Measured memory_bytes: 7996
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int L;

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

    cin>>L;
    int K = 31-__builtin_clz(L);
    vector<tuple<int,int,int>> ed;
    for (int i=1;i<=K;i++) {
      ed.pb({i,i+1,1<<(K-i)});
      ed.pb({i,i+1,0});
    }
    int prv=-1;
    int cur = 0;
    for (int i=K;i>=0;i--) {
      if(!(L&(1<<i))) continue;
      if (prv != -1)
        ed.pb({1, K-i+1, cur});
      prv = i;
      cur += 1<<prv;
    }

    cout << K+1 << ' ' << ed.size() << '\n';
    for (auto& [a,b,c] : ed)
      cout << a << ' ' << b << ' ' << c << '\n';
    return 0;
}


Measured memory_bytes: 3632
/* This Template is property of Pranav Khiste aka desmond_kaneki*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fit(a,b) for(auto it=a;it!=b;it++)
#define vll vector<ll>
#define pb push_back
#define qll queue<ll>
#define p push
#define mp make_pair
#define fst first
#define snd second
#define pll pair<ll,ll>
#define vpll vector<pll>
#define debug(x) cout<<#x<<' '<<x<<endl;
#define endl '\n'
#define SUP LLONG_MAX
#define INF -1000000000000
#define MAX_N 100005
#define test() ll var;  cin>>var; while(var--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fileio freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);  // use cin cout only!!
main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val w = inputs.head

  println(solve(w))

  def solve(w: String): String = {
    val charMap = scala.collection.mutable.HashMap.empty[Char, Boolean]
    w.toSeq.foreach { c =>
      if (charMap.contains(c)) {
        charMap.update(c, !charMap(c))
      } else {
        charMap.update(c, false)
      }
    }

    val resultSet = charMap.values.toSet
    if (resultSet.size == 1 && resultSet.head) {
      "Yes"
    } else {
      "No"
    }
  }
}

Measured memory_bytes: 27332