akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

class UnionFind {
public:
  vector<int> Parent;
  int root(int A) {
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  UnionFind(int N) { Parent = vector<int>(N, -1); }

  int size(int A) { return -Parent[root(A)]; }

  int connect(int A, int B) {
    A = root(A);
    B = root(B);
    if(A == B) return false;

    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    int na, nb;
    cin >> na >> nb;
    a[i] = --na, b[i] = --nb;
  }
  vector<ll> ans(m);
  ans[m - 1] = (ll)n * (n - 1) / 2;

  UnionFind uf(n);

  for(int i = m - 1; i > 0; i--) {
    ans[i - 1] = ans[i];
    if(uf.root(a[i]) != uf.root(b[i])) {
      ans[i - 1] -= (ll)uf.size(a[i]) * uf.size(b[i]);
      uf.connect(a[i], b[i]);
    }
  }

  rep(i, m) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int n = sc.nextInt();
        int result,x,result2,y;
        int mov = 0;
        int ikisaki[][] = new int[n][2];
        for(int i = 0; i < n; i++){
            for(int k = 0; k < 2; k++){
                ikisaki[i][k] = sc.nextInt();
            }
        }
        for(int i = 1; i < n; i++){
            result = ikisaki[i][0] - ikisaki[i-1][0];
            x = Math.abs(result);
            result2 = ikisaki[i][1] - ikisaki[i-1][1];
            y = Math.abs(result2);
            mov = mov + x + y;
            if(result > 0 && result2 > 0 || result < 0 && result2 < 0){
                if(x <= y){
                    mov = mov - x;
                }else{
                    mov = mov - y;
                }
            }
        }
        System.out.println(mov);
    }
}

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

const int maxn = 2e3+5;
int n, k, q;
int a[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k >> q;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 1e9+9;
    for (int i = 0; i < n; i++) {
        //cout << "testing " << a[i] << '\n';
        int X = a[i];
        vector<int> v;
        vector<int> curr;
        for (int j = 0; j < n; j++) {
            if (a[j] < X) continue;
            curr.push_back(a[j]);
            if (j == n-1 || a[j+1] < X) {
                //end of contig. sequence
                /*
                for (int k: curr) {
                    cout << k << ' ';
                }
                cout << '\n';
                */
                sort(curr.begin(),curr.end());
                int rem = (int)curr.size()-k+1;
                for (int k = 0; k < rem; k++) {
                    v.push_back(curr[k]);
                }
                
                curr.clear();
            }
        }
        sort(v.begin(),v.end());
        if (v.size() >= q) {
            int Y = v[q-1];
            //cout << X << ": " << Y << '\n';
            ans = min(ans,Y-X);
        }
    }
    cout << ans << '\n';
}



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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

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

    vi ans(n + 1, 0);
    vi res;
    bool valid = true;
    for (int i = n; i > 0; --i) {
        int tot = 0;
        for (int j = i; j <= n; j += i) {
            tot += ans[j];
        }

        if (tot % 2 != a[i] % 2) {
            ++ans[i];
            res.push_back(i);
        }
    }

    reverse(all(res));
    cout << res.size() << '\n';
    for (auto& x : res) {
        cout << x << ' ';
    }
    
    return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<string>
#define LL long long
#define PP std::pair<LL,LL>
int main() {
	std::string A,B,C;
	std::cin >> A >> B >> C;
	if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}
	return 0;
}

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

bool comp(pair<int,int> a, pair<int,int> b){
	return a.first < b.first;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	ll n,m;
	cin >> n >> m;
	vector<pair<ll,ll>> v;
	for(ll i=0; i<n; i++){
		ll a,b;
		cin >> a >> b;
		v.push_back(make_pair(a,b));
	}
	sort(v.begin(), v.end(), comp);
	ll price = 0, count = 0;
	ll final1 = 0, final2 = 0;
	for(auto x:v){
		price += x.first*x.second;
		count += x.second;
		if(count >= m){
			final1 = x.first;
			final2 = x.second;
			break;
		}
	}
	cout << price - (count-m)*final1;
	return 0;

}

Measured memory_bytes: 5340
using System;

public class hello
{
    public static void Main()
    {
        for (int i = 0; i < 7; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            Console.WriteLine(a - b);
        }
    }
}

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
int main(){
    long a,b,k;
    cin >> a >> b >> k;
    if(a>=k){
        cout << a-k <<" " << b << endl;
    }else{
        if(a+b<=k){
            cout << 0 <<" "<< 0 << endl;
        }else{
            cout << 0 <<" "<< a+b-k << endl;
        }
    }
    return 0;
}

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

