akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    using namespace std;
    #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
     
    int main() {FIN
     
      int n, r;
                cin >> n >> r;
                if (n >= 10)
                  cout << r << "\n";
                else
                  cout << r + 100 * (10 - n) << "\n";
    	return 0;
    }

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

using namespace std;

int main(){
   int n;

   long long a[200000];

   cin >> n;

   for(int i=0; i<n; i++){
      cin >> a[i];
      a[i] -= 1+i;
   }

   sort(a, a+n);

   long long med = a[n/2];
   long long res = 0;

   for(int i=0; i<n; i++){
      res += abs(a[i] - med);
   }

   cout << res << endl;

   return 0;
}


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

int main()
{
    int n,c = 0;
    cin >> n;
    cin.ignore();
    string s;
    cin >> s;
    for(int i = 0; i < n-2; i++)
    {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
        {
            c++;
            i += 2;
        }
    }
    cout << c ;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return input()
def n():
    return int(input())
def d():
    return float(input())

def ls():
    return input().split()
def ln():#a,b,c,....  int,int,int,....
    return map(int, input().split())
def ld():
    return map(float, input().split())

def fs():
    return [input() for i in range(input())]
def fn():
    return [int(input()) for i in range(input())]
def fd():
    return [float(input()) for i in range(input())]


a,b,c = ln()
if a == b:
    print(c)
elif b == c:
    print(a)
else:
    print(b)


Measured memory_bytes: 5332
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[100010];
int cnt;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt += a[i];
	}
	if (cnt % (n*(n + 1) / 2)) {
		cout << "NO" << endl;
		return 0;
	}
	int k = cnt / (n*(n + 1) / 2);
	int cnt2 = 0;
	for (int i = 0; i < n; i++) {
		int x = a[(i + 1) % n] - a[i];
		if (k < x) {
			cout << "NO" << endl;
			return 0;
		}
		if ((k - x) % n) {
			cout << "NO" << endl;
			return 0;
		}
		cnt2 += (k - x) / n;
	}
	if (cnt2 == k)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;
using ll = long long;

int main() {
  string str;
  cin >> str;
  ll n_str = static_cast<ll>(str.size());

  ll ans = 0;
  for (ll i = 0; i < n_str;) {
    ll p1 = 0;
    ll p2 = 0;
    for (ll j = i; j < n_str; ++j) {
      if (str[j] == '<' and p2 != 0)
        break;
      else if (str[j] == '<')
        ++p1;
      else
        ++p2;
    }

    ll last = 0;
    for (ll i = 0; i < p1 - 1; ++i)
      ans += ++last;
    last = 0;
    for (ll i = 0; i < p2 - 1; ++i)
      ans += ++last;
    ans += max(p1, p2);

    i += p1 + p2;
  }
  cout << ans << endl;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	
	vector<int> v(5);
	vector<pair<int, int>> p(5);
	REP(i,5){
		int v; cin >> v;
		int amari = v % 10;
		if(amari == 0) amari = 9;
		p[i] = make_pair(amari, v);
	}

	SORT(p);
	int ans = 0;
	for(int i=4;i>0;--i){
		if((p[i].second % 10) > 0) p[i].second += (10 - p[i].second % 10);
		ans += p[i].second;
	}
	ans += p.front().second;


	cout << ans << endl;


	return 0;

}


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

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

	vector<int> sum(M);
	for (int i = 0; i < N; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int a;
			cin >> a;
			sum[a-1]++;
		}
	}

	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (sum[i] == N) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  if(n%2==1) print(0);
  else {
    ll div10=10,five=0;
    while(n/div10>0) {
      five+=n/div10;
      div10*=5;
    }
    print(five);
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n), f(n), d(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n)cin >> f[i];
	sort(all(a));
	sort(all(f), greater<ll>());
	rep(i, 0, n)d[i] = a[i] * f[i];
	ll left = -1ll, right = (ll)1e13, mid, N;
	while (right - left > 1ll) {
		N = 0, mid = (right + left) / 2ll;
		rep(i, 0ll, n) {
			if (d[i] > mid)N += (d[i] - mid + f[i] - 1) / f[i];
		}
		(N <= k ? right : left) = mid;
	}
	printf("%lld\n", right);
	return 0;
}


