akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, C, K; cin >> N >> C >> K;
	vi TS (N);
	F0R(i, N) cin >> TS[i];
	sort(TS.begin(), TS.end());
	int leave = TS[0] + K;
	int people = 0;
	int total = 0;
	for (int t : TS) {
		if (t > leave || people == C) {
			++total;
			people = 0;
			leave = t + K;
		}
		++people;
		leave = min(leave, t + K);
	}
	if (people > 0) ++total;
	print(total);
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
const int maxn=1101000;
struct edge{
	int to,next,dis;
}e[maxn*4];
int tot,head[maxn];
void add(int u,int v,int w){
	e[++tot].to=v;
	e[tot].dis=w;
	e[tot].next=head[u];
	head[u]=tot;
}
int dis[maxn],b[maxn];
int n,m,cnt;
void spfa(int s){
	memset(dis,0x3f,sizeof dis);
	memset(b,0,sizeof b);
	queue<int>q;
	dis[s]=0,b[s]=1;q.push(s);
	while(!q.empty()){
		s=q.front();q.pop();b[s]=0;
		for(int i=head[s];i;i=e[i].next){
			int to=e[i].to;
			if(dis[to]>dis[s]+e[i].dis){
				dis[to]=dis[s]+e[i].dis;
				if(!b[to]){q.push(to),b[to]=1;}
			}
		}
	}
}
map<int,int>mp[maxn];
int find(int x,int y){
	if(mp[x][y]) return mp[x][y];
	else mp[x][y]=++cnt;
	return mp[x][y];
}
int main(){
	n=read(),m=read();
	cnt=n;
	for(int i=1;i<=m;i++){
		int x=read(),y=read(),w=read();
		int xx=find(x,w),yy=find(y,w);
		//add(u,n+w,1);add(n+w,u,1);
		//add(v,n+w,1);add(n+w,v,1);
		add(xx,yy,0);add(yy,xx,0);
		add(x,xx,1),add(y,yy,1);
		add(xx,x,1),add(yy,y,1);
	}
	spfa(1);
	if(dis[n]>=0x3f3f3f3f){
		printf("-1\n");
		return 0;
	}
	printf("%d\n",dis[n]/2);
	return 0;
}

Measured memory_bytes: 99328
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			list.add(sc.nextInt());
		}
		list.sort(Comparator.reverseOrder());
		int a = 0;
		int b = 0;
		for(int i = 0; i < list.size(); i++) {
			if(i % 2 == 0) {
				a += list.get(i);
			} else {
				b += list.get(i);
			}
		}
		System.out.println(a - b);
	}

}


Measured memory_bytes: 22996
#include <iostream>

int main()
{
    int n, m, l;

    std::cin >> n >> m >> l;

    int A[n][m] = {};
    int B[m][l] = {};
    long long pro[n][l] = {};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            std::cin >> A[i][j];
        }
    }

    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < l; j++)
        {
            std::cin >> B[i][j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            for (int k = 0; k < l; k++)
            {
                pro[i][k] += A[i][j] * B[j][k];
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < l; j++)
        {
            std::cout << pro[i][j];
            if (j < l - 1)
                std::cout << " ";
        }
        std::cout << std::endl;
    }
}


Measured memory_bytes: 3176
#include "bits/stdc++.h"
using namespace std;


int main() {

	vector<int> vtrees;
	int N, K;
	int height;
	int difference;
	int min_difference;

	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> height;
		vtrees.push_back(height);
	}

	sort(vtrees.begin(), vtrees.end(), greater<int>());
	min_difference = vtrees.at(0);

	for (int i = 0; i < N - K + 1; i++) {
		difference = vtrees.at(i) - vtrees.at(i + K - 1);
		if (difference < min_difference) {
			min_difference = difference;
		}

	}

	cout << min_difference << endl;

	return 0;

}


Measured memory_bytes: 892
from itertools import combinations
N = int(input())
if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
elif N==2:
    print("No")
elif N==3:
    print("Yes")
    print(3)
    print(2,1,2)
    print(2,1,3)
    print(2,2,3)