int main()
{
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string L;
    string R;
    rep(i, tx - sx)
    {
        L += 'L';
        R += 'R';
    }

    string U;
    string D;
    rep(i, ty - sy)
    {
        U += 'U';
        D += 'D';
    }

    string ans = R + U + L + D + 'D' + R + 'R' + U + 'U' + 'L' + 'U' + L + 'L' + D + 'D' + 'R';

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {
 
  public static void Main (string[] args) {
    var temp = Console.ReadLine().Split(' ').Select(long.Parse);
    var N = temp.ElementAt(0);
    var M = temp.ElementAt(1);
    var ans = N * (N - 1) / 2 + M * (M- 1) / 2;
    Console.WriteLine(ans);
 
  }
  
}

Measured memory_bytes: 11220
using System;
using System.Linq;

namespace B___Kagami_Mochi
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Di = Enumerable.Range(1, N).Select(_ => int.Parse(Console.ReadLine())).OrderByDescending(x => x).Distinct().ToArray();

            Console.WriteLine(Di.Count());
        }
    }
}


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

int main ()
{
   int N,L;
   cin >> N>>L;
   vector<string> v;
   for(int i=0;i<N;i++){
      string a;
      cin >> a ;
      v.push_back(a);
   }
   sort(v.begin(),v.end());
   for(int i=0;i<v.size();i++){
      cout << v[i];
   }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ab = scanner.nextLine().split(" ", 2);
        int a = Integer.parseInt(ab[0]);
        int b = Integer.parseInt(ab[1]);
        if ((a + b) % 2 == 0) {
            System.out.println((a + b) / 2);
        } else {
            System.out.println((a + b) / 2 + 1);
        }
    }
}


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

void Main()
{
    long n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<long> b(n+1);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++)
    {
        b[i+1] = b[i] + a[i];
    }
    
    int ok = 0, ng = 200002;
    while (abs(ok - ng) > 1) { // ok: 幸福度がok以上の、握手の回数がm回未満
        int mid = (ok + ng)/2;
        long hand = 0;
        for (int i = 0; i < n; i++)
        {
            hand += lower_bound(a.begin(), a.end(), mid-a[i]-1) - a.begin();
        }
        if (n*n - hand >= m) ok = mid;
        else ng = mid;
        // cout << "ok:" << ok << " ng: " << ng << " hand: " << n*n - hand << endl;
    }
  //cout << ok << endl;
    long ans = 0;
    long sum = 0;
    for (int i = 0; i < n; i++)
    {
        long ind = lower_bound(a.begin(), a.end(), ok-a[i]-1) - a.begin();
        sum += n - ind;
        //cout << n-ind << endl;
        ans += b[n]-b[ind]+a[i]*(n-ind);
    }
    // cout << sum << endl;
    if (sum != 0) ans -= (ok-1)*(sum-m);
    
    cout << ans << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 4524
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=jp
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++){
  cin >> A[i];
  }
  //A??????????´???????
  for(int i = 0; i < N; i++){
    int v = A[i];
    int j = i-1;
    while(j>= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(int k = 0; k < N-1; k++){
      cout << A[k] << " ";
    }
    cout << A[N-1] << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
ll MOD = 998244353;
ll num[300010];
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n % 2)ans = x % MOD * ans % MOD;
    return ans;
}

ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}

