akhauriyash/Code-Regression huggingface dataset:
/*
  AUTHOR:SOURABH
  CREATED:31:05:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pii , null_type, less< pii >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,i,l,r,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        vll a(n),b(n);
        fn(i,n)cin>>a[i]>>b[i];
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        if(n%2)
            cout<<b[n/2]-a[n/2]+1;
        else
        {
            ans=0;
            l=(a[n/2-1]+a[n/2])/2;
            if((a[n/2-1]+a[n/2])%2)
                l++,ans++;
            r=(b[n/2-1]+b[n/2])/2;
            if((b[n/2-1]+b[n/2])%2)
                ans++;
            ans+=r-l+1;ans+=r-l;
            cout<<ans;
        }
    }
    return 0;
}









Measured memory_bytes: 6348
N = int(input())
import numpy as np
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int,input().split())
na = np.median(A)
nb = np.median(B)
if N%2 == 1:
    ans = int(nb - na + 1)
    print(ans)
    exit()
else:
    ans = int(2*(nb - na)) + 1
    print(ans)
    exit()


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n+1);
  for(int i=0;i<=n;i++) p[i]=i;
  vector<long> q(n+2);
  q[0] = 0;
  for(int i=1;i<=n+1;i++) q[i] = q[i-1]+p[i-1];
  long ans = 0;
  long mod = 1000000007;
  for (int i=k;i<=n+1;i++){
    ans += (q[n+1]-q[n+1-i]-q[i]+1)%mod;
  }
  cout << ans%mod << endl;
}

Measured memory_bytes: 5608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    string s; cin >> s;
    
    ll R = count(s.begin(),s.end(),'R');
    ll B = count(s.begin(),s.end(),'B');
    if(R > B) return "Yes";
    else return "No";
//    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()


int main() {
    string S;
    cin >> S;
    int len = S.length(), ans = len;
    vector<int> vi;
    char c = S[0];
    FOR(i, 1, len) {
        if (S[i] != c) {
            c = S[i];
            vi.push_back(i);
        }
    }

    for (int i : vi) ans = min(ans, max(i, len - i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    string N;

    cin >> N;

    cout << (N == "ABC"?"ARC":"ABC") << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Car
{
	int pos, v, prev;
	double t;
	Car(int pos, int prev, int v, double t)
		: pos(pos), prev(prev), v(v), t(t) { }
};
bool operator<(const Car& a, const Car& b)
{
	return a.t > b.t;
}
int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		int s, g;
		cin >> s >> g;
		--s, --g;
		int d[32][32], c[32][32];
		CLEAR(d, -1);
		while (m--)
		{
			int x, y, dis, cons;
			cin >> x >> y >> dis >> cons;
			--x, --y;
			d[x][y] = d[y][x] = dis;
			c[x][y] = c[y][x] = cons;
		}

		double min_time[32][32][32];
		const double INF = 1e10;
		rep (i, n) rep (j, n)rep (k, 31)
			min_time[i][j][k] = INF;

		priority_queue<Car> q;
		q.push(Car(s, n, 0, 0));
		min_time[s][n][0] = 0;
		while (!q.empty())
		{
			Car car = q.top(); q.pop();
			if (car.t > min_time[car.pos][car.prev][car.v])
				continue;

			for (int to = 0; to < n; ++to)
			{
				if (to != car.prev && d[car.pos][to] != -1)
				{
					for (int a = -1; a <= 1; ++a)
					{
						int nv = car.v + a;
						if (nv <= 0 || nv > c[car.pos][to])
							continue;

						double nt = car.t + (double)d[car.pos][to] / nv;
						if (nt < min_time[to][car.pos][nv])
						{
							q.push(Car(to, car.pos, nv, nt));
							min_time[to][car.pos][nv] = nt;
						}
					}
				}
			}
		}
		double res = INF;
		for (int i = 0; i < n; ++i)
			min_swap(res, min_time[g][i][1]);
		if (res < INF)
			printf("%.6f\n", res);
		else
			puts("unreachable");
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
static double PI = ::acos(-1);


int main()
{
    int64 n, k;
    cin >> n >> k;
    vint a(n), f(n);
    Rep(i, n)
    {
        cin >> a[i];
    }
    Rep(i, n)
    {
        cin >> f[i];
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<int>());

    int64 left = -1, right = 1e12;
    while (left + 1 < right)
    {
        int64 center = (left + right) / 2;
        int64 sum = 0;
        Rep(i, n)
        {
            sum += max(0LL, a[i] - center / f[i]);
        }
        if (k >= sum)
        {
            right = center;
        }
        else
        {
            left = center;
        }
    }
    cout << right << endl;

    return 0;
}


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

    } else{
      printf("a == b\n");
    }
return 0;
}



Measured memory_bytes: 2100
# -*- coding:utf-8 -*-

def solve(a, s):
	left = 0
	right = len(a) - 1
	
	cnt = 0
	while left <= right:
		mid = (left + right) / 2
		cnt += 1
		if a[mid] == s:
			break
		elif a[mid] < s:
			left = mid + 1
		else:
			right = mid - 1
	return cnt


while True:
	n = int(raw_input())
	if n == 0: break
	a = [ int(raw_input()) for _ in xrange(n) ]
	s = int(raw_input())
	print solve(a, s)

Measured memory_bytes: 4228
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    for(ll i = 0; i < N; i++){
        cin >> X[i];
    }
    vector<ll> dif(N, 0);
    for(ll i = 1; i < N; i++){
        dif[i] = X[i] - X[i - 1];
    }
    ll sum = 0;
    for(ll i = 1; i < N; i++){
        sum += min(A * dif[i], B);
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split(' ');
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int C = int.Parse(str[2]);

		string[] strB = Console.ReadLine().Split(' ');
		int[] B = new int[M];
		for (int i = 0; i < M; i++)
		{
			B[i] = int.Parse(strB[i]);
			// Console.WriteLine("Bは"+B[i]);
		}

		int[,] A = new int[N, M];
		for (int i = 0; i < N; i++)
		{
			string[] strA = Console.ReadLine().Split(' ');
			for (int j = 0; j < M; j++)
			{
				A[i, j] = int.Parse(strA[j]);
				// Console.WriteLine("Aは"+A[i,j]);
			}
		}
		//入力完了

		int fAns = 0;
		int[] ans = new int[N];
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < M; j++)
			{
				ans[i] += A[i,j] * B[j];
			}
			ans[i] += C;
			// Console.WriteLine(ans[i]);
			if(ans[i] > 0)
				fAns++;
		}
		Console.WriteLine(fAns);
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
#define MN 10000
#define mod 998244353
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,a[MN+5],tot=0;
bitset<4000005> b;
int main()
{
    b[0]=1;n=read();
    for(int i=1;i<=n;++i) a[i]=read(),tot+=a[i],b=b|(b<<a[i]);
    for(int j=(tot+1)/2;;++j) if(b[j]) return 0*printf("%d\n",j);
    return 0;
}


Measured memory_bytes: 2176
n, m, l = map(int, input().split(' '))
a = [list(map(int, input().split(' '))) for i in range(n)]
b = [list(map(int, input().split(' '))) for i in range(m)]

c = []
for i in range(n):
    lst = []
    for j in range(l):
        tmp = 0
        for k in range(m):
            tmp += (a[i][k] * b[k][j])
        lst.append(tmp)
    c.append(lst)

for i in range(n):
    for j in range(l):
        if (j == l - 1):
            print(c[i][j])
        else:
            print(f"{c[i][j]} ", end="")



Measured memory_bytes: 7068
n;s;e;w;i;main(){
    char t[1000];
    gets(t);
    
    for(;i<strlen(t);i++){
        if(t[i]=='N'){
            n=1;
        }else if(t[i]=='S'){
            s=1;
        }else if(t[i]=='E'){
            e=1;
        }else if(t[i]=='W'){
            w=1;
        }
    }
    
    if(abs(n-s)+abs(w-e)){
        printf("No");   
    }else{
    
        printf("Yes"); 
    }
    
    /*
    if((n-s)==0 && (w-e)==0){
        printf("Yes");   
    }else{
    
        printf("No"); 
    }*/
    
    
}


