akhauriyash/Code-Regression huggingface dataset:
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  1000000007
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int bigmod(int a, int p, int m){ 
    if (p == 0)  return (1 % m) ; 
    if (p & 1){ 
        int p1 = a % m ;
        int p2 = bigmod( a, p-1, m ); 
        return  (p1 * p2) % m; 
    }
    int p1 = bigmod( a, p/2, m ); 
    return  (p1 * p1) % m; 
}

int fact(int n,int k) { 
	int  a=1, b=1 ; 
	for (int i=1;i<=k;i++) { 
		a *= n-i+1 ; 
		b *= i ; 
	} 
	return  ( a * bigmod(b, mod-2, mod)) % mod ; 
}

inline void solve(){
    int  n, k ; 
    cin >> n >> k ; 
    k-- ; 
    vi  fact(n+1), a(n+1); 
    for (int i=1;i<=n;i++) cin >> a[i] ; 
    fact[0] = fact[1] = 1 ; 
    for (int i=2;i<=n;i++) {
    	fact[i] = fact[i-1]*i ; 
    	fact[i] %= mod ; 
    }
    sort(a.begin()+1,a.end()) ; 
    int  mn=0, mx=0 ; 
    for (int i=1,N;i<=n;i++){

    	if (i<=n-k) {
    		N = n-i;
    		int h= (fact[N]*bigmod(fact[N-k]*fact[k],mod-2,mod)) % mod ; 
    		mn += h * a[i] ; 
    		mn %= mod ; 
    	}
    	if (i > k) { 
    		N = i-1;
    		int h= (fact[N]*bigmod(fact[N-k]*fact[k],mod-2,mod)) % mod ; 
    		mx += h * a[i] ; 
    		mx %= mod; 
    	}
    }
    co((mx-mn+mod)%mod) ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
 

Measured memory_bytes: 4692
K = int(input())
A, B = map(int, input().split())
x = A // K
y = B // K
p = A % K
q = B % K
ans = "NG"
if (p * q == 0):
  ans = "OK"
elif ((y - x) > 0) :
  ans = "OK"
print(ans)

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

vector<ll> a;
ll n, k;

bool ok(ll x) {
	ll res = 0;
	for(ll i = 0; i < n; i++) if(a[i] > x) {
		res += a[i] / x;
		if(a[i] % x == 0) res--;
	}
	return res <= k;
}

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

	cin >> n >> k;
	a.resize(n);
	for(ll i = 0; i < n; i++) cin >> a[i];
	ll x = 0;
	for(ll b = 2000000000; b; b /= 2) while(!ok(x + b)) x += b;
	cout << x + 1 << '\n';
}


Measured memory_bytes: 4736
N = int(input())
rooms = [[[0 for i in range(10)] for i in range(3)] for i in range(4)]

for i in range(N):
  b,f,r,v = map(int,input().split())
  rooms[b-1][f-1][r-1] += v
  if rooms[b-1][f-1][r-1] < 0:
    rooms[b-1][f-1][r-1] = 0
  elif rooms[b-1][f-1][r-1] > 9:
    rooms[b-1][f-1][r-1] = 9
  
for i in range(4):
  for j in range(3):
    for k in range(10):
    
        if k == 0:
          print(" "+ str(rooms[i][j][k]),end =" ") 
        elif k == 9:
          print(rooms[i][j][k],end ="")
        else:
          print(rooms[i][j][k],end =" ")  
    
    print()
  if i != 3:
    print("####################") 