Measured memory_bytes: 8016
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = solve(A, B);

        System.out.println(ans);
    }

    private static int solve(int A, int B) {
        int S = A*B - A - B + 1;

        return S;
    }
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll x;
  cin >> x;

  // 500で割った商
  ll q500 = x / 500;
  // 500で割った余り
  ll r500 = x % 500;
  ll q5 = r500 / 5;
  cout << 1000 * q500 + 5 * q5 << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC115_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            if (a == 25)
            {
                Console.WriteLine("Christmas");
            }
            else if (a == 24)
            {
                Console.WriteLine("Christmas Eve");
            }
            else if (a == 23)
            {
                Console.WriteLine("Christmas Eve Eve");
            }else
            {
                Console.WriteLine("Christmas Eve Eve Eve");
            }
        }
    }
}


Measured memory_bytes: 11092
num = int(input())
card_list = [x for x in input().split()]
origin = card_list[:]
card_list2 = origin[:]
cards = {x : int(x[1]) for x in card_list}

for i in range(num):
    for j in range(num-1, i, -1):
        if cards[card_list[j]] < cards[card_list[j-1]]:
            card_list[j], card_list[j-1] = card_list[j-1], card_list[j]
print(' '.join(card_list))
print('Stable')

for i in range(num):
    minj = i
    for j in range(i, num):
        if cards[card_list2[j]] < cards[card_list2[minj]]:
            minj = j
    card_list2[i], card_list2[minj] = card_list2[minj], card_list2[i]
print(' '.join(card_list2))

if card_list == card_list2:
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5612
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int N, A, B;
vector<int> h;

bool check(int num) {
	vector<int> v = h;
	rep(i, N) v[i] = max(0LL, v[i] - B * num);

	int cnt = 0;
	rep(i, N) {
		cnt += (v[i] + (A - B) - 1) / (A - B);
	}

	return cnt <= num;
}

