akhauriyash/Code-Regression huggingface dataset:
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int l=0;
  int r=s.length();
  int len = r;
  r--;
  while(s[l]!='A' || s[r]!='Z')
  {
  	// cout<<"l:: "<<s[l]<<" ";
    if(s[l]!='A')
      l++,len--;
    // cout<<"r:: "<<s[r]<<endl;
   	if(s[r]!='Z')
      r--,len--;
  }
  cout<<len<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> v(n - 1, 0);
	for (int i = 0; i < n - 1; i++) {
		cin >> v[i];
	}
	int res = v[0] + v.back();
	for (int i = 0; i + 1 < v.size(); i++) {
		res += min(v[i], v[i + 1]);
	}
	cout << res << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    set<int> s;
    int n;
    cin >> n;
    rep(i, n)
    {
        int d;
        cin >> d;
        s.insert(d);
    }

    OP(s.size());
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){
	int n,i;
	int min,mp;
	int now;
	scanf("%d",&n);
	scanf("%d",&min);
	scanf("%d",&now);
	mp=now-min;
	if(min>now)min=now;
	
	for(i=2;i<n;i++){
		scanf("%d",&now);
		if(mp<now-min)mp=now-min;
		if(min>now)min=now;
	}
	printf("%d\n",mp);
	return 0;
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, S;
  cin >> K >> S;
  int answer = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) answer++;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll a,b; cin>>a>>b;
    for(int i=1; i<100000; i++){
        if((ll)(i*0.08)==a && (ll)(i*0.1)==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include"cstdio"
#include"cstring"
int main(){
	char s[100005],a[27]="abcdefghijklmnopqrstuvwxyz";
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++)
	for(int j=0;j<26;j++)
	{
		if(s[i]==a[j])
		{
			a[j]='1';
			break;
		}	
	}
	for(int k=0;k<26;k++)
	{
		if(a[k]!='1')
		{
			printf("%c\n",a[k]);
			break;
		}
		else if(k==25)
				printf("None\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const ll INF = (1LL<<50);
const int MAX_N = 1e3+10;

struct Edge
{
	int to;
	ll cost;
	Edge(int to, ll cost) : to(to), cost(cost) {}
};

typedef vector<vector<Edge> > AdjList;
AdjList G(MAX_N);
int n;
vector<ll> dist;
bool judge[MAX_N];

void bellman_ford(ll s){
	dist = vector<ll> (n, INF);
	dist[s] = 0;
	for (int i = 0; i < n; ++i) {
		for (int v = 0; v < n; ++v) {
			for (int k = 0; k < G[v].size(); ++k) {
				Edge e = G[v][k];
				if (dist[v] != INF && dist[e.to] > dist[v] + e.cost)
				{
					dist[e.to] = dist[v] + e.cost;
				}
			}
		}
	}
}


int main(int argc, char const *argv[])
{
	int m;
	cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		c *= -1;
		G[a].push_back(Edge(b, c));
	}

	fill(judge, judge+n, false);

	bellman_ford(0);

	for (int u = 0; u < n; ++u) {
		for (int j = 0; j < G[u].size(); ++j) {
			Edge e = G[u][j];
			if (dist[e.to]==INF) continue;

			if (dist[e.to] > dist[u]+e.cost) judge[e.to] = true;
			if (judge[u]==true) judge[e.to] = true;
		}
	}

	if (judge[n-1]) cout << "inf" << endl;
	else {
		cout << -dist[n-1] << endl;
	}
	return 0;
}

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


int main() {
  int N, sum1 = 0, sum2 = 0, j;
  cin >> N;
  vector<int> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
    sum1 += S.at(i);
  }
  for (int i = 0; sum1 >= sum2 * 2; i++) {
    sum2 += S.at(i);
    j = i;
  }
  cout << min (abs(sum1 - 2 * sum2), abs(sum1 - 2 * (sum2 - S.at(j)))) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); 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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

const ll MAX = 100000;
int main() {
  vector <bool> is_prime(MAX, 1);
  is_prime.at(0) = false;
  for (ll i = 2; i <= MAX; i++) {
    if (is_prime.at(i-1)) {
      for (ll j = 2*i; j <= MAX; j += i) is_prime.at(j-1) = false;
    }
  }
  vector <bool> v(MAX, 0);
  for (ll i = 1; i <= MAX; i += 2) {
    if (is_prime.at(i-1) && is_prime.at((i+1)/2-1)) v.at(i-1) = true;
  }
  vector <ll> sum(MAX+1, 0);
  rep(i, MAX) {
    if (v.at(i)) {
      sum.at(i+1) = sum.at(i)+1;
    } else {
      sum.at(i+1) = sum.at(i);
    }
  }
  ll n;
  cin >> n;
  rep(i, n) {
    ll l, r;
    cin >> l >> r;
    cout << sum.at(r) - sum.at(l-1) << endl;
  }
}

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

using namespace std;

using ll = long long;
using ld = long double;

const ll INF = 1e15;

inline ld calc(ll vmax, ll vmin, ll vmax_r, ll vmin_r, ll vmax_l, ll vmin_l, ld t) {
    return max({(ld)vmax, vmax_r + t, vmax_l - t}) - min({(ld)vmin, vmin_r + t, vmin_l - t});
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    vector<char> d(n);

    ll xmax = -INF, xmin = INF, ymax = -INF, ymin = INF;
    ll ymax_u = -INF, ymin_u = INF, ymax_d = -INF, ymin_d = INF;
    ll xmax_l = -INF, xmin_l = INF, xmax_r = -INF, xmin_r = INF;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> d[i];
        if (d[i] == 'U') {
            xmax = max(xmax, x[i]);
            xmin = min(xmin, x[i]);
            ymax_u = max(ymax_u, y[i]);
            ymin_u = min(ymin_u, y[i]);
        } else if (d[i] == 'D') {
            xmax = max(xmax, x[i]);
            xmin = min(xmin, x[i]);
            ymax_d = max(ymax_d, y[i]);
            ymin_d = min(ymin_d, y[i]);
        } else if (d[i] == 'L') {
            ymax = max(ymax, y[i]);
            ymin = min(ymin, y[i]);
            xmax_l = max(xmax_l, x[i]);
            xmin_l = min(xmin_l, x[i]);
        } else {
            ymax = max(ymax, y[i]);
            ymin = min(ymin, y[i]);
            xmax_r = max(xmax_r, x[i]);
            xmin_r = min(xmin_r, x[i]);
        }
    }

    ld L = 0, R = 1e8;
    for (int i = 0; i <= 200; i++) {
        ld mid1 = (L * 2 + R) / 3;
        ld x1 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, mid1);
        ld y1 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, mid1);
        ld val1 = x1 * y1;

        ld mid2 = (L + R * 2) / 3;
        ld x2 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, mid2);
        ld y2 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, mid2);
        ld val2 = x2 * y2;

        if (val1 < val2) R = mid2;
        else L = mid1;    
    }

    ld x1 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, L);
    ld y1 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, L);
    ld val1 = x1 * y1;

    ld x2 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, R);
    ld y2 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, R);
    ld val2 = x2 * y2;    
    cout << fixed << setprecision(15) << min(val1, val2) << "\n";
    return 0;
}


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

