akhauriyash/Code-Regression huggingface dataset:
def BubbleSort(C, N):
    for i in range(N-1):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]
    return C

def SelectionSort(C, N):
    for i in range(N):
        min_j = i
        for j in range(i+1, N):
            if int(C[j][1]) < int(C[min_j][1]):
                min_j = j
        C[i], C[min_j] = C[min_j], C[i] 
    return C

def isStable(in_list, out_list):
    N = len(in_list)
    for i_in in range(N):
        for j_in in range(i_in+1, N):
            for i_out in range(N):
                for j_out in range(i_out+1, N):
                    if (in_list[i_in][1] == in_list[j_in][1]) and\
                       (in_list[i_in] == out_list[j_out]) and\
                       (in_list[j_in] == out_list[i_out]):
                        return False
    return True

if __name__ == "__main__":
    N = int(input())
    C = list(map(str, input().split()))
    C1 = C.copy()
    C2 = C.copy()
    Bubble_C = BubbleSort(C1, N)
    Selection_C = SelectionSort(C2, N)

    print(*Bubble_C)
    print('Stable')
    print(*Selection_C)
    if Bubble_C == Selection_C:
        print('Stable')
    else:
        print('Not stable')


Measured memory_bytes: 5608
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int m = sc.nextInt();
      
		List<String[]> arrList = new ArrayList<>(); 
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
          	if("".equals(s)){
              continue;
            }
			arrList.add(s.split(" "));
		}
		sc.close();

		Map<Integer, Integer> ansMap = new HashMap<>();
		for(int j=1; j<=m; j++) {
			ansMap.put(Integer.valueOf(j), Integer.valueOf(0));
		}
		for(String[] strArr : arrList) {
			makeMap(ansMap, strArr);
		}
		
		int ans = 0;
		for(Map.Entry<Integer, Integer> entry : ansMap.entrySet()) {
			if (entry.getValue() == n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	
	private static void makeMap(Map<Integer, Integer> ansMap, String[] arr) {
		int size = Integer.parseInt(arr[0]);
		for(int i=1; i<=size; i++) {
			Integer key = Integer.parseInt(arr[i]);
			int a = ansMap.get(key).intValue();
			ansMap.put(key, Integer.valueOf(a+1));
		}
	}
}


Measured memory_bytes: 23252
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
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
from copy import deepcopy
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', '')

#edgeは1次元ですべて(始点,終点,重み)を格納
def bellmanford(edge,N):
    costs = [inf] * N
    costs[0] = 0
    exist_minus_cycle = False
    for i in range(N):
        update = False
        for from_, to, cost in edge:
            cost_to = costs[from_] + cost
            if cost_to < costs[to]:
                update = True
                costs[to] = cost_to
                
        if not update:
            break
        elif i==N-1:
            exist_minus_cycle = True

    #どこで無限に更新されるか判定
    minus_cycle = set()
    if exist_minus_cycle:
        for i in range(N+1):
            for from_, to, cost in edge:
                cost_to = costs[from_] + cost
                if from_ in minus_cycle:
                    minus_cycle.add(to)
                if cost_to < costs[to]:
                    minus_cycle.add(from_)
                    minus_cycle.add(to)
                    costs[to] = cost_to
    return costs, minus_cycle


def main():
    N,M,P = MI()
    edges = []
    for _ in range(M):
        A,B,C = MI_()
        cost = P - (C+1)
        edges.append((A,B,cost))

    
    costs,minus_cycle = bellmanford(edges,N)

    if N-1 in minus_cycle :
        print(-1)
    else:
        print(max(0,-costs[-1]))



if __name__ == '__main__':
    main()


Measured memory_bytes: 46124
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void fastios() { ios_base::sync_with_stdio(0); cin.tie(0); }

static const int N = 10005;
vi p(N, -1);
vi d(N, 1);

void unite(int x, int y) {
	while (p[x] != -1) {
		x = p[x];
	}
	while (p[y] != -1) {
		y = p[y];
	}
	if (x == y) return;
	if (d[x] > d[y]) p[y] = x;
	else if (d[x] < d[y]) p[x] = y;
	else {
		p[y] = x;
		d[x]++;
	}
}

bool same(int x, int y) {
	while (p[x] != -1) {
		x = p[x];
	}
	while (p[y] != -1) {
		y = p[y];
	}
	if (x == y) return 1;
	else return 0;
}

int main() {
	int n, q;
	cin >> n >> q;
	Loop(i, q) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) unite(x, y);
		else cout << same(x, y) << endl;
	}
	return 0;
}