signed main() {
	cin >> N >> A >> B;

	inputVector(h, N);

	int low = 0;
	int high = 1000000001;
	int mid = (high + low) / 2;
	while (high - low > 2) {
		if (check(mid)) {
			high = mid;
		} else {
			low = mid;
		}

		mid = (low + high) / 2;
	}

	for (int i = high; i >= low; i--) {
		if (check(i)) mid = i;
		else break;
	}

	cout << mid << endl;

    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void solve(){
    ll L; cin >> L;
    ll r = 0;
    ll n = 1;
    while((n*2) <= L){
        n *= 2;
        r++;
    }
    ll N = r+1;
    ll M = 0;
    vector<vector<pll>> G(N+1);
    for(int i = 1; i < N;i++){
        G[i].push_back(pll(i+1,1<<(i-1)));
        G[i].push_back(pll(i+1,0));
        M+=2;
    }
    for(ll t = N-1; t >= 1;t--){
        if((L-(1<<(t-1)))>=n){
            G[t].push_back(pll(N,L-(1<<(t-1))));
            M++;
            L -= (1<<(t-1));
        }
    }
    cout << N << " " << M << endl;
    for(int i = 1; i < N;i++){
        for(auto e:G[i]){
            cout << i << " " << e.first << " " << e.second << endl;
        }
    }
//    cout << G << endl;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


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

string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> s;
    for(int i = 0 ; i < s.size()-8 ; i++)
        cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 50000000

int parent(int i) {return i / 2;}
int left(int i) {return 2*i;}
int right(int i){return 2*i + 1;}
int H;
int A[MAX];

void maxHeap(int idx){
    int l = left(idx);
    int r = right(idx);
    int large;
    if(l <= H && A[idx] < A[l]){
        large = l;
    } else {
        large = idx;
    }

    if(r <= H && A[large] < A[r]){
        large = r;
    }

    if(large != idx){
        int tmp = A[idx];
        A[idx] = A[large];
        A[large] = tmp;
        maxHeap(large);
    }

}

void exec(){
    for(int i = H/2; i >= 1; i--) maxHeap(i);
}

int main(){
    int i;
    scanf("%d", &H);
    for(i = 1; i <= H; i++){
        scanf("%d", &A[i]);
    }

    exec();

    for(i = 1; i <= H; i++){
        printf(" %d", A[i]);
    }

    printf("\n");

    return 0;
}



Measured memory_bytes: 3640
import math
def myinput_int():
    return list(map(int, input().split()))

N, = myinput_int()
hairetu=[]
max=-1
max_pos=-1
next=-1
for i in range(N):
    temp, = myinput_int()

    if max<temp :
        max=temp
        max_pos=i
    elif next<temp :
        next=temp

for i in range(N):
    if i==max_pos:
        print(next)
    else:
        print(max)



Measured memory_bytes: 4668
#include <bits/stdc++.h>
#define INF 1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define arr array
#define _lower_bound(a, x) lower_bound(a.begin(), a.end(), x) - a.begin()
#define _upper_bound(a, x) upper_bound(a.begin(), a.end(), x) - a.begin()
#define _debug(x) cout << #x << " = " << x << endl;
#define _sort(x) sort(x.begin(), x.end())
#define _rsort(x) sort(x.rbegin(), x.rend())
#define _reverse(x) reverse(x.begin(), x.end())
typedef long long ll;
using namespace std;

void solve() {
	int n; cin >> n;
	cout << (n >= 30 ? "Yes\n" : "No\n");
}   

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

    // int t; cin >> t;
    // while(t--) 
        solve();
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <vector>

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

#define INF 1000000000

using namespace std;

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

    vector<int> X(N);
    REP(i, N)
        cin >> X[i];

    vector<int> costs(100);

    for(int p = 0; p < 100; ++p) {
        REP(i, N) {
            costs[p] += (X[i] - p) * (X[i] - p);
        }
    }

    cout << *min_element(ALL(costs)) << endl;

    return 0;
}


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

int INF = 1001001001;

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

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

int main() {
    ll n, w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1, vector<ll>(w+1));
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        for (int sum_w = 0; sum_w <= w; sum_w++) {
            if (sum_w - x >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - x] + y);
            }
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 83152
A,B,M = map(int,input().split())
F = list(map(int,input().split()))
F.insert(0,10**6)
G = list(map(int,input().split()))
G.insert(0,10**6)
cmin = 10**6
for _ in range(M):
    x,y,c = map(int,input().split())
    cnt = F[x]+G[y]-c
    cmin = min(cmin,cnt)
F = sorted(F)
G = sorted(G)
cmin = min(cmin,F[0]+G[0])
print(cmin)

Measured memory_bytes: 68588
while True:
    n = int(raw_input())
    if n == 0: break
    cnt = 0
    while True:
        if n == 6174: print cnt; break;
        a = []
        for i in range(4):
            x = n/(10**(3-i))
            a.append(x)
            n-= x * (10**(3-i))
        a.sort()
        for i in range(4):
            n += (a[3-i] - a[i]) * (10**(3-i))
        if n == 0:
            print "NA"; break;
        cnt += 1

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

int main()
{
	int a, b, c, d, i = 8;
	char p[] = {'+', '-'};
	scanf("%1d%1d%1d%1d", &a, &b, &c, &d);
	while (i--)
		if (a+(i&4?-b:b)+(i&2?-c:c)+(i&1?-d:d) == 7)
		{
			printf("%d%c%d%c%d%c%d=7\n",a,p[i/4%2],b,p[i/2%2],c,p[i%2],d);
			return 0;	
		}
}


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