else:
    flg = 0
    for i in range(4,int((3*N)**0.5)+2):
        if N==(i*(i-1))//2:
            flg=1
            K = i
            break
    if flg==0:
        print("No")
    else:
        S = {i:[] for i in range(K)}
        for j,x in enumerate(combinations(range(K),2)):
            j += 1
            i0,i1 = x[0],x[1]
            S[i0].append(j)
            S[i1].append(j)
        print("Yes")
        print(K)
        for i in range(K):
            print(len(S[i]),*S[i])

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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    int N,M;
    COMinit();
    cin>>N>>M;
    auto vec=prime_factorize(M);
    ll res=1;
    for(auto pa : vec){
        int num=pa.second;
        ll tmp=COM(num+N-1,N-1);
        res=(res*tmp)%MOD;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <string.h>
 
int main(){
    char w[10], t[1000];
    int i, count = 0;
     
    scanf("%s", w);
    while(scanf("%s", t)){
        if (strcmp(t, "END_OF_TEXT") == 0) break;
        for (i = 0; i < strlen(t); i++) t[i] = tolower(t[i]);
        if (strcmp(w,t) == 0) count++;
    }
    printf("%d\n", count);
     
    return 0;
}
 

 

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int a;
	string s;
	cin>>a>>s;
	if(a>=3200)cout<<s<<endl;
	else cout<<"red"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by zzt on 17-1-17.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();

        System.out.println(a*b*c==175&&a+b+c==17?"YES":"NO");
    }
}

Measured memory_bytes: 9676
from collections import Counter
import math
from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
# for i in range(int(input())):
# arr = list(map(int, input().split()))
# a,b= map(int, input().split())
import bisect
#for i in range(int(input())):
def knapSack(W, wt, val, n):
    K = [[0 for x in range(W + 1)] for x in range(n + 1)]

    # Build table K[][] in bottom up manner
    for i in range(n + 1):
        for w in range(W + 1):
            if i == 0 or w == 0:
                K[i][w] = 0
            elif wt[i - 1] <= w:
                K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w])
            else:
                K[i][w] = K[i - 1][w]

    return K[n][W]


n, c = map(int, input().split())
w = []
v = []
for i in range(n):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)
print(knapSack(c, w, v, n))

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

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

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

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

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

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

void debug_out() { cerr << endl; }

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

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

void test_case() {
  int n;
  cin >> n;
  vector<int> A(n + 2);
  for (int i = 1; i <= n + 1; ++i) {
    cin >> A[i];
  }
  vector<int> B(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> B[i];
  }
  long long def = 0;
  for (int i = 1; i <= n; ++i) {
    auto defeat = [&](int j) {
      int ded = min(B[i], A[j]);
      def += ded;
      B[i] -= ded;
      A[j] -= ded;
    };
    defeat(i);
    defeat(i + 1);
  }
  cout << def << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 1024
import copy


def main():
    """
    自己ループを含まない
    二重辺を含まない: 点AからBへの辺は１つ(以下)
    連結グラフ：任意の点から任意の点に移動できる

    ある辺を取り除くと非連結になる場合、その辺を橋という
    →橋がなくなるとたどり着けない

    N: <=50
    M: <= 50

    ある辺を取り除いてすべてのノードにたどり着けるか
    すべてのノードを列挙する
    ノードを辿ってみる（探索アルゴリズム）
    たどれたらたどれたノードをため込む
    終わったら列挙したノードと比較して同じならOK
    """
    N, M = map(int, input().split())
    e = set()
    for _ in range(M):
        a, b = map(int, input().split())
        e.add((a, b))

    ans = 0
    for k in e:
        searched = set()
        e_copy = copy.deepcopy(e)
        e_copy.remove(k)

        def dfs(v1):
            searched.add(v1)
            for v2 in range(1, N + 1):
                if v2 in searched:
                    continue
                if (v1, v2) in e_copy or \
                        (v2, v1) in e_copy:
                    dfs(v2)

        dfs(1)
        if len(searched) < N:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<tuple>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int n, ma, mb;
int a[40], b[40], c[40];
int mincost = INF;

void solve(tuple<int, int, int> t, int k){
	if(k == n){
		int cost = get<2>(t);
		if((double)get<0>(t) / get<1>(t) == (double)ma / mb && cost < mincost){
			mincost = cost;
		}
		return;
	}
	
	solve(t, k+1);
	
	if(get<2>(t) + c[k] > mincost) return;
	get<0>(t) += a[k];
	get<1>(t) += b[k];
	get<2>(t) += c[k];
	solve(t, k+1);
}

signed main(){
	cin >> n >> ma >> mb;
	rep(n){
		cin >> a[i] >> b[i] >> c[i];
	}
	solve(make_tuple(0, 0, 0), 0);
	if(mincost == INF){
		cout << -1;
	}else{
		cout << mincost;
	}
}


Measured memory_bytes: 256
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)1e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n;
vector<int> g[5011], dp[1011], d[1011];
int x[5011], y[5011];
void dfs(int v = 1, int p = 1){
	dp[v].resize(x[v] + 1);
	d[v].resize(x[v] + 1);
	for(int i = 0; i <= x[v]; i ++){
		dp[v][i] = inf;
	}
	dp[v][0] = 0;
	for(int j = 0; j < g[v].sz(); j ++){
		int to = g[v][j];
		if(to == p)
			continue;
		dfs(to, v);
		d[v] = dp[v];
		for(int i = 0; i <= x[v]; i ++){
			dp[v][i] = inf;
		}
		int a = x[to], b = y[to];
		for(int i = 0; i <= x[v]; i ++){
			if(i + a <= x[v])
				dp[v][i + a] = min(dp[v][i + a], d[v][i] + b);
			if(i + b <= x[v])
				dp[v][i + b] = min(dp[v][i + b], d[v][i] + a);
		} 
	}
	y[v] = inf;
	for(int i = 0; i <= x[v]; i ++){
		y[v] = min(y[v], dp[v][i]);
	}
}
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n;
	for(int i = 2; i <= n; i ++){
		int a;
		cin >> a;
		g[a].pb(i);
		g[i].pb(a);
	}       
	for(int i = 1; i <= n; i ++)
		cin >> x[i];
	dfs();
	if(y[1] < inf){
		cout << "POSSIBLE";
	}else
		cout << "IMPOSSIBLE";
	return 0;
}

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