Measured memory_bytes: 5632
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<int> > A(H, vector<int>(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> A[i][j];
		}
	}
	vector<pair<int, int> > ord;
	for (int i = 0; i < H; ++i) {
		if (i % 2 == 0) {
			for (int j = 0; j < W; ++j) {
				ord.push_back(make_pair(i, j));
			}
		}
		else {
			for (int j = W - 1; j >= 0; --j) {
				ord.push_back(make_pair(i, j));
			}
		}
	}
	int pre = -1;
	vector<vector<int> > ops;
	for (int i = 0; i < ord.size(); ++i) {
		if (A[ord[i].first][ord[i].second] % 2 == 0) continue;
		if (pre == -1) pre = i;
		else {
			for (int j = pre; j < i; ++j) {
				ops.push_back({ ord[j].first, ord[j].second, ord[j + 1].first, ord[j + 1].second });
			}
			pre = -1;
		}
	}
	cout << ops.size() << endl;
	for (vector<int> i : ops) {
		cout << i[0] + 1 << ' ' << i[1] + 1 << ' ' << i[2] + 1 << ' ' << i[3] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 13036
#include<iostream>
using namespace std;
int main() {
	string s, t;
	cin >> s>> t;
	if (s.size() + 1 != t.size()) {
		cout << "No" << endl;
	}
	else {
		if (t.substr(0, s.size()) == s)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a; string s;
    cin >> a >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n;
    cin >> n;
    vector<int>v(n);
    for(auto& itr : v) cin >> itr;
    deque<int>deq;
    rep(i,n){
        if(i == 0 )deq.push_back(v[i]);
        else{
            if(i % 2)deq.push_front(v[i]);
            else deq.push_back(v[i]);
        }
    }
    if(n % 2)reverse(all(deq));
    rep(i,deq.size()){
        if(i)cout << " ";
        cout << deq[i];
    }
    cout << endl;
}



Measured memory_bytes: 5504
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，DP
// 存在判定：構成方法，入力の特徴
// 例外を十分に含む一般化．想像力の限界
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int N, M; cin >> N >> M;
vector<tuple<int, int, int>> PYn(M);
rep(i, 0, M) {
    int p, y;
    cin >> p >> y;
    PYn[i] = make_tuple(p, y, i);
}
sort(ALL(PYn));

vector<pair<int, string>> nN(M);
int x = 1;
rep(i, 0, M){
    nN[i].first = get<2>(PYn[i]);

    string p = to_string(get<0>(PYn[i]));
    while (p.size() < 6) p = '0' + p;

    string y = to_string(x);
    while (y.size() < 6) y = '0' + y;

    nN[i].second = p + y;

    if (i < M - 1) {
        if (get<0>(PYn[i]) != get<0>(PYn[i+1])) x = 1;
        else ++x;
    }
}

sort(ALL(nN));
rep(i, 0, M) cout << nN[i].second << "\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 8960
# coding: utf-8
# 500円玉の枚数
a = int(input())
# 100円玉の枚数
b = int(input())
# 50円玉の枚数
c = int(input())
# 合計金額
x = int(input())
 
def main():
    flag = "FALSE"
    count = 0
    for i in range(0, a+1):
        for j in range(0, b+1):
            for k in range(0, c+1):
                total = int(500*i+100*j+50*k)
                if total == x:
                    count = count + 1
                else:
                    pass
    print(count)
 
if __name__ == '__main__':
    main()

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

const int N = 21;

int dp[N + 1][1 << N];
bool a[N][N];
int n;
const int MOD = 1e9 + 7;

void add(int& a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void solve() {
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1; // only one way to distribute 0 man and 0 women
    for (int i = 0; i < n; ++i) {
        for (int mask = 0; mask < (1 << n); ++mask) {
            if (__builtin_popcount(mask) != i) continue;
            for (int j = 0; j < n; ++j) {
                if (!(mask & (1 << j)) && a[i][j]) {
                    add(dp[i + 1][mask | (1 << j)], dp[i][mask]);
                }
            }
        }
    }
    printf("%d\n", dp[n][(1 << n) - 1]);
}

int main() {
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                scanf("%d", a[i] + j);
            }
        }
        solve();
    }
    return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int w,h,x,y;
  cin>>w>>h>>x>>y;
  double area=(double)w*(double)h/2;
  if(2*x==w&&2*y==h){
    cout << fixed << setprecision(9) << area;
    cout<<" "<<1<<endl;
  }else{
    cout << fixed << setprecision(9) << area;
    cout<<" "<<0<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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 main() {
    int n,m;
    cin >> n >> m;
    vector<int>p(m),y(m);
    rep(i,m) {
        cin >> p[i] >> y[i];
        p[i]--;
    }    
    vector<vector<int>>val(n);
    rep(i,m) {
        val[p[i]].push_back(y[i]);
    }
    rep(i,n) {
        sort(val[i].begin(),val[i].end());
    }
    rep(i,m) {
        printf("%06d",p[i]+1);
        int id = lower_bound(val[p[i]].begin(),val[p[i]].end(),y[i])-val[p[i]].begin();
        printf("%06d\n",id+1);
    }
}

Measured memory_bytes: 7808
N = int(input())
H = list(map(int,input().split()))

A = [[0 for i in range(N)] for j in range(101)]
#print(A)

for i in range(101):
    for j in range(N):
        if H[j] - i > 0:
            A[i][j] = 1 
#print(A)

ans = 0
for i in range(101):
    cnt = 0
    for j in range(N):
        if cnt == 0 and A[i][j] == 1:
            cnt+=1
            ans +=1
        elif A[i][j] == 0:
            cnt = 0
        
print(ans)

Measured memory_bytes: 3064
def gcd(a, b):
    """
    最大公約数
    """
    if b > a:
        a, b = b, a
    c = a % b
    return b if c == 0 else gcd(b, c)


N, X = list(map(int, input().split()))
xlist = list(map(int, input().split()))
xlist.append(X)
xlist.sort()

m = xlist[1] - xlist[0]
for i in range(1, len(xlist) - 1):
    d = xlist[i + 1] - xlist[i]
    m = gcd(d, m)
print(m)


Measured memory_bytes: 14252
S = input()

Kugiri = len(S) // 2
if S == ''.join(list(reversed(S))):
    up = ''
    down = ''
    for i in range(0, Kugiri):
        up += S[i]
    for q in range(Kugiri + 1, len(S)):
        down += S[q]
    if up == ''.join(list(reversed(up))) and down == ''.join(list(reversed(down))):
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    int n = Integer.parseInt(r.readLine());
    String[] sl = r.readLine().split("[\\s]+");
    int[] x = new int[n];
    
    int z = 0;
    for(int i = 0; i < n; i++)
    {
      x[i] = Integer.parseInt(sl[i]);
      if(z < x[i])
      {
        z = x[i];
      }
    }
    
    int v = 0;
    
    for(int i = 0; i < n; i++)
    {
      int w = x[i];
      if(w <= z / 2)
      {
        if(v <= z / 2)
        {
          v = Math.max(v, w);
        }
        else
        {
          if(z - v < w) v = w;
        }
      }
      else
      {
        if(v <= z / 2)
        {
          if(w < z - v) v = w;
        }
        else
        {
          v = Math.min(v, w);
        }
      }
    }
    
    System.out.printf("%d %d", z, v);
  }


}