int n, ans;
vector <int> a;

int main() {
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < 2 * n; i += 2)
		ans += a[i];
	cout << ans << endl;
	return 0;
}


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

using namespace std;

using ll = long long;

int main(){
    ll n; cin >> n;
    ll arr[n];
    for(ll i = 0; i < n; ++i){
        cin >> arr[i];
    }
    ll ans = arr[0];
    for(ll i = 0; i < n; ++i){
        ans = min(ans, __gcd(arr[i], ans));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buffer = Console.ReadLine().Split();
            int[] list = new int[100];
            for (var i = int.Parse(buffer[0]); i < int.Parse(buffer[1]); i++)
                list[i] = 1;

            for (var i = int.Parse(buffer[2]); i < int.Parse(buffer[3]); i++)
                list[i] += 1;

            Console.WriteLine(list.Where(v => v == 2).Count());
        }
    }
}


Measured memory_bytes: 28252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

class UnionFind{
public:
	vector<int> par;
	//0-indexed
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		par[x] = y;
	}
};

bool solve(){
	ll H,W;
	cin >> W >> H;
	UnionFind island;
	island.init(W*H);
	ll dx[] = {0,1,0,-1,1,1,-1,-1};
	ll dy[] = {1,0,-1,0,1,-1,1,-1};
 	if(H==0&&W==0)return false;
	ll tile[H][W];
	ll zero = 0;
	FOR(i,0,H)FOR(j,0,W)cin>>tile[i][j];
	FOR(i,0,H)FOR(j,0,W){
		if(tile[i][j]==1){
			ll x = i;
			ll y = j;
			FOR(k,0,8)if(x+dx[k]<H&&x+dx[k]>=0&&y+dy[k]<W&&y+dy[k]>=0){
				ll nx = x+dx[k];
				ll ny = y+dy[k];
				if(tile[nx][ny]==1)
					island.unite(x*W+y,nx*W+ny);
			}
		}else{
			zero++;
		}
	}
	set<ll> s;
	FOR(i,0,H*W)s.insert(island.root(i));
	cout << s.size() - zero << endl;
	return true;
}

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


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  int count=0;
  for(int i=0;i<N-1;i++){
    count+=L.at(i);
  }
  if(count>L.at(N-1)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



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

    ll ans = 0ll;
    for (int i = 1; i <= N; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            ans += i;
        }
    }
    
    cout << ans << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

double EPS = 1e-10;
double add(double a, double b){
  if(abs(a+b) < EPS* (abs(a) + abs(b))) return 0;
  return a+b;
}

struct P{
  double x,y;
  P(){}
  P(double _x,double _y):x(_x),y(_y){}
  P operator + (P p){
    return P(add(x,p.x) ,add(y,p.y));
  }
  P operator - (P p){
    return P(add(x,-p.x) ,add(y,-p.y));
  }
  P operator * (double d){
    return P(x * d,y * d);
  }
  bool operator==(const P p){
    return (x == p.x && y == p.y);
  }
  friend ostream& operator<<(ostream& os,const P& p){
    os << "("<<p.x <<","<<p.y<<")";
    return os;
  }
  double norm(){
    return sqrt(x*x + y*y);
  }
  double dot(P p){
    return add(x * p.x,y*p.y);
  }
  double det(P p){
    return add(x*p.y,-y*p.x);
  }
  double dist2(P p){
    return ((*this-p).x * (*this-p).x) + ((*this-p).y * (*this-p).y);
  }
  P GetCenter(P &p){
    return P((*this+p).x/2,(*this+p).y/2);
  }
  double GetSlope(P &p){
    P tmp = *this - p;
    return tmp.y/tmp.x;
  }
};
//???????????????????????¨?????????
bool on_seg(P p1,P p2,P q){
  return (p1-q).det(p2-q) == 0 && (p1-q).dot(p2-q) <= 0;
}
//???????°????
P intersection(P p1, P p2, P q1,P q2){
  return p1 + (p2-p1) * ((q2 - q1).det(q1-p1) / (q2 - q1).det(p2-p1)) ;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  ll num = 1;
  while(cin >> n && n){
    double ans = 0;
    vector<P> v(n+1);
    rep(i,n){
      cin >> v[i].x >> v[i].y;
    }
    v[n] = v[0];
    REP(i,0,n){
      ans += v[i].det(v[i+1]);
    }
    ans *= 0.5;
    fcout(1) << num << " " << abs(ans) << endl;
    ++num;
  }
  return 0;
}