Measured memory_bytes: 1616
<?php
[$N, $c['A'], $c['B'], $c['C']] = array_map('intval',explode(' ',trim(fgets(STDIN))));;
for($i = 0; $i < $N; $i++){
    $S[] = trim(fgets(STDIN));
}
$path = [];
dfs(0, $path, $c);
echo "No\n"; // ゴールインできなかったらだめです！
function dfs($d, &$path, $c){ // &は参照渡し。そうしないと値の複製O(N)が実行され、全体でO(N^2)になる
    global $S, $N; // PHPで関数外の変数を参照するにはこうやればよい
    if($d == $N){ // ゴールイン！
        echo "Yes\n";
        echo implode("\n", $path);
        exit;
    }
    $s = $S[$d];
    for($i = 0; $i < 2; $i++){ //1文字目と2文字目をそれぞれ試す
        if($c[$s[$i]] > 0){ 
            $path[] = $s[1-$i]; //経路を追加
            $c[$s[$i]]--; //片方をへらす
            $c[$s[1-$i]]++; //他方を増やす
            dfs($d+1, $path, $c);
            $c[$s[$i]]++; // 元に戻す
            $c[$s[1-$i]]--; // 元に戻す
            array_pop($path); // 元に戻す
        }
    }
}


Measured memory_bytes: 129740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF=1e9+7;