Measured memory_bytes: 51660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}
// multimap
// mmap.emplace(key,value);
// auto ngw = list.equal_range("");
// for(auto e = ngw.first; it != ngw.second ; ++e)


int main(){
    ll N,A; cin >> N >> A;
    vl x(N); rdv(x);
    vvvl dp(N+1,vvl(N+1,vl(2555,0)));
    dp[0][0][0] = 1;
    rep(i,N){
        rep(j,N){
            rep(k,2505){
                dp[i+1][j][k] += dp[i][j][k];
                if(k<2503){
                    dp[i+1][j+1][k+x[i]] += dp[i][j][k];
                }
            }
        }
    }
    ll ans = 0;
    rep(i,N){
        ans += dp[N][i+1][A*(i+1)];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 53248
#include <iostream>

using namespace std;

int main()
{
    int a,b,x;
    cin>>x;
    cin>>a;
    cin>>b;
    a=a-x;
    b=b-x;


    if(a<0)
    {
        a=-a;
    }

    if(b<0)
    {
        b=-b;
    }
    if(a<b)
    {
        cout<<"A";
    }
    else
    {
        cout<<"B";
    }
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/agc032/tasks/agc032_a
// 解説見たらたったこれだけのことか・・・という感じ
// 操作の逆順から考える、という思考はなかったので新しい視座を得られた、とするか・・・

fun main() {
    agc032a()
}

fun agc032a() {
    val n = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    if (isImpossible(b)) {
        println(-1)
        return
    }
    var ans = mutableListOf<Int>()
    while (b.isNotEmpty()) {
        var j = b.lastIndex
        while (j >= 0) {
            if (b[j] == j + 1) {
                ans.add(b[j])
                b.removeAt(j)
                break
            }
            j--
        }
    }
    ans.reverse()
    println(ans.joinToString("\n"))
}

private fun isImpossible(values: List<Int>): Boolean {
    for (i in values.indices) {
        if (values[i] > i + 1) return true
    }
    return false
}

Measured memory_bytes: 36584
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string> s(n);
  map<string,int> mp;
  for(int i=0;i<n;i++){
    cin>>s.at(i);
    mp[s.at(i)]++;
  }
  cout<<mp.size()<<endl;
  return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int count = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (i % 2 == 0 && a % 2 == 1)
            ++count;
    }
    cout << count << "\n";
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    sort(deq.begin(),deq.end());
    int flag=0;
    for (int j=0;j+1<=n;j++) {
        if (deq[j]==deq[j+1]) {
            cout<<"NO"<<endl;
            flag=1;
            break;
        }
    }
    if (flag==0) {
        cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 1024
import java.math.BigInteger

fun main(args: Array<String>) {
    val (a, b, c) = readLine()!!.split(" ")
    val now = BigInteger(a).abs()
    val k = BigInteger(b)
    val dist = BigInteger(c)

    var out: BigInteger
    if (now >= k * dist) {
        out = now - (k * dist)
    }
    else {
        val jump = now / dist
        out = now % dist

        if ((k - jump).testBit(0)) {
            out = (out - dist).abs()
        }
    }
    println(out)
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int k = ri();
	int q = ri();
	int res[n];
	for (int i = 0; i < n; i++) res[i] = k - q;
	for (int i = 0; i < q; i++) {
		int a = ri() - 1;
		res[a]++;
	}
	for (int i = 0; i < n; i++) {
		std::cout << (res[i] > 0 ? "Yes" : "No") << std::endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
vector<int> vec(N);
int ans = 0;
for (int i = 0;i < N;i++) {
    cin >> vec.at(i);
    ans += vec.at(i);
}
if (ans % 10 != 0) cout << ans << endl;
else {
    sort(vec.begin(),vec.end());
    int i = 0;
    for (i = 0;i < N;i++) {
        if (vec.at(i) %10 != 0) break; 
    }
    if (i == N) cout << 0 << endl;
    else cout << ans-vec.at(i) << endl;
}




return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
A = list(map(int, input().split()))
pre = A[0]
index = -1
for i in range(1, N):
    if pre + A[i] >= L:
        index = i
        break
    pre = A[i]

if index == -1:
    print("Impossible")
else:
    print("Possible")
    i = 1
    while i < index:
        print(i)
        i += 1
    i = N - 1
    while index - 1 < i:
        print(i)
        i -= 1

Measured memory_bytes: 14076
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

int main() {
  string s;
  cin>>s;
  int k = (s.size()+1)/2;
  int res =0;
  for(int i =0;i<k;i++){
    if(s[i]!=s[s.size()-i-1]){
      res++;
    }
  }
  cout<<res<<endl;
}

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

int main() {
    int K;
    cin >> K;
    int res=0;
    for (int i=1; i<K; i++) {
        for (int j=i+1; j<=K; j++) {
            if (i%2==0 && j%2!=0) res++;
            else if (i%2!=0 && j%2==0) res++;
        }
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int main() {
    int n; cin >> n;
    ll m = 0, a = 0, r = 0, c = 0, h = 0;
    rep(i, n) {
        string s; cin >> s;
        if (s[0] == 'M') m++;
        else if (s[0] == 'A') a++;
        else if (s[0] == 'R') r++;
        else if (s[0] == 'C') c++;
        else if (s[0] == 'H') h++;
    }

    ll d[5] = {m, a, r, c, h};
    int first[10]  = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
    int second[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
    int third[10]  = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

    ll ans = 0;
    rep(i, 10) {
        ans += d[first[i]] * d[second[i]] * d[third[i]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Data::Dumper;

my @INPUT;
while (<>) {
    chomp;
    push @INPUT, $_;
}

my $N = shift @INPUT;
my @a = split " ", shift @INPUT;

my $change = 0;
my $len = 1;
my $before;
for my $a (@a) {
    if ($before && $before == $a) {
        $len++;
        next;
    }
    $change += int ($len / 2);
    $before = $a;
    $len = 1;
}
$change += int ($len / 2);
say $change;


Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner fc = new FastScanner(System.in);
        N = fc.nextInt();
        A = fc.nextIntArray(N);
        System.out.println(solve());
    }

    static int solve() {
        Map<Integer, Integer> cnt = new HashMap<>();
        for (int a : A) {
            if( cnt.containsKey(a) ) {
                cnt.put(a, cnt.get(a)+1);
            } else {
                cnt.put(a, 1);
            }
        }

        int ans = 0;
        for (int a : cnt.keySet()) {
            int c = cnt.get(a);
            if( c > a ) {
                ans += c - a;

            } else if( a > c ) {
                ans += c;
            }
        }
        return ans;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 43760
#include <iostream>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e4 + 5, INF = 1e9 + 5;

int p[N], a[4*N], b[4*N], la[4*N], lb[4*N];

void updTree(int *tree, int *lazy, int i, int l, int r, int uL, int uR, int ch, int lz = 0)
{
	tree[i] += lz;
	lazy[i] += lz;

	if (uL > r or uR < l)
		return;

	if (l == r)
	{
		tree[i] += ch;
		return;
	}

	if (uL <= l and r <= uR)
	{
		tree[i] += ch;
		lazy[i] += ch;
		return;
	}

	int mid = (l+r)/2;

	updTree(tree, lazy, 2*i, l, mid, uL, uR, ch, lazy[i]);
	updTree(tree, lazy, 2*i + 1, mid+1, r, uL, uR, ch, lazy[i]);

	lazy[i] = 0;
}

int queryTree(int *tree, int *lazy, int i, int l, int r, int q, int lz = 0)
{
	tree[i] += lz;
	lazy[i] += lz;

	if (q < l or q > r)
		return 0;

	if (l == r)
		return tree[i];

	int mid = (l+r)/2;
	int ans = queryTree(tree, lazy, 2*i, l, mid, q, lazy[i]) + queryTree(tree, lazy, 2*i + 1, mid+1, r, q, lazy[i]);
	lazy[i] = 0;

	return ans;
}

int main()
{
	int n;
	cin >> n;

	for (int i = 1; i <= n; ++i)
		cin >> p[i];

	for (int i = 1; i <= n; ++i)
	{
		updTree(a, la, 1, 1, n, i, i, i);
		updTree(b, lb, 1, 1, n, i, i, n-i+1);
	}

	int sum = queryTree(a, la, 1, 1, n, p[1]) + queryTree(b, lb, 1, 1, n, p[1]);

	for (int i = 2; i <= n; ++i)
	{
		int temp = queryTree(a, la, 1, 1, n, p[i]) + queryTree(b, lb, 1, 1, n, p[i]);

		if (temp <= sum)
		{
			int diff = sum - temp + 1;

			updTree(a, la, 1, 1, n, p[i], n, diff);
			updTree(b, lb, 1, 1, n, 1, p[i], diff);

			sum = temp + 2*diff;
		}
	}

	for (int i = 1; i <= n; ++i)
		cout << queryTree(a, la, 1, 1, n, i) << ' ';

	cout << endl;

	for (int i = 1; i <= n; ++i)
		cout << queryTree(b, lb, 1, 1, n, i) << ' ';

	cout << endl;

	// int a_p = INF/2, b_p = INF/2;
	// a[p[1]] = b[p[1]] = INF/2;

	// for (int i = 2; i <= n; ++i)
	// {
	// 	if (p[i] > p[i-1])
	// 	{
	// 		int ch = (p[i]-p[i-1]);

	// 		a[p[i]] = a_p + 2*ch;
	// 		a_p += 2*ch;
	// 		b[p[i]] = b_p - ch;
	// 		b_p -= ch;
	// 	}

	// 	else
	// 	{
	// 		int ch = (p[i-1]-p[i]);

	// 		b[p[i]] = b_p + 2*ch;
	// 		b_p += 2*ch;
	// 		a[p[i]] = a_p - ch;
	// 		a_p -= ch;
	// 	}
	// }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[200009];
ll b[200009],num=0;
ll f(ll x)
{
    return x*(x-1)/2;
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]),b[a[i]]++;
    for(int i=1; i<=n; i++)
        num+=f(b[i]);
    for(int i=1; i<=n; i++)
        printf("%lld\n",num-(b[a[i]]-1));
    return 0;
}



Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MAX = 333;
Int dp[333][333];
const Int INF = 1e15;

void chmin(Int &x,Int y){if(x>y)x=y;};
void chmax(Int &x,Int y){if(x<y)x=y;};

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  vector<Int> s(n+1);
  for(Int i=0;i<n;i++) s[i+1]=s[i]+a[i];
  
  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=INF;

  for(Int i=0;i<n;i++) dp[i][i+1]=0;


  auto calc=[&](Int x,Int y){
    Int res=0,c=0;
    while(x||y||c){
      res+=(x%10)*(y%10)+c;
      c=(x%10)+(y%10)+c>=10;
      x/=10;y/=10;
    }
    return res;
  };
  
  for(Int l=2;l<=n;l++){
    for(Int i=0;i+l<=n;i++){
      Int k=i+l;
      for(Int j=i+1;j<k;j++){
	chmin(dp[i][k],dp[i][j]+dp[j][k]+calc(s[j]-s[i],s[k]-s[j]));
      }
    }    
  }

  cout<<dp[0][n]<<endl;
  return 0;
}



Measured memory_bytes: 4096
#include <stdio.h>
#define bit(n,m)(((n)>>(m))&1)

unsigned long f;
unsigned long m[15];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int k;
		scanf("%d",&k);
		while(k--){
			int t;
			scanf("%d",&t);
			m[i]|=1UL<<t;
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int t,x;
		scanf("%d%d",&t,&x);
		switch(t){
			case 0:
				printf("%lu\n",bit(f,x));
				break;
			case 1:
				f|=m[x];
				break;
			case 2:
				f&=~m[x];
				break;
			case 3:
				f^=m[x];
				break;
			case 4:
				printf("%d\n",(f&m[x])==m[x]);
				break;
			case 5:
				printf("%d\n",(f&m[x])!=0);
				break;
			case 6:
				printf("%d\n",(f&m[x])==0);
				break;
			case 7:
				printf("%d\n",__builtin_popcountll(f&m[x]));
				break;
			case 8:
				printf("%lu\n",f&m[x]);
				break;
		}
	}
}


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

int main(){
    int t;
    cin>>t;
    for(int k=0;k<t;k++){
        int n,d;
        cin>>n>>d;
        if(!(n%2))
            cout<<127*(n-1)+127-d<<endl;
        else
            cout<<127*(n-1)+d<<endl;



    }
    return 0;

}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int a[20111],n,b[20111],p[20111];
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)
	{
		get1(p[i]);
		a[p[i]]=p[i]*30000;
		b[p[i]]=(n-p[i]+1)*30000+i;
	}
	for(int i=1;i<=n;i++)printf("%d ",a[i]);puts("");
	for(int i=1;i<=n;i++)printf("%d ",b[i]);puts("");
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<"\n"
#define mod 1000000007ll
#define inf 9999999999999999ll
#define nl endl
#define modulo 998244353

bool possible(ll r,ll b,ll w,ll x,ll y)
{
    if(r+w<x || b+w<y)
        return false;
    ll x1=max(x-r,0ll);
    ll x2=x-x1;
    if(b+x2<y)
        return false;
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vi p(a),q(b),r(c);
    for(ll i=0;i<a;i++)
        cin>>p[i];
    for(ll i=0;i<b;i++)
        cin>>q[i];
    for(ll i=0;i<c;i++)
        cin>>r[i];
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    vii arr;
    for(ll i=0;i<x;i++)
    {
        arr.pb(mp(p[i],1));
    }
    for(ll i=0;i<y;i++)
    {
        arr.pb(mp(q[i],2));
    }
    for(ll i=0;i<c;i++)
    {
        arr.pb(mp(r[i],3));
    }
    sort(arr.rbegin(),arr.rend());
    ll ans=0;
    for(ll i=0;i<x+y;i++)
        ans+=arr[i].F;
    cout<<ans<<nl;
    return 0;
}


Measured memory_bytes: 12524
#include <bits/stdc++.h>    //vectorを使う
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (a==b){
        if(a!=c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        if(b==c){
            cout << "Yes" << endl;
        }else if(a==c){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

}


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

int n,a[205];
int ans;

int main() {
	scanf("%d",&n);
	for(int i=1;i<=2*n;++i)  scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2)  ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
package main

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

func main() {
	sc = initScanner(os.Stdin)
	n, d := scanInt(sc), scanInt(sc)
	fmt.Println(solve(n, d))
}

func solve(n, d int) int {
	var count int

	ns := make([][]float64, n)
	for i := 0; i < n; i++ {
		ns[i] = scanFloat64Slice(sc, d)
	}

	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			tmp := calc(d, ns[i], ns[j])
			if math.Ceil(tmp) == math.Floor(tmp) {
				count++
			}
		}
	}
	return count
}

func calc(d int, a, b []float64) float64 {
	var sum float64
	for i := 0; i < d; i++ {
		sum += math.Pow(a[i]-b[i], 2)
	}
	return math.Sqrt(sum)
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func scanFloat64Slice(sc *bufio.Scanner, n int) []float64 {
	fs := make([]float64, n)
	for i := 0; i < n; i++ {
		fs[i] = scanFloat64(sc)
	}

	return fs
}

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

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
 
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(y,x%y);
}
 
ll lcm(ll x, ll y){
	return (x*y/gcd(x,y));
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int n,d;
	cin >> n >> d;
	double x[n][d];
	REP(i,n){
		REP(j,d){
			cin >> x[i][j];
		}
	}
	double ans=0;
	double cal=0;
	REP(i,n){
		REP(j,n){
			if(i!=j){
				REP(k,d){
					cal+=pow(x[i][k]-x[j][k],2);
				}
				cal=sqrt(cal);
				if(cal-(int)cal==0.0) ans++;
				cal=0;
			}
		}
	}
	cout << ans/2 << endl;
/////////////////////////////////////////////
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
const int MAXN=100010;
long long f[110][MAXN];
int n,w[110],v[110];

int main(){
	memset(f,0x7f,sizeof(f));
	long long p;scanf("%d%lld",&n,&p);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&w[i],&v[i]);
	f[0][0]=0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=100000;j++){
			if(j-v[i]<0)
				f[i][j]=f[i-1][j];
			else
				f[i][j]=std::min(f[i-1][j],f[i-1][j-v[i]]+w[i]);
			// printf("(%d %d)%lld\n",i,j,f[i][j]);
		}
	for(int i=100000;~i;i--)
		if(f[n][i]<=p){
			printf("%d\n",i);
			return 0;
		}
	return 0;
}

Measured memory_bytes: 86144
h,w=map(int,input().split())
table=[]
for _ in range(h):
  a=input()
  b=[]
  for i in range(w):
    if a[i]=='#':
      b.append(1)
    else:
      b.append(0)
  table.append(b)
ans=0
for i in range(h):
  ans+=sum(table[i])
if ans==h+w-1:
  print('Possible')
else:
  print('Impossible')

 

Measured memory_bytes: 62036
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int gcnt = 0;
		int pcnt = 0;
		int point = 0;
		for (char you : line.toCharArray()) {
			char me;
			if (gcnt == pcnt) {
				me = 'g';
				gcnt++;
			} else {
				me = 'p';
				pcnt++;
			}
			if (you == 'g') {
				if (me == 'p') {
					point++;
				}
			} else {
				if (me == 'g') {
					point--;
				}
			}
		}
		System.out.println(point);
		long end = System.currentTimeMillis();
		//System.out.println((end-start) + "ms");
	}

}


Measured memory_bytes: 10964
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;

class Unionfind {
    vector<int> parent;
    vector<int> rank;
    vector<int> size;
public:
    Unionfind(const int n) {
        parent.reserve(n);
        rank.reserve(n);
        size.reserve(n);
        for(int i=0; i<n; i++) {
            parent[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    // recursively find root element
    int find(const int x) {
        if (parent[x] == x) return x;
        // reconnect root and x
        return parent[x] = find(parent[x]);
    }
    // merge x and y trees, < O(log n)
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        // union by rank
        if (rank[x] < rank[y]) {
            parent[x] = y;
            size[y] += size[x];
        }
        else {
            parent[y] = x;
            if (rank[x] == rank[y]) ++rank[x];
            size[x] += size[y];
        }
    }
    bool isUnited(ll x, ll y) { return find(x) == find(y); }
    // get size of tree
    int getsize(int x) {
        return (size[find(x)]);
    }

};

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    int l, r;
    Unionfind uf(N);
    vector<set<int> > a(N);
    rep(i, M) {
        cin >> l >> r;
        --l, --r;
        uf.unite(l, r);
        a[l].insert(r);
        a[r].insert(l);
    }
    vector<set<int> > b(N);
    rep(i, K) {
        cin >> l >> r;
        --l, --r;
        b[l].insert(r);
        b[r].insert(l);
    }
    int ans;
    rep(i, N) {
        ans = uf.getsize(i) - 1;
        set<int> block = b[i];
        for(auto &j: a[i]) ans--;
        for(auto &j: b[i]) if(uf.isUnited(i, j)) ans--;
        cout << ans << ' ';
    }
    cout << endl;




	return 0;
}


Measured memory_bytes: 30080
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::random_device dev;
std::mt19937 rnd(dev());
bool solve(int n, const std::string &s, int len) {
	int mod = std::uniform_int_distribution<>(800000000, 1000000000)(rnd);
	int base = std::uniform_int_distribution<>(800000000, 1000000000)(rnd);
	std::vector<int> hashed(n + 1);
	std::vector<int> power(n + 1);
	hashed[0] = 0;
	power[0] = 1;
	for (int i = 0; i < n; i++) {
		power[i + 1] = (int64_t) power[i] * base % mod;
		hashed[i + 1] = (int64_t) hashed[i] * base % mod + s[i];
		if (hashed[i + 1] >= mod) hashed[i + 1] -= mod;
	}
	/*
	std::vector<std::vector<int> > table(n, std::vector<int>(n + 1));
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			table[i][j] = (hashed[j] - (int64_t) hashed[i] * power[j - i] % mod + mod) % mod;
		}
	}*/
	int res = 0;
	
	std::vector<std::pair<int, int> > tmp;
	tmp.reserve(n - len + 1);
	for (int j = len; j <= n; j++) // upper
		tmp.push_back({(hashed[j] - (int64_t) hashed[j - len] * power[len] % mod + mod) % mod, j});
	std::sort(tmp.begin(), tmp.end());
	int start = tmp[0].second;
	for (int j = 0; j < (int) tmp.size(); j++) {
		if (j + 1 >= (int) tmp.size() || tmp[j].first != tmp[j + 1].first) {
			if (tmp[j].second - start >= len) return true;
			if (j + 1 < (int) tmp.size()) start = tmp[j + 1].second;
		}
	}
	return false;
	/*
	std::vector<std::unordered_set<int> > hash(n + 1); // [len]
	int res = 0;
	for (int j = n; j; j--) {
		for (int k = j + 1; k <= n; k++) hash[k - j].insert(table[j][k]);
		for (int i = 0; i < j; i++)
			if (hash[j - i].count(table[i][j])) res = std::max(res, j - i);
	}
	return res;*/
}

int main() {
	int n = ri();
	std::string s;
	std::cin >> s;
	for (auto &c : s) c -= 'a';
	clock_t r0 = clock();
	
	int res = 1000000000;
	int l = -1;
	int r = n / 2 + 1;
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		bool res = true;
		for (int i = 0; i < 100; i++) if (!solve(n, s, m)) res = false;
		if (res) l = m;
		else r = m;
	}
	clock_t r1 = clock();
	std::cout << l << std::endl;
	std::cerr << (double) (r1 - r0) / CLOCKS_PER_SEC << std::endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//Get the highest value and key from a map.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

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

  for (int i = 0; i < s.size(); i++) {
    if (i == (k - 1)) {
      s[i] = tolower(s[i]);
    }
  }

  cout << s << endl;
  return 0;
}


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

int main(){
    
    int M,N;

    int sum=0;

    cin>>N>>M;

    vector <int> A(N);

    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        sum=sum+A.at(i);
    }

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


    if(A.at(N-M)*M*4>=sum){
        cout << "Yes" << endl;
    }else{

        cout << "No" << endl;

    }


} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    ll n,k;cin>>n>>k;
    ll sq=(ll)sqrt(n);
    ll dp[k][sq+1];memset(dp,0,sizeof(dp));
    ll ep[k][sq+1];memset(ep,0,sizeof(ep));
    rep(j,1,sq)dp[0][j]=1;
    rep(j,1,sq){
        if(j<=sq-1){
            ep[0][j]=n/j-n/(j+1);
        }else{
            rep(x,sq+1,n/sq){
                ep[0][j]++;
            }
        }
    }
    rep(j,1,sq){
        Add(dp[0][j],dp[0][j-1]);
        Add(ep[0][j],ep[0][j-1]);
    }
    rep(i,0,k-2){
        rep(k,1,sq){
            dp[i+1][k]=dp[i][sq];
            ep[i+1][k]=mod((ep[0][k]-ep[0][k-1])*dp[i][k]);
            /*
            rep(j,1,sq){
                Add(dp[i+1][k],dp[i][j]);
                if(k>=j)Add(ep[i+1][k],dp[i][j]*ep[0][k]);
            }*/
        }
        rep(k,1,sq){
            Add(dp[i+1][k],ep[i][sq]-ep[i][k-1]);
            /*
            rep(j,1,sq){
                if(k<=j)Add(dp[i+1][k],ep[i][j]);
            }*/
        }
        rep(j,1,sq){
            Add(dp[i+1][j],dp[i+1][j-1]);
            Add(ep[i+1][j],ep[i+1][j-1]);
        }
    }
    /*
    rep(i,0,k-1){
        rep(j,0,sq)cout<<dp[i][j]<<" ";cout<<endl;
    }cout<<endl;
    rep(i,0,k-1){
        rep(j,0,sq)cout<<ep[i][j]<<" ";cout<<endl;
    }cout<<endl;
    */
    ll ans=dp[k-1][sq]+ep[k-1][sq];
    cout<<mod(ans)<<endl;
    
    return 0;
}
/*
 10 3
 0 1 2 3
 0 10 15 18
 0 58 111 150

 0 5 7 7
 0 5 19 40
 0 50 155 281

 431
 
 
 1 1 1
 10 5 3
 27 22 18

 5 2 0
 5 4 0
 50 30 0
 */


Measured memory_bytes: 49664
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (declare #.OPT)
  (let* ((unit-r (read))
         (unit-g (read))
         (unit-b (read))
         (n (read))
         (res 0))
    (declare (uint16 unit-r unit-g unit-b n)
             (uint32 res))
    (loop for r to n by unit-r
          do (loop for g to (- n r) by unit-g
                   for rest = (- n r g)
                   when (zerop (mod rest unit-b))
                   do (incf res)))
    (println res)))
 
#-swank(main)


Measured memory_bytes: 16100