Measured memory_bytes: 3272
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define CVector CPoint
#define INF 0x3f3f3f3f
#define MAXN 1e5
const LL mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1e-10;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-')f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

int n,m;
int x[100005];
LL f[200005];
LL sumx[200005],cnt[200005];

void update(LL *a,int p,int x){
    for(int i=p;i<=2*m;i+=i&-i){
        a[i]+=x;
    }
}

LL query(LL *a,int p){
    LL ret=0;
    for(int i=p;i>0;i-=i&-i){
        ret=ret+a[i];
    }
    return ret;
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    LL ans=0;
    for(int i=0;i<n;i++) cin>>x[i];
    for(int i=0;i<n-1;i++){
        ans+=(x[i+1]+m-x[i])%m;
        if(x[i]+1<x[i+1]){
            update(sumx,x[i]+1,x[i]+1);
            update(sumx,x[i+1]+1,-x[i]-1);
            update(cnt,x[i]+1,1);
            update(cnt,x[i+1]+1,-1);
        }else if(x[i]>x[i+1]&&x[i]+1<x[i+1]+m){
            update(sumx,x[i]+1,x[i]+1);
            update(sumx,x[i+1]+m+1,-x[i]-1);
            update(cnt,x[i]+1,1);
            update(cnt,x[i+1]+m+1,-1);
        }
        //for(int i=1;i<=2*m;i++){
         //cout<<" "<<query(cnt,i)*i-query(sumx,i);
        //}
        //cout<<endl;
    }
    for(int i=1;i<=2*m;i++){
        f[i]=query(cnt,i)*i-query(sumx,i);
    }
    for(int i=1;i<=m;i++) f[i]+=f[i+m];//cout<<f[i]<<" ";
    LL cnt=0;
    for(int i=1;i<=m;i++){
        if(f[i]>cnt){
            cnt=f[i];
        }
    }
    cout<<ans-cnt<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 5376
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    int ans=0;
    int p=0, q=0, r=0;
    int i;
    for(i=0; i<n; i++) {
        char str[15]={0};
        scanf("%s", str);

        int len=strlen(str);
        if(str[0]=='B' && str[len-1]=='A') p++;
        else if(str[0]=='B') q++;
        else if(str[len-1]=='A') r++;

        int j;
        for(j=0; j<len-1; j++) {
            if(str[j]=='A' && str[j+1]=='B') ans++;
        }
    }
    if(q==0 && r==0) {
        if(p>1) ans += (p-1);
    }
    else {
        ans += MIN(q,r)+p;
    }
    printf("%d\n", ans);

    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
bitset<200000>md;
int arr[200000];
int main()
{

    int n,m,c=0,p=0;
    string s;
    int a;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
cin>>a>>s;
if(md[a]==0){
    if(s=="WA")arr[a]++;
    else {c++; md[a]=1;p+=arr[a];}
}
    }
    cout<<c<<" "<<p<<endl;
}


Measured memory_bytes: 4024
#include<iostream>//头文件
#include<fstream>
#include<algorithm>
using namespace std;
int n,k,a[55],h;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
     cin>>n>>k;
     for(int i=1;i<=n;i++)
     {
        cin>>a[i];
     }
     sort(a+1,a+n+1,cmp);
     for(int i=1;i<=k;i++)
     {
        h=h+a[i];
     }
     cout<<h<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

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

  cout << max({a + b, a - b, a * b}) << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