int main(){
	int a, b, k, c, i;
	cin >> a >> b >> k;
	c = 0;
	for (i = min(a, b); i > 0; --i){
		if (a % i == 0 && b % i == 0) c++;
		if (c == k) break;
	}
	if (c == k) cout << i;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,h;
	bool a[4][13];
	char t;
	for(int i=0;i<4;i++)
		for(int j=0;j<13;j++)
			a[i][j]=false;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t>>h;
		if(t=='S')
			a[0][h-1]=true;
		if(t=='H')
			a[1][h-1]=true;
		if(t=='C')
			a[2][h-1]=true;
		if(t=='D')
			a[3][h-1]=true;
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			if(a[i][j]==false){
				if(i==0)
					cout<<"S "<<j+1<<endl;
				if(i==1)
					cout<<"H "<<j+1<<endl;
				if(i==2)
					cout<<"C "<<j+1<<endl;
				if(i==3)
					cout<<"D "<<j+1<<endl;
			}
		}
	}
	return 0;
}

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

int main(void){
  int A,B,X;
  scanf("%d %d %d",&A,&B,&X);
  if(A <= X && X <= A+B ){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}


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

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();

  println!("{}", (a + b) / 2 + (a + b) % 2);
}



Measured memory_bytes: 4352
import collections
import itertools
import operator


class UnionFind:
    def __init__(self, x):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)
        self.size = collections.defaultdict(lambda: 1)
        if x is not None:
            for elem in range(x+1):
                _, _, _ = self.parent[elem], self.rank[elem],self.size[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not self.are_same(x,y):
            xx = self.size[x]
            yy = self.size[y]
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += xx
            else:
                self.parent[y] = x
                self.size[x] += yy
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

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

    def are_same(self, x, y):
        '''print(x,y,self.find(x),self.find(y),self.find(x) == self.find(y))'''
        return self.find(x) == self.find(y)

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]

a,b = map(int,input().split())
su = 0
c = list(map(int,input().split()))
uf = UnionFind(a)
for i in range(b):
    n,m = map(int,input().split())
    uf.unite(n,m)

aaa = list(uf.grouper())

