akhauriyash/Code-Regression huggingface dataset:
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}

template <class T>
T clampMax(const T& a, const T& b) { return min(a, b); }

template <class T>
T clampMin(const T& a, const T& b) { return max(a, b); }


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

const int MAX_N = 100010;
int N;
LL h[MAX_N];
LL memo[MAX_N];

LL Solve(int pos)
{
    if (memo[pos] >= 0) return memo[pos];
    if (pos >= N) return memo[pos] = 2000000000;
    if (pos == N - 1) return memo[pos] = 0;
    int cost1 = abs(h[pos] - h[pos + 1]) + Solve(pos + 1);
    int cost2 = abs(h[pos] - h[pos + 2]) + Solve(pos + 2);
    return memo[pos] = min(cost1, cost2);
}

int main()
{
    cin >> N;
    REP(i, N) cin >> h[i];
    REP(i, N + 2) memo[i] = -1;
    cout << Solve(0) << endl;
    return 0;
}

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

int main() {
  double n, k;
  double point;
  double ans = 0, m;

  cin >> n >> k;

  if (n < k) {
    for (double i = 1.0; i <= n; i++) {
      point = i;
      for (m = 0.0; point < k; m++) {
        point *= 2.0;
      }
      ans += pow(0.5, m);
    }
  }
  else {
    for (double i = 1.0; i <= k; i++) {
      point = i;
      for (m = 0.0; point < k; m++) {
        point *= 2.0;
      }
      ans += pow((0.5), m);
    }
    ans += n - k;
  }

  cout << setprecision(20) << ans / n << endl;
}

Measured memory_bytes: 256
n = int(input())
words = []
for i in range(n):
    words.append(input())
    
def get_res(words):
    if len(words) != len(set(words)):
        return 'No'
    for i in range(len(words) - 1):
        if words[i][-1] != words[i + 1][0]:
            return 'No'
    return 'Yes'

print(get_res(words))

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(100000)

def set_enable_goal(cur_node, back_paths, enable_goal):
    if cur_node in back_paths:
        for next_node in back_paths[cur_node]:
            if enable_goal[next_node - 1] == 0:
                enable_goal[next_node - 1] = 1
                set_enable_goal(next_node, back_paths, enable_goal)


N, M = map(int, input().split())
MIN = float('-inf')
INF_LIMIT = -MIN

back_paths = {}
all_paths = {}
for i in range(M):
    a, b, c = map(int, input().split())
    if a in all_paths:
        all_paths[a].append((b, c))
    else:
        all_paths[a] = [(b, c)]

    if b in back_paths:
        back_paths[b].append(a)
    else:
        back_paths[b] = [a]


# path cut
enable_goal= [0 for i in range(N)]
enable_goal[N - 1] = 1
set_enable_goal(N, back_paths, enable_goal)

for a, paths in all_paths.items():
    if not enable_goal[a - 1]:
        all_paths[a] = []
    else:
        valid_paths = []
        for b, c in paths:
            if enable_goal[b - 1]:
                valid_paths.append((b, c))
        all_paths[a] = valid_paths


scores = [MIN for i in range(N)]
scores[0] = 0

is_inf = False
for n in range(N):
    for a in all_paths.keys():
        for b, c in all_paths[a]:
            scores[b - 1] = max(scores[b - 1], scores[a - 1] + c)

# loop check
if not is_inf:
    prev_score = scores[N - 1]
    for a in all_paths.keys():
        for b, c in all_paths[a]:
            scores[b - 1] = max(scores[b - 1], scores[a - 1] + c)
    if prev_score != scores[N - 1]:
        is_inf = True


if is_inf:
    print('inf')
else:
    print(scores[N - 1])

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

typedef long long ll;

ll N, K;
ll R;
int main() {
  cin >> N >> K;
  ll x = 1;
  while (x <= N) {
    x *= K;
    ++R;
  }
  cout << R << endl;
  return 0;
}


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