K = int(input())
balls = list(map(int, input().split()))
mv = 0
border = (K-1) // 2
for ball in balls:
  if ball <= border:
    mv += ball * 2
  else:
    mv += abs((K - ball) * 2)
print(mv)



Measured memory_bytes: 3060
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A);
    vector<ll> q(B);
    vector<ll> r(C);
    REP(i, A) { cin >> p[i]; }
    REP(i, B) { cin >> q[i]; }
    REP(i, C) { cin >> r[i]; }

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> all;
    REP(i, X) all.push_back(p[i]);
    REP(i, Y) all.push_back(q[i]);
    REP(i, r.size()) all.push_back(r[i]);
    sort(all.begin(), all.end(), greater<ll>());

    ll ans = 0;
    REP(i, X + Y) { ans += all[i]; }

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


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

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

  unordered_set<int64_t> divs;

  // 2以上であるN-1の約数,
  // Nの約数の一部を(N自身とsqrt(N)以下のものを試して)追加
  divs.insert(N);
  if(N-1 > 1){ divs.insert(N-1); }
  int64_t div= 2;
  while(div*div <= N){
    int cnt= 0;
    int64_t tmp= N;
    while(tmp%div==0){
      cnt++;
      tmp/= div;
    }
    if(tmp%div==1){
      divs.insert(div);
      if(cnt==0){ divs.insert((N-1)/div); }
    }

    div++;
  }
  
  cout << divs.size() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	long long a,b,c;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0){
		cout<<0;
	}
	else{
		long long x=max(max(a,b),c);
		if(x==a){
			cout<<b*c;
		}
		else if(x==b){
			cout<<a*c;
		}
		else if(x==c){
			cout<<a*b;
		} 
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()

int main() 
{
	 // #ifndef ONLINE_JUDGE
  //       freopen("input.txt", "r", stdin);
  //       freopen("output.txt", "w", stdout);
  //   #endif
    fastio();
    int a,p;
    cin>>a>>p;
    int k = 3*a+p;
    int ans=k/2;
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;string s;
  std::cin >> n;
  std::cin >> s;
  ll x = 0;
  ll ans = 0;
  re(i, n) {
    if(s[i]=='I') x++;
    else x--;
    ans = max(ans, x);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
using ll = long long;


int main() {
  int a;
  cin >> a;
  int ans;
  ans = a % 1000;
  if(ans==0) cout << ans << endl;
  else{
    cout << 1000 - ans << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}
template<class T>
string IntToString(T num){
  string res;stringstream ss;ss<<num;
  return ss.str();
}
ll StringToInt(string &str){
  ll res=0;
  for(int i=0;i<(int)str.size();i++)
    res=(res*10+str[i]-'0');
  return res;
}

int n,m;
int xs[10001];
int ys[10001];
int minx;
int miny;
int maxx;
int maxy;
int sums[5010][5010];
pii ps[10001];

int main(){
  cin>>n>>m;
  set<int> sx,sy;
  map<pii,int> sp;
  for(int i=0;i<n;i++){
    cin>>xs[i]>>ys[i];
    ps[i].first=ys[i];
    ps[i].second=xs[i];
    sx.insert(xs[i]);
    sy.insert(ys[i]);
    sp[ps[i]]++;
  }
  vector<int> sortedx,sortedy;
  for(set<int>::iterator it=sx.begin();it!=sx.end();it++)
    sortedx.push_back(*it);
  for(set<int>::iterator it=sy.begin();it!=sy.end();it++)
    sortedy.push_back(*it);
  for(int i=0;i<(int)sortedy.size();i++)
    for(int j=0;j<(int)sortedx.size();j++){
      sums[i+1][j+1]=sums[i+1][j]+sums[i][j+1]-sums[i][j];
      if(sp.count(pii(sortedy[i],sortedx[j]))>0){
	sums[i+1][j+1]+=sp[pii(sortedy[i],sortedx[j])];
      }
    }
  for(int i=0;i<m;i++){
    cin>>minx>>miny>>maxx>>maxy;
    int minxPos=lower_bound(sortedx.begin(),sortedx.end(),minx)-sortedx.begin();
    int maxxPos=upper_bound(sortedx.begin(),sortedx.end(),maxx)-sortedx.begin()-1;
    int minyPos=lower_bound(sortedy.begin(),sortedy.end(),miny)-sortedy.begin();
    int maxyPos=upper_bound(sortedy.begin(),sortedy.end(),maxy)-sortedy.begin()-1;
    int cnt=sums[maxyPos+1][maxxPos+1]-sums[minyPos][maxxPos+1]
      -sums[maxyPos+1][minxPos]+sums[minyPos][minxPos];
    cout<<cnt<<endl;
  }
  return 0;
}

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

int main() {
    int N;
    pair<int,int> A[100001];
    cin >> N;
    for (int i=1;i<=N;i++) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort (A+1, A+N+1);
    for (int i=1;i<=N;i++) {
        cout << A[i].second;
        if (i!=N) cout << " ";
    }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b))cout<<"B";
    else cout<<"A";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,tmp[10]={512,256,128,64,32,16,8,4,2,1};
  while(cin >> n && n!=EOF){
    int cnt[10]={0};
    for(int i=0;i<10;i++){
      if(n-tmp[i]>=0){
	n-=tmp[i];
	cnt[i]++;
      }
      if(n==0) break;
    }
    int flg=0;
    for(int i=9;i>=0;i--){
      if(cnt[i]==1){
      if(flg==1)cout << " ";
	cout << tmp[i];
	flg=1;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1160
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())





def main():
	n,m=MI()

	L=[[] for _ in range(m+1)]
	for i in range(1,n+1):
		KL=LI()
		for l in KL[1:]:
			L[l].append(i)
	#print(L)

	UF=UnionFind(n)

	for l in L:
		if len(l)>=2:
			for i,j in zip(l[:-1],l[1:]):
				UF.union(i-1,j-1)
	print("YES" if UF.group_count()==1 else "NO")


if __name__ == "__main__":
	main()


Measured memory_bytes: 22388
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, rank, mi, ni;
  cin >> N;
  vector<int> vec(N);
  vector<int> ran(N);
  for(int i=0;i<N;i++) cin >> vec.at(i);
  for(int i=0;i<N;i++){
    rank =1;
    mi = vec.at(i);
    for(int j=0;j<N;j++){
      ni = vec.at(j);
      if(mi<ni) rank++;
    }
    ran.at(i) += rank;
  }
   int n, m, l, k, t;
  t=0;
  for(int i=0;i<N;i++){
    n = ran.at(i);
    for(int j=0;j<N;j++){
      m = ran.at(j);
      if(n==m&&i!=j) {
      for(int a=0;a<N;a++) if(ran.at(a)==m&&a!=i) ran.at(a)++;
      }}}
        
 for (int i=0;i<N;i++){
   l = ran.at(i);
   k = vec.at(i);
   if(l%2==1) t += k;
   if(l%2==0) t -= k;
 }
  cout << t << endl;
}


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

int main()
{
	int a, b;
	char op;
	while(true){
		cin >> a >> op >> b;
		if(op == '+'){
			cout << a + b << endl;
		}
		if(op == '-'){
			cout << a - b << endl;
		}
		if(op == '*'){
			cout << a * b << endl;
		}
		if(op == '/'){
			cout << a / b << endl;
		}
		if(op == '?'){
			break;
		}
	}
}

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

//#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main(){
    int N;
    cin>>N;
    string s;
    //string A='A';
    cin>>s;
    int co=0;
    rep(i,N){
        if (s.substr(i,3)=="ABC")
        {
           co++;
        }
    }
    cout<<co<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x,n;
    cin >> x >> n;

    vector<int> ary(n);
    rep(i,n) cin >> ary[i];
    // bool flag = false;
    rep(i,1000)
    {
        int sa = i/2;
        if (i%2==0) sa*=-1;
        // cout << sa << endl;
        auto res = find(ary.begin(), ary.end(), x+sa);
        if (res==ary.end())
        {
            cout << x+sa << endl;
            // flag = true;
            break;
        }
    }


}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define lol long long
int main(){
  lol a,b=0;
  cin>>a;
  while(1){
    for(lol i=2;i<a;i++){
      if(a%i==0) b=1;
    }
    if(b!=1){
      break;
    }
    else{
      b=0;
      a++;
    }
  }
  cout<<a<<"\n";
  return(0);
}

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

int main(){
  string N;
  cin >>N;
	
  int len = N.size();
  int sum = 0;
  rep(i,0,len) sum += (int)(N[i])-'0';
  
  string ans;
  int n = stoi(N);
  
  if(n%sum==0) ans = "Yes";
  else if(n%sum!=0) ans = "No"; 
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	long long int x, y, z;
	scanf("%lld %lld %lld", &x, &y, &z);
	printf("%lld\n", (x - z) / (y + z));
	}

Measured memory_bytes: 128
from sys import stdin
input = lambda: stdin.readline().rstrip()
na, nb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min_b = 10**9
for i in range(na):
    min_a = min(min_a, a[i])
for i in range(nb):
    min_b = min(min_b, b[i])
ans = min_a + min_b
for i in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
print(ans)


Measured memory_bytes: 97268
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	long N;
  int sw = 0;
  cin >> N;
  for(int i = 0;i < N;i++){
    if(sw == 1)break;
    for(int j = i * -1 - 1;j < i;j++){
      if(i*i*i*i*i - j*j*j*j*j == N){
        cout << i << " " << j << endl;
        sw = 1;
        break;
      }
    }
  }
return 0;
}

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

#define ll long long
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ii pair < int, int >
#define vi vector < int > 
#define all(a) (a).begin(), (a).end()

using namespace std;

const int maxn = 2e5 + 10;
const double eps = 1e-9;

void solve() {
	int n, r;
	cin >> n >> r;
	cout << r + 100 * max( 0, 10 - n ) << "\n";
}

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


Measured memory_bytes: 256
mod = 10**9 + 7
a, b  = map(int,input().split())
k = abs(a-b)
def f(i):
  dest = 1
  while i != 0:
    dest *= i
    dest %= mod
    i -= 1
  return dest
if k >= 2:
  print(0)
elif k == 1:
  print( f(a) * f(b) % mod)
elif k == 0:
  print( 2 * f(a) * f(b) % mod)

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

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

    map<ll, ll> mp;
    mp[0] = 1;
    reverse(s.begin(), s.end());

    ll tmp = 0, base = 1;
    rep(i, s.size()) {
        tmp = (tmp + (s[i] - '0') * base) % 2019;
        base *= 10;
        base %= 2019;
        mp[tmp]++;
    }
    ll ans = 0;
    for (auto t : mp) {
        ans += t.second * (t.second - 1) / 2;
    }
    cout << ans << endl;
}


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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS= 1e-10;

int n;
int w[110];
ll v[110];
int W;
ll dp[110][MAXN];


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    cin>> n>>W;
    forn(i,n) cin>> w[i+1]>> v[i+1];

    for1(i,n){
        for1(j,W){
            if(w[i]<=j){
                dp[i][j] = max(v[i]+ dp[i-1][max(j-w[i],0)],dp[i-1][j]);
            }else{
                dp[i][j]= dp[i-1][j];
            }
        }
    }
    cout<< dp[n][W]<<el;
}


Measured memory_bytes: 79360