void combi(ll n,ll r){
    for(ll i = 1;i <= r;i++){
        num[i] = divmod((n-i+1)*num[i-1],i);
    }
}
main(){
    ll N,A,B,K;
    cin >> N >> A >> B >> K;
    num[0] = 1;
    combi(N,N);
    ll ans = 0;
    rep(i,N+1){
        if((K - A*i) % B != 0)continue;
        int x = i,y = (K - A*i) / B;
        if(y < 0 || y > N)continue;
        ans += num[x] * num[y] % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
def divisors(n):
    res = []
    for d in range(1, int(n**0.5)+1):
        if n%d==0:
            res.append(d)
            res.append(n//d)
    res = sorted(set(res))
    return res

# 素因数分解
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

K = int(input())
N = 3
invK = modinv(K)
P = [0] * (K+1)
mod = 10**9+7
for i in range(1, K+1):
    p = pow(K//i * invK, N, mod)
    P[i] = p
KN = pow(K, N, mod)
ans = 0


# https://kazuma8128.hatenablog.com/entry/2018/07/29/231819
for i in range(K, 1, -1):
    #print(i, divisors(i))
    for d in divisors(i):
        if d!=i:
            P[d] -= P[i]
for i, p in enumerate(P[1:], 1):
    n = p * KN % mod
    #print(i, n)
    ans = (ans + n * i) % mod
print(ans)


Measured memory_bytes: 68868
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll K,A,B;
    cin>>K>>A>>B;
    ll t=(K-A+1)/2;
    ll ans=K+1;
    if(B-A-2>=0){
        ans=t*(B-A-2)+K+1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
      	if(N % 1000 == 0) {
        	System.out.println(0);  
        } else {
         	int quo = N / 1000;
          	int total = 1000 * (quo + 1);
          	int rem = total - N;
	        System.out.println(rem);
        }
	}
}

Measured memory_bytes: 35648
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, H;
    cin >> N >> H;
    int a, a_max;
    a_max = 0;
    vector<int> b(N);

    REP(i, N){
        cin >> a >> b[i];
        a_max = max(a, a_max);
    }

    SORT(b);

    int ans = 0;
    
    REP(i, N){
        if(b[N - i - 1] > a_max){
            ans++;
            H -= b[N - i - 1];
            if(H <= 0) break;
        }else{
            break;
        }
    }

    if(H > 0){
        if(H % a_max == 0){
            ans += H / a_max;
        }else{
            ans += H / a_max + 1;
        }
    }
    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, t;
    cin >> n >> x >> t;
    int ans = (n / x) * t;
    if (n % x != 0) ans += t;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3588
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    res = 2 * 10 ** 10
    x = 0
    y = sum(a)
    for i in range(n - 1):
        x += a[i]
        y -= a[i]
        d = abs(x-y)
        if res > d:
            res = d
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23792
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long LL;
struct X{
	int x;
	int y;
	LL h;
	X(){
		x=0;
		y=0;
		h=0;
	}
};
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int i;
	LL maxH=0;
	vector<X> myVec(N);
	for (i=0;i<N;i++){
		cin>>myVec[i].x>>myVec[i].y>>myVec[i].h;
		if (maxH<myVec[i].h){
			maxH=myVec[i].h;
		}
	}
	int Cx,Cy;
	LL H=maxH;
	
	while(true){
		for (Cx=0;Cx<=100;Cx++){
			for (Cy=0;Cy<=100;Cy++){
				bool bFind=true;
				for (i=0;i<N;i++){
					LL h1=H-abs(myVec[i].x-Cx)-abs(myVec[i].y-Cy);
					if (h1<0){
						h1=0;
					}
					if (myVec[i].h!=h1){
						bFind=false;
					}
					if (!bFind){
						break;
					}
				}
				if (bFind){
					cout<<Cx<<" "<<Cy<<" "<<H<<endl;
					return 0;
				}
			}
		}
		H++;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int[][] s = new int[n+1][4];
			for(int i = 0;i < n+1;i++){
				for(int j = 0;j < 4;j++){
					s[i][j] = scan.nextInt();
				}
			}
			int[] a = {4,9,4};
			boolean sw = true;
			int ca;
			for(int i = 0;i < n;i++){
				ca = 0;
				for(int j = 1;j < 4;j++){
					if(s[i][j] > s[n][j-1]){
						break;
					}
					ca += s[i][j]*a[j-1];
					if(j == 3 && ca <= s[n][3]){
						System.out.println(s[i][0]);
						sw = false;
					}
				}
			}
			if(sw){
				System.out.println("NA");
			}
		}
	}
}

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

int main(){
  long A, B, K;
  cin >> A >> B >> K;
  long temp = A;
  if(K >= A){
      A = 0;
    }  
  else if(K < A){
    A -= K;
  }
  if(A == 0){
      B -= (K - temp);
  }
  if(B < 0){
    B = 0;
  }
  cout << A << " " << B << "\n";
  return 0;
}

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

using namespace std;

vector <vector <int>> adjl(200000);
vector <int> res(200000,0);

void dfs(int t, int prev, int dsum){
  dsum += res[t];
  res[t] = dsum;
  for (int i = 0; i < adjl[t].size(); i++)
    if (adjl[t][i] != prev) 
     dfs(adjl[t][i], t, dsum);
}

int main(){
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++){
    int a, b;
    cin >> a >> b;
    adjl[a-1].push_back(b-1);
    adjl[b-1].push_back(a-1);
  }
  for (int i = 0; i < q; i++){
    int a, b;
    cin >> a >> b;
    res[a-1] += b;
  }
  dfs(0,-1,0);
  for (int i = 0; i < n; i++) cout << res[i] << " ";
}

Measured memory_bytes: 23424
from collections import Counter

s = input()
mod = 2019

li = [0]
num = 0
power = 1
for e in s[::-1]:
    num += int(e) * power
    num %= mod
    li.append(num)

    power *= 10
    power %= mod

c = Counter(li)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 16720
N = int(input())
S = input()
lst = list(S)
l = len(lst)