for i in range(len(aaa)):
    for j in range(len(aaa[i])):
        if uf.are_same(c[aaa[i][j]-1],aaa[i][j]):
            su += 1

print(su)



Measured memory_bytes: 48780
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n;
	string s;
	cin >> n >> s;
	vector<vector<Int>> dp(n, vector<Int>(n, -1));
	for(Int i=0; i<n; ++i)
		if(s[i] == s[n-1])
			dp[i][n-1] = 1;
	for(Int i=n-2; i>0; --i)
		for(Int j=i-1; j>=0; --j)
			if(s[i] == s[j])
				dp[j][i] = 1+max((Int)0, dp[j+1][i+1]);
	Int ans = 0;
	for(Int i=0; i<n; ++i)
		for(Int j=0; j<n; ++j)
			ans = max(ans, min(dp[i][j], j-i));
	cout << ans << "\n";
//	for(Int i=0; i<n; ++i)
//		for(Int j=0; j<n; ++j)
//			cout << dp[i][j] << " \n"[j+1==n];
}

Measured memory_bytes: 195840
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits>
#include <map>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>

typedef long long li;
using namespace std;

li max(li a, li b) {
    return a > b ? a : b;
}

li max(li a, li b, li c) {
    return max(a, max(b, c));
}

li max(li a, li b, li c, li d) {
    return max(a, max(b, max(c, d)));
}

li max(li a, li b, li c, li d, li e) {
    return max(a, max(b, max(c, max(d, e))));
}


li pow_mod(li n, li e, li mod)
{
    li r = 1;
    
    while(e > 0)
    {
        if(e & 1)
            r *= n;
            r %= mod;
        
        n *= n;
        n %= mod;
        e >>= 1;
    }
    
    return r;
}


int main() {
    li h, s = 0, m = 1;
    cin >> h;
    
    while(h > 0) {
        s += m;
        h /= 2;
        m *= 2;
    }
    
    cout << s << endl;
    
    return 0;
}


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

int main()
{
    int n;
    scanf("%d", &n);

    int x[n], y[n];
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &x[i]);
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &y[i]);
    }


    double s_1 = 0;
    for (i = 0; i < n; i++) {
        s_1 += fabs(x[i] - y[i]);
    }
    double d_1 = s_1;
    printf("%lf\n",d_1);


    double s_2 = 0;
    for (i = 0; i < n; i++) {
        s_2 += pow(fabs(x[i] - y[i]), 2);
    }
    double d_2 = pow(s_2, ((double)1 / 2));
    printf("%lf\n",d_2);


    double s_3 = 0;
    for (i = 0; i < n; i++) {
        s_3 += pow(fabs(x[i] - y[i]), 3);
    }
    double d_3 =  pow(s_3, ((double)1 / 3));
    printf("%lf\n",d_3);


    double max = 0;
    for (i = 0; i < n; i++) {
        if (max < fabs(x[i] - y[i])) {
            max = fabs(x[i] - y[i]);
        }
    }
    double d_inf = max;
    printf("%lf\n",d_inf);

    return 0;
}



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