long long pow(long long a,long long b) {
  if(b == 0)return 1;
  else return pow(a*a%1000000007,b/2)*(b%2==0?1:a)%1000000007;
}

int main() {
  int S;
  cin >> S;
  vector<long long> F(S,1),I(S,1);
  int i;
  for(i=1;i<S;i++)F[i] = F[i-1]*i%1000000007;
  for(i=0;i<S;i++)I[i] = pow(F[i],1000000005);
  long long ans = 0;
  for(i=0;S>=3*(i+1);i++) {
    ans = (ans + (F[S-2*i-3]*I[i]%1000000007)*I[S-3*i-3]%1000000007)%1000000007;
  }
  cout << ans << endl;
}

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

int main(){
    string str;
    cin >> str;
    str += 'Z';
    int ans = 0;

    for(int i = 0; i < str.length();i++){
        int ans1 = 0;
        int j = i;
        while(str.at(j) == 'A' || str.at(j) == 'G' || str.at(j) == 'C' || str.at(j) == 'T'){
            ans1++;
            j++;
            i = j;
        }
        ans = max(ans,ans1);
    }
    cout << ans << endl;
    
}

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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  int sum = 0;
  rep(i, n) {
    cin >> p[i];
    p[i]++;
    if (i < k) sum += p[i];
  }
  int ans = sum;
  for (int i = k; i < n; i++) {
    sum += p[i];
    sum -= p[i - k];
    ans = max(ans, sum);
  }
  if (ans % 2) {
    cout << ans / 2 << ".5";
  } else {
    cout << ans / 2;
  }
  return 0;
}


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

int main() 
{
    ll n;
    string s;
    cin>>n>>s;
    ll b=s.size();
    b=min(n,b);
    for(ll i=0;i<b;i++) cout<<s[i];
    if(s.size()>n) cout<<"...";
}