num = 0
#if N % 2 != 0:
#   print("No")
for i in range(N//2):
    if lst[i] == lst[i + N//2]:
        num += 1
if N % 2 != 0:
    print("No")
elif num == N//2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(a,b);
    cout << a*b << nn;
    return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans[n]={};
    int i=0;
    while(i<n){
        int rc=0,lc=0;
        while(s[i]=='R'){
            rc++;
            i++;
        }
        int sakai=i;
        while(s[i]=='L'&&i<n){
            lc++;
            i++;
        }
        
        //ans sakaiに対しての操作
        if(rc==lc){
            ans[sakai]=rc;ans[sakai-1]=rc;
        }
        else if(rc>lc){
            if((rc+lc)%2==0){
                ans[sakai]=(rc+lc)/2;
                ans[sakai-1]=(rc+lc)/2;
            }
            else{
                if(rc%2!=0){
                    ans[sakai]=(rc+lc-1)/2;
                    ans[sakai-1]=(rc+lc+1)/2;
                }
                else{
                    ans[sakai-1]=(rc+lc-1)/2;
                    ans[sakai]=(rc+lc+1)/2;
                }
            }
        }
        else{
            if((rc+lc)%2==0){
                ans[sakai]=(rc+lc)/2;
                ans[sakai-1]=(rc+lc)/2;
            }
            else{
                if(lc%2==0){
                    ans[sakai]=(rc+lc-1)/2;
                    ans[sakai-1]=(rc+lc+1)/2;
                }
                else{
                    ans[sakai-1]=(rc+lc-1)/2;
                    ans[sakai]=(rc+lc+1)/2;
                }
            }
        }
    }
    rep(i,n-1){
        cout<<ans[i]<<' ';
    }
    cout<<ans[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int r,l,N,q[20005],H,S,M,T,R,i;
int I()
{
	scanf("%d:%d:%d",&H,&M,&S);
	return H*3600+M*60+S;
}

int c(const void *a,const void *b)
{
	if(abs(*(int*)a)==abs(*(int*)b))
		return *(int*)a-*(int*)b;
	return abs(*(int*)a)-abs(*(int*)b);
}

int main()
{
	for(;scanf("%d",&N),N;)
	{
		l=R=0;
		for(i=0;i<2*N;i++)
		{
			q[l++]=(i%2?-1:1)*I();
		}
		qsort(q,2*N,4,c);
		for(i=R=r=0;i<2*N;i++)
		{
			r+=q[i]<0?-1:1;
			R=r<R?R:r;
		}
		printf("%d\n",R);
	}
	return 0;
}

Measured memory_bytes: 800
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
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;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

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

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    vector<double> v(n);
    rep(i,0,n){
        cin >> v[i];
        v[i] = ((v[i] + 1.0) * v[i] / 2.0) / v[i];
    }
    debug(v);
    double ans = 0;
    rep(i,0,k){
        ans += v[i];
    }
    double temp = ans;
    rep(j,k,n){
        temp += v[j];
        temp -= v[j - k];
        chmax(ans, temp);
    }

    cout << fixed << setprecision(15);
    cout << ans << "\n";
}

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

using namespace std;

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

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

int main() {
  
  int N; cin >> N; int64_t ans = 0;
  
  map<string, int64_t> memo;
  
  for (int i = 0; i < N; i++) {
    
    string s; cin >> s;
    
    sort(s.begin(), s.end());
    
    memo[s]++;
    
  }
  
  for (auto x : memo) {
    
    int64_t tmp = x.second;
    
    ans += tmp * (tmp - 1) / 2;
    
  }
  
  cout << ans << endl;
  
}

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

int main() {
    int a[3];
    int tmp,n=3;
    cin >> a[0] >> a[1] >> a[2];
    for(int i = 0; i < n; ++i) {
        for(int j = n-1; j > i; --j) {
            if(a[j] < a[j-1]) {
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
            }
        }
    }
    cout << a[0] << " " << a[1] << " " << a[2] << "\n";
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n,t,s=0x3f3f3f3f;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&t);
		int sum=0;
		while(t%2==0)
		{
			t/=2;
			sum++;
		}
		s=min(s,sum);
	}
	printf("%d\n",s);
	return 0;
}

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

int main(){
  string s,t;
  cin>>s;
  int sz=s.size();
  for(int i=0;i<sz;i++){
    if(s[i]=='0') t.push_back('0');
    else if(s[i]=='1') t.push_back('1');
    else if(t.size()!=0) t.pop_back();
  }
  for(int i=0;i<t.size();i++){
    cout<<t[i];
  }


}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int n = 1;

        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();

        while(n !=0){
            ArrayList<Integer> score = new ArrayList<Integer>();
            int max = 0, min = 1000, total = 0;
            for(int i = 0; i < n; i++ ){
                score.add(scan.nextInt());
            }

            for(int i = 0;i < n ;i++){
                int a = score.get(i);
                max = Math.max(a, max);
                min = Math.min(a, min);
                total += a;
            }

            int ave = (total - (max + min)) / (n -2);

            System.out.println(ave);
            n = scan.nextInt();
        }
        scan.close();
    }
}