Measured memory_bytes: 3024
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b && a<c){
        if(b<c){
            printf("%d %d %d\n",a,b,c);
        }
        else{
            printf("%d %d %d\n",a,c,b);
        }
    }
    else if(b<a && b<c){
        if(a<c){
            printf("%d %d %d\n",b,a,c);
        }
        else{
            printf("%d %d %d\n",b,c,a);
        }
    }
    else if(c<a && c<b){
        if(a<b){
           printf("%d %d %d\n",c,a,b);
        }
        else{
            printf("%d %d %d\n",c,b,a);
        }
    }
    else if(a==b){
        if(a<c){
            printf("%d %d %d\n",a,b,c);
        }
        else{
            printf("%d %d %d\n",c,b,a);
        }
    }
    else if(a==c){
        if(a<b){
            printf("%d %d %d\n",a,c,b);
        }
        else{
            printf("%d %d %d\n",b,a,c);
        }
    }
    else if(b==c){
        if(a<c){
            printf("%d %d %d\n",a,b,c);
        }
        else{
            printf("%d %d %d\n",b,c,a);
        }
    }
    return 0;
}



Measured memory_bytes: 2064
import sys
import collections
sys.setrecursionlimit(10**7)


def init(n):
    return list(range(n+1))

def find(lis, x):
    if lis[x] == x:
        return x
    else:
        lis[x] = find(lis, lis[x])
        return lis[x]

def sameset(lis, x, y):
    return find(lis, x) == find(lis, y)

def union(lis, x, y):
    x = find(lis, x)
    y = find(lis, y)
    if x != y:
        lis[x] = y

V,E=map(int,input().split())
union_find_tree = init(V)
graph = []
for _ in range(E):
    s, t, w = map(int, input().split())
    graph.append((s,t,w))

cost = 0
for (s,t,w) in sorted(graph, key=lambda x: x[2]):
    if not sameset(union_find_tree,s,t):
        union(union_find_tree,s,t)
        cost += w
print(cost)


Measured memory_bytes: 25792
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
char a;
cin >> a;
if(a < 'a')
    cout << 'A' << endl;
else
    cout << "a" << endl;
}

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

int main(){

 	#ifndef ONLINE_JUDGE
 	freopen("input.txt", "r", stdin);
 	freopen("output.txt", "w", stdout);
 	#endif

 	int a,l,c,t;
 	cin>>a>>l;
 	for (t = 0; t <= a; ++t)
 	{
 		c=a-t;
 		if(l==((c*2)+(t*4))){
 			cout<<"Yes";
 			exit(0);
 		}
 	}
 	cout<<"No";
 	return 0;
}

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