Measured memory_bytes: 3600
h,w,K=map(int,input().split())
s=[list(input())for i in range(h)]
import numpy as np
s=np.array(s)
l=[]
for i in range(h):
    l.append(len(s[i][s[i]=="#"]))
for i in range(w):
    l.append(len(s[:,i][s[:,i]=="#"]))
ss=sum(l)//2
n=h+w
ans=0
for i in range(1<<n):
    tmp=ss
    for j in range(h):
        if i>>j&1:
            tmp-=l[j]
    for j in range(h,n):
        if i>>j&1:
            tmp-=l[j]
            for idx,k in enumerate(s[:,j-h]):
                if k=="#":
                    if i>>idx&1:
                        tmp+=1
    if tmp==K:
        ans+=1
print(ans)

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

int main() {
  int N, M, x=0;
  string str;
  cin >> N;
  vector<string> vec(100);
  vector<int> vec2(100);
  for(int i=0; i<N; i++){
  	cin >> str;
  	for(int j=0; j<=x; j++){
  	  if(str == vec.at(j)){
  	    vec2.at(j)++;
  	    break;
  	  }
  	  if(j==x){
  	    vec.at(x)=str;
  	    vec2.at(x)++;
  	    x++;
  	    break;
  	  }
  	}
  }
  cin >> M;
  for(int i=0; i<M; i++){
  	cin >> str;
  	for(int j=0; j<=x; j++){
  	  if(str == vec.at(j)){
  	    vec2.at(j)--;
  	    break;
  	  }
  	  if(j==x){
  	    vec.at(x)=str;
  	    vec2.at(x)--;
  	    x++;
  	    break;
  	  }
  	}
  }
  
  sort(vec2.begin(),vec2.end());
  reverse(vec2.begin(),vec2.end());
  
  cout << vec2.at(0) << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, K = read_ints()
S = read()[:-1]


# 偶数番目に0の個数を格納するようなデータ構造を構築する
num_cnts = []
now = '1'  # 0から考慮する
cnt = 0
for s in S:
    if s == now:
        cnt += 1
    if s != now:  # もしいまカウントしている文字と異なったらカウントを格納して、カウントをリセットする。
        num_cnts.append(cnt)
        now = s
        cnt = 1
num_cnts.append(cnt)
# もしSが0で終わっていたら0個の1を付け足す
if S[-1] == '0':
    num_cnts.append(0)

assert len(num_cnts) % 2 == 1, '奇数個じゃない！'

# しゃくとり法で実装
add = min(2*K+1, len(num_cnts))  # Kで指定するよりも短い場合はそっちに合わせる
ans = 1

# forの外にleft, rightを持つ
left = 0
right = 0
tmp = 0  # num_cnt[left:right]のsum

# しゃくとりしながら最大長の探索
for next_left in range(0, len(num_cnts) - add + 1, 2):
    # 次のleft,rightを計算する #今回はあまりしゃくとりのありがたみがない
    next_left = next_left  # あえてこう書いてる
    next_right = next_left+add

    # 左端を移動する (左側の移動によって減る分を計算する)
    while (next_left > left):
        tmp -= num_cnts[left]
        left += 1

    # 右端を移動する
    while (next_right > right):
        tmp += num_cnts[right]
        right += 1

    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 4212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;



int main() {
	ll n; cin >> n;
	vector<vector<ll>> cnt(10, vector<ll>(10));
	for (int i = 1; i <= n; i++) {
		string s = to_string(i);
		int a = s.front(), b = s.back();
		cnt[a - '0'][b - '0']++;
	}
	ll ans = 0;
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			ans += cnt[i][j] * cnt[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

long long *fact, *inv;

template <typename T, typename U, typename V>
auto pow(T x_, U n_, V mod_) {
    std::common_type_t<T, U, V> ret = 1, x = x_, n = n_, mod = mod_;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <typename T, typename U>
auto inverse(T x, U p) { return pow(x, p - 2, p); }

void init_factorial(int n, long long mod) {
    fact = new long long[n + 1];
    inv = new long long[n + 1];
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

template <class T = long long int>
class Bit {
    private:
    int len;
    T *arr;
    T init;

    public:
    Bit(int length, T initialValue = 0) : len(length), init(initialValue) {
        arr = new T[length + 1];
        for (int i = 0; i <= length; i++) {
            arr[i] = initialValue;
        }
    }
    ~Bit() {
        delete[] arr;
    }
    void update(int a, T newval) {
        for (int x = a; x <= len; x += x & -x) arr[x] += newval;
    }
    T query(int a) const {
        T ret = init;
        for (int x = a; x > 0; x -= x & -x) ret += arr[x];
        return ret;
    }
};

int main() {
    constexpr i64 mod = 998244353;
    int n;
    std::cin >> n;
    init_factorial(n, mod);
    std::vector<std::pair<int, int>> a;
    std::vector<int> ys;
    std::vector<i64> ts(n + 1);
    ts[0] = 1;
    for (int i = 0; i < n; i++) {
        int x, y;
        std::cin >> x >> y;
        a.emplace_back(x, y);
        ys.push_back(y);
        ts[i + 1] = ts[i] * 2 % mod;
    }

    std::sort(a.begin(), a.end());
    std::sort(ys.begin(), ys.end());
    ys.erase(std::unique(ys.begin(), ys.end()), ys.end());
    for (auto &e : a) e.second = std::lower_bound(ys.begin(), ys.end(), e.second) - ys.begin() + 1;

    i64 ret = ts[n - 1] * n % mod;
    Bit<> bit(n + 10);

    for (int i = 0; i < n; i++) {
        i64 p = bit.query(a[i].second), c = i - p, b = a[i].second - 1 - p, q = n - 1 - i - b;
        bit.update(a[i].second, 1);
        ret = (ret + (ts[c] - 1) * (ts[b] - 1) % mod * ts[p] % mod * ts[q] % mod + (ts[p] - 1) * (ts[q] - 1) % mod * (ts[c] + ts[b] - 1) % mod) % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 9840
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int h, w, n;
vector<H>a;
int b[10];
signed main() {
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (x - i >= 1 && y - j >= 1 && x - i + 2 <= h && y - j + 2 <= w) {
					a.push_back(H{ x - i,y - j });
				}
			}
		}
	}
	sort(all(a));
	int ans = 0;
	for (int i = 0; i < a.size(); ) {
		int j = i;
		while (j < a.size() && a[i] == a[j]) {
			j++;
		}
		b[j - i]++;
		if (j - i > 0) ans++;
		i = j;
	}
	b[0] = (h - 2)*(w - 2) - ans;
	for (int i = 0; i < 10; i++) {
		cout << b[i] << endl;
	}
}

Measured memory_bytes: 18024
n = int(input())
a = [input() for _ in range(n)]

cnt_col = [0]*n
cnt_row = [0]*n

for i in range(n):
    for j in range(n):
        if(a[i][j] == '#'):
            cnt_col[i] += 1
            cnt_row[j] += 1

if(sum(cnt_col)==0):
    print(-1)
    exit()

b_row = cnt_row.count(n)


ans = 2*n
for i in range(n):
    if(cnt_col[i] == n):
        ans = min(ans, n-b_row)
        continue

    if(cnt_row[i] > 0):
        ans = min(ans, n-cnt_col[i] + n-b_row)
    else:
        ans = min(ans, n-cnt_col[i] + n-b_row + 1)

print(ans)

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

int main() {
  int n;cin>>n;
  vector<int> vec(20);
  rep(i,n){
    int a;cin>>a;
    vec[a/400]++;
  }
  int cnt1=0,cnt2=0;
  rep(i,20){
    if(i>7)cnt2+=vec[i];
    else {
      if(vec[i]>0)cnt1++;
    }
  }
  if(cnt1==0)cout<<1<<" "<<cnt2<<endl;
  else cout<<cnt1<<" "<<cnt1+cnt2<<endl;
}

Measured memory_bytes: 3632
from collections import Counter

n = int(input())
d = list(map(int, input().split()))
mod = 998244353

a = sorted(list(set(d)))

if d[0] != 0:
    ans = 0
elif a[-1] != len(a)-1:
    ans = 0
else:
    c = sorted(Counter(d).items())
    if c[0] != (0, 1):
        ans = 0
    else:
        ans = 1
        pre = 1
        for k, v in c:
            ans *= pre ** v
            ans %= mod
            pre = v

print(ans)

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  ll N, K;

  CIN(N >> K);

  ll H[N];
  for (int i = 0; i < N; i++) {
    CIN(H[i]);
  }

  sort(H, H + N, greater<>());

  ll c = 0;
  for (ll i = K; i < N; i++) {
    c += H[i];
  }

  COUT(c);

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = (n - 1); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 100000007;

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (d > s * t)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-d > k or e-c > k or e-b > k or e-a > k or d-c > k or d-b > k or d-a > k or c-b > k or c-a > k or b-a > k:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
/*
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
*/
#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int dp[18][301];
int n;

int rec(int idx, int mul){
    if(mul<0) return 0;
    if(idx>17) return mul==0;
    if(dp[idx][mul]) return dp[idx][mul];
    return dp[idx][mul]=rec(idx + 1, mul) + rec(idx, mul-idx*idx);
}

void solve(){
    cout<<rec(1,n)<<endl;
}

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

    while(cin>>n,n){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3144
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
//const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int D[100010];

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

	int N;
	cin >> N;
	rep(i, 0, N)
	{
		cin >> D[i];
	}

	sort(D, D + N);

	cout << D[N / 2] - D[N / 2 - 1] << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int N,M;
bool graph[60][60];
bool vis[60];
int a[60],b[60];
void dfs(int x){
    if(vis[x]) return ;
    vis[x]=true;
    for(int i=0;i<N;i++){
        if(graph[x][i]){
            dfs(i);
        }
    }
}
int main() {
    cin>>N>>M;
    int cnt=0;
    for(int i=0;i<M;i++){
            cin>>a[i]>>b[i];
            a[i]--;
            b[i]--;
            graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
        }
    for(int j=0;j<M;j++){  
        graph[a[j]][b[j]]=graph[b[j]][a[j]]=false;
    for(int i=0;i<N;i++) vis[i]=false;
    dfs(0);
    bool connected=true;
    for(int i=0;i<N;i++){
        if(!vis[i]) connected=false;
    }
    if(!connected) cnt++;
    graph[a[j]][b[j]]=graph[b[j]][a[j]]=true;
    }
    cout<<cnt<<endl;




    return 0;
}

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


int main(){
    int N,K;
    cin>>N>>K;
    int h[N];
    for(int i=0;i<N;i++)cin>>h[i];

    sort(h,h+N);
    int gap[N-K+1];
    for(int i=0;i+K-1<N;i++)gap[i]=h[i+K-1]-h[i];
    sort(gap,gap+(N-K+1));
    cout<<gap[0]<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
#define MAX_N 1000000005


int main() {
	int s,w;
	cin >> s >> w;
	if(s>w) cout << "safe" << endl;
	else cout << "unsafe" << endl;

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;

    if (B % A == 0){
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int K,Q;
int d[5005];
int main()
{
	scanf("%d%d", &K, &Q);
    for(int i=0;i<K;i++) scanf("%d", d + i);
    while(Q--)
    {
        int n,x,m;
		scanf("%d%d%d", &n, &x, &m);
		x%=m;
        ll sum=0,cnt=0;
        for(int i=0;i<K;i++)  sum+=(d[i]%m),cnt+=(d[i]%m==0);
        ll add=1ll*((n-1)/K)*sum;cnt=cnt*((n-1)/K);
        for(int i=0;i<=n-2-((n-1)/K)*K;i++)  add+=(d[i]%m),cnt+=(d[i]%m==0);
        cout<<(n-1-(add+x)/m+x/m)-cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
N,K=map(int,input().split())
D=list(input().split())

for i in range(N,10*N+1):
  s=str(i)
  flag=True
  for x in D:
    if x in s:
      flag=False
      break
  if flag:
    print(s)
    break
  else:
    continue

    

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

vi color;
vector<vi> adj;

void dfs(int v, int c)
{
    color[v] = c;
    for(auto u:adj[v]){
        if (color[u]!=-1) continue;
        dfs(u, 1-c);
    }
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    color.resize(n,-1);
    adj.resize(n);
    rep(i,n-1){
        int a,b; cin>>a>>b; a--; b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(0,0);
    vi blank[2];
    rep(i,n) blank[color[i]].pb(i);
    int x = blank[0].size();
    int y = blank[1].size();
    if (x>y){
        swap(x,y);
        blank[0].swap(blank[1]);
    }
    vi ans(n);
    set<int> rnum, rspa;
    rep(i,n) rnum.ins(i+1), rspa.ins(i);
    if (x<=n/3){
        rep(i,x){
            ans[blank[0][i]] = (i+1)*3;
            rspa.erase(blank[0][i]);
            rnum.erase((i+1)*3);
        }
    }else{
        rep(i,(n+2)/3){
            ans[blank[0][i]] = i*3+1;
            rspa.erase(blank[0][i]);
            rnum.erase(i*3+1);
        }
        rep(i,(n+1)/3){
            ans[blank[1][i]] = i*3+2;
            rspa.erase(blank[1][i]);
            rnum.erase(i*3+2);
        }
    }
    auto it = rnum.begin();
    for(auto s:rspa){
        ans[s] = *it;
        it++;
    }
    rep(i,n){
        if (i>0) cout<<" ";
        cout<<ans[i];
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 33904
s = input()

flg = True
for index, char in enumerate(s):
    if index % 2 == 0:
        if char == 'L':
            flg = False
            break
    else:
        if char == 'R':
            flg = False
            break
    
if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
def selectionSort(a,b):
    for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            ret = b[i]
            b[i] =b[mini]
            b[mini] = ret
    
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output
    
    
def bubblesort(a,b):
    swap = True
    while swap:
        swap = False
        for j in range(1,len(a))[::-1]:
            if a[j] < a[j-1]:
                ret = a[j]
                a[j] = a[j-1]
                a[j-1] = ret
                ret = b[j]
                b[j] = b[j-1]
                b[j-1] = ret
                swap = True
    output = []           
    for i in range(len(a)):
        output.append(str(b[i])+str(a[i]))
    print(" ".join(output))
    return output


n = int(input())
card = input().split()
number = []
mark = []
number2 = []
mark2 = []
for i in range(n):
    number.append(int(list(card[i])[1]))
    mark.append(list(card[i])[0])
    number2.append(int(list(card[i])[1]))
    mark2.append(list(card[i])[0])

output1 = bubblesort(number,mark)
print("Stable")
output2 = selectionSort(number2, mark2)
print("Stable" if output1 == output2 else "Not stable"  )

Measured memory_bytes: 7792
N = int(input())

sieve = [0] * 101
sieve[0] = -1
sieve[1] = -1
for i in range(2, 101):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, 101, i):
        if sieve[j] == 0:
            sieve[j] = i

d = {}
for i in range(2, N + 1):
    while i != 1:
        d.setdefault(sieve[i], 0)
        d[sieve[i]] += 1
        i //= sieve[i]


result = 0
# 75 = 5 * 5 * 3
# x ^ 4 * y ^ 4 * z ^ 2 の約数の個数は75個
n2 = 0
n4 = 0
for k in d:
    if 2 <= d[k] <= 3:
        n2 += 1
    elif d[k] >= 4:
        n4 += 1
result += n2 * n4 * (n4 - 1) // 2 + n4 * (n4 - 1) * (n4 - 2) // 2
# x ^ 14 * y ^ 4 の約数の個数は75個
n4 = 0
n14 = 0
for k in d:
    if 4 <= d[k] <= 13:
        n4 += 1
    elif d[k] >= 14:
        n14 += 1
result += n4 * n14 + n14 * (n14 - 1)
# x ^ 24 * y ^ 2 の約数の個数は75個
n2 = 0
n24 = 0
for k in d:
    if 2 <= d[k] <= 23:
        n2 += 1
    elif d[k] >= 24:
        n24 += 1
result += n2 * n24 + n24 * (n24 - 1)
# x ^ 74 の約数の個数は75個
n74 = 0
for k in d:
    if d[k] >= 74:
        n74 += 1
result += n74
print(result)


Measured memory_bytes: 9300
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007



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

    int ans = 0;
    rep(i, s.size() - 1) {
        if (s[i + 1] == s[i]) {
            if (s[i] == '1') s[i + 1] = '0';
            else s[i + 1] = '1';
            ans++;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100005][14];
ll MOD = 1e9 + 7;
ll bpow(ll b, ll p, ll m) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  string s;
  cin >> s;
  // for (int i = 0; i < 13; i++)
  dp[0][0] = 1;
  for (int i = 1; i <= s.length(); i++) {
    if (s[i - 1] == '?') {
      for (int k = 0; k < 13; k++) {
        for (int j = 0; j < 10; j++) {
          ll temp = (j * bpow(10, s.length() - i, 13)) % 13;
          dp[i][(k + temp) % 13] =
              (dp[i][(k + temp) % 13] + dp[i - 1][k]) % MOD;
        }
      }
    } else {
      ll temp = (s[i - 1] - '0') * bpow(10, s.length() - i, 13);
      for (int k = 0; k < 13; k++) {
        dp[i][(k + temp) % 13] = dp[i - 1][k];
      }
    }
  }
  // for (int i = 0; i <= s.length(); i++) {
  //   for (int j = 0; j < 13; j++) {
  //     cout << dp[i][j] << ' ';
  //   }
  //   cout << endl;
  // }
  cout << dp[s.length()][5] << endl;
}

Measured memory_bytes: 11392
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,m;
int main(){
	scanf("%lld %lld",&n,&m);
	ll ans=max(4-n,0)+max(4-m,0);
	if(ans==6)ans+=4;
	printf("%lld\n",ans*100000);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]==s[i+1]){
		cout<<"Bad"<<endl;
		return 0;
	}
	cout<<"Good"<<endl;
	return 0;
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int a, b, c;
	cin >> a >> b >> c;
	int mini = min(a, min(b, c));
	int maxi = max(a, max(b, c));
	int sum = a + b + c;
	if(mini == 5 && maxi == 7 && sum == 17){
			cout << "YES" << endl;
	}else{
			cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
cin = open(0).read().strip().split('\n')
n = int(cin[0])
a = list(map(int, cin[1].split(' ')))
b = list(map(int, cin[2].split(' ')))
c = list(map(int, cin[3].split(' ')))

a = sorted(a)
b = sorted(b)
c = sorted(c)

from bisect import bisect_left, bisect

print(sum([bisect_left(a, bi)*(n-bisect(c, bi)) for bi in b]))

Measured memory_bytes: 26052
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace
import           Text.Printf


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons
getInt = readLn :: IO Int
getIntTuple = (\vec -> (vec VU.! 0, vec VU.! 1)) <$> getIntVector

main = do
  (n,k) <- getIntTuple
  print $ solve n k

solve n k = min min1 min2
  where
    times  = n `div` k
    times' = (n + (k-1)) `div` k
    min1 = abs $ (n - times *k)
    min2 = abs $ (n - times'*k)


Measured memory_bytes: 4200
s = input()
cnt = 0

if len(s)%2:
  for i in range(int(len(s)/2)):
      if s[i] != s[len(s) -i -1]:
          cnt += 1
else:
    for i in range(int(len(s)/2)):
        if s[i] != s[len(s) -i -1]:
            cnt += 1
print(cnt)

Measured memory_bytes: 3060
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x

    def size(self, x):
        return -self.par[self.find(x)]


n, k = map(int, input().split())
uf = UnionFind(n)
for _ in range(k):
    a, b = map(int, input().split())
    uf.unite(a - 1, b - 1)

cnt = 0
for x in uf.par:
    if x < 0:
        cnt += 1
print(cnt - 1)


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

int main() {
  int N; cin>>N;
  vector<int> A(N);
  int min=1<<30;
  int max=0;
  for(int i=0; i<N; ++i){
    cin>>A[i];
    if(A[i]<min){
      min=A[i];
    }
    if(A[i]>max){
      max=A[i];
    }
  }
  int t=abs(max-min);
  cout<<t<<endl;
  return 0;
}

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

const int maxn=(int)2e5+10;
vector<int> v[maxn];
int dp[maxn];
int in[maxn];
bool bylo[maxn];
queue<int> q;

int main()
{
	int n,m;
	scanf("%d %d",&n, &m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d %d",&a, &b);
		v[a].push_back(b);
		++in[b];
	}
	for(int i=1;i<=n;i++)
		if(!in[i])
			q.push(i);
	while(q.size())
	{
		int p=q.front(); q.pop();
		bylo[p]=true;
		for(auto it : v[p])
		{
			dp[it]=max(dp[p]+1,dp[it]);
			--in[it];
			if(!in[it] && !bylo[it])
				q.push(it);
		}
	}
	int maksi=0;
	for(int i=1;i<=n;i++)
		maksi=max(maksi,dp[i]);
	printf("%d",maksi);
}

Measured memory_bytes: 8960
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = unsigned long long;
using namespace std;

int main(void) {
    int a,b;
    cin >> a >> b;

    int price = 0;
    if (a >= 13) {
        price = b;
    }

    else if (a >= 6 && a <= 12) {
        price = b/2;
    }

    cout << price << endl;

    return 0;
}

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

int main()
{
        int r, c;
        cin >> r >> c;
        int table[r][c];

        for(int i=0; i<r; i++){
                for(int j=0; j<c; j++){
                        cin >> table[i][j];
                }
        }
        
        int totalR, totalC, total;;        

        for(int i=0; i<r; i++){
                totalR=0;
                for(int j=0; j<c; j++){
                        totalR += table[i][j];
                        cout << table[i][j] << " ";
                }
                cout << totalR << endl;
        }
        total = 0;
        for(int i=0; i<c; i++){
                totalC=0;
                for(int j=0; j<r; j++){
                        totalC += table[j][i];
                }
                total += totalC;
                cout << totalC << " ";
        }
        cout << total << endl;
 
        return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N, Y;
        N = scanner.nextInt();
        Y = scanner.nextInt();
        int x =0;
        int y =0;
        int z =0;
        loop: for (int i = 0; i < N+1; i++) {
            for (int j = 0, k = N - i - j; j <= N - i; j++, k--) {
                if (Y == 10000 * i + 5000 * k + 1000 * j) {
                    x = i;
                    y = k;
                    z = j;
                    break loop;
                }else{
                     x = -1;
                     y = -1;
                     z = -1;
                }
            }
        }
        System.out.println(x+" "+y+" "+z);
    }
}


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

int main() {

    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    cout << string(tx-sx,'R') << string(ty-sy,'U');
    cout << string(tx-sx,'L') << string(ty-sy,'D');
    cout << "D" << string(tx-sx+1,'R') << string(ty-sy+1,'U') << "L";
    cout << "U" << string(tx-sx+1,'L') << string(ty-sy+1,'D') << "R";
    
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll N=1E6+7;
const ll mod=1e9+7;

ll arr[N];
ll mp[N];

ll ksm(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}

int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll mx=0;
    for(ll i=1;i<=n;i++){
        cin>>arr[i];
        mx=max(mx,arr[i]);
    }
    ll pos=0;
    for(ll i=1;i<=n;i++){
        ll x=arr[i];
        ll y=sqrt(x);
        for(ll j=2;j<=y;j++){
            ll cnt=0;
            while(x%j==0){
                x/=j;
                cnt++;
            }
            mp[j]=max(mp[j],cnt);
        }
        if(x!=1) mp[x]=max(mp[x],(ll)1);
    }
    ll sum=1;
    for(ll i=1;i<=mx;i++)
        sum=(sum%mod*ksm(i,mp[i])%mod)%mod;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=sum*ksm(arr[i],mod-2)%mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 8832
N = int(input())
S = list(map(str,input()))

r = 0
g = 0
b = 0
for i in range(N):
    if S[i] == "R":
        r+=1
    elif S[i] == "G":
        g+=1
    else:
        b+=1
ans = 0
for i in range(N):
    for j in range(1,N//2+2):
        if i+2*j < N:
            if S[i] != S[i+j] and S[i] != S[i+2*j] and S[i+j] != S[i+2*j]:
                ans +=1

print(r*g*b-ans)

Measured memory_bytes: 9240
/*************************************************************\
~*********************ENJOY THE SILENCE***********************~
\*************************************************************/

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

/*******************Debugging defines*************************/

#define ok_dump() cerr<<"OK\n"
#define var_dump(x) cerr<<#x": "<<x<<'\n'
#define arr_dump(x, n) do{cerr<<#x"[]: ";\
     for(int _=0;_<n;++_) cerr<<x[_]<<" ";cerr<<'\n';}while(0)

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

const int kMaxN = 500000;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b, c;
	cin >> a >> b >> c;

	if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0 << endl;
	} else {
		if(a > b) swap(a, b);
		if(b > c) swap(b, c);
		if(a > c) swap(a, c);

		cout << 1LL * a * b << endl;
	}

	return 0;
}

/*************************************************************\
~*********************ENJOY THE SILENCE***********************~
\*************************************************************/


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

using namespace std;

int main ()
{
    long int n;
    long int k;
    long int i;
    long int h;
    long int sum=0;
    scanf("%ld %ld",&n,&k);

    vector <long int> vec(n);

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

    if(n<=k) 
    {
        printf("%ld",sum);
        return 0;
    }

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


    

    for(i=0;i<n-k;i++)
    {
        sum+=vec[i];
    }



    cout << sum;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
 
int main() {
    int x, h;
    while(cin >> x >> h) {
        if(x == 0 && h == 0) break;
        double ans = 0.0;
        ans += (double)x * x;
        ans += 2.0 * x * sqrt(x * x / 4.0 + h * h);
        printf("%.6f\n",ans);
    }
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);//標高
  vector<int> S(N);//0ならいい展望台 1以上ならゴミの展望台
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
  }
  vector<int> A(M), B(M);

  for(int i = 0; i < M; i++){
    cin >> A.at(i) >> B.at(i);
    if(H.at(A.at(i) - 1) < H.at(B.at(i) - 1)){
      S.at(A.at(i) - 1)++;
    }
    else if(H.at(A.at(i) - 1) > H.at(B.at(i) - 1)){
      S.at(B.at(i) - 1)++;
    }
    else{
      S.at(A.at(i) - 1)++;
      S.at(B.at(i) - 1)++;
    }
  }//ひっくい展望台をどんどんイ
  
  int c = 0;//いい展望台の数
  for(int i = 0; i < N; i++){
    if(S.at(i) == 0){
      c++;
    }
  }
  
  cout << c << endl;//出
}


Measured memory_bytes: 4776