Measured memory_bytes: 20980
#include<bits/stdc++.h>
using namespace std;
int dp[200005];
int main()
{
int n,i;
scanf("%d",&n);
int x;
set<int> st;
set<int>::iterator it;
int ans = 0;
for(i=1; i<=n; i++)
{
scanf("%d",&x);
dp[x] = dp[x-1] + 1;
ans = max(ans, dp[x]);
}

printf("%d\n",n-ans);
return 0;
}

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

struct N{
  int R,C,S;
};

  N n[80000000];

int main()
{
  int p,q;
  int Ind[20],nr[20],nc[20],ns[20];
  string s1[20],s2[20],s;
  while(1){
    cin>>p>>q;
    if(p+q==0)break;
    nr[0]=nc[0]=ns[0]=0;
    for(int i=0;i<p;i++){
      cin>>s1[i];
      Ind[i]=0;
      if(i!=0){
	nr[i]=nr[i-1];
	nc[i]=nc[i-1];
	ns[i]=ns[i-1];
      }
      bool flag=true;
      for(int j=0;j<s1[i].length();j++){
	if(s1[i][j]!='.')flag=false;
	if(s1[i][j]=='.' && flag)Ind[i]++;
	if(s1[i][j]=='(')nr[i]++;
	if(s1[i][j]==')')nr[i]--;
	if(s1[i][j]=='{')nc[i]++;
	if(s1[i][j]=='}')nc[i]--;
	if(s1[i][j]=='[')ns[i]++;
	if(s1[i][j]==']')ns[i]--;
      }
    }
    int a=0;
    
    for(int R=1;R<=20;R++){
      for(int C=1;C<=20;C++){
	for(int S=1;S<=20;S++){
	  bool flag=true;
	  for(int i=1;i<p;i++){
	    if(Ind[i]!=(R*(nr[i-1])+C*(nc[i-1])+S*(ns[i-1])))flag=false;
	  }
	  if(flag){
	    n[a].R=R;
	    n[a].C=C;
	    n[a].S=S;
	    a++;
	  }
	}
      }
    }
    nr[0]=nc[0]=ns[0]=0;
    for(int i=1;i<q+1;i++){
      cin>>s2[i];
      if(i!=0){
	nr[i]=nr[i-1];
	nc[i]=nc[i-1];
	ns[i]=ns[i-1];
      }
	for(int j=0;j<s2[i].length();j++){
	  if(s2[i][j]=='(')nr[i]++;
	  if(s2[i][j]==')')nr[i]--;
	  if(s2[i][j]=='{')nc[i]++;
	  if(s2[i][j]=='}')nc[i]--;
	  if(s2[i][j]=='[')ns[i]++;
	  if(s2[i][j]==']')ns[i]--;
	}
      
    }
    for(int i=0;i<q;i++){
      int b=-1;
      for(int j=0;j<a;j++){
	if(b!=-1 && b!=n[j].R*nr[i]+n[j].C*nc[i]+n[j].S*ns[i]){
	  b=-1;
	  break;
	}
	else b=n[j].R*nr[i]+n[j].C*nc[i]+n[j].S*ns[i];
      }
      cout<<b;
      if(i!=q-1)cout<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[110][100010] = {0};

int main()
{
    ll n, w;
    cin >> n >> w;
    vector<ll> weight(n + 1), value(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> weight[i] >> value[i];
    }
    for (ll i = 1; i < n + 1; i++)
    {
        for (ll j = 0; j < w + 1; j++)
        {
            if (j - weight[i] >= 0)
            {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    cout << dp[n][w] << endl;
}

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

using namespace std;

int main()
{
    int n;
    scanf("%i", &n);
    vector<long long> arr(n+4), dp(n+4, INT_MAX);
    for (int x = 1; x <= n; x++)
        scanf("%lli", &arr[x]);
    dp[1] = 0;
    for (int x = 1; x < n; x++)
    {
        dp[x+1] = min(dp[x+1], dp[x] + abs(arr[x]-arr[x+1]));
        dp[x+2] = min(dp[x+2], dp[x] + abs(arr[x]-arr[x+2]));
    }
    printf("%lli\n", dp[n]);
}


Measured memory_bytes: 1792
#include <stdio.h>
// #include <string.h>
// #include <math.h>

int main() {
    int a,b,c,x=0,i=0;
    
    scanf("%d %d %d",&a,&b,&c);
    while(x<c){
        i++;
        x+=a;
        if(i%7==0){
            x+=b;
        }
    }
    printf("%d\n",i);
    return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
  int n, x , y;
  
  int dist[2010][2010]={0},Q[2010]={0};
  
  cin >> n >> x >> y;
  
  for(int i=1;i<=n-1;i++){
    for(int j=i+1;j<=n;j++){
      dist[i][j] = min({abs(i-j),abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j)});
      Q[dist[i][j]]++;
    }
  }
  
  for(int i=1;i<n;i++){
    cout << Q[i]<< endl;
  }
  
}
  
  


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

mina = min(A)
mini = A.index(mina)
maxa = max(A)
maxi = A.index(maxa)

if mina >= 0:
  print(N-1)
  for i in range(N-1):
    print("{} {}".format(i+1, i+2))
elif maxa < 0:
  print(N-1)
  for i in range(N-1):
    print("{} {}".format(N-i, N-i-1))
else:
  if -mina < maxa:
    print(2*N-1)
    for i in range(N):
      print("{} {}".format(maxi+1, i+1))
    for i in range(N-1):
      print("{} {}".format(i+1, i+2))
  else:
    print(2*N-1)
    for i in range(N):
      print("{} {}".format(mini+1, i+1))
    for i in range(N-1):
      print("{} {}".format(N-i, N-i-1))

Measured memory_bytes: 9248
#include<bits/stdc++.h>
#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
const int MAX_E = 2020;
const int MAX_V = 1010;

struct edge{int from, to, cost;};
edge es[MAX_E];
int d[MAX_V];
int V, E;

int bellman_ford(int s){
    for(int i = 0; i < V; i++)
        d[i] = INF;
    d[s] = 0;
    int cnt = 0;
    while(true){
        bool update = false;
        cnt++;
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(cnt == V)
                    return true;
                update = true;
            }
        }
        if(!update)break;
    }
    return false;
}

signed main(){
    cin >> V >> E;
    int r;
    cin >> r;
    int s, t, c;
    rep(i, E){
        cin >> s >> t >> c;
        es[i].from = s;
        es[i].to = t;
        es[i].cost = c;
    }
    if(bellman_ford(r))
        cout << "NEGATIVE CYCLE" << endl;
    else{
        rep(i, V){
            if(d[i] == INF)cout << "INF" << endl;
            else
                cout << d[i] << endl;
        }
    }
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  map<int ,int> road;
  int a,b;
  for(int i = 0;i < m;i++) {
    cin >> a >> b;
    if(road.count(a)) {
      road.at(a)++;
    }else {
      road[a] = 1;
    }
    if(road.count(b)) {
      road.at(b)++;
    }else {
      road[b] = 1;
    }
  }
  for(int i = 1;i <= n;i++) {
    if(road.count(i)) {
      cout << road.at(i) << endl;
    }else {
      cout << 0 << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define vi vector<ll>
# define vvi vector<vi>
# define rep(i, N) for (int i = 0; i < N; i++)
# define Rep(i, N) for (int i = 1; i <= N; i++)
# define deb(x) cerr << #x << ": " << x << endl;
# define deb2(x, i) cerr << #x << "[" << i << "]: " << x[i] << endl;
/*
vi v(10, 2); 
rep(i, 10) deb2(v, i); 
*/

/*
int a; cin >> a;
int a, b; cin >> a >> b;
rep(i, n){cin >> v[i];}
cout <<   << endl;
*/
vector<int> g[200005];
int par[200005];

signed		main()
{
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++)

	{
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<int> ans;
	
	queue<int> q;
	q.push(1);
	par[1] = 1;

	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		for (auto nv: g[u])if (!par[nv])
		{
			q.push(nv);
			par[nv] = u;
		}
	}
	puts("Yes");
	for (int i = 2; i <= n; i++) cout << par[i] << endl;
}



Measured memory_bytes: 12860
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M = LI()
AB = LRI(M)

visited = [False] * N

# routeやん
root = [[] for _ in range(N)]
for a, b in AB:
    root[a-1].append(b-1)
    root[b-1].append(a-1)

ret = [-1] * N
Q = collections.deque([[0,0]])
while Q:
    qs = Q.popleft()
    b = qs[0]
    q = qs[1]

    if visited[q]:
        continue
    else:
        visited[q] = True
    
    ret[q] = b

    for r in root[q]:
        Q.append([q, r])

if -1 in ret:
    print("No")
else:
    print("Yes")
    for i, r in enumerate(ret):
        if i == 0:
            continue

        print(r+1)


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

using P=pair<int,int>;
using Graph=vector<vector<int>>;
const int INF=1e9;

int main()
{
   int N; cin>>N;
   Graph G(N);
   for(int i=0;i<N-1;i++){
      int a,b; cin>>a>>b;
      a--; b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }

   int K; cin>>K;
   vector<int> num(N,-1);
   for(int i=0;i<K;i++){
      int v,p; cin>>v>>p;
      num[v-1]=p;
   }

   int root=-1;
   for(int i=0;i<N;i++) if(num[i]>=0) root=i;

   bool ok=true;
   function<void(int,int,int)> parity_check=[&](int v,int p,int d)
   {
      if(num[v]>=0 and abs(num[v]-num[root])%2!=d%2) ok=false;
      for(int u:G[v]) if(u!=p){
         parity_check(u,v,d+1);
      }
   }; parity_check(root,-1,0);
   if(!ok){
      cout<<"No"<<endl;
      return 0;
   }

   vector<int> L(N,-INF),R(N,INF);
   function<P(int,int)> calc=[&](int v,int p)
   {
      for(int u:G[v]) if(u!=p){
         P child=calc(u,v);
         L[v]=max(L[v],child.first-1);
         R[v]=min(R[v],child.second+1);
      }
      if(num[v]>=0){
         L[v]=max(L[v],num[v]);
         R[v]=min(R[v],num[v]);
      }
      if(L[v]>R[v]) ok=false;
      // cout<<v+1<<' '<<L[v]<<' '<<R[v]<<endl;
      return make_pair(L[v],R[v]);
   };
   calc(root,-1);
   if(!ok){
      cout<<"No"<<endl;
      return 0;
   }

   function<void(int,int)> write=[&](int v,int p)
   {
      for(int u:G[v]) if(u!=p){
         if(L[u]<=num[v]-1 and num[v]-1<=R[u]) num[u]=num[v]-1;
         else num[u]=num[v]+1;
         write(u,v);
      }
   };
   write(root,-1);
   cout<<"Yes"<<endl;
   for(int i=0;i<N;i++) cout<<num[i]<<endl;
   return 0;
}



Measured memory_bytes: 16896
#include <iostream>
#include <complex>
using namespace std;
  
double cross(complex<double> A, complex<double> B){
	return (conj(A)*B).imag();
}
 
int main(){
    complex<double> Points[3], P;
    while(true){
        double x, y;
        for(int i=0; i<3; i++){
            cin >> x >> y;
            Points[i] = {x, y};
        }
        cin >> x >> y;
        P = {x, y};
         
        if(!cin)break;
         
        int sum = 0;
        for(int i=0; i<3; i++){
            sum += cross(Points[(i+1)%3]-Points[i], (P-Points[i])) > 0;
        }
        cout << (sum==0 || sum==3? "YES": "NO") << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int d = a/b;
    int r = a%b;
    double f = 1.0*a/b;
    System.out.println(d+" "+r+" "+String.format("%.5f",f));
  }
}



Measured memory_bytes: 26452
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n; i++)
#define all(v) (v).begin(), (v).end()
#define decimal fixed << setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    string s;
    cin >> s;
    int ans = INF;
    int tmp = 0;
    rep(i, s.size()){
        if(s[i]-'0' != i%2) tmp++;
    }
    ans = min(tmp, (int)(s.size()-tmp));
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(string a,string b){makelower(a);makelower(b);return a<b;}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
////////////////////////////////////////////////////////////////////////////</editor-fold>

class unionFind{
private: vector<int> p,rank,size;int numOfSet;
public:
    unionFind(int n){
        rank.assign(n,0);p.assign(n,0);size.assign(n,1);numOfSet=n;
        for(int i = 0; i <n ; ++i)p[i]=i;
    }
    int findSet(int i){return (p[i]==i)?i:p[i]=findSet(p[i]);}
    bool isSameSet(int i,int j){return findSet(i)==findSet(j);}
    int sizeOfSet(int i){return size[findSet(i)];}
    int numDisjointSets(){return numOfSet;}
    void unionSet(int i,int j){
        if(!isSameSet(i,j)){
            int x=findSet(i),y=findSet(j);numOfSet--;
            if(rank[x]>rank[y])swap(x,y);
            p[x]=y;
            size[y]+=size[x];
            if(rank[x]==rank[y])rank[y]++;
        }
    }
};

int main() {
///<editor-fold desc="ios">
  //  IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>
    long in=1,o;
    //cin>>o;
    int n,m;
    cin>>n>>m;
    unionFind dsu(n);
    for(long i = 0; i < m; ++i){
        int a,b;
        cin>>a>>b;
        a--;b--;
        dsu.unionSet(a,b);

    }
    cout<<dsu.numDisjointSets()-1<<endl;








}

Measured memory_bytes: 4580
import java.util.Scanner;

public class Main {

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

		int A = sc.nextInt();
		boolean flg = false;

		while (true) {
			if (A % 10 == 7) {
				flg = true;
				break;
			}
			A = A / 10;
			if (A == 0) {
				break;
			}
		}

		if (flg) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35776
#include<stdio.h>

int main(){
  int length;
  int A[100];
  int i=0,j=0;
  int flag=0;
  int key;

  scanf("%d",&length);

  while(i < length){
    scanf("%d",&A[i]);
    i++;
  }

  for(i = 0;i < length-1;i++){
    for(j = length-1;j >= 1;j--){

      if(A[j] < A[j-1]){
	key = A[j-1];
	A[j-1] = A[j];
	A[j] = key;
	flag++;
      }
    }
  }
 for(i = 0;i < length-1;i++){   //表示
      printf("%d ",A[i]);
    }
    printf("%d\n",A[i]);
    printf("%d\n",flag);
    return 0;
}
	

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
bool f(string a,string b){//a>b?
	return a==""||a.size()>b.size()||(a.size()==b.size()&&a>b);
}
string add(string a,string b){//a+b
	int t=min(a.size(),b.size());
	for(int i=t;i>=0;i--){
		bool h=true;
		rep(j,i)if(a[a.size()-i+j]!=b[j])h=false;
		if(h)return a+b.substr(i);
	}
	return "";
}
int main(){
	int n;
	while(cin>>n,n){
		vector<string>in(n);
		rep(i,n)cin>>in[i];
		sort(all(in));
		n=unique(all(in))-in.begin();
		vector<bool>ha(n,true);
		rep(i,n)rep(j,n)if(i!=j&&in[i].find(in[j])!=string::npos)ha[j]=false;
		vector<string>tmp;
		rep(i,n)if(ha[i])tmp.pb(in[i]);
		in=tmp;n=in.size();
		sort(all(in));
		vector<vector<string> >dp(1<<n,vector<string>(n,""));
		rep(i,n)dp[1<<i][i]=in[i];
		loop(i,1,1<<n)rep(j,n)if(i&1<<j)rep(k,n)if((i&1<<k)==0){
			int t=i^1<<k;
			string w=add(dp[i][j],in[k]);
			if(f(dp[t][k],w))dp[t][k]=w;
		}
		int w=(1<<n)-1;
		string out=dp[w][0];
		loop(i,1,n)if(f(out,dp[w][i]))out=dp[w][i];
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1812
using System;
using System.Collections.Generic;
					
public class my
{
	public static void Main()
	{
		string s;
		
		while( null != ( s = Console.ReadLine()) ) {
			var a = my.GetIntArray(4, s);
			var b = my.GetIntArray(4);
			
			Console.WriteLine("{0} {1}", my.Hit(a, b), my.Blow(a, b));
		}
	}
	
	private static int Hit(int[] a, int[] b)
	{
		var cnt = 0;
		
		for(int i = 0; i < a.Length; i++) {
			if(a[i] == b[i])	cnt++;
		}
		
		return cnt;
	}
	
	private static int Blow(int[] a, int[] b)
	{
		var cnt = 0;
		
		for(int i = 0; i < a.Length; i++) {
			for(int j =0; j < b.Length; j++) {
				if(i == j) continue;
				
				if(a[i] == b[j])	cnt++;
			}
		}
		
		return cnt;
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}

	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static int[] GetIntArray(int n, string t)
	{
		var A = new int[n];
		var s = t.Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}

	private static int[] GetIntArray(char c)
	{
		return Array.ConvertAll(Console.ReadLine().Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(string s)
	{
		return Array.ConvertAll(s.Split(' '), int.Parse);
	}
	
	private static double[] GetDoubleArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
	}
	
	public static string Reverse(string s)
	{
		var c = s.ToCharArray();
		Array.Reverse(c);
		
		return new String(c);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}

	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteVector(Vector v)
	{
		Console.WriteLine(string.Format("{0:f8} {1:f8}", v.X, v.Y));
	}
}

public struct Vector
{
	public double X,Y;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
//const int MOD=998244353;
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[1000001];
vector<ll>prime;

void seive(int limit)
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=limit;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=limit;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=limit;i++)if(!isPrime[i])prime.pb(i);
}

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

    set<int>r,g,b;
    vector<int>rr,gg,bb;
    f(n)
    {
        if(s[i]=='R')r.insert(i),rr.pb(i);
        if(s[i]=='G')g.insert(i),gg.pb(i);
        if(s[i]=='B')b.insert(i),bb.pb(i);
    }

    ll ans=0;

    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]==s[j])continue;

            char c='R'+'G'+'B'-s[i]-s[j];

            if(c=='R')
            {
                int pos=lower_bound(rr.begin(),rr.end(),j)-rr.begin();
                ans+=rr.size()-pos;
                if(r.count(2*j-i))ans--;
            }
            else if(c=='G')
            {
                int pos=lower_bound(gg.begin(),gg.end(),j)-gg.begin();
                ans+=gg.size()-pos;
                if(g.count(2*j-i))ans--;
            }
            else
            {
                int pos=lower_bound(bb.begin(),bb.end(),j)-bb.begin();
                ans+=bb.size()-pos;
                if(b.count(2*j-i))ans--;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3744