int main(void){
    int x, ans=1;
    cin >> x;
    for (int b=1; b<=(int)sqrt(x); b++){
        for (int p=2; p<=1000; p++){
            if (pow(b, p) > x){
                ans = max(ans, (int)pow(b, p-1));
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <tuple>
#include <vector>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int n, m, p, q, c, r1, r2;

vector<tuple<int, int, int> > dat;

inline void divide(int pos)
{
	vector<tuple<int, int, int> > dat1;

	int u = dat.size();

	for (int i = 0; i < u; i++)
	{
		int l = get<0>(dat[i]);
		int r = get<1>(dat[i]);
		int t = get<2>(dat[i]);

		if (l < pos && pos < r)
		{
			dat[i] = make_tuple(l, pos, t);

			dat.insert(dat.begin() + i + 1, make_tuple(pos, r, t + pos - l));
		}
	}
}

inline void shuffle(int a, int b)
{
	divide(a);
	divide(b);

	int l = lower_bound(dat.begin(), dat.end(), make_tuple(a, 0, 0)) - dat.begin();
	int r = lower_bound(dat.begin(), dat.end(), make_tuple(b, 0, 0)) - dat.begin();
	int u = dat.size();

	vector<tuple<int, int, int> > dat1;

	int pos = 0;

	for (int i = r; i < u; i++)
	{
		dat1.push_back(make_tuple(pos, pos - get<0>(dat[i]) + get<1>(dat[i]), get<2>(dat[i]))); pos += get<1>(dat[i]) - get<0>(dat[i]);
	}

	for (int i = l; i < r; i++)
	{
		dat1.push_back(make_tuple(pos, pos - get<0>(dat[i]) + get<1>(dat[i]), get<2>(dat[i]))); pos += get<1>(dat[i]) - get<0>(dat[i]);
	}

	for (int i = 0; i < l; i++)
	{
		dat1.push_back(make_tuple(pos, pos - get<0>(dat[i]) + get<1>(dat[i]), get<2>(dat[i]))); pos += get<1>(dat[i]) - get<0>(dat[i]);
	}

	dat = dat1;
}

int main()
{
	while(true)
	{
		scanf("%d", &n);
		
		if (n == 0) { break; }

		scanf("%d", &m);
		scanf("%d", &p); p--;
		scanf("%d", &q);
		scanf("%d", &c);

		dat = { make_tuple(0, n, 1) };

		for (int i = 0; i < m; i++)
		{
			scanf("%d", &r1);
			scanf("%d", &r2);

			shuffle(r1, r2);
		}

		int ret = 0;

		for (int i = 0; i < dat.size(); i++)
		{
			int l = get<0>(dat[i]);
			int r = get<1>(dat[i]);
			int t = get<2>(dat[i]);

			if (p <= l && r <= q)
			{
				ret += min(max(c - t + 1, 0), r - l);
			}
			else if (l <= p && q <= r)
			{
				ret += min(max(c - (t + (p - l)), 0), q - p);
			}
			else if (p <= l && l < q)
			{
				ret += min(max(c - t + 1, 0), q - l);
			}
			else if (p < r && r <= q)
			{
				ret += min(max(c - (t + (p - l)) + 1, 0), r - p);
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

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

int main(void){
    int n,a[100];
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    
    cout << a[n];
    for(int i = n-1; i >= 1; i--){
        cout << " " << a[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3096
using static System.Console;

namespace ConsoleApp4
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(ReadLine());
            var s = ReadLine().Split(' ');
            var d = int.Parse(s[0]);
            var x = int.Parse(s[1]);

            var a = new int[n];

            for (var i = 0; i < n; i++)
            {
                a[i] = int.Parse(ReadLine());
            }

            var counter = 0;

            foreach (var item in a)
            {
                var b = 0;

                while (b * item + 1 <= d)
                {
                    counter++;
                    b++;
                }
            }

            WriteLine(counter + x);

        }

    }
}


Measured memory_bytes: 11092
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
	int k = scanner.nextInt();
	int a = scanner.nextInt(),b = scanner.nextInt(),y=0;
	
	for (int i=a;i<=b;i++) {
		if (i%k==0) {
			System.out.println("OK");
			y=1;
			break;
		}
	}
	if (y==0) System.out.println("NG");
	scanner.close();}}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> v(n,0);
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
        {
            cnt++;
        }
        else
        {
            v[i] += cnt / 2;
            v[i - 1] += (cnt + 1) / 2;
            cnt = 0;
        }
    }
    cnt = 0;
    for (int i = 1; i < n + 1; i++)
    {
        if (s[n - i] == 'L')
        {
            cnt++;
        }
        else
        {
            v[n - i] += cnt / 2;
            v[n - (i - 1)] += (cnt + 1) / 2;
            cnt = 0;
        }
    }
    for (int i : v)
    {
        cout << i << " ";
    }
    return 0;
}

Measured memory_bytes: 1024
A,B,C,D=map(int,input().split())
takahashi=A
aoki=C
count=1
while (takahashi>0 and aoki>0):
    count=count+1
    if count % 2 == 0:
        aoki=aoki-B
    else:
        takahashi = takahashi - D

if aoki <= 0:
    print("Yes")
else:
    print("No")

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int main(){
    int n;
    cin >> n;
    int cnt[3] = {};
    REP(i,n) {
        int tmp;
        cin >> tmp;
        cnt[tmp%3]++;
    }
    if (cnt[0] == n) {
        cout << 1 << endl;
        return 0;
    }
    int ans;
    if(cnt[1] < cnt[2] - 3){
        ans = cnt[1] * 2 + 3;
    }else if(cnt[1] <= cnt[2] + 3){
        ans = cnt[1] + cnt[2];
    }else{
        ans = cnt[2] * 2 + 3;
    }
    ans += cnt[0];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3104
import java.util.*;

public class Main {
public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  
  String s = sc.next();
  
  if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)){
    System.out.println("Yes");
  }else{
    System.out.println("No");
  }
}
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
#include <bitset>
using namespace std;
#define MOD 1000000007

long long N, X, Y, Z, XYZ;
long long dp[41][1<<16];

int main(){
    cin >> N >> X >> Y >> Z;
    XYZ=X+Y+Z;

    int mask = 0;
    mask |= 1<<(X+Y+Z-1);
    mask |= 1<<(Y+Z-1);
    mask |= 1<<(Z-1);

    dp[0][0] = 1;

    for(int i=1; i<=N; i++){
        for(int j=0; j<(1<<(XYZ-1)); j++){
            for(int k=1; k<=10; k++){
                int l = j<<1;
                l |= 1;
                l <<= k-1;
                if((l & mask) == mask) continue;
                l &= (1<<(XYZ-1)) - 1;
                dp[i][l] += dp[i-1][j];
                dp[i][l] %= MOD;
            }
        }
    }

    long long ans = 0;
    for(int i=0; i<(1<<(XYZ-1)); i++)
        ans = (ans + dp[N][i]) % MOD;

    long long pow10 = 1;
    for(int i=0; i<N; i++)
        pow10 = (pow10 * 10) % MOD;

    cout << (pow10 - ans + MOD) % MOD << endl;
    return 0;
}


Measured memory_bytes: 20736
#include <cstdio>
#include <cstring>

int main() {
    char x[1001];
    while (1) {
        scanf("%s", x);
        if (x[0] == '0') break;

        int sum = 0;
        for (int i = 0; i < strlen(x); i++) {
            sum += x[i] - '0';
        }
        printf("%d\n", sum);
    }
    
    return 0;
}


Measured memory_bytes: 2672
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdouble(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int main(void) {
	int n;
	n = getint();
	showint(180*(n-2));
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdouble(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	while(true) {
		cin>>h>>w;
		if(h==0&&w==0) break;
		for(int i=0; i<h; i++) {
			for(int j=0; j<w; j++) {
				cout<<'#';
			}
			cout<<'\n';
		}
		cout<<'\n';
	}
	return 0;
}



Measured memory_bytes: 3204
//Bokann ga bokka--nn!!
//JOI 2006yo-6
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main(){
	int a,b;
	int n;
	while(1)
	{
		cin >> a >> b;
		if(!a) return 0;
		cin >> n;
		bool out[20][20]={};
		for(int i=0;i<n;i++)
		{
			int c,d; cin >> c >> d;
			out[c][d]=true;
		}
		int dp[20][20]={};
		dp[1][1]=1;
		for(int i=1;i<=a;i++)
		{
			for(int j=1;j<=b;j++)
			{
				if(out[i][j]) continue;
				if(i!=1) dp[i][j]+=dp[i-1][j];
				if(j!=1) dp[i][j]+=dp[i][j-1];
			}
		}
		cout << dp[a][b] << endl;
	}
}

Measured memory_bytes: 1160
S = input()
dic = {}
flg = True

for i in range(4):
    if S[i] in dic:
        dic[S[i]] += 1
    else:
        dic[S[i]] = 1
        
for k, v in dic.items():
    if v == 2:
        pass
    else:
        flg = False

if flg == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>
#include <iomanip>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )


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

	double total = 0;
	rep( i, N )
	{
		double d;
		string s;
		cin >> d >> s;

		if ( s == "JPY" )
		{
			total += d;
		}
		else
		{
			total += d * 380000.0;
		}
	}

	cout << fixed << setprecision( 8 ) << total << endl;

	return ( 0 );
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int r = Integer.parseInt(br.readLine());
        System.out.println(problem134a(r));
    }

    private static int problem134a(int r) {
        return 3 * r * r;
    }
}

Measured memory_bytes: 23508
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 1010000
ll MOD=1e9+7;
vector<vec> G;
int g[1010][1010];
vec visited;
vec ans;
bool dfs(int x,int s,int t){
    if(x==s&&t)return 1;
    if(visited[x]){
        return 0;
    }
    visited[x]=1;
    for(auto e:G[x]){
        if(dfs(e,s,1)){
            ans.pb(x);
            return 1;
        }
    }
    return 0;
}
int main(){
    int n=in();
    double d=(double)((n+1)/2)/(double)n;
    printf("%.10f",d);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

class bit
{
	private:
		vector<int> v;

	public:
		bit(int n)
		{
			v = vector<int>(n + 1, 0);
		}

		int get(int n)
		{
			int result = 0;
			for(int i = n; i > 0; i -= i & -i){
				result += v[i];
			}
			return result;
		}

		void add(int x, int val)
		{
			for(int i = x; i < v.size(); i += i & -i){
				v[i] += val;
			}
		}
};

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int> > v(300001);
	for(int i = 0; i < n; i++){
		int l, r;
		cin >> l >> r;
		v[r - l + 1].push_back(l);
	}
	int tmp = 0;
	bit b(m);
	for(int i = 1; i <= m; i++){
		int ans = 0;
		for(int j = i; j <= m; j += i){
			ans += b.get(j);
		}
		cout << n - tmp + ans << endl;
		for(int j = 0; j < v[i].size(); j++){
			b.add(v[i][j], 1);
			b.add(v[i][j] + i, -1);
		}
		tmp += v[i].size();
	}
	return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(){
  int n;
  double t,a;
  double diff = 10000;
  int ans = 0;
  cin >> n >> t >> a;
  for(int i=0;i<n;i++){
    double h;
    cin >> h;
    if(t-h*0.006==a){
      cout << i+1 << endl;
      return 0;
    }else if(fabs(a-(t-h*0.006))<diff){
      ans = i+1;
      diff = fabs(a-(t-h*0.006));
    }
  }
  cout << ans << endl;
}

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

int main()
{
    long long int n,i,counter,j,flag;
    cin>>n;
    long long int a[n];
    for(i=1;i<=n;i++)
        cin>>a[i];
    counter=0,flag=0;
    for(i=1,j=1;i<=n;i++)
    {
        if(a[i]==j)
        {
            flag=1;
            j++;
        }
        else
            counter++;
    }
    if(flag==1)
        cout<<counter<<endl;
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 1792
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			while (true) {
				int H = sc.nextInt();
				int W = sc.nextInt();
				if (H == 0 && W == 0) {
					break;
				}

				for (int h = 0; h < H; h++) {
					for (int w = 0; w < W; w++) {
						if (h == 0 || h == H - 1 || w == 0 || w == W - 1) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 34672
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    LL N,M;
    cin >> N >> M;
    
    LL ans = 0;
    if(2*N >= M){
        ans += M/2;
        cout << ans << endl;
        return 0;
    }

    ans += N;
    M = M - 2*N;
    ans += M/4;
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3520
from math import sqrt

x = int(input())
ans = 0

def is_prime(num):
    if num == 0 or num == 1:
        return False
    else:
        this_is_prime = True
        for i in range(2, int(sqrt(num)) + 1):
            if num % i == 0:
                this_is_prime = False
        return this_is_prime

for num in range(x, 10**6):
    if is_prime(num):
        ans = num
        break

print(ans)

Measured memory_bytes: 38512
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


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

const int N=200005;


void solve()
{
    string s,t;
    cin>>s>>t;
    int n=s.length();
    for(int i=0;i<n;i++)
        if(s[i]!=t[i])
        {
            cout<<"No"<<endl;
            return;
        }
    cout<<"Yes"<<endl;
}

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


Measured memory_bytes: 3660
N = gets.to_i
B = gets.split.map(&:to_i)
A = Array.new(N, 0)
A[0] = B[0]

B.each_with_index do |b,i|
    A[i] = b unless b > A[i]
    A[i+1] = b
end

puts A.inject(:+)

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

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

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

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

  sort(ALL(a));
  sort(ALL(b));

  int a_max=a[N-1];

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

  if(H>0)ans += (H+a_max-1)/a_max;

  cout << ans << endl;
}



Measured memory_bytes: 1024
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a = Counter(a)
ary = [0,0]
for i in a:
    if a[i] >= 4:
        ary.append(i)
        ary.append(i)
    elif a[i] >= 2:
        ary.append(i)
ary.sort()
print(ary.pop()*ary.pop())

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

int main() {
  int N, max, turn, alice, bob, maxid;
  cin >> N;
  vector<int> a(N);
  turn = 0;
  alice = 0;
  bob = 0;
  maxid = 0;

  for (int i = 0; i < a.size(); i++) 
    cin >> a.at(i);

  for (int i = 0; i < a.size(); i++) {
    max = 0;
    for(int j = 0; j < a.size(); j++) {
      if (max < a.at(j)) {
        max = a.at(j);
        maxid = j;
      }
    }
    a.at(maxid) = 0;
    if (turn % 2 == 0)
      alice += max;
    else 
      bob += max;
    turn++;
  } 
  
  cout << alice - bob << endl;
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////

int main(){fastio
    
    ll l,r,d;cin>>l>>r>>d;
    ll ans=0;
    rep(i,l,r){
        if(i%d==0)ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 200010;

int N;
ll A[MAX];

ll solve() {
    ll left = 0, right = 0;
    int l_idx = -1, r_idx = N;
    while (r_idx - l_idx > 1) {
        if (left < right) {
            left += A[++l_idx];
        } else {
            right += A[--r_idx];
        }
    }
    return abs(left - right);
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
    int m, n;
    long long rst = 1;

    scanf("%d%d", &m, &n);
    if(m-n>1 || m-n<-1) printf("0\n");
    else{
        for(int i=m; i>=1; i--){
            rst*=i;
            rst%=1000000007;
        }
        for(int i=n; i>=1; i--){
            rst*=i;
            rst%=1000000007;
        }
        if(m==n){
            rst*=2;
            rst%=1000000007;
        }
        printf("%lld\n", rst);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n;
ll dp[1<<21];
ll a[22][22];
ll store[22][1<<21];
ll f[22];
int main(){FAST;
cin>>n;
for(ll i=0;i<n;++i){
  for(ll j=0;j<n;++j){
    cin>>a[i][j];
  }
}
for(ll i=0;i<(1<<n);++i){
  ll ct = __builtin_popcount(i);
  store[ct][f[ct]++] = i;
}
dp[0] = 1;
for(ll i=0;i<n;++i){
  for(ll j=0;j<f[i];++j){
    for(ll k=0;k<n;++k){
      if((1<<k)&store[i][j]){

      }
      else if(a[i][k]){
        dp[store[i][j]|(1<<k)]+=dp[store[i][j]];
        dp[store[i][j]|(1<<k)]%=MOD;
      }
    }
  }
}
cout<<dp[(1<<n)-1];
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


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

void solve(){
    int N;
    cin >> N;
    int64_t ans = 0;
    vector<vector<pair<int, int>>> V(2);
    for(int i=0; i<N; i++){
        int k, l, r;
        cin >> k >> l >> r;
        if(l > r){
            ans += r;
            V[0].emplace_back(l-r, k-1);
        }else{
            ans += l;
            V[1].emplace_back(r-l, N-k-1);
        }
    }
    for(auto& A : V){
        int sz = A.size();
        set<int> st;
        for(int i=0; i<sz; i++) st.insert(-i);
        sort(A.rbegin(), A.rend());
        for(auto& [v, i] : A){
            auto it = st.lower_bound(-i);
            if(it != st.end()){
                ans += v;
                st.erase(it);
            }
        }
    }
    cout << ans << endl;
}

int main(){
    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 9684
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
    /*ld r;cin>>r;
    cout<<r*2*pi<<endl;*/
    /*ll n;cin>>n;
    vector<ll>ans(n,0);
    rep(i,n-1){
        ll a;cin>>a;a--;
        ans[a]++;
    }
    rep(i,n)cout<<ans[i]<<endl;*/
    ll n,m;cin>>n>>m;
    rep(i,m){
        ll a;cin>>a;
        n-=a;
    }
    cout<<max(n,(ll)-1)<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


Measured memory_bytes: 3616
H,W = map(int,input().split())
campus = [list(input()) for h in range(H)]

ans = 1
for h in range(H):
    for w in range(W):
        if campus[h][w] == '#':
            check = 0
            if h != 0:
                if campus[h-1][w] == '#':
                    check = 1
            if w != 0:
                if campus[h][w-1] == '#':
                    check = 1
            if h != H-1:
                if campus[h+1][w] == '#':
                    check = 1
            if w != W-1:
                if campus[h][w+1] == '#':
                    check =1
            if check == 0:
                ans = 0
                break

if ans == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    System.out.println((N * (N - 1) / 2) + (M * (M - 1) / 2));
  }
}

Measured memory_bytes: 21588
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <random>
#include <chrono>
using namespace std;

#define F first
#define S second
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define MP make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define kiyohime ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using vec = vector<T>;
template<typename T> using Prior = priority_queue<T>;
template<typename T> using prior = priority_queue<T, vec<T>, greater<T>>;

const int INF = 1e9;
const ll LLINF = (ll)4*1e18;
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;
const int xx[8] = {0,1,0,-1,1,1,-1,-1};
const int yy[8] = {1,0,-1,0,1,-1,-1,1};

void pmod(ll &a, ll b) {a = (a+b)%MOD;}
void mmod(ll &a, ll b) {a = (a-b+MOD)%MOD;}
void tmod(ll &a, ll b) {a = (a*b)%MOD;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll POW(ll a, ll b) {ll res=1; do{if(b%2)tmod(res,a);tmod(a,a);}while(b>>=1); return res;}
template<typename T> void amax(T &a, T b) {if(a < b) a = b;}
template<typename T> void amin(T &a, T b) {if(a > b) a = b;}

#define N 100010

int dsu[N];
ll sz[N];

int find(int x){
    return dsu[x] == x ? x : dsu[x] = find(dsu[x]);
}

void unite(int a, int b){
    sz[find(b)] += sz[find(a)];
    dsu[find(a)] = find(b);
}

void solve(){
    int n, m;
    
    cin >> n >> m;
    vec<pii> v(m);
    for(auto &i:v) cin >> i.F >> i.S;
    reverse(ALL(v));
    
    rep1(i, n) dsu[i] = i, sz[i] = 1;
    
    ll k = (ll) n * (n-1) / 2;
    vec<ll> ans;
    ans.EB(k);
    for(auto i:v) {
        if(find(i.F) != find(i.S)){
            k -= sz[find(i.F)] * sz[find(i.S)];
            unite(i.F, i.S);
        }
        ans.EB(k);
    }
    
    reverse(ALL(ans));
    rep1(i, m) cout << ans[i] << ' ' ;
    cout << endl;
}

int main(){
    kiyohime
    int T = 1;
    
//    cin >> T;
    while(T--){
        solve();
    }
}




Measured memory_bytes: 6744
def algae(r, d, x):

    ans = []
    count = x
    for i in range(1, 11):
        count = r*count - d
        ans.append(count)
    return ans

def main():
    r, d, x = map(int, input().split())
    ans = algae(r, d, x)
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
int a[100010];
string s;
bool check(int x){
  //cerr<<x<<endl;
	int cnt=0;
	set<P> st[2];
	set<int> sti[2];
	int c[100010]={};
	for(int i=0; i<n; i++){
		cnt++;
		if(i==n-1 || ((a[i]<x)!=(a[i+1]<x))){
			if(a[i]<x){
				st[0].insert({cnt, i});
				c[i]=cnt;
				sti[0].insert(i);
			}else{
				st[1].insert({cnt, i});
				c[i]=cnt;
				sti[1].insert(i);
			}
			cnt=0;
		}
	}
	if(st[0].empty() || st[1].empty()){
		return st[0].empty();
	}
	int d[2]={};
	for(int i=0; i<n-1; i++){
		int t=0;
		if(s[i]=='m') t=1;
		{
			if(*sti[t].begin()>*sti[t^1].begin()){
				int i0=*sti[t^1].begin();
				P p0=P(c[i0], i0);
				st[t^1].erase(p0);
				p0.first--; c[i0]--;
				st[t^1].insert(p0);
			}
			if(*sti[t].rbegin()<*sti[t^1].rbegin()){
				int i0=*sti[t^1].rbegin();
				P p0=P(c[i0], i0);
				st[t^1].erase(p0);
				p0.first--; c[i0]--;
				st[t^1].insert(p0);
			}
			d[t]--;
			d[t^1]++;
			for(auto itr=st[t].begin(); itr!=st[t].end();){
				P p=*itr;
				if(p.first>-d[t]) break;
				itr=st[t].erase(itr);
				int k=p.second;
              sti[t].erase(k);
				auto itr1=sti[t^1].lower_bound(k);
				if(itr1==sti[t^1].end()) continue;
				auto itr2=itr1;
				if(itr2==sti[t^1].begin()) continue;
              itr2--;
				P p1=P(c[*itr1], *itr1), p2=P(c[*itr2], *itr2);
				st[t^1].erase(p1); st[t^1].erase(p2);
				int k1=*itr1;
				c[k1]=c[k1]+c[*itr2]+d[t^1];
				p1=P(c[k1], k1);
				st[t^1].insert(p1);
				sti[t^1].erase(itr2);
			}
		}
		if(st[0].empty() || st[1].empty()){
			return st[0].empty();
		}
	}
	//cerr<<x<<endl;
	//assert(0);
}
int main()
{
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	cin>>s;
	int l=0, r=n+1;
	while(r-l>1){
		int mid=(l+r)/2;
		if(check(mid)) l=mid;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

ll n;
ll ans;
//string s,t;
signed main(){
	acc_io;
	cin>>n;
	map<int,int>a;
	rep(i,0,n){
		int tmp;
		cin>>tmp;
		++a[tmp];
	}
	ans=0;
	for(auto i:a){
//	for(pair<ll,ll> i:a){
		if(i.second>=i.first){
			ans+=i.second-i.first;
		}
		else{
			ans+=i.second;
		}
	}
	
//	DBG(s,t,0,0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4736
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;
 
int main() {
    int m1, m2, d1, d2; cin >> m1 >> d1 >> m2 >> d2;
    if (d1 > d2) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x, y;
  cin >> x >> y;
  if (y % 2 == 0 and 2 * x <= y and y <= 4 * x) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 3644
n, t = map(int, input().split())
t_min = 1001

for i in range(n):
    x, y = map(int, input().split())
    if y <= t:
        t_min = min(t_min, x)

if t_min == 1001:
    print("TLE")
else:
    print(t_min)

Measured memory_bytes: 2940
let id x = x
let n = Scanf.scanf "%d\n" id
let d, x = Scanf.scanf "%d %d\n" (fun a b -> a, b)

let eat freq =
  let rec aux day sum =
    if d < day then sum else aux (day + freq) (sum + 1)
  in
  aux 1 0

let solve n = 
  let rec aux i sum =
    if i = 0 then sum
    else aux (i - 1) (sum + eat (Scanf.scanf "%d\n" id))
  in
  aux n 0

let () = solve n |> (+) x |> Printf.printf "%d\n"

Measured memory_bytes: 384
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
n, m = map(int, input().split())
t = [[int(x) for x in input().split()] for _ in range(m)]
uf = UnionFind(n)
ans=[]
ans.append(n*(n-1)/2)

for i in t[::-1]:
    if uf.isSameGroup(i[0],i[1]):
        ans.append(ans[-1])
        
    else:
        ans.append(ans[-1]-(uf.Count(i[0])*uf.Count(i[1])))
        
        uf.Unite(i[0],i[1])
for i in ans[-2::-1]:
    
    print(int(i))                   
                  


Measured memory_bytes: 28004