int main() {
    int N,t,l;
    cin >> N;
    vector<int> p;

    p.push_back(1);
    t = 1;
    while((t*=6) <= 100000)
        p.push_back(t);
    t = 1;
    while((t*=9) <= 100000)
        p.push_back(t);
    l = p.size();

    vector<vector<int>> dp(l+1, vector<int>(N+1,INF));
    rep(i,l+1)
        dp.at(i).at(0) = 0;

    rep(i,l)
        rep(j,N+1)
            if(p.at(i) > j)
                dp.at(i+1).at(j) = dp.at(i).at(j);
            else
                dp.at(i+1).at(j) = min(dp.at(i).at(j), dp.at(i+1).at(j-p.at(i))+1);
    cout << dp.at(l).at(N) << endl;
}

Measured memory_bytes: 5760
#include "iostream"
using namespace std;

char letter[100001];
int a[100001], b[100001];
int num;

int main() {
	cin >> letter;
	for (int i = 0; letter[i] != NULL; i++) {
		if (letter[i] == 'b')a[i] = 0;
		else if (letter[i] == 'd')a[i] = 1;
		else if (letter[i] == 'p')a[i] = 2;
		else a[i] = 3;
		num++;
	}
	for (int i = 0; i < num; i++) {
		if (letter[num - 1 - i] == 'd')b[i] = 0;
		else if (letter[num - 1 - i] == 'b')b[i] = 1;
		else if (letter[num - 1 - i] == 'q') b[i] = 2;
		else b[i] = 3;
	}
	for (int i = 0; i < num; i++) {
		if (a[i] != b[i]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0) (__VA_ARGS__)
#define rep_0(i, end) for (int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for (int i = (fr); i <= (ba); ++i)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

  int N;
  std::cin >> N;
  std::vector<long long> a(N), b(N);
  rep (i, N) std::cin >> a[i];
  rep (i, N) std::cin >> b[i];

  long long one = 0, two = 0, steps = 0;
  rep (i, N) {
    steps += b[i] - a[i];
    if (a[i] < b[i]) two += (b[i] - a[i] + 1) / 2;
    else one += a[i] - b[i];
  }

  puts(one <= steps && two <= steps ? "Yes" : "No");
  return 0;

}


Measured memory_bytes: 384
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextLong()

  val mod = 1000000007

  def plus(a: Long, b: Long): Long = (a + b) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  def fact(n: Long, res: Long = 1): Long = {
    if (n == 0) res else fact(n-1, times(res, n))
  }

  if ((n-m).abs > 1) {
    println(0)
  } else if (n == m) {
    val f = fact(n)
    println(times(2, times(f, f)))
  } else {
    val f = fact(n.min(m))
    println(times(f, times(f, n.max(m))))
  }
}