Measured memory_bytes: 3176
s = input()
t = input()

ls = len(s)
lt = len(t)
ans = ""
dp = [[0]*(lt+1) for i in range(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

x = lt
y = ls

while x-1>=0 and y-1>=0:
    if dp[y][x] == dp[y][x-1]:
        x -= 1
    elif dp[y][x] == dp[y-1][x]:
        y -= 1
    else:
        ans = s[y-1] + ans
        x -= 1
        y -= 1

print(ans)

Measured memory_bytes: 112220
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
int n,a[200005], b[200005];
int cur = 1, tr[200005], dc[200005];
int c = 100000;
pair<int,int> store[200005];
int f(int u){
	return (a[u] == u ? u : a[u] = f(a[u]));
}
int m(int u,int v){
	u = f(u); v= f(v);
	a[v] = u;
}
signed main(){
	cin >> n;
	for(int i = 1 ; i <= 200004 ; i ++) a[i] = i;
	for(int i = 1 ; i <= n ; i ++){
		int x, y;
		cin >> x >> y;
		b[x] = 1; b[c + y] = 1;
		m(x, c + y);
	}
	int ans = 0;
	for(int i = 1 ; i <= 200004 ; i ++){
		if(b[i]){
			if(!dc[f(i)]){
				dc[f(i)] = 1;
				tr[f(i)] = cur;
				cur ++;
			}
			if(i <= c) store[tr[f(i)]].fi ++;
			else store[tr[f(i)]].se ++;
		}
	}
	for(int i = 1 ; i < cur ; i ++)
		ans += store[i].fi * store[i].se;
	cout << ans - n;
}


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

m = -10
s = 0
for d in A:
    s+=B[d-1]
    if d == m + 1:
        s+=C[m-1]
    m = d
print(s)


Measured memory_bytes: 3060
/**
 * author: apikdech
 * created: 19:06:43 08-03-2020
 * last modified: 19:09:30 08-03-2020
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007, N = 1e5 + 5;

int a[N], b[N], ma = MOD, mb = MOD, ans = MOD;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int A, B, M;
  cin >> A >> B >> M;
  for (int i = 0; i < A; i++) {
    cin >> a[i];
    ma = min(ma, a[i]);
  }
  for (int i = 0; i < B; i++) {
    cin >> b[i];
    mb = min(mb, b[i]);
  }
  ans = min(ans, ma + mb);
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--, y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << "\n";
  // cerr << "time = " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << " ms\n";
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
 
struct Card {
    char suit,
    value;
};
 
void bubble(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j >= i + 1; j--) {
            if (A[j].value < A[j - 1].value) {
                Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
            }
        }
    }
}
 
void selection(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j].value < A[minj].value) {
                minj = j;
            }
        }
        Card t = A[i]; A[i] = A[minj]; A[minj] = t;
    }
}
 
void print(struct Card A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}
 
bool isStable(struct Card C1[], struct Card C2[], int N) {
    for (int i = 0; i < N; i++) {
        if (C1[i].suit != C2[i].suit) {
            return false;
        }
    }
    return true;
}
 
int main() {
    Card C1[100], C2[100];
    int N;
     
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> C1[i].suit >> C1[i].value;
    }
     
    for (int i = 0; i < N; i++) {
        C2[i] = C1[i];
    }
     
    bubble(C1, N);
    selection(C2, N);
     
    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if (isStable(C1, C2, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
     
    return 0;
}


Measured memory_bytes: 3140
Sum, Ave, Cou = 0, 0, 0
while True :
    try :
        a, b = input().split(',')
        Sum += int(a) * int(b)
        Ave += int(b)
        Cou += 1
    except : break
print(Sum)
if Ave / Cou - Ave // Cou >= 0.5 : print(Ave // Cou+1)
else : print(Ave//Cou)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
  ios_base::sync_with_stdio (false);
  cin.tie(NULL);

  ll N;

  cin >> N;

  vl a(N, 0);

  FOR(i, 0, N) cin >> a[i];

  vector<vector<pll> > dp(N+1, vector<pll>(N+1, mp(0, oo)));


  FOR(i, 0, N){
    dp[i][i].xx = a[i];
    dp[i][i].yy = 0;
  }
  FOR(i, 0, N-1){
    dp[i][i+1].xx = a[i]+a[i+1];
    dp[i][i+1].yy = a[i]+a[i+1];
  }

  FOR(l, 2, N)FOR(p, 0, N-l){
    ll i = p;
    ll j = p+l;

    FOR(k, 0, j-i){
      if((dp[i][i+k].yy+dp[i+k+1][j].yy)+(dp[i][i+k].xx+dp[i+k+1][j].xx) < dp[i][j].yy){
        dp[i][j].xx = dp[i][i+k].xx+dp[i+k+1][j].xx;
        dp[i][j].yy = dp[i][i+k].yy+dp[i+k+1][j].yy+dp[i][i+k].xx+dp[i+k+1][j].xx;
      }
    }
  }

  /*
  cout << '\n';

  FOR(i, 0, N){
    FOR(j, 0, N){
      if(dp[i][j].yy == oo){
        cout << "#  ";
      }
      else{
        cout << dp[i][j].yy <<' ';
      }

    }
      cout << '\n';
  }

  */
  cout << dp[0][N-1].yy << endl;



}


Measured memory_bytes: 2816
n = int(input())
if n == 0:
    print(0)
    exit
ans = ''
ans_n = 0

for i in range(1, 100):
    if n == ans_n:
        print(ans[::-1])
        exit()
    if (n - ans_n) % (2 ** i) == 0:
        ans += '0'
    else:
        ans += '1'
        ans_n += (-2) ** (i - 1)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import math

N, P = map(int, input().split())
ans = 1
target = 2
sum = {}

if N == 1:
    ans = P
else:
	while True:
	    if P % target == 0:
	        if target in sum:
	            sum[target] += 1
	        else:
	            sum[target] = 1
	        P /= target
	        target = 2
	    else:
	        target += 1
	    if math.sqrt(P) < target:
	        P = int(P)
	        if P in sum:
	            sum[P] += 1
	        else:
	            sum[P] = 1
	        break
	for fact in sum:
	    # print("{} {}".format(fact, sum[fact]))
	    while sum[fact] >= N:
	        sum[fact] -= N
	        ans *= fact

print("{}".format(ans))


Measured memory_bytes: 3064
#include <stdio.h>

int main() {
	long int Zx = 0, Xy = 0, Yz = 0, xyz = 0, count;
	scanf("%ld", &count);
	for (int u = 0; u < count; u++) {
		char kata[5];
		scanf("%s", &kata);
		switch (kata[0]) {
			case 'A':
				Zx++;
				break;
			case 'W':
				Xy++;
				break;
			case 'T':
				Yz++;
				break;
			case 'R':
				xyz++;
				break;		
		}	
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", Zx, Xy, Yz, xyz);
	return 0;
}

Measured memory_bytes: 1732
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max<T>(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min<T>(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

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

	int n = s.size();
	set<string> st;
	REP(i, n) {
		REP(j, min(5, n - i)) { st.insert(s.substr(i, j + 1)); }
	}
	auto ittr = st.begin();
	REP(i, k - 1) { ittr++; }
	string result = *ittr;

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 4812
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000000;

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

  int length = s.length();

  int max = 0;
  REP(i,length){
    int streak = 0;
    for (int j = i; j < length; j++) {
      char tmp = s[j];
      if (tmp != 'A'&&tmp != 'T'&&tmp != 'G'&&tmp != 'C') {
        break;
      }
      streak++;
    }
    if (streak > max) {
      max = streak;
    }
  }
  cout << max << endl;
  return 0;
}

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

#define PQ priority_queue
#define P pair<int,int>
#define CLA(array) memset(array,0,sizeof array)
#define CLINF(array) memset(array,0x3f,sizeof array)
#define CLF(array) memset(array,-1,sizeof array)
#define DB(a) cout << "DEBUG " << a << endl;
#define lowbit(x) (x)&(-x)
#define fi first
#define se second
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100000 + 10;
const int INF = 0x3f3f3f3f;

int a[MAXN];
int main(){
    //ios_base::sync_with_stdio(false);
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		
	}
	sort(a, a+n);
	LL x = 0, y = 0;
	for(int i = n-1; i >= 1; i--){
		if(a[i] == a[i-1]){
			if(x) y = (LL)a[i];
			else x = (LL)a[i];
			i --;
		}
		if(x && y) break;
	}
	// cout << x << " " << y << endl;
	LL sum = (x*y);
	printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 640
#ifdef __GNUC__
#include <bits/stdc++.h>
#else
#include "bits/stdc++.h"
#define scanf scanf_s
#endif
#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define WHL(i) while(i)
#define putn printf("\n")
#define all(container) container.begin(), container.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


//template<class T> istream& operator >> (istream &is, vector<T> &vec) {
//	for (T &x : vec)is >> x;
//	return is;
//}

int num, cent, A[2 * 100000 + 10];

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

	cin >> num;

	REP (i, num) {
		cin >> A[i];
		A[i] -= i + 1;
	}

	sort (A, A + num);
	cent = A[num / 2];

	ll M;
	REP (i, num) {
		M += abs (cent - A[i]);
	}
	cout << M << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

constexpr int kMaxN = 500000 + 100;
char S[kMaxN];

set<int> app[26];

int main() {
  int N;
  scanf("%d", &N);
  scanf("%s", S);
  for (int i = 0; i < N; i++) {
    app[S[i] - 'a'].insert(i);
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int i;
      char c;
      scanf("%d %c", &i, &c);
      i--;
      if (S[i] == c)
        continue;
      app[S[i] - 'a'].erase(i);
      app[c - 'a'].insert(i);
      S[i] = c;
    } else if (t == 2) {
      int l, r;
      scanf("%d%d", &l, &r);
      l--, r--;
      int ans = 0;
      for (int i = 0; i < 26; i++) {
        auto p = app[i].lower_bound(l);
        if (p != end(app[i]) && *p <= r)
          ans++;
      }
      cout << ans << endl;
    } else {
      assert(false);
    }
  }
  return 0;
}


Measured memory_bytes: 24320
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 2000;

using ll = long long;

ll N, x;
ll a[MAX_N], f[MAX_N];

int main()
{
  scanf( "%lld%lld", &N, &x );
  rep( i, N )
    scanf( "%lld", a+i ), f[i] = a[i];

  ll ans = 1e13;

  rep( k, N )
  {
    ll sum = k*x;
    rep( i, N )
    {
      f[i] = std::min( f[i], a[(i-k+N)%N] );
      sum += f[i];
    }

    ans = std::min( ans, sum );
  }

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

  return 0;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  bool flag = false;
  if(A > B && A > C && B < C)
    flag = true;
  else if(A < B && B > C && A < C)
    flag = true;
  
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main(){
    long long a,b,k;cin>>a>>b>>k;
    if(a>=k) cout<<a-k<<" "<<b;
    else if(a<k&&a+b>k) cout<<0<<" "<<b-(k-a)<<endl;
    else cout<<0<<" "<<0<<endl;
}

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

int main(){
  int n;
  cin >> n;
  
  vector<ll> a,b;
  
  for(int i=0; i<n; i++){
    ll x,y;
    cin >> x >> y;
    
    a.push_back(x);
    b.push_back(y);
  }
  
  ll ans(0);
  
  for(int i=n-1; i>=0; i--){
    ans += ((ans+a[i]) % b[i] != 0) * (b[i] - ((ans + a[i]) % b[i]));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 2036
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	cards := map[string]*[13]bool{
		"S": &[13]bool{},
		"H": &[13]bool{},
		"C": &[13]bool{},
		"D": &[13]bool{},
	}
	i := 0
	for sc.Scan() {
		if i != 0 {
			card := strings.Split(sc.Text(), " ")
			num, _ := strconv.Atoi(card[1])
			cards[card[0]][num-1] = true
		}
		i++
	}

	printCards("S", cards["S"])
	printCards("H", cards["H"])
	printCards("C", cards["C"])
	printCards("D", cards["D"])
}

func printCards(suit string, cards *[13]bool) {
	for i, v := range cards {
		if !v {
			fmt.Printf("%s %d\n", suit, i+1)
		}
	}
}



Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
bool ling(string a,string aa)
{
	for(int i=0;i<a.size();i++)
	{
		if(a[i]!='?' && a[i]!=aa[i])
		return false;
	}
	return true;
}
int main()
{
	string s,t,b="~";
	cin>>s>>t;
	for(int i=0;i<=(int)s.size()-(int)t.size();i++)
	{
		string z=s.substr(i,t.size());
		if(ling(z,t)){
			string w=s;
			for(int j=i;j<i+t.size();j++)
			{
				w[j]=t[j-i];
			}
			for(int j=0;j<i;j++)
			{
				if(w[j]=='?')
				w[j]='a';
			}
			for(int j=i+t.size();j<w.size();j++)
			{
				if(w[j]=='?')
				w[j]='a';
			}
			b=min(b,w);
		}
	}
	if(b=="~")
	cout<<"UNRESTORABLE\n";
	else
	cout<<b<<endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

vector<int> ver;
void dfs(const graph &g,int v){
  ver[v]=1;
  for(auto i:g[v]){
    if(ver[i]!=1)continue;
    dfs(g,i);
  }
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}


int main(){
  int i,j,cnt=0;
  ll n,k;
  cin>>n>>k;
  ll a[n],f[n];
  for(i=0;i<n;i++)cin>>a[i];
  for(i=0;i<n;i++)cin>>f[i];
  ll sum=0;
  for(i=0;i<n;i++)sum+=a[i];
  if(sum<=k){
    cout<<0<<endl;
    return 0;
  }
  ll left=0,right=1e12;
  sort(a,a+n);
  sort(f,f+n,greater<ll>());
  while(abs1(right-left)>1){
    ll mid=left+(right-left)/2;
    sum=0;
    for(i=0;i<n;i++){
      sum+=max((ll)0,a[i]-mid/f[i]);
    }
    if(sum<=k)right=mid;
    else left=mid;
  }
  cout<<right<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
using namespace std;

const double PI=acos(-1);

int main(){
    int a, b, c, sum = 0;
    cin >> a >> b >> c;
    while(a%2 == 0 && b%2 == 0 && c%2 == 0){
        if(a == b && b == c){
            sum = -1;
            break;
        }
        int aa = a/2, bb = b/2, cc = c/2;
        a = bb+cc;
        b = aa+cc;
        c = aa+bb;
        sum++;
    }

    cout << sum << endl;
    return 0;
}

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

template<class S, class T>
void dfs(unsigned long now, unsigned long prev, unsigned long& time, const S& edge, T& ord, T& low){
    low[now] = ord[now] = ++time;
    for(const auto& i : edge[now])if(i != prev){
        if(ord[i] > time)dfs(i, now, time, edge, ord, low);
        low[now] = min(low[now], low[i]);
    }
}

int main(){
    size_t N, M;
    cin >> N >> M;
    vector<vector<size_t>> edge(N);
    vector<pair<size_t, size_t>> edg(M);
    for(auto& i : edg){
        cin >> i.first >> i.second;
        edge[--i.first].push_back(--i.second);
        edge[i.second].push_back(i.first);
    }
    vector<size_t> ord(N, numeric_limits<size_t>::max()), low(N, numeric_limits<size_t>::max());
    size_t time{0};
    dfs(0, 0, time, edge, ord, low);
    size_t ans{0};
    for(const auto& i : edg)if(ord[i.first] < low[i.second] || ord[i.second] < low[i.first])++ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	
	string a, b;
	cin >> a >> b;
	if ((a[0] == 'D' && b[0] == 'H') || (a[0] == 'H' && b[0] == 'D')) {
		cout << 'D';
	}
	else cout << 'H';
}

Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int c = 0;
	int a = 0;
	REP(i, n) {
		if(s[i] == '(') {
			c++;
		} else {
			if(c == 0) {
				a++;
			} else {
				c--;
			}
		}
	}

	cout << string(a, '(') << s << string(c, ')') << endl;

	return 0;
}


Measured memory_bytes: 3640
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	ar := make([]int, len(s))
	br := make([]int, len(s))
	for i := 0; i < len(s); i++ {
		t := i
		c := 0
		if i >= 2 {
			if s[i] == s[i-1] && s[i-1] == s[i-2] {
				ar[br[i-2]]++
				br[i] = br[i-2]
				continue
			}
		}
		for {
			if s[t] == 'L' {
				t--
			} else {
				t++
			}
			c++
			if s[i] != s[t] {
				if c%2 == 0 {
					ar[t]++
					br[i] = t
					break
				} else {
					if s[t] == 'L' {
						ar[t-1]++
						br[i] = t - 1
						break
					}
					ar[t+1]++
					br[i] = t + 1
					break
				}
			}
		}
	}
	for i, v := range ar {
		if i == len(s)-1 {
			fmt.Println(v)
		} else {
			fmt.Printf("%d ", v)
		}
	}
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0 ,n){
        cin >> a[i];
        a[i] --;
    }
    int ans = 0;
    rep(i, 0, n){
        if(i == a[a[i]]) ans++;
    }
    o(ans / 2);
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::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 == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, 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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll r, d, x;
	cin >> r >> d >> x;
	REP(i, 10) {
		x = x * r - d;
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static ArrayList<Integer> ps;
	static int[] cnt = new int[50001];

	static boolean solve() {
		int n = in.nextInt();
		if (n == 0) return false;

		out.println(cnt[n]);

		return true;
	}

	static ArrayList<Integer> createPrimeList(int n) {
		if (n < 2) return null;
		ArrayList<Integer> res = new ArrayList<Integer>();
		BitSet isPrimeBit = createIsPrimeBit(n);
		int p = 1;
		while ((p = isPrimeBit.nextSetBit(p+1)) >= 0) {
			res.add(p);
		}
		return res;
	}

	static BitSet createIsPrimeBit(int n) {
		if (n < 2) return null;
		BitSet res = new BitSet();
		res.set(2,n,true);
		for (int i=2; i*i<n; i=res.nextSetBit(i+1)) {
			for (int j=i+i; j<n; j+=i) res.set(j,false);
		}
		return res;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		ps = createPrimeList(50000);

		for (int px : ps) {
			for (int py : ps) {
				if (px > py) continue;
				if (px + py <= 50000) cnt[px+py]++;
			}
		}

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 42156
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<queue>

using namespace std;

#define INF 1000000007

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  int cnt = 0;
  for(int i = 0; i < n; i++){
    cin >> h[i];
    if(h[i] >= k) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
int binary_search(vector<int> v,int n){//sorted v, count v=n
	if(v.size()==0) return 0;
	if(v[0]>n)return 0;
	if(v[v.size()-1]<n)return 0;
	int l,r,mid,max,min;
	l=0;
	r=v.size();
	if(v[v.size()-1]==n){
		max=v.size()-1;
	}else{
		while(r-l>1){
			mid=(l+r)/2;
			if(v[mid]<=n){//v[l]<=n<v[r]
				l=mid;
			}else{
				r=mid;
			}
		}
		max = l;//max means v[all]<=n. all<=max
	}
	l=0;
	r=v.size();
	if(v[0]==n){
		min=0;
	}else{
		while(r-l>1){
			mid=(l+r)/2;
			if(n<=v[mid]){//v[l]<n<=v[r]
				r=mid;
			}else{
				l=mid;
			}
		}
	min = r;//min means v[all]<=n. all>=min
	}
	//cout<<max<<" "<<min<<endl;
	return max-min+1;
}


int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	long long int cnt = 0;
	vector<int>v;
	rep(i,n){
		//count v==i-a[i]
		cnt += upper_bound(v.begin(),v.end(),i-a[i])-lower_bound(v.begin(),v.end(),i-a[i]);
		//sorted_insert i+a[i]
		v.insert(std::lower_bound(v.begin(), v.end(), i+a[i]), i+a[i]);
		//binary_insert(v,i+a[i]);
		//rep(i,v.size())cout<<v[i]<<" ";
		//cout<<endl;


	}
	cout<<cnt<<endl;
	/*
	int k;
	cin>>k;
	binary_insert(a,k);
	rep(i,a.size())cout<<a[i]<<" ";
	cout<<endl;
	*/

	return 0;
}


Measured memory_bytes: 5044
#include<stdio.h>
long long p[1000],q[1000];
main()
{
	long long n,h,w,i,j,s=0,a,b;
	scanf("%lld %lld %lld",&n,&h,&w);
	for(i=0;i<n;i++)
	{
		scanf("%lld %lld",&p[i],&q[i]);
		a=p[i]/h;
		b=q[i]/w;
		if(a>b) s=s+b;
		else s=s+a;
	}
	printf("%lld",s);
}

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

int main(void){
  int n, k, ans=0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(),p.end());
  rep(i,k) ans += p[i];
  cout << ans << endl;
  return 0;
}


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

using R=long double;
const R EPS=1e-9L;
using P=complex<R>;
using VP=vector<P>;
using L=struct{P s,t;};
using C=struct{P c;R r;};

auto& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}

VP cross(C c, L l){
	P h=proj(l,c.c),e=polar(sqrt(norm(c.r)-norm(h-c.c)),arg(l.t-l.s));
	return VP{h-e,h+e};
}

VP cross(C a,C b){
	P d=b.c-a.c,w=(norm(d)+norm(a.r)-norm(b.r))/(2.0L*norm(d))*d;
	return cross(a,{a.c+w,a.c+w+1il*w});
}

int main(void){
	C c1,c2;
	cin >> c1.c >> c1.r >> c2.c >> c2.r;
		
	VP res=cross(c1,c2);
	if(real(res[0])-real(res[1])>0) swap(res[0],res[1]);
	if(abs(real(res[0])-real(res[1]))<EPS and (imag(res[0])-imag(res[1])>0)) swap(res[0],res[1]);
	cout.precision(20);
	cout << fixed << res[0] << " " << res[1] << endl;
	return 0;
}

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

int main() {
   int N,max;
   int count = 1;
   int judge = 0;
   cin >> N;
   vector<int> H(N);
   for(int i=0;i<N;i++){
       cin >> H.at(i);
   }

    for(int i=1;i<N;i++){
       for(int j=0;j<i;j++){
           if(H.at(i)<H.at(j)){
               judge++;
           }
        }
        if(judge == 0)
            count+=1;
        
        else
        {
            judge = 0;
        }
    }  
    cout << count << endl;

    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int H,W;
int Move[4][2]={0,1,0,-1,-1,0,1,0};
const int SIZE=200;
struct node{
	int x,y;//第x行第y列 
	int step;
};
char board[SIZE][SIZE];
bool vis[SIZE][SIZE];
queue<node>q;
int bfs()
{
	node s;
	node n;
	node t;
	s.x=1;
	s.y=1;
	s.step=0;
	q.push(s);
	vis[1][1]=1;
	while(q.size())
	     {
	     	t=q.front();
	     	q.pop();
	     	if(t.x==H&&t.y==W)
	     	return t.step;
	        for(int i=0;i<4;++i)
	        {
	        	n=t;
	        	n.x+=Move[i][0];
	        	n.y+=Move[i][1];
				
	        	n.step=t.step+1;
	        	if(n.x>=1&&n.x<=H&&n.y>=1&&n.y<=W&&!vis[n.x][n.y]&&board[n.x][n.y]!='#')
	        	     {  
	        	       
	        	     	q.push(n); vis[n.x][n.y]=1;
					 }
			}
	         
		 }
		 return -1;
	
}
int main()
{
	cin>>H>>W;
	memset(board,0,sizeof(board));
	memset(vis,0,sizeof(vis));
	int i,j,black=0;
	for(i=1;i<=H;++i)
	for(j=1;j<=W;++j)
	{
		cin>>board[i][j];
		if(board[i][j]=='#')
		{
			black++;
		
		}
	}


	int sum=bfs();
	if(sum==-1)cout<<sum<<endl;
	else cout<<H*W-black-sum-1<<endl;
}

Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

fn main() {
    let mut vec: Vec<usize> = vec![0; 4];
    for _ in 0..3 {
        let a: usize = read();
        let b: usize = read();
        vec[a-1] += 1;
        vec[b-1] += 1;
    }
    let mut ok = true;
    for i in 0..4 {
        if vec[i] != 1 && vec[i] != 2 {
            ok = false;
        }
    }
    println!("{}", if ok {"YES"} else {"NO"});
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<char> slimes(n);
	for(int i=0;i<n;i++)
	{
		cin>>slimes[i];
	}
	int cnt1 = 0;
	for (int i=0;i<n-1;i++)
	{
		if (slimes[i] != slimes[i+1])
			cnt1++;
	}
	cout<<cnt1 + 1<<endl;
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)

	voting := scanIntSlice(n)

	sum := 0
	for i := 0; i < n; i++ {
		sum += voting[i]
	}

	sort.Sort(sort.Reverse(sort.IntSlice(voting)))
	if float64(voting[m-1]) >= float64(sum)/float64((4*m)) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

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

int ans = 0;
int n;
int m;
int k[10];
int s[10][10];
int p[10];

void func(int a, int flag[]){
    
    if (a == n) {
        int num = 0;
        rep(i, m){
            int count = 0;
            rep(j, k[i]){
                if (flag[s[i][j]-1] == 1) {
                    count++;
                }
            }
            if (count % 2 == p[i]) {
                num++;
            }
        }
        if (num == m) {
            ans++;
        }
        // rep(i, n) cout << flag[i] << " ";
        // cout << endl;
        return;
    }
    // rep(i, n) cout << flag[i] << " ";
    // cout << endl;
    int flag1[n];
    rep(i, n) flag1[i] = flag[i];
    flag1[a] = 0;
    func(a + 1, flag1);
    flag1[a] = 1;
    func(a + 1, flag1);
    return;
}

int main(){
    cin >> n >> m;
    rep(i, m) {
        cin >> k[i];
        rep(j, k[i]) cin >> s[i][j];
    }
    rep(i, m) cin >> p[i];
    int b[n];
    func(0, b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



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

	ll k;
	cin >> k;

	if (k % 2 == 0)
	{
		cout << -1 << endl;
        return 0;
	}
	ll keta = 1;
	ll num = 7;
	for (ll i = 0; i < 50000000; i++)
	{
		if (num % k == 0)
		{
			cout << i+1 << endl;
			return 0;
		}
		num *= 10;
		num %= k;
		num += 7;
		num %= k;
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    sort(s.begin(), s.end());

    cout << ((s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) ? "Yes" : "No") << endl;

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back

using namespace std;

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

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void solve() {

}

int main() {
  int n;
  cin >> n;
  vector<int> P(n), Q(n);
  rep(i,n) cin >> P[i];
  rep(i,n) cin >> Q[i];
  vector<int> vec;
  REP(i,1,n+1) vec.pb(i);
  int p,q,c=1;
  do {
    bool same = true;
    rep(i,n) if( vec[i] != P[i] ) { same = false; break; }
    if( same ) p = c;
    same = true;
    rep(i,n) if( vec[i] != Q[i] ) { same = false; break; }
    if( same ) q = c;    
    ++c;
  } while( next_permutation(ALL(vec)) );
  cout << abs(p-q) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007
using namespace std;
int main(){
    int a,b;    cin>>a>>b;

    cout<<a*b<<" "<<2*(a+b)<<endl;
}


Measured memory_bytes: 3108
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    int sum=0;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)
    cout<<-1<<"\n";
    else
    cout<<(n-sum)<<"\n";
    return 0;
}

Measured memory_bytes: 3652
N, M = map(int, input().split())
Path = [list(map(int, input().split())) for _ in range(M)]
import itertools

lis = [x for x in range(2, N+1)] 
ans = 0

permutations_lis = itertools.permutations(lis)

for one_case in permutations_lis:
  List = [1]
  List.extend(one_case)
  for i in range(N-1):
    if not ([List[i], List[i+1]] in Path or [List[i+1], List[i]] in Path):
      break
  else:
    ans += 1
print(ans)

Measured memory_bytes: 74080
class Integer
  def mod_add(x)
    (self + x) % MOD
  end
  def mod_sub(x)
    (self - x) % MOD
  end
  def mod_mul(x)
    (self * x) % MOD
  end
  
  # a.mod_div(b) => a / b
  def mod_div(x)
    (self * x.mod_inv) % MOD
  end
  
  # a.mod_pow(b) => a ** b
  def mod_pow(x)
    a = self
    res = 1
    while x > 0
      res = res * a % MOD if x[0] == 1
      a = a * a % MOD
      x >>= 1
    end
    res
  end
  
  # for prime mod
  def mod_inv()
    self.mod_pow(MOD - 2)
  end
  
  def mod_comb(n, k)
    a = 1
    b = 1
    k.times do |i|
      b *= i + 1
      b %= MOD
    end
    k.times do |i|
      a *= n - i
      a %= MOD
    end
    a * b.mod_inv % MOD
  end
end

class ModCombination
  attr_reader :fac, :finv
  
  def initialize(n)
    @fac = Array.new(n+1)
    @finv = Array.new(n+1)
    @fac[0] = 1
    1.upto(n) do |i|
      @fac[i] = (@fac[i-1] * i) % MOD
    end
    
    @finv[n] = @fac[n].mod_inv;
    n.downto(1) do |i|
      @finv[i-1] = (@finv[i] * i) % MOD
    end
  end
 
  def combination(n, k)
    return 0 if k < 0 || k > n
    return (@fac[n] * @finv[k] * @finv[n-k]) % MOD
  end
end

MOD=10**9+7
X,Y=gets.split.map(&:to_i)
#X,Y=10**6+1,10**6
if (X+Y) % 3 != 0
  puts 0
else
  n = (X+Y)/3
  a, b = X-n, Y-n
  mc = ModCombination.new(a+b)
  puts mc.combination(a+b, a)
end

Measured memory_bytes: 12284
#include<stdio.h>

int main()
{
    int a, b, c, d;
    for(c=1; c<=200; c++)
    {
        while(scanf("%d %d", &a, &b) != EOF)
        {
            if(a<0 || b<0 || a>1000000 || b>1000000)
                return 0;
            d = a + b;
            c = 0;
            while(d>0)
            {
                d = d /10;
                c++;
            }
            printf("%d\n", c);
        }
    }

    return 0;
}

Measured memory_bytes: 596
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e9+7;
const ll MAXN=300200;
ll i,j;
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll n;
cin>>n;
vector<ll> v(n);
F(i,0,n)
{
    cin>>v[i];
}
sort(v.begin(),v.end());
ll k,cnt=0;
F(i,0,n)
{
    F(j,i+1,n)
    {
        F(k,j+1,n)
        {
            if(v[i]!=v[j] && v[i]!=v[k] && v[j]!=v[k] && v[i]+v[j]>v[k])
            {
                cnt++;
            }
        }
    }
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 3656