void lcs(string s1,string s2,int l1,int l2)
{
    int dp[l1+5][l2+5];

    memset(dp,0,sizeof(dp));
    for(int i=1; i<=l1; i++)
    {
        for(int j=1; j<=l2; j++)
        {
            if(s1[i-1] == s2[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int index=dp[l1][l2];
    char LCS[index+5];
    LCS[index]='\0';
    int i=l1;
    int j=l2;

    while (i > 0 && j > 0)
    {
        if (s1[i-1] == s2[j-1])
        {
            LCS[index-1] = s1[i-1];
            i--;
            j--;
            index--;
        }
        else if (dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }

    cout<<LCS<<endl;
}

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int l1=s1.length();
    int l2=s2.length();
    lcs(s1,s2,l1,l2);
}


Measured memory_bytes: 35584
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int n;
	int a[100000+10],b[100000+10];
	LL res=0;
	scanf("%d",&n);
	rb(i,1,n+1){
		scanf("%d",&a[i]);
	}rb(i,1,n){
		scanf("%d",&b[i]);
	}
	rb(i,1,n){
		if(a[i]<b[i]){
			b[i]-=a[i];
			res+=a[i];
			if(a[i+1]<b[i]){
				res+=a[i+1];
				a[i+1]=0; 
			}
			else{
				a[i+1]-=b[i];
				res+=b[i];
			}
		}
		else{
			res+=b[i];
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int c=1;c<N;c++){
        int tmp = N -c;
        float x = sqrt(tmp);

        for(int b=1;b<x;b++){
            if(tmp % b == 0) ans+=2;
        }

        if(floor(x) == x){
            if(tmp % (int)x == 0) ans +=1;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    int n;
    cin>>n;
    cin>>s;
    long long ans=1,cnt=0,temp=0,mod=1000000007;
    if(s[0]=='W'||s[s.length()-1]=='W'){
        cout<<0;
        return 0;
    }
    for(int i=0;i<s.length();i++){
        if((cnt&1)^(s[i]=='B')) cnt++;
        else{
            ans=ans*cnt%mod;
            cnt--;
            temp++;
        }
    }
    for(int i=1;i<=n;i++){
        ans=ans*i%mod;
    }
    if(temp==n) cout<<ans;
    else cout<<0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		int a;
		int b = 0;
		Scanner data1 = new Scanner(System.in);
	    a = data1.nextInt();
	    b = data1.nextInt();
		if(a < b){
			System.out.println("a < b");
		}else if(a > b){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
	}

}

Measured memory_bytes: 25976
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll H;
  cin >> H;
  ll ans=1;
  ll cnt=1;
  while(H>1){
    H=H/2;
    cnt*=2;
    ans+=cnt;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> D(M);
  for(int i=0;i<M;i++){
    cin>>D[i];
    D[i]--;
  }

  vector<int> darkness(N,-1);
  for(int i=0;i<M;i++){
    darkness[D[i]]=i;
  }
  
  vector<vector<int> > v(N,vector<int>(K));
  for(int i=0;i<N;i++){
    for(int j=0;j<K;j++){
      cin>>v[i][j];
      v[i][j]--;
    }
  }

  vector<int> d(1<<M, INF);
  queue<int> que;
  que.push((1<<M)-1);
  d[(1<<M)-1]=0;
  while(que.size()){
    int now=que.front();que.pop();
    for(int k=0;k<K;k++){
      int next_mask=0;
      for(int m=0;m<M;m++){
	if(now & (1<<m)){
	  int next= v[D[m]][k];
	  if(darkness[next]<0)continue;
	  next_mask |= (1 << darkness[next]);
	  // cout<<next_mask<<endl;
	}
      }

      if(d[next_mask]>d[now]+1){
	d[next_mask]=d[now]+1;
	que.push(next_mask);
      }
      if(next_mask==0){
	cout<<d[0]<<endl;
	return 0;
      }
    }
  }
  cout<<d[0]<<endl;
  return 0;
}



Measured memory_bytes: 3468
#include <iostream>
using namespace std;
int main() {
	int a, b,ans=0;
	cin >> a >> b;

	for (int i = a; i <= b; i++) {
		if (i % 10 == (i - i % 10000) / 10000 && (i % 100 - i % 10) / 10 == (i % 10000 - i % 1000) / 1000) ans += 1;
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using static System.Math;
using System;

public class hello
{
    public static int sL;
    public static string s;
    public static void Main()
    {
        s = Console.ReadLine().Trim();
        sL = s.Length;
        var c1 = calc1();
        if (c1 == 0) { Console.WriteLine(0); goto exit; }
        var c2 = calc2();
        Console.WriteLine(Min(c1, c2));
    exit:;
    }
    static int calc2()
    {
        var p = 0;
        var t2 = 0;
        var t1 = 10;
        while (p < sL)
        {
            if (s[p] == '1')
            {
                if (p + 1 < sL)
                    t2 = Max(t2, 10 + int.Parse(s[p + 1].ToString()));
                p += 2;
            }
            else
            {
                t1 = Min(t1, int.Parse(s[p].ToString()));
                p++;
            }
        }
        if (t1 == 10 | t2 == 0) return 10;
        else return t2 - t1;
    }
    static int getdev1()
    {
        var smax = 0;
        var smin = 10;
        for (int i = 1; i <= 9; i++)
        {
            if (s.Contains(i.ToString()))
            {
                smax = Max(smax, i);
                smin = Min(smin, i);
            }
        }
        return smax - smin;
    }
    static int getdevN(int n, int dev1)
    {
        var temp = new string[n];
        for (int i = 0; i < n; i++)
        {
            var w = sL / n;
            var t = s.Substring(w * i, w);
            temp[i] = t;
        }

        StringComparer cmp = StringComparer.OrdinalIgnoreCase;
        Array.Sort(temp, cmp);

        var ch = checkBI(temp[n - 1], temp[0]);
        if (ch == -1) return -1;
        if (ch < dev1) return ch;
        else return -1;
    }
    static int checkBI (string a , string b)
    {
        var aL = a.Length;
        if (aL == 2)
        {
            var t = int.Parse(a) - int.Parse(b);
            return t <= 7 ? t : -1;
        }

        var a1 = a.Substring(0, aL - 2);
        var b1 = b.Substring(0, aL - 2);
        if (a1 != b1) return -1;
        var a2 = int.Parse(a.Substring(aL - 2));
        var b2 = int.Parse(b.Substring(aL - 2));
        var t2 = a2 - b2;
        return t2 <= 7 ? t2 : -1;
    }
    static int calc1()
    {
        var dev = new List<int>();
        for (int i = 2; i * i <= sL; i++)
        {
            if (sL % i == 0)
            {
                dev.Add(i);
                if (sL / i != i) dev.Add(sL / i);
            }
        }
        var dev1 = getdev1();
        var ans = dev1;
        foreach (var x in dev)
        {
            var t = getdevN(x, dev1);
            if (t != -1) ans = Min(ans, t);
            if (ans == 0) return 0;
        }
        return ans;
    }
}



Measured memory_bytes: 38280
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n, m, c;
    cin >> n >> m >> c;
    vi b(m);

    fo(i, m) cin >> b[i];

    int ans = 0;
    fo(i, n) {
        int cont = 0;
        fo(j, m) {
            int a;
            cin >> a;
            cont += a * b[j];
        }
        if ( cont + c > 0 ) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut s = String::new();

    match std::io::stdin().read_line(&mut s) {
        Ok(_) => println!(
            "{}",
            match s.trim() {
                "ARC" => "ABC",
                _ => "ARC",
            }
        ),
        Err(e) => panic!(e),
    }
}


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

struct dat {
  string name;
  int id, point;
};

int n;
vector<dat> v;

int main() {
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].name >> v[i].point;
    v[i].id = i + 1;
  }
  // auto は function<bool(dat, dat)>
  auto f = [](dat l, dat r) {
    if (l.name != r.name) return l.name < r.name;
    return l.point > r.point;
  };
  sort(v.begin(), v.end(), f);
  for (int i = 0; i < n; ++i) cout << v[i].id << endl;
  return 0;
}


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

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

    int count = 0;

    for(int a=0; a<30 ; a++){
        for(int b=0; b<20 ; b++){
            int total = 4*a + 7*b;
            if(total == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String slimeSequence = sc.nextLine();
		
		sc.close();
		int numOfSlime = n;
		char beforeChar = 'A';
		
		for(int i = 0; i < n ; i++) {
			char nowChar = slimeSequence.charAt(i);
			if(nowChar == beforeChar) {
				numOfSlime--;
			}
			beforeChar = nowChar;
		}
		
		System.out.println(numOfSlime);
	}

}

Measured memory_bytes: 27460
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int n;

  cin>>n;

  cout<<(800*n)-(200*(n/15))<<endl;
      
  return 0;

}




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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a >= b && a >= c) {
        cout << (b+c) << endl;
    } else if(b >= a && b >= c) {
        cout << (a+c) << endl;
    } else {
        cout << (a+b) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b;
  
  scanf("%d %d",&a,&b);
  int tmp = a+b;
  if(tmp<a-b){tmp=a-b;}
  if(tmp<a*b){tmp=a*b;}
  printf("%d\n",tmp);
  
  return 0;
}

Measured memory_bytes: 128
n=int(input())
lists=list(map(int,input().split()))
x_1=0
for _ in range(n):
    if _%2==0:
        x_1+=lists[_]
    else:
        x_1-=lists[_]
        
anslist=[]
anslist.append(x_1)
for i in range(n-1):
    x=2*lists[i]-anslist[-1]
    anslist.append(x)
print(*anslist)

Measured memory_bytes: 14032
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    ss = [input() for _ in range(n)]

    alphabets = [chr(ord('a') + x) for x in range(26)]

    ans = [0 for _ in range(26)]
    for i, a in enumerate(alphabets):
        ans[i] = min([s.count(a) for s in ss])

    ans_str = ''

    for a, cnt in zip(alphabets, ans):
        ans_str += a * cnt

    print(ans_str)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
cbaa
daacc
acacac"""
        output = """aac"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3
a
aa
b"""
        output = """"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main(
    resolve()


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll MOD=1e9 + 7;

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

    ll m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;

    if(m1!=m2)cout<<1;
    else cout<<0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;



void solve()
{
  ll n,w,x,y,ans=0;
  cin>>n>>w;
  std::vector<ll> dp(w+1);
  for (int i = 0; i < n; ++i)
  {
    cin>>x>>y;
  
    for(ll j=w-x;j>=0;j-- )
    {
    dp[j+x] = max(dp[j+x],dp[j] + y);
    }
  }
  for (int i = 1; i <=w; ++i)
  {
    ans = max(dp[i],ans);
    //c(dp[i]);
  }
c(ans);
}

signed main(){
  
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 1024
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, m, now = 0, l, r, ans = 0;
  scanf("%lld%lld", &n, &m);
  ll sum[n + 1];
  for(i = 0; i < n; ++i) sum[i] = 0;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &l, &r);
    sum[--l]++, sum[r]--;
  }
  for(i = 0; i < n; ++i) {
    now += sum[i];
    if(now == m) ans++;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		set<int> S;
		S.insert(-1); S.insert(N);
		vector<pair<UL, UL>> A2(N);
		rep(i, N) A2[i] = { A[i], i };
		sort(A2.begin(), A2.end());
		ULL ans = 0;
		for (int i = 0; i < N; i++) {
			int p = A2[i].second;
			int l = *(--S.upper_bound(p));
			int r = *S.upper_bound(p);
			//cout << p << " " << l << " " << r << " ";
			ULL dance = (ULL)A[p] * (p - l) * (r - p);
			ans += dance;
			S.insert(p);
			//cout << dance << endl;
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main()
{
   int a,b,c;
  
   cin >>a>>b>>c;
   if((a+b)==c) cout <<"Yes";
   else if((b+c)==a)  cout <<"Yes";
   else if((c+a)==b)  cout <<"Yes";
   
   else
     cout << "No"<< endl;
}

Measured memory_bytes: 256
Form = ["((aeb)f(cgd))", "((ae(bfc))gd)", "(ae((bfc)gd))", "(((aeb)fc)gd)", "(ae(bf(cgd)))"]
Exp = ["+", "-", "*"]
def solve(num)
  num.permutation(4).to_a.each do |a, b, c, d| 
    Exp.repeated_permutation(3).to_a.each do |e, f, g|
      h = {}
      [a,b,c,d,e,f,g].zip(("a".."g").to_a).each{|i, j| h[j] = i }
      Form.each do |form|
        if eval(ret = form.gsub(/a|b|c|d|e|f|g/, h)) == 10
          puts ret
          return true
        end
      end
    end
  end
  false
end
loop do
  num = gets.split
  break if num[0] == "0"
  p 0 unless solve(num)
end

Measured memory_bytes: 9576
s=input()
k=int(input())
lists=[]
flag=False
for i in range(len(s)):
    lists.append(s[i]) 
    
if len(s)>=2 and len(set(lists))>=2:
    lists.append("good")
    sums=0
    cnt=1
    ind=[]
    for j in range(len(s)):
        if lists[j]!=lists[j+1]:
            if cnt==1:
                cnt=1
            elif cnt>=2:
                ind.append(cnt)
                sums+=(cnt//2)
                cnt=1
        elif lists[j]==lists[j+1]:
            cnt+=1  
    del lists[-1]
    if lists[-1]==lists[-2] and ind[-1]%2==0:

        pass
         
    if lists[-1]==lists[-2] and ind[-1]%2!=0:

        if lists[-1]==lists[0] and (lists[0]!=lists[1]or( lists[0]==lists[1] and ind[0]%2!=0)) :
            sums+=1
            flag=True
        else:
            pass
    if lists[-1]!=lists[-1]:
        if lists[-1]==lists[0]:
            sums+=1
        else:
            pass
    if flag:
        print(sums*k-1)
    else:
        print(sums*k)
 
elif len(s)==1:
        print(k//2)
elif len(set(lists))==1:
    print(k*len(lists)//2)


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] sort = new long[n];
        for (int i = 0; i < n; i++) {
            long num = sc.nextLong();
            a[i] = num;
            sort[i] = num;
        }
        Arrays.sort(sort);
        long max = sort[n - 1];
        for (int i = 0; i < n; i++) {
            if (max == a[i]) {
                System.out.println(sort[n - 2]);
                continue;
            }
            System.out.println(max);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 66828
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> t;

	set<ll>s;
	for(i=1;i<=9;i++)
		s.insert(i);


	while(t--)
	{
		x=*(s.begin());
		y=x%10;
		if(y==9 || y==0)
		{
			if(y==9)
				s.insert(x*10+8),s.insert(x*10+9);
			else
				s.insert(x*10),s.insert(x*10+1);
		}
		else
		{
			s.insert(x*10+y-1),s.insert(x*10+y),s.insert(x*10+y+1);
		}
		s.erase(s.begin());
	}
	cout<<x<<endl;
}

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

int main() {
    int n, m, l, a[100][100], b[100][100];
    ll c[100][100] = {};

    cin >> n >> m >> l;
    rep(i,n)
        rep(j,m) cin >> a[i][j];
    rep(i,m)
        rep(j,l) cin >> b[i][j];

    rep(i,n)
        rep(j,l)
            rep(k,m) {
                c[i][j] += a[i][k]*b[k][j];
            }

    rep(i,n) {
        rep(j,l) {
            if (j) cout << ' ';
            cout << c[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3272
import math
n,m = map(int, input().split())
if abs(n-m) <= 1:
    a = max(n,m)
    b = min(n,m)
    if a-b == 1:
        print((math.factorial(a)*math.factorial(b))%(10**9+7))
    else:
        print((math.factorial(a)*math.factorial(b)*2)%(10**9+7))
else:
    print(0)


Measured memory_bytes: 5184
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1LL<<60;
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(void) {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    h2 -= h1; m2 -= m1;
    if (m2 < 0) {
        m2 += 60;
        h2--;
    }
    cout << 60 * h2 + m2 - k << endl; 
}

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

ll N; 
ll l[4000];

void solve(){
    vector<ll> v(N);
    for(int i=0; i<N; i++)v[i] = l[i+1];
    sort(v.begin(),v.end());
    ll ans=0;
    for(ll i= N-1; i>= 0; i--){
        for(ll j = i-1; j>= 0; j--){
            auto itr = lower_bound(v.begin(),v.end(),v[i] + v[j]);
            ll no = distance(itr,v.end());
            ans += (N-1-i) - no;
        }
    }
    cout<<ans<<endl;
}

int main(){
    cin>>N;
    for(int i=1; i<=N; i++) cin>>l[i];
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,a,b,c,x;
	while(cin>>n>>a>>b>>c>>x,n) 
	{
		int rdm[n];
		for(int i = 0; i < n; ++i)
		{
			cin>>rdm[i];
		}

		int pos=0,ans=0;
		while(ans<=10000) 
		{
			if(rdm[pos]==x) pos++;
			if(pos==n) break;

			x=(a*x+b)%c;
			ans++;
		}
		cout<<(ans==10001?-1:ans)<<endl;
	}
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int n,m,p,dp[305][305][305];
int main()
{
	scanf("%d%d%d",&n,&m,&p);
	dp[0][1][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		for(int k=i;k>=0;k--)
		{
			if(k) dp[i][j][k-1]=(dp[i][j][k-1]+dp[i][j][k])%p;
			else dp[i][j+1][i]=(dp[i][j+1][i]+dp[i][j][k])%p;
			dp[i+1][j][k]=(dp[i+1][j][k]+1ll*dp[i][j][k]*(k+1)%p)%p;
		}
	}
	printf("%d\n",dp[n][m][0]);
}

Measured memory_bytes: 113148