Measured memory_bytes: 55372
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }


signed main() {

	int d[100][100];
	int N, M;
	cin >> N >> M;

	rep(i, N)rep(j, N) d[i][j] = INF;
	rep(i, M) {
		int a, b, w;
		cin >> a >> b >> w;
		d[a][b] = w;
	}

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			if (d[i][k] == INF) continue;
			for (int j = 0; j < N; j++) {
				if (d[k][j] == INF) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	bool negative = false;
	rep(i, N) if (d[i][i] < 0) negative = true;

	if (negative) cout << "NEGATIVE CYCLE" << endl;
	else {
		rep(i, N) {
			rep(j, N) {
				if (i == j) cout << "0";
				else if (d[i][j] == INF) cout << "INF";
				else
					cout << d[i][j];
				if (j < N - 1) cout << " ";
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll n, k; cin >> n >> k;
    ll p[n];
    rep(i, n){
        cin >> p[i];
    }

    double expect[n];
    rep(i, n){
        expect[i] = (p[i] + 1) / 2.0;
    }

    double sum_expect[n + 1] = {};
    reps(i, 1, n + 1){
        sum_expect[i] = sum_expect[i - 1] + expect[i - 1];
    }

    // rep(i, n){
    //     cout << expect[i] << "  ";
    // }
    // cout << endl;
    // rep(i, n + 1){
    //     cout << sum_expect[i] << "  ";
    // }
    // cout << endl;

    double ans = 0.0;
    rep(i, n - k + 1){
        // cout << sum_expect[i + k] - sum_expect[i] << endl;
        ans = max(ans, sum_expect[i + k] - sum_expect[i]);
    }

    cout << fixed << setprecision(10);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
using namespace std;
 
int main(){
  int N;
  string S;
  cin >> N >> S;
  int R[2] = {};
  for(auto& c : S){
    if(c == 'R') c = '0';
    else c = '1';
    ++R[c-'0'];
  }
  int ans = min(R[0],R[1]);
  int L[2] = {};
  for(auto c : S){
    --R[c-'0'];
    ++L[c-'0'];
    ans = min(ans,max(L[1],R[0]));
  }
  cout << ans << endl;
}

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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

signed main() {
    ll A, B, K;
    cin >> A >> B >> K;

    if (K <= A) {
        cout << A - K << ' ';
        cout << B << endl;
    } else if (K <= (A+B)) {
        cout << 0 << ' ';
        cout << B + A - K << endl;
    } else {
        cout << 0 << ' ';
        cout << 0 << endl;
    }


}



Measured memory_bytes: 3592
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

ll count(ll x) {
  if (x == 1) return 1;
  return 2*count(x>>1) + 1;
}

void solve(ll H) {
  cout << count(H) << endl;
}

int main() {
  ll H;
  cin >> H;
  solve(H);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n,x;
    scanf("%d %d", &n, &x);    

    int curr=0;
    int count=1;
    for(int i=0;i<n;i++)
    {
        int l;
        scanf("%d", &l);
        curr+=l;
        if(curr<=x) count++;
    }

    printf("%d\n", count);

}

Measured memory_bytes: 256
#include <iostream>

int main()
{
   int a,b,c,d,e,f;
    std::cin>>a>>b>>c>>d>>e>>f;
    if(a+b*5+c*10+d*50+e*100+f*500<1000)std::cout<<0<<std::endl;
    else std::cout<<1<<std::endl;
}

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

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

    int a = -1;
    int b = -1;
    int c = -1;
    int total = 0;
    for(int i = 0; i <= n; i++){
        for(int j = 0; i + j <= n; j++){
            total = 10000*i + 5000*j + 1000*(n - i - j);
            if(total == y){
                a = i;
                b = j;
                c = n - i - j;
            }
        }
    }

    cout << a << " " << b << " " << c << endl;

    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[m], d[m];
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, m) cin >> c[i] >> d[i];

    rep(i, n) {
        int ans = 1e9;
        int now = 0;
        rep(j, m) {
            int l = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (l < ans) {
                ans = l;
                now = j + 1;
            }
        }
        cout << now << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    VEC(int,v,n);
    sort(ALL(v),greater<int>());
    int a = 0,b = 0;
    rep(i,n){
        if(i%2==0)a += v[i];
        else b += v[i];
    }
    cout<<a-b;
}



Measured memory_bytes: 256
N = int(input())
S = sorted([int(input()) for i in range(N)])
A = sum(S)

if A%10!=0:
  print(A)
else:
  T = [s for s in S if s%10!=0]
  if len(T)==0:
    print(0)
  else:
    print(A-T[0])

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
    int i,j,k,n;
    int b,f,r,v,c[5][4][11];
    scanf("%d",&n);
    
    for(i=0;i<5;i++){
        for(j=0;j<4;j++){
            for(k=0;k<11;k++){
                c[i][j][k]=0;
            }
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        c[b][f][r]=v+c[b][f][r];
    }
    for(i=1;i<=4;i++){
        if(i>1){
            printf("####################\n");
        }
    for(j=1;j<=3;j++){
        for(k=1;k<=10;k++) printf(" %d",c[i][j][k]);
        printf("\n");
        }
    }
    
  return 0;
}


Measured memory_bytes: 2060
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll x, a, b;
  scanf("%lld%lld%lld", &x, &a, &b);
  if (llabs(x - a) < llabs(x - b))
    puts("A");
  else
    puts("B");

  return 0;
}


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

using namespace std;

#define ll long long




void solve() {

	int l, r, d;
	cin >> l >> r >> d;
	int cnt = 0;
	for(int i = l; i <= r; i++) {
		if(i % d == 0) {
			cnt++;
		}
	}
	cout << cnt;

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

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

int main() {
	
	int n, k;
	string s;
	cin >> n >> k >> s;
	s[k-1] = s[k-1] - 'A' + 'a';
	cout << s << endl;
	
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  double sum = 0;
  for (int i = 1; i <= n; ++i) {
    int c = i;
    double p = 1.0 / n;
    while (c < k) {
      c *= 2;
      p /= 2;
    }
    sum += p;
  }
  cout << fixed << setprecision(16) << sum << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<ll> a(n);
	for (auto &v : a) {
		cin >> v;
	}
	a.push_back(0LL);

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= 2LL) {
			ans += a[i] / 2LL;
			a[i] = a[i] & 1LL ? 1LL : 0LL;
		}

		if (a[i] >= 1LL && a[i + 1] >= 1LL) {
			ll score = min(a[i], a[i + 1]);
			ans += score;
			a[i] -= score;
			a[i + 1] -= score;
		}
	}

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


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

const int maxn = 22;
int N, a[maxn][maxn], dp[1<<maxn], MOD = 1e9+7;

int cnt_dig(int state){
    int cnt = 0;
    while (state) {
        cnt++;
        state = state&(state-1);
    }
    return cnt;
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>N;
    for(int i = 0; i<N;i++){
        for(int j =0 ; j<N; j++){
            cin>>a[i][j];
        }
    }
    dp[0]=1;
    for(int i = 0; i < (1<<N); i++){
        int c = cnt_dig(i);
        for(int j = 0; j<N; j++){
            if (!((i >> j) & 1)) {
                if (a[c][j]) dp[i | (1 << j)] = (dp[i | (1 << j)] + dp[i]) % MOD;
            }
        }
    }
    
    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}



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

int main () {
  int a,b,c,x,ans=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a&&i*500<=x;i++){
    for(int j=0;j<=b&&i*500+j*100<=x;j++){
      if((x-(500*i+100*j))%50==0&&(x-(500*i+100*j))/50<=c&&(x-(500*i+100*j))/50>=0&&(i+j+(x-(500*i+100*j))/50)>0){
        ans++;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int a[4];

    signed call_of_Cthulhu( signed datum ) {

        for ( int i = 0; i < 3; i++ ) {
            int q, w;
            read q >> w;
            a[q]++;
            a[w]++;
            if ( a[q] == 3 || a[w] == 3 ) {
                echo "NO" fin;
                return 0;
            }
        }
        echo "YES" fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main {
 
    public static void main(String[] args) throws Exception {
 
        try {
 
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
            int currentRating = Integer.parseInt(br.readLine());
            int goalRating = Integer.parseInt(br.readLine());
 
            int targetRating = 0;
            targetRating = (goalRating - currentRating) + goalRating;
            System.out.println(targetRating);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

int main(void){
    vector<string> grade;
    while(1){
        int m,f,r;
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1)
            break;
        if(m==-1 || f==-1){
            grade.push_back("F");
            continue;
        }
        
        int sum = m+f;
        if(sum >= 80){
            grade.push_back("A");
            continue;
        }

        if(sum >=65){
            grade.push_back("B");
            continue;
        }

        if(sum >= 50){
            grade.push_back("C");
            continue;
        }

        if(sum >=30){
            if(r >= 50){
                grade.push_back("C");
            }
            else
                grade.push_back("D");
            continue;
        }

        if(sum < 30){
            grade.push_back("F");
            continue;
        }
    }

    for(auto result : grade){
        cout << result << endl;
    }
}


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

using namespace std;

using ll = long long;
using P = pair<int, int>;
using E = pair<ll, P>;

const ll INF = 1LL << 60;

int n;
ll D;
ll a[200005];
vector< E > edges;

void solve(int L, int R) {
    if (R - L <= 1) return;
    int mid = (R + L) / 2;

    ll lval = INF;
    int lidx = -1;
    for (int i = L; i < mid; i++) {
        ll tmp = a[i] - D * i;
        if (lval > tmp) {
            lidx = i;
            lval = tmp;
        }
    }

    ll rval = INF;
    int ridx = -1;
    for (int i = mid; i < R; i++) {
        ll tmp = a[i] + D * i;
        if (rval > tmp) {
            ridx = i;
            rval = tmp;
        }
    }

    for (int i = L; i < mid; i++) {
        edges.emplace_back(a[i] + a[ridx] + D * (ridx - i), P(i, ridx));
    }

    for (int i = mid; i < R; i++) {
        edges.emplace_back(a[i] + a[lidx] + D * (i - lidx), P(lidx, i));
    }

    solve(L, mid);
    solve(mid, R);
}

struct UnionFind {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;

    UnionFind(int sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return is_union;
    }

    int find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -data[find(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> D;
    for (int i = 0; i < n; i++) cin >> a[i];
    solve(0, n);

    sort(edges.begin(), edges.end());
    UnionFind uf(n);
    ll ans = 0;
    for (E& e : edges) {
        ll cost = e.first;
        int u = e.second.first, v = e.second.second;
        if (!uf.same(u, v)) {
            uf.unite(u, v);
            ans += cost;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 69472
A, B, ANGC = gets.split.map &:to_i
CR = ANGC * Math::PI / 180.0
C = (A*A + B*B - A * B * Math.cos(CR) * 2)**(1.0/2)
SS = A * B * Math.sin(CR)
puts SS / 2
puts A + B + C
puts SS / A

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

using namespace std;

vector<vector<int>> D;

int main(){
	int K; scanf("%d",&K);
	D = vector<vector<int>>(20, vector<int>(10, 0));

	D[1] = vector<int>(10, 1);
	for(int i=2;i<D.size();i++){
		for(int j=0;j<10;j++){
			if(j > 0) D[i][j] += D[i-1][j-1];
			D[i][j] += D[i-1][j];
			if(j < 9) D[i][j] += D[i-1][j+1];
		}
	}
	int len, now, S = 0;
	for(len = 1; ; len++){
		for(now = 1; now<10; now++){
			K -= D[len][now];
			if(K <= 0) break;
		}
		if(now < 10) break;
	}
	K += D[len][now];
	for(;len>=1; len--){
		printf("%d", now);
		if(now >= 1 && K <= D[len-1][now-1]){ now = now - 1; continue; }
		if(now >= 1) K -= D[len-1][now-1];
		if(K <= D[len-1][now]) continue;
		K -= D[len-1][now];
		now = now + 1;
	}
}


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

int to_i(const string &s) {
    int n;
    istringstream is(s);
    is >> n;
    return n;
}

string to_s(int n) {
    char buf[256];
    sprintf(buf, "%04d", n);
    return string(buf);
}

int main() {
    string s;
    while (cin >> s, s != "0000") {
        string t;
        int n;
        int c = 0;
        while (true) {
            if (s == "6174") {
                cout << c << endl;
                break;
            }
            t = s;
            sort(s.begin(), s.end());
            sort(t.begin(), t.end(), greater<char>());
            if (s == t) {
                cout << "NA" << endl;
                break;
            }
            n = to_i(t) - to_i(s);
            s = to_s(n);
            c++;
        }
    }
    return 0;
}

Measured memory_bytes: 1292
(a,b) = input().split()
a = int (a)
a = a + 1
b = int (b)
list_a = set(range(1,a,1))
for i in range(b):
    c = input()
    d = input().split()
    d = set(map(int,d))
    list_a = list_a-d
print(len(list_a))

Measured memory_bytes: 9088
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1000000007
#define mxval 1e9 + 7
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/*********FUNCTIONS**************/
int powom(int a,int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a;
        a = a * a;
        b >>= 1;
    }
    return result;
}
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	for(int i=1;i<n-1;i++){
		vector<int> v1;
		for(int j=-1;j<2;j++){
			v1.pb(v[i+j]);
		}
		sort(all(v1));
		if(v1[1]==v[i]){
			cnt[0]++;
		}
	}
	cout<<cnt[0];
	return 0;
}
//.........

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	print_Yes_No(a==b && b==c);
}


Measured memory_bytes: 256
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    M = 10 ** 5

    N = int(input())

    g = tuple(set() for _ in range(M * 2))
    for _ in range(N):
        x, y = (int(x) - 1 for x in input().split())  # 一律に移動
        g[x].add(y + M)
        g[y + M].add(x)

    visited = [0] * (M * 2)
    ans = 0
    for s in range(M * 2):
        if visited[s]: continue
        visited[s] = 1
        dq = deque()
        dq.append(s)

        sz = 0
        x = 0
        e = 0
        while dq:
            v = dq.popleft()
            sz += 1
            if v < M:
                x += 1
            for u in g[v]:
                e += 1
                if visited[u]: continue
                visited[u] = 1
                dq.append(u)
        ans += (sz - x) * x - (e // 2)
        # ans += (sz - x) * x - (sz - 1) # sz-1は木に限られるのでWA

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69124
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;


#[fastout]
fn main() {
    input! {
    n: usize,
    a: [Usize1; n]
    }
    let mut g = vec![0; n];
    for i in 0..n {
        g[a[i]] = i + 1;
    }
    for c in g {
        print!("{} ", c)
    }
}


Measured memory_bytes: 4044
#include<stdio.h>
typedef long long int LL;


int main(){
	LL N,h,n,w,t1,t2;
	
	scanf("%d",&N);
	
	for(h=1;h<=3500;h++){
		for(n=1;n<=3500;n++){
			t1=N*h*n;
			t2=4*h*n-N*(h+n);
			if(t1>0&&t2>0&&t1%t2==0){
				w=t1/t2;
				printf("%lld %lld %lld",h,n,w);
				return 0;
			}
		}
	}
	
	return 0;
} 

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#define LEN 100

char s[LEN], t[LEN];

int main(void)
{
    scanf("%s", s);
    scanf("%s", t);
    int lastpos = -1;
    for (int i = 0; i < strlen(s); i++) {
        bool flag = true;
        for (int j = 0; j < strlen(t); j++) {
            if (i + j >= strlen(s) || s[i + j] != t[j] && s[i + j] != '?') {
                flag = false;
                break;
            }
        }
        if (flag) lastpos = i;
    }
    if (lastpos == -1) {
        printf("UNRESTORABLE\n");
        return 0;
    }
    for (int i = 0; i < strlen(s); i++) {
        if (i >= lastpos && i < lastpos + strlen(t))
            s[i] = t[i - lastpos];
        else if (s[i] == '?') s[i] = 'a';
    }
    printf("%s\n", s);
    return 0;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

// template<class T> void chmin(T& a, T b) {
//     if (a > b) {
//         a = b;
//     }
// }

// template<class T> void chmax(T& a, T b) {
//     if (a < b) {
//         a = b;
//     }
// }

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

    vector<int> h(n+1);
    for(int in=0;in<n;in++) {
        cin >> h.at(in);
    }
    h.at(n) = 0;

    int ans=0;
    for(int in=0;in<n;in++) {
        if(h.at(in)>h.at(in+1)) ans += h.at(in)-h.at(in+1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{

    private final static int MOD = 1_000_000_007;

    public static int gcd(int a, int b) { 
        // Everything divides 0  
        if (a == 0) 
          return b; 
        if (b == 0) 
          return a; 
       
        // base case 
        if (a == b) 
            return a; 
       
        // a is greater 
        if (a > b) 
            return gcd(a-b, b); 
        return gcd(a, b-a); 
    }
    
    public static long mod(long a, long b) {
        return ((a % b) + b ) % b;
    }

    public static int mod (int a, int b) {
        return ((a % b) + b ) % b;
    }
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
	String s = in.nextLine();
	String t = in.nextLine();
	int res = 0;
	for (int i = 0; i < s.length(); i++) {
	    if (s.charAt(i) != t.charAt(i)) res++;
	}
	System.out.println(res);
	in.close();
    }
}


Measured memory_bytes: 42180
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
bool h = false;
ll reg1 = 0;
bool judge(ll x){
    cout << x << endl;
    string s;
    cin >> s;
    ll reg;
    if (s == "Vacant"){
        h = true;
        return 0;
    }else if(s=="Male"){
        reg = ((1 + (x) % 2) % 2);
    }else{
        reg = (( (x) % 2) % 2);
    }
    return reg == reg1;
}
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
ll combi(ll a, ll b)
{
    if (a < b)
        return 0;
    ll res = 1;
    for (ll i = a; i >= a - b + 1; i--)
    {
        res *= i;
        res %= MOD;
    }
    rep3(i, 1, b + 1)
    {
        res *= modinv(i, MOD);
        res %= MOD;
    }
    return res;
}
//a,m=MOD MOD逆元
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    VV vec(n, V(n));
    rep(i, n) rep(j, n) cin >> vec[i][j];
    ll res=0;
    rep(i,n){
        rep(j,n){
            bool h=false;
            rep(k,n){
                if(vec[i][k]+vec[k][j]<vec[i][j]){
                    cout << -1 << endl;
                    return 0;
                }
                if(vec[i][k]+vec[k][j]==vec[i][j]&&vec[i][k]!=0&&vec[k][j]!=0){
                    h=true;
                }
            }
            if(!h)res+=vec[i][j];
        }
    }
    cout<<res/2<<endl;
}


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

int main(){
  int a=0, b=0, c=0, swap=0;
  cin >> a >> b >> c;
  if(a>b){
    swap = a;
    a = b;
    b = swap;
  }
  if(a>c){
    swap = a;
    a = c;
    c = swap;
  }
  if(b>c){
    swap = b;
    b = c;
    c = swap;
  }
  cout << a << " " << b << " "  << c << endl;
}

Measured memory_bytes: 1164